VirtualBox

Changeset 50832 in vbox


Ignore:
Timestamp:
Mar 21, 2014 6:08:32 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
92911
Message:

pr6022. Support X509 certification during import OVF appliance.

Location:
trunk
Files:
6 edited

Legend:

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

    r50155 r50832  
    18791879/** @} */
    18801880
     1881/** @name RTX509 status codes
     1882 * @{ */
     1883/** Error during reading a certificate in PEM format from BIO */
     1884#define VERR_READING_CERT_FROM_BIO                  (-22800)
     1885/** Error extract a public key from the certificate */
     1886#define VERR_EXTRACT_PUBKEY_FROM_CERT               (-22801)
     1887/** Error extract RSA from the public key */
     1888#define VERR_EXTRACT_RSA_FROM_PUBLIC_KEY            (-22802)
     1889/** Error the signature verification */
     1890#define VERR_RSA_VERIFICATION_FUILURE               (-22803)
     1891/** Error basic constraints were not found */
     1892#define VERR_NO_BASIC_CONSTARAINTS                  (-22804)
     1893/** Error getting extensions from the certificate */
     1894#define VERR_GETTING_EXTENSION_FROM_CERT            (-22805)
     1895/** Error getting a data from the extension */
     1896#define VERR_GETTING_DATA_FROM_EXTENSION            (-22806)
     1897/** Error print out an extension to BIO */
     1898#define VERR_PRINT_EXTENSION_TO_BIO                 (-22807)
     1899/** Error X509 certificate verification */
     1900#define VERR_X509_CERTIFICATE_VERIFICATION_FAILURE  (-22808)
     1901/** Error X509 certificate isn't self signed */
     1902#define VERR_NOT_SELFSIGNED_X509_CERTIFICATE        (-22809)
     1903/** @} */
    18811904
    18821905/* SED-END */
  • trunk/include/iprt/mangling.h

    r50792 r50832  
    11991199# define RTReqRetain                                    RT_MANGLER(RTReqRetain)
    12001200# define RTReqWait                                      RT_MANGLER(RTReqWait)
     1201# define RTRSAVerify                                    RT_MANGLER(RTRSAVerify)
    12011202# define RTReqGetStatus                                 RT_MANGLER(RTReqGetStatus)
    12021203# define RTS3BucketsDestroy                             RT_MANGLER(RTS3BucketsDestroy)
     
    18821883# define RTVfsUtilDummyPollOne                          RT_MANGLER(RTVfsUtilDummyPollOne)
    18831884# define RTVfsUtilPumpIoStreams                         RT_MANGLER(RTVfsUtilPumpIoStreams)
     1885# define RTX509PrepareOpenSSL                           RT_MANGLER(RTX509PrepareOpenSSL)
     1886# define RTX509CertificateVerify                        RT_MANGLER(RTX509CertificateVerify)
     1887# define RTX509GetErrorDescription                      RT_MANGLER(RTX509GetErrorDescription)
    18841888# define RTZipBlockCompress                             RT_MANGLER(RTZipBlockCompress)
    18851889# define RTZipBlockDecompress                           RT_MANGLER(RTZipBlockDecompress)
  • trunk/src/VBox/Main/Makefile.kmk

    r50686 r50832  
    318318        $(PATH_STAGE_LIB)/SSMStandalone$(VBOX_SUFF_LIB) \
    319319        $(LIB_DDU)
    320 VBoxSVC_SDKS = VBOX_LIBPNG VBOX_ZLIB
     320
     321VBoxSVC_SDKS = VBOX_LIBPNG VBOX_ZLIB VBOX_OPENSSL
    321322VBoxSVC_LIBS.solaris = \
    322323        adm \
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r50444 r50832  
    181181                               PSHASTORAGE pStorage);
    182182    HRESULT i_verifyManifestFile(const Utf8Str &strFile, ImportStack &stack, void *pvBuf, size_t cbSize);
     183
     184    HRESULT i_verifyCertificateFile(void *pvBuf, size_t cbSize, PSHASTORAGE pStorage);
    183185
    184186    void i_convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r50355 r50832  
    4747#include <VBox/settings.h>
    4848
     49#include <iprt/x509.h>
    4950#include <set>
    5051
     
    15171518
    15181519                /* verify Certificate */
     1520                rc = i_verifyCertificateFile(pvCertBuf, cbCertFile, &storage);
     1521                if (FAILED(rc)) throw rc;
    15191522            }
    15201523        }
     
    15881591    void *pvCertBuf = NULL;
    15891592    Utf8Str OVFfilename;
     1593    void  *pSignatureRSA = NULL;
    15901594
    15911595    writeLock.release();
     
    16931697                    if (pvCertBuf)
    16941698                    {
    1695                     /* verify the certificate */
     1699                        /* verify the certificate */
     1700                        rc = i_verifyCertificateFile(pvCertBuf, cbCertFile, pStorage);
     1701                        if (FAILED(rc)) throw rc;
    16961702                    }
    16971703                }
     
    17381744                        if (pvCertBuf)
    17391745                        {
    1740                         /* verify the certificate */
     1746                            /* verify the certificate */
     1747                            rc = i_verifyCertificateFile(pvCertBuf, cbCertFile, pStorage);
     1748                            if (FAILED(rc)) throw rc;
    17411749                        }
    17421750                    }
     
    20372045HRESULT Appliance::i_verifyManifestFile(const Utf8Str &strFile, ImportStack &stack, void *pvBuf, size_t cbSize)
    20382046{
     2047    LogFlowFuncEnter();
     2048    LogFlowFunc(("Appliance %p\n", this));
    20392049    HRESULT rc = S_OK;
    20402050
     
    20642074
    20652075    RTMemFree(paTests);
    2066 
     2076    LogFlowFuncLeave();
     2077
     2078    return rc;
     2079}
     2080
     2081HRESULT Appliance::i_verifyCertificateFile(void *pvBuf, size_t cbSize, PSHASTORAGE pStorage)
     2082{
     2083    LogFlowFuncEnter();
     2084    LogFlowFunc(("Appliance %p\n", this));
     2085    HRESULT rc = S_OK;
     2086
     2087    int vrc = 0;
     2088    RTDIGESTTYPE digestType;
     2089    void * pvCertBuf = pvBuf;
     2090    size_t cbCertSize = cbSize;
     2091    Utf8Str manifestDigest = pStorage->strDigest;
     2092
     2093    vrc = RTManifestVerifyDigestType(pvCertBuf, cbCertSize, &digestType);
     2094    if (RT_FAILURE(vrc))
     2095    {
     2096        rc = setError(VBOX_E_FILE_ERROR, tr("Digest type of certificate is unknown"));
     2097    }
     2098    else
     2099    {
     2100        RTX509PrepareOpenSSL();
     2101
     2102        vrc = RTRSAVerify(pvCertBuf, (unsigned int)cbCertSize, manifestDigest.c_str(), digestType);
     2103        if (RT_SUCCESS(vrc))
     2104        {
     2105            vrc = RTX509CertificateVerify(pvCertBuf, (unsigned int)cbCertSize);
     2106        }
     2107
     2108        /* After first unsuccessful operation */
     2109        if (RT_FAILURE(vrc))
     2110        {
     2111            {
     2112                /* first stage for getting possible error code and it's description using native openssl method */
     2113                char* errStrDesc = NULL;
     2114                unsigned long errValue = RTX509GetErrorDescription(&errStrDesc);
     2115
     2116                if(errValue != 0)
     2117                {
     2118                    rc = setError(VBOX_E_FILE_ERROR, tr(errStrDesc));
     2119                    LogFlowFunc(("Error during verifying X509 certificate(internal openssl description): %s\n", errStrDesc));
     2120                }
     2121
     2122                RTMemFree(errStrDesc);
     2123            }
     2124
     2125            {
     2126                /* second stage for getting possible error code using our defined errors codes. The original error description
     2127                   will be replaced by our description */
     2128
     2129                Utf8Str errStrDesc;
     2130                switch(vrc)
     2131                {
     2132                    case VERR_READING_CERT_FROM_BIO:
     2133                        errStrDesc = "Error during reading a certificate in PEM format from BIO ";
     2134                        break;
     2135                    case VERR_EXTRACT_PUBKEY_FROM_CERT:
     2136                        errStrDesc = "Error during extraction a public key from the certificate ";
     2137                        break;
     2138                    case VERR_EXTRACT_RSA_FROM_PUBLIC_KEY:
     2139                        errStrDesc = "Error during extraction RSA from the public key ";
     2140                        break;
     2141                    case VERR_RSA_VERIFICATION_FUILURE:
     2142                        errStrDesc = "RSA verification failure ";
     2143                        break;
     2144                    case VERR_NO_BASIC_CONSTARAINTS:
     2145                        errStrDesc = "Basic constraints were not found ";
     2146                        break;
     2147                    case VERR_GETTING_EXTENSION_FROM_CERT:
     2148                        errStrDesc = "Error during getting extensions from the certificate ";
     2149                        break;
     2150                    case VERR_GETTING_DATA_FROM_EXTENSION:
     2151                        errStrDesc = "Error during extraction data from the extension ";
     2152                        break;
     2153                    case VERR_PRINT_EXTENSION_TO_BIO:
     2154                        errStrDesc = "Error during print out an extension to BIO ";
     2155                        break;
     2156                    case VERR_X509_CERTIFICATE_VERIFICATION_FAILURE:
     2157                        errStrDesc = "X509 certificate verification failure ";
     2158                        break;
     2159                    case VERR_NOT_SELFSIGNED_X509_CERTIFICATE:
     2160                        errStrDesc = "Only self signed X509 certificates are supported at moment";
     2161                        break;
     2162                    default:
     2163                        errStrDesc = "Unknown error during X509 certificate verification";
     2164                }
     2165                rc = setError(VBOX_E_FILE_ERROR, tr(errStrDesc.c_str()));
     2166            }
     2167        }
     2168    }
     2169
     2170    LogFlowFuncLeave();
    20672171    return rc;
    20682172}
  • trunk/src/VBox/Runtime/Makefile.kmk

    r50526 r50832  
    282282        common/checksum/sha512.cpp \
    283283        common/checksum/sha512str.cpp \
     284        common/checksum/x509.cpp \
    284285        common/dbg/dbg.cpp \
    285286        common/dbg/dbgas.cpp \
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