Changeset 57584 in vbox for trunk/src/VBox
- Timestamp:
- Aug 29, 2015 8:02:02 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 102412
- Location:
- trunk/src/VBox/Runtime/common/crypto
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/crypto/RTCrStoreCertAddFromFile.cpp
r57572 r57584 34 34 #include <iprt/assert.h> 35 35 #include <iprt/err.h> 36 #include <iprt/file.h> 36 37 #include <iprt/crypto/pem.h> 37 38 … … 102 103 AssertReturn(!(fFlags & ~(RTCRCERTCTX_F_ADD_IF_NOT_FOUND | RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR)), VERR_INVALID_FLAGS); 103 104 104 PCRTCRPEMSECTION pSectionHead; 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); 105 size_t cbContent; 106 void *pvContent; 107 int rc = RTFileReadAllEx(pszFilename, 0, 64U*_1M, RTFILE_RDALL_O_DENY_WRITE, &pvContent, &cbContent); 108 108 if (RT_SUCCESS(rc)) 109 109 { 110 PCRTCRPEMSECTION pCurSec = pSectionHead; 111 while (pCurSec) 110 /* 111 * Is it a java key store file? 112 */ 113 if ( cbContent > 32 114 && ((uint32_t const *)pvContent)[0] == RT_H2BE_U32_C(UINT32_C(0xfeedfeed)) /* magic */ 115 && ((uint32_t const *)pvContent)[1] == RT_H2BE_U32_C(UINT32_C(0x00000002)) /* version */ ) 116 rc = RTCrStoreCertAddFromJavaKeyStoreInMem(hStore, fFlags, pvContent, cbContent, pszFilename, pErrInfo); 117 /* 118 * No assume PEM or DER encoded binary certificate. 119 */ 120 else 112 121 { 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); 115 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 122 PCRTCRPEMSECTION pSectionHead; 123 rc = RTCrPemParseContent(pvContent, cbContent, fFlags, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), 124 &pSectionHead, pErrInfo); 125 if (RT_SUCCESS(rc)) 116 126 { 117 rc = rc2; 118 if (!(fFlags & RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR)) 119 break; 127 PCRTCRPEMSECTION pCurSec = pSectionHead; 128 while (pCurSec) 129 { 130 int rc2 = RTCrStoreCertAddEncoded(hStore, 131 RTCRCERTCTX_F_ENC_X509_DER | (fFlags & RTCRCERTCTX_F_ADD_IF_NOT_FOUND), 132 pCurSec->pbData, pCurSec->cbData, 133 !RTErrInfoIsSet(pErrInfo) ? pErrInfo : NULL); 134 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 135 { 136 rc = rc2; 137 if (!(fFlags & RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR)) 138 break; 139 } 140 pCurSec = pCurSec->pNext; 141 } 142 143 RTCrPemFreeSections(pSectionHead); 120 144 } 121 pCurSec = pCurSec->pNext;122 145 } 123 124 RTCrPemFreeSections(pSectionHead); 146 RTFileReadAllFree(pvContent, cbContent); 125 147 } 148 else 149 rc = RTErrInfoSetF(pErrInfo, rc, "RTFileReadAllEx failed with %Rrc on '%s'", rc, pszFilename); 126 150 return rc; 127 151 }
Note:
See TracChangeset
for help on using the changeset viewer.