diff --git a/dist/jose-commonjs.js b/dist/jose-commonjs.js index a7722a7..fd866f8 100644 --- a/dist/jose-commonjs.js +++ b/dist/jose-commonjs.js @@ -837,7 +837,7 @@ Jose.Utils.importRsaPrivateKey = function(rsa_key, alg) { rsa_key.alg = alg; } jwk = Utils.convertRsaKey(rsa_key, ["n", "e", "d", "p", "q", "dp", "dq", "qi"]); - config = getCryptoConfig("RSA-OAEP"); + config = getCryptoConfig(alg); } else { var rk = {}; for (var name in rsa_key) { diff --git a/dist/jose-testing.js b/dist/jose-testing.js index b20a3b2..60e5a4f 100644 --- a/dist/jose-testing.js +++ b/dist/jose-testing.js @@ -840,7 +840,7 @@ Jose.Utils.importRsaPrivateKey = function(rsa_key, alg) { rsa_key.alg = alg; } jwk = Utils.convertRsaKey(rsa_key, ["n", "e", "d", "p", "q", "dp", "dq", "qi"]); - config = getCryptoConfig("RSA-OAEP"); + config = getCryptoConfig(alg); } else { var rk = {}; for (var name in rsa_key) { diff --git a/dist/jose.js b/dist/jose.js index 72c9471..474e177 100644 --- a/dist/jose.js +++ b/dist/jose.js @@ -842,7 +842,7 @@ Jose.Utils.importRsaPrivateKey = function(rsa_key, alg) { rsa_key.alg = alg; } jwk = Utils.convertRsaKey(rsa_key, ["n", "e", "d", "p", "q", "dp", "dq", "qi"]); - config = getCryptoConfig("RSA-OAEP"); + config = getCryptoConfig(alg); } else { var rk = {}; for (var name in rsa_key) { diff --git a/dist/jose.min.js b/dist/jose.min.js index ebf167a..b1643b2 100644 --- a/dist/jose.min.js +++ b/dist/jose.min.js @@ -1 +1 @@ -!function(e,t,r,n,a){"use strict";t.subtle||(t.subtle=t.webkitSubtle);var i={},o={},s={};e.setCrypto=function(e){i.crypto=e},void 0!==t&&e.setCrypto(t),"function"!=typeof atob&&(atob=function(e){return new Buffer(e,"base64").toString("binary")}),"function"!=typeof btoa&&(btoa=function(e){return(e instanceof Buffer?e:new Buffer(e.toString(),"binary")).toString("base64")}),i.caniuse=function(){var e=!0;return e=e&&"function"==typeof r,e=e&&"function"==typeof r.reject,e=e&&"function"==typeof r.prototype.then,e=e&&"function"==typeof r.all,e=e&&"object"==typeof i.crypto,e=e&&"object"==typeof i.crypto.subtle,e=e&&"function"==typeof i.crypto.getRandomValues,e=e&&"function"==typeof i.crypto.subtle.importKey,e=e&&"function"==typeof i.crypto.subtle.generateKey,e=e&&"function"==typeof i.crypto.subtle.exportKey,e=e&&"function"==typeof i.crypto.subtle.wrapKey,e=e&&"function"==typeof i.crypto.subtle.unwrapKey,e=e&&"function"==typeof i.crypto.subtle.encrypt,e=e&&"function"==typeof i.crypto.subtle.decrypt,e=e&&"function"==typeof i.crypto.subtle.sign,e=e&&"function"==typeof ArrayBuffer,e=e&&("function"==typeof a||"object"==typeof a),e=e&&("function"==typeof Uint32Array||"object"==typeof Uint32Array),e=e&&"object"==typeof JSON,e=e&&"function"==typeof JSON.parse,e=e&&"function"==typeof JSON.stringify,e=e&&"function"==typeof atob,e=e&&"function"==typeof btoa},i.assert=function(e,t){if(!e)throw new n(t)},e.Jose=i,e.JoseJWE=o,e.JoseJWS=s;var c=function(){this.setKeyEncryptionAlgorithm("RSA-OAEP"),this.setContentEncryptionAlgorithm("A256GCM"),this.setContentSignAlgorithm("RS256")};i.WebCryptographer=c,c.prototype.setKeyEncryptionAlgorithm=function(e){this.key_encryption=u(e)},c.prototype.getKeyEncryptionAlgorithm=function(){return this.key_encryption.jwe_name},c.prototype.setContentEncryptionAlgorithm=function(e){this.content_encryption=u(e)},c.prototype.getContentEncryptionAlgorithm=function(){return this.content_encryption.jwe_name},c.prototype.setContentSignAlgorithm=function(e){this.content_sign=f(e)},c.prototype.getContentSignAlgorithm=function(){return this.content_sign.jwa_name},c.prototype.createIV=function(){var e=new a(new Array(this.content_encryption.iv_bytes));return i.crypto.getRandomValues(e)},c.prototype.createCek=function(){var e=y(this.content_encryption);return i.crypto.subtle.generateKey(e.id,!0,e.enc_op)},c.prototype.wrapCek=function(e,t){return i.crypto.subtle.wrapKey("raw",e,t,this.key_encryption.id)},c.prototype.unwrapCek=function(e,t){var r=y(this.content_encryption),n=this.content_encryption.specific_cek_bytes>0,a=this.key_encryption.id;return i.crypto.subtle.unwrapKey("raw",e,t,a,r.id,n,r.dec_op)};var y=function(e){var t=e.specific_cek_bytes;if(t){if(16==t)return{id:{name:"AES-CBC",length:128},enc_op:["encrypt"],dec_op:["decrypt"]};if(32==t)return{id:{name:"AES-CBC",length:256},enc_op:["encrypt"],dec_op:["decrypt"]};if(64==t)return{id:{name:"HMAC",hash:{name:"SHA-256"}},enc_op:["sign"],dec_op:["verify"]};if(128==t)return{id:{name:"HMAC",hash:{name:"SHA-384"}},enc_op:["sign"],dec_op:["verify"]};i.assert(!1,"getCekWorkaround: invalid len")}return{id:e.id,enc_op:["encrypt"],dec_op:["decrypt"]}};c.prototype.encrypt=function(e,t,a,o){var s=this.content_encryption;if(e.length!=s.iv_bytes)return r.reject(n("invalid IV length"));if(s.auth.aead){var c=s.auth.tag_bytes,y={name:s.id.name,iv:e,additionalData:t,tagLength:8*c};return a.then(function(e){return i.crypto.subtle.encrypt(y,e,o).then(function(e){var t=e.byteLength-c;return{cipher:e.slice(0,t),tag:e.slice(t)}})})}var u=p(s,a,["encrypt"]),f=u[0],d=u[1].then(function(t){var r={name:s.id.name,iv:e};return i.crypto.subtle.encrypt(r,t,o)}),g=d.then(function(r){return h(s,f,t,e,r)});return r.all([d,g]).then(function(e){return{cipher:e[0],tag:e[1]}})},c.prototype.decrypt=function(e,t,o,s,c){var y=function(e,t,o,s){return i.assert(o instanceof a,"compare: invalid input"),i.assert(s instanceof a,"compare: invalid input"),t.then(function(t){var c=i.crypto.subtle.sign(e.auth.id,t,o),y=i.crypto.subtle.sign(e.auth.id,t,s);return r.all([c,y]).then(function(e){var t=new a(e[0]),i=new a(e[1]);if(t.length!=i.length)throw new n("compare failed");for(var o=0;o0&&i.assert(!1,"convertRsaKey: Was expecting "+a.join()),void 0!==e.kty&&i.assert("RSA"==e.kty,"convertRsaKey: expecting rsa_key['kty'] to be 'RSA'"),n.kty="RSA";try{f(e.alg),r=e.alg}catch(t){try{u(e.alg),r=e.alg}catch(e){i.assert(r,"convertRsaKey: expecting rsa_key['alg'] to have a valid value")}}n.alg=r;for(var o=0;o0))throw new n("No recipients defined. At least one is required to verify the JWS.");if(e.waiting_kid)throw new n("still generating key IDs");return t.forEach(function(t){var r=t.protected.kid;i&&(a[r]=i(r)),o.push(e.cryptographer.verify(t.aad,e.payload,t.signature,a[r],r).then(function(t){return t.verified&&(t.payload=l.Base64Url.decode(e.payload)),t}))}),r.all(o)}}(window,window.crypto,window.Promise,window.Error,window.Uint8Array); \ No newline at end of file +!function(e,t,h,f,d){"use strict";t.subtle||(t.subtle=t.webkitSubtle);var g={},r={},n={};e.setCrypto=function(e){g.crypto=e},void 0!==t&&e.setCrypto(t),"function"!=typeof atob&&(atob=function(e){return new Buffer(e,"base64").toString("binary")}),"function"!=typeof btoa&&(btoa=function(e){return(e instanceof Buffer?e:new Buffer(e.toString(),"binary")).toString("base64")}),g.caniuse=function(){var e=!0;return e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e&&"function"==typeof h)&&"function"==typeof h.reject)&&"function"==typeof h.prototype.then)&&"function"==typeof h.all)&&"object"==typeof g.crypto)&&"object"==typeof g.crypto.subtle)&&"function"==typeof g.crypto.getRandomValues)&&"function"==typeof g.crypto.subtle.importKey)&&"function"==typeof g.crypto.subtle.generateKey)&&"function"==typeof g.crypto.subtle.exportKey)&&"function"==typeof g.crypto.subtle.wrapKey)&&"function"==typeof g.crypto.subtle.unwrapKey)&&"function"==typeof g.crypto.subtle.encrypt)&&"function"==typeof g.crypto.subtle.decrypt)&&"function"==typeof g.crypto.subtle.sign)&&"function"==typeof ArrayBuffer)&&("function"==typeof d||"object"==typeof d))&&("function"==typeof Uint32Array||"object"==typeof Uint32Array))&&"object"==typeof JSON)&&"function"==typeof JSON.parse)&&"function"==typeof JSON.stringify)&&"function"==typeof atob)&&"function"==typeof btoa},g.assert=function(e,t){if(!e)throw new f(t)},e.Jose=g,e.JoseJWE=r,e.JoseJWS=n;var a=function(){this.setKeyEncryptionAlgorithm("RSA-OAEP"),this.setContentEncryptionAlgorithm("A256GCM"),this.setContentSignAlgorithm("RS256")};(g.WebCryptographer=a).prototype.setKeyEncryptionAlgorithm=function(e){this.key_encryption=p(e)},a.prototype.getKeyEncryptionAlgorithm=function(){return this.key_encryption.jwe_name},a.prototype.setContentEncryptionAlgorithm=function(e){this.content_encryption=p(e)},a.prototype.getContentEncryptionAlgorithm=function(){return this.content_encryption.jwe_name},a.prototype.setContentSignAlgorithm=function(e){this.content_sign=u(e)},a.prototype.getContentSignAlgorithm=function(){return this.content_sign.jwa_name},a.prototype.createIV=function(){var e=new d(new Array(this.content_encryption.iv_bytes));return g.crypto.getRandomValues(e)},a.prototype.createCek=function(){var e=i(this.content_encryption);return g.crypto.subtle.generateKey(e.id,!0,e.enc_op)},a.prototype.wrapCek=function(e,t){return g.crypto.subtle.wrapKey("raw",e,t,this.key_encryption.id)},a.prototype.unwrapCek=function(e,t){var r=i(this.content_encryption),n=0