VirtualBox

source: vbox/trunk/src/VBox/Main/include/CryptoUtils.h@ 94771

Last change on this file since 94771 was 94771, checked in by vboxsync, 3 years ago

Main: Introduce crypto utilities for handling SSM files, bugref:9955

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: CryptoUtils.h 94771 2022-05-02 10:07:05Z vboxsync $ */
2/** @file
3 * Main - Cryptographic utility functions used by both VBoxSVC and VBoxC.
4 */
5
6/*
7 * Copyright (C) 2022 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef MAIN_INCLUDED_CryptoUtils_h
19#define MAIN_INCLUDED_CryptoUtils_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <iprt/cdefs.h>
25#include <iprt/types.h>
26#include <iprt/vfs.h>
27
28#include <VBox/VBoxCryptoIf.h>
29#include <VBox/com/string.h>
30#include <VBox/vmm/ssm.h>
31
32#include "SecretKeyStore.h"
33#ifdef VBOX_COM_INPROC
34# include "ConsoleImpl.h"
35#else
36# include "MachineImpl.h"
37# include "VirtualBoxImpl.h"
38#endif
39
40
41/**
42 * Class handling encrypted and non encrypted SSM files.
43 */
44class SsmStream
45{
46 public:
47#ifdef VBOX_COM_INPROC
48 SsmStream(Console *pParent, SecretKeyStore *pKeyStore, const Utf8Str &strKeyId, const Utf8Str &strKeyStore);
49#else
50 SsmStream(VirtualBox *pParent, SecretKeyStore *pKeyStore, const Utf8Str &strKeyId, const Utf8Str &strKeyStore);
51#endif
52 ~SsmStream();
53
54 /**
55 * Actually opens the stream for either reading or writing.
56 *
57 * @returns VBox status code.
58 * @param strFilename The filename of the saved state to open or create.
59 * @param fWrite Flag whether the stream should be opened for writing (true) or readonly (false).
60 * @param ppSsmHandle Where to store the SSM handle on success, don't call SSMR3Close() but the provided close() method.
61 */
62 int open(const Utf8Str &strFilename, bool fWrite, PSSMHANDLE *ppSsmHandle);
63
64 /**
65 * Closes an previously opened stream.
66 *
67 * @returns VBox status code.
68 */
69 int close(void);
70
71 private:
72
73 static DECLCALLBACK(int) i_ssmCryptoWrite(void *pvUser, uint64_t offStream, const void *pvBuf, size_t cbToWrite);
74 static DECLCALLBACK(int) i_ssmCryptoRead(void *pvUser, uint64_t offStream, void *pvBuf, size_t cbToRead, size_t *pcbRead);
75 static DECLCALLBACK(int) i_ssmCryptoSeek(void *pvUser, int64_t offSeek, unsigned uMethod, uint64_t *poffActual);
76 static DECLCALLBACK(uint64_t) i_ssmCryptoTell(void *pvUser);
77 static DECLCALLBACK(int) i_ssmCryptoSize(void *pvUser, uint64_t *pcb);
78 static DECLCALLBACK(int) i_ssmCryptoIsOk(void *pvUser);
79 static DECLCALLBACK(int) i_ssmCryptoClose(void *pvUser, bool fCancelled);
80
81#ifdef VBOX_COM_INPROC
82 Console *m_pParent;
83#else
84 VirtualBox *m_pParent;
85#endif
86 /** The key store for getting at passwords. */
87 SecretKeyStore *m_pKeyStore;
88 /** The key ID holding the password, empty if the saved state is not encrypted. */
89 Utf8Str m_strKeyId;
90 /** The keystore holding the encrypted DEK. */
91 Utf8Str m_strKeyStore;
92 /** The VFS file handle. */
93 RTVFSFILE m_hVfsFile;
94 /** The SSM handle when opened. */
95 PSSMHANDLE m_pSsm;
96 /** The SSM stream callbacks table. */
97 SSMSTRMOPS m_StrmOps;
98 /** The cryptographic interfacer. */
99 PCVBOXCRYPTOIF m_pCryptoIf;
100};
101
102#endif /* !MAIN_INCLUDED_CryptoUtils_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette