VirtualBox

Changeset 59625 in vbox


Ignore:
Timestamp:
Feb 10, 2016 8:55:22 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105464
Message:

IPRT: Added RTCrPemFindFirstSectionInContent and exposed certificate PEM markers (g_aRTCrX509CertificateMarkers).

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/crypto/pem.h

    r57577 r59625  
    44
    55/*
    6  * Copyright (C) 2006-2015 Oracle Corporation
     6 * Copyright (C) 2006-2016 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424 */
    2525
    26 #ifndef ___iprt_crypto_spc_h
    27 #define ___iprt_crypto_spc_h
     26#ifndef ___iprt_crypto_pem_h
     27#define ___iprt_crypto_pem_h
    2828
    29 #include <iprt/asn1.h>
    30 #include <iprt/crypto/x509.h>
    31 #include <iprt/crypto/pkcs7.h>
    32 #include <iprt/md5.h>
    33 #include <iprt/sha.h>
     29#include <iprt/types.h>
    3430
    3531
     
    156152/** @} */
    157153
     154/**
     155 * Finds the beginning of first PEM section using the specified markers.
     156 *
     157 * This will not look any further than the first section.  Nor will it check for
     158 * binaries.
     159 *
     160 * @returns Pointer to the "-----BEGIN XXXX" sequence on success.
     161 *          NULL if not found.
     162 * @param   pvContent       The content bytes to parse.
     163 * @param   cbContent       The number of content bytes.
     164 * @param   paMarkers       Array of one or more section markers to look for.
     165 * @param   cMarkers        Number of markers in the array.
     166 */
     167RTDECL(const char *) RTCrPemFindFirstSectionInContent(void const *pvContent, size_t cbContent,
     168                                                      PCRTCRPEMMARKER paMarkers, size_t cMarkers);
     169
    158170/** @} */
    159171
  • trunk/include/iprt/crypto/x509.h

    r59620 r59625  
    2828
    2929#include <iprt/asn1.h>
     30#include <iprt/crypto/pem.h>
    3031
    3132
     
    965966                                               PRTERRINFO pErrInfo, const char *pszErrorTag);
    966967
     968/** X509 Certificate markers for RTCrPemFindFirstSectionInContent et al. */
     969extern RTDATADECL(RTCRPEMMARKER const)  g_aRTCrX509CertificateMarkers[];
     970/** Number of entries in g_aRTCrX509CertificateMarkers. */
     971extern RTDATADECL(uint32_t const)       g_cRTCrX509CertificateMarkers;
     972
    967973
    968974
  • trunk/include/iprt/mangling.h

    r59620 r59625  
    27432743# define RTCrRsaPrivateKey_CheckSanity                  RT_MANGLER(RTCrRsaPrivateKey_CheckSanity)
    27442744# define RTCrRsaPublicKey_CheckSanity                   RT_MANGLER(RTCrRsaPublicKey_CheckSanity)
     2745# define RTCrPemFindFirstSectionInContent               RT_MANGLER(RTCrPemFindFirstSectionInContent)
    27452746# define RTCrPemFreeSections                            RT_MANGLER(RTCrPemFreeSections)
    27462747# define RTCrPemParseContent                            RT_MANGLER(RTCrPemParseContent)
     
    33143315# define g_RTAsn1DefaultAllocator                       RT_MANGLER(g_RTAsn1DefaultAllocator)
    33153316# define g_RTAsn1EFenceAllocator                        RT_MANGLER(g_RTAsn1EFenceAllocator)
     3317# define g_aRTCrX509CertificateMarkers                  RT_MANGLER(g_aRTCrX509CertificateMarkers)
     3318# define g_cRTCrX509CertificateMarkers                  RT_MANGLER(g_cRTCrX509CertificateMarkers)
     3319
    33163320#if 0 /* Disabled for now as I'm not sure the assmbler supports mangling yet. */
    33173321# define g_abRTZeroPage                                 RT_MANGLER(g_abRTZeroPage)
  • trunk/src/VBox/Runtime/common/crypto/pemfile.cpp

    r57641 r59625  
    271271     *      tab, newline, return, form feed
    272272     *
    273      * However, if we wan't to read PEM files which contains human readable
     273     * However, if we want to read PEM files which contains human readable
    274274     * certificate details before or after each base-64 section, we can't stick
    275275     * to 7-bit ASCII.  We could say it must be UTF-8, but that's probably to
    276      * limited too.  So, we'll settle for detecting binary files by control
     276     * limited as well.  So, we'll settle for detecting binary files by control
    277277     * characters alone (safe enough for DER encoded stuff, I think).
    278278     */
     
    435435
    436436
    437 
    438437RTDECL(int) RTCrPemReadFile(const char *pszFilename, uint32_t fFlags, PCRTCRPEMMARKER paMarkers, size_t cMarkers,
    439438                            PCRTCRPEMSECTION *ppSectionHead, PRTERRINFO pErrInfo)
     
    455454}
    456455
     456
     457RTDECL(const char *) RTCrPemFindFirstSectionInContent(void const *pvContent, size_t cbContent,
     458                                                      PCRTCRPEMMARKER paMarkers, size_t cMarkers)
     459{
     460    size_t offBegin;
     461    if (rtCrPemFindMarker((uint8_t *)pvContent, cbContent, 0, "BEGIN", 5, paMarkers, cMarkers, NULL, &offBegin, NULL))
     462        return (const char *)pvContent + offBegin;
     463    return NULL;
     464}
  • trunk/src/VBox/Runtime/common/crypto/x509-file.cpp

    r59620 r59625  
    4343static RTCRPEMMARKERWORD const g_aWords_Certificate[]  = { { RT_STR_TUPLE("CERTIFICATE") } };
    4444/** X509 Certificate markers. */
    45 static RTCRPEMMARKER     const g_aCertificateMarkers[] = { { g_aWords_Certificate, RT_ELEMENTS(g_aWords_Certificate) } };
     45RT_DECL_DATA_CONST(RTCRPEMMARKER const) g_aRTCrX509CertificateMarkers[] =
     46{
     47    { g_aWords_Certificate, RT_ELEMENTS(g_aWords_Certificate) }
     48};
     49/** Number of entries in g_aRTCrX509CertificateMarkers. */
     50RT_DECL_DATA_CONST(uint32_t const) g_cRTCrX509CertificateMarkers = RT_ELEMENTS(g_aRTCrX509CertificateMarkers);
    4651
    4752
     
    5156    AssertReturn(!fFlags, VERR_INVALID_FLAGS);
    5257    PCRTCRPEMSECTION pSectionHead;
    53     int rc = RTCrPemReadFile(pszFilename, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), &pSectionHead, pErrInfo);
     58    int rc = RTCrPemReadFile(pszFilename, 0, g_aRTCrX509CertificateMarkers, g_cRTCrX509CertificateMarkers,
     59                             &pSectionHead, pErrInfo);
    5460    if (RT_SUCCESS(rc))
    5561    {
     
    8591    AssertReturn(!fFlags, VERR_INVALID_FLAGS);
    8692    PCRTCRPEMSECTION pSectionHead;
    87     int rc = RTCrPemParseContent(pvBuf, cbBuf, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers),
     93    int rc = RTCrPemParseContent(pvBuf, cbBuf, 0, g_aRTCrX509CertificateMarkers, g_cRTCrX509CertificateMarkers,
    8894                                 &pSectionHead, pErrInfo);
    8995    if (RT_SUCCESS(rc))
     
    121127    AssertReturn(!fFlags, VERR_INVALID_FLAGS);
    122128    PCRTCRPEMSECTION pSectionHead;
    123     int rc = RTCrPemReadFile(pszFilename, 0, g_aCertificateMarkers, RT_ELEMENTS(g_aCertificateMarkers), &pSectionHead, pErrInfo);
     129    int rc = RTCrPemReadFile(pszFilename, 0, g_aRTCrX509CertificateMarkers, g_cRTCrX509CertificateMarkers,
     130                             &pSectionHead, pErrInfo);
    124131    if (RT_SUCCESS(rc))
    125132    {
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