Azure-Samples / active-directory-verifiable-credentials

A code sample demonstrating how to use Azure Active Directory's preview functionality to issue and consume verifiable credentials.
108 stars 64 forks source link

TypeError: Key is not of type 'CryptoKey' at SubtleCryptoKeyVault.checkCryptoKey #12

Closed maakle closed 3 years ago

maakle commented 3 years ago

The following line in /issuer/app.js breaks for me: req.session.issueRequest = await requestBuilder.build().create(); The error leads to the QR code not being generated. Any idea what's wrong? Seems like it's a bug in the SDK and something is going wrong with signing the request?

Full error log:

(node:62578) UnhandledPromiseRejectionWarning: TypeError: Key is not of type 'CryptoKey'
    at SubtleCryptoKeyVault.checkCryptoKey (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/webcrypto-core/build/webcrypto-core.js:893:19)
    at SubtleCryptoKeyVault.sign (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/webcrypto-core/build/webcrypto-core.js:762:14)
    at SubtleCryptoExtension.signByKeyStore (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/verifiablecredentials-crypto-sdk-typescript-plugin/dist/lib/SubtleCryptoExtension.js:53:40)
    at JwsToken.sign (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/verifiablecredentials-crypto-sdk-typescript-protocol-jose/dist/lib/jws/JwsToken.js:382:40)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Jose.sign (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/verifiablecredentials-crypto-sdk-typescript/dist/lib/Jose.js:52:23)
    at async Requestor.create (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/verifiablecredentials-verification-sdk-typescript/dist/lib/api_oidc_request/Requestor.js:70:27)
    at async exports.issueRequest (/Users/mathiasklenk/passbase-dev/credential-issuer/src/controller/credentialIssuerController.js:76:30)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:62578) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:62578) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:62578) UnhandledPromiseRejectionWarning: TypeError: Key is not of type 'CryptoKey'
    at SubtleCryptoKeyVault.checkCryptoKey (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/webcrypto-core/build/webcrypto-core.js:893:19)
    at SubtleCryptoKeyVault.sign (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/webcrypto-core/build/webcrypto-core.js:762:14)
    at SubtleCryptoExtension.signByKeyStore (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/verifiablecredentials-crypto-sdk-typescript-plugin/dist/lib/SubtleCryptoExtension.js:53:40)
    at JwsToken.sign (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/verifiablecredentials-crypto-sdk-typescript-protocol-jose/dist/lib/jws/JwsToken.js:382:40)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Jose.sign (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/verifiablecredentials-crypto-sdk-typescript/dist/lib/Jose.js:52:23)
    at async Requestor.create (/Users/mathiasklenk/passbase-dev/credential-issuer/node_modules/verifiablecredentials-verification-sdk-typescript/dist/lib/api_oidc_request/Requestor.js:70:27)
    at async exports.issueRequest (/Users/mathiasklenk/passbase-dev/credential-issuer/src/controller/credentialIssuerController.js:76:30)
mahoekst commented 3 years ago

Did you change the didconfig.json? Sounds like the connection to keyvault isn't working correctly.

maakle commented 3 years ago

I looked at your latest commits and changed it accordingly. Now it works again. Thanks!

maakle commented 3 years ago

The project crashes again with the same error on a clean git pull when you press the Get Credential button. Maybe you wanna have a look into this @mahoekst

Same error:

throw new TypeError(`Key is not of type 'CryptoKey'`);
                  ^
TypeError: Key is not of type 'CryptoKey' at SubtleCryptoKeyVault.checkCryptoKey 
mahoekst commented 3 years ago

The project crashes again with the same error on a clean git pull when you press the Get Credential button. Maybe you wanna have a look into this @mahoekst

Same error:

throw new TypeError(`Key is not of type 'CryptoKey'`);
                  ^
TypeError: Key is not of type 'CryptoKey' at SubtleCryptoKeyVault.checkCryptoKey 

can you tell me what exact steps you did after git clone? Is it not working without any code changes? IF you changed anything can you please specify the details about what you changed?

maakle commented 3 years ago

Actually pretty standard. I didn't change anything on the latest git clone. This is what I did:

  1. git clone git@github.com:Azure-Samples/active-directory-verifiable-credentials.git
  2. Cd into the project and issuer folder cd active-directory-verifiable-credentials/issuer/
  3. Run npm i or yarn to install all dependencies in the issuer folder
  4. Run node app.js to start the App on localhost:8081
  5. Run ngrok 8081 to start port forwarding -> Then open the ngrok url in the browser. Until here everything works.
  6. When I click the Get Credential button the app crashes like in the screenshot
Screen Shot 2021-04-26 at 8 48 03 AM

I am running this on MacOS and with Node 15.6.0. Does it work for you on a clean git pull of the project? My assumption is there is something wrong with the keys in didconfig.json, but perhaps you know more.

This is what the 502 error in ngrok says:

Screen Shot 2021-04-26 at 8 55 43 AM
mahoekst commented 3 years ago

I just tried again, clean git clone, npm i and it just works. I am running the LTS version on Windows.

maakle commented 3 years ago

I think that just did the trick. I reverted node back on v14.15.4 and now it seems to run. Maybe one of the sub dependencies is not compatible with the latest node version that I was running? You probably wanna look into this long term or create a ticket to come back to it and make it work with node 15 and higher.

Thanks!

mahoekst commented 3 years ago

Thanks. I filed a bug in our system to take a look and test with Node 15 and up. Thanks for reporting this.

pritesh93 commented 3 years ago

Had the same issue on Node 14.16.1 (LTS).... May not be just Node 15+, happy to provide more details!

EDIT: Seems like the doc doesn't mention to change the config values of the didconfig.json. https://docs.microsoft.com/en-us/azure/active-directory/verifiable-credentials/enable-your-tenant-verifiable-credentials#update-the-sample-app

Within this section here. Going to attempt to continue on, but it seems off.