From 0041cd1a2093a996da500b56bee0cce2ca80243f Mon Sep 17 00:00:00 2001 From: thedisbo1125 Date: Tue, 27 Jan 2026 01:29:35 -0500 Subject: [PATCH] Add the ability to view RDP certificates through the webservice. Signed-off-by: thedisbo1125 --- src/VBox/Main/idl/VirtualBox.xidl | 20 ++++++++++ src/VBox/Main/include/VirtualBoxImpl.h | 3 ++ src/VBox/Main/src-server/VirtualBoxImpl.cpp | 43 +++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/src/VBox/Main/idl/VirtualBox.xidl b/src/VBox/Main/idl/VirtualBox.xidl index a8b4e912806..e553c6e9e67 100644 --- a/src/VBox/Main/idl/VirtualBox.xidl +++ b/src/VBox/Main/idl/VirtualBox.xidl @@ -3035,6 +3035,26 @@ + + + Returns an ICertificate structure for the requested certificate. + + Certificate file was not found. + + + Error reading certificate file. + + + + + Name and path of the certificate file. + + + + + + + diff --git a/src/VBox/Main/include/VirtualBoxImpl.h b/src/VBox/Main/include/VirtualBoxImpl.h index a02882359bc..92713d550c5 100644 --- a/src/VBox/Main/include/VirtualBoxImpl.h +++ b/src/VBox/Main/include/VirtualBoxImpl.h @@ -56,6 +56,7 @@ class GuestOSType; class Progress; class Host; class SystemProperties; +class Certificate; class DHCPServer; class PerformanceCollector; class CloudProviderManager; @@ -357,6 +358,8 @@ class ATL_NO_VTABLE VirtualBox : HRESULT getCloudProviderManager(ComPtr &aCloudProviderManager); // wrapped IVirtualBox methods + HRESULT getCertificateInfo(const com::Utf8Str &aCertificateFilename, + ComPtr &aCertificateInfo); HRESULT composeMachineFilename(const com::Utf8Str &aName, const com::Utf8Str &aGroup, const com::Utf8Str &aCreateFlags, diff --git a/src/VBox/Main/src-server/VirtualBoxImpl.cpp b/src/VBox/Main/src-server/VirtualBoxImpl.cpp index 5d80f4803af..b1641ee828b 100644 --- a/src/VBox/Main/src-server/VirtualBoxImpl.cpp +++ b/src/VBox/Main/src-server/VirtualBoxImpl.cpp @@ -77,6 +77,7 @@ #include "HostImpl.h" #include "USBControllerImpl.h" #include "SystemPropertiesImpl.h" +#include "CertificateImpl.h" #include "GuestOSTypeImpl.h" #include "NetworkServiceRunner.h" #include "DHCPServerImpl.h" @@ -389,6 +390,7 @@ struct VirtualBox::Data const RTTHREAD threadAsyncEvent; EventQueue * const pAsyncEventQ; const ComObjPtr pEventSource; + ComObjPtr ptrCertificateInfo; #ifdef VBOX_WITH_EXTPACK /** The extension pack manager object lives here. */ @@ -1091,6 +1093,12 @@ void VirtualBox::uninit() unconst(m->pSystemProperties).setNull(); } + if (m->ptrCertificateInfo) + { + m->ptrCertificateInfo->uninit(); + unconst(m->ptrCertificateInfo).setNull(); + } + if (m->pHost) { m->pHost->uninit(); @@ -1280,6 +1288,41 @@ HRESULT VirtualBox::getSystemProperties(ComPtr &aSystemProper return S_OK; } +HRESULT VirtualBox::getCertificateInfo(const com::Utf8Str &aCertificateFilename, + ComPtr &aCertificateInfo) +{ + RTERRINFOSTATIC ErrInfo; + RTCRX509CERTIFICATE x509certificate; + HRESULT hrc; + + if (RTFileExists(aCertificateFilename.c_str())) + { + int vrc = RTCrX509Certificate_ReadFromFile(&x509certificate, aCertificateFilename.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"), + aCertificateFilename.c_str(), vrc, &ErrInfo.Core); + } + + m->ptrCertificateInfo.createObject(); + hrc = m->ptrCertificateInfo->initCertificate(&x509certificate, false, false); + if (SUCCEEDED(hrc)) + { + /* set the return value */ + m->ptrCertificateInfo.queryInterfaceTo(aCertificateInfo.asOutParam()); + } + } + else + { + hrc = VERR_FILE_NOT_FOUND; + } + + return hrc; +} + HRESULT VirtualBox::getMachines(std::vector > &aMachines) { AutoReadLock al(m->allMachines.getLockHandle() COMMA_LOCKVAL_SRC_POS);