Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
after(() => {
object.destroy();
// set default value for objectId
graphene.registerAttribute(attrName, pkcs11.CKA_LABEL, "string");
});
before(() => {
object = session.create({
class: graphene.ObjectClass.DATA,
label: "data.set",
objectId: Buffer.from("my custom id"),
token: false,
value: Buffer.from("Hello"),
});
// change default type of attribute
graphene.registerAttribute(attrName, pkcs11.CKA_LABEL, "buffer");
});
/*
* Workaround for opencryptoki bug reporting wrong ecpt length.
*/
ecpt = this._fixEcpt(ecpt);
logger.debug(__func() + 'ecpt[' + ecpt.length + ']: ' +
util.inspect(ecpt, {depth: null}));
/*
* Set CKA_ID of public and private key to be SKI.
*/
const ski = HashPrimitives.SHA2_256(ecpt, null /* We want a Buffer */);
this._pkcs11SetAttributeValue(
pkcs11, pkcs11Session, handles.publicKey,
[{type: pkcs11js.CKA_ID, value: ski}, {type: pkcs11js.CKA_LABEL, value: ski.toString('hex')}]);
this._pkcs11SetAttributeValue(
pkcs11, pkcs11Session, handles.privateKey,
[{type: pkcs11js.CKA_ID, value: ski}, {type: pkcs11js.CKA_LABEL, value: ski.toString('hex')}]);
logger.debug(__func() + 'pub ski: ' + util.inspect(
(this._pkcs11GetAttributeValue(
pkcs11, pkcs11Session, handles.publicKey,
[{type: pkcs11js.CKA_ID}]))[0].value,
{depth: null}));
logger.debug(__func() + 'priv ski: ' + util.inspect(
(this._pkcs11GetAttributeValue(
pkcs11, pkcs11Session, handles.privateKey,
[{type: pkcs11js.CKA_ID}]))[0].value,
{depth: null}));
return {ski, ecpt, pub: handles.publicKey, priv: handles.privateKey};
}
(this._pkcs11GetAttributeValue(
pkcs11, pkcs11Session, handles.publicKey,
[{type: pkcs11js.CKA_EC_POINT}]))[0].value;
/*
* Workaround for opencryptoki bug reporting wrong ecpt length.
*/
ecpt = this._fixEcpt(ecpt);
logger.debug(__func() + 'ecpt[' + ecpt.length + ']: ' +
util.inspect(ecpt, {depth: null}));
/*
* Set CKA_ID of public and private key to be SKI.
*/
const ski = HashPrimitives.SHA2_256(ecpt, null /* We want a Buffer */);
this._pkcs11SetAttributeValue(
pkcs11, pkcs11Session, handles.publicKey,
[{type: pkcs11js.CKA_ID, value: ski}, {type: pkcs11js.CKA_LABEL, value: ski.toString('hex')}]);
this._pkcs11SetAttributeValue(
pkcs11, pkcs11Session, handles.privateKey,
[{type: pkcs11js.CKA_ID, value: ski}, {type: pkcs11js.CKA_LABEL, value: ski.toString('hex')}]);
logger.debug(__func() + 'pub ski: ' + util.inspect(
(this._pkcs11GetAttributeValue(
pkcs11, pkcs11Session, handles.publicKey,
[{type: pkcs11js.CKA_ID}]))[0].value,
{depth: null}));
logger.debug(__func() + 'priv ski: ' + util.inspect(
(this._pkcs11GetAttributeValue(
pkcs11, pkcs11Session, handles.privateKey,
[{type: pkcs11js.CKA_ID}]))[0].value,
{depth: null}));
return {ski, ecpt, pub: handles.publicKey, priv: handles.privateKey};
/**
* Type of Attribute
*/
t: AttributeItemType;
}
interface IAttributeItems {
[key: string]: IAttributeItem;
}
const attribute: IAttributeItems = {
/* The following attribute types are defined: */
class: { v: pkcs11.CKA_CLASS, t: TYPE_NUMBER },
token: { v: pkcs11.CKA_TOKEN, t: TYPE_BOOL },
private: { v: pkcs11.CKA_PRIVATE, t: TYPE_BOOL },
label: { v: pkcs11.CKA_LABEL, t: TYPE_STRING },
application: { v: pkcs11.CKA_APPLICATION, t: TYPE_STRING },
value: { v: pkcs11.CKA_VALUE, t: TYPE_BUFFER },
/* CKA_OBJECT_ID is new for v2.10 */
objectId: { v: pkcs11.CKA_OBJECT_ID, t: TYPE_BUFFER },
certType: { v: pkcs11.CKA_CERTIFICATE_TYPE, t: TYPE_NUMBER },
issuer: { v: pkcs11.CKA_ISSUER, t: TYPE_BUFFER },
serial: { v: pkcs11.CKA_SERIAL_NUMBER, t: TYPE_BUFFER },
/* CKA_AC_ISSUER, CKA_OWNER, and CKA_ATTR_TYPES are new
* for v2.10 */
issuerAC: { v: pkcs11.CKA_AC_ISSUER, t: TYPE_BUFFER },
owner: { v: pkcs11.CKA_OWNER, t: TYPE_BUFFER },
attrTypes: { v: pkcs11.CKA_ATTR_TYPES, t: TYPE_BUFFER },
"use strict";
var pkcs11 = require("pkcs11js");
var TYPE_NUMBER = "number";
var TYPE_BOOL = "boolen";
var TYPE_STRING = "string";
var TYPE_BUFFER = "buffer";
var TYPE_DATE = "date";
var attribute = {
class: { v: pkcs11.CKA_CLASS, t: TYPE_NUMBER },
token: { v: pkcs11.CKA_TOKEN, t: TYPE_BOOL },
private: { v: pkcs11.CKA_PRIVATE, t: TYPE_BOOL },
label: { v: pkcs11.CKA_LABEL, t: TYPE_STRING },
application: { v: pkcs11.CKA_APPLICATION, t: TYPE_STRING },
value: { v: pkcs11.CKA_VALUE, t: TYPE_BUFFER },
objectId: { v: pkcs11.CKA_OBJECT_ID, t: TYPE_BUFFER },
certType: { v: pkcs11.CKA_CERTIFICATE_TYPE, t: TYPE_NUMBER },
issuer: { v: pkcs11.CKA_ISSUER, t: TYPE_BUFFER },
serial: { v: pkcs11.CKA_SERIAL_NUMBER, t: TYPE_BUFFER },
issuerAC: { v: pkcs11.CKA_AC_ISSUER, t: TYPE_BUFFER },
owner: { v: pkcs11.CKA_OWNER, t: TYPE_BUFFER },
attrTypes: { v: pkcs11.CKA_ATTR_TYPES, t: TYPE_BUFFER },
trusted: { v: pkcs11.CKA_TRUSTED, t: TYPE_BOOL },
certCategory: { v: pkcs11.CKA_CERTIFICATE_CATEGORY, t: TYPE_NUMBER },
javaDomain: { v: pkcs11.CKA_JAVA_MIDP_SECURITY_DOMAIN, t: TYPE_NUMBER },
url: { v: pkcs11.CKA_URL, t: TYPE_STRING },
ski: { v: pkcs11.CKA_HASH_OF_SUBJECT_PUBLIC_KEY, t: TYPE_BUFFER },
aki: { v: pkcs11.CKA_HASH_OF_ISSUER_PUBLIC_KEY, t: TYPE_BUFFER },
checkValue: { v: pkcs11.CKA_CHECK_VALUE, t: TYPE_BUFFER },