Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as pkcs11js from "pkcs11js";
const libPath = "C:\\tmp\\rtpkcs11ecp.dll";
let pkcs11 = new pkcs11js.PKCS11();
pkcs11.load(libPath);
pkcs11.C_Initialize();
try {
// Getting info about PKCS11 Module
let module_info = pkcs11.C_GetInfo();
// Getting list of slots
let slots = pkcs11.C_GetSlotList(true);
let slot = slots[0];
// Getting info about slot
let slot_info = pkcs11.C_GetSlotInfo(slot);
// Getting info about token
let token_info = pkcs11.C_GetTokenInfo(slot);
context("Slot", () => {
let mod = new pkcs11.PKCS11();;
let slot;
before(() => {
mod.load(config.lib);
mod.C_Initialize();
const slots = mod.C_GetSlotList();
slot = slots[0];
});
after(() => {
mod.C_Finalize();
});
it("Info", () => {
const info = mod.C_GetSlotInfo(slot);
context("RSA", () => {
let mod = new pkcs11.PKCS11();;
let slot, session;
before(() => {
mod.load(config.lib);
mod.C_Initialize();
const slots = mod.C_GetSlotList();
slot = slots[0];
session = mod.C_OpenSession(slot, pkcs11.CKF_RW_SESSION | pkcs11.CKF_SERIAL_SESSION);
});
after(() => {
mod.C_CloseAllSessions(slot);
mod.C_Finalize();
});
context("GenerateKeyPair", () => {
context("EC", () => {
let mod = new pkcs11.PKCS11();;
let slot, session;
before(() => {
mod.load(config.lib);
mod.C_Initialize();
const slots = mod.C_GetSlotList();
slot = slots[0];
session = mod.C_OpenSession(slot, pkcs11.CKF_RW_SESSION | pkcs11.CKF_SERIAL_SESSION);
});
after(() => {
mod.C_CloseAllSessions(slot);
mod.C_Finalize();
});
context("GenerateKeyPair", () => {
Module.load = function (libFile, libName) {
var lib = new pkcs11.PKCS11();
lib.load(libFile);
var module = new Module(lib);
module.libFile = libFile;
module.libName = libName || libFile;
return module;
};
return Module;
super();
this._keySize = keySize;
this._curveName = `secp${this._keySize}r1`;
this._ecdsaCurve = elliptic.curves[`p${this._keySize}`];
this._hashAlgo = hashAlgo;
this._hashFunction = HashPrimitives[hashPair];
/*
* Load native PKCS11 library, open PKCS11 session and login.
*/
if (_pkcs11 === null) {
_pkcs11 = new pkcs11js.PKCS11();
}
this._pkcs11 = _pkcs11;
this._pkcs11OpenSession(this._pkcs11, pkcs11Lib, pkcs11Slot, pkcs11Pin, pkcs11UserType, pkcs11ReadWrite);
/*
* SKI to key cache for getKey(ski) function.
*/
this._skiToKey = {};
this.keyToSki = new Map();
}