Skip to content
This repository has been archived by the owner on Feb 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #62 from kevlened/rsa-fix
Browse files Browse the repository at this point in the history
fix(RSASSA): change modulusLength and publicExponent calculation
  • Loading branch information
EternalDeiwos authored Feb 1, 2018
2 parents 4aa22cc + 9f16126 commit 1566cdd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/algorithms/RSASSA-PKCS1-v1_5.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const crypto = require('crypto')
const {spawnSync} = require('child_process')
const keyto = require('@trust/keyto')
const {TextEncoder, TextDecoder} = require('text-encoding')
const base64url = require('base64url').default

/**
* Local dependencies
Expand Down Expand Up @@ -319,11 +320,11 @@ class RSASSA_PKCS1_v1_5 extends Algorithm {
} else {
throw new KeyFormatNotSupportedError(format)
}
// 3-7. Setupp RSSASSA object
// 3-7. Setup RSSASSA object
let alg = new RSASSA_PKCS1_v1_5({
name: 'RSASSA-PKCS1-v1_5',
modulusLength: (new Buffer(jwk.n, 'base64').length / 2) * 8,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // TODO use jwk.e
modulusLength: base64url.toBuffer(jwk.n).length * 8,
publicExponent: new Uint8Array(base64url.toBuffer(jwk.e)),
hash: normalizedHash
})

Expand Down
16 changes: 16 additions & 0 deletions test/algorithms/RSASSA-PKCS1-v1_5_Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,14 @@ const NotSupportedError = require('../../src/errors/NotSupportedError')
key.algorithm.should.be.instanceof(RSASSA_PKCS1_v1_5)
})

it('should define modulusLength', () => {
key.algorithm.modulusLength.should.eql(2048)
})

it('should define publicExponent', () => {
key.algorithm.publicExponent.should.eql(new Uint8Array([0x01, 0x00, 0x01]))
})

it('should define extractable', () => {
key.extractable.should.equal(false)
})
Expand Down Expand Up @@ -690,6 +698,14 @@ const NotSupportedError = require('../../src/errors/NotSupportedError')
key.algorithm.should.be.instanceof(RSASSA_PKCS1_v1_5)
})

it('should define modulusLength', () => {
key.algorithm.modulusLength.should.eql(2048)
})

it('should define publicExponent', () => {
key.algorithm.publicExponent.should.eql(new Uint8Array([0x01, 0x00, 0x01]))
})

it('should define extractable', () => {
key.extractable.should.equal(true)
})
Expand Down

0 comments on commit 1566cdd

Please sign in to comment.