VirtualBox

Changeset 57584 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 29, 2015 8:02:02 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
102412
Message:

IPRT: Implemented reading lib/Security/cacerts from JRE.

Location:
trunk/src/VBox/Runtime/common/crypto
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/crypto/RTCrStoreCertAddFromFile.cpp

    r57572 r57584  
    3434#include <iprt/assert.h>
    3535#include <iprt/err.h>
     36#include <iprt/file.h>
    3637#include <iprt/crypto/pem.h>
    3738
     
    102103    AssertReturn(!(fFlags & ~(RTCRCERTCTX_F_ADD_IF_NOT_FOUND | RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR)), VERR_INVALID_FLAGS);
    103104
    104     PCRTCRPEMSECTION pSectionHead;
    105     int rc = RTCrPemReadFile(pszFilename,
    106                              fFlags & RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR ? RTCRPEMREADFILE_F_CONTINUE_ON_ENCODING_ERROR : 0,
    107                              g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), &pSectionHead, pErrInfo);
     105    size_t      cbContent;
     106    void        *pvContent;
     107    int rc = RTFileReadAllEx(pszFilename, 0, 64U*_1M, RTFILE_RDALL_O_DENY_WRITE, &pvContent, &cbContent);
    108108    if (RT_SUCCESS(rc))
    109109    {
    110         PCRTCRPEMSECTION pCurSec = pSectionHead;
    111         while (pCurSec)
     110        /*
     111         * Is it a java key store file?
     112         */
     113        if (   cbContent > 32
     114            && ((uint32_t const *)pvContent)[0] == RT_H2BE_U32_C(UINT32_C(0xfeedfeed)) /* magic */
     115            && ((uint32_t const *)pvContent)[1] == RT_H2BE_U32_C(UINT32_C(0x00000002)) /* version */ )
     116            rc = RTCrStoreCertAddFromJavaKeyStoreInMem(hStore, fFlags, pvContent, cbContent, pszFilename, pErrInfo);
     117        /*
     118         * No assume PEM or DER encoded binary certificate.
     119         */
     120        else
    112121        {
    113             int rc2 = RTCrStoreCertAddEncoded(hStore, RTCRCERTCTX_F_ENC_X509_DER | (fFlags & ~RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR),
    114                                               pCurSec->pbData, pCurSec->cbData, !RTErrInfoIsSet(pErrInfo) ? pErrInfo : NULL);
    115             if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
     122            PCRTCRPEMSECTION pSectionHead;
     123            rc = RTCrPemParseContent(pvContent, cbContent, fFlags, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers),
     124                                     &pSectionHead, pErrInfo);
     125            if (RT_SUCCESS(rc))
    116126            {
    117                 rc = rc2;
    118                 if (!(fFlags & RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR))
    119                     break;
     127                PCRTCRPEMSECTION pCurSec = pSectionHead;
     128                while (pCurSec)
     129                {
     130                    int rc2 = RTCrStoreCertAddEncoded(hStore,
     131                                                      RTCRCERTCTX_F_ENC_X509_DER | (fFlags & RTCRCERTCTX_F_ADD_IF_NOT_FOUND),
     132                                                      pCurSec->pbData, pCurSec->cbData,
     133                                                      !RTErrInfoIsSet(pErrInfo) ? pErrInfo : NULL);
     134                    if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
     135                    {
     136                        rc = rc2;
     137                        if (!(fFlags & RTCRCERTCTX_F_ADD_CONTINUE_ON_ERROR))
     138                            break;
     139                    }
     140                    pCurSec = pCurSec->pNext;
     141                }
     142
     143                RTCrPemFreeSections(pSectionHead);
    120144            }
    121             pCurSec = pCurSec->pNext;
    122145        }
    123 
    124         RTCrPemFreeSections(pSectionHead);
     146        RTFileReadAllFree(pvContent, cbContent);
    125147    }
     148    else
     149        rc = RTErrInfoSetF(pErrInfo, rc, "RTFileReadAllEx failed with %Rrc on '%s'", rc, pszFilename);
    126150    return rc;
    127151}
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