Changeset 57572 in vbox
- Timestamp:
- Aug 28, 2015 1:31:29 AM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 102396
- Location:
- trunk
- Files:
-
- 6 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cdefs.h
r57433 r57572 1452 1452 * 1453 1453 * @param a_szConst String constant. 1454 * @sa RTSTRTUPLE 1454 1455 */ 1455 1456 #define RT_STR_TUPLE(a_szConst) a_szConst, (sizeof(a_szConst) - 1) -
trunk/include/iprt/crypto/pem.h
r56291 r57572 117 117 * @returns IPRT status code. 118 118 * @param pszFilename The path to the file to read. 119 * @param fFlags Flags reserved for future hacks.119 * @param fFlags RTCRPEMREADFILE_F_XXX. 120 120 * @param paMarkers Array of one or more section markers to look for. 121 121 * @param cMarkers Number of markers in the array. … … 125 125 RTDECL(int) RTCrPemReadFile(const char *pszFilename, uint32_t fFlags, PCRTCRPEMMARKER paMarkers, size_t cMarkers, 126 126 PCRTCRPEMSECTION *ppSectionHead, PRTERRINFO pErrInfo); 127 /** @name RTCRPEMREADFILE_F_XXX - Flags for RTCrPemReadFile 128 * @{ */ 129 /** Continue on encoding error. */ 130 #define RTCRPEMREADFILE_F_CONTINUE_ON_ENCODING_ERROR RT_BIT(0) 131 /** @} */ 127 132 128 133 /** @} */ -
trunk/include/iprt/crypto/store.h
r56291 r57572 58 58 59 59 60 /** 61 * Standard store identifiers. 62 * 63 * This is a least common denominator approach to system specific certificate 64 * stores, could be extended to include things other than certificates later if 65 * we need it. 66 * 67 * Windows has lots of different stores, they'll be combined by the 68 * implementation, possibly leading to duplicates. The user stores on Windows 69 * seems to be unioned with the system (machine) stores. 70 * 71 * Linux may have different stores depending on the distro/version/installation, 72 * in which case we'll combine them, which will most likely lead to 73 * duplicates just like on windows. Haven't found any easily accessible 74 * per-user certificate stores on linux yet, so they'll all be empty. 75 * 76 * Mac OS X seems a lot simpler, at least from the GUI point of view. Each 77 * keychains as a "Certificates" folder (the "My Certificates" folder seems to 78 * only be a matching of "Keys" and "Certificates"). However, there are two 79 * system keychains that we need to combine, "System" and "System Roots". As 80 * with Windows and Linux, there is a possibility for duplicates here. 81 * 82 * On solaris we have currently no idea where to look for a certificate store, 83 * so that doesn't yet work. 84 * 85 * Because of the OS X setup, we do not provide any purpose specific 86 */ 87 typedef enum RTCRSTOREID 88 { 89 /** Mandatory invalid zero value. */ 90 RTCRSTOREID_INVALID = 0, 91 /** Open the certificate store of the current user containing trusted 92 * CAs and certificates. 93 * @remarks This may or may not include all the certificates in the system 94 * store, that's host dependent. So, you better look in both. */ 95 RTCRSTOREID_USER_TRUSTED_CAS_AND_CERTIFICATES, 96 /** Open the certificate store of the system containg trusted CAs 97 * and certificates. */ 98 RTCRSTOREID_SYSTEM_TRUSTED_CAS_AND_CERTIFICATES, 99 /** End of valid values. */ 100 RTCRSTOREID_END, 101 /** Traditional enum type compression prevention hack. */ 102 RTCRSTOREID_32BIT_HACK = 0x7fffffff 103 } RTCRSTOREID; 104 105 /** 106 * Creates a snapshot of a standard store. 107 * 108 * This will return an in-memory store containing all data from the given store. 109 * There will be no duplicates in this one. 110 * 111 * @returns IPRT status code. 112 * @retval VWRN_ALREADY_EXISTS if the certificate is already present and 113 * RTCRCERTCTX_F_ADD_IF_NOT_FOUND was specified. 114 * @param phStore Where to return the store handle. Use 115 * RTCrStoreRelease to release it. 116 * @param enmStoreId The store to snapshot. 117 * @param pErrInfo Where to return additional error/warning info. 118 * Optional. 119 */ 120 RTDECL(int) RTCrStoreCreateSnapshotById(PRTCRSTORE phStore, RTCRSTOREID enmStoreId, PRTERRINFO pErrInfo); 121 60 122 RTDECL(int) RTCrStoreCreateInMem(PRTCRSTORE phStore, uint32_t cSizeHint); 61 123 … … 63 125 RTDECL(uint32_t) RTCrStoreRelease(RTCRSTORE hStore); 64 126 RTDECL(PCRTCRCERTCTX) RTCrStoreCertByIssuerAndSerialNo(RTCRSTORE hStore, PCRTCRX509NAME pIssuer, PCRTASN1INTEGER pSerialNo); 127 128 /** 129 * Add a certificate to the store. 130 * 131 * @returns IPRT status code. 132 * @retval VWRN_ALREADY_EXISTS if the certificate is already present and 133 * RTCRCERTCTX_F_ADD_IF_NOT_FOUND was specified. 134 * @retval VERR_WRITE_PROTECT if the store doesn't support adding. 135 * @param hStore The store to add the certificate to. 136 * @param fFlags RTCRCERTCTX_F_XXX. Encoding must be specified. 137 * RTCRCERTCTX_F_ADD_IF_NOT_FOUND is supported. 138 * @param pvSrc The encoded certificate bytes. 139 * @param cbSrc The size of the encoded certificate. 140 * @param pErrInfo Where to return additional error/warning info. 141 * Optional. 142 */ 65 143 RTDECL(int) RTCrStoreCertAddEncoded(RTCRSTORE hStore, uint32_t fFlags, void const *pvSrc, size_t cbSrc, PRTERRINFO pErrInfo); 144 145 /** 146 * Adds certificates from the specified file. 147 * 148 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is 149 * 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/or 153 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR. 154 * @param pszFilename The filename. 155 * @param pErrInfo Where to return additional error/warning info. 156 * Optional. 157 */ 66 158 RTDECL(int) RTCrStoreCertAddFromFile(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo); 159 160 /** 161 * Adds certificates from files in the specified directory. 162 * 163 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is 164 * used, an error is returned as an error (and not a warning). 165 * 166 * @param hStore The store to add the certificate(s) to. 167 * @param fFlags RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or 168 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR. 169 * @param pszDir The path to the directory. 170 * @param paSuffixes List of suffixes of files to process. 171 * @param cSuffixes Number of suffixes. If this is 0, all files are 172 * processed. 173 * @param pErrInfo Where to return additional error/warning info. 174 * Optional. 175 */ 176 RTDECL(int) RTCrStoreCertAddFromDir(RTCRSTORE hStore, uint32_t fFlags, const char *pszDir, 177 PCRTSTRTUPLE paSuffixes, size_t cSuffixes, PRTERRINFO pErrInfo); 178 179 /** 180 * Adds all certificates from @a hStoreSrc into @a hStore. 181 * 182 * @returns IPRT status code. Even when RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR is 183 * used, an error is returned as an error (and not a warning). 184 * 185 * @param hStore The destination store. 186 * @param fFlags RTCRCERTCTX_F_ADD_IF_NOT_FOUND and/or 187 * RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR. 188 * @param hStoreSrc The source store. 189 */ 190 RTDECL(int) RTCrStoreCertAddFromStore(RTCRSTORE hStore, uint32_t fFlags, RTCRSTORE hStoreSrc); 191 192 /** 193 * Exports the certificates in the store to a PEM file 194 * 195 * @returns IPRT status code. 196 * @param hStore The store which certificates should be exported. 197 * @param fFlags Reserved for the future, MBZ. 198 * @param pszFilename The name of the destination PEM file. This will 199 * be truncated. 200 */ 201 RTDECL(int) RTCrStoreCertExportAsPem(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename); 67 202 68 203 RTDECL(int) RTCrStoreCertFindAll(RTCRSTORE hStore, PRTCRSTORECERTSEARCH pSearch); … … 119 254 #define RTCRCERTCTX_F_ENC_PKCS6_DER UINT32_C(0x00000002) 120 255 #endif 256 /** Mask containing the flags that ends up in the certificate context. */ 257 #define RTCRCERTCTX_F_MASK UINT32_C(0x000000ff) 258 259 /** Add APIs: Add the certificate if not found. */ 260 #define RTCRCERTCTX_F_ADD_IF_NOT_FOUND UINT32_C(0x00010000) 261 /** Add APIs: Continue on error when possible. */ 262 #define RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR UINT32_C(0x00020000) 121 263 /** @} */ 122 264 -
trunk/include/iprt/crypto/x509.h
r56291 r57572 165 165 166 166 /** 167 * Matches the directory name against a comma separated list of the com onent167 * Matches the directory name against a comma separated list of the component 168 168 * strings (case sensitive). 169 169 * -
trunk/include/iprt/mangling.h
r57079 r57572 1050 1050 # define RTPathCopyComponents RT_MANGLER(RTPathCopyComponents) 1051 1051 # define RTPathCountComponents RT_MANGLER(RTPathCountComponents) 1052 # define RTPathEnsureTrailingSeparator RT_MANGLER(RTPathEnsureTrailingSeparator) 1052 1053 # define RTPathExecDir RT_MANGLER(RTPathExecDir) 1053 1054 # define RTPathExists RT_MANGLER(RTPathExists) … … 1344 1345 # define RTSgBufGetNextSegment RT_MANGLER(RTSgBufGetNextSegment) 1345 1346 # define RTSha1 RT_MANGLER(RTSha1) 1347 # define RTSha1Check RT_MANGLER(RTSha1Check) 1346 1348 # define RTSha1Digest RT_MANGLER(RTSha1Digest) 1347 1349 # define RTSha1DigestFromFile RT_MANGLER(RTSha1DigestFromFile) … … 1352 1354 # define RTSha1Update RT_MANGLER(RTSha1Update) 1353 1355 # define RTSha224 RT_MANGLER(RTSha224) 1356 # define RTSha224Check RT_MANGLER(RTSha224Check) 1354 1357 # define RTSha224Final RT_MANGLER(RTSha224Final) 1355 1358 # define RTSha224FromString RT_MANGLER(RTSha224FromString) … … 1360 1363 # define RTSha224DigestFromFile RT_MANGLER(RTSha224DigestFromFile) 1361 1364 # define RTSha256 RT_MANGLER(RTSha256) 1365 # define RTSha256Check RT_MANGLER(RTSha256Check) 1362 1366 # define RTSha256Final RT_MANGLER(RTSha256Final) 1363 1367 # define RTSha256FromString RT_MANGLER(RTSha256FromString) … … 1368 1372 # define RTSha256DigestFromFile RT_MANGLER(RTSha256DigestFromFile) 1369 1373 # define RTSha384 RT_MANGLER(RTSha384) 1374 # define RTSha384Check RT_MANGLER(RTSha384Check) 1370 1375 # define RTSha384Final RT_MANGLER(RTSha384Final) 1371 1376 # define RTSha384FromString RT_MANGLER(RTSha384FromString) … … 1374 1379 # define RTSha384Update RT_MANGLER(RTSha384Update) 1375 1380 # define RTSha512 RT_MANGLER(RTSha512) 1381 # define RTSha512Check RT_MANGLER(RTSha512Check) 1376 1382 # define RTSha512Final RT_MANGLER(RTSha512Final) 1377 1383 # define RTSha512FromString RT_MANGLER(RTSha512FromString) … … 1380 1386 # define RTSha512Update RT_MANGLER(RTSha512Update) 1381 1387 # define RTSha512t224 RT_MANGLER(RTSha512t224) 1388 # define RTSha512t224Check RT_MANGLER(RTSha512t224Check) 1382 1389 # define RTSha512t224Final RT_MANGLER(RTSha512t224Final) 1383 1390 # define RTSha512t224FromString RT_MANGLER(RTSha512t224FromString) … … 1386 1393 # define RTSha512t224Update RT_MANGLER(RTSha512t224Update) 1387 1394 # define RTSha512t256 RT_MANGLER(RTSha512t256) 1395 # define RTSha512t256Check RT_MANGLER(RTSha512t256Check) 1388 1396 # define RTSha512t256Final RT_MANGLER(RTSha512t256Final) 1389 1397 # define RTSha512t256FromString RT_MANGLER(RTSha512t256FromString) … … 2892 2900 # define RTCrStoreRetain RT_MANGLER(RTCrStoreRetain) 2893 2901 # define RTCrStoreCreateInMem RT_MANGLER(RTCrStoreCreateInMem) 2902 # define RTCrStoreCreateSnapshotById RT_MANGLER(RTCrStoreCreateSnapshotById) 2894 2903 # define RTCrStoreCertAddFromFile RT_MANGLER(RTCrStoreCertAddFromFile) 2904 # define RTCrStoreCertAddFromDir RT_MANGLER(RTCrStoreCertAddFromDir) 2905 # define RTCrStoreCertAddFromStore RT_MANGLER(RTCrStoreCertAddFromStore) 2906 # define RTCrStoreCertExportAsPem RT_MANGLER(RTCrStoreCertExportAsPem) 2895 2907 # define RTErrInfoAdd RT_MANGLER(RTErrInfoAdd) 2896 2908 # define RTErrInfoAddF RT_MANGLER(RTErrInfoAddF) -
trunk/include/iprt/path.h
r56291 r57572 357 357 */ 358 358 RTDECL(size_t) RTPathStripTrailingSlash(char *pszPath); 359 360 /** 361 * Ensures that the path has a trailing path separator such that file names can 362 * be appended without further work. 363 * 364 * This can be helpful when preparing for efficiently combining a directory path 365 * with the filenames returned by RTDirRead. The return value gives you the 366 * position at which you copy the RTDIRENTRY::szName to construct a valid path 367 * to it. 368 * 369 * @returns The length of the path, 0 on buffer overflow. 370 * @param pszPath The path. 371 * @param cbPath The length of the path buffer @a pszPath points to. 372 */ 373 RTDECL(size_t) RTPathEnsureTrailingSeparator(char *pszPath, size_t cbPath); 359 374 360 375 /** -
trunk/include/iprt/sha.h
r56291 r57572 69 69 70 70 /** 71 * Computes the SHA-1 hash for the given data comparing it with the one given. 72 * 73 * @returns true on match, false on mismatch. 74 * @param pvBuf Pointer to the data. 75 * @param cbBuf The amount of data (in bytes). 76 * @param pabHash The hash to verify. (What is passed is a pointer to the 77 * caller's buffer.) 78 */ 79 RTDECL(bool) RTSha1Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA1_HASH_SIZE]); 80 81 /** 71 82 * Initializes the SHA-1 context. 72 83 * … … 177 188 178 189 /** 190 * Computes the SHA-256 hash for the given data comparing it with the one given. 191 * 192 * @returns true on match, false on mismatch. 193 * @param pvBuf Pointer to the data. 194 * @param cbBuf The amount of data (in bytes). 195 * @param pabHash The hash to verify. (What is passed is a pointer to the 196 * caller's buffer.) 197 */ 198 RTDECL(bool) RTSha256Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA256_HASH_SIZE]); 199 200 /** 179 201 * Initializes the SHA-256 context. 180 202 * … … 275 297 276 298 /** 299 * Computes the SHA-224 hash for the given data comparing it with the one given. 300 * 301 * @returns true on match, false on mismatch. 302 * @param pvBuf Pointer to the data. 303 * @param cbBuf The amount of data (in bytes). 304 * @param pabHash The hash to verify. (What is passed is a pointer to the 305 * caller's buffer.) 306 */ 307 RTDECL(bool) RTSha224Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA224_HASH_SIZE]); 308 309 /** 277 310 * Initializes the SHA-224 context. 278 311 * … … 383 416 384 417 /** 418 * Computes the SHA-512 hash for the given data comparing it with the one given. 419 * 420 * @returns true on match, false on mismatch. 421 * @param pvBuf Pointer to the data. 422 * @param cbBuf The amount of data (in bytes). 423 * @param pabHash The hash to verify. (What is passed is a pointer to the 424 * caller's buffer.) 425 */ 426 RTDECL(bool) RTSha512Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA512_HASH_SIZE]); 427 428 /** 385 429 * Initializes the SHA-512 context. 386 430 * … … 438 482 typedef RTSHA512CONTEXT *RT_CONCAT3(PRTSHA,a_UName,CONTEXT); \ 439 483 RTDECL(void) RT_CONCAT(RTSha,a_Name)(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RT_CONCAT3(RTSHA,a_UName,_HASH_SIZE)]); \ 484 RTDECL(bool) RT_CONCAT3(RTSha,a_Name,Check)(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RT_CONCAT3(RTSHA,a_UName,_HASH_SIZE)]); \ 440 485 RTDECL(void) RT_CONCAT3(RTSha,a_Name,Init)(RT_CONCAT3(PRTSHA,a_UName,CONTEXT) pCtx); \ 441 486 RTDECL(void) RT_CONCAT3(RTSha,a_Name,Update)(RT_CONCAT3(PRTSHA,a_UName,CONTEXT) pCtx, const void *pvBuf, size_t cbBuf); \ -
trunk/include/iprt/types.h
r57004 r57572 2176 2176 2177 2177 /** 2178 * String tuple to go with the RT_STR_TUPLE macro. 2179 */ 2180 typedef struct RTSTRTUPLE 2181 { 2182 /** The string. */ 2183 const char *psz; 2184 /** The string length. */ 2185 size_t cch; 2186 } RTSTRTUPLE; 2187 /** Pointer to a string tuple. */ 2188 typedef RTSTRTUPLE *PRTSTRTUPLE; 2189 /** Pointer to a const string tuple. */ 2190 typedef RTSTRTUPLE const *PCRTSTRTUPLE; 2191 2192 /** 2178 2193 * Wait for ever if we have to. 2179 2194 */ -
trunk/src/VBox/Runtime/Makefile.kmk
r57078 r57572 369 369 common/crypto/store-inmem.cpp \ 370 370 common/crypto/RTCrStoreCertAddFromFile.cpp \ 371 common/crypto/RTCrStoreCertAddFromDir.cpp \ 372 common/crypto/RTCrStoreCertAddFromStore.cpp \ 373 common/crypto/RTCrStoreCertExportAsPem.cpp \ 371 374 common/dbg/dbg.cpp \ 372 375 common/dbg/dbgas.cpp \ … … 458 461 common/path/RTPathCopyComponents.cpp \ 459 462 common/path/RTPathCountComponents.cpp \ 463 common/path/RTPathEnsureTrailingSeparator.cpp \ 460 464 common/path/RTPathExt.cpp \ 461 465 common/path/RTPathFilename.cpp \ … … 735 739 r3/nt/RTProcQueryParent-r3-nt.cpp \ 736 740 r3/win/env-win.cpp \ 741 r3/win/RTCrStoreCreateSnapshotById-win.cpp \ 737 742 r3/win/RTHandleGetStandard-win.cpp \ 738 743 r3/win/RTSystemQueryOSInfo-win.cpp \ … … 779 784 RuntimeR3_SOURCES.linux = \ 780 785 generic/cdrom-generic.cpp \ 786 generic/RTCrStoreCreateSnapshotById-generic.cpp \ 781 787 generic/RTDirQueryInfo-generic.cpp \ 782 788 generic/RTDirSetTimes-generic.cpp \ … … 865 871 RuntimeR3_SOURCES.os2 = \ 866 872 generic/cdrom-generic.cpp \ 873 generic/RTCrStoreCreateSnapshotById-generic.cpp \ 867 874 generic/RTDirQueryInfo-generic.cpp \ 868 875 generic/RTDirSetTimes-generic.cpp \ … … 939 946 darwin/RTErrConvertFromDarwinKern.cpp \ 940 947 generic/cdrom-generic.cpp \ 948 generic/RTCrStoreCreateSnapshotById-generic.cpp \ 941 949 generic/RTDirQueryInfo-generic.cpp \ 942 950 generic/RTDirSetTimes-generic.cpp \ … … 1008 1016 RuntimeR3_SOURCES.freebsd = \ 1009 1017 generic/cdrom-generic.cpp \ 1018 generic/RTCrStoreCreateSnapshotById-generic.cpp \ 1010 1019 generic/RTDirQueryInfo-generic.cpp \ 1011 1020 generic/RTDirSetTimes-generic.cpp \ … … 1079 1088 RuntimeR3_SOURCES.solaris = \ 1080 1089 generic/cdrom-generic.cpp \ 1090 generic/RTCrStoreCreateSnapshotById-generic.cpp \ 1081 1091 generic/RTDirQueryInfo-generic.cpp \ 1082 1092 generic/RTDirSetTimes-generic.cpp \ … … 1153 1163 1154 1164 RuntimeR3_SOURCES.haiku = \ 1165 generic/RTCrStoreCreateSnapshotById-generic.cpp \ 1155 1166 generic/RTDirQueryInfo-generic.cpp \ 1156 1167 generic/RTDirSetTimes-generic.cpp \ -
trunk/src/VBox/Runtime/common/checksum/alt-sha1.cpp
r57358 r57572 442 442 443 443 444 RTDECL(void) RTSha1Final(PRTSHA1CONTEXT pCtx, uint8_t pabDigest[RTSHA1_HASH_SIZE])444 static void rtSha1FinalInternal(PRTSHA1CONTEXT pCtx) 445 445 { 446 446 Assert(pCtx->AltPrivate.cbMessage < UINT64_MAX / 2); … … 481 481 pCtx->AltPrivate.auH[3] = RT_H2BE_U32(pCtx->AltPrivate.auH[3]); 482 482 pCtx->AltPrivate.auH[4] = RT_H2BE_U32(pCtx->AltPrivate.auH[4]); 483 484 memcpy(pabDigest, &pCtx->AltPrivate.auH[0], RTSHA1_HASH_SIZE); 485 483 } 484 485 486 DECLINLINE(void) rtSha1WipeCtx(PRTSHA1CONTEXT pCtx) 487 { 486 488 RT_ZERO(pCtx->AltPrivate); 487 489 pCtx->AltPrivate.cbMessage = UINT64_MAX; 490 } 491 492 493 RTDECL(void) RTSha1Final(PRTSHA1CONTEXT pCtx, uint8_t pabDigest[RTSHA1_HASH_SIZE]) 494 { 495 rtSha1FinalInternal(pCtx); 496 memcpy(pabDigest, &pCtx->AltPrivate.auH[0], RTSHA1_HASH_SIZE); 497 rtSha1WipeCtx(pCtx); 488 498 } 489 499 RT_EXPORT_SYMBOL(RTSha1Final); … … 499 509 RT_EXPORT_SYMBOL(RTSha1); 500 510 511 512 RTDECL(bool) RTSha1Check(const void *pvBuf, size_t cbBuf, uint8_t const pabHash[RTSHA1_HASH_SIZE]) 513 { 514 RTSHA1CONTEXT Ctx; 515 RTSha1Init(&Ctx); 516 RTSha1Update(&Ctx, pvBuf, cbBuf); 517 rtSha1FinalInternal(&Ctx); 518 519 bool fRet = memcmp(pabHash, &Ctx.AltPrivate.auH[0], RTSHA1_HASH_SIZE) == 0; 520 521 rtSha1WipeCtx(&Ctx); 522 return fRet; 523 } 524 RT_EXPORT_SYMBOL(RTSha1Check); 525 -
trunk/src/VBox/Runtime/common/checksum/alt-sha256.cpp
r57358 r57572 607 607 608 608 609 RTDECL(bool) RTSha256Check(const void *pvBuf, size_t cbBuf, uint8_t const pabHash[RTSHA256_HASH_SIZE]) 610 { 611 RTSHA256CONTEXT Ctx; 612 RTSha256Init(&Ctx); 613 RTSha256Update(&Ctx, pvBuf, cbBuf); 614 rtSha256FinalInternal(&Ctx); 615 616 bool fRet = memcmp(pabHash, &Ctx.AltPrivate.auH[0], RTSHA256_HASH_SIZE) == 0; 617 618 RT_ZERO(Ctx.AltPrivate.auH); 619 return fRet; 620 } 621 RT_EXPORT_SYMBOL(RTSha256Check); 622 623 609 624 610 625 /* … … 652 667 RT_EXPORT_SYMBOL(RTSha224); 653 668 669 670 RTDECL(bool) RTSha224Check(const void *pvBuf, size_t cbBuf, uint8_t const pabHash[RTSHA224_HASH_SIZE]) 671 { 672 RTSHA224CONTEXT Ctx; 673 RTSha224Init(&Ctx); 674 RTSha224Update(&Ctx, pvBuf, cbBuf); 675 rtSha256FinalInternal(&Ctx); 676 677 bool fRet = memcmp(pabHash, &Ctx.AltPrivate.auH[0], RTSHA224_HASH_SIZE) == 0; 678 679 RT_ZERO(Ctx.AltPrivate.auH); 680 return fRet; 681 } 682 RT_EXPORT_SYMBOL(RTSha224Check); 683 -
trunk/src/VBox/Runtime/common/checksum/alt-sha512.cpp
r57358 r57572 596 596 597 597 598 RTDECL(bool) RTSha512Check(const void *pvBuf, size_t cbBuf, uint8_t const pabHash[RTSHA512_HASH_SIZE]) 599 { 600 RTSHA512CONTEXT Ctx; 601 RTSha512Init(&Ctx); 602 RTSha512Update(&Ctx, pvBuf, cbBuf); 603 rtSha512FinalInternal(&Ctx); 604 605 bool fRet = memcmp(pabHash, &Ctx.AltPrivate.auH[0], RTSHA512_HASH_SIZE) == 0; 606 607 RT_ZERO(Ctx.AltPrivate.auH); 608 return fRet; 609 } 610 RT_EXPORT_SYMBOL(RTSha512Check); 611 612 598 613 599 614 /* … … 643 658 644 659 660 RTDECL(bool) RTSha384Check(const void *pvBuf, size_t cbBuf, uint8_t const pabHash[RTSHA384_HASH_SIZE]) 661 { 662 RTSHA384CONTEXT Ctx; 663 RTSha384Init(&Ctx); 664 RTSha384Update(&Ctx, pvBuf, cbBuf); 665 rtSha512FinalInternal(&Ctx); 666 667 bool fRet = memcmp(pabHash, &Ctx.AltPrivate.auH[0], RTSHA384_HASH_SIZE) == 0; 668 669 RT_ZERO(Ctx.AltPrivate.auH); 670 return fRet; 671 } 672 RT_EXPORT_SYMBOL(RTSha384Check); 673 674 645 675 /* 646 676 * SHA-512/224 is just SHA-512 with different initial values an a truncated result. … … 689 719 690 720 721 RTDECL(bool) RTSha512t224Check(const void *pvBuf, size_t cbBuf, uint8_t const pabHash[RTSHA512T224_HASH_SIZE]) 722 { 723 RTSHA512T224CONTEXT Ctx; 724 RTSha512t224Init(&Ctx); 725 RTSha512t224Update(&Ctx, pvBuf, cbBuf); 726 rtSha512FinalInternal(&Ctx); 727 728 bool fRet = memcmp(pabHash, &Ctx.AltPrivate.auH[0], RTSHA512T224_HASH_SIZE) == 0; 729 730 RT_ZERO(Ctx.AltPrivate.auH); 731 return fRet; 732 } 733 RT_EXPORT_SYMBOL(RTSha512t224Check); 734 735 691 736 /* 692 737 * SHA-512/256 is just SHA-512 with different initial values an a truncated result. … … 734 779 RT_EXPORT_SYMBOL(RTSha512t256); 735 780 781 782 RTDECL(bool) RTSha512t256Check(const void *pvBuf, size_t cbBuf, uint8_t const pabHash[RTSHA512T256_HASH_SIZE]) 783 { 784 RTSHA512T256CONTEXT Ctx; 785 RTSha512t256Init(&Ctx); 786 RTSha512t256Update(&Ctx, pvBuf, cbBuf); 787 rtSha512FinalInternal(&Ctx); 788 789 bool fRet = memcmp(pabHash, &Ctx.AltPrivate.auH[0], RTSHA512T256_HASH_SIZE) == 0; 790 791 RT_ZERO(Ctx.AltPrivate.auH); 792 return fRet; 793 } 794 RT_EXPORT_SYMBOL(RTSha512t256Check); 795 -
trunk/src/VBox/Runtime/common/checksum/openssl-sha1.cpp
r57358 r57572 37 37 38 38 #include <iprt/assert.h> 39 #include <iprt/string.h> 40 39 41 40 42 AssertCompile(RT_SIZEOFMEMB(RTSHA1CONTEXT, abPadding) >= RT_SIZEOFMEMB(RTSHA1CONTEXT, Private)); … … 49 51 } 50 52 RT_EXPORT_SYMBOL(RTSha1); 53 54 55 RTDECL(bool) RTSha1Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA1_HASH_SIZE]) 56 { 57 RTSHA1CONTEXT Ctx; 58 RTSha1Init(&Ctx); 59 RTSha1Update(&Ctx, pvBuf, cbBuf); 60 uint8_t abActualDigest[RTSHA1_HASH_SIZE]; 61 RTSha1Final(&Ctx, abActualDigest); 62 bool fRet = memcmp(pabDigest, abActualDigest, RTSHA1_HASH_SIZE) == 0; 63 RT_ZERO(abActualDigest); 64 return fRet; 65 } 66 RT_EXPORT_SYMBOL(RTSha1Check); 51 67 52 68 … … 65 81 66 82 67 RTDECL(void) RTSha1Final(PRTSHA1CONTEXT pCtx, uint8_t pabDigest[ 32])83 RTDECL(void) RTSha1Final(PRTSHA1CONTEXT pCtx, uint8_t pabDigest[RTSHA1_HASH_SIZE]) 68 84 { 69 85 SHA1_Final((unsigned char *)&pabDigest[0], &pCtx->Private); -
trunk/src/VBox/Runtime/common/checksum/openssl-sha256.cpp
r57358 r57572 37 37 38 38 #include <iprt/assert.h> 39 #include <iprt/string.h> 40 39 41 40 42 AssertCompile(RT_SIZEOFMEMB(RTSHA256CONTEXT, abPadding) >= RT_SIZEOFMEMB(RTSHA256CONTEXT, Private)); … … 49 51 } 50 52 RT_EXPORT_SYMBOL(RTSha256); 53 54 55 RTDECL(bool) RTSha256Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA256_HASH_SIZE]) 56 { 57 RTSHA256CONTEXT Ctx; 58 RTSha256Init(&Ctx); 59 RTSha256Update(&Ctx, pvBuf, cbBuf); 60 uint8_t abActualDigest[RTSHA256_HASH_SIZE]; 61 RTSha256Final(&Ctx, abActualDigest); 62 bool fRet = memcmp(pabDigest, abActualDigest, RTSHA256_HASH_SIZE) == 0; 63 RT_ZERO(abActualDigest); 64 return fRet; 65 } 66 RT_EXPORT_SYMBOL(RTSha256Check); 51 67 52 68 … … 87 103 88 104 105 RTDECL(bool) RTSha224Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA224_HASH_SIZE]) 106 { 107 RTSHA224CONTEXT Ctx; 108 RTSha224Init(&Ctx); 109 RTSha224Update(&Ctx, pvBuf, cbBuf); 110 uint8_t abActualDigest[RTSHA224_HASH_SIZE]; 111 RTSha224Final(&Ctx, abActualDigest); 112 bool fRet = memcmp(pabDigest, abActualDigest, RTSHA224_HASH_SIZE) == 0; 113 RT_ZERO(abActualDigest); 114 return fRet; 115 } 116 RT_EXPORT_SYMBOL(RTSha224Check); 117 118 89 119 RTDECL(void) RTSha224Init(PRTSHA224CONTEXT pCtx) 90 120 { -
trunk/src/VBox/Runtime/common/checksum/openssl-sha512.cpp
r57358 r57572 37 37 38 38 #include <iprt/assert.h> 39 #include <iprt/string.h> 40 39 41 40 42 AssertCompile(RT_SIZEOFMEMB(RTSHA512CONTEXT, abPadding) >= RT_SIZEOFMEMB(RTSHA512CONTEXT, Private)); … … 49 51 } 50 52 RT_EXPORT_SYMBOL(RTSha512); 53 54 55 RTDECL(bool) RTSha512Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA512_HASH_SIZE]) 56 { 57 RTSHA512CONTEXT Ctx; 58 RTSha512Init(&Ctx); 59 RTSha512Update(&Ctx, pvBuf, cbBuf); 60 uint8_t abActualDigest[RTSHA512_HASH_SIZE]; 61 RTSha512Final(&Ctx, abActualDigest); 62 bool fRet = memcmp(pabDigest, abActualDigest, RTSHA512_HASH_SIZE) == 0; 63 RT_ZERO(abActualDigest); 64 return fRet; 65 } 66 RT_EXPORT_SYMBOL(RTSha512Check); 51 67 52 68 … … 88 104 89 105 106 RTDECL(bool) RTSha384Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA384_HASH_SIZE]) 107 { 108 RTSHA384CONTEXT Ctx; 109 RTSha384Init(&Ctx); 110 RTSha384Update(&Ctx, pvBuf, cbBuf); 111 uint8_t abActualDigest[RTSHA384_HASH_SIZE]; 112 RTSha384Final(&Ctx, abActualDigest); 113 bool fRet = memcmp(pabDigest, abActualDigest, RTSHA384_HASH_SIZE) == 0; 114 RT_ZERO(abActualDigest); 115 return fRet; 116 } 117 RT_EXPORT_SYMBOL(RTSha384Check); 118 119 90 120 RTDECL(void) RTSha384Init(PRTSHA384CONTEXT pCtx) 91 121 { -
trunk/src/VBox/Runtime/common/crypto/RTCrStoreCertAddFromFile.cpp
r57548 r57572 100 100 RTDECL(int) RTCrStoreCertAddFromFile(RTCRSTORE hStore, uint32_t fFlags, const char *pszFilename, PRTERRINFO pErrInfo) 101 101 { 102 AssertReturn(!fFlags, VERR_INVALID_FLAGS); 103 #if 0 104 RTCRX509CERTIFICATES Certs; 105 int rc = RTCrX509Certificates_ReadFromFile(pszFilename, 0, &Certs, pErrInfo); 106 if (RT_SUCCESS(rc)) 107 { 108 for (uint32_t i = 0; i < Certs.cCerts; i++) 109 { 110 int rc2 = RTCrStoreCertAddEncoded(hStore, RTCRCERTCTX_F_ENC_X509_DER, 111 RTASN1CORE_GET_RAW_ASN1_PTR(&Certs.paCerts[i].SeqCore.Asn1Core), 112 RTASN1CORE_GET_RAW_ASN1_SIZE(&Certs.paCerts[i].SeqCore.Asn1Core), 113 RT_SUCCESS(rc) ? pErrInfo : NULL); 114 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 115 rc = rc2; 116 } 117 118 RTAsn1Destroy(&Certs.SetCore.Asn1Core); 119 } 120 return rc; 121 #else 102 AssertReturn(!(fFlags & ~(RTCRCERTCTX_F_ADD_IF_NOT_FOUND | RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR)), VERR_INVALID_FLAGS); 122 103 123 104 PCRTCRPEMSECTION pSectionHead; 124 int rc = RTCrPemReadFile(pszFilename, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), &pSectionHead, pErrInfo); 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); 125 108 if (RT_SUCCESS(rc)) 126 109 { … … 128 111 while (pCurSec) 129 112 { 130 int rc2 = RTCrStoreCertAddEncoded(hStore, RTCRCERTCTX_F_ENC_X509_DER , pCurSec->pbData, pCurSec->cbData,131 RT_SUCCESS(rc) ? pErrInfo : NULL);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); 132 115 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 116 { 133 117 rc = rc2; 118 if (!(fFlags & RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR)) 119 break; 120 } 134 121 pCurSec = pCurSec->pNext; 135 122 } … … 138 125 } 139 126 return rc; 140 #endif141 127 } 142 128 -
trunk/src/VBox/Runtime/common/crypto/pemfile.cpp
r57358 r57572 125 125 uint8_t const *pbSavedContent = pbContent; 126 126 size_t const cbSavedContent = cbContent; 127 uint32_t iMarker = 0; 128 while (iMarker < cMarkers) 127 for (uint32_t iMarker = 0; iMarker < cMarkers; iMarker++) 129 128 { 130 129 pbContent = pbSavedContent; … … 143 142 cbContent -= cchWord; 144 143 145 if (!cbContent || !RT_C_IS_BLANK(*pbContent)) 146 break; 147 do 148 { 149 pbContent++; 150 cbContent--; 151 } while (cbContent > 0 && RT_C_IS_BLANK(*pbContent)); 144 if (!cbContent) 145 break; 146 if (RT_C_IS_BLANK(*pbContent)) 147 do 148 { 149 pbContent++; 150 cbContent--; 151 } while (cbContent > 0 && RT_C_IS_BLANK(*pbContent)); 152 else if (cWords > 1 || pbContent[0] != '-') 153 break; 152 154 153 155 cWords--; … … 175 177 if (poffEnd) 176 178 *poffEnd = pbContent - pbStart; 177 if ( *ppMatch)179 if (ppMatch) 178 180 *ppMatch = &paMarkers[iMarker]; 179 181 return true; … … 265 267 { 266 268 /* 267 * Assume a well formed PEM file contains only 7-bit ASCII and restricts268 * itselfto the following control characters:269 * Well formed PEM files should probably only contain 7-bit ASCII and 270 * restrict thenselfs to the following control characters: 269 271 * tab, newline, return, form feed 272 * 273 * However, if we wan't to read PEM files which contains human readable 274 * certificate details before or after each base-64 section, we can't stick 275 * to 7-bit ASCII. We could say it must be UTF-8, but that's probably to 276 * limited too. So, we'll settle for detecting binary files by control 277 * characters alone (safe enough for DER encoded stuff, I think). 270 278 */ 271 279 while (cbFile-- > 0) 272 280 { 273 281 uint8_t const b = *pbFile++; 274 if ( b >= 0x7f 275 || (b < 32 && b != '\t' && b != '\n' && b != '\r' && b != '\f') ) 282 if (b < 32 && b != '\t' && b != '\n' && b != '\r' && b != '\f') 276 283 { 277 284 /* Ignore EOT (4), SUB (26) and NUL (0) at the end of the file. */ … … 280 287 || ( cbFile == 1 281 288 && *pbFile == '\0'))) 282 return true; 289 return false; 290 283 291 if (b == 0 && cbFile == 0) 284 return true; 285 return false; 286 } 287 } 288 return true; 292 return false; 293 294 return true; 295 } 296 } 297 return false; 289 298 } 290 299 … … 328 337 PCRTCRPEMSECTION *ppSectionHead, PRTERRINFO pErrInfo) 329 338 { 330 AssertReturn(! fFlags, VERR_INVALID_FLAGS);339 AssertReturn(!(fFlags & ~RTCRPEMREADFILE_F_CONTINUE_ON_ENCODING_ERROR), VERR_INVALID_FLAGS); 331 340 332 341 size_t cbContent; … … 362 371 /* Decode the section. */ 363 372 /** @todo copy the preamble as well. */ 364 rc= rtCrPemDecodeBase64(pbContent + offBegin, offEnd - offBegin,365 (void **)&pSection->pbData, &pSection->cbData);366 if (RT_FAILURE(rc ))373 int rc2 = rtCrPemDecodeBase64(pbContent + offBegin, offEnd - offBegin, 374 (void **)&pSection->pbData, &pSection->cbData); 375 if (RT_FAILURE(rc2)) 367 376 { 368 377 pSection->pbData = NULL; 369 378 pSection->cbData = 0; 370 break; 379 if ( rc2 == VERR_INVALID_BASE64_ENCODING 380 && (fFlags & RTCRPEMREADFILE_F_CONTINUE_ON_ENCODING_ERROR)) 381 rc = -rc2; 382 else 383 { 384 rc = rc2; 385 break; 386 } 371 387 } 372 388 -
trunk/src/VBox/Runtime/common/crypto/store-inmem.cpp
r57358 r57572 282 282 int rc; 283 283 284 AssertMsgReturn( fFlags== RTCRCERTCTX_F_ENC_X509_DER285 || fFlags== RTCRCERTCTX_F_ENC_TAF_DER284 AssertMsgReturn( (fFlags & RTCRCERTCTX_F_ENC_MASK) == RTCRCERTCTX_F_ENC_X509_DER 285 || (fFlags & RTCRCERTCTX_F_ENC_MASK) == RTCRCERTCTX_F_ENC_TAF_DER 286 286 , ("Only X.509 and TAF DER are supported: %#x\n", fFlags), VERR_INVALID_FLAGS); 287 287 288 if (pThis->cCerts + 1 > pThis->cCertsAlloc) 288 /* 289 * Check for duplicates if specified. 290 */ 291 if (fFlags & RTCRCERTCTX_F_ADD_IF_NOT_FOUND) 292 { 293 uint32_t iCert = pThis->cCerts; 294 while (iCert-- > 0) 295 { 296 PRTCRSTOREINMEMCERT pCert = pThis->papCerts[iCert]; 297 if ( pCert->Core.Public.cbEncoded == cbEncoded 298 && pCert->Core.Public.fFlags == (fFlags & RTCRCERTCTX_F_ENC_MASK) 299 && memcmp(pCert->Core.Public.pabEncoded, pbEncoded, cbEncoded) == 0) 300 return VWRN_ALREADY_EXISTS; 301 } 302 } 303 304 /* 305 * Add it. 306 */ 307 if (pThis->cCerts + 1 <= pThis->cCertsAlloc) 308 { /* likely */ } 309 else 289 310 { 290 311 rc = rtCrStoreInMemGrow(pThis, pThis->cCerts + 1); … … 293 314 } 294 315 295 rc = rtCrStoreInMemCreateCertEntry(pThis, fFlags, pbEncoded, cbEncoded, pErrInfo, &pThis->papCerts[pThis->cCerts]); 316 rc = rtCrStoreInMemCreateCertEntry(pThis, fFlags & RTCRCERTCTX_F_ENC_MASK, pbEncoded, cbEncoded, 317 pErrInfo, &pThis->papCerts[pThis->cCerts]); 296 318 if (RT_SUCCESS(rc)) 297 319 { … … 360 382 return rc; 361 383 } 362 384 RT_EXPORT_SYMBOL(RTCrStoreCreateInMem); 385 -
trunk/src/VBox/Runtime/common/crypto/store-internal.h
r56290 r57572 125 125 * Adds a certificate to the store. 126 126 * 127 * @returns IPRT status. 128 * @retval VWRN_ALREADY_EXISTS if the certificate is already present and 129 * RTCRCERTCTX_F_ADD_IF_NOT_FOUND was specified. 127 130 * @param pvProvider The provider specific data. 128 131 * @param fFlags RTCRCERTCTX_F_XXX. -
trunk/src/VBox/Runtime/common/crypto/store.cpp
r57358 r57572 174 174 AssertPtrReturn(pvSrc, VERR_INVALID_POINTER); 175 175 AssertReturn(cbSrc > 16 && cbSrc < _1M, VERR_OUT_OF_RANGE); 176 AssertMsgReturn( fFlags == RTCRCERTCTX_F_ENC_X509_DER 177 || fFlags == RTCRCERTCTX_F_ENC_TAF_DER 176 AssertReturn(!(fFlags & ~(RTCRCERTCTX_F_ADD_IF_NOT_FOUND | RTCRCERTCTX_F_ENC_MASK)), VERR_INVALID_FLAGS); 177 AssertMsgReturn( (fFlags & RTCRCERTCTX_F_ENC_MASK) == RTCRCERTCTX_F_ENC_X509_DER 178 || (fFlags & RTCRCERTCTX_F_ENC_MASK) == RTCRCERTCTX_F_ENC_TAF_DER 178 179 , ("Only X.509 and TAF DER supported: %#x\n", fFlags), VERR_INVALID_FLAGS); 179 180 -
trunk/src/VBox/Runtime/tools/RTSignTool.cpp
r56978 r57572 496 496 { 497 497 case 'r': case 'a': 498 rc = RTCrStoreCertAddFromFile(ch == 'r' ? State.hRootStore : State.hAdditionalStore, 0, ValueUnion.psz, 499 RTErrInfoInitStatic(&StaticErrInfo)); 498 rc = RTCrStoreCertAddFromFile(ch == 'r' ? State.hRootStore : State.hAdditionalStore, 499 RTCRCERTCTX_F_ADD_IF_NOT_FOUND | RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR, 500 ValueUnion.psz, RTErrInfoInitStatic(&StaticErrInfo)); 500 501 if (RT_FAILURE(rc)) 501 502 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error loading certificate '%s': %Rrc - %s", 502 503 ValueUnion.psz, rc, StaticErrInfo.szMsg); 504 if (RTErrInfoIsSet(&StaticErrInfo.Core)) 505 RTMsgWarning("Warnings loading certificate '%s': %s", ValueUnion.psz, StaticErrInfo.szMsg); 503 506 break; 504 507
Note:
See TracChangeset
for help on using the changeset viewer.