Closed littledivy closed 9 months ago
I would like to start with the first method crypto.verify()
npm:octokit
is not working correctly due to jsonwebtoken
throwing errors like this:
error: Uncaught Error: secretOrPrivateKey must be an asymmetric key when using RS256
at Object.module.exports [as sign] (file:///app/node_modules/.deno/jsonwebtoken@9.0.1/node_modules/jsonwebtoken/sign.js:124:22)
Another one: https://github.com/denoland/deno/issues/19836
Missing AES-GCM in cipher issues:
Hey @littledivy, has there been any progress with crypto.Decipheriv.prototype.setAutoPadding
? Stumbled upon missing method when using npm:ethereum-cryptography
.
Error: Not implemented: crypto.Cipheriv.prototype.setAutoPadding
at notImplemented (ext:deno_node/_utils.ts:9:11)
at Cipheriv.setAutoPadding (ext:deno_node/internal/crypto/cipher.ts:46:9)
npm:octokit
is not working correctly due tojsonwebtoken
throwing errors like this:error: Uncaught Error: secretOrPrivateKey must be an asymmetric key when using RS256 at Object.module.exports [as sign] (file:///app/node_modules/.deno/jsonwebtoken@9.0.1/node_modules/jsonwebtoken/sign.js:124:22)
FYI, I wanted to note here for visibility that it seems this issue is fixed in Deno 1.38.1—however, it doesn't appear this is used on Deno Deploy just yet: https://github.com/denoland/deno/issues/20938#issuecomment-1810512827
It seems that the error is occurring from verifyIdToken()
in npm:firebase-admin
because crypto.createPublicKey()
is missing.
When I validate the JWT using verifyIdToken()
in firebase-admin/auth
, I get the error below.
[Internal Formatting Error] TypeError: Cannot read properties of undefined (reading 'message')
at PrefixedFirebaseError.get message (file:///C:/Users/ayame/work/deno/.../node_modules/.deno/firebase-admin@12.0.0/node_modules/firebase-admin/lib/utils/error.js:62:27)
at PrefixedFirebaseError.toString (<anonymous>)
at inspectError (ext:deno_console/01_console.js:1535:36)
at formatRaw (ext:deno_console/01_console.js:902:16)
at formatValue (ext:deno_console/01_console.js:664:10)
at formatProperty (ext:deno_console/01_console.js:1663:11)
at formatRaw (ext:deno_console/01_console.js:982:9)
at formatValue (ext:deno_console/01_console.js:664:10)
at inspectArgs (ext:deno_console/01_console.js:3087:17)
at console.error (ext:deno_console/01_console.js:3206:7)
When I debugged and checked the actual error.message, the content was as follows.
Error: Firebase ID token has invalid signature. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.
at FirebaseTokenVerifier.mapJwtErrorToAuthError (file:///C:/Users/ayame/work/deno/.../node_modules/.deno/firebase-admin@12.0.0/node_modules/firebase-admin/lib/auth/token-verifier.js:330:14)
at file:///C:/Users/ayame/work/deno/.../node_modules/.deno/firebase-admin@12.0.0/node_modules/firebase-admin/lib/auth/token-verifier.js:306:20
at Object.runMicrotasks (ext:core/01_core.js:820:30)
at processTicksAndRejections (ext:deno_node/_next_tick.ts:53:10)
at runNextTicks (ext:deno_node/_next_tick.ts:71:3)
at eventLoopTick (ext:core/01_core.js:188:21)
at async file:///C:/Users/ayame/work/deno/.../routes/api/[...path].ts:277:23
at async dispatch (https://deno.land/x/hono@v3.11.12/compose.ts:45:17)
at async https://deno.land/x/hono@v3.11.12/validator/validator.ts:141:5
at async dispatch (https://deno.land/x/hono@v3.11.12/compose.ts:45:17)
The above error is wrapped by firebase. The original error was something like this:
Error: secretOrPublicKey must be an asymmetric key when using RS256
at file:///C:/Users/ayame/work/deno/.../node_modules/.deno/firebase-admin@12.0.0/node_modules/firebase-admin/lib/utils/jwt.js:275:27
at file:///C:/Users/ayame/work/deno/.../node_modules/.deno/jsonwebtoken@9.0.2/node_modules/jsonwebtoken/verify.js:194:14
at file:///C:/Users/ayame/work/deno/.../node_modules/.deno/firebase-admin@12.0.0/node_modules/firebase-admin/lib/utils/jwt.js:232:17
at Object.runMicrotasks (ext:core/01_core.js:820:30)
at processTicksAndRejections (ext:deno_node/_next_tick.ts:53:10)
at runNextTicks (ext:deno_node/_next_tick.ts:71:3)
at eventLoopTick (ext:core/01_core.js:188:21)
This error is actually coming from inside npm:node-jsonwebtoken
.
// https://github.com/auth0/node-jsonwebtoken/blob/bc28861f1fa981ed9c009e29c044a19760a0b128/verify.js#L122
try {
secretOrPublicKey = createPublicKey(secretOrPublicKey);
} catch (_) {
try {
secretOrPublicKey = createSecretKey(typeof secretOrPublicKey === 'string' ? Buffer.from(secretOrPublicKey) : secretOrPublicKey);
} catch (_) {
return done(new JsonWebTokenError('secretOrPublicKey is not valid key material'))
}
}
In the end, I found out that the cause of the error was that createPublicKey
was not implemented.
I have converted the pending items into seperate issues. Closing this one.
Hello,
I am testing nodejs code that I wrote last year with Deno 2,
I encounter an error when doing the following (I only extracted the errored code)
import { generateKeyPairSync } from "node:crypto";
const passphrase: string = "mypassphrase";
const cipher: string = "aes-256-cbc";
const modulusLength: number = 4096;
const key = generateKeyPairSync("rsa", {
modulusLength,
publicKeyEncoding: {
type: "spki",
format: "pem",
},
privateKeyEncoding: {
type: "pkcs8",
format: "pem",
cipher,
passphrase,
},
});
console.log(key);
Error:
error: Uncaught (in promise) Error: PEM error: PEM Base64 error: invalid Base64 length
I see above that the generateKeyPairSync
has been implemented, do I need to do something special ?
or node:crypto
should work as is ?
Thank you !
Can't believe you released Deno 2 without fixing setAutoPadding... Luckily Bun does have it implemented.
Please leave a comment below if you are planning to contribute so we can avoid duplicate work.
Unimplemented
crypto.verify()
@kt3k #18765crypto.createVerify()
@kt3k #18703crypto.generateKeyPairSync()
@littledivy https://github.com/denoland/deno/pull/18651crypto.generateKeyPair()
@littledivy https://github.com/denoland/deno/pull/18651crypto.X509Certificate
@littledivy https://github.com/denoland/deno/pull/18625crypto.generatePrimeSync()
@littledivy https://github.com/denoland/deno/pull/18861crypto.sign()
@kt3k #18765crypto.createSign()
@kt3k #18471crypto.hkdfSync()
@littledivy https://github.com/denoland/deno/pull/18612crypto.hkdf()
@littledivy https://github.com/denoland/deno/pull/18612crypto.getCurves()
@levex https://github.com/denoland/deno/pull/18832crypto.generateKeySync()
@littledivy https://github.com/denoland/deno/pull/18609crypto.generateKey()
@littledivy https://github.com/denoland/deno/pull/18609crypto.getDiffieHellman()
@levex https://github.com/denoland/deno/pull/19137crypto.createECDH()
@levex https://github.com/denoland/deno/pull/18832crypto.createDiffieHellmanGroup()
@levex https://github.com/denoland/deno/pull/19137crypto.createDiffieHellman()
@levex https://github.com/denoland/deno/pull/18943crypto.createPrivateKey()
@littledivy https://github.com/denoland/deno/pull/20981crypto.Decipheriv.prototype.setAutoPadding
crypto.checkPrimeSync()
@littledivy https://github.com/denoland/deno/pull/18465crypto.generatePrime()
@littledivy https://github.com/denoland/deno/pull/18861crypto.checkPrime()
@littledivy https://github.com/denoland/deno/pull/18465Port polyfill to Rust
crypto.scryptSync()
@levex #18746crypto.scrypt()
@levex #18746crypto.randomInt()
@levex https://github.com/denoland/deno/pull/18658crypto.randomFill()
@levex https://github.com/denoland/deno/pull/18658crypto.randomFillSync()
@levex https://github.com/denoland/deno/pull/18658crypto.pbkdf2Sync()
@littledivy https://github.com/denoland/deno/pull/18470crypto.pbkdf2()
@littledivy https://github.com/denoland/deno/pull/18470OpenSSL-specific
crypto.setFips()
crypto.setEngine()
Identified bugs