From 286ff364b4941257806cfdbf0f7b5c2bb5466342 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 27 May 2015 10:57:18 -0600 Subject: [PATCH] generate keys w/ ursa, fallback to node-forge Running the demo went from 89 minutes down to about 3 on raspberry pi. Related: * https://github.com/digitalbazaar/forge/issues/263 * https://github.com/letsencrypt/node-acme/issues/22. --- lib/crypto-util.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/crypto-util.js b/lib/crypto-util.js index f8a3634..88be57d 100644 --- a/lib/crypto-util.js +++ b/lib/crypto-util.js @@ -96,7 +96,22 @@ module.exports = { ///// KEY PAIR MANAGEMENT generateKeyPair: function(bits) { - var keyPair = forge.pki.rsa.generateKeyPair({bits: bits, e: 0x10001}); + var ursa, keyPair; + + try { + ursa = require('ursa'); + } catch(e) { + // ignore + } + + if (ursa) { + // This takes between 2 and 6 seconds on a raspberry pi + keyPair = ursa.generatePrivateKey(bits, 0x10001); + return module.exports.importPemPrivateKey(keyPair.toPrivatePem('utf8')); + } + + // This takes 20-30 minutes on a raspberry pi + keyPair = forge.pki.rsa.generateKeyPair({bits: bits, e: 0x10001}); return { privateKey: exportPrivateKey(keyPair.privateKey), publicKey: exportPublicKey(keyPair.publicKey)