Changeset 64926 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Dec 16, 2016 9:43:08 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/tools/RTSignTool.cpp
r64916 r64926 473 473 return RTEXITCODE_FAILURE; 474 474 } 475 476 477 478 /** 479 * Worker for recursively searching for MS nested signatures and signer infos. 480 * 481 * @returns Pointer to the signer info corresponding to @a iSignature. NULL if 482 * not found. 483 * @param pSignedData The signature to search. 484 * @param piNextSignature Pointer to the variable keeping track of the next 485 * signature number. 486 * @param iReqSignature The request signature number. 487 * @param ppSignedData Where to return the signature data structure. 488 */ 489 static PRTCRPKCS7SIGNERINFO SignToolPkcs7_FindNestedSignatureByIndexWorker(PRTCRPKCS7SIGNEDDATA pSignedData, 490 uint32_t *piNextSignature, 491 uint32_t iReqSignature, 492 PRTCRPKCS7SIGNEDDATA *ppSignedData) 493 { 494 for (uint32_t iSignerInfo = 0; iSignerInfo < pSignedData->SignerInfos.cItems; iSignerInfo++) 495 { 496 /* Match?*/ 497 PRTCRPKCS7SIGNERINFO pSignerInfo = pSignedData->SignerInfos.papItems[iSignerInfo]; 498 if (*piNextSignature == iReqSignature) 499 { 500 *ppSignedData = pSignedData; 501 return pSignerInfo; 502 } 503 *piNextSignature += 1; 504 505 /* Look for nested signatures. */ 506 for (uint32_t iAttrib = 0; iAttrib < pSignerInfo->UnauthenticatedAttributes.cItems; iAttrib++) 507 if (pSignerInfo->UnauthenticatedAttributes.papItems[iAttrib]->enmType == RTCRPKCS7ATTRIBUTETYPE_MS_NESTED_SIGNATURE) 508 { 509 PRTCRPKCS7SETOFCONTENTINFOS pCntInfos; 510 pCntInfos = pSignerInfo->UnauthenticatedAttributes.papItems[iAttrib]->uValues.pContentInfos; 511 for (uint32_t iCntInfo = 0; iCntInfo < pCntInfos->cItems; iCntInfo++) 512 { 513 PRTCRPKCS7CONTENTINFO pCntInfo = pCntInfos->papItems[iCntInfo]; 514 if (RTCrPkcs7ContentInfo_IsSignedData(pCntInfo)) 515 { 516 PRTCRPKCS7SIGNERINFO pRet; 517 pRet = SignToolPkcs7_FindNestedSignatureByIndexWorker(pCntInfo->u.pSignedData, piNextSignature, 518 iReqSignature, ppSignedData); 519 if (pRet) 520 return pRet; 521 } 522 } 523 } 524 } 525 return NULL; 526 } 527 528 529 /** 530 * Locates the given nested signature. 531 * 532 * @returns Pointer to the signer info corresponding to @a iSignature. NULL if 533 * not found. 534 * @param pThis The PKCS\#7 structure to search. 535 * @param iReqSignature The requested signature number. 536 * @param ppSignedData Where to return the pointer to the signed data that 537 * the returned signer info belongs to. 538 * 539 * @todo Move into SPC or PKCS\#7. 540 */ 541 static PRTCRPKCS7SIGNERINFO SignToolPkcs7_FindNestedSignatureByIndex(PSIGNTOOLPKCS7 pThis, uint32_t iReqSignature, 542 PRTCRPKCS7SIGNEDDATA *ppSignedData) 543 { 544 uint32_t iNextSignature = 0; 545 return SignToolPkcs7_FindNestedSignatureByIndexWorker(pThis->pSignedData, &iNextSignature, iReqSignature, ppSignedData); 546 } 547 475 548 476 549 … … 797 870 { 798 871 RT_NOREF_PV(enmLevel); 799 RTStrmPrintf(pStrm, "extract-exe-signer-cert [--ber|--cer|--der] [-- exe|-e] <exe> [--output|-o] <outfile.cer>\n");872 RTStrmPrintf(pStrm, "extract-exe-signer-cert [--ber|--cer|--der] [--signature-index|-i <num>] [--exe|-e] <exe> [--output|-o] <outfile.cer>\n"); 800 873 return RTEXITCODE_SUCCESS; 801 874 } … … 808 881 static const RTGETOPTDEF s_aOptions[] = 809 882 { 810 { "--ber", 'b', RTGETOPT_REQ_NOTHING }, 811 { "--cer", 'c', RTGETOPT_REQ_NOTHING }, 812 { "--der", 'd', RTGETOPT_REQ_NOTHING }, 813 { "--exe", 'e', RTGETOPT_REQ_STRING }, 814 { "--output", 'o', RTGETOPT_REQ_STRING }, 883 { "--ber", 'b', RTGETOPT_REQ_NOTHING }, 884 { "--cer", 'c', RTGETOPT_REQ_NOTHING }, 885 { "--der", 'd', RTGETOPT_REQ_NOTHING }, 886 { "--exe", 'e', RTGETOPT_REQ_STRING }, 887 { "--output", 'o', RTGETOPT_REQ_STRING }, 888 { "--signature-index", 'i', RTGETOPT_REQ_UINT32 }, 815 889 }; 816 890 … … 820 894 unsigned cVerbosity = 0; 821 895 uint32_t fCursorFlags = RTASN1CURSOR_FLAGS_DER; 896 uint32_t iSignature = 0; 822 897 823 898 RTGETOPTSTATE GetState; … … 835 910 case 'c': fCursorFlags = RTASN1CURSOR_FLAGS_CER; break; 836 911 case 'd': fCursorFlags = RTASN1CURSOR_FLAGS_DER; break; 912 case 'i': iSignature = ValueUnion.u32; break; 837 913 case 'V': return HandleVersion(cArgs, papszArgs); 838 914 case 'h': return HelpExtractExeSignerCert(g_pStdOut, RTSIGNTOOLHELP_FULL); … … 866 942 if (rcExit == RTEXITCODE_SUCCESS) 867 943 { 868 /* Find the signing certificate (ASSUMING there's only one signer and that 869 the certificate used is shipped in the set of certificates). */ 944 /* Find the signing certificate (ASSUMING that the certificate used is shipped in the set of certificates). */ 945 PRTCRPKCS7SIGNEDDATA pSignedData; 946 PCRTCRPKCS7SIGNERINFO pSignerInfo = SignToolPkcs7_FindNestedSignatureByIndex(&This, iSignature, &pSignedData); 870 947 rcExit = RTEXITCODE_FAILURE; 871 if ( This.pSignedData->SignerInfos.cItems == 1)872 { 873 PCRTCRPKCS7ISSUERANDSERIALNUMBER pISN = & This.pSignedData->SignerInfos.papItems[0]->IssuerAndSerialNumber;948 if (pSignerInfo) 949 { 950 PCRTCRPKCS7ISSUERANDSERIALNUMBER pISN = &pSignedData->SignerInfos.papItems[0]->IssuerAndSerialNumber; 874 951 PCRTCRX509CERTIFICATE pCert; 875 pCert = RTCrPkcs7SetOfCerts_FindX509ByIssuerAndSerialNumber(& This.pSignedData->Certificates,952 pCert = RTCrPkcs7SetOfCerts_FindX509ByIssuerAndSerialNumber(&pSignedData->Certificates, 876 953 &pISN->Name, &pISN->SerialNumber); 877 954 if (pCert) … … 910 987 } 911 988 else 912 RTMsgError("SignerInfo count: %u", This.pSignedData->SignerInfos.cItems); 913 989 RTMsgError("Could not locate signature #%u!", iSignature); 914 990 915 991 /* Delete the signature data. */
Note:
See TracChangeset
for help on using the changeset viewer.