diff --git a/package.json b/package.json index 277cf30..28e8166 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/algorithms/RSASSA-PKCS1-v1_5.js b/src/algorithms/RSASSA-PKCS1-v1_5.js index bba4e35..2e7ffe4 100644 --- a/src/algorithms/RSASSA-PKCS1-v1_5.js +++ b/src/algorithms/RSASSA-PKCS1-v1_5.js @@ -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 @@ -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) {