@@ -992,7 +992,7 @@ module.exports = {
992
992
993
993
show_version: true,
994
994
show_comment: true,
995
- versionstring: "OpenPGP.js v0.10.3 ",
995
+ versionstring: "OpenPGP.js v0.11.0 ",
996
996
commentstring: "http://openpgpjs.org",
997
997
998
998
keyserver: "keyserver.linux.it", // "pgp.mit.edu:11371"
@@ -9079,7 +9079,6 @@ function RSA() {
9079
9079
9080
9080
function generate(B, E) {
9081
9081
var webCrypto = util.getWebCrypto();
9082
- var promise;
9083
9082
9084
9083
//
9085
9084
// Native RSA keygen using Web Crypto
@@ -9088,22 +9087,41 @@ function RSA() {
9088
9087
if (webCrypto) {
9089
9088
var Euint32 = new Uint32Array([parseInt(E, 16)]); // get integer of exponent
9090
9089
var Euint8 = new Uint8Array(Euint32.buffer); // get bytes of exponent
9091
- var keyGenOpt = {
9092
- name: 'RSASSA-PKCS1-v1_5',
9093
- modulusLength: B, // the specified keysize in bits
9094
- publicExponent: Euint8.subarray(0, 3), // take three bytes (max 65537)
9095
- hash: {
9096
- name: 'SHA-1' // not required for actual RSA keys, but for crypto api 'sign' and 'verify'
9097
- }
9098
- };
9099
- promise = webCrypto.generateKey(keyGenOpt, true, ['sign', 'verify']);
9100
- return promise.then(exportKey).then(decodeKey);
9090
+ var keyGenOpt;
9091
+
9092
+ if (window.crypto.subtle) {
9093
+ // current standard spec
9094
+ keyGenOpt = {
9095
+ name: 'RSASSA-PKCS1-v1_5',
9096
+ modulusLength: B, // the specified keysize in bits
9097
+ publicExponent: Euint8.subarray(0, 3), // take three bytes (max 65537)
9098
+ hash: {
9099
+ name: 'SHA-1' // not required for actual RSA keys, but for crypto api 'sign' and 'verify'
9100
+ }
9101
+ };
9102
+ return webCrypto.generateKey(keyGenOpt, true, ['sign', 'verify']).then(exportKey).then(decodeKey);
9103
+
9104
+ } else if (window.crypto.webkitSubtle) {
9105
+ // outdated spec implemented by Webkit
9106
+ keyGenOpt = {
9107
+ name: 'RSA-OAEP',
9108
+ modulusLength: B, // the specified keysize in bits
9109
+ publicExponent: Euint8.subarray(0, 3), // take three bytes (max 65537)
9110
+ };
9111
+ return webCrypto.generateKey(keyGenOpt, true, ['encrypt', 'decrypt']).then(exportKey).then(function(key) {
9112
+ if (key instanceof ArrayBuffer) {
9113
+ // parse raw ArrayBuffer bytes to jwk/json (WebKit/Safari quirk)
9114
+ return decodeKey(JSON.parse(String.fromCharCode.apply(null, new Uint8Array(key))));
9115
+ }
9116
+ return decodeKey(key);
9117
+ });
9118
+ }
9101
9119
}
9102
9120
9103
- function exportKey(key ) {
9121
+ function exportKey(keypair ) {
9104
9122
// export the generated keys as JsonWebKey (JWK)
9105
9123
// https://tools.ietf.org/html/draft-ietf-jose-json-web-key-33
9106
- return webCrypto.exportKey('jwk', key .privateKey);
9124
+ return webCrypto.exportKey('jwk', keypair .privateKey);
9107
9125
}
9108
9126
9109
9127
function decodeKey(jwk) {
@@ -9129,7 +9147,7 @@ function RSA() {
9129
9147
// JS code
9130
9148
//
9131
9149
9132
- promise = new Promise(function(resolve) {
9150
+ return new Promise(function(resolve) {
9133
9151
var key = new keyObject();
9134
9152
var rng = new SecureRandom();
9135
9153
var qs = B >> 1;
@@ -9167,8 +9185,6 @@ function RSA() {
9167
9185
9168
9186
resolve(key);
9169
9187
});
9170
-
9171
- return promise;
9172
9188
}
9173
9189
9174
9190
this.encrypt = encrypt;
@@ -16196,8 +16212,8 @@ module.exports = {
16196
16212
return;
16197
16213
}
16198
16214
16199
- if (typeof window !== 'undefined' && window.crypto && window.crypto.subtle ) {
16200
- return window.crypto.subtle;
16215
+ if (typeof window !== 'undefined' && window.crypto) {
16216
+ return window.crypto.subtle || window.crypto.webkitSubtle ;
16201
16217
}
16202
16218
}
16203
16219
};
0 commit comments