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

Fixed RSASSA-PKCS1-v1_5.js to use NodeRSA if openssl is not installed… #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"base64url": "^3.0.0",
"elliptic": "^6.4.0",
"node-rsa": "^0.4.0",
"text-encoding": "^0.6.1"
"text-encoding": "^0.6.1",
"node-forge": "^0.8.0"
},
"devDependencies": {
"chai": "^3.5.0",
Expand Down
23 changes: 18 additions & 5 deletions src/algorithms/RSASSA-PKCS1-v1_5.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {spawnSync} = require('child_process')
const keyto = require('@trust/keyto')
const {TextEncoder, TextDecoder} = require('text-encoding')
const base64url = require('base64url').default
const pki = require('node-forge').pki

/**
* Local dependencies
Expand Down Expand Up @@ -176,11 +177,23 @@ class RSASSA_PKCS1_v1_5 extends Algorithm {
// - fallback on node-rsa if OpenSSL is not available on the system
let privateKey = spawnSync('openssl', ['genrsa', modulusLength || 4096]).stdout
let publicKey = spawnSync('openssl', ['rsa', '-pubout'], { input: privateKey }).stdout
try {
keypair.privateKey = privateKey.toString('ascii')
keypair.publicKey = publicKey.toString('ascii')
} catch (error){
throw new OperationError(error.message)

if(privateKey && publicKey) {
try {
keypair.privateKey = privateKey.toString('ascii')
keypair.publicKey = publicKey.toString('ascii')
} catch (error){
throw new OperationError(error.message)
}
} else {
// - what is this bit option, where do we get the value from in this api?
let {modulusLength,publicExponent} = params
let key = new RSA({b:(modulusLength || 4096)})
privateKey = pki.privateKeyFromPem(key.exportKey())
publicKey = pki.setRsaPublicKey(privateKey.n, privateKey.e)

keypair.privateKey = pki.privateKeyToPem(privateKey)
keypair.publicKey = pki.publicKeyToPem(publicKey)
}
// 3. Throw operation error if anything fails
} catch (error) {
Expand Down