{"action":"created","issue":{"url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-p11/issues/43","repository_url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-p11","labels_url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-p11/issues/43/labels{/name}","comments_url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-p11/issues/43/comments","events_url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-p11/issues/43/events","html_url":"https://github.com/PeculiarVentures/node-webcrypto-p11/issues/43","id":347407357,"node_id":"MDU6SXNzdWUzNDc0MDczNTc=","number":43,"title":"Unable to get certificate from HSM device","user":{"login":"ENDaZONELT","id":1504224,"node_id":"MDQ6VXNlcjE1MDQyMjQ=","avatar_url":"https://avatars3.githubusercontent.com/u/1504224?v=4","gravatar_id":"","url":"https://api.github.com/users/ENDaZONELT","html_url":"https://github.com/ENDaZONELT","followers_url":"https://api.github.com/users/ENDaZONELT/followers","following_url":"https://api.github.com/users/ENDaZONELT/following{/other_user}","gists_url":"https://api.github.com/users/ENDaZONELT/gists{/gist_id}","starred_url":"https://api.github.com/users/ENDaZONELT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ENDaZONELT/subscriptions","organizations_url":"https://api.github.com/users/ENDaZONELT/orgs","repos_url":"https://api.github.com/users/ENDaZONELT/repos","events_url":"https://api.github.com/users/ENDaZONELT/events{/privacy}","received_events_url":"https://api.github.com/users/ENDaZONELT/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-03T13:57:28Z","updated_at":"2018-08-06T15:52:47Z","closed_at":null,"author_association":"NONE","body":"Certificate is stored on HSM device and I need to get it for signing. But when I try to do that an error message occurs.\r\n\r\n```js\r\nimport * as xadesjs from 'xadesjs';\r\nimport { WebCrypto } from 'node-webcrypto-p11';\r\n\r\nasync function test() {\r\n\r\n    const cryptoConfig = {\r\n        library: \"/home/app/src/lib/pkcs11.so\",\r\n        name: \"Ultimaco HSM\",\r\n        slot: 2,\r\n        readWrite: false,\r\n        pin: \"xxxxxxxxxxxx\"\r\n    };\r\n\r\n    const crypto = new WebCrypto(cryptoConfig);\r\n    xadesjs.Application.setEngine(\"pkcs11\", crypto);\r\n\r\n    const certificateList = await crypto.certStorage.keys();\r\n    console.log(certificateList);\r\n\r\n    try {\r\n        const certificate = await crypto.certStorage.getItem('x509-0500000000000000-6365727469666963617465');\r\n    } catch (e) {\r\n        console.log(e.toString());\r\n    }\r\n}\r\nexport default { test };\r\n```\r\n\r\nconsole log:\r\n```\r\n[ 'x509-0500000000000000-6365727469666963617465' ]\r\n\r\nError: CKR_GENERAL_ERROR:5\r\n    at Error (native) C_GetAttributeValue:444\r\n```\r\n\r\n```\r\nError: CKR_GENERAL_ERROR:5\r\n    at Error (native) C_GetAttributeValue:444\r\n    at SessionObject.getAttribute (/home/app/src/node_modules/graphene-pk11/build/object.js:59:25)\r\n    at SessionObject.get (/home/app/src/node_modules/graphene-pk11/build/object.js:77:21)\r\n    at SessionObject.get [as class] (/home/app/src/node_modules/graphene-pk11/build/object.js:86:25)\r\n    at SessionObject.toType (/home/app/src/node_modules/graphene-pk11/build/object.js:95:22)\r\n    at Promise (/home/app/src/node_modules/node-webcrypto-p11/built/crypto/rsa.js:219:53)\r\n    at new Promise (<anonymous>)\r\n    at Function.importJwkPublicKey (/home/app/src/node_modules/node-webcrypto-p11/built/crypto/rsa.js:215:16)\r\n    at importKey.apply.then (/home/app/src/node_modules/node-webcrypto-p11/built/crypto/rsa.js:132:37)\r\n    at <anonymous>\r\n    at process._tickDomainCallback (internal/process/next_tick.js:228:7)`\r\n```\r\n\r\nBut there were no problems to get a certificate using session.find() \r\n\r\n```js\r\nimport { WebCrypto } from 'node-webcrypto-p11';\r\nimport * as graphene from 'graphene-pk11';\r\n\r\nasync function test() {\r\n\r\n    const Module = graphene.Module;\r\n\r\n    const mod = Module.load(\"/home/app/src/libcs_pkcs11_R2.so\", \"Ultimaco\");\r\n\r\n    mod.initialize();\r\n\r\n    const session = mod.getSlots(2).open();\r\n    session.login(\"xxxxxxxxxx\");\r\n\r\n    const fetchedCertificates = session.find({class: graphene.ObjectClass.CERTIFICATE});\r\n    const certificate = fetchedCertificates.items(0).toType();\r\n\r\n    console.log(`======= certificate: `, certificate);\r\n    console.log(`======= Object.getOwnPropertyNames(certificate): `, Object.getOwnPropertyNames(certificate));\r\n    console.log(`======= certificate.lib: `, certificate.lib);\r\n    console.log(`======= certificate.handle: `, certificate.handle);\r\n    console.log(`======= certificate.handle.toString('hex'): `, certificate.handle.toString('hex'));\r\n    console.log(`======= certificate.id.toString('hex'): `, certificate.id.toString('hex'));\r\n    console.log(`======= certificate.label: `, certificate.label);\r\n    console.log(`======= certificate.subject: `, certificate.subject);\r\n    console.log(`======= certificate.value: `, certificate.value);\r\n\r\n    session.logout();\r\n    mod.finalize();        \r\n}\r\n\r\nexport default { test };\r\n```\r\n\r\n```\r\n======= certificate:  X509Certificate {\r\n  handle: <Buffer 05 00 00 00 00 00 00 00>,\r\n  session: \r\n   Session {\r\n     handle: <Buffer 9e 16 4f 01 00 00 00 00>,\r\n     slot: \r\n      Slot {\r\n        handle: <Buffer 02 00 00 00 00 00 00 00>,\r\n        module: [Object],\r\n        slotDescription: 'XXXX - SLOT_0002',\r\n        manufacturerID: 'Utimaco IS GmbH',\r\n        flags: 5,\r\n        hardwareVersion: [Object],\r\n        firmwareVersion: [Object] },\r\n     state: 0,\r\n     flags: 4,\r\n     deviceError: 0 } }\r\n======= Object.getOwnPropertyNames(certificate):  [ 'lib', 'handle', 'session' ]\r\n======= certificate.lib:  PKCS11 { libPath: '/home/app/src/libcs_pkcs11_R2.so' }\r\n======= certificate.handle:  <Buffer 05 00 00 00 00 00 00 00>\r\n======= certificate.handle.toString('hex'):  0500000000000000\r\n======= certificate.id.toString('hex'):  6365727469666963617465\r\n======= certificate.label:  X509 Certificate\r\n======= certificate.subject:  <Buffer 30 81 99 31 30 30 2e 06 37 30 36 ... >\r\n======= certificate.value:  <Buffer 30 82 05 72 30 82 04 5a a0 31 0b 30 09 06 03 55 04 ... >\r\n```"},"comment":{"url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-p11/issues/comments/410756293","html_url":"https://github.com/PeculiarVentures/node-webcrypto-p11/issues/43#issuecomment-410756293","issue_url":"https://api.github.com/repos/PeculiarVentures/node-webcrypto-p11/issues/43","id":410756293,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDc1NjI5Mw==","user":{"login":"microshine","id":7333669,"node_id":"MDQ6VXNlcjczMzM2Njk=","avatar_url":"https://avatars3.githubusercontent.com/u/7333669?v=4","gravatar_id":"","url":"https://api.github.com/users/microshine","html_url":"https://github.com/microshine","followers_url":"https://api.github.com/users/microshine/followers","following_url":"https://api.github.com/users/microshine/following{/other_user}","gists_url":"https://api.github.com/users/microshine/gists{/gist_id}","starred_url":"https://api.github.com/users/microshine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/microshine/subscriptions","organizations_url":"https://api.github.com/users/microshine/orgs","repos_url":"https://api.github.com/users/microshine/repos","events_url":"https://api.github.com/users/microshine/events{/privacy}","received_events_url":"https://api.github.com/users/microshine/received_events","type":"User","site_admin":false},"created_at":"2018-08-06T15:52:47Z","updated_at":"2018-08-06T15:52:47Z","author_association":"CONTRIBUTOR","body":"@ENDaZONELT Thank you for your information\r\n\r\nAs I can see from log this can be HSM error. You've got `CKR_GENERAL_ERROR ` on public key importing. I cannot reproduce this error with my PKCS11 providers.\r\n\r\nCan you try to create RSA public key in your HSM via `Session.create` function and get `class` attribute from created object?\r\n\r\n```js\r\nconst object = session.create({\r\n    token: false,\r\n    class: graphene.ObjectClass.PUBLIC_KEY,\r\n    keyType: graphene.KeyType.RSA,\r\n    private: false,\r\n    label: \"RSA-Test-key\",\r\n    id: Buffer.from(\"rsa-test-public-key\"),\r\n    verify: true,\r\n    encrypt: true,\r\n    wrap: true,\r\n    publicExponent: Buffer.from(\"j2MS4Q5yM8bODfWWdwg9aHo3vBtuBeOkArnMKfgP0vPUGoi2Xe+vrHfSFKlb3kBjJVJcIYoEtU1POTtWlj1TnPfJl8vT/poumWAk+W8q20spuRfFA5X6sJvcgsr8XXeKG7IlSqvlE8ETRdPjH8QtOA2qYbzigqx1q0rQKJ5yZ60yivP8fxstb0tFQLJspfYh+tMi02zHPEksZZUjwZe1EkLJED9yZBvlORT6jHubnRkCiQ85rGHx1ADXY7wNa4pPJ8TXH5EUAoBdXW4ommjpXQBW2e7kTxTBmfQRHo22iKwB8CvAepW5zMYgBnKl7UuqpI3BPUaPD76gghybKeahPQ==\", \"base64\")\r\n    modulus: Buffer.from([1,0,1]),\r\n});\r\nconsole.log(object.class);\r\n```"}}
{"actor":{"display_login":"microshine"}}