VirtualBox

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

Last change on this file since 94793 was 94793, checked in by vboxsync, 2 years ago

Main,VMM: Implemented most of the functionality for encrypted VMs (encrypting log files is still missing), bugref:9955

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: CryptoUtils.h 94793 2022-05-03 11:47:03Z 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
31#include <VBox/vmm/ssm.h>
32#include <VBox/vmm/vmmr3vtable.h>
33#include <VBox/vmm/vmapi.h>
34
35#include "SecretKeyStore.h"
36#ifdef VBOX_COM_INPROC
37# include "ConsoleImpl.h"
38#else
39# include "MachineImpl.h"
40# include "VirtualBoxImpl.h"
41#endif
42
43
44/**
45 * Class handling encrypted and non encrypted SSM files.
46 */
47class SsmStream
48{
49 public:
50#ifdef VBOX_COM_INPROC
51 SsmStream(Console *pParent, PCVMMR3VTABLE pVMM, SecretKeyStore *pKeyStore, const Utf8Str &strKeyId, const Utf8Str &strKeyStore);
52#else
53 SsmStream(VirtualBox *pParent, SecretKeyStore *pKeyStore, const Utf8Str &strKeyId, const Utf8Str &strKeyStore);
54#endif
55 ~SsmStream();
56
57 /**
58 * Actually opens the stream for either reading or writing.
59 *
60 * @returns VBox status code.
61 * @param strFilename The filename of the saved state to open or create.
62 * @param fWrite Flag whether the stream should be opened for writing (true) or readonly (false).
63 * @param ppSsmHandle Where to store the SSM handle on success, don't call SSMR3Close() but the provided close() method.
64 */
65 int open(const Utf8Str &strFilename, bool fWrite, PSSMHANDLE *ppSsmHandle);
66
67 /**
68 * Opens the saved state file for reading, doesn't call SSMR3Open().
69 *
70 * @returns VBox status code.
71 * @param strFilename The filename of the saved state to open.
72 */
73 int open(const Utf8Str &strFilename);
74
75 /**
76 * Creates a new saved state file under the given path.
77 *
78 * @returns VBox status code.
79 * @param strFilename The filename of the saved state to create.
80 */
81 int create(const Utf8Str &strFilename);
82
83 /**
84 * Returns the pointer to the stream operations table after a succesful opening/creation.
85 *
86 * @return VBox status code.
87 * @param ppStrmOps Where to store the pointer to the stream operations table on success.
88 * @param ppvStrmOpsUser Where to store the pointer to the opaque user data on success.
89 */
90 int querySsmStrmOps(PCSSMSTRMOPS *ppStrmOps, void **ppvStrmOpsUser);
91
92 /**
93 * Closes an previously opened stream.
94 *
95 * @returns VBox status code.
96 */
97 int close(void);
98
99 private:
100
101 static DECLCALLBACK(int) i_ssmCryptoWrite(void *pvUser, uint64_t offStream, const void *pvBuf, size_t cbToWrite);
102 static DECLCALLBACK(int) i_ssmCryptoRead(void *pvUser, uint64_t offStream, void *pvBuf, size_t cbToRead, size_t *pcbRead);
103 static DECLCALLBACK(int) i_ssmCryptoSeek(void *pvUser, int64_t offSeek, unsigned uMethod, uint64_t *poffActual);
104 static DECLCALLBACK(uint64_t) i_ssmCryptoTell(void *pvUser);
105 static DECLCALLBACK(int) i_ssmCryptoSize(void *pvUser, uint64_t *pcb);
106 static DECLCALLBACK(int) i_ssmCryptoIsOk(void *pvUser);
107 static DECLCALLBACK(int) i_ssmCryptoClose(void *pvUser, bool fCancelled);
108
109#ifdef VBOX_COM_INPROC
110 Console *m_pParent;
111 PCVMMR3VTABLE m_pVMM;
112#else
113 VirtualBox *m_pParent;
114#endif
115 /** The key store for getting at passwords. */
116 SecretKeyStore *m_pKeyStore;
117 /** The key ID holding the password, empty if the saved state is not encrypted. */
118 Utf8Str m_strKeyId;
119 /** The keystore holding the encrypted DEK. */
120 Utf8Str m_strKeyStore;
121 /** The VFS file handle. */
122 RTVFSFILE m_hVfsFile;
123 /** The SSM handle when opened. */
124 PSSMHANDLE m_pSsm;
125 /** The SSM stream callbacks table. */
126 SSMSTRMOPS m_StrmOps;
127 /** The cryptographic interfacer. */
128 PCVBOXCRYPTOIF m_pCryptoIf;
129};
130
131#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