How to use the pkcs11js.CKA_TOKEN function in pkcs11js

To help you get started, we’ve selected a few pkcs11js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PeculiarVentures / graphene / src / template.ts View on Github external
*/
  v: number;
  /**
   * 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 },
github PeculiarVentures / pvpkcs11 / test / rsa.js View on Github external
{ type: pkcs11.CKA_DECRYPT, value: true },
                { type: pkcs11.CKA_UNWRAP, value: true },
            ];
            const publicTemplate = [
                { type: pkcs11.CKA_ID, value: new Buffer("1234567890") },
                { type: pkcs11.CKA_PUBLIC_EXPONENT, value: new Buffer([1, 0, 1]) },
                { type: pkcs11.CKA_MODULUS_BITS, value: 1024 },
                { type: pkcs11.CKA_VERIFY, value: true },
                { type: pkcs11.CKA_ENCRYPT, value: true },
                { type: pkcs11.CKA_WRAP, value: true },
            ];

            const keys = mod.C_GenerateKeyPair(session, { mechanism: pkcs11.CKM_RSA_PKCS_KEY_PAIR_GEN, parameter: null }, publicTemplate, privateTemplate);

            let attrs = mod.C_GetAttributeValue(session, keys.privateKey, [
                { type: pkcs11.CKA_TOKEN }
            ]);
        });
    });
github PeculiarVentures / pvpkcs11 / test / ec.js View on Github external
const privateTemplate = [
                { type: pkcs11.CKA_ID, value: new Buffer("1234567890") },
                { type: pkcs11.CKA_SIGN, value: true },
                { type: pkcs11.CKA_DERIVE, value: true },
            ];
            const publicTemplate = [
                { type: pkcs11.CKA_ID, value: new Buffer("1234567890") },
                { type: pkcs11.CKA_EC_PARAMS, value: new Buffer("06082A8648CE3D030107", "hex") },
                { type: pkcs11.CKA_VERIFY, value: true },
                { type: pkcs11.CKA_DERIVE, value: true },
            ];

            const keys = mod.C_GenerateKeyPair(session, { mechanism: pkcs11.CKM_ECDSA_KEY_PAIR_GEN, parameter: null }, publicTemplate, privateTemplate);

            let attrs = mod.C_GetAttributeValue(session, keys.privateKey, [
                { type: pkcs11.CKA_TOKEN }
            ]);
        });
    });
github PeculiarVentures / graphene / build / template.js View on Github external
"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 },
github hyperledger / fabric-sdk-node / fabric-common / lib / impl / bccsp_pkcs11.js View on Github external
{type: pkcs11js.CKA_ENCRYPT, value: true},
			{type: pkcs11js.CKA_DECRYPT, value: true},
			/*
			 * If user is logged in:
			 *   - key will be private
			 *   - key will be non-ephemeral by user request
			 * If user is not logged in:
			 *   - key will be public
			 *   - key will be ephermal regardless of user request
			 *
			 * Note that public and private here means publically and privately
			 * accessible, respectively, and has nothing to do with public and
			 * private key pair.
			 */
			{type: pkcs11js.CKA_PRIVATE, value: this._pkcs11Login},
			{type: pkcs11js.CKA_TOKEN, value: this._pkcs11Login && pkcs11Token}
		];

		/*
			* Call PKCS11 API to generate the key.
			*/
		const handle = pkcs11.C_GenerateKey(
			pkcs11Session, {mechanism: pkcs11js.CKM_AES_KEY_GEN},
			secretKeyTemplate);
		/*
			* Template for querying key attributes (debug only).
			*/
		const objectTemplate = [
			{type: pkcs11js.CKA_ID},
			{type: pkcs11js.CKA_CLASS},
			{type: pkcs11js.CKA_KEY_TYPE},
			{type: pkcs11js.CKA_VALUE_LEN},
github hyperledger / fabric-sdk-node / fabric-common / lib / impl / bccsp_pkcs11.js View on Github external
* Call PKCS11 API to generate the key pair.
			*
			* Return public and private key handles.
			*/
		const handles = pkcs11.C_GenerateKeyPair(
			pkcs11Session, {mechanism: pkcs11js.CKM_EC_KEY_PAIR_GEN},
			publicKeyTemplate, privateKeyTemplate);
		/*
			* Template for querying key attributes (debug only).
			*/
		const objectTemplate = [
			{type: pkcs11js.CKA_ID},
			{type: pkcs11js.CKA_CLASS},
			{type: pkcs11js.CKA_KEY_TYPE},
			{type: pkcs11js.CKA_PRIVATE},
			{type: pkcs11js.CKA_TOKEN}
		];
		logger.debug(__func() + 'privateKey: ' + util.inspect(
			this._pkcs11GetAttributeValue(
				pkcs11, pkcs11Session, handles.privateKey,
				objectTemplate),
			{depth: null}));
		logger.debug(__func() + 'publicKey: ' + util.inspect(
			this._pkcs11GetAttributeValue(
				pkcs11, pkcs11Session, handles.publicKey,
				objectTemplate),
			{depth: null}));
		/*
			* Get the public key EC point.
			*/
		let ecpt =
			(this._pkcs11GetAttributeValue(