Changeset 57572 in vbox for trunk/src/VBox/Runtime/common/crypto
- Timestamp:
- Aug 28, 2015 1:31:29 AM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 102396
- Location:
- trunk/src/VBox/Runtime/common/crypto
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/crypto/RTCrStoreCertAddFromFile.cpp
r57548 r57572 100 100 RTDECL(int) RTCrStoreCertAddFromFile(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo) 101 101 { 102 AssertReturn(!fFlags, VERR_INVALID_FLAGS); 103 #if 0 104 RTCRX509CERTIFICATES Certs; 105 int rc = RTCrX509Certificates_ReadFromFile(pszFilename, 0, &Certs, pErrInfo); 106 if (RT_SUCCESS(rc)) 107 { 108 for (uint32_t i = 0; i < Certs.cCerts; i++) 109 { 110 int rc2 = RTCrStoreCertAddEncoded(hStore, RTCRCERTCTX_F_ENC_X509_DER, 111 RTASN1CORE_GET_RAW_ASN1_PTR(&Certs.paCerts[i].SeqCore.Asn1Core), 112 RTASN1CORE_GET_RAW_ASN1_SIZE(&Certs.paCerts[i].SeqCore.Asn1Core), 113 RT_SUCCESS(rc) ? pErrInfo : NULL); 114 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 115 rc = rc2; 116 } 117 118 RTAsn1Destroy(&Certs.SetCore.Asn1Core); 119 } 120 return rc; 121 #else 102 AssertReturn(!(fFlags & ~(RTCRCERTCTX_F_ADD_IF_NOT_FOUND | RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR)), VERR_INVALID_FLAGS); 122 103 123 104 PCRTCRPEMSECTION pSectionHead; 124 int rc = RTCrPemReadFile(pszFilename, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), &pSectionHead, pErrInfo); 105 int rc = RTCrPemReadFile(pszFilename, 106 fFlags & RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR ? RTCRPEMREADFILE_F_CONTINUE_ON_ENCODING_ERROR : 0, 107 g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), &pSectionHead, pErrInfo); 125 108 if (RT_SUCCESS(rc)) 126 109 { … … 128 111 while (pCurSec) 129 112 { 130 int rc2 = RTCrStoreCertAddEncoded(hStore, RTCRCERTCTX_F_ENC_X509_DER , pCurSec->pbData, pCurSec->cbData,131 RT_SUCCESS(rc) ? pErrInfo : NULL);113 int rc2 = RTCrStoreCertAddEncoded(hStore, RTCRCERTCTX_F_ENC_X509_DER | (fFlags & ~RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR), 114 pCurSec->pbData, pCurSec->cbData, !RTErrInfoIsSet(pErrInfo) ? pErrInfo : NULL); 132 115 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 116 { 133 117 rc = rc2; 118 if (!(fFlags & RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR)) 119 break; 120 } 134 121 pCurSec = pCurSec->pNext; 135 122 } … … 138 125 } 139 126 return rc; 140 #endif141 127 } 142 128 -
trunk/src/VBox/Runtime/common/crypto/pemfile.cpp
r57358 r57572 125 125 uint8_t const *pbSavedContent = pbContent; 126 126 size_t const cbSavedContent = cbContent; 127 uint32_t iMarker = 0; 128 while (iMarker < cMarkers) 127 for (uint32_t iMarker = 0; iMarker < cMarkers; iMarker++) 129 128 { 130 129 pbContent = pbSavedContent; … … 143 142 cbContent -= cchWord; 144 143 145 if (!cbContent || !RT_C_IS_BLANK(*pbContent)) 146 break; 147 do 148 { 149 pbContent++; 150 cbContent--; 151 } while (cbContent > 0 && RT_C_IS_BLANK(*pbContent)); 144 if (!cbContent) 145 break; 146 if (RT_C_IS_BLANK(*pbContent)) 147 do 148 { 149 pbContent++; 150 cbContent--; 151 } while (cbContent > 0 && RT_C_IS_BLANK(*pbContent)); 152 else if (cWords > 1 || pbContent[0] != '-') 153 break; 152 154 153 155 cWords--; … … 175 177 if (poffEnd) 176 178 *poffEnd = pbContent - pbStart; 177 if ( *ppMatch)179 if (ppMatch) 178 180 *ppMatch = &paMarkers[iMarker]; 179 181 return true; … … 265 267 { 266 268 /* 267 * Assume a well formed PEM file contains only 7-bit ASCII and restricts268 * itselfto the following control characters:269 * Well formed PEM files should probably only contain 7-bit ASCII and 270 * restrict thenselfs to the following control characters: 269 271 * tab, newline, return, form feed 272 * 273 * However, if we wan't to read PEM files which contains human readable 274 * certificate details before or after each base-64 section, we can't stick 275 * to 7-bit ASCII. We could say it must be UTF-8, but that's probably to 276 * limited too. So, we'll settle for detecting binary files by control 277 * characters alone (safe enough for DER encoded stuff, I think). 270 278 */ 271 279 while (cbFile-- > 0) 272 280 { 273 281 uint8_t const b = *pbFile++; 274 if ( b >= 0x7f 275 || (b < 32 && b != '\t' && b != '\n' && b != '\r' && b != '\f') ) 282 if (b < 32 && b != '\t' && b != '\n' && b != '\r' && b != '\f') 276 283 { 277 284 /* Ignore EOT (4), SUB (26) and NUL (0) at the end of the file. */ … … 280 287 || ( cbFile == 1 281 288 && *pbFile == '\0'))) 282 return true; 289 return false; 290 283 291 if (b == 0 && cbFile == 0) 284 return true; 285 return false; 286 } 287 } 288 return true; 292 return false; 293 294 return true; 295 } 296 } 297 return false; 289 298 } 290 299 … … 328 337 PCRTCRPEMSECTION *ppSectionHead, PRTERRINFO pErrInfo) 329 338 { 330 AssertReturn(! fFlags, VERR_INVALID_FLAGS);339 AssertReturn(!(fFlags & ~RTCRPEMREADFILE_F_CONTINUE_ON_ENCODING_ERROR), VERR_INVALID_FLAGS); 331 340 332 341 size_t cbContent; … … 362 371 /* Decode the section. */ 363 372 /** @todo copy the preamble as well. */ 364 rc= rtCrPemDecodeBase64(pbContent + offBegin, offEnd - offBegin,365 (void **)&pSection->pbData, &pSection->cbData);366 if (RT_FAILURE(rc ))373 int rc2 = rtCrPemDecodeBase64(pbContent + offBegin, offEnd - offBegin, 374 (void **)&pSection->pbData, &pSection->cbData); 375 if (RT_FAILURE(rc2)) 367 376 { 368 377 pSection->pbData = NULL; 369 378 pSection->cbData = 0; 370 break; 379 if ( rc2 == VERR_INVALID_BASE64_ENCODING 380 && (fFlags & RTCRPEMREADFILE_F_CONTINUE_ON_ENCODING_ERROR)) 381 rc = -rc2; 382 else 383 { 384 rc = rc2; 385 break; 386 } 371 387 } 372 388 -
trunk/src/VBox/Runtime/common/crypto/store-inmem.cpp
r57358 r57572 282 282 int rc; 283 283 284 AssertMsgReturn( fFlags== RTCRCERTCTX_F_ENC_X509_DER285 || fFlags== RTCRCERTCTX_F_ENC_TAF_DER284 AssertMsgReturn( (fFlags & RTCRCERTCTX_F_ENC_MASK) == RTCRCERTCTX_F_ENC_X509_DER 285 || (fFlags & RTCRCERTCTX_F_ENC_MASK) == RTCRCERTCTX_F_ENC_TAF_DER 286 286 , ("Only X.509 and TAF DER are supported: %#x\n", fFlags), VERR_INVALID_FLAGS); 287 287 288 if (pThis->cCerts + 1 > pThis->cCertsAlloc) 288 /* 289 * Check for duplicates if specified. 290 */ 291 if (fFlags & RTCRCERTCTX_F_ADD_IF_NOT_FOUND) 292 { 293 uint32_t iCert = pThis->cCerts; 294 while (iCert-- > 0) 295 { 296 PRTCRSTOREINMEMCERT pCert = pThis->papCerts[iCert]; 297 if ( pCert->Core.Public.cbEncoded == cbEncoded 298 && pCert->Core.Public.fFlags == (fFlags & RTCRCERTCTX_F_ENC_MASK) 299 && memcmp(pCert->Core.Public.pabEncoded, pbEncoded, cbEncoded) == 0) 300 return VWRN_ALREADY_EXISTS; 301 } 302 } 303 304 /* 305 * Add it. 306 */ 307 if (pThis->cCerts + 1 <= pThis->cCertsAlloc) 308 { /* likely */ } 309 else 289 310 { 290 311 rc = rtCrStoreInMemGrow(pThis, pThis->cCerts + 1); … … 293 314 } 294 315 295 rc = rtCrStoreInMemCreateCertEntry(pThis, fFlags, pbEncoded, cbEncoded, pErrInfo, &pThis->papCerts[pThis->cCerts]); 316 rc = rtCrStoreInMemCreateCertEntry(pThis, fFlags & RTCRCERTCTX_F_ENC_MASK, pbEncoded, cbEncoded, 317 pErrInfo, &pThis->papCerts[pThis->cCerts]); 296 318 if (RT_SUCCESS(rc)) 297 319 { … … 360 382 return rc; 361 383 } 362 384 RT_EXPORT_SYMBOL(RTCrStoreCreateInMem); 385 -
trunk/src/VBox/Runtime/common/crypto/store-internal.h
r56290 r57572 125 125 * Adds a certificate to the store. 126 126 * 127 * @returns IPRT status. 128 * @retval VWRN_ALREADY_EXISTS if the certificate is already present and 129 * RTCRCERTCTX_F_ADD_IF_NOT_FOUND was specified. 127 130 * @param pvProvider The provider specific data. 128 131 * @param fFlags RTCRCERTCTX_F_XXX. -
trunk/src/VBox/Runtime/common/crypto/store.cpp
r57358 r57572 174 174 AssertPtrReturn(pvSrc, VERR_INVALID_POINTER); 175 175 AssertReturn(cbSrc > 16 && cbSrc < _1M, VERR_OUT_OF_RANGE); 176 AssertMsgReturn( fFlags == RTCRCERTCTX_F_ENC_X509_DER 177 || fFlags == RTCRCERTCTX_F_ENC_TAF_DER 176 AssertReturn(!(fFlags & ~(RTCRCERTCTX_F_ADD_IF_NOT_FOUND | RTCRCERTCTX_F_ENC_MASK)), VERR_INVALID_FLAGS); 177 AssertMsgReturn( (fFlags & RTCRCERTCTX_F_ENC_MASK) == RTCRCERTCTX_F_ENC_X509_DER 178 || (fFlags & RTCRCERTCTX_F_ENC_MASK) == RTCRCERTCTX_F_ENC_TAF_DER 178 179 , ("Only X.509 and TAF DER supported: %#x\n", fFlags), VERR_INVALID_FLAGS); 179 180
Note:
See TracChangeset
for help on using the changeset viewer.