Certificate.js

Use these functions for X.509 credential handling.

Use these functions to create a user interface in HTML and JavaScript, that uses X.509 certificates as the Workflow credentials.

This file contains the functions that allow parsing a certificate date, creating a certificate from a JSON string value, retrieving a certificate from a file (Android), retrieving a certificate from the server (iOS), and so on.

Function Description
CertificateStore.parseCertDate(value) Parses a certificate date.
CertificateStore.createCert(value) Creates a certificate from the specified JSON string value.
CertificateStore.prototype.certificateLabels(filterSubject, filterIssuer) Returns a list of all the certificate labels in this store (can be empty). Each certificate in this store has a unique label.
CertificateStore.getDefault() Returns a certificate without the signedCertificate part set.
CertificateStore.prototype.getPublicCertificate(label) Returns a certificate without the signedCertificate part set.
Supported platforms:
  • Windows Mobile Professional
  • BlackBerry
CertificateStore.prototype.getSignedCertificate(label, password) Returns the certificate with the specified label, decrypting it if necessary using the specified password; or returns null if the certificate is encrypted and the password is incorrect.
Supported platforms:
  • Windows Mobile Professional
  • BlackBerry
CertificateStore.prototype.listAvailableCertificatesFromFileSystem(folder, fileExtension) Returns a list of full path names for the certificate files found in the file system for import.

Android platforms only.

CertificateStore.prototype.getSignedCertificateFromFile(filePath, password) Gets a certificate from a file.

Android platforms only.

CertificateStore.prototype.getSignedCertificateFromServer(username, serverPassword, certPassword) Gets a certificate from the server.

iOS platforms only.

getSignedCertificateFromAfaria(commonName, challengeCode) To retrieve an x509 certificate from Afaria, you must get a CertificateStore and then call getSignedCertificateFromAfaria. If Afaria is installed and configured on the device, this gets the Afaria seeding file from the Afaria server. If the seeding file is retrieved from the Afaria server, the user is prompted to update user specific information in the Settings screen. The parameters are:
  • commonName – this parameter is required.
  • challengeCode – this parameter is optional, depending on how the Afaria server is configured.

    For example:

    var certStore = CertificateStore.getDefault(); afariaCert = certStore.getSignedCertificateFromAfaria(commonName, challengeCode);

You can choose to set the results of a getSignedCertificate function as the password.

Example 1

certificateLabels(filterSubject, filterIssuer)

// The following script gets all the labels for certificates 
// with the provided subject and issuer
var certStore = CertificateStore.getDefault();
var labels = certStore.certificateLabels("MyUser", "mydomain.com");

- getPublicCertificate(label)

// The following script gets the certificate data for the first
// certificate to match the provided subject and issuer
var certStore = CertificateStore.getDefault();
var labels = certStore.certificateLabels("MyUser", "mydomain.com");
var cert = certStore.getPublicCertificate(labels[0]);

- getSignedCertificate(label)

// The following script gets the signed certificate data for the first
// certificate to match the provided subject and issuer
var certStore = CertificateStore.getDefault();
var labels = certStore.certificateLabels("MyUser", mydomain.com");
var cert = certStore.getSignedCertificate(labels[0]);

var username = cert.subjectCN;
var password = cert.signedCertificate;

- listAvailableCertificatesFromFileSystem(sFolder, sFileExtension)

// The following script gets an array of file paths for files on
// the sdcard with the extension p12
var certStore = CertificateStore.getDefault();
var certPaths = certStore.listAvailableCertificatesFromFileSystem("/sdcard/", "p12");

- getSignedCertificateFromFile(filePath, password)

// The following script gets the signed certificate data for the first
// p12 file found on the sdcard
var certStore = CertificateStore.getDefault();
var certPaths = certStore.listAvailableCertificatesFromFileSystem("/sdcard/", "p12");
var cert = certStore.getSignedCertificateFromFile(certPaths[0], "password");

- getSignedCertificateFromServer(username, serverPassword, certPassword) 

// The following script gets the signed certificate data for the 
// user MYDOMAIN\MYUSERNAME from the server
var certStore = CertificateStore.getDefault();
cert = certStore.getSignedCertificateFromServer("MYDOMAIN\\MYUSERNAME", "myserverpassword", "mycertpassword");