Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/VBox/Main/idl/VirtualBox.xidl
Original file line number Diff line number Diff line change
Expand Up @@ -3035,6 +3035,26 @@
</desc>
</attribute>

<method name="getCertificateInfo">
<desc>
Returns an ICertificate structure for the requested certificate.
<result name="VERR_FILE_NOT_FOUND">
Certificate file was not found.
</result>
<result name="VBOX_E_FILE_ERROR">
Error reading certificate file.
</result>
</desc>
<param name="CertificateFilename" type="wstring" dir="in">
<desc>
Name and path of the certificate file.
</desc>
</param>
<param name="CertificateInfo" type="ICertificate" dir="return">
<desc></desc>
</param>
</method>

<method name="composeMachineFilename">
<rest request="get" path="/server/method/"/>
<desc>
Expand Down
3 changes: 3 additions & 0 deletions src/VBox/Main/include/VirtualBoxImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class GuestOSType;
class Progress;
class Host;
class SystemProperties;
class Certificate;
class DHCPServer;
class PerformanceCollector;
class CloudProviderManager;
Expand Down Expand Up @@ -357,6 +358,8 @@ class ATL_NO_VTABLE VirtualBox :
HRESULT getCloudProviderManager(ComPtr<ICloudProviderManager> &aCloudProviderManager);

// wrapped IVirtualBox methods
HRESULT getCertificateInfo(const com::Utf8Str &aCertificateFilename,
ComPtr<ICertificate> &aCertificateInfo);
HRESULT composeMachineFilename(const com::Utf8Str &aName,
const com::Utf8Str &aGroup,
const com::Utf8Str &aCreateFlags,
Expand Down
43 changes: 43 additions & 0 deletions src/VBox/Main/src-server/VirtualBoxImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -389,6 +390,7 @@ struct VirtualBox::Data
const RTTHREAD threadAsyncEvent;
EventQueue * const pAsyncEventQ;
const ComObjPtr<EventSource> pEventSource;
ComObjPtr<Certificate> ptrCertificateInfo;

#ifdef VBOX_WITH_EXTPACK
/** The extension pack manager object lives here. */
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1280,6 +1288,41 @@ HRESULT VirtualBox::getSystemProperties(ComPtr<ISystemProperties> &aSystemProper
return S_OK;
}

HRESULT VirtualBox::getCertificateInfo(const com::Utf8Str &aCertificateFilename,
ComPtr<ICertificate> &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<ComPtr<IMachine> > &aMachines)
{
AutoReadLock al(m->allMachines.getLockHandle() COMMA_LOCKVAL_SRC_POS);
Expand Down