Changeset 52600 in vbox
- Timestamp:
- Sep 4, 2014 10:59:00 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/asn1-generator-asn1-decoder.h
r51770 r52600 24 24 */ 25 25 26 #include <iprt/string.h> 27 26 28 #define RTASN1TMPL_PASS RTASN1TMPL_PASS_DECODE 27 29 #include <iprt/asn1-generator-pass.h> -
trunk/include/iprt/asn1-generator-init.h
r51770 r52600 24 24 */ 25 25 26 #include <iprt/string.h> 26 27 27 28 #define RTASN1TMPL_PASS RTASN1TMPL_PASS_INIT -
trunk/include/iprt/asn1-generator-pass.h
r51919 r52600 1039 1039 { a_MoreConstraints } 1040 1040 1041 # define RTASN1TMPL_MEMBER_CONSTR_U64_MIN_MAX(a_Name, uMin, uMax, a_MoreConstraints) \ 1042 if (RT_SUCCESS(rc)) \ 1043 { \ 1044 if (RT_UNLIKELY( RTAsn1Integer_UnsignedCompareWithU64(&pThis->a_Name, uMin) < 0 \ 1045 || RTAsn1Integer_UnsignedCompareWithU64(&pThis->a_Name, uMax) > 0) ) \ 1046 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, \ 1047 "%s::" #a_Name ": Out of range: %#x not in {%#llx..%#llx}", \ 1048 pszErrorTag, pThis->a_Name.Asn1Core.cb > 8 ? UINT64_MAX : pThis->a_Name.uValue.u, \ 1049 (uint64_t)(uMin), (uint64_t)(uMax)); \ 1050 } \ 1051 { a_MoreConstraints } 1052 1041 1053 # define RTASN1TMPL_MEMBER_CONSTR_PRESENT(a_Name, a_Api, a_MoreConstraints) \ 1042 1054 if (RT_SUCCESS(rc) && RT_UNLIKELY(!RT_CONCAT(a_Api,_IsPresent)(&pThis->a_Name))) \ … … 1259 1271 RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, RTASN1TMPL_ITAG_F_UP, RT_NOTHING) 1260 1272 #endif 1273 #ifndef RTASN1TMPL_PCHOICE_ITAG_UC 1274 # define RTASN1TMPL_PCHOICE_ITAG_UC(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api) \ 1275 RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, RTASN1TMPL_ITAG_F_UC, RT_NOTHING) 1276 #endif 1261 1277 #ifndef RTASN1TMPL_PCHOICE_ITAG_CP 1262 1278 # define RTASN1TMPL_PCHOICE_ITAG_CP(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api) \ … … 1283 1299 #ifndef RTASN1TMPL_MEMBER_CONSTR_BITSTRING_MIN_MAX 1284 1300 # define RTASN1TMPL_MEMBER_CONSTR_BITSTRING_MIN_MAX(a_Name, cMinBits, cMaxBits, a_MoreConstraints) 1301 #endif 1302 #ifndef RTASN1TMPL_MEMBER_CONSTR_U64_MIN_MAX 1303 # define RTASN1TMPL_MEMBER_CONSTR_U64_MIN_MAX(a_Name, uMin, uMax, a_MoreConstraints) 1285 1304 #endif 1286 1305 #ifndef RTASN1TMPL_MEMBER_CONSTR_PRESENT … … 1372 1391 #undef RTASN1TMPL_MEMBER_CONSTR_MIN_MAX 1373 1392 #undef RTASN1TMPL_MEMBER_CONSTR_BITSTRING_MIN_MAX 1393 #undef RTASN1TMPL_MEMBER_CONSTR_U64_MIN_MAX 1374 1394 #undef RTASN1TMPL_MEMBER_CONSTR_PRESENT 1375 1395 -
trunk/include/iprt/asn1.h
r52537 r52600 397 397 398 398 399 /** Aliases two ASN.1 types. */ 399 /** Aliases two ASN.1 types, no method aliases. */ 400 #define RTASN1TYPE_ALIAS_TYPE_ONLY(a_TypeNm, a_AliasType) \ 401 typedef a_AliasType a_TypeNm; \ 402 typedef a_TypeNm *RT_CONCAT(P,a_TypeNm); \ 403 typedef a_TypeNm const *RT_CONCAT(PC,a_TypeNm) 404 405 /** Aliases two ASN.1 types and methods. */ 400 406 #define RTASN1TYPE_ALIAS(a_TypeNm, a_AliasType, a_ImplExtNm, a_AliasExtNm) \ 401 407 typedef a_AliasType a_TypeNm; \ -
trunk/include/iprt/crypto/pkcs7.h
r52537 r52600 85 85 /** Signing time (PKCS \#9), use pSigningTime. */ 86 86 RTCRPKCS7ATTRIBUTETYPE_SIGNING_TIME, 87 /** Microsoft timestamp info (RFC-3161) signed data, use pContentInfo. */ 88 RTCRPKCS7ATTRIBUTETYPE_MS_TIMESTAMP, 87 89 /** Blow the type up to 32-bits. */ 88 90 RTCRPKCS7ATTRIBUTETYPE_32BIT_HACK = 0x7fffffff … … 115 117 /** Signing time(s) (RTCRPKCS7ATTRIBUTETYPE_SIGNING_TIME). */ 116 118 PRTASN1SETOFTIMES pSigningTime; 119 /** Microsoft timestamp (RFC-3161 signed data). */ 120 struct RTCRPKCS7SETOFCONTENTINFOS *pContentInfos; 117 121 } uValues; 118 122 } RTCRPKCS7ATTRIBUTE; … … 173 177 * Value: SignerInfo. */ 174 178 #define RTCR_PKCS9_ID_COUNTER_SIGNATURE_OID "1.2.840.113549.1.9.6" 179 /** Microsoft timestamp (RTF-3161) counter signature (SignedData). 180 * @remarks This isn't defined by PKCS \#9, but lumped in here for 181 * convenience. It's actually listed as SPC by MS. */ 182 #define RTCR_PKCS9_ID_MS_TIMESTAMP "1.3.6.1.4.1.311.3.3.1" 175 183 /** @} */ 184 176 185 177 186 /** … … 193 202 */ 194 203 RTDECL(PCRTASN1TIME) RTCrPkcs7SignerInfo_GetSigningTime(PCRTCRPKCS7SIGNERINFO pThis, PCRTCRPKCS7SIGNERINFO *ppSignerInfo); 204 205 206 /** 207 * Get the (first) timestamp from within a Microsoft timestamp server counter 208 * signature. 209 * 210 * @returns Pointer to the signing time if found, NULL if not. 211 * @param pThis The SignerInfo to search. 212 * @param ppContentInfo Where to return the pointer to the counter 213 * signature, optional. 214 */ 215 RTDECL(PCRTASN1TIME) RTCrPkcs7SignerInfo_GetMsTimestamp(PCRTCRPKCS7SIGNERINFO pThis, 216 struct RTCRPKCS7CONTENTINFO const **ppContentInfo); 195 217 196 218 … … 223 245 */ 224 246 RTASN1OCTETSTRING Content; 247 /** Pointer to the CMS octet string that's inside the Content, NULL if PKCS \#7. 248 * 249 * Hack alert! When transitioning from PKCS \#7 to CMS, the designers decided to 250 * change things and add another wrapper. This time we're talking about a real 251 * octet string, not like the one above which is really an explicit content tag. 252 * When constructing or decoding CMS content, this will be the same pointer as 253 * Content.pEncapsulated, while the union below will be holding the same pointer 254 * as pCmsContent->pEncapsulated. 255 */ 256 PRTASN1OCTETSTRING pCmsContent; 225 257 /** Same as Content.pEncapsulated, except a choice of known types. */ 226 258 union … … 230 262 /** ContentType is RTCRSPCINDIRECTDATACONTENT_OID. */ 231 263 struct RTCRSPCINDIRECTDATACONTENT *pIndirectDataContent; 264 /** ContentType is RTCRTSPTSTINFO_OID. */ 265 struct RTCRTSPTSTINFO *pTstInfo; 232 266 /** Generic / Unknown / User. */ 233 267 PRTASN1CORE pCore; … … 238 272 /** Pointer to the const IPRT representation of a PKCS \#7 ContentInfo. */ 239 273 typedef RTCRPKCS7CONTENTINFO const *PCRTCRPKCS7CONTENTINFO; 240 241 274 RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7CONTENTINFO, RTDECL, RTCrPkcs7ContentInfo, SeqCore.Asn1Core); 275 RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7SETOFCONTENTINFOS, RTCRPKCS7CONTENTINFO, RTDECL, RTCrPkcs7SetOfContentInfos); 242 276 243 277 RTDECL(bool) RTCrPkcs7ContentInfo_IsSignedData(PCRTCRPKCS7CONTENTINFO pThis); 278 279 280 /** 281 * PKCS \#7 Certificate choice. 282 */ 283 typedef enum RTCRPKCS7CERTCHOICE 284 { 285 RTCRPKCS7CERTCHOICE_INVALID = 0, 286 RTCRPKCS7CERTCHOICE_X509, 287 RTCRPKCS7CERTCHOICE_EXTENDED_PKCS6, 288 RTCRPKCS7CERTCHOICE_AC_V1, 289 RTCRPKCS7CERTCHOICE_AC_V2, 290 RTCRPKCS7CERTCHOICE_OTHER, 291 RTCRPKCS7CERTCHOICE_END, 292 RTCRPKCS7CERTCHOICE_32BIT_HACK = 0x7fffffff 293 } RTCRPKCS7CERTCHOICE; 294 295 296 /** 297 * Common representation for PKCS \#7 ExtendedCertificateOrCertificate and the 298 * CMS CertificateChoices types. 299 */ 300 typedef struct RTCRPKCS7CERT 301 { 302 /** Dummy ASN.1 record, not encoded. */ 303 RTASN1DUMMY Dummy; 304 /** The value allocation. */ 305 RTASN1ALLOCATION Allocation; 306 /** The choice of value. */ 307 RTCRPKCS7CERTCHOICE enmChoice; 308 /** The value union. */ 309 union 310 { 311 /** Standard X.509 certificate (RTCRCMSCERTIFICATECHOICE_X509). */ 312 PRTCRX509CERTIFICATE pX509Cert; 313 /** Extended PKCS \#6 certificate (RTCRCMSCERTIFICATECHOICE_EXTENDED_PKCS6). */ 314 PRTASN1CORE pExtendedCert; 315 /** Attribute certificate version 1 (RTCRCMSCERTIFICATECHOICE_AC_V1). */ 316 PRTASN1CORE pAcV1; 317 /** Attribute certificate version 2 (RTCRCMSCERTIFICATECHOICE_AC_V2). */ 318 PRTASN1CORE pAcV2; 319 /** Other certificate (RTCRCMSCERTIFICATECHOICE_OTHER). */ 320 PRTASN1CORE pOtherCert; 321 } u; 322 } RTCRPKCS7CERT; 323 /** Pointer to the IPRT representation of PKCS \#7 or CMS certificate. */ 324 typedef RTCRPKCS7CERT *PRTCRPKCS7CERT; 325 /** Pointer to the const IPRT representation of PKCS \#7 or CMS certificate. */ 326 typedef RTCRPKCS7CERT const *PCRTCRPKCS7CERT; 327 RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7CERT, RTDECL, RTCrPkcs7Cert, Dummy.Asn1Core); 328 RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7SETOFCERTS, RTCRPKCS7CERT, RTDECL, RTCrPkcs7SetOfCerts); 329 330 RTDECL(PCRTCRX509CERTIFICATE) RTCrPkcs7SetOfCerts_FindX509ByIssuerAndSerialNumber(PCRTCRPKCS7SETOFCERTS pCertificates, 331 PCRTCRX509NAME pIssuer, 332 PCRTASN1INTEGER pSerialNumber); 244 333 245 334 … … 258 347 RTCRPKCS7CONTENTINFO ContentInfo; 259 348 /** Certificates, optional, implicit tag 0. (Required by Authenticode.) */ 260 RTCR X509CERTIFICATESCertificates;349 RTCRPKCS7SETOFCERTS Certificates; 261 350 /** Certificate revocation lists, optional, implicit tag 1. 262 351 * Not used by Authenticode, so currently stubbed. */ … … 270 359 typedef RTCRPKCS7SIGNEDDATA const *PCRTCRPKCS7SIGNEDDATA; 271 360 RTASN1TYPE_STANDARD_PROTOTYPES(RTCRPKCS7SIGNEDDATA, RTDECL, RTCrPkcs7SignedData, SeqCore.Asn1Core); 361 RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRPKCS7SETOFSIGNEDDATA, RTCRPKCS7SIGNEDDATA, RTDECL, RTCrPkcs7SetOfSignedData); 272 362 273 363 /** PKCS \#7 SignedData object ID. */ … … 276 366 /** PKCS \#7 SignedData version number 1. */ 277 367 #define RTCRPKCS7SIGNEDDATA_V1 1 368 /* No version 2 seems to exist. */ 369 /** CMS SignedData version number 3. 370 * This should only be used if there are version 1 attribute certificates 371 * present, or if there are version 3 SignerInfo items present, or if 372 * enmcCountInfo is not id-data (RFC-5652, section 5.1). */ 373 #define RTCRPKCS7SIGNEDDATA_V3 3 374 /** CMS SignedData version number 4. 375 * This should only be used if there are version 2 attribute certificates 376 * present (RFC-5652, section 5.1). */ 377 #define RTCRPKCS7SIGNEDDATA_V4 4 378 /** CMS SignedData version number 5. 379 * This should only be used if there are certificates or/and CRLs of the 380 * OTHER type present (RFC-5652, section 5.1). */ 381 #define RTCRPKCS7SIGNEDDATA_V5 5 278 382 279 383 … … 384 488 * signing time attributes and use the @a pValidationTime instead. */ 385 489 #define RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_SIGNING_TIME_IF_PRESENT RT_BIT_32(0) 490 /** Same as RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_SIGNING_TIME_IF_PRESENT for the MS 491 * timestamp counter sigantures. */ 492 #define RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_MS_TIMESTAMP_IF_PRESENT RT_BIT_32(1) 386 493 /** Only use signging time attributes from counter signatures. */ 387 #define RTCRPKCS7VERIFY_SD_F_COUNTER_SIGNATURE_SIGNING_TIME_ONLY RT_BIT_32( 1)494 #define RTCRPKCS7VERIFY_SD_F_COUNTER_SIGNATURE_SIGNING_TIME_ONLY RT_BIT_32(2) 388 495 /** Don't validate the counter signature containing the signing time, just use 389 496 * it unverified. This is useful if we don't necessarily have the root 390 * certificates for the timestamp server handy, but use with great care. */ 391 #define RTCRPKCS7VERIFY_SD_F_USE_SIGNING_TIME_UNVERIFIED RT_BIT_32(2) 497 * certificates for the timestamp server handy, but use with great care. 498 * @sa RTCRPKCS7VERIFY_SD_F_USE_MS_TIMESTAMP_UNVERIFIED */ 499 #define RTCRPKCS7VERIFY_SD_F_USE_SIGNING_TIME_UNVERIFIED RT_BIT_32(3) 500 /** Don't validate the MS counter signature containing the signing timestamp. 501 * @sa RTCRPKCS7VERIFY_SD_F_USE_SIGNING_TIME_UNVERIFIED */ 502 #define RTCRPKCS7VERIFY_SD_F_USE_MS_TIMESTAMP_UNVERIFIED RT_BIT_32(4) 503 /** Do not consider timestamps in microsoft counter signatures. */ 504 #define RTCRPKCS7VERIFY_SD_F_IGNORE_MS_TIMESTAMP RT_BIT_32(5) 505 /** The signed data requires certificates to have the timestamp extended 506 * usage bit present. This is used for recursivly verifying MS timestamp 507 * signatures. */ 508 #define RTCRPKCS7VERIFY_SD_F_USAGE_TIMESTAMPING RT_BIT_32(6) 509 392 510 /** Indicates internally that we're validating a counter signature and should 393 511 * use different rules when checking out the authenticated attributes. -
trunk/include/iprt/crypto/x509.h
r52537 r52600 1023 1023 RTDECL(int) RTCrX509CertPathsSetUntrustedStore(RTCRX509CERTPATHS hCertPaths, RTCRSTORE hUntrustedStore); 1024 1024 RTDECL(int) RTCrX509CertPathsSetUntrustedArray(RTCRX509CERTPATHS hCertPaths, PCRTCRX509CERTIFICATE paCerts, uint32_t cCerts); 1025 RTDECL(int) RTCrX509CertPathsSetUntrustedSet(RTCRX509CERTPATHS hCertPaths, struct RTCRPKCS7SETOFCERTS const *pSetOfCerts); 1025 1026 RTDECL(int) RTCrX509CertPathsSetValidTime(RTCRX509CERTPATHS hCertPaths, PCRTTIME pTime); 1026 1027 RTDECL(int) RTCrX509CertPathsSetValidTimeSpec(RTCRX509CERTPATHS hCertPaths, PCRTTIMESPEC pTimeSpec); -
trunk/include/iprt/mangling.h
r52539 r52600 2397 2397 # define RTCrPkcs7SignerInfo_Enum RT_MANGLER(RTCrPkcs7SignerInfo_Enum) 2398 2398 # define RTCrPkcs7SignerInfo_GetSigningTime RT_MANGLER(RTCrPkcs7SignerInfo_GetSigningTime) 2399 # define RTCrPkcs7SignerInfo_GetMsTimestamp RT_MANGLER(RTCrPkcs7SignerInfo_GetMsTimestamp) 2399 2400 # define RTCrPkcs7SignerInfos_Compare RT_MANGLER(RTCrPkcs7SignerInfos_Compare) 2400 2401 # define RTCrPkcs7SignerInfos_Delete RT_MANGLER(RTCrPkcs7SignerInfos_Delete) … … 2760 2761 # define RTCrTafTrustAnchorInfo_CheckSanity RT_MANGLER(RTCrTafTrustAnchorInfo_CheckSanity) 2761 2762 # define RTCrTafTrustAnchorList_CheckSanity RT_MANGLER(RTCrTafTrustAnchorList_CheckSanity) 2763 # define RTCrTspAccuracy_CheckSanity RT_MANGLER(RTCrTspAccuracy_CheckSanity) 2764 # define RTCrTspAccuracy_Clone RT_MANGLER(RTCrTspAccuracy_Clone) 2765 # define RTCrTspAccuracy_Compare RT_MANGLER(RTCrTspAccuracy_Compare) 2766 # define RTCrTspAccuracy_DecodeAsn1 RT_MANGLER(RTCrTspAccuracy_DecodeAsn1) 2767 # define RTCrTspAccuracy_Delete RT_MANGLER(RTCrTspAccuracy_Delete) 2768 # define RTCrTspAccuracy_Enum RT_MANGLER(RTCrTspAccuracy_Enum) 2769 # define RTCrTspAccuracy_Init RT_MANGLER(RTCrTspAccuracy_Init) 2770 # define RTCrTspMessageImprint_CheckSanity RT_MANGLER(RTCrTspMessageImprint_CheckSanity) 2771 # define RTCrTspMessageImprint_Clone RT_MANGLER(RTCrTspMessageImprint_Clone) 2772 # define RTCrTspMessageImprint_Compare RT_MANGLER(RTCrTspMessageImprint_Compare) 2773 # define RTCrTspMessageImprint_DecodeAsn1 RT_MANGLER(RTCrTspMessageImprint_DecodeAsn1) 2774 # define RTCrTspMessageImprint_Delete RT_MANGLER(RTCrTspMessageImprint_Delete) 2775 # define RTCrTspMessageImprint_Enum RT_MANGLER(RTCrTspMessageImprint_Enum) 2776 # define RTCrTspMessageImprint_Init RT_MANGLER(RTCrTspMessageImprint_Init) 2777 # define RTCrTspTstInfo_CheckSanity RT_MANGLER(RTCrTspTstInfo_CheckSanity) 2778 # define RTCrTspTstInfo_Clone RT_MANGLER(RTCrTspTstInfo_Clone) 2779 # define RTCrTspTstInfo_Compare RT_MANGLER(RTCrTspTstInfo_Compare) 2780 # define RTCrTspTstInfo_DecodeAsn1 RT_MANGLER(RTCrTspTstInfo_DecodeAsn1) 2781 # define RTCrTspTstInfo_Delete RT_MANGLER(RTCrTspTstInfo_Delete) 2782 # define RTCrTspTstInfo_Enum RT_MANGLER(RTCrTspTstInfo_Enum) 2783 # define RTCrTspTstInfo_Init RT_MANGLER(RTCrTspTstInfo_Init) 2762 2784 # define RTCrCertCtxRelease RT_MANGLER(RTCrCertCtxRelease) 2763 2785 # define RTCrCertCtxRetain RT_MANGLER(RTCrCertCtxRetain) -
trunk/src/VBox/HostDrivers/Support/Makefile.kmk
r52406 r52600 281 281 $(VBOX_PATH_RUNTIME_SRC)/common/crypto/taf-init.cpp \ 282 282 $(VBOX_PATH_RUNTIME_SRC)/common/crypto/taf-sanity.cpp \ 283 $(VBOX_PATH_RUNTIME_SRC)/common/crypto/tsp-asn1-decoder.cpp \ 284 $(VBOX_PATH_RUNTIME_SRC)/common/crypto/tsp-core.cpp \ 285 $(VBOX_PATH_RUNTIME_SRC)/common/crypto/tsp-init.cpp \ 286 $(VBOX_PATH_RUNTIME_SRC)/common/crypto/tsp-sanity.cpp \ 283 287 $(VBOX_PATH_RUNTIME_SRC)/common/checksum/alt-md2.cpp \ 284 288 $(VBOX_PATH_RUNTIME_SRC)/common/checksum/alt-md5.cpp \ -
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp
r52541 r52600 1004 1004 1005 1005 uint32_t fFlags = RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_SIGNING_TIME_IF_PRESENT 1006 | RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_MS_TIMESTAMP_IF_PRESENT 1006 1007 | RTCRPKCS7VERIFY_SD_F_COUNTER_SIGNATURE_SIGNING_TIME_ONLY; 1007 1008 #ifndef IN_RING0 1008 1009 if (!g_fHaveOtherRoots) 1009 1010 #endif 1010 fFlags |= RTCRPKCS7VERIFY_SD_F_USE_SIGNING_TIME_UNVERIFIED ;1011 fFlags |= RTCRPKCS7VERIFY_SD_F_USE_SIGNING_TIME_UNVERIFIED | RTCRPKCS7VERIFY_SD_F_USE_MS_TIMESTAMP_UNVERIFIED; 1011 1012 return RTCrPkcs7VerifySignedData(pContentInfo, fFlags, g_hSpcAndNtKernelSuppStore, g_hSpcAndNtKernelRootStore, 1012 1013 &ValidationTime, supHardNtViCertVerifyCallback, pNtViRdr, pErrInfo); -
trunk/src/VBox/Runtime/Makefile.kmk
r52443 r52600 359 359 common/crypto/taf-init.cpp \ 360 360 common/crypto/taf-sanity.cpp \ 361 common/crypto/tsp-asn1-decoder.cpp \ 362 common/crypto/tsp-core.cpp \ 363 common/crypto/tsp-init.cpp \ 364 common/crypto/tsp-sanity.cpp \ 361 365 common/crypto/store.cpp \ 362 366 common/crypto/store-inmem.cpp \ … … 1920 1924 common/crypto/taf-init.cpp \ 1921 1925 common/crypto/taf-sanity.cpp \ 1926 common/crypto/tsp-asn1-decoder.cpp \ 1927 common/crypto/tsp-core.cpp \ 1928 common/crypto/tsp-init.cpp \ 1929 common/crypto/tsp-sanity.cpp \ 1922 1930 common/checksum/alt-md2.cpp \ 1923 1931 common/checksum/alt-sha1.cpp \ … … 2734 2742 spc-template.o spc-template.obj: spc-core.o spc-asn1-decoder.o spc-sanity.o spc-init.o 2735 2743 taf-template.o taf-template.obj: taf-core.o taf-asn1-decoder.o taf-sanity.o taf-init.o 2744 tsp-template.o tsp-template.obj: tsp-core.o tsp-asn1-decoder.o tsp-sanity.o tsp-init.o 2736 2745 x509-template.o x509-template.obj: x509-core.o x509-asn1-decoder.o x509-sanity.o x509-init.o 2737 2746 pkcs7-template.o pkcs7-template.obj: pkcs7-core.o pkcs7-asn1-decoder.o pkcs7-sanity.o pkcs7-init.o -
trunk/src/VBox/Runtime/common/asn1/asn1-cursor.cpp
r52533 r52600 28 28 * Header Files * 29 29 *******************************************************************************/ 30 #define RT_STRICT 30 31 #include "internal/iprt.h" 31 32 #include <iprt/asn1.h> … … 47 48 * 48 49 * For reference, 'RTSignTool verify-exe RTSignTool.exe', requires a value of 15 49 * to work without hitting the limit. 50 * to work without hitting the limit for signatures with simple timestamps, and 51 * 23 (amd64/rel = ~3KB) for the new microsoft timestamp counter signatures. 50 52 */ 51 53 #ifdef IN_RING3 -
trunk/src/VBox/Runtime/common/asn1/asn1-dump.cpp
r51858 r52600 84 84 static void rtAsn1DumpPrintIdent(PRTASN1DUMPDATA pData, uint32_t uDepth) 85 85 { 86 uint32_t i = 0; 87 uDepth *= 2; 88 while (i < uDepth) 86 uint32_t cchLeft = uDepth * 2; 87 while (cchLeft > 0) 89 88 { 90 89 static char const s_szSpaces[] = " "; 91 uint32_t cch = RT_MIN( uDepth, sizeof(s_szSpaces) - 1);90 uint32_t cch = RT_MIN(cchLeft, sizeof(s_szSpaces) - 1); 92 91 rtAsn1DumpPrintf(pData, &s_szSpaces[sizeof(s_szSpaces) - 1 - cch]); 93 i += cch;92 cchLeft -= cch; 94 93 } 95 94 } -
trunk/src/VBox/Runtime/common/asn1/asn1-ut-time-decode.cpp
r51770 r52600 178 178 * Check the dot. 179 179 */ 180 if (*pchFraction == '.')180 if (*pchFraction != '.') 181 181 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_INVALID_GENERALIZED_TIME_ENCODING, 182 182 "%s: Expected GeneralizedTime fraction dot, found: '%c' ('%.*s')", -
trunk/src/VBox/Runtime/common/crypto/pkcs7-asn1-decoder.cpp
r52533 r52600 35 35 #include <iprt/string.h> 36 36 #include <iprt/crypto/spc.h> 37 #include <iprt/crypto/tsp.h> 37 38 38 39 #include "pkcs7-internal.h" … … 42 43 * PKCS #7 ContentInfo 43 44 */ 45 typedef enum RTCRPKCS7CONTENTINFOCHOICE 46 { 47 RTCRPKCS7CONTENTINFOCHOICE_INVALID = 0, 48 RTCRPKCS7CONTENTINFOCHOICE_UNKNOWN, 49 RTCRPKCS7CONTENTINFOCHOICE_SIGNED_DATA, 50 RTCRPKCS7CONTENTINFOCHOICE_SPC_INDIRECT_DATA_CONTENT, 51 RTCRPKCS7CONTENTINFOCHOICE_TSP_TST_INFO, 52 RTCRPKCS7CONTENTINFOCHOICE_END, 53 RTCRPKCS7CONTENTINFOCHOICE_32BIT_HACK = 0x7fffffff 54 } RTCRPKCS7CONTENTINFOCHOICE; 44 55 45 56 static int rtCrPkcs7ContentInfo_DecodeExtra(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTCRPKCS7CONTENTINFO pThis, … … 48 59 pThis->u.pCore = NULL; 49 60 50 int rc; 51 RTASN1CURSOR ContentCursor; 61 /* 62 * Figure the type. 63 */ 64 RTCRPKCS7CONTENTINFOCHOICE enmChoice; 65 size_t cbContent = 0; 52 66 if (RTAsn1ObjId_CompareWithString(&pThis->ContentType, RTCRPKCS7SIGNEDDATA_OID) == 0) 53 67 { 54 rc = RTAsn1MemAllocZ(&pThis->Content.EncapsulatedAllocation, (void **)&pThis->Content.pEncapsulated, 55 sizeof(*pThis->u.pSignedData)); 56 if (RT_SUCCESS(rc)) 57 { 58 pThis->u.pCore = pThis->Content.pEncapsulated; 59 rc = RTAsn1CursorInitSubFromCore(pCursor, &pThis->Content.Asn1Core, &ContentCursor, "Content"); 60 if (RT_SUCCESS(rc)) 61 rc = RTCrPkcs7SignedData_DecodeAsn1(&ContentCursor, 0, pThis->u.pSignedData, "SignedData"); 62 } 68 enmChoice = RTCRPKCS7CONTENTINFOCHOICE_SIGNED_DATA; 69 cbContent = sizeof(*pThis->u.pSignedData); 63 70 } 64 71 else if (RTAsn1ObjId_CompareWithString(&pThis->ContentType, RTCRSPCINDIRECTDATACONTENT_OID) == 0) 65 72 { 66 rc = RTAsn1MemAllocZ(&pThis->Content.EncapsulatedAllocation, (void **)&pThis->Content.pEncapsulated, 67 sizeof(*pThis->u.pIndirectDataContent)); 73 enmChoice = RTCRPKCS7CONTENTINFOCHOICE_SPC_INDIRECT_DATA_CONTENT; 74 cbContent = sizeof(*pThis->u.pIndirectDataContent); 75 } 76 else if (RTAsn1ObjId_CompareWithString(&pThis->ContentType, RTCRTSPTSTINFO_OID) == 0) 77 { 78 enmChoice = RTCRPKCS7CONTENTINFOCHOICE_TSP_TST_INFO; 79 cbContent = sizeof(*pThis->u.pTstInfo); 80 } 81 else 82 { 83 enmChoice = RTCRPKCS7CONTENTINFOCHOICE_UNKNOWN; 84 cbContent = 0; 85 } 86 87 int rc = VINF_SUCCESS; 88 if (enmChoice != RTCRPKCS7CONTENTINFOCHOICE_UNKNOWN) 89 { 90 /* 91 * Detect CMS octet string and open the content cursor. 92 * Current we don't have work with any contet which is octet string, 93 * they're all sequences, which make detection so much simpler. 94 */ 95 PRTASN1OCTETSTRING pOctetString = &pThis->Content; 96 RTASN1CURSOR ContentCursor; 97 rc = RTAsn1CursorInitSubFromCore(pCursor, &pThis->Content.Asn1Core, &ContentCursor, "Content"); 98 if ( RT_SUCCESS(rc) 99 && RTAsn1CursorIsNextEx(&ContentCursor, ASN1_TAG_OCTET_STRING, ASN1_TAGFLAG_PRIMITIVE | ASN1_TAGCLASS_UNIVERSAL)) 100 { 101 rc = RTAsn1MemAllocZ(&pThis->Content.EncapsulatedAllocation, (void **)&pThis->Content.pEncapsulated, 102 sizeof(*pOctetString)); 103 if (RT_SUCCESS(rc)) 104 { 105 pThis->pCmsContent = pOctetString = (PRTASN1OCTETSTRING)pThis->Content.pEncapsulated; 106 rc = RTAsn1OctetString_DecodeAsn1(&ContentCursor, 0, pOctetString, "CmsContent"); 107 if (RT_SUCCESS(rc)) 108 rc = RTAsn1CursorCheckEnd(&ContentCursor); 109 if (RT_SUCCESS(rc)) 110 rc = RTAsn1CursorInitSubFromCore(pCursor, &pOctetString->Asn1Core, &ContentCursor, "CmsContent"); 111 } 112 } 68 113 if (RT_SUCCESS(rc)) 69 114 { 70 pThis->u.pCore = pThis->Content.pEncapsulated; 71 rc = RTAsn1CursorInitSubFromCore(pCursor, &pThis->Content.Asn1Core, &ContentCursor, "Content"); 115 /* 116 * Allocate memory for the decoded content. 117 */ 118 rc = RTAsn1MemAllocZ(&pOctetString->EncapsulatedAllocation, (void **)&pOctetString->pEncapsulated, cbContent); 72 119 if (RT_SUCCESS(rc)) 73 rc = RTCrSpcIndirectDataContent_DecodeAsn1(&ContentCursor, 0, pThis->u.pIndirectDataContent, "IndirectDataContent"); 120 { 121 pThis->u.pCore = pOctetString->pEncapsulated; 122 123 /* 124 * Decode it. 125 */ 126 switch (enmChoice) 127 { 128 case RTCRPKCS7CONTENTINFOCHOICE_SIGNED_DATA: 129 rc = RTCrPkcs7SignedData_DecodeAsn1(&ContentCursor, 0, pThis->u.pSignedData, "SignedData"); 130 break; 131 case RTCRPKCS7CONTENTINFOCHOICE_SPC_INDIRECT_DATA_CONTENT: 132 rc = RTCrSpcIndirectDataContent_DecodeAsn1(&ContentCursor, 0, pThis->u.pIndirectDataContent, 133 "IndirectDataContent"); 134 break; 135 case RTCRPKCS7CONTENTINFOCHOICE_TSP_TST_INFO: 136 rc = RTCrTspTstInfo_DecodeAsn1(&ContentCursor, 0, pThis->u.pTstInfo, "TstInfo"); 137 break; 138 default: 139 AssertFailed(); 140 rc = VERR_IPE_NOT_REACHED_DEFAULT_CASE; 141 break; 142 } 143 if (RT_SUCCESS(rc)) 144 rc = RTAsn1CursorCheckEnd(&ContentCursor); 145 if (RT_SUCCESS(rc)) 146 return VINF_SUCCESS; 147 148 RTAsn1MemFree(&pOctetString->EncapsulatedAllocation, pOctetString->pEncapsulated); 149 pOctetString->pEncapsulated = NULL; 150 pThis->u.pCore = NULL; 151 } 74 152 } 75 153 } 76 else77 return VINF_SUCCESS;78 79 if (RT_SUCCESS(rc))80 rc = RTAsn1CursorCheckEnd(&ContentCursor);81 if (RT_SUCCESS(rc))82 return VINF_SUCCESS;83 154 return rc; 84 155 } -
trunk/src/VBox/Runtime/common/crypto/pkcs7-core.cpp
r52537 r52600 34 34 #include <iprt/err.h> 35 35 #include <iprt/string.h> 36 #include <iprt/crypto/tsp.h> 36 37 37 38 #include "pkcs7-internal.h" … … 127 128 128 129 130 RTDECL(PCRTASN1TIME) RTCrPkcs7SignerInfo_GetMsTimestamp(PCRTCRPKCS7SIGNERINFO pThis, PCRTCRPKCS7CONTENTINFO *ppContentInfo) 131 { 132 /* 133 * Assume there is only one, so no need to enumerate anything here. 134 */ 135 uint32_t cAttrsLeft = pThis->UnauthenticatedAttributes.cItems; 136 PCRTCRPKCS7ATTRIBUTE pAttr = pThis->UnauthenticatedAttributes.paItems; 137 while (cAttrsLeft-- > 0) 138 { 139 if (pAttr->enmType == RTCRPKCS7ATTRIBUTETYPE_MS_TIMESTAMP) 140 { 141 uint32_t cLeft = pAttr->uValues.pContentInfos->cItems; 142 PCRTCRPKCS7CONTENTINFO pContentInfo = &pAttr->uValues.pContentInfos->paItems[0]; 143 while (cLeft-- > 0) 144 { 145 if (RTAsn1ObjId_CompareWithString(&pContentInfo->ContentType, RTCRPKCS7SIGNEDDATA_OID) == 0) 146 { 147 if (RTAsn1ObjId_CompareWithString(&pContentInfo->u.pSignedData->ContentInfo.ContentType, 148 RTCRTSPTSTINFO_OID) == 0) 149 { 150 if (ppContentInfo) 151 *ppContentInfo = pContentInfo; 152 return &pContentInfo->u.pSignedData->ContentInfo.u.pTstInfo->GenTime; 153 } 154 } 155 156 pContentInfo++; 157 } 158 } 159 pAttr++; 160 } 161 162 /* 163 * No signature was found. 164 */ 165 if (ppContentInfo) 166 *ppContentInfo = NULL; 167 168 return NULL; 169 } 170 171 129 172 /* 130 173 * PCKS #7 ContentInfo. … … 138 181 139 182 /* 183 * Set of some kind of certificate supported by PKCS #7 or CMS. 184 */ 185 186 RTDECL(PCRTCRX509CERTIFICATE) 187 RTCrPkcs7SetOfCerts_FindX509ByIssuerAndSerialNumber(PCRTCRPKCS7SETOFCERTS pCertificates, 188 PCRTCRX509NAME pIssuer, PCRTASN1INTEGER pSerialNumber) 189 { 190 for (uint32_t i = 0; i < pCertificates->cItems; i++) 191 if ( pCertificates->paItems[i].enmChoice == RTCRPKCS7CERTCHOICE_X509 192 && RTCrX509Certificate_MatchIssuerAndSerialNumber(pCertificates->paItems[i].u.pX509Cert, pIssuer, pSerialNumber)) 193 return pCertificates->paItems[i].u.pX509Cert; 194 return NULL; 195 } 196 197 198 /* 140 199 * Generate the standard core code. 141 200 */ -
trunk/src/VBox/Runtime/common/crypto/pkcs7-sanity.cpp
r51770 r52600 47 47 //RTAsn1Dump(&pSignedData->SeqCore.Asn1Core, 0, 0, RTAsn1DumpStrmPrintfV, g_pStdOut); 48 48 49 if (RTAsn1Integer_UnsignedCompareWithU32(&pSignedData->Version, RTCRPKCS7SIGNEDDATA_V1) != 0) 49 if ( RTAsn1Integer_UnsignedCompareWithU32(&pSignedData->Version, RTCRPKCS7SIGNEDDATA_V1) != 0 50 && RTAsn1Integer_UnsignedCompareWithU32(&pSignedData->Version, RTCRPKCS7SIGNEDDATA_V3) != 0 51 && RTAsn1Integer_UnsignedCompareWithU32(&pSignedData->Version, RTCRPKCS7SIGNEDDATA_V4) != 0 52 && RTAsn1Integer_UnsignedCompareWithU32(&pSignedData->Version, RTCRPKCS7SIGNEDDATA_V5) != 0) 50 53 return RTErrInfoSetF(pErrInfo, VERR_CR_PKCS7_SIGNED_DATA_VERSION, "SignedData version is %llu, expected %u", 51 54 pSignedData->Version.uValue.u, RTCRPKCS7SIGNEDDATA_V1); … … 82 85 "SignedData.Certifcates is empty, expected at least one certificate"); 83 86 84 if (pSignedData->Certificates.cItems > 0)85 {86 int rc = RTCrX509Certificates_CheckSanity(&pSignedData->Certificates, 0, pErrInfo, "SignedData.T0.Certificates");87 if (RT_FAILURE(rc))88 return rc;89 }90 91 87 /* 92 88 * Crls. … … 127 123 128 124 PCRTCRX509CERTIFICATE pCert; 129 pCert = RTCr X509Certificates_FindByIssuerAndSerialNumber(&pSignedData->Certificates,130 &pSignerInfo->IssuerAndSerialNumber.Name,131 &pSignerInfo->IssuerAndSerialNumber.SerialNumber);125 pCert = RTCrPkcs7SetOfCerts_FindX509ByIssuerAndSerialNumber(&pSignedData->Certificates, 126 &pSignerInfo->IssuerAndSerialNumber.Name, 127 &pSignerInfo->IssuerAndSerialNumber.SerialNumber); 132 128 if (!pCert && (fFlags & RTCRPKCS7SIGNEDDATA_SANITY_F_SIGNING_CERT_PRESENT)) 133 129 return RTErrInfoSetF(pErrInfo, VERR_CR_PKCS7_SIGNER_CERT_NOT_SHIPPED, … … 146 142 147 143 /* Digest encryption algorithm. */ 144 #if 0 /** @todo Unimportant: Seen timestamp signatures specifying pkcs1-Sha256WithRsaEncryption in SignerInfo and just RSA in the certificate. Figure out how to compare the two. */ 148 145 if ( pCert 149 146 && RTCrX509AlgorithmIdentifier_Compare(&pSignerInfo->DigestEncryptionAlgorithm, … … 153 150 i, pSignerInfo->DigestEncryptionAlgorithm.Algorithm.szObjId, 154 151 pCert->TbsCertificate.SubjectPublicKeyInfo.Algorithm.Algorithm.szObjId); 152 #endif 155 153 156 154 /* Authenticated attributes we know. */ -
trunk/src/VBox/Runtime/common/crypto/pkcs7-template.h
r52503 r52600 59 59 RTASN1TMPL_MEMBER_DYN( uValues, pSigningTime, RTASN1SETOFTIMES, RTAsn1SetOfTimes, Allocation, 60 60 enmType, RTCRPKCS7ATTRIBUTETYPE_SIGNING_TIME, RTAsn1ObjId_CompareWithString(&pThis->Type, RTCR_PKCS9_ID_SIGNING_TIME_OID) == 0); 61 RTASN1TMPL_MEMBER_DYN( uValues, pContentInfos, RTCRPKCS7SETOFCONTENTINFOS, RTCrPkcs7SetOfContentInfos, Allocation, 62 enmType, RTCRPKCS7ATTRIBUTETYPE_MS_TIMESTAMP, RTAsn1ObjId_CompareWithString(&pThis->Type, RTCR_PKCS9_ID_MS_TIMESTAMP) == 0); 61 63 RTASN1TMPL_MEMBER_DYN_DEFAULT( uValues, pCores, RTASN1SETOFCORES, RTAsn1SetOfCores, Allocation, 62 64 enmType, RTCRPKCS7ATTRIBUTETYPE_UNKNOWN); … … 122 124 RTASN1TMPL_MEMBER( DigestAlgorithms, RTCRX509ALGORITHMIDENTIFIERS, RTCrX509AlgorithmIdentifiers); 123 125 RTASN1TMPL_MEMBER( ContentInfo, RTCRPKCS7CONTENTINFO, RTCrPkcs7ContentInfo); 124 RTASN1TMPL_MEMBER_OPT_ITAG( Certificates, RTCR X509CERTIFICATES, RTCrX509Certificates,0);126 RTASN1TMPL_MEMBER_OPT_ITAG( Certificates, RTCRPKCS7SETOFCERTS, RTCrPkcs7SetOfCerts, 0); 125 127 RTASN1TMPL_MEMBER_OPT_ITAG( Crls, RTASN1CORE, RTAsn1Core, 1); 126 128 RTASN1TMPL_MEMBER( SignerInfos, RTCRPKCS7SIGNERINFOS, RTCrPkcs7SignerInfos); 127 129 RTASN1TMPL_EXEC_CHECK_SANITY( rc = rtCrPkcs7SignedData_CheckSanityExtra(pThis, fFlags, pErrInfo, pszErrorTag) ) /* no ; */ 128 130 RTASN1TMPL_END_SEQCORE(); 131 #undef RTASN1TMPL_TYPE 132 #undef RTASN1TMPL_EXT_NAME 133 #undef RTASN1TMPL_INT_NAME 134 135 136 /* 137 * Set of PCKS #7 SignedData. 138 */ 139 #define RTASN1TMPL_TYPE RTCRPKCS7SETOFSIGNEDDATA 140 #define RTASN1TMPL_EXT_NAME RTCrPkcs7SetOfSignedData 141 #define RTASN1TMPL_INT_NAME rtCrPkcs7SetOfSignedData 142 RTASN1TMPL_SET_OF(RTCRPKCS7SIGNEDDATA, RTCrPkcs7SignedData); 129 143 #undef RTASN1TMPL_TYPE 130 144 #undef RTASN1TMPL_EXT_NAME … … 163 177 #undef RTASN1TMPL_INT_NAME 164 178 179 180 /* 181 * Set of PCKS #7 ContentInfo. 182 */ 183 #define RTASN1TMPL_TYPE RTCRPKCS7SETOFCONTENTINFOS 184 #define RTASN1TMPL_EXT_NAME RTCrPkcs7SetOfContentInfos 185 #define RTASN1TMPL_INT_NAME rtCrPkcs7SetOfContentInfos 186 RTASN1TMPL_SET_OF(RTCRPKCS7CONTENTINFO, RTCrPkcs7ContentInfo); 187 #undef RTASN1TMPL_TYPE 188 #undef RTASN1TMPL_EXT_NAME 189 #undef RTASN1TMPL_INT_NAME 190 191 192 /* 193 * One PKCS #7 ExtendedCertificateOrCertificate or a CMS CertificateChoices (sic). 194 */ 195 #define RTASN1TMPL_TYPE RTCRPKCS7CERT 196 #define RTASN1TMPL_EXT_NAME RTCrPkcs7Cert 197 #define RTASN1TMPL_INT_NAME rtCrPkcs7Cert 198 RTASN1TMPL_BEGIN_PCHOICE(); 199 RTASN1TMPL_PCHOICE_ITAG_UC( ASN1_TAG_SEQUENCE, RTCRPKCS7CERTCHOICE_X509, u.pX509Cert, X509Cert, RTCRX509CERTIFICATE, RTCrX509Certificate); 200 RTASN1TMPL_PCHOICE_ITAG( 0, RTCRPKCS7CERTCHOICE_EXTENDED_PKCS6, u.pExtendedCert, ExtendedCert, RTASN1CORE, RTAsn1Core); 201 RTASN1TMPL_PCHOICE_ITAG( 1, RTCRPKCS7CERTCHOICE_AC_V1, u.pAcV1, AcV1, RTASN1CORE, RTAsn1Core); 202 RTASN1TMPL_PCHOICE_ITAG( 2, RTCRPKCS7CERTCHOICE_AC_V2, u.pAcV2, AcV2, RTASN1CORE, RTAsn1Core); 203 RTASN1TMPL_PCHOICE_ITAG( 3, RTCRPKCS7CERTCHOICE_OTHER, u.pOtherCert, OtherCert, RTASN1CORE, RTAsn1Core); 204 RTASN1TMPL_END_PCHOICE(); 205 #undef RTASN1TMPL_TYPE 206 #undef RTASN1TMPL_EXT_NAME 207 #undef RTASN1TMPL_INT_NAME 208 209 210 /* 211 * Set of PKCS #7 ExtendedCertificateOrCertificate or a CMS CertificateChoices. 212 */ 213 #define RTASN1TMPL_TYPE RTCRPKCS7SETOFCERTS 214 #define RTASN1TMPL_EXT_NAME RTCrPkcs7SetOfCerts 215 #define RTASN1TMPL_INT_NAME rtCrPkcs7SetOfCerts 216 RTASN1TMPL_SET_OF(RTCRPKCS7CERT, RTCrPkcs7Cert); 217 #undef RTASN1TMPL_TYPE 218 #undef RTASN1TMPL_EXT_NAME 219 #undef RTASN1TMPL_INT_NAME 220 -
trunk/src/VBox/Runtime/common/crypto/pkcs7-verify.cpp
r52545 r52600 71 71 if (RT_SUCCESS(rcOssl)) 72 72 { 73 for (uint32_t i = 0; i < pContentInfo->u.pSignedData->Certificates.cItems; i++) 74 rtCrOpenSslAddX509CertToStack(pAddCerts, &pContentInfo->u.pSignedData->Certificates.paItems[i]); 73 PCRTCRPKCS7SETOFCERTS pCerts = &pContentInfo->u.pSignedData->Certificates; 74 for (uint32_t i = 0; i < pCerts->cItems; i++) 75 if (pCerts->paItems[i].enmChoice == RTCRPKCS7CERTCHOICE_X509) 76 rtCrOpenSslAddX509CertToStack(pAddCerts, pCerts->paItems[i].u.pX509Cert); 75 77 76 78 … … 398 400 { 399 401 hSignerCertSrc = NULL; 400 pSignerCert = RTCr X509Certificates_FindByIssuerAndSerialNumber(&pSignedData->Certificates,401 &pSignerInfo->IssuerAndSerialNumber.Name,402 &pSignerInfo->IssuerAndSerialNumber.SerialNumber);402 pSignerCert = RTCrPkcs7SetOfCerts_FindX509ByIssuerAndSerialNumber(&pSignedData->Certificates, 403 &pSignerInfo->IssuerAndSerialNumber.Name, 404 &pSignerInfo->IssuerAndSerialNumber.SerialNumber); 403 405 if (!pSignerCert) 404 406 return RTErrInfoSetF(pErrInfo, VERR_CR_PKCS7_SIGNED_DATA_CERT_NOT_FOUND, … … 426 428 rc = RTCrX509CertPathsSetUntrustedStore(hCertPaths, hAdditionalCerts); 427 429 if (pSignedData->Certificates.cItems > 0 && RT_SUCCESS(rc)) 428 rc = RTCrX509CertPathsSetUntrustedArray(hCertPaths, 429 pSignedData->Certificates.paItems, 430 pSignedData->Certificates.cItems); 430 rc = RTCrX509CertPathsSetUntrustedSet(hCertPaths, &pSignedData->Certificates); 431 431 if (RT_SUCCESS(rc)) 432 432 { … … 586 586 return rc; 587 587 588 AssertReturn(!(fFlags & RTCRPKCS7VERIFY_SD_F_COUNTER_SIGNATURE), VERR_INVALID_FLAGS);589 590 588 /* 591 589 * Hash the content info. … … 640 638 * Validate the signed infos. 641 639 */ 640 uint32_t fPrimaryVccFlags = !(fFlags & RTCRPKCS7VERIFY_SD_F_USAGE_TIMESTAMPING) 641 ? RTCRPKCS7VCC_F_SIGNED_DATA : RTCRPKCS7VCC_F_TIMESTAMP; 642 642 rc = VERR_CR_PKCS7_NO_SIGNER_INFOS; 643 643 for (i = 0; i < pSignedData->SignerInfos.cItems; i++) … … 651 651 /* 652 652 * See if we can find a trusted signing time. 653 * (Note that while it would make sense splitting up this function, 654 * we need to carry a lot of arguments around, so better not.) 653 655 */ 654 656 bool fDone = false; … … 667 669 rc = rtCrPkcs7VerifySignerInfo(pSignerInfo, pSignedData, hThisDigest, fFlags, 668 670 hAdditionalCerts, hTrustedCerts, &ThisValidationTime, 669 pfnVerifyCert, RTCRPKCS7VCC_F_SIGNED_DATA| RTCRPKCS7VCC_F_TIMESTAMP,671 pfnVerifyCert, fPrimaryVccFlags | RTCRPKCS7VCC_F_TIMESTAMP, 670 672 pvUser, pErrInfo); 671 673 } … … 680 682 rc = rtCrPkcs7VerifySignerInfo(pSignerInfo, pSignedData, hThisDigest, fFlags, hAdditionalCerts, 681 683 hTrustedCerts, &ThisValidationTime, 682 pfnVerifyCert, RTCRPKCS7VCC_F_SIGNED_DATA, pvUser, pErrInfo);684 pfnVerifyCert, fPrimaryVccFlags, pvUser, pErrInfo); 683 685 } 684 686 fDone = RT_SUCCESS(rc) … … 693 695 694 696 /* 697 * If not luck, check for microsoft timestamp counter signatures. 698 */ 699 if (!fDone && !(fFlags & RTCRPKCS7VERIFY_SD_F_IGNORE_MS_TIMESTAMP)) 700 { 701 PCRTCRPKCS7CONTENTINFO pSignedTimestamp = NULL; 702 pSignedTime = RTCrPkcs7SignerInfo_GetMsTimestamp(pSignerInfo, &pSignedTimestamp); 703 if (pSignedTime) 704 { 705 RTTIMESPEC ThisValidationTime; 706 if (RT_LIKELY(RTTimeImplode(&ThisValidationTime, &pSignedTime->Time))) 707 { 708 rc = VINF_SUCCESS; 709 if (!(fFlags & RTCRPKCS7VERIFY_SD_F_USE_MS_TIMESTAMP_UNVERIFIED)) 710 rc = RTCrPkcs7VerifySignedData(pSignedTimestamp, 711 fFlags | RTCRPKCS7VERIFY_SD_F_IGNORE_MS_TIMESTAMP 712 | RTCRPKCS7VERIFY_SD_F_USAGE_TIMESTAMPING, 713 hAdditionalCerts, hTrustedCerts, &ThisValidationTime, 714 pfnVerifyCert, pvUser, pErrInfo); 715 716 if (RT_SUCCESS(rc)) 717 rc = rtCrPkcs7VerifySignerInfo(pSignerInfo, pSignedData, hThisDigest, fFlags, hAdditionalCerts, 718 hTrustedCerts, &ThisValidationTime, 719 pfnVerifyCert, fPrimaryVccFlags, pvUser, pErrInfo); 720 fDone = RT_SUCCESS(rc) 721 || (fFlags & RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_MS_TIMESTAMP_IF_PRESENT); 722 } 723 else 724 { 725 rc = RTErrInfoSet(pErrInfo, VERR_INTERNAL_ERROR_3, "RTTimeImplode failed"); 726 fDone = true; 727 } 728 729 } 730 } 731 732 /* 695 733 * No valid signing time found, use the one specified instead. 696 734 */ 697 735 if (!fDone) 698 736 rc = rtCrPkcs7VerifySignerInfo(pSignerInfo, pSignedData, hThisDigest, fFlags, hAdditionalCerts, hTrustedCerts, 699 pValidationTime, pfnVerifyCert, RTCRPKCS7VCC_F_SIGNED_DATA, pvUser, pErrInfo);737 pValidationTime, pfnVerifyCert, fPrimaryVccFlags, pvUser, pErrInfo); 700 738 RTCrDigestRelease(hThisDigest); 701 739 if (RT_FAILURE(rc)) … … 721 759 * Verify using OpenSSL and combine the results (should be identical). 722 760 */ 761 /** @todo figure out how to verify MS timstamp signatures using OpenSSL. */ 762 if (fFlags & RTCRPKCS7VERIFY_SD_F_USAGE_TIMESTAMPING) 763 return rc; 723 764 int rcOssl = rtCrPkcs7VerifySignedDataUsingOpenSsl(pContentInfo, fFlags, hAdditionalCerts, hTrustedCerts, 724 765 pvContent, cbContent, RT_SUCCESS(rc) ? pErrInfo : NULL); -
trunk/src/VBox/Runtime/common/crypto/x509-certpaths.cpp
r51823 r52600 39 39 #include <iprt/list.h> 40 40 #include <iprt/time.h> 41 #include <iprt/crypto/pkcs7.h> /* PCRTCRPKCS7SETOFCERTS */ 41 42 #include <iprt/crypto/store.h> 42 43 … … 92 93 #define RTCRX509CERTPATHNODE_SRC_NONE 0 93 94 #define RTCRX509CERTPATHNODE_SRC_TARGET 1 94 #define RTCRX509CERTPATHNODE_SRC_UNTRUSTED_ARRAY 2 95 #define RTCRX509CERTPATHNODE_SRC_UNTRUSTED_STORE 3 96 #define RTCRX509CERTPATHNODE_SRC_TRUSTED_STORE 4 97 #define RTCRX509CERTPATHNODE_SRC_TRUSTED_CERT 5 95 #define RTCRX509CERTPATHNODE_SRC_UNTRUSTED_SET 2 96 #define RTCRX509CERTPATHNODE_SRC_UNTRUSTED_ARRAY 3 97 #define RTCRX509CERTPATHNODE_SRC_UNTRUSTED_STORE 4 98 #define RTCRX509CERTPATHNODE_SRC_TRUSTED_STORE 5 99 #define RTCRX509CERTPATHNODE_SRC_TRUSTED_CERT 6 98 100 #define RTCRX509CERTPATHNODE_SRC_IS_TRUSTED(uSrc) ((uSrc) >= RTCRX509CERTPATHNODE_SRC_TRUSTED_STORE) 99 101 /** @} */ … … 164 166 /** Store of untrusted certificates. */ 165 167 RTCRSTORE hUntrustedStore; 166 /** Array of untrusted certificates, typically from the protocol (like the 167 * certificates member of PKCS \#7 SignedData). */ 168 /** Array of untrusted certificates, typically from the protocol. */ 168 169 PCRTCRX509CERTIFICATE paUntrustedCerts; 169 170 /** Number of entries in paUntrusted. */ 170 171 uint32_t cUntrustedCerts; 172 /** Set of untrusted PKCS \#7 / CMS certificatess. */ 173 PCRTCRPKCS7SETOFCERTS pUntrustedCertsSet; 171 174 172 175 /** UTC time we're going to validate the path at, requires … … 364 367 pThis->hUntrustedStore = NIL_RTCRSTORE; 365 368 pThis->paUntrustedCerts = NULL; /* Referencing user memory. */ 369 pThis->pUntrustedCertsSet = NULL; /* Referencing user memory. */ 366 370 pThis->papInitialUserPolicySet = NULL; /* Referencing user memory. */ 367 371 pThis->pInitialPermittedSubtrees = NULL; /* Referencing user memory. */ … … 438 442 pThis->paUntrustedCerts = paCerts; 439 443 pThis->cUntrustedCerts = cCerts; 444 return VINF_SUCCESS; 445 } 446 447 448 RTDECL(int) RTCrX509CertPathsSetUntrustedSet(RTCRX509CERTPATHS hCertPaths, PCRTCRPKCS7SETOFCERTS pSetOfCerts) 449 { 450 PRTCRX509CERTPATHSINT pThis = hCertPaths; 451 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 452 AssertReturn(pThis->u32Magic == RTCRX509CERTPATHSINT_MAGIC, VERR_INVALID_HANDLE); 453 454 pThis->pUntrustedCertsSet = pSetOfCerts; 440 455 return VINF_SUCCESS; 441 456 } … … 694 709 if (RTCrX509Certificate_MatchSubjectOrAltSubjectByRfc5280(&pThis->paUntrustedCerts[i], pIssuer)) 695 710 rtCrX509CertPathsAddIssuer(pThis, pNode, &pThis->paUntrustedCerts[i], NULL, 696 RTCRX509CERTPATHNODE_SRC_UNTRUSTED_ARRAY); 711 RTCRX509CERTPATHNODE_SRC_UNTRUSTED_ARRAY); 712 713 /** @todo Rainy day: Should abstract the untrusted array and set so we don't get 714 * unnecessary PKCS7/CMS header dependencies. */ 715 716 /* 717 * Untrusted set. 718 */ 719 if (pThis->pUntrustedCertsSet) 720 { 721 uint32_t const cCerts = pThis->pUntrustedCertsSet->cItems; 722 PCRTCRPKCS7CERT paCerts = pThis->pUntrustedCertsSet->paItems; 723 for (uint32_t i = 0; i < cCerts; i++) 724 if ( paCerts[i].enmChoice == RTCRPKCS7CERTCHOICE_X509 725 && RTCrX509Certificate_MatchSubjectOrAltSubjectByRfc5280(paCerts[i].u.pX509Cert, pIssuer)) 726 rtCrX509CertPathsAddIssuer(pThis, pNode, paCerts[i].u.pX509Cert, NULL, RTCRX509CERTPATHNODE_SRC_UNTRUSTED_SET); 727 } 697 728 } 698 729 … … 1084 1115 { 1085 1116 case RTCRX509CERTPATHNODE_SRC_TARGET: return "target"; 1117 case RTCRX509CERTPATHNODE_SRC_UNTRUSTED_SET: return "untrusted_set"; 1086 1118 case RTCRX509CERTPATHNODE_SRC_UNTRUSTED_ARRAY: return "untrusted_array"; 1087 1119 case RTCRX509CERTPATHNODE_SRC_UNTRUSTED_STORE: return "untrusted_store"; -
trunk/src/VBox/Runtime/tools/RTSignTool.cpp
r52538 r52600 183 183 PCRTCRPKCS7ISSUERANDSERIALNUMBER pISN = &pSd->SignerInfos.paItems[0].IssuerAndSerialNumber; 184 184 PCRTCRX509CERTIFICATE pCert; 185 pCert = RTCr X509Certificates_FindByIssuerAndSerialNumber(&pSd->Certificates,186 &pISN->Name, &pISN->SerialNumber);185 pCert = RTCrPkcs7SetOfCerts_FindX509ByIssuerAndSerialNumber(&pSd->Certificates, 186 &pISN->Name, &pISN->SerialNumber); 187 187 if (pCert) 188 188 { … … 404 404 return RTCrPkcs7VerifySignedData(pContentInfo, 405 405 RTCRPKCS7VERIFY_SD_F_COUNTER_SIGNATURE_SIGNING_TIME_ONLY 406 | RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_SIGNING_TIME_IF_PRESENT, 406 | RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_SIGNING_TIME_IF_PRESENT 407 | RTCRPKCS7VERIFY_SD_F_ALWAYS_USE_MS_TIMESTAMP_IF_PRESENT, 407 408 pState->hAdditionalStore, pState->hRootStore, &ValidationTime, 408 409 VerifyExecCertVerifyCallback, pState, pErrInfo);
Note:
See TracChangeset
for help on using the changeset viewer.