Skip to content

Latest commit

 

History

History
273 lines (204 loc) · 8.46 KB

nf-certcli-icertrequest-getcertificate.md

File metadata and controls

273 lines (204 loc) · 8.46 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:certcli.ICertRequest.GetCertificate
ICertRequest::GetCertificate (certcli.h)
Returns the certificate issued for the request as an X.509 certificate, or optionally packaged in a Public Key Cryptography Standards (PKCS)
CCertRequest object [Security]
GetCertificate method
CR_OUT_BASE64
CR_OUT_BASE64HEADER
CR_OUT_BINARY
CR_OUT_CHAIN
CR_OUT_CRLS
GetCertificate
GetCertificate method [Security]
GetCertificate method [Security]
CCertRequest object
GetCertificate method [Security]
ICertRequest interface
GetCertificate method [Security]
ICertRequest2 interface
GetCertificate method [Security]
ICertRequest3 interface
ICertRequest interface [Security]
GetCertificate method
ICertRequest.GetCertificate
ICertRequest2 interface [Security]
GetCertificate method
ICertRequest2::GetCertificate
ICertRequest3 interface [Security]
GetCertificate method
ICertRequest3::GetCertificate
ICertRequest::GetCertificate
certcli/ICertRequest2::GetCertificate
certcli/ICertRequest3::GetCertificate
certcli/ICertRequest::GetCertificate
security.icertrequest2_getcertificate
security\icertrequest2_getcertificate.htm
security
ba8fc725-c376-4e66-8417-777ce13f2954
12/05/2018
CCertRequest object [Security],GetCertificate method, CR_OUT_BASE64, CR_OUT_BASE64HEADER, CR_OUT_BINARY, CR_OUT_CHAIN, CR_OUT_CRLS, GetCertificate, GetCertificate method [Security], GetCertificate method [Security],CCertRequest object, GetCertificate method [Security],ICertRequest interface, GetCertificate method [Security],ICertRequest2 interface, GetCertificate method [Security],ICertRequest3 interface, ICertRequest interface [Security],GetCertificate method, ICertRequest.GetCertificate, ICertRequest2 interface [Security],GetCertificate method, ICertRequest2::GetCertificate, ICertRequest3 interface [Security],GetCertificate method, ICertRequest3::GetCertificate, ICertRequest::GetCertificate, certcli/ICertRequest2::GetCertificate, certcli/ICertRequest3::GetCertificate, certcli/ICertRequest::GetCertificate, security.icertrequest2_getcertificate
certcli.h
Certsrv.h
Windows
Windows XP [desktop apps only]
Windows Server 2003 [desktop apps only]
Certidl.lib
Certcli.dll
Windows
19H1
ICertRequest::GetCertificate
certcli/ICertRequest::GetCertificate
c++
APIRef
kbSyntax
COM
Certcli.dll
ICertRequest3.GetCertificate
ICertRequest2.GetCertificate
ICertRequest.GetCertificate
CCertRequest.GetCertificate

ICertRequest::GetCertificate

-description

The GetCertificate method returns the certificate issued for the request as an X.509 certificate, or optionally packaged in a Public Key Cryptography Standards (PKCS) #7 message that contains the complete certificate chain for the Certificate Services server.

-parameters

-param Flags [in]

A flag for the format and whether the complete certificate chain is included.

The format of the returned certificate can be one of the following flags.

Value Meaning
CR_OUT_BASE64HEADER
BASE64 format with begin/end
CR_OUT_BASE64
BASE64 format without begin/end
CR_OUT_BINARY
Binary format
 

The following flags can be combined with the format flag.

Value Meaning
CR_OUT_CHAIN
Include complete certificate chain in the PKCS #7.

If this flag is not specified, only the requested certificate, in X.509 format, is returned.

CR_OUT_CRLS
Include certificate revocation lists (CRLs) in the PKCS #7.
 

For example, to retrieve a binary certificate with complete certificate chain in C++ you would write the following.

hResult = pCertReq->GetCACertificate(FALSE, bstrConfig,
     CR_OUT_BINARY | CR_OUT_CHAIN, &bstrCert);

-param pstrCertificate [out]

A pointer to the BSTR that contains the certificate, in the specified format.

When using this method, create a variable of BSTR type, set the variable equal to NULL, and then pass the address of this variable as pstrCertificate. When you have finished using the certificate pointed to by pstrCertificate, free it by calling the SysFreeString function.

-returns

If the method sets *pstrCertificate to the BSTR that contains the certificate for the request, the method returns S_OK.

If the method fails, it returns an HRESULT value that indicates the error. For a list of common error codes, see Common HRESULT Values.

-remarks

An application would call this method to retrieve the certificate issued by means of an earlier call to ICertRequest3::Submit or ICertRequest3::RetrievePending.

Examples

The following example shows retrieving a certificate.

#include <windows.h>
#include <stdio.h>
#include <Certcli.h>

HRESULT main()
{
    //  Pointer to interface object.
    ICertRequest * pCertRequest = NULL;

    //  Variable for COMPUTER\CANAME.
    BSTR         bstrCA = NULL;

    //  Variable for CA Certificate.
    BSTR         bstrCACert = NULL;

    HRESULT     hr;

    //  Initialize COM.
    hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

    //  Check status.
    if (FAILED(hr))
    {
        printf("Failed CoInitializeEx [%x]\n", hr);
        goto error;
    }

    //  Instantiate the CertConfig object.
    hr = CoCreateInstance(CLSID_CCertRequest,
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          IID_ICertRequest,
                          (void **)&pCertRequest);
    if (FAILED(hr))
    {
        printf("Failed CoCreateInstance pCertRequest [%x]\n", hr);
        goto error;
    }

    //  Note use of two backslashes (\\) in C++ 
    //  to produce one backslash (\).
    bstrCA = SysAllocString(L"server01\\myCAName");
    
    //  Retrieve the CA certificate.
    hr = pCertRequest->GetCACertificate(FALSE,
                                        bstrCA,
                                        CR_OUT_BASE64,
                                        &bstrCACert);
    if (FAILED(hr))
    {
        printf("Failed GetCACertificate [%x]\n", hr);
        goto error;
    }
    else
    {
        //  Use CA Certificate as needed.
    }

    //  Done processing.

error:

    //  Free BSTR values.
    if (NULL != bstrCA)
        SysFreeString(bstrCA);

    if (NULL != bstrCACert)
        SysFreeString(bstrCACert);

    //  Clean up object resources.
    if (NULL != pCertRequest)
        pCertRequest->Release();

    //  Free COM resources.
    CoUninitialize();

    return hr;

}

-see-also

CCertRequest

ICertRequest

ICertRequest2

ICertRequest3