SetCertificateEx Method

Applies to TestComplete 14.60, last modified on April 22, 2021

Description

Use this method to define the certificate used to represent the tested web service by specifying query parameters.

Declaration

ClientCertificateObj.SetCertificateEx(StoreLocationStoreNameFindTypeFindValue)

ClientCertificateObj An expression, variable or parameter that specifies a reference to a ClientCertificate object
StoreLocation [in]    Required    Integer    
StoreName [in]    Required    Integer    
FindType [in]    Required    Integer    
FindValue [in]    Required    String    
Result None

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

StoreLocation

Specifies the location of the X.509 certificate store. The allowed parameter values are:

Constant Value Description
slCurrentUser 0 Specifies the X.509 certificate store used by the current user.
slLocalMachine 1 Specifies the X.509 certificate store assigned to the local machine.

StoreName

Specifies the name of the X.509 certificate store to open. The allowed parameter values are:

Constant Value Description
snAddressBook 1 Specifies the X.509 certificate store for other users.
snAuthRoot 2 Specifies the X.509 certificate store for third-party certificate authorities (CAs).
snCertificateAuthority 3 Specifies the X.509 certificate store for intermediate certificate authorities (CAs).
snDisallowed 4 Specifies the X.509 certificate store for revoked certificates.
snMy 5 Specifies the X.509 certificate store for personal certificates.
snRoot 6 Specifies the X.509 certificate store for trusted root certificate authorities (CAs).
snTrustedPeople 7 Specifies the X.509 certificate store for directly trusted people and resources.
snTrustedPublisher 8 Specifies the X.509 certificate store for directly trusted publishers.

FindType

Specifies the type of the X.509 search to be executed. The allowed parameter values are:

Constant Value Description
ftFindByThumbprint 0 Finds the certificate by its thumbprint that is specified by the FindValue parameter.
ftFindBySubjectName 1 Finds the certificate by its subject name specified by the FindValue parameter.
ftFindBySubjectDistinguishedName 2 Finds the certificate by its subject distinguished name specified by the FindValue parameter.
ftFindByIssuerName 3 Finds the certificate by its issuer name specified by the ew34FindValue parameter.
ftFindByIssuerDistinguishedName 4 Finds the certificate by its issuer distinguished name specified by the FindValue parameter.
ftFindBySerialNumber 5 Finds the certificate by its serial number specified by the FindValue parameter. The serial number must be in reverse order because it is an integer.
ftFindByTimeValid 6 Finds all the certificates that will be valid till the date specified by the FindValue parameter.
ftFindByTimeNotYetValid 7 Finds all the certificates that will not be valid till the date specified by the FindValue parameter.
ftFindByTimeExpired 8 Finds all the certificates that will expire till the date specified by the FindValue parameter.
ftFindByTemplateName 9 Finds the certificate by its template name specified by the FindValue parameter.
ftFindByApplicationPolicy 10 Finds the certificate either by its application policy friendly name or by the object identifier specified by the FindValue parameter. For example, you can use the following values of the FindValue parameter: "Encrypting File System" or "1.3.6.1.4.1.311.10.3.4". For the web service that will be localized, specify the object identifier value instead of the policy friendly name.
ftFindByCertificatePolicy 11 Finds the certificate either by its friendly name or by its object identifier specified by the FindValue parameter. For the web service that will be localized, specify the object identifier value instead of the friendly name.
ftFindByExtension 12 Finds the certificate that matches the extension specified by the FindValue parameter.
ftFindByKeyUsage 13 Finds the certificate either by its key usage (as string) or by its bit mask containing all the requested key usages (as integer). The desired value is specified by the FindValue parameter. For example, you can use the following values of the FindValue parameter: "KeyEncipherment" string or the 0x30 integer that indicates "KeyEncipherment" and "DataEncipherment" key usages.
ftFindBySubjectKeyIdentifier 14 Finds the certificate by its subject key identifier in hexadecimal specified by the FindValue parameter.

FindValue

The value to be searched for in the X.509 certificate store. The type of the specified value depends on the FindType parameter.

Result Value

None.

Example

The code snippet below demonstrates how you can use the SetCertificateEx method to define the certificate by its serial number.

JavaScript, JScript

function ServiceSertificate()
{
  var MyWebService, Crd, Certificate;
  
  // Obtain the tested web service
  MyWebService = WebServices.SampleWebService;
  
  // Call a web service Credentials property
  Crd = MyWebService.Credentials;
  
  // Obtain the client certificate object
  Certificate = Crd.ClientCertificate;
  
  // Defines the client certificate
  Certificate.SetCertificateEx(slLocalMachine, snMy, ftFindBySerialNumber, "11 b3 a6 b8 85 45 bd a4 41 91 91 33 ff 32 5d c3");
}

Python

def ServiceCertificate():
  # Obtain the tested web service 
  MyWebService = WebServices.SampleWebService
  # Call a web service Credentials property  
  Crd = MyWebService.Credentials
  # Obtain the client certificate object 
  Certificate = Crd.ClientCertificate
  # Defines the client certificate 
  Certificate.SetCertificateEx(slLocalMachine, snMy, ftFindBySerialNumber, "11 b3 a6 b8 85 45 bd a4 41 91 91 33 ff 32 5d c3")

VBScript

Sub ServiceSertificate

  Dim MyWebService, Crd, Certificate
  
  ' Obtain the tested web service
  Set MyWebService = WebServices.SampleWebService
  
  ' Call a web service Credentials property
  Set Crd = MyWebService.Credentials
  
  ' Obtain the client certificate object
  Set Certificate = Crd.ClientCertificate
  
  ' Defines the client certificate
  Call Certificate.SetCertificateEx(slLocalMachine, snMy, ftFindBySerialNumber, "11 b3 a6 b8 85 45 bd a4 41 91 91 33 ff 32 5d c3")

End Sub

DelphiScript

function ServiceSertificate();
var
  MyWebService, Crd, Certificate: OleVariant;
begin
  
  // Obtain the tested web service
  MyWebService := WebServices.SampleWebService;
  
  // Call a web service Credentials property
  Crd := MyWebService.Credentials;
  
  // Obtain the client certificate object
  Certificate := Crd.ClientCertificate;
  
  // Defines the client certificate
  Certificate.SetCertificateEx(slLocalMachine, snMy, ftFindBySerialNumber, '11 b3 a6 b8 85 45 bd a4 41 91 91 33 ff 32 5d c3');

end;

C++Script, C#Script

function ServiceSertificate()
{
  var MyWebService, Crd, Certificate;
  
  // Obtain the tested web service
  MyWebService = WebServices["SampleWebService"];
  
  // Call a web service Credentials property
  Crd = MyWebService["Credentials"];
  
  // Obtain the client certificate object
  Certificate = Crd["ClientCertificate"];
  
  // Defines the client certificate
  Certificate["SetCertificateEx"]( slLocalMachine, snMy, ftFindBySerialNumber, "11 b3 a6 b8 85 45 bd a4 41 91 91 33 ff 32 5d c3" );
}

See Also

ClientCertificate Object
Testing Web Services

Highlight search results