VirtualBox

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

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

bugref:9416. The part of OCI import logic. New functions - OciRestClient::exportImage, createImageFromInstance; new API functions - ICloudClient::importInstance, getInstanceInfo; new helper classes - HandleRestBinaryResponse, DownloadSession; changes in the Appliance import and export parts.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.9 KB
Line 
1/* $Id: ApplianceImplPrivate.h 78428 2019-05-07 11:03:49Z vboxsync $ */
2/** @file
3 * VirtualBox Appliance private data definitions
4 */
5
6/*
7 * Copyright (C) 2006-2019 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 ApplianceState { ApplianceIdle, ApplianceImporting, ApplianceExporting };
70 enum digest_T {SHA1, SHA256};
71
72 Data()
73 : state(ApplianceIdle)
74 , fDigestTypes(0)
75 , hOurManifest(NIL_RTMANIFEST)
76 , fManifest(true)
77 , fDeterminedDigestTypes(false)
78 , hTheirManifest(NIL_RTMANIFEST)
79 , hMemFileTheirManifest(NIL_RTVFSFILE)
80 , fSignerCertLoaded(false)
81 , fCertificateIsSelfSigned(false)
82 , fSignatureValid(false)
83 , fCertificateValid(false)
84 , fCertificateMissingPath(true)
85 , fCertificateValidTime(false)
86 , pbSignedDigest(NULL)
87 , cbSignedDigest(0)
88 , enmSignedDigestType(RTDIGESTTYPE_INVALID)
89 , fExportISOImages(false)
90 , pReader(NULL)
91 , ulWeightForXmlOperation(0)
92 , ulWeightForManifestOperation(0)
93 , ulTotalDisksMB(0)
94 , cDisks(0)
95 , m_cPwProvided(0)
96 {
97 }
98
99 ~Data()
100 {
101 if (pReader)
102 {
103 delete pReader;
104 pReader = NULL;
105 }
106 resetReadData();
107 }
108
109 /**
110 * Resets data used by read.
111 */
112 void resetReadData(void)
113 {
114 strOvfManifestEntry.setNull();
115 if (hOurManifest != NIL_RTMANIFEST)
116 {
117 RTManifestRelease(hOurManifest);
118 hOurManifest = NIL_RTMANIFEST;
119 }
120 if (hTheirManifest != NIL_RTMANIFEST)
121 {
122 RTManifestRelease(hTheirManifest);
123 hTheirManifest = NIL_RTMANIFEST;
124 }
125 if (hMemFileTheirManifest)
126 {
127 RTVfsFileRelease(hMemFileTheirManifest);
128 hMemFileTheirManifest = NIL_RTVFSFILE;
129 }
130 if (pbSignedDigest)
131 {
132 RTMemFree(pbSignedDigest);
133 pbSignedDigest = NULL;
134 cbSignedDigest = 0;
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 }
152
153 ApplianceState state;
154
155 LocationInfo locInfo; // location info for the currently processed OVF
156 /** The digests types to calculate (RTMANIFEST_ATTR_XXX) for the manifest.
157 * This will be a single value when exporting. Zero, one or two. */
158 uint32_t fDigestTypes;
159 /** Manifest created while importing or exporting. */
160 RTMANIFEST hOurManifest;
161
162 /** @name Write data
163 * @{ */
164 bool fManifest; // Create a manifest file on export
165 /** @} */
166
167 /** @name Read data
168 * @{ */
169 /** The manifest entry name of the OVF-file. */
170 Utf8Str strOvfManifestEntry;
171
172 /** Set if we've parsed the manifest and determined the digest types. */
173 bool fDeterminedDigestTypes;
174
175 /** Manifest read in during read() and kept around for later verification. */
176 RTMANIFEST hTheirManifest;
177 /** Memorized copy of the manifest file for signature checking purposes. */
178 RTVFSFILE hMemFileTheirManifest;
179
180 /** The signer certificate from the signature file (.cert).
181 * This will be used in the future provide information about the signer via
182 * the API. */
183 RTCRX509CERTIFICATE SignerCert;
184 /** Set if the SignerCert member contains usable data. */
185 bool fSignerCertLoaded;
186 /** Cached RTCrX509Validity_IsValidAtTimeSpec result set by read(). */
187 bool fCertificateIsSelfSigned;
188 /** Set by read() if pbSignedDigest verified correctly against SignerCert. */
189 bool fSignatureValid;
190 /** Set by read() when the SignerCert checked out fine. */
191 bool fCertificateValid;
192 /** Set by read() when the SignerCert certificate path couldn't be built. */
193 bool fCertificateMissingPath;
194 /** Set by read() when the SignerCert (+path) is valid in the temporal sense. */
195 bool fCertificateValidTime;
196 /** For keeping certificate error messages we delay from read() to import(). */
197 Utf8Str strCertError;
198 /** The signed digest of the manifest. */
199 uint8_t *pbSignedDigest;
200 /** The size of the signed digest. */
201 size_t cbSignedDigest;
202 /** The digest type used to sign the manifest. */
203 RTDIGESTTYPE enmSignedDigestType;
204 /** The certificate info object. This is NULL if no signature and
205 * successfully loaded certificate. */
206 ComObjPtr<Certificate> ptrCertificateInfo;
207 /** @} */
208
209 bool fExportISOImages;// when 1 the ISO images are exported
210
211 RTCList<ImportOptions_T> optListImport;
212 RTCList<ExportOptions_T> optListExport;
213
214 ovf::OVFReader *pReader;
215
216 std::list< ComObjPtr<VirtualSystemDescription> >
217 virtualSystemDescriptions;
218
219 std::list<Utf8Str> llWarnings;
220
221 ULONG ulWeightForXmlOperation;
222 ULONG ulWeightForManifestOperation;
223 ULONG ulTotalDisksMB;
224 ULONG cDisks;
225
226 std::list<Guid> llGuidsMachinesCreated;
227
228 /** Sequence of password identifiers to encrypt disk images during export. */
229 std::vector<com::Utf8Str> m_vecPasswordIdentifiers;
230 /** Map to get all medium identifiers assoicated with a given password identifier. */
231 std::map<com::Utf8Str, GUIDVEC> m_mapPwIdToMediumIds;
232 /** Secret key store used to hold the passwords during export. */
233 SecretKeyStore *m_pSecretKeyStore;
234 /** Number of passwords provided. */
235 uint32_t m_cPwProvided;
236};
237
238struct Appliance::XMLStack
239{
240 std::map<Utf8Str, const VirtualSystemDescriptionEntry*> mapDisks;
241 std::list<Utf8Str> mapDiskSequence;
242 std::list<Utf8Str> mapDiskSequenceForOneVM;//temporary keeps all disks attached to one exported VM
243 std::map<Utf8Str, bool> mapNetworks;
244};
245
246class Appliance::TaskOVF : public ThreadTask
247{
248public:
249 enum TaskType
250 {
251 Read,
252 Import,
253 Write
254 };
255
256 TaskOVF(Appliance *aThat,
257 TaskType aType,
258 LocationInfo aLocInfo,
259 ComObjPtr<Progress> &aProgress)
260 : ThreadTask("TaskOVF"),
261 pAppliance(aThat),
262 taskType(aType),
263 locInfo(aLocInfo),
264 pProgress(aProgress),
265 enFormat(ovf::OVFVersion_unknown),
266 rc(S_OK)
267 {
268 switch (taskType)
269 {
270 case TaskOVF::Read: m_strTaskName = "ApplRead"; break;
271 case TaskOVF::Import: m_strTaskName = "ApplImp"; break;
272 case TaskOVF::Write: m_strTaskName = "ApplWrit"; break;
273 default: m_strTaskName = "ApplTask"; break;
274 }
275 }
276
277 static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
278
279 Appliance *pAppliance;
280 TaskType taskType;
281 const LocationInfo locInfo;
282 ComObjPtr<Progress> pProgress;
283
284 ovf::OVFVersion_T enFormat;
285
286 HRESULT rc;
287
288 void handler()
289 {
290 Appliance::i_importOrExportThreadTask(this);
291 }
292};
293
294class Appliance::TaskOPC : public ThreadTask
295{
296public:
297 enum TaskType
298 {
299 Export
300 };
301
302 TaskOPC(Appliance *aThat,
303 TaskType aType,
304 LocationInfo aLocInfo,
305 ComObjPtr<Progress> &aProgress)
306 : ThreadTask("TaskOPC"),
307 pAppliance(aThat),
308 taskType(aType),
309 locInfo(aLocInfo),
310 pProgress(aProgress),
311 rc(S_OK)
312 {
313 m_strTaskName = "OPCExpt";
314 }
315
316 ~TaskOPC()
317 {
318 }
319
320 static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
321
322 Appliance *pAppliance;
323 TaskType taskType;
324 const LocationInfo locInfo;
325 ComObjPtr<Progress> pProgress;
326
327 HRESULT rc;
328
329 void handler()
330 {
331 Appliance::i_exportOPCThreadTask(this);
332 }
333};
334
335
336class Appliance::TaskCloud : public ThreadTask
337{
338public:
339 enum TaskType
340 {
341 Export,
342 Import,
343 ReadData
344 };
345
346 TaskCloud(Appliance *aThat,
347 TaskType aType,
348 LocationInfo aLocInfo,
349 ComObjPtr<Progress> &aProgress)
350 : ThreadTask("TaskCloud"),
351 pAppliance(aThat),
352 taskType(aType),
353 locInfo(aLocInfo),
354 pProgress(aProgress),
355 rc(S_OK)
356 {
357 switch (taskType)
358 {
359 case TaskCloud::Export: m_strTaskName = "CloudExpt"; break;
360 case TaskCloud::Import: m_strTaskName = "CloudImpt"; break;
361 case TaskCloud::ReadData: m_strTaskName = "CloudRead"; break;
362 default: m_strTaskName = "CloudTask"; break;
363 }
364 }
365
366 ~TaskCloud()
367 {
368 }
369
370 static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
371
372 Appliance *pAppliance;
373 TaskType taskType;
374 const LocationInfo locInfo;
375 ComObjPtr<Progress> pProgress;
376
377 HRESULT rc;
378
379 void handler()
380 {
381 Appliance::i_importOrExportCloudThreadTask(this);
382 }
383};
384
385struct MyHardDiskAttachment
386{
387 ComPtr<IMachine> pMachine;
388 Utf8Str controllerName;
389 int32_t lControllerPort; // 0-29 for SATA
390 int32_t lDevice; // IDE: 0 or 1, otherwise 0 always
391};
392
393/**
394 * Used by Appliance::importMachineGeneric() to store
395 * input parameters and rollback information.
396 */
397struct Appliance::ImportStack
398{
399 // input pointers
400 const LocationInfo &locInfo; // ptr to location info from Appliance::importFS()
401 Utf8Str strSourceDir; // directory where source files reside
402 const ovf::DiskImagesMap &mapDisks; // ptr to disks map in OVF
403 ComObjPtr<Progress> &pProgress; // progress object passed into Appliance::importFS()
404
405 // input parameters from VirtualSystemDescriptions
406 Utf8Str strNameVBox; // VM name
407 Utf8Str strSettingsFilename; // Absolute path to VM config file
408 Utf8Str strMachineFolder; // Absolute path to VM folder (derived from strSettingsFilename)
409 Utf8Str strOsTypeVBox; // VirtualBox guest OS type as string
410 Utf8Str strPrimaryGroup; // VM primary group as string
411 Utf8Str strDescription;
412 uint32_t cCPUs; // CPU count
413 bool fForceHWVirt; // if true, we force enabling hardware virtualization
414 bool fForceIOAPIC; // if true, we force enabling the IOAPIC
415 uint32_t ulMemorySizeMB; // virtual machine RAM in megabytes
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