1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-10 21:22:35 +01:00
send/assets/cryptofill.js

15 lines
58 KiB
JavaScript
Raw Normal View History

var liner=function(e){function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}var t={};return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},r.p="",r(r.s=16)}([function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),function(e){function n(e){for(var r,t=e,n=/[^%](%\d+)/g,a=[];r=n.exec(t);)a.push({arg:r[1],index:r.index});for(var o=a.length-1;o>=0;o--){var i=a[o],s=i.arg.substring(1),c=i.index+1;t=t.substring(0,c)+arguments[+s]+t.substring(c+1+s.length)}return t=t.replace("%%","%")}function a(e){var r;r="string"==typeof e?{name:e}:e,p.checkAlgorithm(r);var t=e;return t.hash&&(t.hash=a(t.hash)),r}function o(e,r){if(!e)throw new s("Parameter '"+r+"' is required and cant be empty");if("undefined"!=typeof Buffer&&Buffer.isBuffer(e))return new Uint8Array(e);if(ArrayBuffer.isView(e)){var t=e.map(function(e){return e});return new Uint8Array(t.buffer)}if(e instanceof ArrayBuffer)return new Uint8Array(e);throw new s("Incoming parameter '"+r+"' has wrong data type. Must be ArrayBufferView or ArrayBuffer")}t.d(r,"WebCryptoError",function(){return s}),t.d(r,"AlgorithmError",function(){return c}),t.d(r,"CryptoKeyError",function(){return u}),t.d(r,"PrepareAlgorithm",function(){return a}),t.d(r,"PrepareData",function(){return o}),t.d(r,"BaseCrypto",function(){return p}),t.d(r,"AlgorithmNames",function(){return h}),t.d(r,"Base64Url",function(){return y}),t.d(r,"SubtleCrypto",function(){return x}),t.d(r,"Aes",function(){return A}),t.d(r,"AesAlgorithmError",function(){return m}),t.d(r,"AesWrapKey",function(){return w}),t.d(r,"AesEncrypt",function(){return v}),t.d(r,"AesECB",function(){return g}),t.d(r,"AesCBC",function(){return C}),t.d(r,"AesCTR",function(){return k}),t.d(r,"AesGCM",function(){return d}),t.d(r,"AesKW",function(){return b}),t.d(r,"RsaKeyGenParamsError",function(){return G}),t.d(r,"RsaHashedImportParamsError",function(){return M}),t.d(r,"Rsa",function(){return B}),t.d(r,"RsaSSA",function(){return T}),t.d(r,"RsaPSSParamsError",function(){return D}),t.d(r,"RsaPSS",function(){return j}),t.d(r,"RsaOAEPParamsError",function(){return W}),t.d(r,"RsaOAEP",function(){return H}),t.d(r,"EcKeyGenParamsError",function(){return U}),t.d(r,"Ec",function(){return _}),t.d(r,"EcAlgorithmError",function(){return K}),t.d(r,"EcDSA",function(){return S}),t.d(r,"EcDH",function(){return O}),t.d(r,"ShaAlgorithms",function(){return E}),t.d(r,"Sha",function(){return P});var i=t(8),s=function(e){function r(r){for(var t=[],a=1;a<arguments.length;a++)t[a-1]=arguments[a];var o=e.call(this)||this;o.code=0,o.message=n.apply(void 0,[r].concat(t));var i=new Error(o.message);return i.name=o.constructor.name,o.stack=i.stack,o}return Object(i.a)(r,e),r.NOT_SUPPORTED="Method is not supported",r}(Error),c=function(e){function r(){var r=null!==e&&e.apply(this,arguments)||this;return r.code=1,r}return Object(i.a)(r,e),r.PARAM_REQUIRED="Algorithm hasn't got required paramter '%1'",r.PARAM_WRONG_TYPE="Algorithm has got wrong type for paramter '%1'. Must be %2",r.PARAM_WRONG_VALUE="Algorithm has got wrong value for paramter '%1'. Must be %2",r.WRONG_ALG_NAME="Algorithm has got wrong name '%1'. Must be '%2'",r.UNSUPPORTED_ALGORITHM="Algorithm '%1' is not supported",r.WRONG_USAGE="Algorithm doesn't support key usage '%1'",r}(s),u=function(e){function r(){var r=null!==e&&e.apply(this,arguments)||this;return r.code=3,r}return Object(i.a)(r,e),r.EMPTY_KEY="CryptoKey is empty",r.WRONG_KEY_ALG="CryptoKey has wrong algorithm '%1'. Must be '%2'",r.WRONG_KEY_TYPE="CryptoKey has wrong type '%1'. Must be '%2'",r.WRONG_KEY_USAGE="CryptoKey has wrong key usage. Must be '%1'",r.NOT_EXTRACTABLE="CryptoKey is not extractable",r.WRONG_FORMAT="CryptoKey has '%1' type. It can be used with '%2' format",r.UNKNOWN_FORMAT="Unknown format in use '%1'. Must be
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)r.hasOwnProperty(t)&&(e[t]=r[t])};Object.assign},function(e,r){e.exports=require("crypto")},function(e,r,t){"use strict";function n(e,r){return Promise.resolve().then(function(){if(e.key)return e;if(e.extractable){return(new A.Crypto).subtle.exportKey("jwk",e).then(function(t){var n=o(e);return n&&(n=w.assign(n,e.algorithm)),r.importKey("jwk",t,n,!0,e.usages)})}throw new m.LinerError("'key' is Native CryptoKey. It can't be converted to JS CryptoKey")})}function a(e,r){w.BrowserInfo().name!==w.Browser.IE&&w.BrowserInfo().name!==w.Browser.Edge&&w.BrowserInfo().name!==w.Browser.Safari||!/^rsa/i.test(e.name)||(r.privateKey?(b.push({hash:e.hash,key:r.privateKey}),b.push({hash:e.hash,key:r.publicKey})):b.push({hash:e.hash,key:r}))}function o(e){var r=null;return b.some(function(t){return t.key===e&&(r=w.assign({},e.algorithm,{hash:t.hash}),!0)}),r}function i(e,r){var t=[];e.privateKey?(t.push(e.privateKey),t.push(e.publicKey)):t.push(e),t.forEach(function(e){"keyUsage"in e&&(e.usages=e.keyUsage||[],e.usages.length||(["verify","encrypt","wrapKey"].forEach(function(t){r.indexOf(t)>-1&&("public"===e.type||"secret"===e.type)&&e.usages.push(t)}),["sign","decrypt","unwrapKey","deriveKey","deriveBits"].forEach(function(t){r.indexOf(t)>-1&&("private"===e.type||"secret"===e.type)&&e.usages.push(t)})))})}function s(e,r,t){if(r&&w.BrowserInfo().name===w.Browser.IE){"extractable"in e&&(e.ext=e.extractable,delete e.extractable);var n=null;switch(r.name.toUpperCase()){case h.AlgorithmNames.AesECB.toUpperCase():case h.AlgorithmNames.AesCBC.toUpperCase():case h.AlgorithmNames.AesGCM.toUpperCase():n=v.AesCrypto;break;default:throw new m.LinerError(m.LinerError.UNSUPPORTED_ALGORITHM,r.name.toUpperCase())}n&&!e.alg&&(e.alg=n.alg2jwk(r)),"key_ops"in e||(e.key_ops=t)}}function c(e){w.BrowserInfo().name===w.Browser.IE&&("ext"in e&&(e.extractable=e.ext,delete e.ext),delete e.key_ops,delete e.alg)}function u(e){var r=/AppleWebKit\/(\d+)/.exec(self.navigator.userAgent);return e.toUpperCase()===h.AlgorithmNames.RsaOAEP&&r&&parseInt(r[1],10)<604}var p=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)r.hasOwnProperty(t)&&(e[t]=r[t])};return function(r,t){function n(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var h=t(0),f=t(0),y=t(0),l=t(3),A=t(2),m=t(1),w=t(5),v=t(11),g=t(12),C=t(13),k=t(14),d=t(15),b=[],E=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return p(r,e),r.prototype.generateKey=function(r,t,n){var o,s=this,c=arguments;return e.prototype.generateKey.apply(this,c).then(function(e){if(o=y.PrepareAlgorithm(r),!(w.BrowserInfo().name===w.Browser.Edge&&o.name.toUpperCase()===h.AlgorithmNames.AesGCM||u(o.name))&&l.nativeSubtle)try{return l.nativeSubtle.generateKey.apply(l.nativeSubtle,c).catch(function(e){w.warn("WebCrypto: native generateKey for "+o.name+" doesn't work.",e&&e.message||"Unknown message")})}catch(e){w.warn("WebCrypto: native generateKey for "+o.name+" doesn't work.",e&&e.message||"Unknown message")}}).then(function(e){if(e){var c=Promise.resolve(e);if(w.BrowserInfo().name===w.Browser.Safari&&(o.name.toUpperCase()===h.AlgorithmNames.EcDH.toUpperCase()||o.name.toUpperCase()===h.AlgorithmNames.EcDSA.toUpperCase())){var u=e.publicKey;c=c.then(function(){return s.exportKey("jwk",u).then(function(a){return s.exportKey("spki",u).then(function(o){for(var i=h.Base64Url.decode(a.x),c=h.Base64Url.decode(a.y),u=i.length+c.length,p=new Uint8Array(o),f=0;f<u;f++){var y=p[p.length-f-1],l=void 0;if(l=f<c.length?c[c.length-f-1]:i[i.length+c.length-f-1],y!==l)return w.warn("WebCrypto: EC key has wrong public key JWK. Key pair will be recreated"),s.generateKey(r,t,n)}return e})})})}return c.then(function(e){return i(e,n),a(o,e),e})}var p;switch(o.name.toLowerCase()){case h.AlgorithmNames.AesECB.toLowerC