VirtualBox

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

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

Copyright year updates by scm.

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