Changeset 59663 in vbox
- Timestamp:
- Feb 14, 2016 8:11:06 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/asn1.h
r58106 r59663 1467 1467 * Optional. 1468 1468 */ 1469 RTDECL(int) RTAsnEncodeWriteHeader(PCRTASN1CORE pAsn1Core, uint32_t fFlags, FNRTASN1ENCODEWRITER pfnWriter, void *pvUser, 1470 PRTERRINFO pErrInfo); 1471 1472 /** 1473 * Prepares the ASN.1 structure for encoding. 1474 * 1475 * The preparations is mainly calculating accurate object size, but may also 1476 * involve operations like recoding internal UTF-8 strings to the actual ASN.1 1477 * format and other things that may require memory to allocated/reallocated. 1469 RTDECL(int) RTAsn1EncodeWriteHeader(PCRTASN1CORE pAsn1Core, uint32_t fFlags, FNRTASN1ENCODEWRITER pfnWriter, void *pvUser, 1470 PRTERRINFO pErrInfo); 1471 1472 /** 1473 * Encodes and writes an ASN.1 object. 1478 1474 * 1479 1475 * @returns IPRT status code … … 1488 1484 RTDECL(int) RTAsn1EncodeWrite(PCRTASN1CORE pRoot, uint32_t fFlags, FNRTASN1ENCODEWRITER pfnWriter, void *pvUser, 1489 1485 PRTERRINFO pErrInfo); 1486 1487 /** 1488 * Encodes and writes an ASN.1 object into a caller allocated memory buffer. 1489 * 1490 * @returns IPRT status code 1491 * @param pRoot The root of the ASN.1 object tree to encode. 1492 * @param fFlags Valid combination of the RTASN1ENCODE_F_XXX 1493 * flags. Must include the encoding type. 1494 * @param pvBuf The output buffer. 1495 * @param cbBuf The buffer size. This should have the size 1496 * returned by RTAsn1EncodePrepare(). 1497 * @param pErrInfo Where to store extended error information. 1498 * Optional. 1499 */ 1500 RTDECL(int) RTAsn1EncodeToBuffer(PCRTASN1CORE pRoot, uint32_t fFlags, void *pvBuf, size_t cbBuf, PRTERRINFO pErrInfo); 1490 1501 1491 1502 /** @} */ -
trunk/include/iprt/crypto/x509.h
r59625 r59663 960 960 PCRTASN1DYNTYPE pParameters, PCRTASN1BITSTRING pPublicKey, 961 961 PRTERRINFO pErrInfo); 962 RTDECL(int) RTCrX509Certificate_VerifySignatureSelfSigned(PCRTCRX509CERTIFICATE pThis, PRTERRINFO pErrInfo); 962 963 RTDECL(int) RTCrX509Certificate_ReadFromFile(PRTCRX509CERTIFICATE pCertificate, const char *pszFilename, uint32_t fFlags, 963 964 PCRTASN1ALLOCATORVTABLE pAllocator, PRTERRINFO pErrInfo); -
trunk/include/iprt/mangling.h
r59625 r59663 2380 2380 # define RTAsn1EncodePrepare RT_MANGLER(RTAsn1EncodePrepare) 2381 2381 # define RTAsn1EncodeRecalcHdrSize RT_MANGLER(RTAsn1EncodeRecalcHdrSize) 2382 # define RTAsn1EncodeToBuffer RT_MANGLER(RTAsn1EncodeToBuffer) 2382 2383 # define RTAsn1EncodeWrite RT_MANGLER(RTAsn1EncodeWrite) 2383 # define RTAsn EncodeWriteHeader RT_MANGLER(RTAsnEncodeWriteHeader)2384 # define RTAsn1EncodeWriteHeader RT_MANGLER(RTAsn1EncodeWriteHeader) 2384 2385 # define RTAsn1BitString_CheckSanity RT_MANGLER(RTAsn1BitString_CheckSanity) 2385 2386 # define RTAsn1BitString_Clone RT_MANGLER(RTAsn1BitString_Clone) … … 3152 3153 # define RTCrX509Validity_CheckSanity RT_MANGLER(RTCrX509Validity_CheckSanity) 3153 3154 # define RTCrX509Certificate_VerifySignature RT_MANGLER(RTCrX509Certificate_VerifySignature) 3155 # define RTCrX509Certificate_VerifySignatureSelfSigned RT_MANGLER(RTCrX509Certificate_VerifySignatureSelfSigned) 3154 3156 # define RTCrTafCertPathControls_DecodeAsn1 RT_MANGLER(RTCrTafCertPathControls_DecodeAsn1) 3155 3157 # define RTCrTafTrustAnchorChoice_DecodeAsn1 RT_MANGLER(RTCrTafTrustAnchorChoice_DecodeAsn1) -
trunk/src/VBox/Runtime/common/asn1/asn1-encode.cpp
r57358 r59663 36 36 #include <iprt/ctype.h> 37 37 #include <iprt/err.h> 38 #include <iprt/string.h> 38 39 39 40 #include <iprt/formats/asn1.h> … … 72 73 } RTASN1ENCODEWRITEARGS; 73 74 75 /** 76 * Argument package for rtAsn1EncodeToBufferCallback passed by 77 * RTAsn1EncodeToBuffer. 78 */ 79 typedef struct RTASN1ENCODETOBUFARGS 80 { 81 /** The destination buffer position (incremented while writing). */ 82 uint8_t *pbDst; 83 /** The size of the destination buffer left (decremented while writing). */ 84 size_t cbDst; 85 } RTASN1ENCODETOBUFARGS; 86 74 87 75 88 RTDECL(int) RTAsn1EncodeRecalcHdrSize(PRTASN1CORE pAsn1Core, uint32_t fFlags, PRTERRINFO pErrInfo) … … 234 247 235 248 236 RTDECL(int) RTAsn EncodeWriteHeader(PCRTASN1CORE pAsn1Core, uint32_t fFlags, FNRTASN1ENCODEWRITER pfnWriter, void *pvUser,237 PRTERRINFO pErrInfo)249 RTDECL(int) RTAsn1EncodeWriteHeader(PCRTASN1CORE pAsn1Core, uint32_t fFlags, FNRTASN1ENCODEWRITER pfnWriter, void *pvUser, 250 PRTERRINFO pErrInfo) 238 251 { 239 252 AssertReturn((fFlags & RTASN1ENCODE_F_RULE_MASK) == RTASN1ENCODE_F_DER, VERR_INVALID_FLAGS); … … 377 390 * Generic path. Start by writing the header for this object. 378 391 */ 379 rc = RTAsn EncodeWriteHeader(pAsn1Core, pArgs->fFlags, pArgs->pfnWriter, pArgs->pvUser, pArgs->pErrInfo);392 rc = RTAsn1EncodeWriteHeader(pAsn1Core, pArgs->fFlags, pArgs->pfnWriter, pArgs->pvUser, pArgs->pErrInfo); 380 393 if (RT_SUCCESS(rc)) 381 394 { … … 426 439 } 427 440 441 442 static DECLCALLBACK(int) rtAsn1EncodeToBufferCallback(const void *pvBuf, size_t cbToWrite, void *pvUser, PRTERRINFO pErrInfo) 443 { 444 RTASN1ENCODETOBUFARGS *pArgs = (RTASN1ENCODETOBUFARGS *)pvUser; 445 if (RT_LIKELY(pArgs->cbDst >= cbToWrite)) 446 { 447 memcpy(pArgs->pbDst, pvBuf, cbToWrite); 448 pArgs->cbDst -= cbToWrite; 449 pArgs->pbDst += cbToWrite; 450 return VINF_SUCCESS; 451 } 452 453 /* 454 * Overflow. 455 */ 456 if (pArgs->cbDst) 457 { 458 memcpy(pArgs->pbDst, pvBuf, pArgs->cbDst); 459 pArgs->pbDst -= pArgs->cbDst; 460 pArgs->cbDst = 0; 461 } 462 return VERR_BUFFER_OVERFLOW; 463 } 464 465 466 RTDECL(int) RTAsn1EncodeToBuffer(PCRTASN1CORE pRoot, uint32_t fFlags, void *pvBuf, size_t cbBuf, PRTERRINFO pErrInfo) 467 { 468 RTASN1ENCODETOBUFARGS Args; 469 Args.pbDst = (uint8_t *)pvBuf; 470 Args.cbDst = cbBuf; 471 return RTAsn1EncodeWrite(pRoot, fFlags, rtAsn1EncodeToBufferCallback, &Args, pErrInfo); 472 } 473 -
trunk/src/VBox/Runtime/common/asn1/asn1-ut-bitstring.cpp
r57358 r59663 272 272 * First the header. 273 273 */ 274 int rc = RTAsn EncodeWriteHeader(&pThis->Asn1Core, fFlags, pfnWriter, pvUser, pErrInfo);274 int rc = RTAsn1EncodeWriteHeader(&pThis->Asn1Core, fFlags, pfnWriter, pvUser, pErrInfo); 275 275 if (RT_SUCCESS(rc) && rc != VINF_ASN1_NOT_ENCODED) 276 276 { -
trunk/src/VBox/Runtime/common/asn1/asn1-ut-octetstring.cpp
r57358 r59663 210 210 * First the header. 211 211 */ 212 int rc = RTAsn EncodeWriteHeader(&pThis->Asn1Core, fFlags, pfnWriter, pvUser, pErrInfo);212 int rc = RTAsn1EncodeWriteHeader(&pThis->Asn1Core, fFlags, pfnWriter, pvUser, pErrInfo); 213 213 if (RT_SUCCESS(rc) && rc != VINF_ASN1_NOT_ENCODED) 214 214 { -
trunk/src/VBox/Runtime/common/crypto/x509-verify.cpp
r57358 r59663 34 34 35 35 #include <iprt/err.h> 36 #include <iprt/mem.h> 36 37 #include <iprt/string.h> 37 38 … … 76 77 /* 77 78 * Here we should recode the to-be-signed part as DER, but we'll ASSUME 78 * that it's already in DER encoding. This is safe. 79 * that it's already in DER encoding and only does this if there the 80 * encoded bits are missing. 79 81 */ 80 return RTCrPkixPubKeyVerifySignature(&pThis->SignatureAlgorithm.Algorithm, pParameters, pPublicKey, &pThis->SignatureValue, 81 RTASN1CORE_GET_RAW_ASN1_PTR(&pThis->TbsCertificate.SeqCore.Asn1Core), 82 RTASN1CORE_GET_RAW_ASN1_SIZE(&pThis->TbsCertificate.SeqCore.Asn1Core), 83 pErrInfo); 82 if ( pThis->TbsCertificate.SeqCore.Asn1Core.uData.pu8 83 && pThis->TbsCertificate.SeqCore.Asn1Core.cb > 0) 84 return RTCrPkixPubKeyVerifySignature(&pThis->SignatureAlgorithm.Algorithm, pParameters, pPublicKey, &pThis->SignatureValue, 85 RTASN1CORE_GET_RAW_ASN1_PTR(&pThis->TbsCertificate.SeqCore.Asn1Core), 86 RTASN1CORE_GET_RAW_ASN1_SIZE(&pThis->TbsCertificate.SeqCore.Asn1Core), 87 pErrInfo); 88 89 uint32_t cbEncoded; 90 int rc = RTAsn1EncodePrepare((PRTASN1CORE)&pThis->TbsCertificate.SeqCore.Asn1Core, RTASN1ENCODE_F_DER, &cbEncoded, pErrInfo); 91 if (RT_SUCCESS(rc)) 92 { 93 void *pvTbsBits = RTMemTmpAlloc(cbEncoded); 94 if (pvTbsBits) 95 { 96 rc = RTAsn1EncodeToBuffer(&pThis->TbsCertificate.SeqCore.Asn1Core, RTASN1ENCODE_F_DER, 97 pvTbsBits, cbEncoded, pErrInfo); 98 if (RT_SUCCESS(rc)) 99 rc = RTCrPkixPubKeyVerifySignature(&pThis->SignatureAlgorithm.Algorithm, pParameters, pPublicKey, 100 &pThis->SignatureValue, pvTbsBits, cbEncoded, pErrInfo); 101 else 102 AssertRC(rc); 103 RTMemTmpFree(pvTbsBits); 104 } 105 else 106 rc = VERR_NO_TMP_MEMORY; 107 } 108 return rc; 84 109 } 85 110 111 112 RTDECL(int) RTCrX509Certificate_VerifySignatureSelfSigned(PCRTCRX509CERTIFICATE pThis, PRTERRINFO pErrInfo) 113 { 114 /* 115 * Validate the input a little. 116 */ 117 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 118 AssertReturn(RTCrX509Certificate_IsPresent(pThis), VERR_INVALID_PARAMETER); 119 120 /* 121 * Assemble parameters for the generic verification call. 122 */ 123 PCRTCRX509TBSCERTIFICATE const pTbsCert = &pThis->TbsCertificate; 124 PCRTASN1DYNTYPE pParameters = NULL; 125 if ( RTASN1CORE_IS_PRESENT(&pTbsCert->SubjectPublicKeyInfo.Algorithm.Parameters.u.Core) 126 && pTbsCert->SubjectPublicKeyInfo.Algorithm.Parameters.enmType != RTASN1TYPE_NULL) 127 pParameters = &pTbsCert->SubjectPublicKeyInfo.Algorithm.Parameters; 128 return RTCrX509Certificate_VerifySignature(pThis, &pTbsCert->SubjectPublicKeyInfo.Algorithm.Algorithm, pParameters, 129 &pTbsCert->SubjectPublicKeyInfo.SubjectPublicKey, pErrInfo); 130 } 131
Note:
See TracChangeset
for help on using the changeset viewer.