Skip to content

Commit eedb722

Browse files
author
Tankred Hase
committed
Fall back to js crypto in case native RSA keygen fails
1 parent d38fc07 commit eedb722

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "openpgp",
33
"description": "OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.",
4-
"version": "0.8.1",
4+
"version": "0.8.2",
55
"homepage": "http://openpgpjs.org/",
66
"engines": {
77
"node": ">=0.8"

src/openpgp.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,19 @@ function generateKeyPair(options) {
240240
result.publicKeyArmored = newKey.toPublic().armor();
241241
return result;
242242

243-
}, 'Error generating keypair!');
243+
}).catch(function(err) {
244+
console.error(err);
245+
246+
if (!util.getWebCrypto()) {
247+
// js fallback already tried
248+
throw new Error('Error generating keypair using js fallback!');
249+
}
250+
251+
// fall back to js keygen in a worker
252+
console.log('Error generating keypair using native WebCrypto... falling back back to js!');
253+
return asyncProxy.generateKeyPair(options);
254+
255+
}).catch(onError.bind(null, 'Error generating keypair!'));
244256
}
245257

246258
//

0 commit comments

Comments
 (0)