RTDECL(int) RTCrX509Certificate_ReadFromFile(PRTCRX509CERTIFICATE pCertificate, const char *pszFilename, uint32_t fFlags, PCRTASN1ALLOCATORVTABLE pAllocator, PRTERRINFO pErrInfo) { AssertReturn(!fFlags, VERR_INVALID_FLAGS); PCRTCRPEMSECTION pSectionHead; int rc = RTCrPemReadFile(pszFilename, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), &pSectionHead, pErrInfo); if (RT_SUCCESS(rc)) { RTCRX509CERTIFICATE TmpCert; RTASN1CURSORPRIMARY PrimaryCursor; RTAsn1CursorInitPrimary(&PrimaryCursor, pSectionHead->pbData, (uint32_t)RT_MIN(pSectionHead->cbData, UINT32_MAX), pErrInfo, pAllocator, RTASN1CURSOR_FLAGS_DER, RTPathFilename(pszFilename)); rc = RTCrX509Certificate_DecodeAsn1(&PrimaryCursor.Cursor, 0, &TmpCert, "Cert"); if (RT_SUCCESS(rc)) { rc = RTCrX509Certificate_CheckSanity(&TmpCert, 0, pErrInfo, "Cert"); if (RT_SUCCESS(rc)) { rc = RTCrX509Certificate_Clone(pCertificate, &TmpCert, &g_RTAsn1DefaultAllocator); if (RT_SUCCESS(rc)) { if (pSectionHead->pNext || PrimaryCursor.Cursor.cbLeft) rc = VINF_ASN1_MORE_DATA; } } RTCrX509Certificate_Delete(&TmpCert); } RTCrPemFreeSections(pSectionHead); } return rc; }
RTDECL(int) RTCrStoreCertAddFromFile(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo) { AssertReturn(!fFlags, VERR_INVALID_FLAGS); #if 0 RTCRX509CERTIFICATES Certs; int rc = RTCrX509Certificates_ReadFromFile(pszFilename, 0, &Certs, pErrInfo); if (RT_SUCCESS(rc)) { for (uint32_t i = 0; i < Certs.cCerts; i++) { int rc2 = RTCrStoreCertAddEncoded(hStore, RTCRCERTCTX_F_ENC_X509_DER, RTASN1CORE_GET_RAW_ASN1_PTR(&Certs.paCerts[i].SeqCore.Asn1Core), RTASN1CORE_GET_RAW_ASN1_SIZE(&Certs.paCerts[i].SeqCore.Asn1Core), RT_SUCCESS(rc) ? pErrInfo : NULL); if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) rc = rc2; } RTAsn1Destroy(&Certs.SetCore.Asn1Core); } return rc; #else PCRTCRPEMSECTION pSectionHead; int rc = RTCrPemReadFile(pszFilename, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), &pSectionHead, pErrInfo); if (RT_SUCCESS(rc)) { PCRTCRPEMSECTION pCurSec = pSectionHead; while (pCurSec) { int rc2 = RTCrStoreCertAddEncoded(hStore, RTCRCERTCTX_F_ENC_X509_DER, pCurSec->pbData, pCurSec->cbData, RT_SUCCESS(rc) ? pErrInfo : NULL); if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) rc = rc2; pCurSec = pCurSec->pNext; } RTCrPemFreeSections(pSectionHead); } return rc; #endif }
RTDECL(int) RTCrX509Certificates_ReadFromFile(const char *pszFilename, uint32_t fFlags, PRTCRX509CERTIFICATES pCertificates, PRTERRINFO pErrInfo) { AssertReturn(!fFlags, VERR_INVALID_FLAGS); PCRTCRPEMSECTION pSectionHead; int rc = RTCrPemReadFile(pszFilename, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), &pSectionHead, pErrInfo); if (RT_SUCCESS(rc)) { pCertificates->Allocation PCRTCRPEMSECTION pCurSec = pSectionHead; while (pCurSec) { pCurSec = pCurSec->pNext; } RTCrPemFreeSections(pSectionHead); } return rc; }