diff --git a/src/VBox/Main/idl/VirtualBox.xidl b/src/VBox/Main/idl/VirtualBox.xidl index 63763167c32..90ff7deb503 100644 --- a/src/VBox/Main/idl/VirtualBox.xidl +++ b/src/VBox/Main/idl/VirtualBox.xidl @@ -24900,6 +24900,26 @@ Snapshot 1 (B.vdi) Snapshot 1 (B.vdi) + + + Returns an ICertificate structure for the VRDE Server. + + Certificate file was not found. + + + Error reading certificate file. + + + + + return ICertificate structure for CA certificate + + + + + + + Sets a VRDE specific property string. diff --git a/src/VBox/Main/include/VRDEServerImpl.h b/src/VBox/Main/include/VRDEServerImpl.h index ab3b59b7010..0cbee7d4ae7 100644 --- a/src/VBox/Main/include/VRDEServerImpl.h +++ b/src/VBox/Main/include/VRDEServerImpl.h @@ -83,6 +83,7 @@ class ATL_NO_VTABLE VRDEServer : HRESULT getAuthLibrary(com::Utf8Str &aAuthLibrary); HRESULT setAuthLibrary(const com::Utf8Str &aAuthLibrary); HRESULT getVRDEProperties(std::vector &aVRDEProperties); + HRESULT getVRDECertificate(BOOL getCACert, ComPtr &aCertificateInfo); // wrapped IVRDEServer methods HRESULT setVRDEProperty(const com::Utf8Str &aKey, diff --git a/src/VBox/Main/src-server/VRDEServerImpl.cpp b/src/VBox/Main/src-server/VRDEServerImpl.cpp index 8c495c97b10..abf3e6c66bf 100644 --- a/src/VBox/Main/src-server/VRDEServerImpl.cpp +++ b/src/VBox/Main/src-server/VRDEServerImpl.cpp @@ -29,6 +29,7 @@ #include "VRDEServerImpl.h" #include "MachineImpl.h" #include "VirtualBoxImpl.h" +#include "CertificateImpl.h" #ifdef VBOX_WITH_EXTPACK # include "ExtPackManagerImpl.h" #endif @@ -1046,6 +1047,56 @@ HRESULT VRDEServer::getVRDEExtPack(com::Utf8Str &aExtPack) return hrc; } +HRESULT VRDEServer::getVRDECertificate(BOOL getCACert, ComPtr &aCertificateInfo) +{ + + RTERRINFOSTATIC ErrInfo; + RTCRX509CERTIFICATE x509certificate; + HRESULT hrc; + ComObjPtr ptrCertificateInfo; + Utf8Str strServerCertificate; + + if (getCACert) + { + strServerCertificate = mData->mapProperties["Security/CACertificate"]; + } + else + { + strServerCertificate = mData->mapProperties["Security/ServerCertificate"]; + } + + int vrc = mParent->i_calculateFullPath(strServerCertificate, strServerCertificate); + AssertRCReturn(vrc, VBOX_E_IPRT_ERROR); + + if (RTFileExists(strServerCertificate.c_str())) + { + vrc = RTCrX509Certificate_ReadFromFile(&x509certificate, strServerCertificate.c_str(), + RTCRX509CERT_READ_F_PEM_ONLY, &g_RTAsn1DefaultAllocator, + RTErrInfoInitStatic(&ErrInfo)); + if (RT_FAILURE(vrc)) + { + RTCrX509Certificate_Delete(&x509certificate); + return setError(VBOX_E_FILE_ERROR, tr("Failed to read certificate '%s': %Rrc%#RTeim\n"), + strServerCertificate.c_str(), vrc, &ErrInfo.Core); + } + + ptrCertificateInfo.createObject(); + hrc = ptrCertificateInfo->initCertificate(&x509certificate, false, false); + if (SUCCEEDED(hrc)) + { + /* set the return value */ + ptrCertificateInfo.queryInterfaceTo(aCertificateInfo.asOutParam()); + } + RTCrX509Certificate_Delete(&x509certificate); + } + else + { + hrc = VERR_FILE_NOT_FOUND; + } + + return hrc; +} + // public methods only for internal purposes ///////////////////////////////////////////////////////////////////////////// HRESULT VRDEServer::setVRDEExtPack(const com::Utf8Str &aExtPack)