VirtualBox

Changeset 101647 in vbox


Ignore:
Timestamp:
Oct 30, 2023 9:34:56 AM (15 months ago)
Author:
vboxsync
Message:

IPRT/RTSignTool: Added a --intermediate-certs-from-system/-A option to the extract-signer-root and extract-timestamp-root commands.

File:
1 edited

Legend:

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

    r100442 r101647  
    10731073    }
    10741074
     1075    /**
     1076     * Adds trusted self-signed certificates from the system.
     1077     *
     1078     * @returns boolean success indicator.
     1079     */
     1080    bool addIntermediateCertsFromSystem(PRTERRINFOSTATIC pStaticErrInfo)
     1081    {
     1082        bool fRc = true;
     1083        RTCRSTOREID const s_aenmStoreIds[] = { RTCRSTOREID_SYSTEM_INTERMEDIATE_CAS, RTCRSTOREID_USER_INTERMEDIATE_CAS };
     1084        for (size_t i = 0; i < RT_ELEMENTS(s_aenmStoreIds); i++)
     1085        {
     1086            CryptoStore Tmp;
     1087            int rc = RTCrStoreCreateSnapshotById(&Tmp.m_hStore, s_aenmStoreIds[i], RTErrInfoInitStatic(pStaticErrInfo));
     1088            if (RT_SUCCESS(rc))
     1089            {
     1090                RTCRSTORECERTSEARCH Search;
     1091                rc = RTCrStoreCertFindAll(Tmp.m_hStore, &Search);
     1092                if (RT_SUCCESS(rc))
     1093                {
     1094                    PCRTCRCERTCTX pCertCtx;
     1095                    while ((pCertCtx = RTCrStoreCertSearchNext(Tmp.m_hStore, &Search)) != NULL)
     1096                    {
     1097                        /* Skip selfsigned certs as they're useless as intermediate certs (IIRC). */
     1098                        if (   pCertCtx->pCert
     1099                            && !RTCrX509Certificate_IsSelfSigned(pCertCtx->pCert))
     1100                        {
     1101                            int rc2 = RTCrStoreCertAddEncoded(this->m_hStore,
     1102                                                              pCertCtx->fFlags | RTCRCERTCTX_F_ADD_IF_NOT_FOUND,
     1103                                                              pCertCtx->pabEncoded, pCertCtx->cbEncoded, NULL);
     1104                            if (RT_FAILURE(rc2))
     1105                                RTMsgWarning("RTCrStoreCertAddEncoded failed for a certificate: %Rrc", rc2);
     1106                        }
     1107                        RTCrCertCtxRelease(pCertCtx);
     1108                    }
     1109
     1110                    int rc2 = RTCrStoreCertSearchDestroy(Tmp.m_hStore, &Search);
     1111                    AssertRC(rc2);
     1112                }
     1113                else
     1114                {
     1115                    RTMsgError("RTCrStoreCertFindAll/%d failed: %Rrc", s_aenmStoreIds[i], rc);
     1116                    fRc = false;
     1117                }
     1118            }
     1119            else
     1120            {
     1121                RTMsgError("RTCrStoreCreateSnapshotById/%d failed: %Rrc%#RTeim", s_aenmStoreIds[i], rc, &pStaticErrInfo->Core);
     1122                fRc = false;
     1123            }
     1124        }
     1125        return fRc;
     1126    }
     1127
    10751128};
    10761129
     
    35883641                if (RT_SUCCESS(rc))
    35893642                {
     3643                    /* Seems we might need this for the sha-1 certs and such. */
     3644                    RTCrX509CertPathsSetValidTimeSpec(hCertPaths, NULL);
     3645
    35903646                    /* Build the paths: */
    35913647                    rc = RTCrX509CertPathsBuild(hCertPaths, RTErrInfoInitStatic(pStaticErrInfo));
     
    37103766    RTStrmWrappedPrintf(pStrm, RTSTRMWRAPPED_F_HANGING_INDENT,
    37113767                        "extract-%s-root [-v|--verbose] [-q|--quiet] [--signature-index|-i <num>] [--root <root-cert.der>] "
    3712                         "[--self-signed-roots-from-system] [--additional <supp-cert.der>] "
     3768                        "[--self-signed-roots-from-system] [--additional <supp-cert.der>] [--intermediate-certs-from-system] "
    37133769                        "[--input] <signed-file> [-f|--force] [--output|-o] <outfile.cer>\n",
    37143770                        fTimestamp ? "timestamp" : "signer");
     
    37343790                            "The file format can be PEM or DER.\n"
    37353791                            "  -R, --self-signed-roots-from-system\n"
    3736                             "    Use all self-signed trusted root certificates found in the system and associated with the "
     3792                            "    Use all self-signed trusted root certificates found on the system and associated with the "
    37373793                            "current user as trusted roots.  This is limited to self-signed certificates, so that we get "
    37383794                            "a full chain even if a non-end-entity certificate is present in any of those system stores for "
     
    37413797                            "    Use the certificate(s) in the specified file as a untrusted intermediate certificates. "
    37423798                            "The file format can be PEM or DER.\n"
     3799                            "  -A, --intermediate-certs-from-system\n"
     3800                            "    Use all certificates found on the system and associated with the current user as intermediate "
     3801                            "certification authorities.\n"
    37433802                            "  --input <signed-file>\n"
    37443803                            "    Signed executable or security cabinet file to examine.  The '--input' option bit is optional "
     
    37643823        { "--self-signed-roots-from-system", 'R', RTGETOPT_REQ_NOTHING },
    37653824        { "--additional",                    'a', RTGETOPT_REQ_STRING },
     3825        { "--intermediate-certs-from-system",'A', RTGETOPT_REQ_NOTHING },
    37663826        { "--add",                           'a', RTGETOPT_REQ_STRING },
    37673827        { "--input",                         'I', RTGETOPT_REQ_STRING },
     
    37873847            case 'a':
    37883848                if (!State.AdditionalStore.addFromFile(ValueUnion.psz, &StaticErrInfo))
     3849                    return RTEXITCODE_FAILURE;
     3850                break;
     3851
     3852            case 'A':
     3853                if (!State.AdditionalStore.addIntermediateCertsFromSystem(&StaticErrInfo))
    37893854                    return RTEXITCODE_FAILURE;
    37903855                break;
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