Skip to content

Latest commit

 

History

History
296 lines (237 loc) · 8.34 KB

nf-bits2_5-ibackgroundcopyjobhttpoptions-setclientcertificatebyid.md

File metadata and controls

296 lines (237 loc) · 8.34 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:bits2_5.IBackgroundCopyJobHttpOptions.SetClientCertificateByID
IBackgroundCopyJobHttpOptions::SetClientCertificateByID (bits2_5.h)
Specifies the identifier of the client certificate to use for client authentication in an HTTPS (SSL) request.
CA
IBackgroundCopyJobHttpOptions interface [BITS]
SetClientCertificateByID method
IBackgroundCopyJobHttpOptions.SetClientCertificateByID
IBackgroundCopyJobHttpOptions::SetClientCertificateByID
MY
ROOT
SPC
SetClientCertificateByID
SetClientCertificateByID method [BITS]
SetClientCertificateByID method [BITS]
IBackgroundCopyJobHttpOptions interface
bits.ibackgroundcopyjobhttpoptions_setclientcertificatebyid
bits2_5/IBackgroundCopyJobHttpOptions::SetClientCertificateByID
bits\ibackgroundcopyjobhttpoptions_setclientcertificatebyid.htm
Bits
60839bac-7f5f-4c43-84d4-26f1b21f974d
12/05/2018
CA, IBackgroundCopyJobHttpOptions interface [BITS],SetClientCertificateByID method, IBackgroundCopyJobHttpOptions.SetClientCertificateByID, IBackgroundCopyJobHttpOptions::SetClientCertificateByID, MY, ROOT, SPC, SetClientCertificateByID, SetClientCertificateByID method [BITS], SetClientCertificateByID method [BITS],IBackgroundCopyJobHttpOptions interface, bits.ibackgroundcopyjobhttpoptions_setclientcertificatebyid, bits2_5/IBackgroundCopyJobHttpOptions::SetClientCertificateByID
bits2_5.h
Bits.h
Windows
Windows Vista
Windows Server 2008
Bits2_5.idl
Bits.lib
Windows
19H1
IBackgroundCopyJobHttpOptions::SetClientCertificateByID
bits2_5/IBackgroundCopyJobHttpOptions::SetClientCertificateByID
c++
APIRef
kbSyntax
COM
Bits.lib
Bits.dll
IBackgroundCopyJobHttpOptions.SetClientCertificateByID

IBackgroundCopyJobHttpOptions::SetClientCertificateByID

-description

Specifies the identifier of the client certificate to use for client authentication in an HTTPS (SSL) request.

-parameters

-param StoreLocation [in]

Identifies the location of a system store to use for looking up the certificate. For possible values, see the BG_CERT_STORE_LOCATION enumeration.

-param StoreName [in]

Null-terminated string that contains the name of the certificate store. The string is limited to 256 characters, including the null terminator. You can specify one of the following system stores or an application-defined store. The store can be a local or remote store.

Value Meaning
CA
Certification authority certificates
MY
Personal certificates
ROOT
Root certificates
SPC
Software Publisher Certificate

-param pCertHashBlob [in]

SHA1 hash that identifies the certificate. Use a 20 byte buffer for the hash. For more information, see Remarks.

-returns

The following table lists some of the possible return values.

Return code Description
S_OK
Success.
E_ACCESSDENIED
The user does not have permission to access the store location.
E_NOTIMPL
The value for the StoreLocation parameter is not defined in the BG_CERT_STORE_LOCATION enumeration.
HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)
Could not find a store matching the StoreName parameter.
CRYPT_E_NOT_FOUND
A certificate matching the hash was not found.
RPC_X_NULL_REF_POINTER
The StoreName or pCertHashBlob parameter cannot be NULL.
RPC_X_BAD_STUB_DATA
The pCertHashBlob buffer size is not 20 bytes.
BG_E_STRING_TOO_LONG
The StoreName parameter is more than 256 characters.
BG_E_INVALID_STATE
The state of the job cannot be BG_JOB_STATE_CANCELLED or BG_JOB_STATE_ACKNOWLEDGED.

-remarks

Only the job owner can specify the client certificate. If the job changes ownership, BITS removes the certificate from the job.

The client certificate is applicable only for remote files that use the HTTP or HTTPS protocol. You can specify a certificate for all job types.

When a website accepts but does not require an SSL client certificate, and the BITS job does not specify a client certificate, the job will fail with ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED (0x80072f0c).

If you create a certificate for the job or application, you could store the certificate identifier (thumbprint) in the registry or database and use it when a job requires a certificate. You could also enumerate the certificates in the store and let the user choose the certificate. Another alternative is to call the CertFindCertificateInStore function to retrieve the certificate context based on some criteria. Using the context, call the CertGetCertificateContextProperty function to retrieve the hash (specify CERT_HASH_PROP_ID for dwPropId).

SmartCard thumbprints are not supported.

Examples

The following example shows how to specify a client certificate for a job using the thumbprint of the certificate. The example hard codes the thumbprint of the certificate and assumes pJob points to a valid job.

  HRESULT hr = S_OK;
  IBackgroundCopyJob* pJob = NULL;  
  IBackgroundCopyJobHttpOptions* pHttpOptions = NULL;
  BYTE Thumbprint[] = {0xa1, 0x06, 0x6e, 0x13, 0xf2, 0x34, 0x49, 0x0a, 0x22, 0xd7, 0x6f, 0xb2, 0x80, 0xab, 0x68, 0x7d, 0x16, 0x55, 0xb3, 0x14};


  // Retrieve a pointer to the IBackgroundCopyJob4 interface.
  hr = pJob->QueryInterface(__uuidof(IBackgroundCopyJobHttpOptions), (void**)&pHttpOptions);
  pJob->Release();
  if (FAILED(hr))
  {
    wprintf(L"QueryInterface for HttpOptions failed with 0x%x.\n", hr);
    goto cleanup;
  }

  // Use the client certificate in the current user's personal (MY) store.
  hr = pHttpOptions->SetClientCertificateByID(BG_CERT_STORE_LOCATION_CURRENT_USER, 
      L"MY", Thumbprint);
  if (FAILED(hr))
  {
    wprintf(L"pHttpOptions->SetClientCertificateByID failed with 0x%x.\n", hr);
    goto cleanup;
  }


cleanup:

  if (pHttpOptions)
  {
    hr = pHttpOptions->Release();
  }

-see-also

IBackgroundCopyJobHttpOptions

IBackgroundCopyJobHttpOptions::GetClientCertificate

IBackgroundCopyJobHttpOptions::RemoveClientCertificate

IBackgroundCopyJobHttpOptions::SetClientCertificateByName