-
-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
bug: keystore.toJWKS throws on windows #17
Comments
Are you saying this snippet does not work for you? const { JWKS: { KeyStore } } = require('@panva/jose');
const keystore = new KeyStore();
keystore.generateSync('RSA', 2048, {
alg: 'RS256',
use: 'sig',
});
console.log(keystore.toJWKS()) |
Yes and my version is E:\HAS\OpenId>node -v |
and package is
|
The only thing i can think of is that the keyobject export does not honour |
can you try going to your |
also run this for me and paste the output please const { generateKeyPairSync } = require('crypto')
generateKeyPairSync('rsa', { modulusLength: 2048 }).privateKey.export({ format: 'pem', type: 'pkcs8' }) |
It works when i change the line you gave me. I'll run the second command |
i ran this
Which gave me |
ok, please revert everything and change const { EOL } = require('os')
const keyto = require('@trust/keyto')
const errors = require('../errors')
const SUPPORTED = new Set(['EC', 'RSA'])
module.exports.keyObjectToJWK = (keyObject) => {
const type = keyObject.type === 'private' ? 'pkcs8' : 'spki'
const format = 'pem'
const pem = keyObject.export({ type, format }).replace(/\n/g, EOL)
return keyto.from(pem, 'pem').toJwk(keyObject.type)
}
module.exports.jwkToPem = (jwk) => {
if (!SUPPORTED.has(jwk.kty)) {
throw new errors.JOSENotSupported(`unsupported key type: ${jwk.kty}`)
}
return keyto.from(jwk, 'jwk').toString('pem', jwk.d ? 'private_pkcs8' : 'public_pkcs8')
} I think this might work as a temporary workaround to the |
Your workaround works and when i check my JSON.stringify(require('os').EOL) i get a "\r\n" and i suppose the generation of the token is something made with just \n so its not based on the OS end of line but something like openssl? Maybe its something i should post on the @trust/keyto? If i can be of some help :x |
Yes, i think That being said i'll work around it for now and in the future the work being done the KeyObject API will remove the need to use the |
@DarkSorrow while we're at it and you're willing to help. Can you clone this repo, make the above change in your source and run
Maybe there are more windows specific bugs that we could uncover. |
Yes sure i'll do that and post something on their channel too later |
ok with your workaround all test pass
|
Thanks for your help @DarkSorrow, i'll get this sorted later today. |
Well thanks for being so reactive, i sent a PR to keyto as well |
I'm trying to generate a key, i used the code i found in the doc
But when i try to start it i get this error
If i understand correctly this is suppose to directly generate a key? I don't see in the doc the need for another file so maybe i'm not understanding something and i know you are probably very busy atm but if there are things i can do to help let me know :x
The text was updated successfully, but these errors were encountered: