VirtualBox

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

Last change on this file since 67231 was 67199, checked in by vboxsync, 8 years ago

Main: ApplianceImplExport.cpp: Hacking OPC exporting.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.4 KB
Line 
1/* $Id: ApplianceImplPrivate.h 67199 2017-06-01 09:08:15Z vboxsync $ */
2/** @file
3 * VirtualBox Appliance private data definitions
4 */
5
6/*
7 * Copyright (C) 2006-2016 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 strPath; /* File path for the import/export */
57 Utf8Str strHostname; /* Hostname on remote storage locations (could be empty) */
58 Utf8Str strUsername; /* Username on remote storage locations (could be empty) */
59 Utf8Str strPassword; /* Password on remote storage locations (could be empty) */
60};
61
62// opaque private instance data of Appliance class
63struct Appliance::Data
64{
65 enum ApplianceState { ApplianceIdle, ApplianceImporting, ApplianceExporting };
66 enum digest_T {SHA1, SHA256};
67
68 Data()
69 : state(ApplianceIdle)
70 , fDigestTypes(0)
71 , hOurManifest(NIL_RTMANIFEST)
72 , fManifest(true)
73#ifndef VBOX_WITH_NEW_TAR_CREATOR
74 , fSha256(false)
75#endif
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 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#ifndef VBOX_WITH_NEW_TAR_CREATOR
165 bool fSha256; // true = SHA256 (OVF 2.0), false = SHA1 (OVF 1.0)
166#endif
167 /** @} */
168
169 /** @name Read data
170 * @{ */
171 /** The manifest entry name of the OVF-file. */
172 Utf8Str strOvfManifestEntry;
173
174 /** Set if we've parsed the manifest and determined the digest types. */
175 bool fDeterminedDigestTypes;
176
177 /** Manifest read in during read() and kept around for later verification. */
178 RTMANIFEST hTheirManifest;
179 /** Memorized copy of the manifest file for signature checking purposes. */
180 RTVFSFILE hMemFileTheirManifest;
181
182 /** The signer certificate from the signature file (.cert).
183 * This will be used in the future provide information about the signer via
184 * the API. */
185 RTCRX509CERTIFICATE SignerCert;
186 /** Set if the SignerCert member contains usable data. */
187 bool fSignerCertLoaded;
188 /** Cached RTCrX509Validity_IsValidAtTimeSpec result set by read(). */
189 bool fCertificateIsSelfSigned;
190 /** Set by read() if pbSignedDigest verified correctly against SignerCert. */
191 bool fSignatureValid;
192 /** Set by read() when the SignerCert checked out fine. */
193 bool fCertificateValid;
194 /** Set by read() when the SignerCert certificate path couldn't be built. */
195 bool fCertificateMissingPath;
196 /** Set by read() when the SignerCert (+path) is valid in the temporal sense. */
197 bool fCertificateValidTime;
198 /** For keeping certificate error messages we delay from read() to import(). */
199 Utf8Str strCertError;
200 /** The signed digest of the manifest. */
201 uint8_t *pbSignedDigest;
202 /** The size of the signed digest. */
203 size_t cbSignedDigest;
204 /** The digest type used to sign the manifest. */
205 RTDIGESTTYPE enmSignedDigestType;
206 /** The certificate info object. This is NULL if no signature and
207 * successfully loaded certificate. */
208 ComObjPtr<Certificate> ptrCertificateInfo;
209 /** @} */
210
211 bool fExportISOImages;// when 1 the ISO images are exported
212
213 RTCList<ImportOptions_T> optListImport;
214 RTCList<ExportOptions_T> optListExport;
215
216 ovf::OVFReader *pReader;
217
218 std::list< ComObjPtr<VirtualSystemDescription> >
219 virtualSystemDescriptions;
220
221 std::list<Utf8Str> llWarnings;
222
223 ULONG ulWeightForXmlOperation;
224 ULONG ulWeightForManifestOperation;
225 ULONG ulTotalDisksMB;
226 ULONG cDisks;
227
228 std::list<Guid> llGuidsMachinesCreated;
229
230 /** Sequence of password identifiers to encrypt disk images during export. */
231 std::vector<com::Utf8Str> m_vecPasswordIdentifiers;
232 /** Map to get all medium identifiers assoicated with a given password identifier. */
233 std::map<com::Utf8Str, GUIDVEC> m_mapPwIdToMediumIds;
234 /** Secret key store used to hold the passwords during export. */
235 SecretKeyStore *m_pSecretKeyStore;
236 /** Number of passwords provided. */
237 uint32_t m_cPwProvided;
238};
239
240struct Appliance::XMLStack
241{
242 std::map<Utf8Str, const VirtualSystemDescriptionEntry*> mapDisks;
243 std::list<Utf8Str> mapDiskSequence;
244 std::list<Utf8Str> mapDiskSequenceForOneVM;//temporary keeps all disks attached to one exported VM
245 std::map<Utf8Str, bool> mapNetworks;
246};
247
248class Appliance::TaskOVF : public ThreadTask
249{
250public:
251 enum TaskType
252 {
253 Read,
254 Import,
255 Write
256 };
257
258 TaskOVF(Appliance *aThat,
259 TaskType aType,
260 LocationInfo aLocInfo,
261 ComObjPtr<Progress> &aProgress)
262 : ThreadTask("TaskOVF"),
263 pAppliance(aThat),
264 taskType(aType),
265 locInfo(aLocInfo),
266 pProgress(aProgress),
267 enFormat(ovf::OVFVersion_unknown),
268 rc(S_OK)
269 {
270 switch (taskType)
271 {
272 case TaskOVF::Read: m_strTaskName = "ApplRead"; break;
273 case TaskOVF::Import: m_strTaskName = "ApplImp"; break;
274 case TaskOVF::Write: m_strTaskName = "ApplWrit"; break;
275 default: m_strTaskName = "ApplTask"; break;
276 }
277 }
278
279 static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
280
281 Appliance *pAppliance;
282 TaskType taskType;
283 const LocationInfo locInfo;
284 ComObjPtr<Progress> pProgress;
285
286 ovf::OVFVersion_T enFormat;
287
288 HRESULT rc;
289
290 void handler()
291 {
292 Appliance::i_importOrExportThreadTask(this);
293 }
294};
295
296struct MyHardDiskAttachment
297{
298 ComPtr<IMachine> pMachine;
299 Utf8Str controllerName;
300 int32_t lControllerPort; // 0-29 for SATA
301 int32_t lDevice; // IDE: 0 or 1, otherwise 0 always
302};
303
304/**
305 * Used by Appliance::importMachineGeneric() to store
306 * input parameters and rollback information.
307 */
308struct Appliance::ImportStack
309{
310 // input pointers
311 const LocationInfo &locInfo; // ptr to location info from Appliance::importFS()
312 Utf8Str strSourceDir; // directory where source files reside
313 const ovf::DiskImagesMap &mapDisks; // ptr to disks map in OVF
314 ComObjPtr<Progress> &pProgress; // progress object passed into Appliance::importFS()
315
316 // input parameters from VirtualSystemDescriptions
317 Utf8Str strNameVBox; // VM name
318 Utf8Str strMachineFolder; // FQ host folder where the VirtualBox machine would be created
319 Utf8Str strOsTypeVBox; // VirtualBox guest OS type as string
320 Utf8Str strDescription;
321 uint32_t cCPUs; // CPU count
322 bool fForceHWVirt; // if true, we force enabling hardware virtualization
323 bool fForceIOAPIC; // if true, we force enabling the IOAPIC
324 uint32_t ulMemorySizeMB; // virtual machine RAM in megabytes
325#ifdef VBOX_WITH_USB
326 bool fUSBEnabled;
327#endif
328 Utf8Str strAudioAdapter; // if not empty, then the guest has audio enabled, and this is the decimal
329 // representation of the audio adapter (should always be "0" for AC97 presently)
330
331 // session (not initially created)
332 ComPtr<ISession> pSession; // session opened in Appliance::importFS() for machine manipulation
333 bool fSessionOpen; // true if the pSession is currently open and needs closing
334
335 /** @name File access related stuff (TAR stream)
336 * @{ */
337 /** OVA file system stream handle. NIL if not OVA. */
338 RTVFSFSSTREAM hVfsFssOva;
339 /** OVA lookahead I/O stream object. */
340 RTVFSIOSTREAM hVfsIosOvaLookAhead;
341 /** OVA lookahead I/O stream object name. */
342 char *pszOvaLookAheadName;
343 /** @} */
344
345 // a list of images that we created/imported; this is initially empty
346 // and will be cleaned up on errors
347 std::list<MyHardDiskAttachment> llHardDiskAttachments; // disks that were attached
348 std::map<Utf8Str , Utf8Str> mapNewUUIDsToOriginalUUIDs;
349
350 ImportStack(const LocationInfo &aLocInfo,
351 const ovf::DiskImagesMap &aMapDisks,
352 ComObjPtr<Progress> &aProgress,
353 RTVFSFSSTREAM aVfsFssOva)
354 : locInfo(aLocInfo),
355 mapDisks(aMapDisks),
356 pProgress(aProgress),
357 cCPUs(1),
358 fForceHWVirt(false),
359 fForceIOAPIC(false),
360 ulMemorySizeMB(0),
361 fSessionOpen(false),
362 hVfsFssOva(aVfsFssOva),
363 hVfsIosOvaLookAhead(NIL_RTVFSIOSTREAM),
364 pszOvaLookAheadName(NULL)
365 {
366 if (hVfsFssOva != NIL_RTVFSFSSTREAM)
367 RTVfsFsStrmRetain(hVfsFssOva);
368
369 // disk images have to be on the same place as the OVF file. So
370 // strip the filename out of the full file path
371 strSourceDir = aLocInfo.strPath;
372 strSourceDir.stripFilename();
373 }
374
375 ~ImportStack()
376 {
377 if (hVfsFssOva != NIL_RTVFSFSSTREAM)
378 {
379 RTVfsFsStrmRelease(hVfsFssOva);
380 hVfsFssOva = NIL_RTVFSFSSTREAM;
381 }
382 if (hVfsIosOvaLookAhead != NIL_RTVFSIOSTREAM)
383 {
384 RTVfsIoStrmRelease(hVfsIosOvaLookAhead);
385 hVfsIosOvaLookAhead = NIL_RTVFSIOSTREAM;
386 }
387 if (pszOvaLookAheadName)
388 {
389 RTStrFree(pszOvaLookAheadName);
390 pszOvaLookAheadName = NULL;
391 }
392 }
393
394 HRESULT restoreOriginalUUIDOfAttachedDevice(settings::MachineConfigFile *config);
395 HRESULT saveOriginalUUIDOfAttachedDevice(settings::AttachedDevice &device,
396 const Utf8Str &newlyUuid);
397 RTVFSIOSTREAM claimOvaLookAHead(void);
398
399};
400
401////////////////////////////////////////////////////////////////////////////////
402//
403// VirtualSystemDescription data definition
404//
405////////////////////////////////////////////////////////////////////////////////
406
407struct VirtualSystemDescription::Data
408{
409 std::vector<VirtualSystemDescriptionEntry>
410 maDescriptions; // item descriptions
411
412 ComPtr<Machine> pMachine; // VirtualBox machine this description was exported from (export only)
413
414 settings::MachineConfigFile
415 *pConfig; // machine config created from <vbox:Machine> element if found (import only)
416};
417
418////////////////////////////////////////////////////////////////////////////////
419//
420// Internal helpers
421//
422////////////////////////////////////////////////////////////////////////////////
423
424void convertCIMOSType2VBoxOSType(Utf8Str &strType, ovf::CIMOSType_T c, const Utf8Str &cStr);
425
426ovf::CIMOSType_T convertVBoxOSType2CIMOSType(const char *pcszVBox, BOOL fLongMode);
427
428Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type);
429
430
431#ifndef VBOX_WITH_NEW_TAR_CREATOR
432typedef struct SHASTORAGE
433{
434 PVDINTERFACE pVDImageIfaces;
435 bool fCreateDigest;
436 bool fSha256; /* false = SHA1 (OVF 1.x), true = SHA256 (OVF 2.0) */
437 Utf8Str strDigest;
438} SHASTORAGE, *PSHASTORAGE;
439
440PVDINTERFACEIO ShaCreateInterface();
441PVDINTERFACEIO FileCreateInterface();
442PVDINTERFACEIO tarWriterCreateInterface(void);
443#endif
444
445int writeBufferToFile(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser);
446
447#endif // !____H_APPLIANCEIMPLPRIVATE
448
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