Changeset 46581 in vbox
- Timestamp:
- Jun 17, 2013 10:43:54 AM (11 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/ApplianceImplPrivate.h
r46518 r46581 229 229 Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type); 230 230 231 bool checkComplianceDigestAndOVFVersion(bool digestType, ovf::OVFVersion_T ovfVersion);232 233 231 234 232 typedef struct SHASTORAGE -
trunk/src/VBox/Main/src-server/ApplianceImpl.cpp
r46518 r46581 309 309 } 310 310 311 bool checkComplianceDigestAndOVFVersion(bool fDigestType, ovf::OVFVersion_T ovfVersion)312 {313 bool res = false;314 if ( (ovfVersion == ovf::OVFVersion_2_0 && fDigestType)315 || (ovfVersion == ovf::OVFVersion_1_0 && !fDigestType)316 || (ovfVersion == ovf::OVFVersion_0_9 && !fDigestType))317 res = true;318 return res;319 }320 321 322 311 //////////////////////////////////////////////////////////////////////////////// 323 312 // -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r46518 r46581 1058 1058 PVDINTERFACEIO pTarIo = 0; 1059 1059 char *pszFilename = 0; 1060 void *pBuf = NULL;1061 1060 SHASTORAGE storage; 1062 1061 1063 1062 RT_ZERO(storage); 1064 1063 1065 try 1066 { 1067 vrc = RTTarOpen(&tar, pTask->locInfo.strPath.c_str(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, true); 1068 if (RT_FAILURE(vrc)) 1064 vrc = RTTarOpen(&tar, pTask->locInfo.strPath.c_str(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, true); 1065 if (RT_FAILURE(vrc)) 1066 rc = setError(VBOX_E_FILE_ERROR, 1067 tr("Could not open the OVA file '%s' (%Rrc)"), 1068 pTask->locInfo.strPath.c_str(), vrc); 1069 else 1070 { 1071 do 1069 1072 { 1070 return setError(VBOX_E_FILE_ERROR, 1071 tr("Could not open the OVA file '%s' (%Rrc)"), 1072 pTask->locInfo.strPath.c_str(), vrc); 1073 } 1074 1075 vrc = RTTarCurrentFile(tar, &pszFilename); 1076 if (RT_FAILURE(vrc)) 1077 { 1078 throw setError(VBOX_E_FILE_ERROR, 1079 tr("Could not extract the OVF file from the OVA package (%Rrc)"), 1080 vrc); 1081 } 1082 1083 //find the manifest file 1084 Utf8Str strMfFile = Utf8Str(pszFilename).stripPath().stripExt().append(".mf"); 1085 vrc = RTTarFileExists(pTask->locInfo.strPath.c_str(), strMfFile.c_str()); 1086 if (RT_SUCCESS(vrc)) 1087 { 1088 //read the manifest file and find a type of used digest 1089 size_t cbRead = 0; 1090 RTDIGESTTYPE digestType = RTDIGESTTYPE_UNKNOWN; 1091 1092 vrc = RTTarExtractFileToBuf(pTask->locInfo.strPath.c_str(), &pBuf, &cbRead, strMfFile.c_str(), NULL, NULL); 1073 vrc = RTTarCurrentFile(tar, &pszFilename); 1093 1074 if (RT_FAILURE(vrc)) 1094 1075 { 1095 throw setError(VBOX_E_FILE_ERROR, 1096 tr("Could not read the manifest file '%s' (%Rrc) from OVA package"), 1097 RTPathFilename(strMfFile.c_str()), vrc); 1098 } 1099 1100 vrc = RTManifestVerifyDigestType(pBuf, cbRead, digestType); 1101 1076 rc = VBOX_E_FILE_ERROR; 1077 break; 1078 } 1079 pTarIo = TarCreateInterface(); 1080 if (!pTarIo) 1081 { 1082 rc = E_OUTOFMEMORY; 1083 break; 1084 } 1085 1086 pShaIo = ShaCreateInterface(); 1087 if (!pShaIo) 1088 { 1089 rc = E_OUTOFMEMORY; 1090 break ; 1091 } 1092 1093 Utf8Str name = applianceIOName(applianceIOTar); 1094 1095 vrc = VDInterfaceAdd(&pTarIo->Core, name.c_str(), 1096 VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO), 1097 &storage.pVDImageIfaces); 1102 1098 if (RT_FAILURE(vrc)) 1103 1099 { 1104 throw setError(VBOX_E_FILE_ERROR, 1105 tr("Could not verify supported digest types in the manifest file '%s' (%Rrc)"), 1106 RTPathFilename(strMfFile.c_str()), vrc); 1107 } 1108 1109 storage.fCreateDigest = true; 1110 1111 if (digestType == RTDIGESTTYPE_SHA256) 1112 { 1113 storage.fSha256 = true; 1114 } 1115 } 1116 } 1117 catch (HRESULT res) 1118 { 1119 rc = res; 1120 } 1121 1122 if (pBuf) 1123 RTMemFree(pBuf); 1124 1125 RTTarClose(tar); 1126 1127 1128 if (SUCCEEDED(rc)) 1129 { 1130 vrc = RTTarOpen(&tar, pTask->locInfo.strPath.c_str(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, true); 1131 if (RT_FAILURE(vrc)) 1132 rc = setError(VBOX_E_FILE_ERROR, 1133 tr("Could not open the OVA file '%s' (%Rrc)"), 1134 pTask->locInfo.strPath.c_str(), vrc); 1135 else 1136 { 1137 do 1138 { 1139 vrc = RTTarCurrentFile(tar, &pszFilename); 1140 if (RT_FAILURE(vrc)) 1141 { 1142 rc = VBOX_E_FILE_ERROR; 1143 break; 1144 } 1145 pTarIo = TarCreateInterface(); 1146 if (!pTarIo) 1147 { 1148 rc = E_OUTOFMEMORY; 1149 break; 1150 } 1151 1152 pShaIo = ShaCreateInterface(); 1153 if (!pShaIo) 1154 { 1155 rc = E_OUTOFMEMORY; 1156 break ; 1157 } 1158 1159 Utf8Str name = applianceIOName(applianceIOTar); 1160 1161 vrc = VDInterfaceAdd(&pTarIo->Core, name.c_str(), 1162 VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO), 1163 &storage.pVDImageIfaces); 1164 if (RT_FAILURE(vrc)) 1165 { 1166 rc = setError(VBOX_E_IPRT_ERROR, "Creation of the VD interface failed (%Rrc)", vrc); 1167 break; 1168 } 1169 1170 rc = readFSImpl(pTask, pszFilename, pShaIo, &storage); 1171 if (FAILED(rc)) 1172 break; 1173 1174 } while (0); 1175 1176 RTTarClose(tar); 1177 } 1178 } 1100 rc = setError(VBOX_E_IPRT_ERROR, "Creation of the VD interface failed (%Rrc)", vrc); 1101 break; 1102 } 1103 1104 rc = readFSImpl(pTask, pszFilename, pShaIo, &storage); 1105 if (FAILED(rc)) 1106 break; 1107 1108 } while (0); 1109 1110 RTTarClose(tar); 1111 } 1112 1179 1113 1180 1114 … … 1198 1132 1199 1133 HRESULT rc = S_OK; 1134 1135 pStorage->fCreateDigest = true; 1200 1136 1201 1137 void *pvTmpBuf = 0; … … 1210 1146 tr("Could not read OVF file '%s' (%Rrc)"), 1211 1147 RTPathFilename(strFilename.c_str()), vrc); 1212 /* Copy the SHA1/SHA256 sum of the OVF file for later validation */ 1213 m->strOVFSHADigest = pStorage->strDigest; 1214 1215 if (pStorage->fCreateDigest) 1148 1149 /* Read & parse the XML structure of the OVF file */ 1150 m->pReader = new ovf::OVFReader(pvTmpBuf, cbSize, pTask->locInfo.strPath); 1151 1152 if (m->pReader->m_envelopeData.getOVFVersion() == ovf::OVFVersion_2_0) 1216 1153 { 1217 m->fManifest = true; 1218 /* Save a type of used SHA algorithm. Type was extracted during pre-reading manifest (.mf) file*/ 1219 m->fSha256 = pStorage->fSha256; 1154 m->fSha256 = true; 1155 1156 uint8_t digest[RTSHA256_HASH_SIZE]; 1157 size_t cbDigest = RTSHA256_DIGEST_LEN; 1158 char *pszDigest; 1159 1160 RTSha256(pvTmpBuf, cbSize, &digest[0]); 1161 1162 vrc = RTStrAllocEx(&pszDigest, cbDigest + 1); 1163 if (RT_SUCCESS(vrc)) 1164 vrc = RTSha256ToString(digest, pszDigest, cbDigest + 1); 1165 else 1166 throw setError(VBOX_E_FILE_ERROR, 1167 tr("Could not allocate string for SHA256 digest (%Rrc)"), vrc); 1168 1169 if (RT_SUCCESS(vrc)) 1170 /* Copy the SHA256 sum of the OVF file for later validation */ 1171 m->strOVFSHADigest = pszDigest; 1172 else 1173 throw setError(VBOX_E_FILE_ERROR, 1174 tr("Converting SHA256 digest to a string was failed (%Rrc)"), vrc); 1175 1176 RTStrFree(pszDigest); 1177 1220 1178 } 1221 1179 else 1222 1180 { 1223 m->fManifest = false; 1181 m->fSha256 = false; 1182 /* Copy the SHA1 sum of the OVF file for later validation */ 1183 m->strOVFSHADigest = pStorage->strDigest; 1224 1184 } 1225 1185 1226 /* Read & parse the XML structure of the OVF file */1227 m->pReader = new ovf::OVFReader(pvTmpBuf, cbSize, pTask->locInfo.strPath);1228 1186 } 1229 1187 catch (RTCError &x) // includes all XML exceptions … … 3482 3440 3483 3441 // this is safe to access because this thread only gets started 3484 // if pReader != NULL3485 3442 const ovf::OVFReader &reader = *m->pReader; 3486 const ovf::OVFVersion_T ovfVersion = reader.m_envelopeData.getOVFVersion(); 3487 3488 /* check compliance between OVF file and MF file (correctly used type of SHA digest)*/ 3489 if (m->fManifest && !checkComplianceDigestAndOVFVersion(m->fSha256, ovfVersion)) 3490 { 3491 RTCString ovfVer = reader.m_envelopeData.getStringOVFVersion(); 3492 throw setError(VBOX_E_FILE_ERROR, 3493 tr("Incompliance between found OVF standard version %s in the OVF file and used digest %s"), 3494 ovfVer.c_str(), (m->fSha256 == false)? "SHA1":"SHA256"); 3495 } 3496 3497 if (ovfVersion == ovf::OVFVersion_2_0) 3498 pStorage->fSha256 = true; 3443 3444 /* 3445 * get the SHA digest version that was set in accordance with the value of attribute "xmlns:ovf" 3446 * of the element <Envelope> in the OVF file during reading operation. See readFSImpl(). 3447 */ 3448 pStorage->fSha256 = m->fSha256; 3499 3449 3500 3450 // create a session for the machine + disks we manipulate below
Note:
See TracChangeset
for help on using the changeset viewer.