VirtualBox

Changeset 91396 in vbox for trunk/src


Ignore:
Timestamp:
Sep 27, 2021 1:40:35 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
147076
Message:

Main: Add IUefiVariableStore interface to manage the content of the UEFI variable store for secure boot support, bugref:9580

Location:
trunk/src/VBox/Main
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/Makefile.kmk

    r91381 r91396  
    401401
    402402testschemadefs: $(VBOX_XML_SCHEMADEFS_H) $(VBOX_XML_SCHEMADEFS_CPP)
     403
     404
     405#
     406# Trust anchors and certificates -> .cpp
     407#
     408VBOX_SVC_CERTS_FILE = $(VBoxSVC_0_OUTDIR)/TrustAnchorsAndCerts.cpp
     409VBOX_SVC_CERTS := \
     410       UefiMicrosoftKek=MicCorKEKCA2011_2011-06-24.crt \
     411       UefiMicrosoftCa=MicCorUEFCA2011_2011-06-27.crt \
     412       UefiMicrosoftProPca=MicWinProPCA2011_2011-10-19.crt
     413
     414VBOX_SVC_CERT_NAMES := $(foreach cert,$(VBOX_SVC_CERTS),$(firstword $(subst =,$(SPACE) ,$(cert))))
     415VBOX_SVC_PATH_CERTIFICATES := $(PATH_SUB_CURRENT)/Certificates
     416
     417$$(VBOX_SVC_CERTS_FILE): $(MAKEFILE_CURRENT) \
     418                $(foreach cert,$(VBOX_SVC_CERTS),$(VBOX_SVC_PATH_CERTIFICATES)/$(lastword $(subst =,$(SPACE) ,$(cert)))) \
     419                $(VBOX_BIN2C) \
     420                | $$(dir $$@)
     421        $(QUIET)$(RM) -f -- $@
     422        $(QUIET)$(APPEND) -n "$@" \
     423        '' \
     424        '#include "TrustAnchorsAndCerts.h"' \
     425               ''
     426        $(foreach cert,$(VBOX_SVC_CERTS), $(NLTAB)$(VBOX_BIN2C) -ascii --append \
     427                "$(firstword $(subst =,$(SP) ,$(cert)))" \
     428                "$(VBOX_SVC_PATH_CERTIFICATES)/$(lastword $(subst =,$(SP) ,$(cert)))" \
     429                "$@")
     430
     431OTHER_CLEAN += $(VBOX_SVC_CERTS_FILE)
     432
     433tst-main-certificates: $(VBOX_SVC_CERTS_FILE)
    403434
    404435
     
    542573
    543574VBoxSVC_SOURCES = \
     575        $(VBOX_SVC_CERTS_FILE) \
    544576        $(VBoxAPIWrap_0_OUTDIR)/VBoxAPI.d \
    545577        src-all/AuthLibrary.cpp \
     
    615647        src-server/TokenImpl.cpp \
    616648        src-server/TrustedPlatformModuleImpl.cpp \
     649        src-server/UefiVariableStoreImpl.cpp \
    617650        $(if $(VBOX_WITH_UNATTENDED), \
    618651        src-server/UnattendedImpl.cpp \
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r91363 r91396  
    58975897  </interface>
    58985898
     5899   <enum
     5900    name="SignatureType"
     5901    uuid="6f6e67ef-9a32-4084-af84-5702679f882a"
     5902    >
     5903    <desc>
     5904      UEFI signature type enumeration.
     5905    </desc>
     5906
     5907    <const name="X509"                  value="0">
     5908      <desc>X.509 certificate.</desc>
     5909    </const>
     5910    <const name="Sha256"                value="1">
     5911      <desc>SHA256 hash.</desc>
     5912    </const>
     5913  </enum>
     5914
     5915  <interface
     5916    name="IUefiVariableStore" extends="$unknown"
     5917    uuid="f39d5888-9009-4e77-94b5-9cdcfc1859c3"
     5918    wsmap="managed"
     5919    reservedMethods="10" reservedAttributes="5"
     5920    >
     5921    <desc>
     5922        The IUefiVariableStore interface allows inspecting and manipulating the content
     5923        of an existing UEFI variable store in a NVRAM file. This is used only in the
     5924        <link to="INvramStore::uefiVariableStore" /> attribute.
     5925    </desc>
     5926
     5927    <method name="addVariable">
     5928      <desc>Adds a new variable to the non volatile storage area.</desc>
     5929      <param name="name" type="wstring" dir="in">
     5930        <desc>Name of the variable.</desc>
     5931      </param>
     5932      <param name="owner" type="uuid" mod="string" dir="in">
     5933        <desc>UUID of the variable owner.</desc>
     5934      </param>
     5935      <param name="data" type="octet" dir="in" safearray="yes">
     5936        <desc>The variable data.</desc>
     5937      </param>
     5938    </method>
     5939
     5940    <method name="deleteVariable">
     5941      <desc>Deletes the given variable from the non volatile storage area.</desc>
     5942      <param name="name" type="wstring" dir="in">
     5943        <desc>Name of the variable.</desc>
     5944      </param>
     5945      <param name="owner" type="uuid" mod="string" dir="in">
     5946        <desc>UUID of the variable owner.</desc>
     5947      </param>
     5948    </method>
     5949
     5950    <method name="changeVariable">
     5951      <desc>Changes the data of the given variable.</desc>
     5952      <param name="name" type="wstring" dir="in">
     5953        <desc>Name of the variable.</desc>
     5954      </param>
     5955      <param name="owner" type="uuid" mod="string" dir="in">
     5956        <desc>UUID of the variable owner.</desc>
     5957      </param>
     5958      <param name="data" type="octet" dir="in" safearray="yes">
     5959        <desc>The new variable data.</desc>
     5960      </param>
     5961    </method>
     5962
     5963    <method name="queryVariableByName">
     5964      <desc>Queries the variable content variable by the given name.</desc>
     5965      <param name="name" type="wstring" dir="in">
     5966        <desc>Name of the variable to look for.</desc>
     5967      </param>
     5968      <param name="owner" type="uuid" mod="string" dir="out">
     5969        <desc>UUID of the variable owner returned on success.</desc>
     5970      </param>
     5971      <param name="data" type="octet" dir="out" safearray="yes">
     5972        <desc>The variable data returned on success.</desc>
     5973      </param>
     5974    </method>
     5975
     5976    <method name="queryVariables">
     5977      <desc>
     5978        Queries all variables in the non volatile storage and returns their names.
     5979      </desc>
     5980      <param name="names" type="wstring" dir="out" safearray="yes">
     5981        <desc>The variable names returned on success.</desc>
     5982      </param>
     5983      <param name="owners" type="uuid" mod="string" dir="out" safearray="yes">
     5984        <desc>UUID of the variable owners returned on success.</desc>
     5985      </param>
     5986    </method>
     5987
     5988    <method name="enrollPlatformKey">
     5989      <desc>
     5990        Convenience method to enroll a new platform key (PK) for enabling Secure Boot.
     5991      </desc>
     5992      <param name="platformKey" type="octet" safearray="yes" dir="in">
     5993        <desc>The platform key (PK) to enroll.</desc>
     5994      </param>
     5995      <param name="owner" type="uuid" mod="string" dir="in">
     5996        <desc>UUID of the PK owner.</desc>
     5997      </param>
     5998    </method>
     5999
     6000    <method name="addKek">
     6001      <desc>
     6002        Convenience method to add a new Key Encryption Key (KEK) for Secure Boot.
     6003      </desc>
     6004      <param name="keyEncryptionKey" type="octet" safearray="yes" dir="in">
     6005        <desc>The Key Encryption Key (KEK) to add.</desc>
     6006      </param>
     6007      <param name="owner" type="uuid" mod="string" dir="in">
     6008        <desc>UUID of the KEK owner.</desc>
     6009      </param>
     6010      <param name="signatureType" type="SignatureType" dir="in">
     6011        <desc>Type of the signature.</desc>
     6012      </param>
     6013    </method>
     6014
     6015    <method name="addSignatureToDb">
     6016      <desc>
     6017        Convenience method to add a new entry to the signature database.
     6018      </desc>
     6019      <param name="signature" type="octet" safearray="yes" dir="in">
     6020        <desc>The signature to add.</desc>
     6021      </param>
     6022      <param name="owner" type="uuid" mod="string" dir="in">
     6023        <desc>UUID of the signature owner.</desc>
     6024      </param>
     6025      <param name="signatureType" type="SignatureType" dir="in">
     6026        <desc>Type of the signature.</desc>
     6027      </param>
     6028    </method>
     6029
     6030    <method name="addSignatureToDbx">
     6031      <desc>
     6032        Convenience method to add a new entry to the forbidden signature database.
     6033      </desc>
     6034      <param name="signature" type="octet" safearray="yes" dir="in">
     6035        <desc>The signature to add.</desc>
     6036      </param>
     6037      <param name="owner" type="uuid" mod="string" dir="in">
     6038        <desc>UUID of the signature owner.</desc>
     6039      </param>
     6040      <param name="signatureType" type="SignatureType" dir="in">
     6041        <desc>Type of the signature.</desc>
     6042      </param>
     6043    </method>
     6044
     6045    <method name="enrollDefaultMsSignatures">
     6046      <desc>
     6047        Convenience method to enroll the standard Microsoft KEK and signatures
     6048        in the signature databases.
     6049      </desc>
     6050    </method>
     6051
     6052  </interface>
     6053
    58996054  <interface
    59006055    name="INvramStore" extends="$unknown"
     
    59146069      </desc>
    59156070    </attribute>
     6071
     6072    <attribute name="uefiVariableStore" type="IUefiVariableStore" readonly="yes">
     6073      <desc>Object to manipulate the data in an existing UEFI variable store.</desc>
     6074    </attribute>
     6075
     6076    <method name="initUefiVariableStore">
     6077      <desc>Initializes the UEFI variable store.</desc>
     6078      <param name="size" type="unsigned long" dir="in">
     6079        <desc>
     6080          Size in bytes of the UEFI variable store. Must be 0 for now to initialize to the
     6081          default size.
     6082        </desc>
     6083      </param>
     6084    </method>
    59166085
    59176086  </interface>
  • trunk/src/VBox/Main/include/NvramStoreImpl.h

    r91346 r91396  
    8080    // Wrapped NVRAM store properties
    8181    HRESULT getNonVolatileStorageFile(com::Utf8Str &aNonVolatileStorageFile);
     82    HRESULT getUefiVariableStore(ComPtr<IUefiVariableStore> &aUefiVarStore);
    8283
    8384    // Wrapped NVRAM store members
    84     /** @todo */
     85    HRESULT initUefiVariableStore(ULONG aSize);
    8586
    8687#ifdef VBOX_COM_INPROC
  • trunk/src/VBox/Main/src-all/NvramStoreImpl.cpp

    r91346 r91396  
    2424#else
    2525# include "MachineImpl.h"
     26# include "AutoStateDep.h"
    2627#endif
     28#include "UefiVariableStoreImpl.h"
    2729
    2830#include "AutoCaller.h"
     
    9496#else
    9597    /** The Machine object owning this NVRAM store. */
    96     Machine * const         pParent;
     98    Machine * const                    pParent;
    9799    /** The peer NVRAM store object. */
    98     ComObjPtr<NvramStore>   pPeer;
     100    ComObjPtr<NvramStore>              pPeer;
     101    /** The UEFI variable store. */
     102    const ComObjPtr<UefiVariableStore> pUefiVarStore;
    99103#endif
    100104
     
    299303
    300304    return S_OK;
     305}
     306
     307
     308HRESULT NvramStore::getUefiVariableStore(ComPtr<IUefiVariableStore> &aUefiVarStore)
     309{
     310#ifndef VBOX_COM_INPROC
     311    /* the machine needs to be mutable */
     312    AutoMutableStateDependency adep(m->pParent);
     313    if (FAILED(adep.rc())) return adep.rc();
     314
     315    /* We need a write lock because of the lazy initialization. */
     316    AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
     317
     318    /* Check if we have to create the UEFI variabel store object */
     319    HRESULT hrc = S_OK;
     320    if (!m->pUefiVarStore)
     321    {
     322        /* Load the NVRAM file first if it isn't already. */
     323        if (!m->bd->mapNvram.size())
     324        {
     325            int vrc = i_loadStore();
     326            if (RT_FAILURE(vrc))
     327                hrc = setError(E_FAIL, tr("Loading the NVRAM store failed (%Rrc)\n"), vrc);
     328        }
     329
     330        if (SUCCEEDED(hrc))
     331        {
     332            NvramStoreIter it = m->bd->mapNvram.find("efi/nvram");
     333            if (it != m->bd->mapNvram.end())
     334            {
     335                RTVFSFILE hVfsFileNvram = it->second;
     336                RTVFS hVfsEfiVarStore;
     337                int vrc = RTEfiVarStoreOpenAsVfs(hVfsFileNvram, 0 /*fMntFlags*/, 0 /*fVarStoreFlags*/, &hVfsEfiVarStore,
     338                                                 NULL /*pErrInfo*/);
     339                if (RT_SUCCESS(vrc))
     340                {
     341                    unconst(m->pUefiVarStore).createObject();
     342                    m->pUefiVarStore->init(this, m->pParent, hVfsEfiVarStore);
     343                }
     344                else
     345                    hrc = setError(E_FAIL, tr("Opening the UEFI variable store failed (%Rrc)."), vrc);
     346            }
     347            else
     348                hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The UEFI NVRAM file is not existing for this machine."));
     349        }
     350    }
     351
     352    if (SUCCEEDED(hrc))
     353        m->pUefiVarStore.queryInterfaceTo(aUefiVarStore.asOutParam());
     354
     355    return hrc;
     356#else
     357    NOREF(aUefiVarStore);
     358    return E_NOTIMPL;
     359#endif
     360}
     361
     362
     363HRESULT NvramStore::initUefiVariableStore(ULONG aSize)
     364{
     365    NOREF(aSize);
     366    return E_NOTIMPL;
    301367}
    302368
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette