VirtualBox

Changeset 95583 in vbox


Ignore:
Timestamp:
Jul 10, 2022 2:06:53 PM (2 years ago)
Author:
vboxsync
Message:

RTSignTool: Some showexe work. bugref:8691

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/tools/RTSignTool.cpp

    r93115 r95583  
    130130static RTEXITCODE HelpHelp(PRTSTREAM pStrm, RTSIGNTOOLHELP enmLevel);
    131131static RTEXITCODE HandleVersion(int cArgs, char **papszArgs);
     132static int HandleShowExeWorkerPkcs7DisplaySignerInfo(PSHOWEXEPKCS7 pThis, size_t offPrefix, PCRTCRPKCS7SIGNERINFO pSignerInfo);
    132133static int HandleShowExeWorkerPkcs7Display(PSHOWEXEPKCS7 pThis, PRTCRPKCS7SIGNEDDATA pSignedData, size_t offPrefix,
    133134                                           PCRTCRPKCS7CONTENTINFO pContentInfo);
     
    18521853        /* Counter signatures (PKCS \#9), use pCounterSignatures. */
    18531854        case RTCRPKCS7ATTRIBUTETYPE_COUNTER_SIGNATURES:
    1854             RTPrintf("%sTODO: RTCRPKCS7ATTRIBUTETYPE_COUNTER_SIGNATURES! %u bytes\n",
    1855                      pThis->szPrefix, pAttr->uValues.pCounterSignatures->SetCore.Asn1Core.cb);
     1855            RTPrintf("%s%u counter signatures, %u bytes in total\n", pThis->szPrefix,
     1856                     pAttr->uValues.pCounterSignatures->cItems, pAttr->uValues.pCounterSignatures->SetCore.Asn1Core.cb);
     1857            for (uint32_t i = 0; i < pAttr->uValues.pCounterSignatures->cItems; i++)
     1858            {
     1859                size_t offPrefix2 = offPrefix;
     1860                if (pAttr->uValues.pContentInfos->cItems > 1)
     1861                    offPrefix2 += RTStrPrintf(&pThis->szPrefix[offPrefix], sizeof(pThis->szPrefix) - offPrefix, "CounterSig[%u]: ", i);
     1862                else
     1863                    offPrefix2 += RTStrPrintf(&pThis->szPrefix[offPrefix], sizeof(pThis->szPrefix) - offPrefix, "  ");
     1864
     1865                int rc2 = HandleShowExeWorkerPkcs7DisplaySignerInfo(pThis, offPrefix2,
     1866                                                                    pAttr->uValues.pCounterSignatures->papItems[i]);
     1867                if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
     1868                    rc = rc2;
     1869            }
    18561870            break;
    18571871
     
    19541968
    19551969/**
     1970 * Displays a SignerInfo structure.
     1971 *
     1972 * @returns IPRT status code.
     1973 * @param   pThis               The show exe instance data.
     1974 * @param   offPrefix           The current prefix offset.
     1975 * @param   pSignerInfo         The structure to display.
     1976 */
     1977static int HandleShowExeWorkerPkcs7DisplaySignerInfo(PSHOWEXEPKCS7 pThis, size_t offPrefix, PCRTCRPKCS7SIGNERINFO pSignerInfo)
     1978{
     1979    int rc = RTAsn1Integer_ToString(&pSignerInfo->IssuerAndSerialNumber.SerialNumber,
     1980                                    pThis->szTmp, sizeof(pThis->szTmp), 0 /*fFlags*/, NULL);
     1981    if (RT_FAILURE(rc))
     1982        RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc);
     1983    RTPrintf("%s                  Serial No: %s\n", pThis->szPrefix, pThis->szTmp);
     1984
     1985    rc = RTCrX509Name_FormatAsString(&pSignerInfo->IssuerAndSerialNumber.Name, pThis->szTmp, sizeof(pThis->szTmp), NULL);
     1986    if (RT_FAILURE(rc))
     1987        RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc);
     1988    RTPrintf("%s                     Issuer: %s\n", pThis->szPrefix, pThis->szTmp);
     1989
     1990    const char *pszType = RTCrDigestTypeToName(RTCrX509AlgorithmIdentifier_QueryDigestType(&pSignerInfo->DigestAlgorithm));
     1991    if (!pszType)
     1992        pszType = pSignerInfo->DigestAlgorithm.Algorithm.szObjId;
     1993    RTPrintf("%s           Digest Algorithm: %s", pThis->szPrefix, pszType);
     1994    if (pThis->cVerbosity > 1)
     1995        RTPrintf(" (%s)\n", pSignerInfo->DigestAlgorithm.Algorithm.szObjId);
     1996    else
     1997        RTPrintf("\n");
     1998
     1999    HandleShowExeWorkerDisplayObjId(pThis, &pSignerInfo->DigestEncryptionAlgorithm.Algorithm,
     2000                                    "Digest Encryption Algorithm: ", "\n");
     2001
     2002    if (pSignerInfo->AuthenticatedAttributes.cItems == 0)
     2003        RTPrintf("%s   Authenticated Attributes: none\n", pThis->szPrefix);
     2004    else
     2005    {
     2006        RTPrintf("%s   Authenticated Attributes: %u item%s\n", pThis->szPrefix,
     2007                 pSignerInfo->AuthenticatedAttributes.cItems, pSignerInfo->AuthenticatedAttributes.cItems > 1 ? "s" : "");
     2008        for (unsigned j = 0; j < pSignerInfo->AuthenticatedAttributes.cItems; j++)
     2009        {
     2010            PRTCRPKCS7ATTRIBUTE pAttr = pSignerInfo->AuthenticatedAttributes.papItems[j];
     2011            size_t offPrefix3 = offPrefix+ RTStrPrintf(&pThis->szPrefix[offPrefix], sizeof(pThis->szPrefix) - offPrefix,
     2012                                                         "              AuthAttrib[%u]: ", j);
     2013            HandleShowExeWorkerPkcs7DisplayAttrib(pThis, offPrefix3, pAttr);
     2014        }
     2015        pThis->szPrefix[offPrefix] = '\0';
     2016    }
     2017
     2018    if (pSignerInfo->UnauthenticatedAttributes.cItems == 0)
     2019        RTPrintf("%s Unauthenticated Attributes: none\n", pThis->szPrefix);
     2020    else
     2021    {
     2022        RTPrintf("%s Unauthenticated Attributes: %u item%s\n", pThis->szPrefix,
     2023                 pSignerInfo->UnauthenticatedAttributes.cItems, pSignerInfo->UnauthenticatedAttributes.cItems > 1 ? "s" : "");
     2024        for (unsigned j = 0; j < pSignerInfo->UnauthenticatedAttributes.cItems; j++)
     2025        {
     2026            PRTCRPKCS7ATTRIBUTE pAttr = pSignerInfo->UnauthenticatedAttributes.papItems[j];
     2027            size_t offPrefix3 = offPrefix + RTStrPrintf(&pThis->szPrefix[offPrefix], sizeof(pThis->szPrefix) - offPrefix,
     2028                                                        "            UnauthAttrib[%u]: ", j);
     2029            HandleShowExeWorkerPkcs7DisplayAttrib(pThis, offPrefix3, pAttr);
     2030        }
     2031        pThis->szPrefix[offPrefix] = '\0';
     2032    }
     2033
     2034    /** @todo show the encrypted stuff (EncryptedDigest)?   */
     2035    return rc;
     2036}
     2037
     2038
     2039/**
    19562040 * Displays a Microsoft SPC indirect data structure.
    19572041 *
     
    21822266    {
    21832267        RTPrintf("%s    Certificates: %u\n", pThis->szPrefix, pSignedData->Certificates.cItems);
    2184         if (pThis->cVerbosity >= 2)
    2185         {
    2186             for (uint32_t i = 0; i < pSignedData->Certificates.cItems; i++)
    2187             {
    2188                 if (i != 0)
    2189                     RTPrintf("\n");
    2190                 RTPrintf("%s      Certificate #%u:\n", pThis->szPrefix, i);
     2268        for (uint32_t i = 0; i < pSignedData->Certificates.cItems; i++)
     2269        {
     2270            PCRTCRPKCS7CERT pCert = pSignedData->Certificates.papItems[i];
     2271            if (i != 0 && pThis->cVerbosity >= 2)
     2272                RTPrintf("\n");
     2273            switch (pCert->enmChoice)
     2274            {
     2275                case RTCRPKCS7CERTCHOICE_X509:
     2276                {
     2277                    PCRTCRX509CERTIFICATE pX509Cert = pCert->u.pX509Cert;
     2278                    int rc2 = RTAsn1QueryObjIdName(&pX509Cert->SignatureAlgorithm.Algorithm, pThis->szTmp, sizeof(pThis->szTmp));
     2279                    RTPrintf("%s      Certificate #%u: %s\n", pThis->szPrefix, i,
     2280                             RT_SUCCESS(rc2) ? pThis->szTmp : pX509Cert->SignatureAlgorithm.Algorithm.szObjId);
     2281
     2282                    rc2 = RTCrX509Name_FormatAsString(&pX509Cert->TbsCertificate.Subject,
     2283                                                      pThis->szTmp, sizeof(pThis->szTmp), NULL);
     2284                    if (RT_FAILURE(rc2))
     2285                        RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc2);
     2286                    RTPrintf("%s        Subject: %s\n", pThis->szPrefix, pThis->szTmp);
     2287
     2288                    rc2 = RTCrX509Name_FormatAsString(&pX509Cert->TbsCertificate.Issuer,
     2289                                                      pThis->szTmp, sizeof(pThis->szTmp), NULL);
     2290                    if (RT_FAILURE(rc2))
     2291                        RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc2);
     2292                    RTPrintf("%s         Issuer: %s\n", pThis->szPrefix, pThis->szTmp);
     2293
     2294
     2295                    char szNotAfter[RTTIME_STR_LEN];
     2296                    RTPrintf("%s          Valid: %s thru %s\n", pThis->szPrefix,
     2297                             RTTimeToString(&pX509Cert->TbsCertificate.Validity.NotBefore.Time,
     2298                                            pThis->szTmp, sizeof(pThis->szTmp)),
     2299                             RTTimeToString(&pX509Cert->TbsCertificate.Validity.NotAfter.Time,
     2300                                            szNotAfter, sizeof(szNotAfter)));
     2301                    break;
     2302                }
     2303
     2304                default:
     2305                    RTPrintf("%s      Certificate #%u: Unsupported type\n", pThis->szPrefix, i);
     2306                    break;
     2307            }
     2308
     2309
     2310            if (pThis->cVerbosity >= 2)
    21912311                RTAsn1Dump(RTCrPkcs7Cert_GetAsn1Core(pSignedData->Certificates.papItems[i]), 0,
    21922312                           ((uint32_t)offPrefix + 9) / 2, RTStrmDumpPrintfV, g_pStdOut);
    2193             }
    2194         }
     2313        }
     2314
    21952315        /** @todo display certificates properly. */
    21962316    }
     
    22072327    else
    22082328        RTPrintf("%s     SignerInfos:\n", pThis->szPrefix);
     2329    int rc = VINF_SUCCESS;
    22092330    for (unsigned i = 0; i < cSigInfos; i++)
    22102331    {
    2211         PRTCRPKCS7SIGNERINFO pSigInfo = pSignedData->SignerInfos.papItems[i];
    22122332        size_t offPrefix2 = offPrefix;
    22132333        if (cSigInfos != 1)
    22142334            offPrefix2 += RTStrPrintf(&pThis->szPrefix[offPrefix], sizeof(pThis->szPrefix) - offPrefix, "SignerInfo[%u]: ", i);
    22152335
    2216         int rc = RTAsn1Integer_ToString(&pSigInfo->IssuerAndSerialNumber.SerialNumber,
    2217                                         pThis->szTmp, sizeof(pThis->szTmp), 0 /*fFlags*/, NULL);
    2218         if (RT_FAILURE(rc))
    2219             RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc);
    2220         RTPrintf("%s                  Serial No: %s\n", pThis->szPrefix, pThis->szTmp);
    2221 
    2222         rc = RTCrX509Name_FormatAsString(&pSigInfo->IssuerAndSerialNumber.Name, pThis->szTmp, sizeof(pThis->szTmp), NULL);
    2223         if (RT_FAILURE(rc))
    2224             RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc);
    2225         RTPrintf("%s                     Issuer: %s\n", pThis->szPrefix, pThis->szTmp);
    2226 
    2227         const char *pszType = RTCrDigestTypeToName(RTCrX509AlgorithmIdentifier_QueryDigestType(&pSigInfo->DigestAlgorithm));
    2228         if (!pszType)
    2229             pszType = pSigInfo->DigestAlgorithm.Algorithm.szObjId;
    2230         RTPrintf("%s           Digest Algorithm: %s", pThis->szPrefix, pszType);
    2231         if (pThis->cVerbosity > 1)
    2232             RTPrintf(" (%s)\n", pSigInfo->DigestAlgorithm.Algorithm.szObjId);
    2233         else
    2234             RTPrintf("\n");
    2235 
    2236         HandleShowExeWorkerDisplayObjId(pThis, &pSigInfo->DigestEncryptionAlgorithm.Algorithm,
    2237                                         "Digest Encryption Algorithm: ", "\n");
    2238 
    2239         if (pSigInfo->AuthenticatedAttributes.cItems == 0)
    2240             RTPrintf("%s   Authenticated Attributes: none\n", pThis->szPrefix);
    2241         else
    2242         {
    2243             RTPrintf("%s   Authenticated Attributes: %u item%s\n", pThis->szPrefix,
    2244                      pSigInfo->AuthenticatedAttributes.cItems, pSigInfo->AuthenticatedAttributes.cItems > 1 ? "s" : "");
    2245             for (unsigned j = 0; j < pSigInfo->AuthenticatedAttributes.cItems; j++)
    2246             {
    2247                 PRTCRPKCS7ATTRIBUTE pAttr = pSigInfo->AuthenticatedAttributes.papItems[j];
    2248                 size_t offPrefix3 = offPrefix2 + RTStrPrintf(&pThis->szPrefix[offPrefix2], sizeof(pThis->szPrefix) - offPrefix2,
    2249                                                              "              AuthAttrib[%u]: ", j);
    2250                 HandleShowExeWorkerPkcs7DisplayAttrib(pThis, offPrefix3, pAttr);
    2251             }
    2252             pThis->szPrefix[offPrefix2] = '\0';
    2253         }
    2254 
    2255         if (pSigInfo->UnauthenticatedAttributes.cItems == 0)
    2256             RTPrintf("%s Unauthenticated Attributes: none\n", pThis->szPrefix);
    2257         else
    2258         {
    2259             RTPrintf("%s Unauthenticated Attributes: %u item%s\n", pThis->szPrefix,
    2260                      pSigInfo->UnauthenticatedAttributes.cItems, pSigInfo->UnauthenticatedAttributes.cItems > 1 ? "s" : "");
    2261             for (unsigned j = 0; j < pSigInfo->UnauthenticatedAttributes.cItems; j++)
    2262             {
    2263                 PRTCRPKCS7ATTRIBUTE pAttr = pSigInfo->UnauthenticatedAttributes.papItems[j];
    2264                 size_t offPrefix3 = offPrefix2 + RTStrPrintf(&pThis->szPrefix[offPrefix2], sizeof(pThis->szPrefix) - offPrefix2,
    2265                                                              "            UnauthAttrib[%u]: ", j);
    2266                 HandleShowExeWorkerPkcs7DisplayAttrib(pThis, offPrefix3, pAttr);
    2267             }
    2268             pThis->szPrefix[offPrefix2] = '\0';
    2269         }
    2270 
    2271         /** @todo show the encrypted stuff (EncryptedDigest)?   */
     2336        int rc2 = HandleShowExeWorkerPkcs7DisplaySignerInfo(pThis, offPrefix2, pSignedData->SignerInfos.papItems[i]);
     2337        if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
     2338            rc = rc2;
    22722339    }
    22732340    pThis->szPrefix[offPrefix] = '\0';
    22742341
    2275     return VINF_SUCCESS;
     2342    return rc;
    22762343}
    22772344
Note: See TracChangeset for help on using the changeset viewer.

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