Git Product home page Git Product logo

Comments (16)

DarkSorrow avatar DarkSorrow commented on May 21, 2024 1

ok with your workaround all test pass

E:\HAS\jose>npm run test
> @panva/[email protected] test E:\HAS\jose
> ava



  1355 tests passed

from jose.

panva avatar panva commented on May 21, 2024

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())

from jose.

DarkSorrow avatar DarkSorrow commented on May 21, 2024

Yes and my version is

E:\HAS\OpenId>node -v
v11.11.0

from jose.

DarkSorrow avatar DarkSorrow commented on May 21, 2024

and package is

"dependencies": {
"@panva/jose": "^0.11.1",
"koa": "^2.7.0",
"koa-body": "^4.1.0",
"koa-ejs": "^4.2.0",
"koa-helmet": "^4.1.0",
"koa-mount": "^4.0.0",
"koa-router": "^7.4.0",
"lodash": "^4.17.11",
"nanoid": "^2.0.1"
}

from jose.

panva avatar panva commented on May 21, 2024

The only thing i can think of is that the keyobject export does not honour const EOL = require('os').EOL;

from jose.

panva avatar panva commented on May 21, 2024

can you try going to your node_modules/@trust/keyto/src/index.js file and changing line 219 to let lines = key.split('\n')? I don't have a windows machine available so this would help me out a lot to confirm.

from jose.

panva avatar panva commented on May 21, 2024

also run this for me and paste the output please

const { generateKeyPairSync } = require('crypto')

generateKeyPairSync('rsa', { modulusLength: 2048 }).privateKey.export({ format: 'pem', type: 'pkcs8' })

from jose.

DarkSorrow avatar DarkSorrow commented on May 21, 2024

It works when i change the line you gave me. I'll run the second command

from jose.

DarkSorrow avatar DarkSorrow commented on May 21, 2024

i ran this

const { generateKeyPairSync } = require('crypto')

let res = generateKeyPairSync('rsa', { modulusLength: 2048 }).privateKey.export({ format: 'pem', type: 'pkcs8' })
console.log(JSON.stringify(res))

Which gave me
"-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCzw77UxBXgwWov\n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KFev+7voe2LVP06gQ4o8N9q67vMypxwwXfM5NrNUcmYm\nsmYpvxo+ILujYmbGNSFJJoXVlS4JMXvoyFvV2QjC0D511ULGVjE1u/VQuw1xTL+C\nsFEe96vGwF85cw1zqVTweV+hfKSsq0ilcCXChY170eEsJ0BDXVqjfrshAoGAafhG\nr3K9SLMeEDoGCm+QB6AcR8mJlc4MLUyS8t8XLgSniTGl653gqVdPYqFun9fRCyy0\nKtInZ8MyigGasx70Kz0NTJLKi6Jko4prKPZjJmY9F/LQ/rdcC8DU8o6+ivcdlbTq\ns85UsMNCWTdtw8HkUQlrjVEK8Mtz2Ho2Ig59mOcCgYBQ9zZu9XNYcUtwCRrta2wK\nGhOWKSl2z3yFVYfocKjsU8ILrPO9ui8tWGvldcsF64Ie7qi6i5Q9N8WlEo30ldDm\nCHg/VQ79bADb7qj12XRrfhWKtjAMGcyTHQqWdSuFQOEA7A0meCzxDW8ar6O7KTWb\nq2WlQN5l1Z/vejSd2tA+Lg==\n-----END PRIVATE KEY-----\n"

from jose.

panva avatar panva commented on May 21, 2024

ok, please revert everything and change lib/help/key_utils.js to

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 @trust/keyto implementation. Upon confirmation i'll work that one in.

from jose.

DarkSorrow avatar DarkSorrow commented on May 21, 2024

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

from jose.

panva avatar panva commented on May 21, 2024

Yes, i think @trust/keyto should not rely on os.EOL, for one the key might be coming from a different system.

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 pem -> jwk path in keyto.

from jose.

panva avatar panva commented on May 21, 2024

@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

npm i
npm test

Maybe there are more windows specific bugs that we could uncover.

from jose.

DarkSorrow avatar DarkSorrow commented on May 21, 2024

Yes sure i'll do that and post something on their channel too later

from jose.

panva avatar panva commented on May 21, 2024

Thanks for your help @DarkSorrow, i'll get this sorted later today.

from jose.

DarkSorrow avatar DarkSorrow commented on May 21, 2024

Well thanks for being so reactive, i sent a PR to keyto as well

from jose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.