VirtualBox

Ignore:
Timestamp:
May 14, 2020 5:42:13 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137978
Message:

VBoxManage/signova: Fixed a PKCS7/CMS signing bug. Validate more of the PKCS7/CMS signature after we're done as it's easier to deal with here than in VBoxSVC. bugref:9699

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r84144 r84311  
    147147    { "import",             USAGE_IMPORTAPPLIANCE,  VBMG_CMD_TODO, handleImportAppliance,      0 },
    148148    { "export",             USAGE_EXPORTAPPLIANCE,  VBMG_CMD_TODO, handleExportAppliance,      0 },
    149     { "signova",            USAGE_S_NEWCMD,      HELP_CMD_SIGNOVA, handleSignAppliance,        0 },
     149    { "signova",            USAGE_S_NEWCMD,      HELP_CMD_SIGNOVA, handleSignAppliance,        VBMG_CMD_F_NO_COM },
    150150#ifdef VBOX_WITH_NETFLT
    151151    { "hostonlyif",         USAGE_HOSTONLYIFS,      VBMG_CMD_TODO, handleHostonlyIf,           0 },
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageAppliance.cpp

    r84264 r84311  
    19901990
    19911991/**
     1992 * Worker for doCheckPkcs7Signature.
     1993 */
     1994static int doCheckPkcs7SignatureWorker(PRTCRPKCS7CONTENTINFO pContentInfo, void const *pvManifest, size_t cbManifest,
     1995                                       unsigned iVerbosity, const char *pszTag, PRTERRINFOSTATIC pErrInfo)
     1996{
     1997    int rc;
     1998
     1999    /*
     2000     * It must be signedData.
     2001     */
     2002    if (RTCrPkcs7ContentInfo_IsSignedData(pContentInfo))
     2003    {
     2004        PRTCRPKCS7SIGNEDDATA pSignedData = pContentInfo->u.pSignedData;
     2005
     2006        /*
     2007         * Inside the signedData there must be just 'data'.
     2008         */
     2009        if (!strcmp(pSignedData->ContentInfo.ContentType.szObjId, RTCR_PKCS7_DATA_OID))
     2010        {
     2011            /*
     2012             * Check that things add up.
     2013             */
     2014            rc = RTCrPkcs7SignedData_CheckSanity(pSignedData,
     2015                                                 RTCRPKCS7SIGNEDDATA_SANITY_F_ONLY_KNOWN_HASH
     2016                                                 | RTCRPKCS7SIGNEDDATA_SANITY_F_SIGNING_CERT_PRESENT,
     2017                                                 RTErrInfoInitStatic(pErrInfo), "SD");
     2018            if (RT_SUCCESS(rc))
     2019            {
     2020                if (iVerbosity > 2 && pszTag == NULL)
     2021                    RTMsgInfo("  Successfully decoded the PKCS#7/CMS signature...");
     2022
     2023                /*
     2024                 * Check that we can verify the signed data, but skip certificate validate as
     2025                 * we probably don't necessarily have the correct root certs handy here.
     2026                 */
     2027                RTTIMESPEC Now;
     2028                rc = RTCrPkcs7VerifySignedDataWithExternalData(pContentInfo, RTCRPKCS7VERIFY_SD_F_TRUST_ALL_CERTS,
     2029                                                               NIL_RTCRSTORE /*hAdditionalCerts*/,
     2030                                                               NIL_RTCRSTORE /*hTrustedCerts*/,
     2031                                                               RTTimeNow(&Now),
     2032                                                               NULL /*pfnVerifyCert*/, NULL /*pvUser*/,
     2033                                                               pvManifest, cbManifest, RTErrInfoInitStatic(pErrInfo));
     2034                if (RT_SUCCESS(rc))
     2035                {
     2036                    if (iVerbosity > 1 && pszTag != NULL)
     2037                        RTMsgInfo("  Successfully verified the PKCS#7/CMS signature");
     2038                }
     2039                else
     2040                    rc = RTMsgErrorRc(rc, "Failed to verify the PKCS#7/CMS signature: %Rrc%RTeim", rc, &pErrInfo->Core);
     2041            }
     2042            else
     2043                RTMsgError("RTCrPkcs7SignedData_CheckSanity failed on PKCS#7/CMS signature: %Rrc%RTeim",
     2044                           rc, &pErrInfo->Core);
     2045
     2046        }
     2047        else
     2048            rc = RTMsgErrorRc(VERR_WRONG_TYPE, "PKCS#7/CMS signature inner ContentType isn't 'data' but: %s",
     2049                              pSignedData->ContentInfo.ContentType.szObjId);
     2050    }
     2051    else
     2052        rc = RTMsgErrorRc(VERR_WRONG_TYPE, "PKCS#7/CMD signature is not 'signedData': %s", pContentInfo->ContentType.szObjId);
     2053    return rc;
     2054}
     2055
     2056/**
    19922057 * For testing the decoding side.
    19932058 */
    19942059static int doCheckPkcs7Signature(void const *pvSignature, size_t cbSignature, PCRTCRX509CERTIFICATE pCertificate,
    1995                                  RTCRSTORE hIntermediateCerts, unsigned iVerbosity, PRTERRINFOSTATIC pErrInfo)
     2060                                 RTCRSTORE hIntermediateCerts, void const *pvManifest, size_t cbManifest,
     2061                                 unsigned iVerbosity, PRTERRINFOSTATIC pErrInfo)
    19962062{
     2063    RT_NOREF(pCertificate, hIntermediateCerts);
     2064
    19972065    RTASN1CURSORPRIMARY PrimaryCursor;
    19982066    RTAsn1CursorInitPrimary(&PrimaryCursor, pvSignature, (uint32_t)cbSignature, RTErrInfoInitStatic(pErrInfo),
     
    20072075            RTAsn1Dump(&ContentInfo.SeqCore.Asn1Core, 0 /*fFlags*/, 0 /*uLevel*/, RTStrmDumpPrintfV, g_pStdOut);
    20082076
    2009         /*
    2010          * It must be signedData.
    2011          */
    2012         if (RTCrPkcs7ContentInfo_IsSignedData(&ContentInfo))
     2077        rc = doCheckPkcs7SignatureWorker(&ContentInfo, pvManifest, cbManifest, iVerbosity, NULL, pErrInfo);
     2078        if (RT_SUCCESS(rc))
    20132079        {
    2014             PRTCRPKCS7SIGNEDDATA pSignedData = ContentInfo.u.pSignedData;
    2015 
    20162080            /*
    2017              * Inside the signedData there must be just 'data'.
     2081             * Clone it and repeat.  This is to catch IPRT paths assuming
     2082             * that encoded data is always on hand.
    20182083             */
    2019             if (!strcmp(pSignedData->ContentInfo.ContentType.szObjId, RTCR_PKCS7_DATA_OID))
     2084            RTCRPKCS7CONTENTINFO ContentInfo2;
     2085            rc = RTCrPkcs7ContentInfo_Clone(&ContentInfo2, &ContentInfo, &g_RTAsn1DefaultAllocator);
     2086            if (RT_SUCCESS(rc))
    20202087            {
    2021                 /*
    2022                  * Check that things add up.
    2023                  */
    2024                 rc = RTCrPkcs7SignedData_CheckSanity(pSignedData,
    2025                                                      RTCRPKCS7SIGNEDDATA_SANITY_F_ONLY_KNOWN_HASH
    2026                                                      | RTCRPKCS7SIGNEDDATA_SANITY_F_SIGNING_CERT_PRESENT,
    2027                                                      RTErrInfoInitStatic(pErrInfo), "SD");
    2028                 if (RT_SUCCESS(rc))
    2029                 {
    2030                     if (iVerbosity > 2)
    2031                         RTMsgInfo("  Successfully decoded the PKCS#7/CMS signature...");
    2032                     RT_NOREF(pCertificate, hIntermediateCerts);
    2033                 }
    2034                 else
    2035                     RTMsgError("RTCrPkcs7SignedData_CheckSanity failed on PKCS#7/CMS signature: %Rrc%RTeim",
    2036                                rc, &pErrInfo->Core);
    2037 
     2088                rc = doCheckPkcs7SignatureWorker(&ContentInfo2, pvManifest, cbManifest, iVerbosity, "cloned", pErrInfo);
     2089                RTCrPkcs7ContentInfo_Delete(&ContentInfo2);
    20382090            }
    20392091            else
    2040                 rc = RTMsgErrorRc(VERR_WRONG_TYPE, "PKCS#7/CMS signature inner ContentType isn't 'data' but: %s",
    2041                                   pSignedData->ContentInfo.ContentType.szObjId);
     2092                rc = RTMsgErrorRc(rc, "RTCrPkcs7ContentInfo_Clone failed: %Rrc", rc);
    20422093        }
    2043         else
    2044             rc = RTMsgErrorRc(VERR_WRONG_TYPE, "PKCS#7/CMD signature is not 'signedData': %s", ContentInfo.ContentType.szObjId);
    20452094    }
    20462095    else
     
    20632112     * Add a blank line, just for good measure.
    20642113     */
    2065     int rc = RTVfsFileWrite(hVfsFileManifest, " ", 1, NULL);
     2114    int rc = RTVfsFileWrite(hVfsFileSignature, " ", 1, NULL);
    20662115    if (RT_FAILURE(rc))
    20672116        return RTMsgErrorRc(rc, "RTVfsFileWrite/signature: %Rrc", rc);
     
    21432192                             */
    21442193                            rc = doCheckPkcs7Signature(pvResult, cbResult, pCertificate, hIntermediateCerts,
    2145                                                        iVerbosity, pErrInfo);
     2194                                                       pvManifest, (size_t)cbManifest, iVerbosity, pErrInfo);
    21462195                        }
    21472196                        else
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