VirtualBox

source: vbox/trunk/src/VBox/Main/include/ApplianceImplPrivate.h@ 60334

Last change on this file since 60334 was 60334, checked in by vboxsync, 9 years ago

CertificateImpl,ApplianceImpl: Drop the unwanted presence attribute and replaced by returning NULL object in IAppliance::getCertificate. Move the certificate object to the data structure. Dropped the clearly unwanted init() method that (a) kept wanting to relate to IAppliance which I though I made clear several times it should not, (b) create an Certificate object in a unready state where most attributes would assert in debug builds and possibly crash. Renamed the CertificateVersion bits and redid the query method to no assume stuff.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.1 KB
Line 
1/* $Id: ApplianceImplPrivate.h 60334 2016-04-05 13:55:31Z vboxsync $ */
2/** @file
3 * VirtualBox Appliance private data definitions
4 */
5
6/*
7 * Copyright (C) 2006-2013 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 ____H_APPLIANCEIMPLPRIVATE
19#define ____H_APPLIANCEIMPLPRIVATE
20
21class VirtualSystemDescription;
22
23#include "ovfreader.h"
24#include "SecretKeyStore.h"
25#include "ThreadTask.h"
26#include <map>
27#include <vector>
28#include <iprt/manifest.h>
29#include <iprt/vfs.h>
30#include <iprt/crypto/x509.h>
31
32////////////////////////////////////////////////////////////////////////////////
33//
34// Appliance data definition
35//
36////////////////////////////////////////////////////////////////////////////////
37
38typedef std::pair<Utf8Str, Utf8Str> STRPAIR;
39
40typedef std::vector<com::Guid> GUIDVEC;
41
42/* Describe a location for the import/export. The location could be a file on a
43 * local hard disk or a remote target based on the supported inet protocols. */
44struct LocationInfo
45{
46 LocationInfo()
47 : storageType(VFSType_File) {}
48 VFSType_T storageType; /* Which type of storage should be handled */
49 Utf8Str strPath; /* File path for the import/export */
50 Utf8Str strHostname; /* Hostname on remote storage locations (could be empty) */
51 Utf8Str strUsername; /* Username on remote storage locations (could be empty) */
52 Utf8Str strPassword; /* Password on remote storage locations (could be empty) */
53};
54
55// opaque private instance data of Appliance class
56struct Appliance::Data
57{
58 enum ApplianceState { ApplianceIdle, ApplianceImporting, ApplianceExporting };
59 enum digest_T {SHA1, SHA256};
60
61 Data()
62 : state(ApplianceIdle)
63 , fDigestTypes(0)
64 , hOurManifest(NIL_RTMANIFEST)
65 , fManifest(true)
66 , fSha256(false)
67 , fDeterminedDigestTypes(false)
68 , hTheirManifest(NIL_RTMANIFEST)
69 , hMemFileTheirManifest(NIL_RTVFSFILE)
70 , fSignerCertLoaded(false)
71 , fCertificateIsSelfSigned(false)
72 , fSignatureValid(false)
73 , fCertificateValid(false)
74 , fCertificateMissingPath(true)
75 , fCertificateValidTime(false)
76 , pbSignedDigest(NULL)
77 , cbSignedDigest(0)
78 , enmSignedDigestType(RTDIGESTTYPE_INVALID)
79 , fExportISOImages(false)
80 , pReader(NULL)
81 , ulWeightForXmlOperation(0)
82 , ulWeightForManifestOperation(0)
83 , ulTotalDisksMB(0)
84 , cDisks(0)
85 , m_cPwProvided(0)
86 {
87 }
88
89 ~Data()
90 {
91 if (pReader)
92 {
93 delete pReader;
94 pReader = NULL;
95 }
96 resetReadData();
97 }
98
99 /**
100 * Resets data used by read.
101 */
102 void resetReadData(void)
103 {
104 strOvfManifestEntry.setNull();
105 if (hOurManifest != NIL_RTMANIFEST)
106 {
107 RTManifestRelease(hOurManifest);
108 hOurManifest = NIL_RTMANIFEST;
109 }
110 if (hTheirManifest != NIL_RTMANIFEST)
111 {
112 RTManifestRelease(hTheirManifest);
113 hTheirManifest = NIL_RTMANIFEST;
114 }
115 if (hMemFileTheirManifest)
116 {
117 RTVfsFileRelease(hMemFileTheirManifest);
118 hMemFileTheirManifest = NIL_RTVFSFILE;
119 }
120 if (pbSignedDigest)
121 {
122 RTMemFree(pbSignedDigest);
123 pbSignedDigest = NULL;
124 cbSignedDigest = 0;
125 }
126 if (fSignerCertLoaded)
127 {
128 RTCrX509Certificate_Delete(&SignerCert);
129 fSignerCertLoaded = false;
130 }
131 enmSignedDigestType = RTDIGESTTYPE_INVALID;
132 fCertificateIsSelfSigned = false;
133 fSignatureValid = false;
134 fCertificateValid = false;
135 fCertificateMissingPath = true;
136 fCertificateValidTime = false;
137 fDeterminedDigestTypes = false;
138 fDigestTypes = RTMANIFEST_ATTR_SHA1 | RTMANIFEST_ATTR_SHA256 | RTMANIFEST_ATTR_SHA512;
139 ptrCertificateInfo.setNull();
140 strCertError.setNull();
141 }
142
143 ApplianceState state;
144
145 LocationInfo locInfo; // location info for the currently processed OVF
146 /** The digests types to calculate (RTMANIFEST_ATTR_XXX) for the manifest.
147 * This will be a single value when exporting. Zero, one or two. */
148 uint32_t fDigestTypes;
149 /** Manifest created while importing or exporting. */
150 RTMANIFEST hOurManifest;
151
152 /** @name Write data
153 * @{ */
154 bool fManifest; // Create a manifest file on export
155 bool fSha256; // true = SHA256 (OVF 2.0), false = SHA1 (OVF 1.0)
156 /** @} */
157
158 /** @name Read data
159 * @{ */
160 /** The manifest entry name of the OVF-file. */
161 Utf8Str strOvfManifestEntry;
162
163 /** Set if we've parsed the manifest and determined the digest types. */
164 bool fDeterminedDigestTypes;
165
166 /** Manifest read in during read() and kept around for later verification. */
167 RTMANIFEST hTheirManifest;
168 /** Memorized copy of the manifest file for signature checking purposes. */
169 RTVFSFILE hMemFileTheirManifest;
170
171 /** The signer certificate from the signature file (.cert).
172 * This will be used in the future provide information about the signer via
173 * the API. */
174 RTCRX509CERTIFICATE SignerCert;
175 /** Set if the SignerCert member contains usable data. */
176 bool fSignerCertLoaded;
177 /** Cached RTCrX509Validity_IsValidAtTimeSpec result set by read(). */
178 bool fCertificateIsSelfSigned;
179 /** Set by read() if pbSignedDigest verified correctly against SignerCert. */
180 bool fSignatureValid;
181 /** Set by read() when the SignerCert checked out fine. */
182 bool fCertificateValid;
183 /** Set by read() when the SignerCert certificate path couldn't be built. */
184 bool fCertificateMissingPath;
185 /** Set by read() when the SignerCert (+path) is valid in the temporal sense. */
186 bool fCertificateValidTime;
187 /** For keeping certificate error messages we delay from read() to import(). */
188 Utf8Str strCertError;
189 /** The signed digest of the manifest. */
190 uint8_t *pbSignedDigest;
191 /** The size of the signed digest. */
192 size_t cbSignedDigest;
193 /** The digest type used to sign the manifest. */
194 RTDIGESTTYPE enmSignedDigestType;
195 /** The certificate info object. This is NULL if no signature and
196 * successfully loaded certificate. */
197 ComObjPtr<Certificate> ptrCertificateInfo;
198 /** @} */
199
200 bool fExportISOImages;// when 1 the ISO images are exported
201
202 RTCList<ImportOptions_T> optListImport;
203 RTCList<ExportOptions_T> optListExport;
204
205 ovf::OVFReader *pReader;
206
207 std::list< ComObjPtr<VirtualSystemDescription> >
208 virtualSystemDescriptions;
209
210 std::list<Utf8Str> llWarnings;
211
212 ULONG ulWeightForXmlOperation;
213 ULONG ulWeightForManifestOperation;
214 ULONG ulTotalDisksMB;
215 ULONG cDisks;
216
217 std::list<Guid> llGuidsMachinesCreated;
218
219 /** Sequence of password identifiers to encrypt disk images during export. */
220 std::vector<com::Utf8Str> m_vecPasswordIdentifiers;
221 /** Map to get all medium identifiers assoicated with a given password identifier. */
222 std::map<com::Utf8Str, GUIDVEC> m_mapPwIdToMediumIds;
223 /** Secret key store used to hold the passwords during export. */
224 SecretKeyStore *m_pSecretKeyStore;
225 /** Number of passwords provided. */
226 uint32_t m_cPwProvided;
227};
228
229struct Appliance::XMLStack
230{
231 std::map<Utf8Str, const VirtualSystemDescriptionEntry*> mapDisks;
232 std::map<Utf8Str, bool> mapNetworks;
233};
234
235class Appliance::TaskOVF: public ThreadTask
236{
237public:
238 enum TaskType
239 {
240 Read,
241 Import,
242 Write
243 };
244
245 TaskOVF(Appliance *aThat,
246 TaskType aType,
247 LocationInfo aLocInfo,
248 ComObjPtr<Progress> &aProgress)
249 : ThreadTask("TaskOVF"),
250 pAppliance(aThat),
251 taskType(aType),
252 locInfo(aLocInfo),
253 pProgress(aProgress),
254 enFormat(ovf::OVFVersion_unknown),
255 rc(S_OK)
256 {
257 switch (taskType)
258 {
259 case TaskOVF::Read: m_strTaskName = "ApplRead"; break;
260 case TaskOVF::Import: m_strTaskName = "ApplImp"; break;
261 case TaskOVF::Write: m_strTaskName = "ApplWrit"; break;
262 default: m_strTaskName = "ApplTask"; break;
263 }
264 }
265
266 static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
267
268 Appliance *pAppliance;
269 TaskType taskType;
270 const LocationInfo locInfo;
271 ComObjPtr<Progress> pProgress;
272
273 ovf::OVFVersion_T enFormat;
274
275 HRESULT rc;
276
277 void handler()
278 {
279 int vrc = Appliance::i_taskThreadImportOrExport(NULL, this); NOREF(vrc);
280 }
281};
282
283struct MyHardDiskAttachment
284{
285 ComPtr<IMachine> pMachine;
286 Bstr controllerType;
287 int32_t lControllerPort; // 0-29 for SATA
288 int32_t lDevice; // IDE: 0 or 1, otherwise 0 always
289};
290
291/**
292 * Used by Appliance::importMachineGeneric() to store
293 * input parameters and rollback information.
294 */
295struct Appliance::ImportStack
296{
297 // input pointers
298 const LocationInfo &locInfo; // ptr to location info from Appliance::importFS()
299 Utf8Str strSourceDir; // directory where source files reside
300 const ovf::DiskImagesMap &mapDisks; // ptr to disks map in OVF
301 ComObjPtr<Progress> &pProgress; // progress object passed into Appliance::importFS()
302
303 // input parameters from VirtualSystemDescriptions
304 Utf8Str strNameVBox; // VM name
305 Utf8Str strMachineFolder; // FQ host folder where the VirtualBox machine would be created
306 Utf8Str strOsTypeVBox; // VirtualBox guest OS type as string
307 Utf8Str strDescription;
308 uint32_t cCPUs; // CPU count
309 bool fForceHWVirt; // if true, we force enabling hardware virtualization
310 bool fForceIOAPIC; // if true, we force enabling the IOAPIC
311 uint32_t ulMemorySizeMB; // virtual machine RAM in megabytes
312#ifdef VBOX_WITH_USB
313 bool fUSBEnabled;
314#endif
315 Utf8Str strAudioAdapter; // if not empty, then the guest has audio enabled, and this is the decimal
316 // representation of the audio adapter (should always be "0" for AC97 presently)
317
318 // session (not initially created)
319 ComPtr<ISession> pSession; // session opened in Appliance::importFS() for machine manipulation
320 bool fSessionOpen; // true if the pSession is currently open and needs closing
321
322 /** @name File access related stuff (TAR stream)
323 * @{ */
324 /** OVA file system stream handle. NIL if not OVA. */
325 RTVFSFSSTREAM hVfsFssOva;
326 /** OVA lookahead I/O stream object. */
327 RTVFSIOSTREAM hVfsIosOvaLookAhead;
328 /** OVA lookahead I/O stream object name. */
329 char *pszOvaLookAheadName;
330 /** @} */
331
332 // a list of images that we created/imported; this is initially empty
333 // and will be cleaned up on errors
334 std::list<MyHardDiskAttachment> llHardDiskAttachments; // disks that were attached
335 std::map<Utf8Str , Utf8Str> mapNewUUIDsToOriginalUUIDs;
336
337 ImportStack(const LocationInfo &aLocInfo,
338 const ovf::DiskImagesMap &aMapDisks,
339 ComObjPtr<Progress> &aProgress,
340 RTVFSFSSTREAM aVfsFssOva)
341 : locInfo(aLocInfo),
342 mapDisks(aMapDisks),
343 pProgress(aProgress),
344 cCPUs(1),
345 fForceHWVirt(false),
346 fForceIOAPIC(false),
347 ulMemorySizeMB(0),
348 fSessionOpen(false),
349 hVfsFssOva(aVfsFssOva),
350 hVfsIosOvaLookAhead(NIL_RTVFSIOSTREAM),
351 pszOvaLookAheadName(NULL)
352 {
353 if (hVfsFssOva != NIL_RTVFSFSSTREAM)
354 RTVfsFsStrmRetain(hVfsFssOva);
355
356 // disk images have to be on the same place as the OVF file. So
357 // strip the filename out of the full file path
358 strSourceDir = aLocInfo.strPath;
359 strSourceDir.stripFilename();
360 }
361
362 ~ImportStack()
363 {
364 if (hVfsFssOva != NIL_RTVFSFSSTREAM)
365 {
366 RTVfsFsStrmRelease(hVfsFssOva);
367 hVfsFssOva = NIL_RTVFSFSSTREAM;
368 }
369 if (hVfsIosOvaLookAhead != NIL_RTVFSIOSTREAM)
370 {
371 RTVfsIoStrmRelease(hVfsIosOvaLookAhead);
372 hVfsIosOvaLookAhead = NIL_RTVFSIOSTREAM;
373 }
374 if (pszOvaLookAheadName)
375 {
376 RTStrFree(pszOvaLookAheadName);
377 pszOvaLookAheadName = NULL;
378 }
379 }
380
381 HRESULT restoreOriginalUUIDOfAttachedDevice(settings::MachineConfigFile *config);
382 HRESULT saveOriginalUUIDOfAttachedDevice(settings::AttachedDevice &device,
383 const Utf8Str &newlyUuid);
384 RTVFSIOSTREAM claimOvaLookAHead(void);
385
386};
387
388////////////////////////////////////////////////////////////////////////////////
389//
390// VirtualSystemDescription data definition
391//
392////////////////////////////////////////////////////////////////////////////////
393
394struct VirtualSystemDescription::Data
395{
396 std::vector<VirtualSystemDescriptionEntry>
397 maDescriptions; // item descriptions
398
399 ComPtr<Machine> pMachine; // VirtualBox machine this description was exported from (export only)
400
401 settings::MachineConfigFile
402 *pConfig; // machine config created from <vbox:Machine> element if found (import only)
403};
404
405////////////////////////////////////////////////////////////////////////////////
406//
407// Internal helpers
408//
409////////////////////////////////////////////////////////////////////////////////
410
411void convertCIMOSType2VBoxOSType(Utf8Str &strType, ovf::CIMOSType_T c, const Utf8Str &cStr);
412
413ovf::CIMOSType_T convertVBoxOSType2CIMOSType(const char *pcszVBox, BOOL fLongMode);
414
415Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type);
416
417
418typedef struct SHASTORAGE
419{
420 PVDINTERFACE pVDImageIfaces;
421 bool fCreateDigest;
422 bool fSha256; /* false = SHA1 (OVF 1.x), true = SHA256 (OVF 2.0) */
423 Utf8Str strDigest;
424} SHASTORAGE, *PSHASTORAGE;
425
426PVDINTERFACEIO ShaCreateInterface();
427PVDINTERFACEIO FileCreateInterface();
428PVDINTERFACEIO tarWriterCreateInterface(void);
429
430int writeBufferToFile(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser);
431
432#endif // !____H_APPLIANCEIMPLPRIVATE
433
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