Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function create_template(session: Session, alg: EcKeyGenParams, extractable: boolean, keyUsages: string[]): ITemplatePair {
const label = `EC-${alg.namedCurve}`;
const idKey = utils.GUID(session);
const keyType = KeyType.ECDSA;
return {
privateKey: {
token: !!process.env.WEBCRYPTO_PKCS11_TOKEN,
sensitive: !!process.env.WEBCRYPTO_PKCS11_SENSITIVE,
class: ObjectClass.PRIVATE_KEY,
keyType,
private: true,
label,
id: idKey,
extractable,
derive: keyUsages.indexOf("deriveKey") !== -1 || keyUsages.indexOf("deriveBits") !== -1,
sign: keyUsages.indexOf("sign") !== -1,
decrypt: keyUsages.indexOf("decrypt") !== -1,
unwrap: keyUsages.indexOf("unwrapKey") !== -1,
},
publicKey: {
token: !!process.env.WEBCRYPTO_PKCS11_TOKEN,
class: ObjectClass.PUBLIC_KEY,
keyType,
private: false,
label,
public static getID(p11Key: Key) {
let name: string;
switch (p11Key.class) {
case ObjectClass.PRIVATE_KEY:
name = "private";
break;
case ObjectClass.PUBLIC_KEY:
name = "public";
break;
case ObjectClass.SECRET_KEY:
name = "secret";
break;
default:
throw new Error(`Unsupported Object type '${ObjectClass[p11Key.class]}'`);
}
return `${name}-${p11Key.handle.toString("hex")}-${p11Key.id.toString("hex")}`;
}
protected static createTemplate(session: graphene.Session, alg: RsaHashedKeyGenParams, extractable: boolean, keyUsages: string[]): ITemplatePair {
const label = `RSA-${alg.modulusLength}`;
const idKey = utils.GUID(session);
return {
privateKey: {
token: !!process.env.WEBCRYPTO_PKCS11_TOKEN,
sensitive: !!process.env.WEBCRYPTO_PKCS11_SENSITIVE,
class: ObjectClass.PRIVATE_KEY,
keyType: KeyType.RSA,
private: true,
label,
id: idKey,
extractable,
derive: false,
sign: keyUsages.indexOf("sign") > -1,
decrypt: keyUsages.indexOf("decrypt") > -1,
unwrap: keyUsages.indexOf("unwrapKey") > -1,
},
publicKey: {
token: !!process.env.WEBCRYPTO_PKCS11_TOKEN,
class: ObjectClass.PUBLIC_KEY,
keyType: KeyType.RSA,
private: false,
label,
function create_template(session: Session, alg: RsaHashedKeyGenParams, extractable: boolean, keyUsages: string[]): ITemplatePair {
const label = `RSA-${alg.modulusLength}`;
const idKey = utils.GUID(session);
return {
privateKey: {
token: !!process.env.WEBCRYPTO_PKCS11_TOKEN,
sensitive: !!process.env.WEBCRYPTO_PKCS11_SENSITIVE,
class: ObjectClass.PRIVATE_KEY,
keyType: KeyType.RSA,
private: true,
label,
id: idKey,
extractable,
derive: false,
sign: keyUsages.indexOf("sign") > -1,
decrypt: keyUsages.indexOf("decrypt") > -1,
unwrap: keyUsages.indexOf("unwrapKey") > -1,
},
publicKey: {
token: !!process.env.WEBCRYPTO_PKCS11_TOKEN,
class: ObjectClass.PUBLIC_KEY,
keyType: KeyType.RSA,
private: false,
label,