VirtualBox

Changeset 50954 in vbox


Ignore:
Timestamp:
Apr 2, 2014 4:19:56 PM (11 years ago)
Author:
vboxsync
Message:

x509.cpp/h: Cleaned up rtX509ReadCertificateFromPEM, please study the changes and clean up the rest.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/x509.h

    r50835 r50954  
    3838 */
    3939
    40 RTDECL(void) RTX509PrepareOpenSSL();
     40/**
     41 * Preparation before start to work with openssl
     42 *
     43 * @todo This should return a status and check that X509 code seems sane.  This
     44 *       would allow dynamic linking if necessary at some point.
     45 */
     46RTDECL(int) RTX509PrepareOpenSSL(void);
     47
    4148/**
    4249 * Verify RSA signature for the given memory buffer.
     
    6471RTDECL(int) RTX509CertificateVerify(void *pvBuf, unsigned int cbSize);
    6572
     73/** @todo document me. */
    6674RTDECL(unsigned long) RTX509GetErrorDescription(char** pErrorDesc);
    6775
  • trunk/src/VBox/Runtime/common/checksum/x509.cpp

    r50904 r50954  
    3030*******************************************************************************/
    3131#include "internal/iprt.h"
    32 
    33 #include <openssl/bio.h>
    34 #include <openssl/err.h>
    35 #include <openssl/pem.h>
    36 #include <openssl/x509.h>
    37 #include <openssl/x509v3.h>
    38 
    3932#include <iprt/x509.h>
     33
    4034#include <iprt/assert.h>
    4135#include <iprt/mem.h>
     
    4539#include <iprt/string.h>
    4640
     41#include <openssl/bio.h>
     42#include <openssl/err.h>
     43#include <openssl/pem.h>
     44#include <openssl/x509.h>
     45#include <openssl/x509v3.h>
     46
     47
    4748/**
    4849 * Preparation before start to work with openssl
    4950 *
    50  * @returns none
    51  *
    52  */
    53 RTDECL(void) RTX509PrepareOpenSSL()
     51 * @returns IPRT status code.
     52 */
     53RTDECL(int) RTX509PrepareOpenSSL(void)
    5454{
    5555    OpenSSL_add_all_digests();
    5656    ERR_load_BIO_strings();
    5757    ERR_load_crypto_strings();
     58    return VINF_SUCCESS;
    5859}
    5960RT_EXPORT_SYMBOL(RTX509PrepareOpenSSL);
    6061
     62
    6163/**
    62  * Read X509 certificate from the given memory buffer into the
    63  * internal structure.
    64  *
    65  * @returns iprt status code.
    66  *
    67  * @param   pvBuf                 string representation
    68  *                                containing X509 certificate
    69  *                                in PEM format
    70  * @param   cbSize                The amount of data (in bytes)
    71  * @param   out_cert              pointer to the structure where
    72  *                                the info about X509
    73  *                                certificate will be stored
    74  */
    75 static int RTX509ReadCertificateFromPEM(void *pvBuf, unsigned int cbSize, X509** out_cert)
    76 {
    77     int rc = VINF_SUCCESS;
    78 
    79     BIO *bio_memory = BIO_new(BIO_s_mem());
    80     int cbytes = BIO_write(bio_memory,(const void*)pvBuf ,cbSize) ;
    81     *out_cert = PEM_read_bio_X509(bio_memory,NULL,0,NULL);
    82     BIO_free(bio_memory);
    83     if(!*out_cert)
    84         rc = VERR_X509_READING_CERT_FROM_BIO;
    85 
    86     return rc;
    87 }
     64 * Read X509 certificate from the given memory buffer into the internal
     65 * structure.
     66 *
     67 * @returns IPRT status code.
     68 *
     69 * @param   pvBuf           String representation containing X509
     70 *                          certificate in PEM format.
     71 * @param   cbBuf           The amount of data @a pvBuf points to.
     72 * @param   ppOutCert       Where to store the pointer to the structure where
     73 *                          the info about X509 certificate will be stored.
     74 */
     75static int rtX509ReadCertificateFromPEM(void const *pvPem, unsigned int cbPem, X509 **ppOutCert)
     76{
     77    BIO *pBio = BIO_new(BIO_s_mem());
     78    if (!pBio)
     79        return VERR_NO_MEMORY;
     80
     81    int cb = BIO_write(pBio, pvPem, cbPem);
     82    *ppOutCert = PEM_read_bio_X509(pBio, NULL, 0, NULL);
     83    BIO_free(pBio);
     84
     85    return *ppOutCert ? VINF_SUCCESS : VERR_X509_READING_CERT_FROM_BIO;
     86}
     87
    8888
    8989/**
     
    194194        }
    195195
    196         rc = RTX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
     196        rc = rtX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
    197197        if (RT_FAILURE(rc))
    198198        {
     
    267267    BIO *bio_memory = NULL;
    268268
    269     while (1)
    270     {
    271         rc = RTX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
     269    for (;;)
     270    {
     271        rc = rtX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
    272272        int loc = X509_get_ext_by_NID(certificate, NID_basic_constraints,-1);
    273273
     
    332332    while(1)
    333333    {
    334         rc = RTX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
     334        rc = rtX509ReadCertificateFromPEM(pvBuf, cbSize, &certificate);
    335335        if (RT_FAILURE(rc))
    336336        {
     
    384384    return rc;
    385385}
    386 
    387386RT_EXPORT_SYMBOL(RTX509CertificateVerify);
     387
    388388
    389389RTDECL(unsigned long) RTX509GetErrorDescription(char** pErrorDesc)
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