VirtualBox

Changeset 64903 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Dec 16, 2016 12:12:05 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
112312
Message:

RTSignTool: Added add-nested-cat-signature and show-cat commands.

Location:
trunk/src/VBox/Runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/asn1/oiddb.cfg

    r64867 r64903  
    1171171.3.6.1.4.1.311.3.3.1           = Ms-CounterSign
    1181181.3.6.1.4.1.311.3.3.2           = Ms-??-3.2
    119 1.3.6.1.4.1.311.10.3.1          = Ms-CertTrustListSigning
    120 1.3.6.1.4.1.311.10.3.2          = Ms-TimeStampSigning
     1191.3.6.1.4.1.311.10.1            = Ms-CertTrustList
     1201.3.6.1.4.1.311.10.1.1          = Ms-SortedCertTrustList
     1211.3.6.1.4.1.311.10.3.1          = Ms-kp-CertTrustListSigning
     1221.3.6.1.4.1.311.10.3.2          = Ms-kp-TimeStampSigning
    1211231.3.6.1.4.1.311.10.3.4          = Ms-EncryptedFileSystem
    1221241.3.6.1.4.1.311.10.3.5          = Ms-WhqlCrypto
  • trunk/src/VBox/Runtime/tools/RTSignTool.cpp

    r64897 r64903  
    180180 * @returns IPRT status code (error message already shown on failure).
    181181 * @param   pThis               The PKCS\#7 signature to decode.
    182  */
    183 static int SignToolPkcs7_Decode(PSIGNTOOLPKCS7 pThis)
     182 * @param   fCatalog            Set if catalog file, clear if executable.
     183 */
     184static int SignToolPkcs7_Decode(PSIGNTOOLPKCS7 pThis, bool fCatalog)
    184185{
    185186    RTERRINFOSTATIC     ErrInfo;
     
    211212                                                     | RTCRPKCS7SIGNEDDATA_SANITY_F_SIGNING_CERT_PRESENT,
    212213                                                     RTErrInfoInitStatic(&ErrInfo), "SD");
    213                 if (RT_FAILURE(rc))
    214                     RTMsgError("PKCS#7 sanity check failed for '%s': %Rrc - %s\n", pThis->pszFilename, rc, ErrInfo.szMsg);
    215214                if (RT_SUCCESS(rc))
    216215                {
     
    223222                                   pThis->pszFilename, rc, ErrInfo.szMsg);
    224223                }
     224                else
     225                    RTMsgError("PKCS#7 sanity check failed for '%s': %Rrc - %s\n", pThis->pszFilename, rc, ErrInfo.szMsg);
    225226            }
    226             else
     227            else if (!fCatalog)
    227228                RTMsgError("Unexpected the signed content in '%s': %s (expected %s)", pThis->pszFilename,
    228229                           pThis->pSignedData->ContentInfo.ContentType.szObjId, RTCRSPCINDIRECTDATACONTENT_OID);
    229230        }
    230231        else
    231             RTMsgError("PKCS#7 content is inside '%s' is not 'signedData': %s\n",
    232                        pThis->pszFilename, pThis->ContentInfo.ContentType.szObjId);
     232            rc = RTMsgErrorRc(VERR_CR_PKCS7_NOT_SIGNED_DATA,
     233                              "PKCS#7 content is inside '%s' is not 'signedData': %s\n",
     234                              pThis->pszFilename, pThis->ContentInfo.ContentType.szObjId);
    233235    }
    234236    else
    235237        RTMsgError("RTCrPkcs7ContentInfo_DecodeAsn1 failed on '%s': %Rrc - %s\n", pThis->pszFilename, rc, ErrInfo.szMsg);
    236238    return rc;
     239}
     240
     241
     242/**
     243 * Reads and decodes PKCS\#7 signature from the given cat file.
     244 *
     245 * @returns RTEXITCODE_SUCCESS on success, RTEXITCODE_FAILURE with error message
     246 *          on failure.
     247 * @param   pThis               The structure to initialize.
     248 * @param   pszFilename         The catalog (or any other DER PKCS\#7) filename.
     249 * @param   cVerbosity          The verbosity.
     250 */
     251static RTEXITCODE SignToolPkcs7_InitFromFile(PSIGNTOOLPKCS7 pThis, const char *pszFilename, unsigned cVerbosity)
     252{
     253    /*
     254     * Init the return structure.
     255     */
     256    RT_ZERO(*pThis);
     257    pThis->pszFilename = pszFilename;
     258
     259    /*
     260     * Lazy bird uses RTFileReadAll and duplicates the allocation.
     261     */
     262    void *pvFile;
     263    int rc = RTFileReadAll(pszFilename, &pvFile, &pThis->cbBuf);
     264    if (RT_SUCCESS(rc))
     265    {
     266        pThis->pbBuf = (uint8_t *)RTMemDup(pvFile, pThis->cbBuf);
     267        RTFileReadAllFree(pvFile, pThis->cbBuf);
     268        if (pThis->pbBuf)
     269        {
     270            if (cVerbosity > 2)
     271                RTPrintf("PKCS#7 signature: %u bytes\n", pThis->cbBuf);
     272
     273            /*
     274             * Decode it.
     275             */
     276            rc = SignToolPkcs7_Decode(pThis, true /*fCatalog*/);
     277            if (RT_SUCCESS(rc))
     278                return RTEXITCODE_SUCCESS;
     279        }
     280        else
     281            RTMsgError("Out of memory!");
     282    }
     283    else
     284        RTMsgError("Error reading '%s' into memory: %Rrc", pszFilename, rc);
     285
     286    SignToolPkcs7_Delete(pThis);
     287    return RTEXITCODE_FAILURE;
    237288}
    238289
     
    358409}
    359410
     411
     412/**
     413 * Writes the signature to the file.
     414 *
     415 * Caller must have called SignToolPkcs7_Encode() prior to this function.
     416 *
     417 * @returns RTEXITCODE_SUCCESS on success, RTEXITCODE_FAILURE with error
     418 *          message on failure.
     419 * @param   pThis               The file which to write.
     420 * @param   cVerbosity          The verbosity.
     421 */
     422static RTEXITCODE SignToolPkcs7_WriteSignatureToFile(PSIGNTOOLPKCS7 pThis, const char *pszFilename, unsigned cVerbosity)
     423{
     424    AssertReturn(pThis->cbNewBuf && pThis->pbNewBuf, RTEXITCODE_FAILURE);
     425
     426    /*
     427     * Open+truncate file, write new signature, close.  Simple.
     428     */
     429    RTFILE hFile;
     430    int rc = RTFileOpen(&hFile, pszFilename, RTFILE_O_WRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_TRUNCATE | RTFILE_O_DENY_WRITE);
     431    if (RT_SUCCESS(rc))
     432    {
     433        rc = RTFileWrite(hFile, pThis->pbNewBuf, pThis->cbNewBuf, NULL);
     434        if (RT_SUCCESS(rc))
     435        {
     436            rc = RTFileClose(hFile);
     437            if (RT_SUCCESS(rc))
     438            {
     439                if (cVerbosity > 0)
     440                    RTMsgInfo("Wrote %u bytes to %s", pThis->cbNewBuf, pszFilename);
     441                return RTEXITCODE_SUCCESS;
     442            }
     443
     444            RTMsgError("RTFileClose failed on %s: %Rrc", pszFilename, rc);
     445        }
     446        else
     447            RTMsgError("Write error on %s: %Rrc", pszFilename, rc);
     448    }
     449    else
     450        RTMsgError("Failed to open %s for writing: %Rrc", pszFilename, rc);
     451    return RTEXITCODE_FAILURE;
     452}
    360453
    361454
     
    428521                 * Decode it.
    429522                 */
    430                 rc = SignToolPkcs7_Decode(pThis);
     523                rc = SignToolPkcs7_Decode(pThis, false /*fCatalog*/);
    431524                if (RT_SUCCESS(rc))
    432525                    return RTEXITCODE_SUCCESS;
     
    445538    SignToolPkcs7Exe_Delete(pThis);
    446539    return RTEXITCODE_FAILURE;
    447 
    448540}
    449541
     
    812904{
    813905    RT_NOREF_PV(enmLevel);
    814     RTStrmPrintf(pStrm, "add-nested-exe-signature [-v|--verbose] <destination-exe> <source-exe>\n");
     906    RTStrmPrintf(pStrm, "add-nested-exe-signature [-v|--verbose] [-d|--debug] <destination-exe> <source-exe>\n");
     907    if (enmLevel == RTSIGNTOOLHELP_FULL)
     908        RTStrmPrintf(pStrm,
     909                     "\n"
     910                     "The --debug option allows the source-exe to be omitted in order to test the\n"
     911                     "encoding and PE file modification.\n");
    815912    return RTEXITCODE_SUCCESS;
    816913}
     
    825922    {
    826923        { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
     924        { "--debug",   'd', RTGETOPT_REQ_NOTHING },
    827925    };
    828926
    829     const char *pszDst = NULL;
    830     const char *pszSrc = NULL;
     927    const char *pszDst     = NULL;
     928    const char *pszSrc     = NULL;
    831929    unsigned    cVerbosity = 0;
     930    bool        fDebug     = false;
    832931
    833932    RTGETOPTSTATE GetState;
     
    841940        {
    842941            case 'v':   cVerbosity++; break;
     942            case 'd':   fDebug = pszSrc == NULL; break;
    843943            case 'V':   return HandleVersion(cArgs, papszArgs);
    844944            case 'h':   return HelpAddNestedExeSignature(g_pStdOut, RTSIGNTOOLHELP_FULL);
     
    848948                    pszDst = ValueUnion.psz;
    849949                else if (!pszSrc)
     950                {
    850951                    pszSrc = ValueUnion.psz;
     952                    fDebug = false;
     953                }
    851954                else
    852955                    return RTMsgErrorExit(RTEXITCODE_FAILURE, "Too many file arguments: %s", ValueUnion.psz);
     
    858961    }
    859962    if (!pszDst)
    860         return RTMsgErrorExit(RTEXITCODE_FAILURE, "No destination excutable given.");
    861     if (!pszSrc)
     963        return RTMsgErrorExit(RTEXITCODE_FAILURE, "No destination executable given.");
     964    if (!pszSrc && !fDebug)
    862965        return RTMsgErrorExit(RTEXITCODE_FAILURE, "No source executable file given.");
    863966
     
    867970    /* Read & decode the source PKCS#7 signature. */
    868971    SIGNTOOLPKCS7EXE Src;
    869     RTEXITCODE rcExit = SignToolPkcs7Exe_InitFromFile(&Src, pszSrc, cVerbosity);
     972    RTEXITCODE rcExit = pszSrc ? SignToolPkcs7Exe_InitFromFile(&Src, pszSrc, cVerbosity) : RTEXITCODE_SUCCESS;
    870973    if (rcExit == RTEXITCODE_SUCCESS)
    871974    {
     
    876979        {
    877980            /* Do the signature manipulation. */
    878             rcExit = SignToolPkcs7_AddNestedSignature(&Dst, &Src, cVerbosity);
     981            if (pszSrc)
     982                rcExit = SignToolPkcs7_AddNestedSignature(&Dst, &Src, cVerbosity);
    879983            if (rcExit == RTEXITCODE_SUCCESS)
    880984                rcExit = SignToolPkcs7_Encode(&Dst, cVerbosity);
     
    886990            SignToolPkcs7Exe_Delete(&Dst);
    887991        }
    888         SignToolPkcs7Exe_Delete(&Src);
     992        if (pszSrc)
     993            SignToolPkcs7Exe_Delete(&Src);
     994    }
     995
     996    return rcExit;
     997}
     998
     999
     1000/*
     1001 * The 'add-nested-cat-signature' command.
     1002 */
     1003static RTEXITCODE HelpAddNestedCatSignature(PRTSTREAM pStrm, RTSIGNTOOLHELP enmLevel)
     1004{
     1005    RT_NOREF_PV(enmLevel);
     1006    RTStrmPrintf(pStrm, "add-nested-cat-signature [-v|--verbose] <destination-cat> <source-cat>\n");
     1007    if (enmLevel == RTSIGNTOOLHELP_FULL)
     1008        RTStrmPrintf(pStrm,
     1009                     "\n"
     1010                     "The --debug option allows the source-cat to be omitted in order to test the\n"
     1011                     "ASN.1 re-encoding of the destination catalog file.\n");
     1012    return RTEXITCODE_SUCCESS;
     1013}
     1014
     1015
     1016static RTEXITCODE HandleAddNestedCatSignature(int cArgs, char **papszArgs)
     1017{
     1018    /*
     1019     * Parse arguments.
     1020     */
     1021    static const RTGETOPTDEF s_aOptions[] =
     1022    {
     1023        { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
     1024        { "--debug",   'd', RTGETOPT_REQ_NOTHING },
     1025    };
     1026
     1027    const char *pszDst     = NULL;
     1028    const char *pszSrc     = NULL;
     1029    unsigned    cVerbosity = 0;
     1030    bool        fDebug     = false;
     1031
     1032    RTGETOPTSTATE GetState;
     1033    int rc = RTGetOptInit(&GetState, cArgs, papszArgs, s_aOptions, RT_ELEMENTS(s_aOptions), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
     1034    AssertRCReturn(rc, RTEXITCODE_FAILURE);
     1035    RTGETOPTUNION ValueUnion;
     1036    int ch;
     1037    while ((ch = RTGetOpt(&GetState, &ValueUnion)))
     1038    {
     1039        switch (ch)
     1040        {
     1041            case 'v':   cVerbosity++; break;
     1042            case 'd':   fDebug = pszSrc == NULL; break;
     1043            case 'V':   return HandleVersion(cArgs, papszArgs);
     1044            case 'h':   return HelpAddNestedCatSignature(g_pStdOut, RTSIGNTOOLHELP_FULL);
     1045
     1046            case VINF_GETOPT_NOT_OPTION:
     1047                if (!pszDst)
     1048                    pszDst = ValueUnion.psz;
     1049                else if (!pszSrc)
     1050                {
     1051                    pszSrc = ValueUnion.psz;
     1052                    fDebug = false;
     1053                }
     1054                else
     1055                    return RTMsgErrorExit(RTEXITCODE_FAILURE, "Too many file arguments: %s", ValueUnion.psz);
     1056                break;
     1057
     1058            default:
     1059                return RTGetOptPrintError(ch, &ValueUnion);
     1060        }
     1061    }
     1062    if (!pszDst)
     1063        return RTMsgErrorExit(RTEXITCODE_FAILURE, "No destination catalog file given.");
     1064    if (!pszSrc && !fDebug)
     1065        return RTMsgErrorExit(RTEXITCODE_FAILURE, "No source catalog file given.");
     1066
     1067    /*
     1068     * Do it.
     1069     */
     1070    /* Read & decode the source PKCS#7 signature. */
     1071    SIGNTOOLPKCS7 Src;
     1072    RTEXITCODE rcExit = pszSrc ? SignToolPkcs7_InitFromFile(&Src, pszSrc, cVerbosity) : RTEXITCODE_SUCCESS;
     1073    if (rcExit == RTEXITCODE_SUCCESS)
     1074    {
     1075        /* Ditto for the destination PKCS#7 signature. */
     1076        SIGNTOOLPKCS7EXE Dst;
     1077        rcExit = SignToolPkcs7_InitFromFile(&Dst, pszDst, cVerbosity);
     1078        if (rcExit == RTEXITCODE_SUCCESS)
     1079        {
     1080            /* Do the signature manipulation. */
     1081            if (pszSrc)
     1082                rcExit = SignToolPkcs7_AddNestedSignature(&Dst, &Src, cVerbosity);
     1083            if (rcExit == RTEXITCODE_SUCCESS)
     1084                rcExit = SignToolPkcs7_Encode(&Dst, cVerbosity);
     1085
     1086            /* Update the destination executable file. */
     1087            if (rcExit == RTEXITCODE_SUCCESS)
     1088                rcExit = SignToolPkcs7_WriteSignatureToFile(&Dst, pszDst, cVerbosity);
     1089
     1090            SignToolPkcs7_Delete(&Dst);
     1091        }
     1092        if (pszSrc)
     1093            SignToolPkcs7_Delete(&Src);
    8891094    }
    8901095
     
    12751480
    12761481/*
    1277  * The 'show-exe' command.
    1278  */
    1279 static RTEXITCODE HelpShowExe(PRTSTREAM pStrm, RTSIGNTOOLHELP enmLevel)
    1280 {
    1281     RT_NOREF_PV(enmLevel);
    1282     RTStrmPrintf(pStrm,
    1283                  "show-exe [--verbose|-v] [--quiet|-q] <exe1> [exe2 [..]]\n");
    1284     return RTEXITCODE_SUCCESS;
    1285 }
    1286 
     1482 * common code for show-exe and show-cat:
     1483 */
    12871484
    12881485/**
     
    16651862     */
    16661863    RTPrintf("%sDigestAlgorithms: ", pThis->szPrefix);
     1864    if (pSignedData->DigestAlgorithms.cItems == 0)
     1865        RTPrintf("none");
    16671866    for (unsigned i = 0; i < pSignedData->DigestAlgorithms.cItems; i++)
    16681867    {
     
    16971896    {
    16981897        RTPrintf("%s    Certificates: %u\n", pThis->szPrefix, pSignedData->Certificates.cItems);
    1699         for (uint32_t i = 0; i < pSignedData->Certificates.cItems; i++)
    1700         {
    1701             if (i != 0)
    1702                 RTPrintf("\n");
    1703             RTPrintf("%s      Certificate #%u:\n", pThis->szPrefix, i);
    1704             RTAsn1Dump(RTCrPkcs7Cert_GetAsn1Core(pSignedData->Certificates.papItems[i]), 0,
    1705                        ((uint32_t)offPrefix + 9) / 2, RTStrmDumpPrintfV, g_pStdOut);
     1898        if (pThis->cVerbosity >= 2)
     1899        {
     1900            for (uint32_t i = 0; i < pSignedData->Certificates.cItems; i++)
     1901            {
     1902                if (i != 0)
     1903                    RTPrintf("\n");
     1904                RTPrintf("%s      Certificate #%u:\n", pThis->szPrefix, i);
     1905                RTAsn1Dump(RTCrPkcs7Cert_GetAsn1Core(pSignedData->Certificates.papItems[i]), 0,
     1906                           ((uint32_t)offPrefix + 9) / 2, RTStrmDumpPrintfV, g_pStdOut);
     1907            }
    17061908        }
    17071909        /** @todo display certificates properly. */
     
    17141916     * Show signatures (SignerInfos).
    17151917     */
    1716     RTPrintf("%s     SignerInfos:\n", pThis->szPrefix);
    17171918    unsigned const cSigInfos = pSignedData->SignerInfos.cItems;
     1919    if (cSigInfos != 1)
     1920        RTPrintf("%s     SignerInfos: %u signers\n", pThis->szPrefix, cSigInfos);
     1921    else
     1922        RTPrintf("%s     SignerInfos:\n", pThis->szPrefix);
    17181923    for (unsigned i = 0; i < cSigInfos; i++)
    17191924    {
     
    17861991
    17871992
    1788 /**
    1789  * Shows the signing info for one executable.
    1790  *
    1791  * @returns RTEXITCODE_SUCCESS on success, RTEXITCODE_FAILURE on failure.
    1792  * @param   pszFilename         The path to the executable.
    1793  * @param   cVerbosity          The verbosity level.
    1794  * @param   enmLdrArch          Sub image selector.
    1795  */
    1796 static RTEXITCODE HandleShowExeWorker(const char *pszFilename, unsigned cVerbosity, RTLDRARCH enmLdrArch)
    1797 {
    1798     SHOWEXEPKCS7 This;
    1799     RT_ZERO(This);
    1800     This.cVerbosity = cVerbosity;
    1801 
    1802     RTEXITCODE rcExit = SignToolPkcs7Exe_InitFromFile(&This, pszFilename, cVerbosity, enmLdrArch);
    1803     if (rcExit == RTEXITCODE_SUCCESS)
    1804     {
    1805         int rc = HandleShowExeWorkerPkcs7Display(&This, This.pSignedData, 0, &This.ContentInfo);
    1806         if (RT_FAILURE(rc))
    1807             rcExit = RTEXITCODE_FAILURE;
    1808         SignToolPkcs7Exe_Delete(&This);
    1809     }
    1810 
    1811     return rcExit;
     1993/*
     1994 * The 'show-exe' command.
     1995 */
     1996static RTEXITCODE HelpShowExe(PRTSTREAM pStrm, RTSIGNTOOLHELP enmLevel)
     1997{
     1998    RT_NOREF_PV(enmLevel);
     1999    RTStrmPrintf(pStrm,
     2000                 "show-exe [--verbose|-v] [--quiet|-q] <exe1> [exe2 [..]]\n");
     2001    return RTEXITCODE_SUCCESS;
    18122002}
    18132003
     
    18152005static RTEXITCODE HandleShowExe(int cArgs, char **papszArgs)
    18162006{
    1817     /* Note! This code does not try to clean up the crypto stores on failure.
    1818              This is intentional as the code is only expected to be used in a
    1819              one-command-per-process environment where we do exit() upon
    1820              returning from this function. */
    1821 
    18222007    /*
    18232008     * Parse arguments.
     
    18292014    };
    18302015
    1831     unsigned  cVerbos = 0;
     2016    unsigned  cVerbosity = 0;
    18322017    RTLDRARCH enmLdrArch = RTLDRARCH_WHATEVER;
    18332018
     
    18412026        switch (ch)
    18422027        {
    1843             case 'v': cVerbose++; break;
    1844             case 'q': cVerbose = 0; break;
     2028            case 'v': cVerbosity++; break;
     2029            case 'q': cVerbosity = 0; break;
    18452030            case 'V': return HandleVersion(cArgs, papszArgs);
    18462031            case 'h': return HelpShowExe(g_pStdOut, RTSIGNTOOLHELP_FULL);
     
    18592044    {
    18602045        RTPrintf(iFile == 0 ? "%s:\n" : "\n%s:\n", ValueUnion.psz);
    1861         RTEXITCODE rcExitThis = HandleShowExeWorker(ValueUnion.psz, cVerbose, enmLdrArch);
     2046
     2047        SHOWEXEPKCS7 This;
     2048        RT_ZERO(This);
     2049        This.cVerbosity = cVerbosity;
     2050
     2051        RTEXITCODE rcExitThis = SignToolPkcs7Exe_InitFromFile(&This, ValueUnion.psz, cVerbosity, enmLdrArch);
     2052        if (rcExitThis == RTEXITCODE_SUCCESS)
     2053        {
     2054            int rc = HandleShowExeWorkerPkcs7Display(&This, This.pSignedData, 0, &This.ContentInfo);
     2055            if (RT_FAILURE(rc))
     2056                rcExit = RTEXITCODE_FAILURE;
     2057            SignToolPkcs7Exe_Delete(&This);
     2058        }
    18622059        if (rcExitThis != RTEXITCODE_SUCCESS && rcExit == RTEXITCODE_SUCCESS)
    18632060            rcExit = rcExitThis;
     2061
     2062        iFile++;
     2063    } while ((ch = RTGetOpt(&GetState, &ValueUnion)) == VINF_GETOPT_NOT_OPTION);
     2064    if (ch != 0)
     2065        return RTGetOptPrintError(ch, &ValueUnion);
     2066
     2067    return rcExit;
     2068}
     2069
     2070
     2071/*
     2072 * The 'show-cat' command.
     2073 */
     2074static RTEXITCODE HelpShowCat(PRTSTREAM pStrm, RTSIGNTOOLHELP enmLevel)
     2075{
     2076    RT_NOREF_PV(enmLevel);
     2077    RTStrmPrintf(pStrm,
     2078                 "show-cat [--verbose|-v] [--quiet|-q] <cat1> [cat2 [..]]\n");
     2079    return RTEXITCODE_SUCCESS;
     2080}
     2081
     2082
     2083static RTEXITCODE HandleShowCat(int cArgs, char **papszArgs)
     2084{
     2085    /*
     2086     * Parse arguments.
     2087     */
     2088    static const RTGETOPTDEF s_aOptions[] =
     2089    {
     2090        { "--verbose",      'v', RTGETOPT_REQ_NOTHING },
     2091        { "--quiet",        'q', RTGETOPT_REQ_NOTHING },
     2092    };
     2093
     2094    unsigned  cVerbosity = 0;
     2095
     2096    RTGETOPTSTATE GetState;
     2097    int rc = RTGetOptInit(&GetState, cArgs, papszArgs, s_aOptions, RT_ELEMENTS(s_aOptions), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
     2098    AssertRCReturn(rc, RTEXITCODE_FAILURE);
     2099    RTGETOPTUNION ValueUnion;
     2100    int ch;
     2101    while ((ch = RTGetOpt(&GetState, &ValueUnion)) && ch != VINF_GETOPT_NOT_OPTION)
     2102    {
     2103        switch (ch)
     2104        {
     2105            case 'v': cVerbosity++; break;
     2106            case 'q': cVerbosity = 0; break;
     2107            case 'V': return HandleVersion(cArgs, papszArgs);
     2108            case 'h': return HelpShowCat(g_pStdOut, RTSIGNTOOLHELP_FULL);
     2109            default:  return RTGetOptPrintError(ch, &ValueUnion);
     2110        }
     2111    }
     2112    if (ch != VINF_GETOPT_NOT_OPTION)
     2113        return RTMsgErrorExit(RTEXITCODE_FAILURE, "No executable given.");
     2114
     2115    /*
     2116     * Do it.
     2117     */
     2118    unsigned   iFile  = 0;
     2119    RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
     2120    do
     2121    {
     2122        RTPrintf(iFile == 0 ? "%s:\n" : "\n%s:\n", ValueUnion.psz);
     2123
     2124        SHOWEXEPKCS7 This;
     2125        RT_ZERO(This);
     2126        This.cVerbosity = cVerbosity;
     2127
     2128        RTEXITCODE rcExitThis = SignToolPkcs7_InitFromFile(&This, ValueUnion.psz, cVerbosity);
     2129        if (rcExitThis == RTEXITCODE_SUCCESS)
     2130        {
     2131            This.hLdrMod = NIL_RTLDRMOD;
     2132
     2133            int rc = HandleShowExeWorkerPkcs7Display(&This, This.pSignedData, 0, &This.ContentInfo);
     2134            if (RT_FAILURE(rc))
     2135                rcExit = RTEXITCODE_FAILURE;
     2136            SignToolPkcs7Exe_Delete(&This);
     2137        }
     2138        if (rcExitThis != RTEXITCODE_SUCCESS && rcExit == RTEXITCODE_SUCCESS)
     2139            rcExit = rcExitThis;
     2140
    18642141        iFile++;
    18652142    } while ((ch = RTGetOpt(&GetState, &ValueUnion)) == VINF_GETOPT_NOT_OPTION);
     
    21332410    { "extract-exe-signer-cert",        HandleExtractExeSignerCert,         HelpExtractExeSignerCert },
    21342411    { "add-nested-exe-signature",       HandleAddNestedExeSignature,        HelpAddNestedExeSignature },
     2412    { "add-nested-cat-signature",       HandleAddNestedCatSignature,        HelpAddNestedCatSignature },
    21352413#ifndef IPRT_IN_BUILD_TOOL
    21362414    { "verify-exe",                     HandleVerifyExe,                    HelpVerifyExe },
    21372415    { "show-exe",                       HandleShowExe,                      HelpShowExe },
     2416    { "show-cat",                       HandleShowCat,                      HelpShowCat },
    21382417#endif
    21392418    { "make-tainfo",                    HandleMakeTaInfo,                   HelpMakeTaInfo },
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette