Changeset 84310 in vbox for trunk/src/VBox/Runtime/common/crypto/iprt-openssl.cpp
- Timestamp:
- May 14, 2020 5:40:35 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/crypto/iprt-openssl.cpp
r84248 r84310 70 70 { 71 71 const unsigned char *pabEncoded; 72 73 /* 74 * ASSUME that if the certificate has data pointers, it's been parsed out 75 * of a binary blob and we can safely access that here. 76 */ 77 if (pCert->SeqCore.Asn1Core.uData.pv) 72 uint32_t cbEncoded; 73 void *pvFree; 74 int rc = RTAsn1EncodeQueryRawBits(RTCrX509Certificate_GetAsn1Core(pCert), 75 (const uint8_t **)&pabEncoded, &cbEncoded, &pvFree, pErrInfo); 76 if (RT_SUCCESS(rc)) 78 77 { 79 pabEncoded = (const unsigned char *)RTASN1CORE_GET_RAW_ASN1_PTR(&pCert->SeqCore.Asn1Core);80 uint32_t cbEncoded = RTASN1CORE_GET_RAW_ASN1_SIZE(&pCert->SeqCore.Asn1Core);81 X509 *pOsslCert = NULL;82 if ( d2i_X509(&pOsslCert, &pabEncoded, cbEncoded)== pOsslCert)78 X509 *pOsslCert = NULL; 79 X509 *pOsslCertRet = d2i_X509(&pOsslCert, &pabEncoded, cbEncoded); 80 RTMemTmpFree(pvFree); 81 if (pOsslCertRet == pOsslCert) 83 82 { 84 83 *ppvOsslCert = pOsslCert; 85 84 return VINF_SUCCESS; 86 85 } 86 rc = RTErrInfoSet(pErrInfo, VERR_CR_X509_OSSL_D2I_FAILED, "d2i_X509"); 87 87 88 } 88 /*89 * Otherwise, we'll have to encode it into a temporary buffer that openssl90 * can decode into its structures.91 */92 else93 {94 PRTASN1CORE pNonConstCore = (PRTASN1CORE)&pCert->SeqCore.Asn1Core;95 uint32_t cbEncoded = 0;96 int rc = RTAsn1EncodePrepare(pNonConstCore, RTASN1ENCODE_F_DER, &cbEncoded, pErrInfo);97 AssertRCReturn(rc, rc);98 99 void * const pvEncoded = RTMemTmpAllocZ(cbEncoded);100 AssertReturn(pvEncoded, VERR_NO_TMP_MEMORY);101 102 rc = RTAsn1EncodeToBuffer(pNonConstCore, RTASN1ENCODE_F_DER, pvEncoded, cbEncoded, pErrInfo);103 if (RT_SUCCESS(rc))104 {105 pabEncoded = (const unsigned char *)pvEncoded;106 X509 *pOsslCert = NULL;107 if (d2i_X509(&pOsslCert, &pabEncoded, cbEncoded) == pOsslCert)108 {109 *ppvOsslCert = pOsslCert;110 RTMemTmpFree(pvEncoded);111 return VINF_SUCCESS;112 }113 }114 else115 {116 RTMemTmpFree(pvEncoded);117 return rc;118 }119 }120 121 89 *ppvOsslCert = NULL; 122 return RTErrInfoSet(pErrInfo, VERR_CR_X509_OSSL_D2I_FAILED, "d2i_X509");90 return rc; 123 91 } 124 92
Note:
See TracChangeset
for help on using the changeset viewer.