VirtualBox

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

Last change on this file since 84141 was 84141, checked in by vboxsync, 5 years ago

Main/Appliance: There should be no need to store two copies of the manifest. Also, we must not return unsanitized strings thru the API. IFF there is genuine need for non-sanitized data, we must return it as a BYTE array rather than a unicode string. bugref:9699

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

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