VirtualBox

Changeset 104745 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
May 21, 2024 12:52:09 PM (6 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/Main/src-server/VRDEServerImpl.cpp

    r104618 r104745  
    241241int VRDEServer::i_generateServerCertificate()
    242242{
    243     Utf8Str strServerCertificate = "server_cert.pem";
    244     Utf8Str strServerPrivateKey = "server_key_private.pem";
    245     mParent->i_calculateFullPath(strServerCertificate, strServerCertificate);
    246     mParent->i_calculateFullPath(strServerPrivateKey, strServerPrivateKey);
    247     const char *pszServerCertificate = strServerCertificate.c_str();
    248     const char *pszServerPrivateKey = strServerPrivateKey.c_str();
    249 
    250     int vrc = RTCrX509Certificate_Generate(pszServerCertificate, pszServerPrivateKey);
    251 
     243    Utf8Str strServerCertificate("server_cert.pem");
     244    int vrc = mParent->i_calculateFullPath(strServerCertificate, strServerCertificate);
     245    AssertRCReturn(vrc, vrc);
     246
     247    Utf8Str strServerPrivateKey("server_key_private.pem");
     248    vrc = mParent->i_calculateFullPath(strServerPrivateKey, strServerPrivateKey);
     249    AssertRCReturn(vrc, vrc);
     250
     251    vrc = RTCrX509Certificate_GenerateSelfSignedRsa(RTDIGESTTYPE_SHA1, 2048 /*cBits*/, 10 * 365 * RT_SEC_1DAY,
     252                                                    0 /*fKeyUsage*/, 0 /*fExtKeyUsage*/, NULL /*pvSubjectTodo*/,
     253                                                    strServerCertificate.c_str(), strServerPrivateKey.c_str(), NULL /*pErrInfo*/);
    252254    if (RT_SUCCESS(vrc))
    253255    {
     
    255257        mData.backup();
    256258
     259/** @todo r=bird: These statements may trigger exceptions and leave
     260 * dangling server_cert.pem & server_key_private.pem files around.
     261 * Since we're not doing an active settings save here (problematic IIRC) there
     262 * are probably hundreds more likely ways this could go belly up and leave those
     263 * files behind.
     264 *
     265 * The problem is that the code relies on the _settings_ to decide whether they
     266 * are there or not, and if no it creates them.  If anything goes wrong before
     267 * we can save settings, this function will fail to retify the situation because
     268 * the file already exist and RTCrX509Certificate_GenerateSelfSignedRsa won't
     269 * overwrite existing files.
     270 *
     271 * Klaus, some settings saving input required here!
     272 */
    257273        mData->mapProperties["Security/Method"] = Utf8Str("TLS");
    258274        mData->mapProperties["Security/ServerCertificate"] = strServerCertificate;
     
    306322                int vrc = i_generateServerCertificate();
    307323                if (RT_FAILURE(vrc))
    308                 {
    309324                    LogRel(("Failed to auto generate server key and certificate: (%Rrc)\n", vrc));
    310                 }
    311325            }
    312326        }
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