export class Pkcs11VerifyPinRequest {
constructor(public pin?: string) {
}
}
export class OsResponse {
constructor(public data: Os, public success: boolean) {
}
}
export class Os {
constructor(public id: string, public version: string) {
}
}
export class PrivateKeyTypeResponse {
constructor(public data: PrivateKeyType, public success: boolean) {
}
}
export class PrivateKeyType {
constructor(public data: string) {
}
}
export class Certificate {
constructor(public certificate?: string, certSn?: string) {
}
}
export class AliasesResponse {
constructor(public data: Aliases, public success: boolean) {
}
}
export class Aliases {
constructor(public aliases: Alias[]) {
}
}
export class Alias {
constructor(public ref: string) {
}
}
export class Pkcs11UploadConfigResponse {
constructor(public data: string, public success: boolean) {
}
}
export class Pkcs11ClearConfigResponse {
constructor(public data: string, public success: boolean) {
}
}
export class Pkcs11GetConfigResponse {
constructor(public data: Pkcs11GetConfig, public success: boolean) {
}
}
export class Pkcs11GetConfig {
constructor(public sessionRef?: string, public tempPath?: string) {
}
}
export class Pkcs11InfoResponse {
constructor(public data: Pkcs11Info, public success: boolean) {
}
}
export class Pkcs11SlotInfoResponse {
constructor(public data: Pkcs11Slot, public success: boolean) {
}
}
export class Pkcs11Info {
constructor(public cryptokiVersion: string,
public manufacturerId: string,
public libraryDescription: string,
public libraryVersion: string) {
}
}
export class Pkcs11Slots {
constructor(public slots: Pkcs11Slot[]) {
}
}
export class Pkcs11Slot {
constructor(public slot: string,
public description: string) {
}
}
export class Pkcs11SlotsResponse {
constructor(public data: Pkcs11Slots, public success: boolean) {
}
}
export class Pkcs11Certificate {
constructor(public cert: string, public certSn: string, public parsed?: object) {
}
}
export class Pkcs11CertificatesResponse {
constructor(public data: Pkcs11Certificate[], public success: boolean) {
}
}
export class Pkcs11SignRequest {
constructor(public algorithm: string,
public data: string,
public pin?: string) {
}
}
export class Pkcs11Config {
constructor(public config: string) {
}
}
export class Pkcs11TokenInfo {
constructor(public slot: string,
public label: string,
public manufacturerId: string,
public model: string,
public serialNumber: string,
public flags: string,
public ulMaxSessionCount: number,
public ulSessionCount: number,
public ulMaxRwSessionCount: number,
public ulMaxPinLen: number,
public ulMinPinLen: number,
public ulTotalPublicMemory: number,
public ulFreePublicMemory: number,
public ulTotalPrivateMemory: number,
public ulFreePrivateMemory: number,
public hardwareVersion: string,
public firmwareVersion: string) {
}
}
export class Pkcs11TokenResponse {
constructor(public data: Pkcs11TokenInfo, public success: boolean) {
}
}
export class Pkcs11ModuleConfig {
constructor(public linux: string, public mac: string, public win: string) {
}
}
Initialising the SDK
Before you are able to use the SDK's methods you need to initialise the trust1connector javascript SDK. Below you can find an example of how to do this. You can also check the integration in web applications page.
In this example you can see when the connector is initialised we try to fetch the pkcs11 configuration already loaded in (if present), if this is not loaded you still need to upload the configuration. (line 30)
we store the client data for later use (line 27)
After initialising the configuration we can fetch all available slots to display on the screen. (line 31)
Configuration
Example
Example config contents
name = Safenet
library = /usr/local/lib/libeTPkcs11.dylib
showInfo=true
slot=0
The most important config values are the name and the library (location of the PKCS11 dylib or DLL).
Base64 ecoding the config contents described in the codeblock above and sending them via the uploadConfig method of the JS sdk will enable you to upload and use that pkcs11 configuration.
Upload configuration
To be able to use the PKCS11 generic you need to upload a correct configuration file, which includes the name and library to be used. We use a html file chooser to fetch a file and use the FilereaderAPI to retrieve the contents of the selected file, then we convert it to a base64 string which we send to the uploadConfig method
const selectedFile = document.querySelector("#pkcs11ConfigFile").files[0];
var reader = new FileReader();
reader.onload = function(evt) {
client.pkcs11Generic().uploadConfig(btoa(evt.target.result))
.then(res => {
// Display something in the UI
})
.catch(err => {
// Display something in the UI
})
};
reader.readAsText(selectedFile);
Get configuration
client.pkcs11Generic().getConfig()
.then(res => {
// Display current config in UI
}, err => {
// error code 806 will be thrown when no config present
})
Clear configuration
This method is used to clear a currently active configuration