VirtualBox

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

Last change on this file since 75920 was 75920, checked in by vboxsync, 6 years ago

bugref:9311. Added support of cloud export into VBoxManage.

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