Changeset 57584 in vbox
- Timestamp:
- Aug 29, 2015 8:02:02 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
-
include/iprt/crypto/store.h (modified) (2 diffs)
-
include/iprt/log.h (modified) (2 diffs)
-
include/iprt/mangling.h (modified) (1 diff)
-
src/VBox/Runtime/common/crypto/RTCrStoreCertAddFromFile.cpp (modified) (2 diffs)
-
src/VBox/Runtime/common/crypto/RTCrStoreCertAddFromJavaKeyStore.cpp (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/crypto/store.h
r57572 r57584 144 144 145 145 /** 146 * Adds certificates from the specified file.147 *148 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is149 * used, an error is returned as an error (and not a warning).150 *151 * @param hStore The store to add the certificate(s) to.152 * @param fFlags RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or153 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR.154 * @param pszFilename The filename.155 * @param pErrInfo Where to return additional error/warning info.156 * Optional.157 */158 RTDECL(int) RTCrStoreCertAddFromFile(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo);159 160 /**161 146 * Adds certificates from files in the specified directory. 162 147 * … … 176 161 RTDECL(int) RTCrStoreCertAddFromDir(RTCRSTORE hStore, uint32_t fFlags, const char *pszDir, 177 162 PCRTSTRTUPLE paSuffixes, size_t cSuffixes, PRTERRINFO pErrInfo); 163 164 /** 165 * Adds certificates from the specified file. 166 * 167 * The supported file formats are: 168 * - PEM (base 64 blobs wrapped in -----BEGIN / END----). Support multiple 169 * certificates in one file. 170 * - Binary DER ASN.1 certificate. Only one per file. 171 * - Java key store version 2. 172 * 173 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is 174 * used, an error is returned as an error (and not a warning). 175 * 176 * @param hStore The store to add the certificate(s) to. 177 * @param fFlags RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or 178 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR. 179 * @param pszFilename The filename. 180 * @param pErrInfo Where to return additional error/warning info. 181 * Optional. 182 */ 183 RTDECL(int) RTCrStoreCertAddFromFile(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo); 184 185 /** 186 * Adds certificates from the specified java key store file. 187 * 188 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is 189 * used, an error is returned as an error (and not a warning). 190 * 191 * @param hStore The store to add the certificate(s) to. 192 * @param fFlags RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or 193 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR. 194 * @param pszFilename The path to the JKS file. 195 * @param pErrInfo Where to return additional error/warning info. 196 * Optional. 197 */ 198 RTDECL(int) RTCrStoreCertAddFromJavaKeyStore(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo); 199 200 /** 201 * Adds certificates from an in-memory java key store. 202 * 203 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is 204 * used, an error is returned as an error (and not a warning). 205 * 206 * @param hStore The store to add the certificate(s) to. 207 * @param fFlags RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or 208 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR. 209 * @param pvContent Pointer to the key store bytes. 210 * @param cbContent The size of the key store. 211 * @param pszErrorName The file name or whatever helpful indicator the 212 * caller want in the error messages. 213 * @param pErrInfo Where to return additional error/warning info. 214 * Optional. 215 */ 216 RTDECL(int) RTCrStoreCertAddFromJavaKeyStoreInMem(RTCRSTORE hStore, uint32_t fFlags, void const *pvContent, size_t cbContent, 217 const char *pszErrorName, PRTERRINFO pErrInfo); 178 218 179 219 /** -
trunk/include/iprt/log.h
r57004 r57584 65 65 RTLOGGROUP_TIME, 66 66 RTLOGGROUP_TIMER, 67 RTLOGGROUP_CRYPTO, 67 68 RTLOGGROUP_ZIP = 31, 68 69 RTLOGGROUP_FIRST_USER = 32 … … 96 97 "RT_TIME", \ 97 98 "RT_TIMER", \ 98 "RT_ 13",\99 "RT_CRYPTO", \ 99 100 "RT_14", \ 100 101 "RT_15", \ -
trunk/include/iprt/mangling.h
r57577 r57584 2902 2902 # define RTCrStoreCreateInMem RT_MANGLER(RTCrStoreCreateInMem) 2903 2903 # define RTCrStoreCreateSnapshotById RT_MANGLER(RTCrStoreCreateSnapshotById) 2904 # define RTCrStoreCertAddFromDir RT_MANGLER(RTCrStoreCertAddFromDir) 2904 2905 # define RTCrStoreCertAddFromFile RT_MANGLER(RTCrStoreCertAddFromFile) 2905 # define RTCrStoreCertAddFromDir RT_MANGLER(RTCrStoreCertAddFromDir) 2906 # define RTCrStoreCertAddFromJavaKeyStore RT_MANGLER(RTCrStoreCertAddFromJavaKeyStore) 2907 # define RTCrStoreCertAddFromJavaKeyStoreInMem RT_MANGLER(RTCrStoreCertAddFromJavaKeyStoreInMem) 2906 2908 # define RTCrStoreCertAddFromStore RT_MANGLER(RTCrStoreCertAddFromStore) 2907 2909 # define RTCrStoreCertExportAsPem RT_MANGLER(RTCrStoreCertExportAsPem) -
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.

