VirtualBox

Ignore:
Timestamp:
May 21, 2024 12:52:09 PM (8 months ago)
Author:
vboxsync
Message:

IPRT,Main: Reworked the newly introduced RTCrX509Certificate_Generate function. It's now called RTCrX509Certificate_GenerateSelfSignedRsa and takes a few more parameters. We still can't read the output it creates. Added a create-self-signed-rsa-cert command to RTSignTool for easy testing. bugref:10310

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/crypto/iprt-openssl.cpp

    r98103 r104745  
    4343#ifdef IPRT_WITH_OPENSSL    /* Whole file. */
    4444# include <iprt/err.h>
     45# include <iprt/file.h>
    4546# include <iprt/string.h>
    4647# include <iprt/mem.h>
     
    169170}
    170171
     172
    171173DECLHIDDEN(int) rtCrOpenSslConvertPkcs7Attribute(void **ppvOsslAttrib, PCRTCRPKCS7ATTRIBUTE pAttrib, PRTERRINFO pErrInfo)
    172174{
    173     const unsigned char *pabEncoded;
    174     uint32_t             cbEncoded;
    175     void                *pvFree;
     175    const unsigned char *pabEncoded = NULL;
     176    uint32_t             cbEncoded  = 0;
     177    void                *pvFree     = NULL;
    176178    int rc = RTAsn1EncodeQueryRawBits(RTCrPkcs7Attribute_GetAsn1Core(pAttrib),
    177179                                      (const uint8_t **)&pabEncoded, &cbEncoded, &pvFree, pErrInfo);
     
    199201
    200202
     203/**
     204 * Writes the content of the @a pvMemBio to the new file @a pszFilename.
     205 *
     206 * @returns IPRT status code.
     207 * @param   pvMemBio    The memory BIO to write out.
     208 * @param   pszFilename The destination file.  This will be created.
     209 *                      The function will fail if this already exists.
     210 * @param   pErrInfo    Where to provide additional error details. Optional.
     211 */
     212DECLHIDDEN(int) rtCrOpenSslWriteMemBioToNewFile(void *pvMemBio, const char *pszFilename, PRTERRINFO pErrInfo)
     213{
     214    int rc;
     215
     216    /* Get the BIO buffer pointer first. */
     217    BUF_MEM *pBioBuf = NULL;
     218    long rcOssl = BIO_get_mem_ptr((BIO *)pvMemBio, &pBioBuf);
     219    if (rcOssl > 0)
     220    {
     221        AssertPtr(pBioBuf);
     222        RTFILE hFile = NIL_RTFILE;
     223        rc = RTFileOpen(&hFile, pszFilename,
     224                        RTFILE_O_WRITE | RTFILE_O_DENY_ALL | RTFILE_O_CREATE | (0600 << RTFILE_O_CREATE_MODE_SHIFT));
     225        if (RT_SUCCESS(rc))
     226        {
     227            rc = RTFileWrite(hFile, pBioBuf->data, pBioBuf->length, NULL);
     228            if (RT_SUCCESS(rc))
     229            {
     230                rc = RTFileClose(hFile);
     231                AssertRCStmt(rc, rc = RTErrInfoSetF(pErrInfo, rc, "RTFileClose failed on '%s'", pszFilename));
     232            }
     233            else
     234            {
     235                rc = RTErrInfoSetF(pErrInfo, rc, "RTFileWrite(,,%#zx,) failed on '%s'", pBioBuf->length, pszFilename);
     236                RTFileClose(hFile);
     237            }
     238            if (RT_FAILURE(rc))
     239                RTFileDelete(pszFilename);
     240        }
     241        else
     242            rc = RTErrInfoSetF(pErrInfo, rc, "RTFileOpen failed on '%s'", pszFilename);
     243    }
     244    else
     245        rc = RTErrInfoSet(pErrInfo, VERR_GENERAL_FAILURE, "BIO_get_mem_ptr");
     246    return rc;
     247}
     248
     249
    201250#endif /* IPRT_WITH_OPENSSL */
    202251
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