From 3f226d9fc1f2453e24765bfabd1ac746677174f5 Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Thu, 26 Sep 2019 14:49:47 -0500 Subject: [PATCH 01/15] refactor --- dist/appid.min.js | 12 +-- dist/appid.umd.min.js | 22 ++--- src/PopupController.js | 6 +- src/constants.js | 2 + src/errors/AppIDError.js | 8 +- src/errors/OAuthError.js | 9 ++ src/index.js | 185 +++++++++++++++++---------------------- src/utils.js | 109 +++++++++++++++++++++++ test/AppIdTest.js | 2 +- test/mocks/UtilsMock.js | 18 ++++ test/utilsTest.js | 73 ++++++++++++++- 11 files changed, 313 insertions(+), 133 deletions(-) create mode 100644 src/errors/OAuthError.js diff --git a/dist/appid.min.js b/dist/appid.min.js index 6f1dcbd..16a4523 100644 --- a/dist/appid.min.js +++ b/dist/appid.min.js @@ -1,4 +1,4 @@ -var AppID=function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=2)}([function(t,e,i){(function(t){var i={userAgent:!1},n={}; +var AppID=function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=5)}([function(t,e){t.exports={MALFORMED_TOKEN:"Invalid JWT token. Got only 2 parts.",INVALID_SIGNATURE:"Invalid signature",INVALID_VERSION:"Invalid version",INVALID_ALGORITHM:"Invalid algorithm",INVALID_ISSUER:"Invalid issuer",INVALID_AUDIENCE:"Invalid audience",INVALID_NONCE:"Invalid nonce",EXPIRED_TOKEN:"Expired token",INVALID_STATE:"Invalid state",INVALID_ORIGIN:"Invalid origin",INVALID_TOKEN:"Invalid token",MISSING_PUBLIC_KEY:"Cannot find public key",INVALID_ACCESS_TOKEN:"Access token must be a string",MISSING_CLIENT_ID:"Missing client ID",MISSING_DISCOVERY_ENDPOINT:"Missing discovery endpoint",RESPONSE_TYPE:"code",RESPONSE_MODE:"web_message",PROMPT:"none",SCOPE:"openid",STATE_LENGTH:20,NONCE_LENGTH:20,CODE_VERIFIER_LENGTH:44,CHALLENGE_METHOD:"S256",TOKEN_ALG:"RS256",VERSION:4,MALFORMED_ACCESS_TOKEN:"eyJpc3MiOiJtb2JpbGVjbGllbnRhY2Nlc3Muc3RhZ2UxLm5nLmJsdWVtaXgubmV0IiwiZXhwIjoxNDg3MDg0ODc4LCJhdWQiOiIyNmNiMDEyZWIzMjdjNjEyZDkwYTY4MTkxNjNiNmJjYmQ0ODQ5Y2JiIiwiaWF0IjoxNDg3MDgxMjc4LCJhdXRoX2J5IjoiZmFjZWJvb2siLCJ0ZW5hbnQiOiI0ZGJhOTQzMC01NGU2LTRjZjItYTUxNi02ZjczZmViNzAyYmIiLCJzY29wZSI6ImFwcGlkX2RlZmF1bHQgYXBwaWRfcmVhZHByb2ZpbGUgYXBwaWRfcmVhZHVzZXJhdHRyIGFwcGlkX3dyaXRldXNlcmF0dHIifQ.HHterec250JSDY1965cM2DadBznl2wTKmzKNSnfjpdTAqax9VZvV3EwuFbEnGp9-i6AC-OlsVj7xvbALkdjwG2lZvpQx0M_gRc_3E0NiYuOGVolcm0wEXtbtDUFFqZQAf9BYYOPZ8OintdBiwUGETbH1ZRVtUvt3nalIko1OPE1Q12LvuRlhz5MClNHmvxJcXc7kucxCx4s4UFFy_HJA1gow7HWFqc9-PZf4JMWA-siYqPrdw_zYeBTBzE5co92F6JBEtGLLCjhJVz9eYgLLECXbak3z6hOaY9352Weuj7AgMOWxzw56jKKsiixMtvzrCzLVIcRUG96UJszwPHtPlA",INVALID_SIGNATURE_TOKEN:"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTU2NjMxMDg5NSwiZXhwIjoxNTY2MzE0NDk1LCJpYXQiOjE1NjYzMTA4OTUsImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciIsImF1ZCI6WyJodHRwOi8vZm9vMS5jb20iLCJodHRwOi8vZm9vMi5jb20iXX0.NBDYg8VZxW770qcbIl40OFvaQntO-FVYUUJocE5ZgcyrvFTuomwF997OcEJghO8BE_Y2m67PbfPFsbN0VI6j"}},function(t,e,i){(function(t){var i={userAgent:!1},n={}; /*! Copyright (c) 2011, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: @@ -14,16 +14,16 @@ if(void 0===r)var r={};r.lang={extend:function(t,e,n){if(!e||!t)throw new Error( * https://code.google.com/p/crypto-js/issues/detail?id=84 * https://crypto-js.googlecode.com/svn-history/r667/branches/3.x/src/core.js */ -var s,a,o,h,u,c,l,f,d,g,p,y=y||(s=Math,o=(a={}).lib={},h=o.Base=function(){function t(){}return{extend:function(e){t.prototype=this;var i=new t;return e&&i.mixIn(e),i.hasOwnProperty("init")||(i.init=function(){i.$super.init.apply(this,arguments)}),i.init.prototype=i,i.$super=this,i},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),u=o.WordArray=h.extend({init:function(t,e){t=this.words=t||[],this.sigBytes=null!=e?e:4*t.length},toString:function(t){return(t||l).stringify(this)},concat:function(t){var e=this.words,i=t.words,n=this.sigBytes,r=t.sigBytes;if(this.clamp(),n%4)for(var s=0;s>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],E=d[F],w=257*d[m]^16843008*m;s[p]=w<<24|w>>>8,a[p]=w<<16|w>>>16,o[p]=w<<8|w>>>24,h[p]=w,w=16843009*E^65537*F^257*S^16843008*p,u[m]=w<<24|w>>>8,c[m]=w<<16|w>>>16,l[m]=w<<8|w>>>24,f[m]=w,p?(p=S^d[d[d[E^S]]],v^=d[d[v]]):p=v=1}var x=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=x[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],E=t[s+13],w=t[s+14],x=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,E,12,u[13]),I=e(I,A,b,C,w,17,u[14]),b=i(b,C=e(C,I,A,b,x,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,x,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,w,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,E,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,w,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,E,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,x,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,w,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,x,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,E,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,E=h.low,w=u.high,x=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,H=p,R=y,B=v,N=m,O=S,j=F,V=E,L=w,K=x,_=b,k=A,M=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&_,Q=V&K^~V&k,z=D&P^D&R^P&R;var tt=T&H^T&B^H&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=M+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),M=_,U=k,_=L,k=K,L=j,K=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=R,O=B,R=P,B=H,P=D,H=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+H,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+R+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),E=h.low=E+V,h.high=F+j+(E>>>0>>0?1:0),x=u.low=x+K,u.high=w+L+(x>>>0>>0?1:0),A=c.low=A+k,c.high=b+_+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+M+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,E=(n=h.words,u.words),w=r.words,x=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+w[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+x[i]]|0,I=16>i?I+((y^(v|~m))+E[0]):32>i?I+((y&m|v&~m)+E[1]):48>i?I+(((y|~v)^m)+E[2]):64>i?I+((y&v|~y&m)+E[3]):I+((y^v^m)+E[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],E=d[F],w=257*d[m]^16843008*m;s[p]=w<<24|w>>>8,a[p]=w<<16|w>>>16,o[p]=w<<8|w>>>24,h[p]=w,w=16843009*E^65537*F^257*S^16843008*p,u[m]=w<<24|w>>>8,c[m]=w<<16|w>>>16,l[m]=w<<8|w>>>24,f[m]=w,p?(p=S^d[d[d[E^S]]],v^=d[d[v]]):p=v=1}var x=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=x[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],E=t[s+13],w=t[s+14],x=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,E,12,u[13]),I=e(I,A,b,C,w,17,u[14]),b=i(b,C=e(C,I,A,b,x,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,x,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,w,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,E,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,w,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,E,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,x,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,w,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,x,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,E,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,E=h.low,w=u.high,x=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,H=p,R=y,B=v,N=m,O=S,j=F,V=E,L=w,_=x,K=b,M=A,k=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&K,Q=V&_^~V&M,z=D&P^D&R^P&R;var tt=T&H^T&B^H&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=k+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),k=K,U=M,K=L,M=_,L=j,_=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=R,O=B,R=P,B=H,P=D,H=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+H,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+R+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),E=h.low=E+V,h.high=F+j+(E>>>0>>0?1:0),x=u.low=x+_,u.high=w+L+(x>>>0<_>>>0?1:0),A=c.low=A+M,c.high=b+K+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+k+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,E=(n=h.words,u.words),w=r.words,x=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+w[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+x[i]]|0,I=16>i?I+((y^(v|~m))+E[0]):32>i?I+((y&m|v&~m)+E[1]):48>i?I+(((y|~v)^m)+E[2]):64>i?I+((y&v|~y&m)+E[3]):I+((y^v^m)+E[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function E(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function w(t){var e,i=E(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(x.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(x.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),x.prototype.DB=v,x.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function _(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function k(){}function M(t){return t}function U(t){this.r2=b(),this.q3=b(),x.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(x.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},x.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},x.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},x.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},x.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},x.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},x.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},x.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},x.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),x.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&x.ZERO.subTo(i,i)}}},x.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},x.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},x.prototype.exp=function(t,e){if(t>4294967295||t<1)return x.ONE;var i=b(),n=b(),r=e.convert(this),s=R(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},x.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},x.prototype.negate=function(){var t=b();return x.ZERO.subTo(this,t),t},x.prototype.abs=function(){return this.s<0?this.negate():this},x.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},x.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+R(this[this.t-1]^this.s&this.DM)},x.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(x.ZERO)>0&&t.subTo(e,e),e},x.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},x.ZERO=H(0),x.ONE=H(1),k.prototype.convert=M,k.prototype.revert=M,k.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},k.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; +var v,m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",S="=";function F(t){var e,i,n="";for(e=0;e+3<=t.length;e+=3)i=parseInt(t.substring(e,e+3),16),n+=m.charAt(i>>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function E(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function w(t){var e,i=E(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(x.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(x.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),x.prototype.DB=v,x.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function K(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function M(){}function k(t){return t}function U(t){this.r2=b(),this.q3=b(),x.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(x.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},x.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},x.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},x.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},x.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},x.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},x.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},x.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},x.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),x.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&x.ZERO.subTo(i,i)}}},x.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},x.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},x.prototype.exp=function(t,e){if(t>4294967295||t<1)return x.ONE;var i=b(),n=b(),r=e.convert(this),s=R(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},x.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},x.prototype.negate=function(){var t=b();return x.ZERO.subTo(this,t),t},x.prototype.abs=function(){return this.s<0?this.negate():this},x.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},x.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+R(this[this.t-1]^this.s&this.DM)},x.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(x.ZERO)>0&&t.subTo(e,e),e},x.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},x.ZERO=H(0),x.ONE=H(1),M.prototype.convert=k,M.prototype.revert=k,M.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},M.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ function Y(){this.i=0,this.j=0,this.S=new Array}x.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},x.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),n=H(i),r=b(),s=b(),a="";for(this.divRemTo(n,r,s);r.signum()>0;)a=(i+s.intValue()).toString(t).substr(1)+a,r.divRemTo(n,r,s);return s.intValue().toString(t)+a},x.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),n=Math.pow(e,i),r=!1,s=0,a=0,o=0;o=i&&(this.dMultiply(n),this.dAddOffset(a,0),s=0,a=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(a,0)),r&&x.ZERO.subTo(this,this)},x.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(x.ONE.shiftLeft(t-1),j,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(x.ONE.shiftLeft(t-1),this);else{var n=new Array,r=7&t;n.length=1+(t>>3),e.nextBytes(n),r>0?n[0]&=(1<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[i++]=n:n<-1&&(e[i++]=this.DV+n),e.t=i,e.clamp()},x.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},x.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},x.prototype.multiplyLowerTo=function(t,e,i){var n,r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;r>0;)i[--r]=0;for(n=i.t-this.t;r=0;)i[n]=0;for(n=Math.max(e-this.t,0);n0)if(0==e)i=this[0]%t;else for(var n=this.t-1;n>=0;--n)i=(e*i+this[n])%t;return i},x.prototype.millerRabin=function(t){var e=this.subtract(x.ONE),i=e.getLowestSetBit();if(i<=0)return!1;var n=e.shiftRight(i);(t=t+1>>1)>q.length&&(t=q.length);for(var r=b(),s=0;s>24},x.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},x.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},x.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},x.prototype.equals=function(t){return 0==this.compareTo(t)},x.prototype.min=function(t){return this.compareTo(t)<0?this:t},x.prototype.max=function(t){return this.compareTo(t)>0?this:t},x.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},x.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},x.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},x.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},x.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=R(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(x.ONE)?x.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},x.prototype.pow=function(t){return this.exp(t,new k)},x.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},x.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>24},x.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},x.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},x.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},x.prototype.equals=function(t){return 0==this.compareTo(t)},x.prototype.min=function(t){return this.compareTo(t)<0?this:t},x.prototype.max=function(t){return this.compareTo(t)>0?this:t},x.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},x.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},x.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},x.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},x.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=R(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(x.ONE)?x.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},x.prototype.pow=function(t){return this.exp(t,new M)},x.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},x.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>8&255,J[W++]^=t>>16&255,J[W++]^=t>>24&255,W>=X&&(W-=X)}((new Date).getTime())}if(null==J){var $;if(J=new Array,W=0,void 0!==n&&(void 0!==n.crypto||void 0!==n.msCrypto)){var Q=n.crypto||n.msCrypto;if(Q.getRandomValues){var tt=new Uint8Array(32);for(Q.getRandomValues(tt),$=0;$<32;++$)J[W++]=tt[$]}else if("Netscape"==i.appName&&i.appVersion<"5"){var et=n.crypto.random(32);for($=0;$>>8,J[W++]=255&$;W=0,Z()}function it(){if(null==G){for(Z(),(G=new Y).init(J),W=0;Wi.length;)i.unshift(0);return i},i=this.getX().toBigInteger(),n=this.getY().toBigInteger(),r=e(i,32);return t?n.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(e(n,32))),r},ut.decodeFrom=function(t,e){e[0];var i=e.length-1,n=e.slice(1,1+i/2),r=e.slice(1+i/2,1+i);n.unshift(0),r.unshift(0);var s=new x(n),a=new x(r);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.decodeFromHex=function(t,e){e.substr(0,2);var i=e.length-2,n=e.substr(2,i/2),r=e.substr(2+i/2,i/2),s=new x(n,16),a=new x(r,16);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.prototype.add2D=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();var e=t.x.subtract(this.x),i=t.y.subtract(this.y).divide(e),n=i.square().subtract(this.x).subtract(t.x),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=this.curve.fromBigInteger(x.valueOf(2)),e=this.curve.fromBigInteger(x.valueOf(3)),i=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),n=i.square().subtract(this.x.multiply(t)),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new x("3")),r=this.negate(),s=this;for(e=n.bitLength()-2;e>0;--e){s=s.twice();var a=n.testBit(e);a!=i.testBit(e)&&(s=s.add2D(a?this:r))}return s},ut.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),i=this.curve.getA().toBigInteger(),n=this.curve.getB().toBigInteger(),r=this.curve.getQ(),s=e.multiply(e).mod(r),a=t.multiply(t).multiply(t).add(i.multiply(t)).add(n).mod(r);return s.equals(a)},ut.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},ut.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),i=this.getY().toBigInteger();if(e.compareTo(x.ONE)<0||e.compareTo(t.subtract(x.ONE))>0)throw new Error("x coordinate out of bounds");if(i.compareTo(x.ONE)<0||i.compareTo(t.subtract(x.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0}; /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval */ -var lt=function(){var t=new RegExp('(?:false|true|null|[\\{\\}\\[\\]]|(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)|(?:"(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))*"))',"g"),e=new RegExp("\\\\(?:([^u])|u(.{4}))","g"),i={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function n(t,e,n){return e?i[e]:String.fromCharCode(parseInt(n,16))}var r=new String(""),s=(Object,Array,Object.hasOwnProperty);return function(i,a){var o,h,u=i.match(t),c=u[0],l=!1;"{"===c?o={}:"["===c?o=[]:(o=[],l=!0);for(var f=[o],d=1-l,g=u.length;d=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function Kt(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function _t(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function Mt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map(function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Rt;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map(function(t){return t.replace("/","\\/")})).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Rt;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=Mt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Rt(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Ht(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),E=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=E,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var w=0;w1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Rt(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Rt(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Rt,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Rt(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(H=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),w=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(H=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(H,0,[2,0],"06"),P=r(H,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var H;S=r(H=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),w=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Ht(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),E=m(t).getEncodedHex(),w="";return w+=Ht(F,"EC PARAMETERS"),w+=Ht(E,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Rt(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e.d=wt(t.d.toString(16)),e.p=wt(t.p.toString(16)),e.q=wt(t.q.toString(16)),e.dp=wt(t.dmp1.toString(16)),e.dq=wt(t.dmq1.toString(16)),e.qi=wt(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e.d=wt(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Rt(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Rt;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=E,e.b64toBA=w,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(w(Et(t)))},e.b64tob64u=Ft,e.b64utob64=Et,e.hex2b64=F,e.hextob64u=wt,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(_t(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(E(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Ht,e.pemtohex=Rt,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map(function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Rt;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map(function(t){return t.replace("/","\\/")})).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Rt;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Rt(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Ht(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),E=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=E,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var w=0;w1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Rt(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Rt(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Rt,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Rt(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(H=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),w=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(H=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(H,0,[2,0],"06"),P=r(H,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var H;S=r(H=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),w=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Ht(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),E=m(t).getEncodedHex(),w="";return w+=Ht(F,"EC PARAMETERS"),w+=Ht(E,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Rt(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e.d=wt(t.d.toString(16)),e.p=wt(t.p.toString(16)),e.q=wt(t.q.toString(16)),e.dp=wt(t.dmp1.toString(16)),e.dq=wt(t.dmq1.toString(16)),e.qi=wt(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e.d=wt(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Rt(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Rt;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=E,e.b64toBA=w,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(w(Et(t)))},e.b64tob64u=Ft,e.b64utob64=Et,e.hex2b64=F,e.hextob64u=wt,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(E(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Ht,e.pemtohex=Rt,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp * @license MIT */ -var n=i(6),r=i(7),s=i(8);function a(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return k(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return M(t).length;default:if(n)return k(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return H(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return E(this,t,e,i);case"latin1":case"binary":return w(this,t,e,i);case"base64":return x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||R(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||R(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||R(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||R(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||R(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||R(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||R(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||R(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||R(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||R(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function M(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(K,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(5))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e,i){const n=i(10),r=i(11);t.exports=class{async request(t,e){const i=await n(t,e),s=await i.text();if(!i.ok||i.status>300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e,i){const n=i(13);t.exports=class{constructor({w:t=window}={}){this.window=t}open(){const t=(screen.width-400)/2,e=(screen.height-700)/2;if(this.popup=this.window.open("","popup",`left=${t},top=${e},width=400,height=700,resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(15);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}},function(t,e,i){const n=i(1),r=i(18);t.exports=class{constructor({jwt:t=i(0)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return M(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return k(t).length;default:if(n)return M(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return H(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return E(this,t,e,i);case"latin1":case"binary":return w(this,t,e,i);case"base64":return x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||R(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||R(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||R(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||R(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||R(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||R(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||R(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||R(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||R(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||R(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function k(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(_,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(8))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e){t.exports=class extends Error{constructor({error:t,description:e}){super(e||t),this.error=t,this.description=e}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(17);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){const e=t.height,i=t.width,r=(screen.width-i)/2,s=(screen.height-e)/2;if(this.popup=this.window.open("","popup",`left=${r},top=${s},width=${i},height=${e},resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(19);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}}]); \ No newline at end of file diff --git a/dist/appid.umd.min.js b/dist/appid.umd.min.js index c26b13f..5fd5cd6 100644 --- a/dist/appid.umd.min.js +++ b/dist/appid.umd.min.js @@ -1,4 +1,4 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AppID=e():t.AppID=e()}(window,function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=2)}([function(t,e,i){(function(t){var i={userAgent:!1},n={}; +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AppID=e():t.AppID=e()}(window,function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=5)}([function(t,e){t.exports={MALFORMED_TOKEN:"Invalid JWT token. Got only 2 parts.",INVALID_SIGNATURE:"Invalid signature",INVALID_VERSION:"Invalid version",INVALID_ALGORITHM:"Invalid algorithm",INVALID_ISSUER:"Invalid issuer",INVALID_AUDIENCE:"Invalid audience",INVALID_NONCE:"Invalid nonce",EXPIRED_TOKEN:"Expired token",INVALID_STATE:"Invalid state",INVALID_ORIGIN:"Invalid origin",INVALID_TOKEN:"Invalid token",MISSING_PUBLIC_KEY:"Cannot find public key",INVALID_ACCESS_TOKEN:"Access token must be a string",MISSING_CLIENT_ID:"Missing client ID",MISSING_DISCOVERY_ENDPOINT:"Missing discovery endpoint",RESPONSE_TYPE:"code",RESPONSE_MODE:"web_message",PROMPT:"none",SCOPE:"openid",STATE_LENGTH:20,NONCE_LENGTH:20,CODE_VERIFIER_LENGTH:44,CHALLENGE_METHOD:"S256",TOKEN_ALG:"RS256",VERSION:4,MALFORMED_ACCESS_TOKEN:"eyJpc3MiOiJtb2JpbGVjbGllbnRhY2Nlc3Muc3RhZ2UxLm5nLmJsdWVtaXgubmV0IiwiZXhwIjoxNDg3MDg0ODc4LCJhdWQiOiIyNmNiMDEyZWIzMjdjNjEyZDkwYTY4MTkxNjNiNmJjYmQ0ODQ5Y2JiIiwiaWF0IjoxNDg3MDgxMjc4LCJhdXRoX2J5IjoiZmFjZWJvb2siLCJ0ZW5hbnQiOiI0ZGJhOTQzMC01NGU2LTRjZjItYTUxNi02ZjczZmViNzAyYmIiLCJzY29wZSI6ImFwcGlkX2RlZmF1bHQgYXBwaWRfcmVhZHByb2ZpbGUgYXBwaWRfcmVhZHVzZXJhdHRyIGFwcGlkX3dyaXRldXNlcmF0dHIifQ.HHterec250JSDY1965cM2DadBznl2wTKmzKNSnfjpdTAqax9VZvV3EwuFbEnGp9-i6AC-OlsVj7xvbALkdjwG2lZvpQx0M_gRc_3E0NiYuOGVolcm0wEXtbtDUFFqZQAf9BYYOPZ8OintdBiwUGETbH1ZRVtUvt3nalIko1OPE1Q12LvuRlhz5MClNHmvxJcXc7kucxCx4s4UFFy_HJA1gow7HWFqc9-PZf4JMWA-siYqPrdw_zYeBTBzE5co92F6JBEtGLLCjhJVz9eYgLLECXbak3z6hOaY9352Weuj7AgMOWxzw56jKKsiixMtvzrCzLVIcRUG96UJszwPHtPlA",INVALID_SIGNATURE_TOKEN:"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTU2NjMxMDg5NSwiZXhwIjoxNTY2MzE0NDk1LCJpYXQiOjE1NjYzMTA4OTUsImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciIsImF1ZCI6WyJodHRwOi8vZm9vMS5jb20iLCJodHRwOi8vZm9vMi5jb20iXX0.NBDYg8VZxW770qcbIl40OFvaQntO-FVYUUJocE5ZgcyrvFTuomwF997OcEJghO8BE_Y2m67PbfPFsbN0VI6j"}},function(t,e,i){(function(t){var i={userAgent:!1},n={}; /*! Copyright (c) 2011, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: @@ -14,37 +14,37 @@ if(void 0===r)var r={};r.lang={extend:function(t,e,n){if(!e||!t)throw new Error( * https://code.google.com/p/crypto-js/issues/detail?id=84 * https://crypto-js.googlecode.com/svn-history/r667/branches/3.x/src/core.js */ -var s,a,o,h,u,c,l,f,d,g,p,y=y||(s=Math,o=(a={}).lib={},h=o.Base=function(){function t(){}return{extend:function(e){t.prototype=this;var i=new t;return e&&i.mixIn(e),i.hasOwnProperty("init")||(i.init=function(){i.$super.init.apply(this,arguments)}),i.init.prototype=i,i.$super=this,i},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),u=o.WordArray=h.extend({init:function(t,e){t=this.words=t||[],this.sigBytes=null!=e?e:4*t.length},toString:function(t){return(t||l).stringify(this)},concat:function(t){var e=this.words,i=t.words,n=this.sigBytes,r=t.sigBytes;if(this.clamp(),n%4)for(var s=0;s>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],E=d[F],x=257*d[m]^16843008*m;s[p]=x<<24|x>>>8,a[p]=x<<16|x>>>16,o[p]=x<<8|x>>>24,h[p]=x,x=16843009*E^65537*F^257*S^16843008*p,u[m]=x<<24|x>>>8,c[m]=x<<16|x>>>16,l[m]=x<<8|x>>>24,f[m]=x,p?(p=S^d[d[d[E^S]]],v^=d[d[v]]):p=v=1}var w=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=w[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],E=t[s+13],x=t[s+14],w=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,E,12,u[13]),I=e(I,A,b,C,x,17,u[14]),b=i(b,C=e(C,I,A,b,w,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,w,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,x,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,E,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,x,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,E,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,w,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,x,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,w,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,E,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,E=h.low,x=u.high,w=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,H=p,R=y,B=v,N=m,O=S,j=F,V=E,L=x,K=w,_=b,k=A,M=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&_,Q=V&K^~V&k,z=D&P^D&R^P&R;var tt=T&H^T&B^H&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=M+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),M=_,U=k,_=L,k=K,L=j,K=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=R,O=B,R=P,B=H,P=D,H=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+H,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+R+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),E=h.low=E+V,h.high=F+j+(E>>>0>>0?1:0),w=u.low=w+K,u.high=x+L+(w>>>0>>0?1:0),A=c.low=A+k,c.high=b+_+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+M+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,E=(n=h.words,u.words),x=r.words,w=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+x[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+w[i]]|0,I=16>i?I+((y^(v|~m))+E[0]):32>i?I+((y&m|v&~m)+E[1]):48>i?I+(((y|~v)^m)+E[2]):64>i?I+((y&v|~y&m)+E[3]):I+((y^v^m)+E[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],w=d[F],E=257*d[m]^16843008*m;s[p]=E<<24|E>>>8,a[p]=E<<16|E>>>16,o[p]=E<<8|E>>>24,h[p]=E,E=16843009*w^65537*F^257*S^16843008*p,u[m]=E<<24|E>>>8,c[m]=E<<16|E>>>16,l[m]=E<<8|E>>>24,f[m]=E,p?(p=S^d[d[d[w^S]]],v^=d[d[v]]):p=v=1}var x=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=x[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],w=t[s+13],E=t[s+14],x=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,w,12,u[13]),I=e(I,A,b,C,E,17,u[14]),b=i(b,C=e(C,I,A,b,x,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,x,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,E,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,w,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,E,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,w,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,x,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,E,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,x,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,w,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,w=h.low,E=u.high,x=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,H=p,R=y,B=v,N=m,O=S,j=F,V=w,L=E,_=x,K=b,M=A,k=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&K,Q=V&_^~V&M,z=D&P^D&R^P&R;var tt=T&H^T&B^H&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=k+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),k=K,U=M,K=L,M=_,L=j,_=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=R,O=B,R=P,B=H,P=D,H=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+H,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+R+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),w=h.low=w+V,h.high=F+j+(w>>>0>>0?1:0),x=u.low=x+_,u.high=E+L+(x>>>0<_>>>0?1:0),A=c.low=A+M,c.high=b+K+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+k+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,w=(n=h.words,u.words),E=r.words,x=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+E[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+x[i]]|0,I=16>i?I+((y^(v|~m))+w[0]):32>i?I+((y&m|v&~m)+w[1]):48>i?I+(((y|~v)^m)+w[2]):64>i?I+((y&v|~y&m)+w[3]):I+((y^v^m)+w[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function E(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function x(t){var e,i=E(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(w.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(w.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),w.prototype.DB=v,w.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function _(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function k(){}function M(t){return t}function U(t){this.r2=b(),this.q3=b(),w.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(w.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},w.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},w.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},w.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},w.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},w.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},w.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},w.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},w.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),w.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&w.ZERO.subTo(i,i)}}},w.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},w.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},w.prototype.exp=function(t,e){if(t>4294967295||t<1)return w.ONE;var i=b(),n=b(),r=e.convert(this),s=R(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},w.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},w.prototype.negate=function(){var t=b();return w.ZERO.subTo(this,t),t},w.prototype.abs=function(){return this.s<0?this.negate():this},w.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},w.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+R(this[this.t-1]^this.s&this.DM)},w.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(w.ZERO)>0&&t.subTo(e,e),e},w.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},w.ZERO=H(0),w.ONE=H(1),k.prototype.convert=M,k.prototype.revert=M,k.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},k.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; +var v,m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",S="=";function F(t){var e,i,n="";for(e=0;e+3<=t.length;e+=3)i=parseInt(t.substring(e,e+3),16),n+=m.charAt(i>>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function w(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function E(t){var e,i=w(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(x.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(x.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),x.prototype.DB=v,x.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function K(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function M(){}function k(t){return t}function U(t){this.r2=b(),this.q3=b(),x.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(x.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},x.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},x.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},x.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},x.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},x.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},x.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},x.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},x.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),x.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&x.ZERO.subTo(i,i)}}},x.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},x.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},x.prototype.exp=function(t,e){if(t>4294967295||t<1)return x.ONE;var i=b(),n=b(),r=e.convert(this),s=R(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},x.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},x.prototype.negate=function(){var t=b();return x.ZERO.subTo(this,t),t},x.prototype.abs=function(){return this.s<0?this.negate():this},x.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},x.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+R(this[this.t-1]^this.s&this.DM)},x.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(x.ZERO)>0&&t.subTo(e,e),e},x.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},x.ZERO=H(0),x.ONE=H(1),M.prototype.convert=k,M.prototype.revert=k,M.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},M.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ -function Y(){this.i=0,this.j=0,this.S=new Array}w.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},w.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),n=H(i),r=b(),s=b(),a="";for(this.divRemTo(n,r,s);r.signum()>0;)a=(i+s.intValue()).toString(t).substr(1)+a,r.divRemTo(n,r,s);return s.intValue().toString(t)+a},w.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),n=Math.pow(e,i),r=!1,s=0,a=0,o=0;o=i&&(this.dMultiply(n),this.dAddOffset(a,0),s=0,a=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(a,0)),r&&w.ZERO.subTo(this,this)},w.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(w.ONE.shiftLeft(t-1),j,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(w.ONE.shiftLeft(t-1),this);else{var n=new Array,r=7&t;n.length=1+(t>>3),e.nextBytes(n),r>0?n[0]&=(1<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[i++]=n:n<-1&&(e[i++]=this.DV+n),e.t=i,e.clamp()},w.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},w.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},w.prototype.multiplyLowerTo=function(t,e,i){var n,r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;r>0;)i[--r]=0;for(n=i.t-this.t;r=0;)i[n]=0;for(n=Math.max(e-this.t,0);n0)if(0==e)i=this[0]%t;else for(var n=this.t-1;n>=0;--n)i=(e*i+this[n])%t;return i},w.prototype.millerRabin=function(t){var e=this.subtract(w.ONE),i=e.getLowestSetBit();if(i<=0)return!1;var n=e.shiftRight(i);(t=t+1>>1)>q.length&&(t=q.length);for(var r=b(),s=0;s36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),n=H(i),r=b(),s=b(),a="";for(this.divRemTo(n,r,s);r.signum()>0;)a=(i+s.intValue()).toString(t).substr(1)+a,r.divRemTo(n,r,s);return s.intValue().toString(t)+a},x.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),n=Math.pow(e,i),r=!1,s=0,a=0,o=0;o=i&&(this.dMultiply(n),this.dAddOffset(a,0),s=0,a=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(a,0)),r&&x.ZERO.subTo(this,this)},x.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(x.ONE.shiftLeft(t-1),j,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(x.ONE.shiftLeft(t-1),this);else{var n=new Array,r=7&t;n.length=1+(t>>3),e.nextBytes(n),r>0?n[0]&=(1<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[i++]=n:n<-1&&(e[i++]=this.DV+n),e.t=i,e.clamp()},x.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},x.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},x.prototype.multiplyLowerTo=function(t,e,i){var n,r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;r>0;)i[--r]=0;for(n=i.t-this.t;r=0;)i[n]=0;for(n=Math.max(e-this.t,0);n0)if(0==e)i=this[0]%t;else for(var n=this.t-1;n>=0;--n)i=(e*i+this[n])%t;return i},x.prototype.millerRabin=function(t){var e=this.subtract(x.ONE),i=e.getLowestSetBit();if(i<=0)return!1;var n=e.shiftRight(i);(t=t+1>>1)>q.length&&(t=q.length);for(var r=b(),s=0;s>24},w.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},w.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},w.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},w.prototype.equals=function(t){return 0==this.compareTo(t)},w.prototype.min=function(t){return this.compareTo(t)<0?this:t},w.prototype.max=function(t){return this.compareTo(t)>0?this:t},w.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},w.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},w.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},w.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},w.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=R(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(w.ONE)?w.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},w.prototype.pow=function(t){return this.exp(t,new k)},w.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},w.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>24},x.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},x.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},x.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},x.prototype.equals=function(t){return 0==this.compareTo(t)},x.prototype.min=function(t){return this.compareTo(t)<0?this:t},x.prototype.max=function(t){return this.compareTo(t)>0?this:t},x.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},x.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},x.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},x.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},x.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=R(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(x.ONE)?x.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},x.prototype.pow=function(t){return this.exp(t,new M)},x.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},x.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>8&255,J[W++]^=t>>16&255,J[W++]^=t>>24&255,W>=X&&(W-=X)}((new Date).getTime())}if(null==J){var $;if(J=new Array,W=0,void 0!==n&&(void 0!==n.crypto||void 0!==n.msCrypto)){var Q=n.crypto||n.msCrypto;if(Q.getRandomValues){var tt=new Uint8Array(32);for(Q.getRandomValues(tt),$=0;$<32;++$)J[W++]=tt[$]}else if("Netscape"==i.appName&&i.appVersion<"5"){var et=n.crypto.random(32);for($=0;$>>8,J[W++]=255&$;W=0,Z()}function it(){if(null==G){for(Z(),(G=new Y).init(J),W=0;W>24,(16711680&r)>>16,(65280&r)>>8,255&r]))),r+=1;return n}function at(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}function ot(t,e,i){for(var n="",r=0;n.length>24,(16711680&r)>>16,(65280&r)>>8,255&r])),r+=1;return n} +function rt(t,e){return new x(t,e)}function st(t,e,i){for(var n="",r=0;n.length>24,(16711680&r)>>16,(65280&r)>>8,255&r]))),r+=1;return n}function at(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}function ot(t,e,i){for(var n="",r=0;n.length>24,(16711680&r)>>16,(65280&r)>>8,255&r])),r+=1;return n} /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ -function ht(t,e){this.x=e,this.q=t}function ut(t,e,i,n){this.curve=t,this.x=e,this.y=i,this.z=null==n?w.ONE:n,this.zinv=null}function ct(t,e,i){this.q=t,this.a=this.fromBigInteger(e),this.b=this.fromBigInteger(i),this.infinity=new ut(this,null,null)}nt.prototype.nextBytes=function(t){var e;for(e=0;e0&&e.length>0))throw"Invalid RSA public key";this.n=rt(t,16),this.e=parseInt(e,16)}},at.prototype.encrypt=function(t){var e=function(t,e){if(e=0&&e>0;){var r=t.charCodeAt(n--);r<128?i[--e]=r:r>127&&r<2048?(i[--e]=63&r|128,i[--e]=r>>6|192):(i[--e]=63&r|128,i[--e]=r>>6&63|128,i[--e]=r>>12|224)}i[--e]=0;for(var s=new nt,a=new Array;e>2;){for(a[0]=0;0==a[0];)s.nextBytes(a);i[--e]=a[0]}return i[--e]=2,i[--e]=0,new w(i)}(t,this.n.bitLength()+7>>3);if(null==e)return null;var i=this.doPublic(e);if(null==i)return null;var n=i.toString(16);return 0==(1&n.length)?n:"0"+n},at.prototype.encryptOAEP=function(t,e,i){var n=function(t,e,i,n){var r=ft.crypto.MessageDigest,s=ft.crypto.Util,a=null;if(i||(i="sha1"),"string"==typeof i&&(a=r.getCanonicalAlgName(i),n=r.getHashLength(a),i=function(t){return It(s.hashHex(Ct(t),a))}),t.length+2*n+2>e)throw"Message too long for RSA";var o,h="";for(o=0;o>3,e,i);if(null==n)return null;var r=this.doPublic(n);if(null==r)return null;var s=r.toString(16);return 0==(1&s.length)?s:"0"+s},at.prototype.type="RSA",at.prototype.doPrivate=function(t){if(null==this.p||null==this.q)return t.modPow(this.d,this.n);for(var e=t.mod(this.p).modPow(this.dmp1,this.p),i=t.mod(this.q).modPow(this.dmq1,this.q);e.compareTo(i)<0;)e=e.add(this.p);return e.subtract(i).multiply(this.coeff).mod(this.p).multiply(this.q).add(i)},at.prototype.setPrivate=function(t,e,i){if(this.isPrivate=!0,"string"!=typeof t)this.n=t,this.e=e,this.d=i;else{if(!(null!=t&&null!=e&&t.length>0&&e.length>0))throw"Invalid RSA private key";this.n=rt(t,16),this.e=parseInt(e,16),this.d=rt(i,16)}},at.prototype.setPrivateEx=function(t,e,i,n,r,s,a,o){if(this.isPrivate=!0,this.isPublic=!1,null==t)throw"RSASetPrivateEx N == null";if(null==e)throw"RSASetPrivateEx E == null";if(0==t.length)throw"RSASetPrivateEx N.length == 0";if(0==e.length)throw"RSASetPrivateEx E.length == 0";if(!(null!=t&&null!=e&&t.length>0&&e.length>0))throw"Invalid RSA private key in RSASetPrivateEx";this.n=rt(t,16),this.e=parseInt(e,16),this.d=rt(i,16),this.p=rt(n,16),this.q=rt(r,16),this.dmp1=rt(s,16),this.dmq1=rt(a,16),this.coeff=rt(o,16)},at.prototype.generate=function(t,e){var i=new nt,n=t>>1;this.e=parseInt(e,16);for(var r=new w(e,16);;){for(;this.p=new w(t-n,1,i),0!=this.p.subtract(w.ONE).gcd(r).compareTo(w.ONE)||!this.p.isProbablePrime(10););for(;this.q=new w(n,1,i),0!=this.q.subtract(w.ONE).gcd(r).compareTo(w.ONE)||!this.q.isProbablePrime(10););if(this.p.compareTo(this.q)<=0){var s=this.p;this.p=this.q,this.q=s}var a=this.p.subtract(w.ONE),o=this.q.subtract(w.ONE),h=a.multiply(o);if(0==h.gcd(r).compareTo(w.ONE)){this.n=this.p.multiply(this.q),this.d=r.modInverse(h),this.dmp1=this.d.mod(a),this.dmq1=this.d.mod(o),this.coeff=this.q.modInverse(this.p);break}}this.isPrivate=!0},at.prototype.decrypt=function(t){var e=rt(t,16),i=this.doPrivate(e);return null==i?null: +function ht(t,e){this.x=e,this.q=t}function ut(t,e,i,n){this.curve=t,this.x=e,this.y=i,this.z=null==n?x.ONE:n,this.zinv=null}function ct(t,e,i){this.q=t,this.a=this.fromBigInteger(e),this.b=this.fromBigInteger(i),this.infinity=new ut(this,null,null)}nt.prototype.nextBytes=function(t){var e;for(e=0;e0&&e.length>0))throw"Invalid RSA public key";this.n=rt(t,16),this.e=parseInt(e,16)}},at.prototype.encrypt=function(t){var e=function(t,e){if(e=0&&e>0;){var r=t.charCodeAt(n--);r<128?i[--e]=r:r>127&&r<2048?(i[--e]=63&r|128,i[--e]=r>>6|192):(i[--e]=63&r|128,i[--e]=r>>6&63|128,i[--e]=r>>12|224)}i[--e]=0;for(var s=new nt,a=new Array;e>2;){for(a[0]=0;0==a[0];)s.nextBytes(a);i[--e]=a[0]}return i[--e]=2,i[--e]=0,new x(i)}(t,this.n.bitLength()+7>>3);if(null==e)return null;var i=this.doPublic(e);if(null==i)return null;var n=i.toString(16);return 0==(1&n.length)?n:"0"+n},at.prototype.encryptOAEP=function(t,e,i){var n=function(t,e,i,n){var r=ft.crypto.MessageDigest,s=ft.crypto.Util,a=null;if(i||(i="sha1"),"string"==typeof i&&(a=r.getCanonicalAlgName(i),n=r.getHashLength(a),i=function(t){return It(s.hashHex(Ct(t),a))}),t.length+2*n+2>e)throw"Message too long for RSA";var o,h="";for(o=0;o>3,e,i);if(null==n)return null;var r=this.doPublic(n);if(null==r)return null;var s=r.toString(16);return 0==(1&s.length)?s:"0"+s},at.prototype.type="RSA",at.prototype.doPrivate=function(t){if(null==this.p||null==this.q)return t.modPow(this.d,this.n);for(var e=t.mod(this.p).modPow(this.dmp1,this.p),i=t.mod(this.q).modPow(this.dmq1,this.q);e.compareTo(i)<0;)e=e.add(this.p);return e.subtract(i).multiply(this.coeff).mod(this.p).multiply(this.q).add(i)},at.prototype.setPrivate=function(t,e,i){if(this.isPrivate=!0,"string"!=typeof t)this.n=t,this.e=e,this.d=i;else{if(!(null!=t&&null!=e&&t.length>0&&e.length>0))throw"Invalid RSA private key";this.n=rt(t,16),this.e=parseInt(e,16),this.d=rt(i,16)}},at.prototype.setPrivateEx=function(t,e,i,n,r,s,a,o){if(this.isPrivate=!0,this.isPublic=!1,null==t)throw"RSASetPrivateEx N == null";if(null==e)throw"RSASetPrivateEx E == null";if(0==t.length)throw"RSASetPrivateEx N.length == 0";if(0==e.length)throw"RSASetPrivateEx E.length == 0";if(!(null!=t&&null!=e&&t.length>0&&e.length>0))throw"Invalid RSA private key in RSASetPrivateEx";this.n=rt(t,16),this.e=parseInt(e,16),this.d=rt(i,16),this.p=rt(n,16),this.q=rt(r,16),this.dmp1=rt(s,16),this.dmq1=rt(a,16),this.coeff=rt(o,16)},at.prototype.generate=function(t,e){var i=new nt,n=t>>1;this.e=parseInt(e,16);for(var r=new x(e,16);;){for(;this.p=new x(t-n,1,i),0!=this.p.subtract(x.ONE).gcd(r).compareTo(x.ONE)||!this.p.isProbablePrime(10););for(;this.q=new x(n,1,i),0!=this.q.subtract(x.ONE).gcd(r).compareTo(x.ONE)||!this.q.isProbablePrime(10););if(this.p.compareTo(this.q)<=0){var s=this.p;this.p=this.q,this.q=s}var a=this.p.subtract(x.ONE),o=this.q.subtract(x.ONE),h=a.multiply(o);if(0==h.gcd(r).compareTo(x.ONE)){this.n=this.p.multiply(this.q),this.d=r.modInverse(h),this.dmp1=this.d.mod(a),this.dmq1=this.d.mod(o),this.coeff=this.q.modInverse(this.p);break}}this.isPrivate=!0},at.prototype.decrypt=function(t){var e=rt(t,16),i=this.doPrivate(e);return null==i?null: /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ -function(t,e){for(var i=t.toByteArray(),n=0;n=i.length)return null;for(var r="";++n191&&s<224?(r+=String.fromCharCode((31&s)<<6|63&i[n+1]),++n):(r+=String.fromCharCode((15&s)<<12|(63&i[n+1])<<6|63&i[n+2]),n+=2)}return r}(i,this.n.bitLength()+7>>3)},at.prototype.decryptOAEP=function(t,e,i){var n=rt(t,16),r=this.doPrivate(n);return null==r?null:function(t,e,i,n){var r=ft.crypto.MessageDigest,s=ft.crypto.Util,a=null;for(i||(i="sha1"),"string"==typeof i&&(a=r.getCanonicalAlgName(i),n=r.getHashLength(a),i=function(t){return It(s.hashHex(Ct(t),a))}),t=t.toByteArray(),o=0;o>3,e,i)},ht.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.x.equals(t.x)},ht.prototype.toBigInteger=function(){return this.x},ht.prototype.negate=function(){return new ht(this.q,this.x.negate().mod(this.q))},ht.prototype.add=function(t){return new ht(this.q,this.x.add(t.toBigInteger()).mod(this.q))},ht.prototype.subtract=function(t){return new ht(this.q,this.x.subtract(t.toBigInteger()).mod(this.q))},ht.prototype.multiply=function(t){return new ht(this.q,this.x.multiply(t.toBigInteger()).mod(this.q))},ht.prototype.square=function(){return new ht(this.q,this.x.square().mod(this.q))},ht.prototype.divide=function(t){return new ht(this.q,this.x.multiply(t.toBigInteger().modInverse(this.q)).mod(this.q))},ut.prototype.getX=function(){return null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))},ut.prototype.getY=function(){return null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))},ut.prototype.equals=function(t){return t==this||(this.isInfinity()?t.isInfinity():t.isInfinity()?this.isInfinity():!!t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(w.ZERO)&&t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(w.ZERO))},ut.prototype.isInfinity=function(){return null==this.x&&null==this.y||this.z.equals(w.ZERO)&&!this.y.toBigInteger().equals(w.ZERO)},ut.prototype.negate=function(){return new ut(this.curve,this.x,this.y.negate(),this.z)},ut.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q),i=t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q);if(w.ZERO.equals(i))return w.ZERO.equals(e)?this.twice():this.curve.getInfinity();var n=new w("3"),r=this.x.toBigInteger(),s=this.y.toBigInteger(),a=(t.x.toBigInteger(),t.y.toBigInteger(),i.square()),o=a.multiply(i),h=r.multiply(a),u=e.square().multiply(this.z),c=u.subtract(h.shiftLeft(1)).multiply(t.z).subtract(o).multiply(i).mod(this.curve.q),l=h.multiply(n).multiply(e).subtract(s.multiply(o)).subtract(u.multiply(e)).multiply(t.z).add(e.multiply(o)).mod(this.curve.q),f=o.multiply(this.z).multiply(t.z).mod(this.curve.q);return new ut(this.curve,this.curve.fromBigInteger(c),this.curve.fromBigInteger(l),f)},ut.prototype.twice=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=new w("3"),e=this.x.toBigInteger(),i=this.y.toBigInteger(),n=i.multiply(this.z),r=n.multiply(i).mod(this.curve.q),s=this.curve.a.toBigInteger(),a=e.square().multiply(t);w.ZERO.equals(s)||(a=a.add(this.z.square().multiply(s)));var o=(a=a.mod(this.curve.q)).square().subtract(e.shiftLeft(3).multiply(r)).shiftLeft(1).multiply(n).mod(this.curve.q),h=a.multiply(t).multiply(e).subtract(r.shiftLeft(1)).shiftLeft(2).multiply(r).subtract(a.square().multiply(a)).mod(this.curve.q),u=n.square().multiply(n).shiftLeft(3).mod(this.curve.q);return new ut(this.curve,this.curve.fromBigInteger(o),this.curve.fromBigInteger(h),u)},ut.prototype.multiply=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new w("3")),r=this.negate(),s=this;for(e=n.bitLength()-2;e>0;--e){s=s.twice();var a=n.testBit(e);a!=i.testBit(e)&&(s=s.add(a?this:r))}return s},ut.prototype.multiplyTwo=function(t,e,i){var n;n=t.bitLength()>i.bitLength()?t.bitLength()-1:i.bitLength()-1;for(var r=this.curve.getInfinity(),s=this.add(e);n>=0;)r=r.twice(),t.testBit(n)?r=i.testBit(n)?r.add(s):r.add(this):i.testBit(n)&&(r=r.add(e)),--n;return r},ct.prototype.getQ=function(){return this.q},ct.prototype.getA=function(){return this.a},ct.prototype.getB=function(){return this.b},ct.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)},ct.prototype.getInfinity=function(){return this.infinity},ct.prototype.fromBigInteger=function(t){return new ht(this.q,t)},ct.prototype.decodePointHex=function(t){switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var e=(t.length-2)/2,i=t.substr(2,e),n=t.substr(e+2,e);return new ut(this,this.fromBigInteger(new w(i,16)),this.fromBigInteger(new w(n,16)));default:return null}}, +function(t,e){for(var i=t.toByteArray(),n=0;n=i.length)return null;for(var r="";++n191&&s<224?(r+=String.fromCharCode((31&s)<<6|63&i[n+1]),++n):(r+=String.fromCharCode((15&s)<<12|(63&i[n+1])<<6|63&i[n+2]),n+=2)}return r}(i,this.n.bitLength()+7>>3)},at.prototype.decryptOAEP=function(t,e,i){var n=rt(t,16),r=this.doPrivate(n);return null==r?null:function(t,e,i,n){var r=ft.crypto.MessageDigest,s=ft.crypto.Util,a=null;for(i||(i="sha1"),"string"==typeof i&&(a=r.getCanonicalAlgName(i),n=r.getHashLength(a),i=function(t){return It(s.hashHex(Ct(t),a))}),t=t.toByteArray(),o=0;o>3,e,i)},ht.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.x.equals(t.x)},ht.prototype.toBigInteger=function(){return this.x},ht.prototype.negate=function(){return new ht(this.q,this.x.negate().mod(this.q))},ht.prototype.add=function(t){return new ht(this.q,this.x.add(t.toBigInteger()).mod(this.q))},ht.prototype.subtract=function(t){return new ht(this.q,this.x.subtract(t.toBigInteger()).mod(this.q))},ht.prototype.multiply=function(t){return new ht(this.q,this.x.multiply(t.toBigInteger()).mod(this.q))},ht.prototype.square=function(){return new ht(this.q,this.x.square().mod(this.q))},ht.prototype.divide=function(t){return new ht(this.q,this.x.multiply(t.toBigInteger().modInverse(this.q)).mod(this.q))},ut.prototype.getX=function(){return null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))},ut.prototype.getY=function(){return null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))},ut.prototype.equals=function(t){return t==this||(this.isInfinity()?t.isInfinity():t.isInfinity()?this.isInfinity():!!t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(x.ZERO)&&t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(x.ZERO))},ut.prototype.isInfinity=function(){return null==this.x&&null==this.y||this.z.equals(x.ZERO)&&!this.y.toBigInteger().equals(x.ZERO)},ut.prototype.negate=function(){return new ut(this.curve,this.x,this.y.negate(),this.z)},ut.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q),i=t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q);if(x.ZERO.equals(i))return x.ZERO.equals(e)?this.twice():this.curve.getInfinity();var n=new x("3"),r=this.x.toBigInteger(),s=this.y.toBigInteger(),a=(t.x.toBigInteger(),t.y.toBigInteger(),i.square()),o=a.multiply(i),h=r.multiply(a),u=e.square().multiply(this.z),c=u.subtract(h.shiftLeft(1)).multiply(t.z).subtract(o).multiply(i).mod(this.curve.q),l=h.multiply(n).multiply(e).subtract(s.multiply(o)).subtract(u.multiply(e)).multiply(t.z).add(e.multiply(o)).mod(this.curve.q),f=o.multiply(this.z).multiply(t.z).mod(this.curve.q);return new ut(this.curve,this.curve.fromBigInteger(c),this.curve.fromBigInteger(l),f)},ut.prototype.twice=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=new x("3"),e=this.x.toBigInteger(),i=this.y.toBigInteger(),n=i.multiply(this.z),r=n.multiply(i).mod(this.curve.q),s=this.curve.a.toBigInteger(),a=e.square().multiply(t);x.ZERO.equals(s)||(a=a.add(this.z.square().multiply(s)));var o=(a=a.mod(this.curve.q)).square().subtract(e.shiftLeft(3).multiply(r)).shiftLeft(1).multiply(n).mod(this.curve.q),h=a.multiply(t).multiply(e).subtract(r.shiftLeft(1)).shiftLeft(2).multiply(r).subtract(a.square().multiply(a)).mod(this.curve.q),u=n.square().multiply(n).shiftLeft(3).mod(this.curve.q);return new ut(this.curve,this.curve.fromBigInteger(o),this.curve.fromBigInteger(h),u)},ut.prototype.multiply=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new x("3")),r=this.negate(),s=this;for(e=n.bitLength()-2;e>0;--e){s=s.twice();var a=n.testBit(e);a!=i.testBit(e)&&(s=s.add(a?this:r))}return s},ut.prototype.multiplyTwo=function(t,e,i){var n;n=t.bitLength()>i.bitLength()?t.bitLength()-1:i.bitLength()-1;for(var r=this.curve.getInfinity(),s=this.add(e);n>=0;)r=r.twice(),t.testBit(n)?r=i.testBit(n)?r.add(s):r.add(this):i.testBit(n)&&(r=r.add(e)),--n;return r},ct.prototype.getQ=function(){return this.q},ct.prototype.getA=function(){return this.a},ct.prototype.getB=function(){return this.b},ct.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)},ct.prototype.getInfinity=function(){return this.infinity},ct.prototype.fromBigInteger=function(t){return new ht(this.q,t)},ct.prototype.decodePointHex=function(t){switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var e=(t.length-2)/2,i=t.substr(2,e),n=t.substr(e+2,e);return new ut(this,this.fromBigInteger(new x(i,16)),this.fromBigInteger(new x(n,16)));default:return null}}, /*! (c) Stefan Thomas | https://github.com/bitcoinjs/bitcoinjs-lib */ -ht.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)},ut.prototype.getEncoded=function(t){var e=function(t,e){var i=t.toByteArrayUnsigned();if(ei.length;)i.unshift(0);return i},i=this.getX().toBigInteger(),n=this.getY().toBigInteger(),r=e(i,32);return t?n.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(e(n,32))),r},ut.decodeFrom=function(t,e){e[0];var i=e.length-1,n=e.slice(1,1+i/2),r=e.slice(1+i/2,1+i);n.unshift(0),r.unshift(0);var s=new w(n),a=new w(r);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.decodeFromHex=function(t,e){e.substr(0,2);var i=e.length-2,n=e.substr(2,i/2),r=e.substr(2+i/2,i/2),s=new w(n,16),a=new w(r,16);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.prototype.add2D=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();var e=t.x.subtract(this.x),i=t.y.subtract(this.y).divide(e),n=i.square().subtract(this.x).subtract(t.x),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=this.curve.fromBigInteger(w.valueOf(2)),e=this.curve.fromBigInteger(w.valueOf(3)),i=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),n=i.square().subtract(this.x.multiply(t)),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new w("3")),r=this.negate(),s=this;for(e=n.bitLength()-2;e>0;--e){s=s.twice();var a=n.testBit(e);a!=i.testBit(e)&&(s=s.add2D(a?this:r))}return s},ut.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),i=this.curve.getA().toBigInteger(),n=this.curve.getB().toBigInteger(),r=this.curve.getQ(),s=e.multiply(e).mod(r),a=t.multiply(t).multiply(t).add(i.multiply(t)).add(n).mod(r);return s.equals(a)},ut.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},ut.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),i=this.getY().toBigInteger();if(e.compareTo(w.ONE)<0||e.compareTo(t.subtract(w.ONE))>0)throw new Error("x coordinate out of bounds");if(i.compareTo(w.ONE)<0||i.compareTo(t.subtract(w.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0}; +ht.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)},ut.prototype.getEncoded=function(t){var e=function(t,e){var i=t.toByteArrayUnsigned();if(ei.length;)i.unshift(0);return i},i=this.getX().toBigInteger(),n=this.getY().toBigInteger(),r=e(i,32);return t?n.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(e(n,32))),r},ut.decodeFrom=function(t,e){e[0];var i=e.length-1,n=e.slice(1,1+i/2),r=e.slice(1+i/2,1+i);n.unshift(0),r.unshift(0);var s=new x(n),a=new x(r);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.decodeFromHex=function(t,e){e.substr(0,2);var i=e.length-2,n=e.substr(2,i/2),r=e.substr(2+i/2,i/2),s=new x(n,16),a=new x(r,16);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.prototype.add2D=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();var e=t.x.subtract(this.x),i=t.y.subtract(this.y).divide(e),n=i.square().subtract(this.x).subtract(t.x),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=this.curve.fromBigInteger(x.valueOf(2)),e=this.curve.fromBigInteger(x.valueOf(3)),i=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),n=i.square().subtract(this.x.multiply(t)),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new x("3")),r=this.negate(),s=this;for(e=n.bitLength()-2;e>0;--e){s=s.twice();var a=n.testBit(e);a!=i.testBit(e)&&(s=s.add2D(a?this:r))}return s},ut.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),i=this.curve.getA().toBigInteger(),n=this.curve.getB().toBigInteger(),r=this.curve.getQ(),s=e.multiply(e).mod(r),a=t.multiply(t).multiply(t).add(i.multiply(t)).add(n).mod(r);return s.equals(a)},ut.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},ut.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),i=this.getY().toBigInteger();if(e.compareTo(x.ONE)<0||e.compareTo(t.subtract(x.ONE))>0)throw new Error("x coordinate out of bounds");if(i.compareTo(x.ONE)<0||i.compareTo(t.subtract(x.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0}; /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval */ -var lt=function(){var t=new RegExp('(?:false|true|null|[\\{\\}\\[\\]]|(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)|(?:"(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))*"))',"g"),e=new RegExp("\\\\(?:([^u])|u(.{4}))","g"),i={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function n(t,e,n){return e?i[e]:String.fromCharCode(parseInt(n,16))}var r=new String(""),s=(Object,Array,Object.hasOwnProperty);return function(i,a){var o,h,u=i.match(t),c=u[0],l=!1;"{"===c?o={}:"["===c?o=[]:(o=[],l=!0);for(var f=[o],d=1-l,g=u.length;d=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new w(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function Kt(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function _t(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function Mt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map(function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Rt;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map(function(t){return t.replace("/","\\/")})).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Rt;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=Mt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Rt(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Ht(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(w.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:w.fromByteArrayUnsigned(i),s:w.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:w.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:w.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new w(e.r,16),s:new w(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new w(t,16),n=new w(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new w(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),E=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=E,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var x=0;x1?new w(n,16):null,u=new w(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new w(t,16),s=new w(e,16),a=new w(i,16),o=new w(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(w.ONE.add(w.ONE),i.subtract(w.ONE)),a=new w(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new w(t.substr(0,n.bitLength()/4),16);if(w.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(w.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new w(pt.getVbyList(t,0,[0],"02"),16),new w(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Rt(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Rt(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Rt,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(wt(t.n),wt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(wt(t.n),wt(t.e),wt(t.d),wt(t.p),wt(t.q),wt(t.dp),wt(t.dq),wt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(wt(t.n),wt(t.e),wt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+wt(t.x)).slice(-l)+("0000000000"+wt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+wt(t.x)).slice(-l)+("0000000000"+wt(t.y)).slice(-l);var d=("0000000000"+wt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Rt(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(H=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),x=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new w(S,16),new w(F,16),new w(E,16),new w(x,16),new w(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(H=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(H,0,[2,0],"06"),P=r(H,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var H;S=r(H=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),x=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new w(S,16),new w(F,16),new w(E,16),new w(x,16),new w(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Ht(w=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(w=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),E=m(t).getEncodedHex(),x="";return x+=Ht(F,"EC PARAMETERS"),x+=Ht(E,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(w=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var w=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",w,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){w=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",w,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){w=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",w,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();w=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(w,"PRIVATE KEY"):Ht(E=b(w,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),w=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(w,"PRIVATE KEY"):Ht(E=b(w,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),w=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(w,"PRIVATE KEY"):Ht(E=b(w,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Rt(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=xt(t.n.toString(16)),e.e=xt(t.e.toString(16)),e.d=xt(t.d.toString(16)),e.p=xt(t.p.toString(16)),e.q=xt(t.q.toString(16)),e.dp=xt(t.dmp1.toString(16)),e.dq=xt(t.dmq1.toString(16)),e.qi=xt(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=xt(t.n.toString(16)),e.e=xt(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=xt(i.x),e.y=xt(i.y),e.d=xt(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=xt(i.x),e.y=xt(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Rt(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Rt;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new w(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=wt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(wt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=w,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=E,e.b64toBA=x,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(x(Et(t)))},e.b64tob64u=Ft,e.b64utob64=Et,e.hex2b64=F,e.hextob64u=xt,e.b64utohex=wt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(_t(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(E(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Ht,e.pemtohex=Rt,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map(function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Rt;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map(function(t){return t.replace("/","\\/")})).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Rt;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Rt(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Ht(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),w=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=w,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var E=0;E1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Rt(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Rt(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Rt,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Rt(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(H=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(H,0,[2],"02"),w=r(H,0,[3],"02"),E=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(H=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(H,0,[2,0],"06"),P=r(H,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var H;S=r(H=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(H,0,[2],"02"),w=r(H,0,[3],"02"),E=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Ht(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),w=m(t).getEncodedHex(),E="";return E+=Ht(F,"EC PARAMETERS"),E+=Ht(w,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Rt(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e.d=Et(t.d.toString(16)),e.p=Et(t.p.toString(16)),e.q=Et(t.q.toString(16)),e.dp=Et(t.dmp1.toString(16)),e.dq=Et(t.dmq1.toString(16)),e.qi=Et(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e.d=Et(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Rt(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Rt;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=w,e.b64toBA=E,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(E(wt(t)))},e.b64tob64u=Ft,e.b64utob64=wt,e.hex2b64=F,e.hextob64u=Et,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(w(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Ht,e.pemtohex=Rt,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp * @license MIT */ -var n=i(6),r=i(7),s=i(8);function a(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return k(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return M(t).length;default:if(n)return k(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return H(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return E(this,t,e,i);case"latin1":case"binary":return x(this,t,e,i);case"base64":return w(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||R(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||R(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||R(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||R(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||R(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||R(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||R(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||R(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||R(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||R(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function M(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(K,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(5))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e,i){const n=i(10),r=i(11);t.exports=class{async request(t,e){const i=await n(t,e),s=await i.text();if(!i.ok||i.status>300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e,i){const n=i(13);t.exports=class{constructor({w:t=window}={}){this.window=t}open(){const t=(screen.width-400)/2,e=(screen.height-700)/2;if(this.popup=this.window.open("","popup",`left=${t},top=${e},width=400,height=700,resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(15);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}},function(t,e,i){const n=i(1),r=i(18);t.exports=class{constructor({jwt:t=i(0)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return M(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return k(t).length;default:if(n)return M(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return H(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return w(this,t,e,i);case"latin1":case"binary":return E(this,t,e,i);case"base64":return x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||R(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||R(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||R(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||R(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||R(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||R(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||R(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||R(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||R(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||R(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function k(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(_,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(8))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e){t.exports=class extends Error{constructor({error:t,description:e}){super(e||t),this.error=t,this.description=e}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(17);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){const e=t.height,i=t.width,r=(screen.width-i)/2,s=(screen.height-e)/2;if(this.popup=this.window.open("","popup",`left=${r},top=${s},width=${i},height=${e},resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(19);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}}])}); \ No newline at end of file diff --git a/src/PopupController.js b/src/PopupController.js index 9a637ff..903323a 100644 --- a/src/PopupController.js +++ b/src/PopupController.js @@ -5,9 +5,9 @@ class PopupController { this.window = w; }; - open() { - const h = 700; - const w = 400; + open(popup) { + const h = popup.height; + const w = popup.width; const left = (screen.width - w) / 2; const top = (screen.height - h) / 2; this.popup = this.window.open('', 'popup', `left=${left},top=${top},width=${w},height=${h},resizable,scrollbars=yes,status=1`); diff --git a/src/constants.js b/src/constants.js index fc413af..338a87f 100644 --- a/src/constants.js +++ b/src/constants.js @@ -12,6 +12,8 @@ module.exports = { INVALID_TOKEN: 'Invalid token', MISSING_PUBLIC_KEY: 'Cannot find public key', INVALID_ACCESS_TOKEN: 'Access token must be a string', + MISSING_CLIENT_ID: 'Missing client ID', + MISSING_DISCOVERY_ENDPOINT: 'Missing discovery endpoint', RESPONSE_TYPE: 'code', RESPONSE_MODE: 'web_message', PROMPT: 'none', diff --git a/src/errors/AppIDError.js b/src/errors/AppIDError.js index c357ab7..f239ef8 100644 --- a/src/errors/AppIDError.js +++ b/src/errors/AppIDError.js @@ -1,8 +1,2 @@ -class AppIDError extends Error { - constructor({error, description}) { - super(description || error); - this.error = error; - this.description = description; - } -} +class AppIDError extends Error {} module.exports = AppIDError; \ No newline at end of file diff --git a/src/errors/OAuthError.js b/src/errors/OAuthError.js new file mode 100644 index 0000000..3add1d6 --- /dev/null +++ b/src/errors/OAuthError.js @@ -0,0 +1,9 @@ +class OAuthError extends Error { + // See https://tools.ietf.org/html/rfc6749#section-4.1.2.1 for the possible error messages + constructor({error, description}) { + super(description || error); + this.error = error; + this.description = description; + } +} +module.exports = OAuthError; \ No newline at end of file diff --git a/src/index.js b/src/index.js index ad37cca..488408a 100644 --- a/src/index.js +++ b/src/index.js @@ -4,10 +4,18 @@ const PopupController = require('./PopupController'); const IFrameController = require('./IFrameController'); const OpenIdConfigurationResource = require('./OpenIDConfigurationResource'); const TokenValidator = require('./TokenValidator'); -const rs = require('jsrsasign'); const constants = require('./constants'); const AppIDError = require('./errors/AppIDError'); +/** + * todo: + * README - detailed desc for each function and errors, params, npm install + * Function comments in index.js + * Move helper functions to different file + * Update tests + * Add popup obj to init - default {height: screen.height * .85, width: 400} + * + */ class AppID { constructor( { @@ -31,86 +39,73 @@ class AppID { this.URL = url; } - async init({clientId, discoveryEndpoint}) { + /** + * Initialize AppID + * @param clientId - The clientId from the singlepageapp application credentials. + * @param discoveryEndpoint - The discoveryEndpoint from the singlepageapp application credentials. + * @param popup - (optional) The popup configuration. + * @returns {Promise} + * @throws AppIDError - For missing required params. + * @throws RequestError - Any errors during a HTTP request. + */ + async init({clientId, discoveryEndpoint, popup = {height: screen.height * .80, width: 400}}) { + if (!clientId) { + throw new AppIDError(constants.MISSING_CLIENT_ID); + } + if (!discoveryEndpoint) { + throw new AppIDError(constants.MISSING_DISCOVERY_ENDPOINT); + } await this.openIdConfigResource.init({discoveryEndpoint, requestHandler: this.request}); this.clientId = clientId; + this.popupConfig = popup; + this.utils = new Utils({openId: this.openIdConfigResource, clientId: this.clientId}); } + /** + * This will open a login widget in a popup which will prompt the user to enter their credentials. + * After a successful login, the popup will close and tokens are returned. + * @returns {Promise<*|tokens|*>} - The tokens of the authenticated user or an error. + * e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} + * @throws AppIDError "Popup closed" - The user closed the popup before authentication was completed. + * @throws TokenError - Any token validation error. + * @throws OAuthError - Any errors from the server. e.g. {error: 'server_error', description: ''} + * @throws RequestError - Any errors during a HTTP request. + */ async signinWithPopup() { - const {codeVerifier, nonce, state, authUrl} = this.getAuthParams(); + const {codeVerifier, nonce, state, authUrl} = this.utils.getAuthParams(this.clientId, this.window.origin); - this.popup.open(); + this.popup.open(this.popupConfig); this.popup.navigate({authUrl}); const message = await this.popup.waitForMessage({messageType: 'authorization_response'}); this.popup.close(); - this.verifyMessage({message, state}); + this.utils.verifyMessage({message, state}); let authCode = message.data.code; - return await this.exchangeTokens({authCode, codeVerifier, nonce}); - } - - async getUserInfo(accessToken) { - if (typeof accessToken !== 'string') { - throw new AppIDError({description: constants.INVALID_ACCESS_TOKEN}); - } - - return await this.request(this.openIdConfigResource.getUserInfoEndpoint(), { - headers: { - 'Authorization': 'Bearer ' + accessToken - } - }); - } - - getAuthParams({prompt} = {}) { - const codeVerifier = this.utils.getRandomString(constants.CODE_VERIFIER_LENGTH); - const codeChallenge = this.utils.sha256(codeVerifier); - const nonce = this.utils.getRandomString(constants.NONCE_LENGTH); - const state = this.utils.getRandomString(constants.STATE_LENGTH); - - let authParams = { - client_id: this.clientId, - response_type: constants.RESPONSE_TYPE, - state: rs.stob64(state), - code_challenge: rs.stob64(codeChallenge), - code_challenge_method: constants.CHALLENGE_METHOD, - redirect_uri: this.window.origin, - response_mode: constants.RESPONSE_MODE, - nonce, - scope: constants.SCOPE - }; - - if (prompt) { - authParams.prompt = prompt; - } - - const authUrl = this.openIdConfigResource.getAuthorizationEndpoint() + '?' + this.utils.buildParams(authParams); - return { + return await this.utils.exchangeTokens({ + authCode, codeVerifier, nonce, - state, - authUrl - }; - } - - verifyMessage({message, state}) { - if (message.data.error || message.data.error_description) { - throw new AppIDError({description: message.data.error_description, error: message.data.error}); - } - - if (rs.b64utos(message.data.state) !== state) { - throw new AppIDError({description: constants.INVALID_STATE}); - } - let messageOrigin = message.origin; - let oauthOrigin = new this.URL(this.openIdConfigResource.getAuthorizationEndpoint()).origin; - if (messageOrigin !== oauthOrigin) { - throw new AppIDError({description: constants.INVALID_ORIGIN}); - } + windowOrigin: this.window.origin + }); } + /** + * Silent sign in will attempt to authenticate the user in a hidden iframe. + * Sign in will be successful only if there is a Cloud Directory SSO token in the browser. + * You will need to enable SSO on the App ID dashboard. + * Possible errors include: + * User not signed in - there is no Cloud Directory SSO token + * @returns {Promise} - The tokens of the authenticated user. + * e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} + * @throws OAuthError - Any errors from the server. e.g. {error: 'access_denied', description: 'User not signed in'} + * @throws AppIDError "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed. + * @throws TokenError - Any token validation error. + * @throws RequestError - Any errors during a HTTP request. + */ async silentSignin() { - const {codeVerifier, nonce, state, authUrl} = this.getAuthParams({prompt: constants.PROMPT}); + const {codeVerifier, nonce, state, authUrl} = this.utils.getAuthParams(this.clientId, this.window.origin, constants.PROMPT); this.iframe.open(authUrl); @@ -120,52 +115,36 @@ class AppID { } finally { this.iframe.remove(); } - - this.verifyMessage({message, state}); - + this.utils.verifyMessage({message, state}); let authCode = message.data.code; - return await this.exchangeTokens({authCode, codeVerifier, nonce}); - } - async exchangeTokens({authCode, nonce, codeVerifier}) { - let issuer = await this.openIdConfigResource.getIssuer(); - let params = { - grant_type: 'authorization_code', - redirect_uri: this.window.origin, - code: authCode, - code_verifier: codeVerifier - }; - - const requestParams = this.utils.buildParams(params); - const tokenEndpoint = this.openIdConfigResource.getTokenEndpoint(); - - const tokens = await this.request(tokenEndpoint, { - method: 'POST', - headers: { - 'Authorization': 'Basic ' + rs.stob64(`${this.clientId}:${codeVerifier}`), - 'Content-Type': 'application/x-www-form-urlencoded' - }, - body: requestParams - }); - const publicKeys = await this.openIdConfigResource.getPublicKeys(); - - const accessTokenPayload = this.tokenValidator.decodeAndValidate({ - token: tokens.access_token, - publicKeys, - issuer, + return await this.utils.exchangeTokens({ clientId: this.clientId, - nonce + authCode, + codeVerifier, + nonce, + openId: this.openIdConfigResource, + windowOrigin: this.window.origin }); + } - const idTokenPayload = this.tokenValidator.decodeAndValidate({ - token: tokens.id_token, - publicKeys, - issuer, - clientId: this.clientId, - nonce - }); + /** + * This method will made a GET request to the user info endpoint using the access token of the authenticated user. + * @param accessToken - The App ID access token of the user + * @returns {Promise} - The user information for the authenticated user. e.g. {sub: '', email: ''} + * @throws AppIDError "Access token must be a string" - Invalid access token. + * @throws RequestError - Any errors during a HTTP request. + */ + async getUserInfo(accessToken) { + if (typeof accessToken !== 'string') { + throw new AppIDError(constants.INVALID_ACCESS_TOKEN); + } - return {accessToken: tokens.access_token, accessTokenPayload, idToken: tokens.id_token, idTokenPayload} + return await this.request(this.openIdConfigResource.getUserInfoEndpoint(), { + headers: { + 'Authorization': 'Bearer ' + accessToken + } + }); } } diff --git a/src/utils.js b/src/utils.js index 11fe362..93a5cb5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,5 +1,26 @@ const rs = require('jsrsasign'); +const AppIDError = require('./errors/AppIDError'); +const OAuthError = require('./errors/OAuthError'); +const RequestHandler = require('./RequestHandler'); +const TokenValidator = require('./TokenValidator'); +const constants = require('./constants'); + class Utils { + constructor( + { + requestHandler = new RequestHandler(), + tokenValidator = new TokenValidator(), + url = URL, + openId, + clientId + } = {}) { + this.URL = url; + this.request = requestHandler.request; + this.tokenValidator = tokenValidator; + this.openId = openId; + this.clientId = clientId; + }; + buildParams(params) { return Object.keys(params).map(function (key) { return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]); @@ -13,5 +34,93 @@ class Utils { sha256(message) { return rs.KJUR.crypto.Util.sha256(message); } + + getAuthParams(clientId, origin, prompt) { + const codeVerifier = this.getRandomString(constants.CODE_VERIFIER_LENGTH); + const codeChallenge = this.sha256(codeVerifier); + const nonce = this.getRandomString(constants.NONCE_LENGTH); + const state = this.getRandomString(constants.STATE_LENGTH); + this.clientId = clientId; + + let authParams = { + client_id: clientId, + response_type: constants.RESPONSE_TYPE, + state: rs.stob64(state), + code_challenge: rs.stob64(codeChallenge), + code_challenge_method: constants.CHALLENGE_METHOD, + redirect_uri: origin, + response_mode: constants.RESPONSE_MODE, + nonce, + scope: constants.SCOPE + }; + + if (prompt) { + authParams.prompt = prompt; + } + + const authUrl = this.openId.getAuthorizationEndpoint() + '?' + this.buildParams(authParams); + return { + codeVerifier, + nonce, + state, + authUrl + }; + } + + verifyMessage({message, state}) { + if (message.data.error || message.data.error_description) { + throw new OAuthError({description: message.data.error_description, error: message.data.error}); + } + + if (rs.b64utos(message.data.state) !== state) { + throw new AppIDError(constants.INVALID_STATE); + } + + if (message.origin !== new this.URL(this.openId.getAuthorizationEndpoint()).origin) { + throw new AppIDError(constants.INVALID_ORIGIN); + } + } + + async exchangeTokens({authCode, nonce, codeVerifier, windowOrigin}) { + let issuer = this.openId.getIssuer(); + let params = { + grant_type: 'authorization_code', + redirect_uri: windowOrigin, + code: authCode, + code_verifier: codeVerifier + }; + + const requestParams = this.buildParams(params); + const tokenEndpoint = this.openId.getTokenEndpoint(); + + const tokens = await this.request(tokenEndpoint, { + method: 'POST', + headers: { + 'Authorization': 'Basic ' + rs.stob64(`${this.clientId}:${codeVerifier}`), + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: requestParams + }); + const publicKeys = await this.openId.getPublicKeys(); + + const accessTokenPayload = this.tokenValidator.decodeAndValidate({ + token: tokens.access_token, + publicKeys, + issuer, + clientId: this.clientId, + nonce + }); + + const idTokenPayload = this.tokenValidator.decodeAndValidate({ + token: tokens.id_token, + publicKeys, + issuer, + clientId: this.clientId, + nonce + }); + + return {accessToken: tokens.access_token, accessTokenPayload, idToken: tokens.id_token, idTokenPayload}; + } } + module.exports = Utils; \ No newline at end of file diff --git a/test/AppIdTest.js b/test/AppIdTest.js index 2c54fd0..a4aa930 100644 --- a/test/AppIdTest.js +++ b/test/AppIdTest.js @@ -164,7 +164,7 @@ describe('AppID tests', () => { try { let res = await appID.getUserInfo({sub: 1234, iss: 'appid'}); } catch (e) { - assert.equal(e.description, constants.INVALID_ACCESS_TOKEN); + assert.equal(e.message, constants.INVALID_ACCESS_TOKEN); } }); }); diff --git a/test/mocks/UtilsMock.js b/test/mocks/UtilsMock.js index 4759a49..72725a2 100644 --- a/test/mocks/UtilsMock.js +++ b/test/mocks/UtilsMock.js @@ -10,5 +10,23 @@ class UtilsMock { buildParams() { return 'param1=test¶m2=test'; } + + getAuthParams() { + return 'authParams' + } + + verifyMessage() { + return; + } + + exchangeTokens() { + return { + accessToken: 'accessToken', + accessTokenPayload: 'tokenPayload', + idToken: 'idToken', + idTokenPayload: 'tokenPayload' + } + } } + module.exports = UtilsMock; \ No newline at end of file diff --git a/test/utilsTest.js b/test/utilsTest.js index 1b7cb67..b1517f5 100644 --- a/test/utilsTest.js +++ b/test/utilsTest.js @@ -1,10 +1,79 @@ -const assert = require('assert'); +const assert = require('chai').assert; const Utils = require('../src/utils'); -const utils = new Utils(); +const RequestHandler = require('./mocks/RequestHandlerMock'); +const TokenValidator = require('./mocks/TokenValidatorMock'); +const OpenIdConfigurationResource = require('./mocks/OpenIdConfigurationMock'); +const {URL} = require('url'); +const utils = new Utils( + { + requestHandler: new RequestHandler(), + tokenValidator: new TokenValidator(), + openId: new OpenIdConfigurationResource(), + clientId: '1234', + url: URL + }); describe('Utils tests', () => { it('should return a param string', () => { let res = utils.buildParams({param1: 'test', param2: 'test', param3: 'test'}); assert.deepEqual(res, 'param1=test¶m2=test¶m3=test'); }); + + it('should return auth params', () => { + let res = utils.getAuthParams('1234', 'http://origin.com', 'none'); + assert.exists(res.codeVerifier, 'returned code verifier'); + assert.exists(res.nonce, 'returned nonce'); + assert.exists(res.state, 'returned state'); + assert.include(res.authUrl, 'prompt=none'); + }); + + it('should return tokens', async () => { + let params = { + authCode: 'code', + nonce: 'nonce', + codeVerifier: 'verifier', + windowOrigin: 'origin' + }; + let res = await utils.exchangeTokens(params); + assert.equal(res.accessTokenPayload, 'tokenPayload'); + }); + + describe('verify message tests', () => { + const error = { + data: {error: 'error from server'} + }; + + const stateError = { + data: {state: 'invalidState'} + }; + + const originError = { + data: {state: 'dmFsaWRTdGF0ZQ=='}, + origin: 'http://invalidorigin' + }; + + it('should throw error', () => { + try { + utils.verifyMessage({message: error}); + } catch (e) { + assert.equal(e.error, 'error from server'); + } + }); + + it('should throw error - invalid state', () => { + try { + utils.verifyMessage({message: stateError, state: 'validState'}); + } catch (e) { + assert.equal(e.message, 'Invalid state'); + } + }); + + it('should throw error - invalid origin', function () { + try { + utils.verifyMessage({message: originError, state: 'validState', authEndpoint: 'http://validorigin'}); + } catch (e) { + assert.equal(e.message, 'Invalid origin'); + } + }); + }); }); \ No newline at end of file From 868e6c909689d4d259883f3320b7f0994fb0badf Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Thu, 26 Sep 2019 14:56:38 -0500 Subject: [PATCH 02/15] rename signin --- dist/appid.min.js | 2 +- dist/appid.umd.min.js | 2 +- sample/public/index.html | 8 ++++---- src/index.js | 2 +- test/AppIdTest.js | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dist/appid.min.js b/dist/appid.min.js index 16a4523..927a2c9 100644 --- a/dist/appid.min.js +++ b/dist/appid.min.js @@ -40,7 +40,7 @@ function(t,e){for(var i=t.toByteArray(),n=0;ni.length;)i.unshift(0);return i},i=this.getX().toBigInteger(),n=this.getY().toBigInteger(),r=e(i,32);return t?n.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(e(n,32))),r},ut.decodeFrom=function(t,e){e[0];var i=e.length-1,n=e.slice(1,1+i/2),r=e.slice(1+i/2,1+i);n.unshift(0),r.unshift(0);var s=new x(n),a=new x(r);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.decodeFromHex=function(t,e){e.substr(0,2);var i=e.length-2,n=e.substr(2,i/2),r=e.substr(2+i/2,i/2),s=new x(n,16),a=new x(r,16);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.prototype.add2D=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();var e=t.x.subtract(this.x),i=t.y.subtract(this.y).divide(e),n=i.square().subtract(this.x).subtract(t.x),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=this.curve.fromBigInteger(x.valueOf(2)),e=this.curve.fromBigInteger(x.valueOf(3)),i=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),n=i.square().subtract(this.x.multiply(t)),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new x("3")),r=this.negate(),s=this;for(e=n.bitLength()-2;e>0;--e){s=s.twice();var a=n.testBit(e);a!=i.testBit(e)&&(s=s.add2D(a?this:r))}return s},ut.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),i=this.curve.getA().toBigInteger(),n=this.curve.getB().toBigInteger(),r=this.curve.getQ(),s=e.multiply(e).mod(r),a=t.multiply(t).multiply(t).add(i.multiply(t)).add(n).mod(r);return s.equals(a)},ut.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},ut.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),i=this.getY().toBigInteger();if(e.compareTo(x.ONE)<0||e.compareTo(t.subtract(x.ONE))>0)throw new Error("x coordinate out of bounds");if(i.compareTo(x.ONE)<0||i.compareTo(t.subtract(x.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0}; /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval */ -var lt=function(){var t=new RegExp('(?:false|true|null|[\\{\\}\\[\\]]|(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)|(?:"(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))*"))',"g"),e=new RegExp("\\\\(?:([^u])|u(.{4}))","g"),i={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function n(t,e,n){return e?i[e]:String.fromCharCode(parseInt(n,16))}var r=new String(""),s=(Object,Array,Object.hasOwnProperty);return function(i,a){var o,h,u=i.match(t),c=u[0],l=!1;"{"===c?o={}:"["===c?o=[]:(o=[],l=!0);for(var f=[o],d=1-l,g=u.length;d=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map(function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Rt;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map(function(t){return t.replace("/","\\/")})).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Rt;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Rt(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Ht(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),E=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=E,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var w=0;w1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Rt(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Rt(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Rt,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Rt(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(H=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),w=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(H=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(H,0,[2,0],"06"),P=r(H,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var H;S=r(H=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),w=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Ht(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),E=m(t).getEncodedHex(),w="";return w+=Ht(F,"EC PARAMETERS"),w+=Ht(E,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Rt(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e.d=wt(t.d.toString(16)),e.p=wt(t.p.toString(16)),e.q=wt(t.q.toString(16)),e.dp=wt(t.dmp1.toString(16)),e.dq=wt(t.dmq1.toString(16)),e.qi=wt(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e.d=wt(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Rt(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Rt;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=E,e.b64toBA=w,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(w(Et(t)))},e.b64tob64u=Ft,e.b64utob64=Et,e.hex2b64=F,e.hextob64u=wt,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(E(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Ht,e.pemtohex=Rt,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map(function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Rt;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map(function(t){return t.replace("/","\\/")})).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Rt;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Rt(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Ht(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),E=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=E,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var w=0;w1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Rt(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Rt(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Rt,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Rt(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(H=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),w=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(H=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(H,0,[2,0],"06"),P=r(H,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var H;S=r(H=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),w=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Ht(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),E=m(t).getEncodedHex(),w="";return w+=Ht(F,"EC PARAMETERS"),w+=Ht(E,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Rt(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e.d=wt(t.d.toString(16)),e.p=wt(t.p.toString(16)),e.q=wt(t.q.toString(16)),e.dp=wt(t.dmp1.toString(16)),e.dq=wt(t.dmq1.toString(16)),e.qi=wt(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e.d=wt(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Rt(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Rt;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=E,e.b64toBA=w,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(w(Et(t)))},e.b64tob64u=Ft,e.b64utob64=Et,e.hex2b64=F,e.hextob64u=wt,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(E(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Ht,e.pemtohex=Rt,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.expi.length;)i.unshift(0);return i},i=this.getX().toBigInteger(),n=this.getY().toBigInteger(),r=e(i,32);return t?n.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(e(n,32))),r},ut.decodeFrom=function(t,e){e[0];var i=e.length-1,n=e.slice(1,1+i/2),r=e.slice(1+i/2,1+i);n.unshift(0),r.unshift(0);var s=new x(n),a=new x(r);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.decodeFromHex=function(t,e){e.substr(0,2);var i=e.length-2,n=e.substr(2,i/2),r=e.substr(2+i/2,i/2),s=new x(n,16),a=new x(r,16);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.prototype.add2D=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();var e=t.x.subtract(this.x),i=t.y.subtract(this.y).divide(e),n=i.square().subtract(this.x).subtract(t.x),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=this.curve.fromBigInteger(x.valueOf(2)),e=this.curve.fromBigInteger(x.valueOf(3)),i=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),n=i.square().subtract(this.x.multiply(t)),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new x("3")),r=this.negate(),s=this;for(e=n.bitLength()-2;e>0;--e){s=s.twice();var a=n.testBit(e);a!=i.testBit(e)&&(s=s.add2D(a?this:r))}return s},ut.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),i=this.curve.getA().toBigInteger(),n=this.curve.getB().toBigInteger(),r=this.curve.getQ(),s=e.multiply(e).mod(r),a=t.multiply(t).multiply(t).add(i.multiply(t)).add(n).mod(r);return s.equals(a)},ut.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},ut.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),i=this.getY().toBigInteger();if(e.compareTo(x.ONE)<0||e.compareTo(t.subtract(x.ONE))>0)throw new Error("x coordinate out of bounds");if(i.compareTo(x.ONE)<0||i.compareTo(t.subtract(x.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0}; /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval */ -var lt=function(){var t=new RegExp('(?:false|true|null|[\\{\\}\\[\\]]|(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)|(?:"(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))*"))',"g"),e=new RegExp("\\\\(?:([^u])|u(.{4}))","g"),i={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function n(t,e,n){return e?i[e]:String.fromCharCode(parseInt(n,16))}var r=new String(""),s=(Object,Array,Object.hasOwnProperty);return function(i,a){var o,h,u=i.match(t),c=u[0],l=!1;"{"===c?o={}:"["===c?o=[]:(o=[],l=!0);for(var f=[o],d=1-l,g=u.length;d=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map(function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Rt;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map(function(t){return t.replace("/","\\/")})).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Rt;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Rt(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Ht(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),w=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=w,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var E=0;E1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Rt(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Rt(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Rt,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Rt(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(H=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(H,0,[2],"02"),w=r(H,0,[3],"02"),E=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(H=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(H,0,[2,0],"06"),P=r(H,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var H;S=r(H=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(H,0,[2],"02"),w=r(H,0,[3],"02"),E=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Ht(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),w=m(t).getEncodedHex(),E="";return E+=Ht(F,"EC PARAMETERS"),E+=Ht(w,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Rt(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e.d=Et(t.d.toString(16)),e.p=Et(t.p.toString(16)),e.q=Et(t.q.toString(16)),e.dp=Et(t.dmp1.toString(16)),e.dq=Et(t.dmq1.toString(16)),e.qi=Et(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e.d=Et(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Rt(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Rt;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=w,e.b64toBA=E,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(E(wt(t)))},e.b64tob64u=Ft,e.b64utob64=wt,e.hex2b64=F,e.hextob64u=Et,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(w(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Ht,e.pemtohex=Rt,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map(function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Rt;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map(function(t){return t.replace("/","\\/")})).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Rt;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Rt(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Ht(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),w=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=w,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var E=0;E1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Rt(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Rt(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Rt,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Rt(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(H=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(H,0,[2],"02"),w=r(H,0,[3],"02"),E=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(H=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(H,0,[2,0],"06"),P=r(H,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var H;S=r(H=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(H,0,[2],"02"),w=r(H,0,[3],"02"),E=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Ht(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),w=m(t).getEncodedHex(),E="";return E+=Ht(F,"EC PARAMETERS"),E+=Ht(w,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Rt(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e.d=Et(t.d.toString(16)),e.p=Et(t.p.toString(16)),e.q=Et(t.q.toString(16)),e.dp=Et(t.dmp1.toString(16)),e.dq=Et(t.dmq1.toString(16)),e.qi=Et(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e.d=Et(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Rt(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Rt;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=w,e.b64toBA=E,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(E(wt(t)))},e.b64tob64u=Ft,e.b64utob64=wt,e.hex2b64=F,e.hextob64u=Et,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(w(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Ht,e.pemtohex=Rt,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp ``` -cd sample -node server.js + +Or, use the minified files in this repo: +```html + ``` ## Getting Started A simple sample application can be found in the `sample` folder in this repo. -If you want to use our SDK in your existing application, load the script using `script` tags. -``` - -``` - You will need an [IBM Cloud App ID](https://www.ibm.com/cloud/app-id) instance with a `singlepageapp` application created. Use the `clientId` and `discoveryEndpoint` from the application credentials to initialize the `AppID` instance. ```javascript @@ -32,11 +41,69 @@ await appID.init({ }); ``` -## Using Sign In with Popup -```html - -``` -The `signinWithPopup` function will trigger a login widget and return the full access and ID tokens along with its payload. -```javascript -const tokens = await appID.signinWithPopup(); -``` +## init +Initialize AppID + +#### Parameters +- `clientId` **[string][8]** The clientId from the singlepageapp application credentials. +- `discoveryEndpoint` **[string][8]** The discoveryEndpoint from the singlepageapp application credentials. +- `popup` **[Object][7]** (optional) The popup configuration. + + +- Throws **AppIDError** For missing required params. +- Throws **RequestError** Any errors during a HTTP request. + +Returns **[Promise][9]** + +## signin + +This will open a login widget in a popup which will prompt the user to enter their credentials. +After a successful login, the popup will close and tokens are returned. + +- Throws **AppIDError** AppIDError "Popup closed" - The user closed the popup before authentication was completed. +- Throws **TokenError** Any token validation error. +- Throws **OAuthError** Any errors from the server. e.g. {error: 'server_error', description: ''} +- Throws **RequestError** Any errors during a HTTP request. + +Returns **[Promise][9]** The tokens of the authenticated user or an error. +e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} + +## silentSignin + +Silent sign in will attempt to authenticate the user in a hidden iframe. +Sign in will be successful only if there is a Cloud Directory SSO token in the browser. +You will need to enable SSO on the App ID dashboard. +Possible errors include: +User not signed in - there is no Cloud Directory SSO token + +- Throws **OAuthError** Any errors from the server. e.g. {error: 'access_denied', description: 'User not signed in'} +- Throws **AppIDError** "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed. +- Throws **TokenError** Any token validation error. +- Throws **RequestError** Any errors during a HTTP request. + +Returns **[Promise][9]** The tokens of the authenticated user. +e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} + +## getUserInfo + +This method will made a GET request to the user info endpoint using the access token of the authenticated user. + +### Parameters + +- `accessToken` **[string][8]** The App ID access token of the user + + +- Throws **AppIDError** "Access token must be a string" - Invalid access token. +- Throws **RequestError** Any errors during a HTTP request. + +Returns **[Promise][9]** The user information for the authenticated user. e.g. {sub: '', email: ''} + +[1]: #installation +[2]: #getting-started +[3]: #init +[4]: #signin +[5]: #silentsignin +[6]: #getuserinfo +[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise \ No newline at end of file diff --git a/package.json b/package.json index aaf5d60..5c26028 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "scripts": { "build": "webpack", "test": "mocha", - "coverage": "nyc --reporter=lcov mocha" + "coverage": "nyc --reporter=lcov mocha", + "docs": "documentation build src/index.js -f md" }, "repository": { "type": "git", @@ -20,7 +21,8 @@ "exclude": [ "**/PopupController.js", "**/IFrameController.js", - "**/OpenIDConfigurationResource.js" + "**/OpenIDConfigurationResource.js", + "**/constants.js" ] }, "dependencies": { diff --git a/src/index.js b/src/index.js index e13630f..f367186 100644 --- a/src/index.js +++ b/src/index.js @@ -7,15 +7,6 @@ const TokenValidator = require('./TokenValidator'); const constants = require('./constants'); const AppIDError = require('./errors/AppIDError'); -/** - * todo: - * README - detailed desc for each function and errors, params, npm install - * Function comments in index.js - * Move helper functions to different file - * Update tests - * Add popup obj to init - default {height: screen.height * .85, width: 400} - * - */ class AppID { constructor( { @@ -41,12 +32,12 @@ class AppID { /** * Initialize AppID - * @param clientId - The clientId from the singlepageapp application credentials. - * @param discoveryEndpoint - The discoveryEndpoint from the singlepageapp application credentials. - * @param popup - (optional) The popup configuration. - * @returns {Promise} - * @throws AppIDError - For missing required params. - * @throws RequestError - Any errors during a HTTP request. + * @param {string} clientId - The clientId from the singlepageapp application credentials. + * @param {string} discoveryEndpoint - The discoveryEndpoint from the singlepageapp application credentials. + * @param {Object} popup - (optional) The popup configuration. + * @returns {Promise} + * @throws {AppIDError} For missing required params. + * @throws {RequestError} Any errors during a HTTP request. */ async init({clientId, discoveryEndpoint, popup = {height: screen.height * .80, width: 400}}) { if (!clientId) { @@ -64,12 +55,12 @@ class AppID { /** * This will open a login widget in a popup which will prompt the user to enter their credentials. * After a successful login, the popup will close and tokens are returned. - * @returns {Promise<*|tokens|*>} - The tokens of the authenticated user or an error. + * @returns {Promise} - The tokens of the authenticated user or an error. * e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} - * @throws AppIDError "Popup closed" - The user closed the popup before authentication was completed. - * @throws TokenError - Any token validation error. - * @throws OAuthError - Any errors from the server. e.g. {error: 'server_error', description: ''} - * @throws RequestError - Any errors during a HTTP request. + * @throws {AppIDError}AppIDError "Popup closed" - The user closed the popup before authentication was completed. + * @throws {TokenError} - Any token validation error. + * @throws {OAuthError} - Any errors from the server. e.g. {error: 'server_error', description: ''} + * @throws {RequestError} - Any errors during a HTTP request. */ async signin() { const {codeVerifier, nonce, state, authUrl} = this.utils.getAuthParams(this.clientId, this.window.origin); @@ -97,12 +88,12 @@ class AppID { * You will need to enable SSO on the App ID dashboard. * Possible errors include: * User not signed in - there is no Cloud Directory SSO token - * @returns {Promise} - The tokens of the authenticated user. + * @returns {Promise} - The tokens of the authenticated user. * e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} - * @throws OAuthError - Any errors from the server. e.g. {error: 'access_denied', description: 'User not signed in'} - * @throws AppIDError "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed. - * @throws TokenError - Any token validation error. - * @throws RequestError - Any errors during a HTTP request. + * @throws {OAuthError} - Any errors from the server. e.g. {error: 'access_denied', description: 'User not signed in'} + * @throws {AppIDError} "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed. + * @throws {TokenError} - Any token validation error. + * @throws {RequestError} - Any errors during a HTTP request. */ async silentSignin() { const {codeVerifier, nonce, state, authUrl} = this.utils.getAuthParams(this.clientId, this.window.origin, constants.PROMPT); @@ -130,10 +121,10 @@ class AppID { /** * This method will made a GET request to the user info endpoint using the access token of the authenticated user. - * @param accessToken - The App ID access token of the user - * @returns {Promise} - The user information for the authenticated user. e.g. {sub: '', email: ''} - * @throws AppIDError "Access token must be a string" - Invalid access token. - * @throws RequestError - Any errors during a HTTP request. + * @param {string} accessToken - The App ID access token of the user + * @returns {Promise} - The user information for the authenticated user. e.g. {sub: '', email: ''} + * @throws {AppIDError} "Access token must be a string" - Invalid access token. + * @throws {RequestError} - Any errors during a HTTP request. */ async getUserInfo(accessToken) { if (typeof accessToken !== 'string') { diff --git a/test/mocks/UtilsMock.js b/test/mocks/UtilsMock.js index 72725a2..a68cb45 100644 --- a/test/mocks/UtilsMock.js +++ b/test/mocks/UtilsMock.js @@ -12,7 +12,7 @@ class UtilsMock { } getAuthParams() { - return 'authParams' + return 'authParams'; } verifyMessage() { @@ -25,7 +25,7 @@ class UtilsMock { accessTokenPayload: 'tokenPayload', idToken: 'idToken', idTokenPayload: 'tokenPayload' - } + }; } } From 14099e3223c2f7e81b95801d23b4bbc5fba84cf7 Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Thu, 26 Sep 2019 15:59:20 -0500 Subject: [PATCH 04/15] update readme --- README.md | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4af37d9..3239a64 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ Client-side javascript SDK for the IBM Cloud App ID service. - [Installation][1] - [Getting Started][2] -- [Documentation][3] - - [init][3] - - [signin][4] - - [silentSignin][5] - - [getUserInfo][6] +- [API Reference][3] + - [init][4] + - [signin][5] + - [silentSignin][6] + - [getUserInfo][7] ## Installation Using npm ```javascript @@ -40,20 +40,31 @@ await appID.init({ discoveryEndpoint: '' }); ``` +Using the signin() in your app to start authentication: +```javascript +document.getElementById('login').addEventListener('click', async () => { + try { + const tokens = await appID.signin(); + } catch (e) { + ... + } +}); +``` +## API Reference ## init Initialize AppID #### Parameters -- `clientId` **[string][8]** The clientId from the singlepageapp application credentials. -- `discoveryEndpoint` **[string][8]** The discoveryEndpoint from the singlepageapp application credentials. -- `popup` **[Object][7]** (optional) The popup configuration. +- `clientId` **[string][9]** The clientId from the singlepageapp application credentials. +- `discoveryEndpoint` **[string][9]** The discoveryEndpoint from the singlepageapp application credentials. +- `popup` **[Object][8]** (optional) The popup configuration. - Throws **AppIDError** For missing required params. - Throws **RequestError** Any errors during a HTTP request. -Returns **[Promise][9]** +Returns **[Promise][10]** ## signin @@ -65,7 +76,7 @@ After a successful login, the popup will close and tokens are returned. - Throws **OAuthError** Any errors from the server. e.g. {error: 'server_error', description: ''} - Throws **RequestError** Any errors during a HTTP request. -Returns **[Promise][9]** The tokens of the authenticated user or an error. +Returns **[Promise][10]** The tokens of the authenticated user or an error. e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} ## silentSignin @@ -81,7 +92,7 @@ User not signed in - there is no Cloud Directory SSO token - Throws **TokenError** Any token validation error. - Throws **RequestError** Any errors during a HTTP request. -Returns **[Promise][9]** The tokens of the authenticated user. +Returns **[Promise][10]** The tokens of the authenticated user. e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} ## getUserInfo @@ -90,20 +101,21 @@ This method will made a GET request to the user info endpoint using the access t ### Parameters -- `accessToken` **[string][8]** The App ID access token of the user +- `accessToken` **[string][9]** The App ID access token of the user - Throws **AppIDError** "Access token must be a string" - Invalid access token. - Throws **RequestError** Any errors during a HTTP request. -Returns **[Promise][9]** The user information for the authenticated user. e.g. {sub: '', email: ''} +Returns **[Promise][10]** The user information for the authenticated user. e.g. {sub: '', email: ''} [1]: #installation [2]: #getting-started -[3]: #init -[4]: #signin -[5]: #silentsignin -[6]: #getuserinfo -[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise \ No newline at end of file +[3]: #api-reference +[4]: #init +[5]: #signin +[6]: #silentsignin +[7]: #getuserinfo +[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise \ No newline at end of file From 00d23d0852b9ccd789ca9db5d5291b15507012ce Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Thu, 26 Sep 2019 16:16:19 -0500 Subject: [PATCH 05/15] update --- README.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3239a64..04b50b3 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,22 @@ document.getElementById('login').addEventListener('click', async () => { ## init Initialize AppID -#### Parameters -- `clientId` **[string][9]** The clientId from the singlepageapp application credentials. -- `discoveryEndpoint` **[string][9]** The discoveryEndpoint from the singlepageapp application credentials. -- `popup` **[Object][8]** (optional) The popup configuration. +### Parameters +- `options` **[Object][8]** + - `options.clientId` **[string][9]** The clientId from the singlepageapp application credentials. + - `options.discoveryEndpoint` **[string][9]** The discoveryEndpoint from the singlepageapp application credentials. + - `options.popup` **[Object][8]** The popup configuration. (optional, default `{height:screen.height*.80,width:400}`) + - `options.popup.height` **[Number][11]** The popup height. + - `options.popup.width` **[Number][11]** The popup width. + +### Example +```javascript +await appID.init({ + clientId: '', + discoveryEndpoint: '' +}); +``` - Throws **AppIDError** For missing required params. - Throws **RequestError** Any errors during a HTTP request. @@ -118,4 +129,5 @@ Returns **[Promise][10]** The user information for the authenticated user. e.g. [7]: #getuserinfo [8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise \ No newline at end of file +[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise +[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number \ No newline at end of file From d994e67b605b587d4acf7e824620fcd68a9f97ab Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Thu, 26 Sep 2019 16:17:12 -0500 Subject: [PATCH 06/15] updates --- src/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index f367186..b6793ee 100644 --- a/src/index.js +++ b/src/index.js @@ -32,12 +32,21 @@ class AppID { /** * Initialize AppID - * @param {string} clientId - The clientId from the singlepageapp application credentials. - * @param {string} discoveryEndpoint - The discoveryEndpoint from the singlepageapp application credentials. - * @param {Object} popup - (optional) The popup configuration. + * @param {Object} options + * @param {string} options.clientId - The clientId from the singlepageapp application credentials. + * @param {string} options.discoveryEndpoint - The discoveryEndpoint from the singlepageapp application credentials. + * @param {Object} options.popup - The popup configuration. + * @param {Number} options.popup.height - The popup height. + * @param {Number} options.popup.width - The popup width. * @returns {Promise} * @throws {AppIDError} For missing required params. * @throws {RequestError} Any errors during a HTTP request. + * @example + * await appID.init({ + * clientId: '', + * discoveryEndpoint: '' + * }); + * */ async init({clientId, discoveryEndpoint, popup = {height: screen.height * .80, width: 400}}) { if (!clientId) { From 5c646790960ceab74d0aec3d575d3020c02927c5 Mon Sep 17 00:00:00 2001 From: Tal Aviel Date: Thu, 26 Sep 2019 16:40:10 -0500 Subject: [PATCH 07/15] docs --- package-lock.json | 148 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- 2 files changed, 150 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 23431ef..2c0f8b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2069,6 +2069,15 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", "dev": true }, + "catharsis": { + "version": "0.8.11", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/catharsis/-/catharsis-0.8.11.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fcatharsis%2F-%2Fcatharsis-0.8.11.tgz", + "integrity": "sha1-0Os9K4K32no84u+xp7AL7MZkNGg=", + "dev": true, + "requires": { + "lodash": "^4.17.14" + } + }, "chai": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", @@ -2576,6 +2585,12 @@ "randombytes": "^2.0.0" } }, + "docdash": { + "version": "1.1.1", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/docdash/-/docdash-1.1.1.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fdocdash%2F-%2Fdocdash-1.1.1.tgz", + "integrity": "sha1-iZJOV5ODiPw9H6kAknrPztfzsk8=", + "dev": true + }, "domain-browser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/domain-browser/-/domain-browser-1.2.0.tgz", @@ -2657,6 +2672,12 @@ "tapable": "^1.0.0" } }, + "entities": { + "version": "1.1.2", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/entities/-/entities-1.1.2.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fentities%2F-%2Fentities-1.1.2.tgz", + "integrity": "sha1-vfpzUplmTfr9NFKe1PhSKidf6lY=", + "dev": true + }, "errno": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz", @@ -4524,12 +4545,57 @@ "esprima": "^4.0.0" } }, + "js2xmlparser": { + "version": "4.0.0", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/js2xmlparser/-/js2xmlparser-4.0.0.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fjs2xmlparser%2F-%2Fjs2xmlparser-4.0.0.tgz", + "integrity": "sha1-rhTMcRsokgg+7W4hn7yZPYWLw6U=", + "dev": true, + "requires": { + "xmlcreate": "^2.0.0" + } + }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", "dev": true }, + "jsdoc": { + "version": "3.6.3", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/jsdoc/-/jsdoc-3.6.3.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fjsdoc%2F-%2Fjsdoc-3.6.3.tgz", + "integrity": "sha1-3M6pfQ5i1j0wa4s+0VJxc7XiGQ0=", + "dev": true, + "requires": { + "@babel/parser": "^7.4.4", + "bluebird": "^3.5.4", + "catharsis": "^0.8.11", + "escape-string-regexp": "^2.0.0", + "js2xmlparser": "^4.0.0", + "klaw": "^3.0.0", + "markdown-it": "^8.4.2", + "markdown-it-anchor": "^5.0.2", + "marked": "^0.7.0", + "mkdirp": "^0.5.1", + "requizzle": "^0.2.3", + "strip-json-comments": "^3.0.1", + "taffydb": "2.6.2", + "underscore": "~1.9.1" + }, + "dependencies": { + "escape-string-regexp": { + "version": "2.0.0", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fescape-string-regexp%2F-%2Fescape-string-regexp-2.0.0.tgz", + "integrity": "sha1-owME6Z2qMuI7L9IPUbq9B8/8o0Q=", + "dev": true + }, + "strip-json-comments": { + "version": "3.0.1", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/strip-json-comments/-/strip-json-comments-3.0.1.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fstrip-json-comments%2F-%2Fstrip-json-comments-3.0.1.tgz", + "integrity": "sha1-hXE5dakfuHvxswXMp3OV5A0qZKc=", + "dev": true + } + } + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -4600,6 +4666,15 @@ "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", "dev": true }, + "klaw": { + "version": "3.0.0", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/klaw/-/klaw-3.0.0.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fklaw%2F-%2Fklaw-3.0.0.tgz", + "integrity": "sha1-sRvsnPJJLwZ1bW6Amrc6KRAlkUY=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.9" + } + }, "lcid": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", @@ -4615,6 +4690,15 @@ "integrity": "sha1-GwuP+ayceIklBYK3C3ExXZ2m2aM=", "dev": true }, + "linkify-it": { + "version": "2.2.0", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/linkify-it/-/linkify-it-2.2.0.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Flinkify-it%2F-%2Flinkify-it-2.2.0.tgz", + "integrity": "sha1-47VGl+eL+RXHCjis14/QngBYsc8=", + "dev": true, + "requires": { + "uc.micro": "^1.0.1" + } + }, "load-json-file": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz", @@ -4765,6 +4849,31 @@ "object-visit": "^1.0.0" } }, + "markdown-it": { + "version": "8.4.2", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/markdown-it/-/markdown-it-8.4.2.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fmarkdown-it%2F-%2Fmarkdown-it-8.4.2.tgz", + "integrity": "sha1-OG+YmY3BWjdyKqdyIIT0Agvdm1Q=", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "entities": "~1.1.1", + "linkify-it": "^2.0.0", + "mdurl": "^1.0.1", + "uc.micro": "^1.0.5" + } + }, + "markdown-it-anchor": { + "version": "5.2.4", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/markdown-it-anchor/-/markdown-it-anchor-5.2.4.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fmarkdown-it-anchor%2F-%2Fmarkdown-it-anchor-5.2.4.tgz", + "integrity": "sha1-05MG/kwZlwW0R50wNoQs803Lok8=", + "dev": true + }, + "marked": { + "version": "0.7.0", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/marked/-/marked-0.7.0.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fmarked%2F-%2Fmarked-0.7.0.tgz", + "integrity": "sha1-tkIB8FHScbHtwQoE0a6bdLuOXA4=", + "dev": true + }, "math-random": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.4.tgz", @@ -4782,6 +4891,12 @@ "safe-buffer": "^5.1.2" } }, + "mdurl": { + "version": "1.0.1", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/mdurl/-/mdurl-1.0.1.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fmdurl%2F-%2Fmdurl-1.0.1.tgz", + "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=", + "dev": true + }, "mem": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", @@ -5986,6 +6101,15 @@ "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "dev": true }, + "requizzle": { + "version": "0.2.3", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/requizzle/-/requizzle-0.2.3.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Frequizzle%2F-%2Frequizzle-0.2.3.tgz", + "integrity": "sha1-RnXJCqyvssA2vTm6LapKHLd3/e0=", + "dev": true, + "requires": { + "lodash": "^4.17.14" + } + }, "resolve": { "version": "1.12.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", @@ -6575,6 +6699,12 @@ "has-flag": "^3.0.0" } }, + "taffydb": { + "version": "2.6.2", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/taffydb/-/taffydb-2.6.2.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Ftaffydb%2F-%2Ftaffydb-2.6.2.tgz", + "integrity": "sha1-fLy2S1oUG2ou/CxdLGe04VCyomg=", + "dev": true + }, "tapable": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/tapable/-/tapable-1.1.3.tgz", @@ -6773,6 +6903,12 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "uc.micro": { + "version": "1.0.6", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/uc.micro/-/uc.micro-1.0.6.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fuc.micro%2F-%2Fuc.micro-1.0.6.tgz", + "integrity": "sha1-nEEagCpAmpH8bPdAgbq6NLJEmaw=", + "dev": true + }, "uglify-js": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", @@ -6793,6 +6929,12 @@ } } }, + "underscore": { + "version": "1.9.1", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/underscore/-/underscore-1.9.1.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Funderscore%2F-%2Funderscore-1.9.1.tgz", + "integrity": "sha1-BtzjSg5op7q8KbNluOdLiSUgOWE=", + "dev": true + }, "unicode-canonical-property-names-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz", @@ -7277,6 +7419,12 @@ "signal-exit": "^3.0.2" } }, + "xmlcreate": { + "version": "2.0.1", + "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/xmlcreate/-/xmlcreate-2.0.1.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fxmlcreate%2F-%2Fxmlcreate-2.0.1.tgz", + "integrity": "sha1-LsOL17cI0hP9GpDiQxxK+cCfalI=", + "dev": true + }, "xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/package.json b/package.json index 5c26028..204eefc 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "build": "webpack", "test": "mocha", "coverage": "nyc --reporter=lcov mocha", - "docs": "documentation build src/index.js -f md" + "docs": "jsdoc src/index.js -t node_modules/docdash --readme README.md --destination doc" }, "repository": { "type": "git", @@ -26,6 +26,7 @@ ] }, "dependencies": { + "docdash": "^1.1.1", "jsrsasign": "^8.0.12" }, "devDependencies": { From 5b45147c8327cb0188841d0aecec78596a6ec878 Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Thu, 26 Sep 2019 16:46:13 -0500 Subject: [PATCH 08/15] clean up docs --- README.md | 19 +++++++++++++------ package.json | 5 +++-- src/index.js | 35 +++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 04b50b3..e4bca89 100644 --- a/README.md +++ b/README.md @@ -82,21 +82,30 @@ Returns **[Promise][10]** This will open a login widget in a popup which will prompt the user to enter their credentials. After a successful login, the popup will close and tokens are returned. +### Example + +```javascript +const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.signin(); +``` + - Throws **AppIDError** AppIDError "Popup closed" - The user closed the popup before authentication was completed. - Throws **TokenError** Any token validation error. - Throws **OAuthError** Any errors from the server. e.g. {error: 'server_error', description: ''} - Throws **RequestError** Any errors during a HTTP request. Returns **[Promise][10]** The tokens of the authenticated user or an error. -e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} ## silentSignin Silent sign in will attempt to authenticate the user in a hidden iframe. Sign in will be successful only if there is a Cloud Directory SSO token in the browser. You will need to enable SSO on the App ID dashboard. -Possible errors include: -User not signed in - there is no Cloud Directory SSO token + +### Example + +```javascript +const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.silentSignin(); +``` - Throws **OAuthError** Any errors from the server. e.g. {error: 'access_denied', description: 'User not signed in'} - Throws **AppIDError** "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed. @@ -104,7 +113,6 @@ User not signed in - there is no Cloud Directory SSO token - Throws **RequestError** Any errors during a HTTP request. Returns **[Promise][10]** The tokens of the authenticated user. -e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} ## getUserInfo @@ -114,11 +122,10 @@ This method will made a GET request to the user info endpoint using the access t - `accessToken` **[string][9]** The App ID access token of the user - - Throws **AppIDError** "Access token must be a string" - Invalid access token. - Throws **RequestError** Any errors during a HTTP request. -Returns **[Promise][10]** The user information for the authenticated user. e.g. {sub: '', email: ''} +Returns **[Promise][10]** The user information for the authenticated user. Example: {sub: '', email: ''} [1]: #installation [2]: #getting-started diff --git a/package.json b/package.json index 204eefc..4535696 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ ] }, "dependencies": { - "docdash": "^1.1.1", "jsrsasign": "^8.0.12" }, "devDependencies": { @@ -42,6 +41,8 @@ "mocha": "^6.2.0", "nyc": "^14.1.1", "webpack": "^4.39.1", - "webpack-cli": "^3.3.6" + "webpack-cli": "^3.3.6", + "docdash": "^1.1.1", + "jsdoc": "^3.6.3" } } diff --git a/src/index.js b/src/index.js index b6793ee..15705f4 100644 --- a/src/index.js +++ b/src/index.js @@ -7,6 +7,9 @@ const TokenValidator = require('./TokenValidator'); const constants = require('./constants'); const AppIDError = require('./errors/AppIDError'); +/** + * Client-side javascript SDK for the IBM Cloud App ID service. + */ class AppID { constructor( { @@ -64,12 +67,13 @@ class AppID { /** * This will open a login widget in a popup which will prompt the user to enter their credentials. * After a successful login, the popup will close and tokens are returned. - * @returns {Promise} - The tokens of the authenticated user or an error. - * e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} - * @throws {AppIDError}AppIDError "Popup closed" - The user closed the popup before authentication was completed. - * @throws {TokenError} - Any token validation error. - * @throws {OAuthError} - Any errors from the server. e.g. {error: 'server_error', description: ''} - * @throws {RequestError} - Any errors during a HTTP request. + * @returns {Promise} The tokens of the authenticated user or an error. + * @throws {AppIDError} "Popup closed" - The user closed the popup before authentication was completed. + * @throws {TokenError} Any token validation error. + * @throws {OAuthError} Any errors from the server. e.g. {error: 'server_error', description: ''} + * @throws {RequestError} Any errors during a HTTP request. + * @example + * const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.signin(); */ async signin() { const {codeVerifier, nonce, state, authUrl} = this.utils.getAuthParams(this.clientId, this.window.origin); @@ -95,14 +99,13 @@ class AppID { * Silent sign in will attempt to authenticate the user in a hidden iframe. * Sign in will be successful only if there is a Cloud Directory SSO token in the browser. * You will need to enable SSO on the App ID dashboard. - * Possible errors include: - * User not signed in - there is no Cloud Directory SSO token - * @returns {Promise} - The tokens of the authenticated user. - * e.g. {accessToken: 'eyg...', accessTokenPayload: { iss: 'https...' }, idToken: 'eyg...', idTokenPayload: { email: 'example@gmail.com' }} - * @throws {OAuthError} - Any errors from the server. e.g. {error: 'access_denied', description: 'User not signed in'} + * @returns {Promise} The tokens of the authenticated user. + * @throws {OAuthError} Any errors from the server. e.g. {error: 'access_denied', description: 'User not signed in'} * @throws {AppIDError} "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed. - * @throws {TokenError} - Any token validation error. - * @throws {RequestError} - Any errors during a HTTP request. + * @throws {TokenError} Any token validation error. + * @throws {RequestError} Any errors during a HTTP request. + * @example + * const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.silentSignin(); */ async silentSignin() { const {codeVerifier, nonce, state, authUrl} = this.utils.getAuthParams(this.clientId, this.window.origin, constants.PROMPT); @@ -131,9 +134,9 @@ class AppID { /** * This method will made a GET request to the user info endpoint using the access token of the authenticated user. * @param {string} accessToken - The App ID access token of the user - * @returns {Promise} - The user information for the authenticated user. e.g. {sub: '', email: ''} - * @throws {AppIDError} "Access token must be a string" - Invalid access token. - * @throws {RequestError} - Any errors during a HTTP request. + * @returns {Promise} The user information for the authenticated user. Example: {sub: '', email: ''} + * @throws {AppIDError} "Access token must be a string" Invalid access token. + * @throws {RequestError} Any errors during a HTTP request. */ async getUserInfo(accessToken) { if (typeof accessToken !== 'string') { From 4e06e9d43ba31c388b638ab3bcdaf2e0d211e926 Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Thu, 26 Sep 2019 17:06:20 -0500 Subject: [PATCH 09/15] add init tests --- dist/appid.min.js | 12 ++++----- dist/appid.umd.min.js | 14 +++++------ src/index.js | 2 +- test/AppIdTest.js | 35 ++++++++++++++++++++++++++- test/mocks/OpenIdConfigurationMock.js | 4 +++ 5 files changed, 52 insertions(+), 15 deletions(-) diff --git a/dist/appid.min.js b/dist/appid.min.js index 927a2c9..3adf3df 100644 --- a/dist/appid.min.js +++ b/dist/appid.min.js @@ -14,16 +14,16 @@ if(void 0===r)var r={};r.lang={extend:function(t,e,n){if(!e||!t)throw new Error( * https://code.google.com/p/crypto-js/issues/detail?id=84 * https://crypto-js.googlecode.com/svn-history/r667/branches/3.x/src/core.js */ -var s,a,o,h,u,c,l,f,d,g,p,y=y||(s=Math,o=(a={}).lib={},h=o.Base=function(){function t(){}return{extend:function(e){t.prototype=this;var i=new t;return e&&i.mixIn(e),i.hasOwnProperty("init")||(i.init=function(){i.$super.init.apply(this,arguments)}),i.init.prototype=i,i.$super=this,i},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),u=o.WordArray=h.extend({init:function(t,e){t=this.words=t||[],this.sigBytes=null!=e?e:4*t.length},toString:function(t){return(t||l).stringify(this)},concat:function(t){var e=this.words,i=t.words,n=this.sigBytes,r=t.sigBytes;if(this.clamp(),n%4)for(var s=0;s>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],E=d[F],w=257*d[m]^16843008*m;s[p]=w<<24|w>>>8,a[p]=w<<16|w>>>16,o[p]=w<<8|w>>>24,h[p]=w,w=16843009*E^65537*F^257*S^16843008*p,u[m]=w<<24|w>>>8,c[m]=w<<16|w>>>16,l[m]=w<<8|w>>>24,f[m]=w,p?(p=S^d[d[d[E^S]]],v^=d[d[v]]):p=v=1}var x=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=x[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],E=t[s+13],w=t[s+14],x=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,E,12,u[13]),I=e(I,A,b,C,w,17,u[14]),b=i(b,C=e(C,I,A,b,x,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,x,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,w,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,E,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,w,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,E,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,x,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,w,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,x,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,E,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,E=h.low,w=u.high,x=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,H=p,R=y,B=v,N=m,O=S,j=F,V=E,L=w,_=x,K=b,M=A,k=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&K,Q=V&_^~V&M,z=D&P^D&R^P&R;var tt=T&H^T&B^H&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=k+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),k=K,U=M,K=L,M=_,L=j,_=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=R,O=B,R=P,B=H,P=D,H=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+H,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+R+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),E=h.low=E+V,h.high=F+j+(E>>>0>>0?1:0),x=u.low=x+_,u.high=w+L+(x>>>0<_>>>0?1:0),A=c.low=A+M,c.high=b+K+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+k+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,E=(n=h.words,u.words),w=r.words,x=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+w[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+x[i]]|0,I=16>i?I+((y^(v|~m))+E[0]):32>i?I+((y&m|v&~m)+E[1]):48>i?I+(((y|~v)^m)+E[2]):64>i?I+((y&v|~y&m)+E[3]):I+((y^v^m)+E[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],E=d[F],w=257*d[m]^16843008*m;s[p]=w<<24|w>>>8,a[p]=w<<16|w>>>16,o[p]=w<<8|w>>>24,h[p]=w,w=16843009*E^65537*F^257*S^16843008*p,u[m]=w<<24|w>>>8,c[m]=w<<16|w>>>16,l[m]=w<<8|w>>>24,f[m]=w,p?(p=S^d[d[d[E^S]]],v^=d[d[v]]):p=v=1}var x=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=x[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],E=t[s+13],w=t[s+14],x=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,E,12,u[13]),I=e(I,A,b,C,w,17,u[14]),b=i(b,C=e(C,I,A,b,x,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,x,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,w,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,E,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,w,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,E,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,x,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,w,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,x,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,E,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,E=h.low,w=u.high,x=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,R=p,H=y,B=v,N=m,O=S,j=F,V=E,L=w,_=x,K=b,M=A,k=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&K,Q=V&_^~V&M,z=D&P^D&H^P&H;var tt=T&R^T&B^R&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=k+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),k=K,U=M,K=L,M=_,L=j,_=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=H,O=B,H=P,B=R,P=D,R=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+R,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+H+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),E=h.low=E+V,h.high=F+j+(E>>>0>>0?1:0),x=u.low=x+_,u.high=w+L+(x>>>0<_>>>0?1:0),A=c.low=A+M,c.high=b+K+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+k+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,E=(n=h.words,u.words),w=r.words,x=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+w[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+x[i]]|0,I=16>i?I+((y^(v|~m))+E[0]):32>i?I+((y&m|v&~m)+E[1]):48>i?I+(((y|~v)^m)+E[2]):64>i?I+((y&v|~y&m)+E[3]):I+((y^v^m)+E[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function E(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function w(t){var e,i=E(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(x.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(x.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),x.prototype.DB=v,x.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function K(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function M(){}function k(t){return t}function U(t){this.r2=b(),this.q3=b(),x.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(x.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},x.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},x.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},x.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},x.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},x.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},x.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},x.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},x.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),x.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&x.ZERO.subTo(i,i)}}},x.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},x.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},x.prototype.exp=function(t,e){if(t>4294967295||t<1)return x.ONE;var i=b(),n=b(),r=e.convert(this),s=R(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},x.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},x.prototype.negate=function(){var t=b();return x.ZERO.subTo(this,t),t},x.prototype.abs=function(){return this.s<0?this.negate():this},x.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},x.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+R(this[this.t-1]^this.s&this.DM)},x.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(x.ZERO)>0&&t.subTo(e,e),e},x.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},x.ZERO=H(0),x.ONE=H(1),M.prototype.convert=k,M.prototype.revert=k,M.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},M.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; +var v,m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",S="=";function F(t){var e,i,n="";for(e=0;e+3<=t.length;e+=3)i=parseInt(t.substring(e,e+3),16),n+=m.charAt(i>>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function E(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function w(t){var e,i=E(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(x.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(x.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),x.prototype.DB=v,x.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function K(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function M(){}function k(t){return t}function U(t){this.r2=b(),this.q3=b(),x.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(x.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},x.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},x.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},x.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},x.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},x.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},x.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},x.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},x.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),x.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&x.ZERO.subTo(i,i)}}},x.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},x.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},x.prototype.exp=function(t,e){if(t>4294967295||t<1)return x.ONE;var i=b(),n=b(),r=e.convert(this),s=H(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},x.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},x.prototype.negate=function(){var t=b();return x.ZERO.subTo(this,t),t},x.prototype.abs=function(){return this.s<0?this.negate():this},x.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},x.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+H(this[this.t-1]^this.s&this.DM)},x.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(x.ZERO)>0&&t.subTo(e,e),e},x.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},x.ZERO=R(0),x.ONE=R(1),M.prototype.convert=k,M.prototype.revert=k,M.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},M.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ -function Y(){this.i=0,this.j=0,this.S=new Array}x.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},x.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),n=H(i),r=b(),s=b(),a="";for(this.divRemTo(n,r,s);r.signum()>0;)a=(i+s.intValue()).toString(t).substr(1)+a,r.divRemTo(n,r,s);return s.intValue().toString(t)+a},x.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),n=Math.pow(e,i),r=!1,s=0,a=0,o=0;o=i&&(this.dMultiply(n),this.dAddOffset(a,0),s=0,a=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(a,0)),r&&x.ZERO.subTo(this,this)},x.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(x.ONE.shiftLeft(t-1),j,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(x.ONE.shiftLeft(t-1),this);else{var n=new Array,r=7&t;n.length=1+(t>>3),e.nextBytes(n),r>0?n[0]&=(1<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[i++]=n:n<-1&&(e[i++]=this.DV+n),e.t=i,e.clamp()},x.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},x.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},x.prototype.multiplyLowerTo=function(t,e,i){var n,r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;r>0;)i[--r]=0;for(n=i.t-this.t;r=0;)i[n]=0;for(n=Math.max(e-this.t,0);n0)if(0==e)i=this[0]%t;else for(var n=this.t-1;n>=0;--n)i=(e*i+this[n])%t;return i},x.prototype.millerRabin=function(t){var e=this.subtract(x.ONE),i=e.getLowestSetBit();if(i<=0)return!1;var n=e.shiftRight(i);(t=t+1>>1)>q.length&&(t=q.length);for(var r=b(),s=0;s36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),n=R(i),r=b(),s=b(),a="";for(this.divRemTo(n,r,s);r.signum()>0;)a=(i+s.intValue()).toString(t).substr(1)+a,r.divRemTo(n,r,s);return s.intValue().toString(t)+a},x.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),n=Math.pow(e,i),r=!1,s=0,a=0,o=0;o=i&&(this.dMultiply(n),this.dAddOffset(a,0),s=0,a=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(a,0)),r&&x.ZERO.subTo(this,this)},x.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(x.ONE.shiftLeft(t-1),j,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(x.ONE.shiftLeft(t-1),this);else{var n=new Array,r=7&t;n.length=1+(t>>3),e.nextBytes(n),r>0?n[0]&=(1<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[i++]=n:n<-1&&(e[i++]=this.DV+n),e.t=i,e.clamp()},x.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},x.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},x.prototype.multiplyLowerTo=function(t,e,i){var n,r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;r>0;)i[--r]=0;for(n=i.t-this.t;r=0;)i[n]=0;for(n=Math.max(e-this.t,0);n0)if(0==e)i=this[0]%t;else for(var n=this.t-1;n>=0;--n)i=(e*i+this[n])%t;return i},x.prototype.millerRabin=function(t){var e=this.subtract(x.ONE),i=e.getLowestSetBit();if(i<=0)return!1;var n=e.shiftRight(i);(t=t+1>>1)>q.length&&(t=q.length);for(var r=b(),s=0;s>24},x.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},x.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},x.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},x.prototype.equals=function(t){return 0==this.compareTo(t)},x.prototype.min=function(t){return this.compareTo(t)<0?this:t},x.prototype.max=function(t){return this.compareTo(t)>0?this:t},x.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},x.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},x.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},x.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},x.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=R(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(x.ONE)?x.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},x.prototype.pow=function(t){return this.exp(t,new M)},x.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},x.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>24},x.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},x.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},x.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},x.prototype.equals=function(t){return 0==this.compareTo(t)},x.prototype.min=function(t){return this.compareTo(t)<0?this:t},x.prototype.max=function(t){return this.compareTo(t)>0?this:t},x.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},x.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},x.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},x.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},x.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=H(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(x.ONE)?x.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},x.prototype.pow=function(t){return this.exp(t,new M)},x.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},x.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>8&255,J[W++]^=t>>16&255,J[W++]^=t>>24&255,W>=X&&(W-=X)}((new Date).getTime())}if(null==J){var $;if(J=new Array,W=0,void 0!==n&&(void 0!==n.crypto||void 0!==n.msCrypto)){var Q=n.crypto||n.msCrypto;if(Q.getRandomValues){var tt=new Uint8Array(32);for(Q.getRandomValues(tt),$=0;$<32;++$)J[W++]=tt[$]}else if("Netscape"==i.appName&&i.appVersion<"5"){var et=n.crypto.random(32);for($=0;$>>8,J[W++]=255&$;W=0,Z()}function it(){if(null==G){for(Z(),(G=new Y).init(J),W=0;Wi.length;)i.unshift(0);return i},i=this.getX().toBigInteger(),n=this.getY().toBigInteger(),r=e(i,32);return t?n.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(e(n,32))),r},ut.decodeFrom=function(t,e){e[0];var i=e.length-1,n=e.slice(1,1+i/2),r=e.slice(1+i/2,1+i);n.unshift(0),r.unshift(0);var s=new x(n),a=new x(r);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.decodeFromHex=function(t,e){e.substr(0,2);var i=e.length-2,n=e.substr(2,i/2),r=e.substr(2+i/2,i/2),s=new x(n,16),a=new x(r,16);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.prototype.add2D=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();var e=t.x.subtract(this.x),i=t.y.subtract(this.y).divide(e),n=i.square().subtract(this.x).subtract(t.x),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=this.curve.fromBigInteger(x.valueOf(2)),e=this.curve.fromBigInteger(x.valueOf(3)),i=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),n=i.square().subtract(this.x.multiply(t)),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new x("3")),r=this.negate(),s=this;for(e=n.bitLength()-2;e>0;--e){s=s.twice();var a=n.testBit(e);a!=i.testBit(e)&&(s=s.add2D(a?this:r))}return s},ut.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),i=this.curve.getA().toBigInteger(),n=this.curve.getB().toBigInteger(),r=this.curve.getQ(),s=e.multiply(e).mod(r),a=t.multiply(t).multiply(t).add(i.multiply(t)).add(n).mod(r);return s.equals(a)},ut.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},ut.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),i=this.getY().toBigInteger();if(e.compareTo(x.ONE)<0||e.compareTo(t.subtract(x.ONE))>0)throw new Error("x coordinate out of bounds");if(i.compareTo(x.ONE)<0||i.compareTo(t.subtract(x.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0}; /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval */ -var lt=function(){var t=new RegExp('(?:false|true|null|[\\{\\}\\[\\]]|(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)|(?:"(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))*"))',"g"),e=new RegExp("\\\\(?:([^u])|u(.{4}))","g"),i={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function n(t,e,n){return e?i[e]:String.fromCharCode(parseInt(n,16))}var r=new String(""),s=(Object,Array,Object.hasOwnProperty);return function(i,a){var o,h,u=i.match(t),c=u[0],l=!1;"{"===c?o={}:"["===c?o=[]:(o=[],l=!0);for(var f=[o],d=1-l,g=u.length;d=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map(function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Rt;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map(function(t){return t.replace("/","\\/")})).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Rt;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Rt(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Ht(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),E=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=E,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var w=0;w1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Rt(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Rt(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Rt,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Rt(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(H=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),w=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(H=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(H,0,[2,0],"06"),P=r(H,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var H;S=r(H=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(H,0,[2],"02"),E=r(H,0,[3],"02"),w=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Ht(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),E=m(t).getEncodedHex(),w="";return w+=Ht(F,"EC PARAMETERS"),w+=Ht(E,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(E=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Rt(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e.d=wt(t.d.toString(16)),e.p=wt(t.p.toString(16)),e.q=wt(t.q.toString(16)),e.dp=wt(t.dmp1.toString(16)),e.dq=wt(t.dmq1.toString(16)),e.qi=wt(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e.d=wt(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Rt(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Rt;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=E,e.b64toBA=w,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(w(Et(t)))},e.b64tob64u=Ft,e.b64utob64=Et,e.hex2b64=F,e.hextob64u=wt,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(E(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Ht,e.pemtohex=Rt,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map((function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Ht;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map((function(t){return t.replace("/","\\/")}))).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Ht;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Ht(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Rt(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),E=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=E,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var w=0;w1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Ht(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Ht(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Ht,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Ht(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(R=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(R,0,[2],"02"),E=r(R,0,[3],"02"),w=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(R=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(R,0,[2,0],"06"),P=r(R,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var R;S=r(R=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(R,0,[2],"02"),E=r(R,0,[3],"02"),w=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Rt(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),E=m(t).getEncodedHex(),w="";return w+=Rt(F,"EC PARAMETERS"),w+=Rt(E,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(E=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Ht(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e.d=wt(t.d.toString(16)),e.p=wt(t.p.toString(16)),e.q=wt(t.q.toString(16)),e.dp=wt(t.dmp1.toString(16)),e.dq=wt(t.dmq1.toString(16)),e.qi=wt(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e.d=wt(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Ht(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Ht;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=E,e.b64toBA=w,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(w(Et(t)))},e.b64tob64u=Ft,e.b64utob64=Et,e.hex2b64=F,e.hextob64u=wt,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(E(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Rt,e.pemtohex=Ht,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp * @license MIT */ -var n=i(9),r=i(10),s=i(11);function a(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return M(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return k(t).length;default:if(n)return M(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return H(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return E(this,t,e,i);case"latin1":case"binary":return w(this,t,e,i);case"base64":return x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||R(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||R(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||R(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||R(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||R(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||R(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||R(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||R(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||R(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||R(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function k(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(_,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(8))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e){t.exports=class extends Error{constructor({error:t,description:e}){super(e||t),this.error=t,this.description=e}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(17);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){const e=t.height,i=t.width,r=(screen.width-i)/2,s=(screen.height-e)/2;if(this.popup=this.window.open("","popup",`left=${r},top=${s},width=${i},height=${e},resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(19);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}}]); \ No newline at end of file +var n=i(9),r=i(10),s=i(11);function a(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return M(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return k(t).length;default:if(n)return M(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return E(this,t,e,i);case"latin1":case"binary":return w(this,t,e,i);case"base64":return x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||H(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||H(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||H(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||H(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||H(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||H(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||H(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||H(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||H(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||H(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function k(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(_,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(8))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e){t.exports=class extends Error{constructor({error:t,description:e}){super(e||t),this.error=t,this.description=e}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(17);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){const e=t.height,i=t.width,r=(screen.width-i)/2,s=(screen.height-e)/2;if(this.popup=this.window.open("","popup",`left=${r},top=${s},width=${i},height=${e},resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(19);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}}]); \ No newline at end of file diff --git a/dist/appid.umd.min.js b/dist/appid.umd.min.js index ec866e4..c283e6e 100644 --- a/dist/appid.umd.min.js +++ b/dist/appid.umd.min.js @@ -1,4 +1,4 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AppID=e():t.AppID=e()}(window,function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=5)}([function(t,e){t.exports={MALFORMED_TOKEN:"Invalid JWT token. Got only 2 parts.",INVALID_SIGNATURE:"Invalid signature",INVALID_VERSION:"Invalid version",INVALID_ALGORITHM:"Invalid algorithm",INVALID_ISSUER:"Invalid issuer",INVALID_AUDIENCE:"Invalid audience",INVALID_NONCE:"Invalid nonce",EXPIRED_TOKEN:"Expired token",INVALID_STATE:"Invalid state",INVALID_ORIGIN:"Invalid origin",INVALID_TOKEN:"Invalid token",MISSING_PUBLIC_KEY:"Cannot find public key",INVALID_ACCESS_TOKEN:"Access token must be a string",MISSING_CLIENT_ID:"Missing client ID",MISSING_DISCOVERY_ENDPOINT:"Missing discovery endpoint",RESPONSE_TYPE:"code",RESPONSE_MODE:"web_message",PROMPT:"none",SCOPE:"openid",STATE_LENGTH:20,NONCE_LENGTH:20,CODE_VERIFIER_LENGTH:44,CHALLENGE_METHOD:"S256",TOKEN_ALG:"RS256",VERSION:4,MALFORMED_ACCESS_TOKEN:"eyJpc3MiOiJtb2JpbGVjbGllbnRhY2Nlc3Muc3RhZ2UxLm5nLmJsdWVtaXgubmV0IiwiZXhwIjoxNDg3MDg0ODc4LCJhdWQiOiIyNmNiMDEyZWIzMjdjNjEyZDkwYTY4MTkxNjNiNmJjYmQ0ODQ5Y2JiIiwiaWF0IjoxNDg3MDgxMjc4LCJhdXRoX2J5IjoiZmFjZWJvb2siLCJ0ZW5hbnQiOiI0ZGJhOTQzMC01NGU2LTRjZjItYTUxNi02ZjczZmViNzAyYmIiLCJzY29wZSI6ImFwcGlkX2RlZmF1bHQgYXBwaWRfcmVhZHByb2ZpbGUgYXBwaWRfcmVhZHVzZXJhdHRyIGFwcGlkX3dyaXRldXNlcmF0dHIifQ.HHterec250JSDY1965cM2DadBznl2wTKmzKNSnfjpdTAqax9VZvV3EwuFbEnGp9-i6AC-OlsVj7xvbALkdjwG2lZvpQx0M_gRc_3E0NiYuOGVolcm0wEXtbtDUFFqZQAf9BYYOPZ8OintdBiwUGETbH1ZRVtUvt3nalIko1OPE1Q12LvuRlhz5MClNHmvxJcXc7kucxCx4s4UFFy_HJA1gow7HWFqc9-PZf4JMWA-siYqPrdw_zYeBTBzE5co92F6JBEtGLLCjhJVz9eYgLLECXbak3z6hOaY9352Weuj7AgMOWxzw56jKKsiixMtvzrCzLVIcRUG96UJszwPHtPlA",INVALID_SIGNATURE_TOKEN:"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTU2NjMxMDg5NSwiZXhwIjoxNTY2MzE0NDk1LCJpYXQiOjE1NjYzMTA4OTUsImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciIsImF1ZCI6WyJodHRwOi8vZm9vMS5jb20iLCJodHRwOi8vZm9vMi5jb20iXX0.NBDYg8VZxW770qcbIl40OFvaQntO-FVYUUJocE5ZgcyrvFTuomwF997OcEJghO8BE_Y2m67PbfPFsbN0VI6j"}},function(t,e,i){(function(t){var i={userAgent:!1},n={}; +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AppID=e():t.AppID=e()}(window,(function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=5)}([function(t,e){t.exports={MALFORMED_TOKEN:"Invalid JWT token. Got only 2 parts.",INVALID_SIGNATURE:"Invalid signature",INVALID_VERSION:"Invalid version",INVALID_ALGORITHM:"Invalid algorithm",INVALID_ISSUER:"Invalid issuer",INVALID_AUDIENCE:"Invalid audience",INVALID_NONCE:"Invalid nonce",EXPIRED_TOKEN:"Expired token",INVALID_STATE:"Invalid state",INVALID_ORIGIN:"Invalid origin",INVALID_TOKEN:"Invalid token",MISSING_PUBLIC_KEY:"Cannot find public key",INVALID_ACCESS_TOKEN:"Access token must be a string",MISSING_CLIENT_ID:"Missing client ID",MISSING_DISCOVERY_ENDPOINT:"Missing discovery endpoint",RESPONSE_TYPE:"code",RESPONSE_MODE:"web_message",PROMPT:"none",SCOPE:"openid",STATE_LENGTH:20,NONCE_LENGTH:20,CODE_VERIFIER_LENGTH:44,CHALLENGE_METHOD:"S256",TOKEN_ALG:"RS256",VERSION:4,MALFORMED_ACCESS_TOKEN:"eyJpc3MiOiJtb2JpbGVjbGllbnRhY2Nlc3Muc3RhZ2UxLm5nLmJsdWVtaXgubmV0IiwiZXhwIjoxNDg3MDg0ODc4LCJhdWQiOiIyNmNiMDEyZWIzMjdjNjEyZDkwYTY4MTkxNjNiNmJjYmQ0ODQ5Y2JiIiwiaWF0IjoxNDg3MDgxMjc4LCJhdXRoX2J5IjoiZmFjZWJvb2siLCJ0ZW5hbnQiOiI0ZGJhOTQzMC01NGU2LTRjZjItYTUxNi02ZjczZmViNzAyYmIiLCJzY29wZSI6ImFwcGlkX2RlZmF1bHQgYXBwaWRfcmVhZHByb2ZpbGUgYXBwaWRfcmVhZHVzZXJhdHRyIGFwcGlkX3dyaXRldXNlcmF0dHIifQ.HHterec250JSDY1965cM2DadBznl2wTKmzKNSnfjpdTAqax9VZvV3EwuFbEnGp9-i6AC-OlsVj7xvbALkdjwG2lZvpQx0M_gRc_3E0NiYuOGVolcm0wEXtbtDUFFqZQAf9BYYOPZ8OintdBiwUGETbH1ZRVtUvt3nalIko1OPE1Q12LvuRlhz5MClNHmvxJcXc7kucxCx4s4UFFy_HJA1gow7HWFqc9-PZf4JMWA-siYqPrdw_zYeBTBzE5co92F6JBEtGLLCjhJVz9eYgLLECXbak3z6hOaY9352Weuj7AgMOWxzw56jKKsiixMtvzrCzLVIcRUG96UJszwPHtPlA",INVALID_SIGNATURE_TOKEN:"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTU2NjMxMDg5NSwiZXhwIjoxNTY2MzE0NDk1LCJpYXQiOjE1NjYzMTA4OTUsImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciIsImF1ZCI6WyJodHRwOi8vZm9vMS5jb20iLCJodHRwOi8vZm9vMi5jb20iXX0.NBDYg8VZxW770qcbIl40OFvaQntO-FVYUUJocE5ZgcyrvFTuomwF997OcEJghO8BE_Y2m67PbfPFsbN0VI6j"}},function(t,e,i){(function(t){var i={userAgent:!1},n={}; /*! Copyright (c) 2011, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: @@ -14,16 +14,16 @@ if(void 0===r)var r={};r.lang={extend:function(t,e,n){if(!e||!t)throw new Error( * https://code.google.com/p/crypto-js/issues/detail?id=84 * https://crypto-js.googlecode.com/svn-history/r667/branches/3.x/src/core.js */ -var s,a,o,h,u,c,l,f,d,g,p,y=y||(s=Math,o=(a={}).lib={},h=o.Base=function(){function t(){}return{extend:function(e){t.prototype=this;var i=new t;return e&&i.mixIn(e),i.hasOwnProperty("init")||(i.init=function(){i.$super.init.apply(this,arguments)}),i.init.prototype=i,i.$super=this,i},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),u=o.WordArray=h.extend({init:function(t,e){t=this.words=t||[],this.sigBytes=null!=e?e:4*t.length},toString:function(t){return(t||l).stringify(this)},concat:function(t){var e=this.words,i=t.words,n=this.sigBytes,r=t.sigBytes;if(this.clamp(),n%4)for(var s=0;s>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],w=d[F],E=257*d[m]^16843008*m;s[p]=E<<24|E>>>8,a[p]=E<<16|E>>>16,o[p]=E<<8|E>>>24,h[p]=E,E=16843009*w^65537*F^257*S^16843008*p,u[m]=E<<24|E>>>8,c[m]=E<<16|E>>>16,l[m]=E<<8|E>>>24,f[m]=E,p?(p=S^d[d[d[w^S]]],v^=d[d[v]]):p=v=1}var x=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=x[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],w=t[s+13],E=t[s+14],x=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,w,12,u[13]),I=e(I,A,b,C,E,17,u[14]),b=i(b,C=e(C,I,A,b,x,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,x,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,E,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,w,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,E,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,w,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,x,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,E,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,x,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,w,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,w=h.low,E=u.high,x=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,H=p,R=y,B=v,N=m,O=S,j=F,V=w,L=E,_=x,K=b,M=A,k=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&K,Q=V&_^~V&M,z=D&P^D&R^P&R;var tt=T&H^T&B^H&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=k+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),k=K,U=M,K=L,M=_,L=j,_=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=R,O=B,R=P,B=H,P=D,H=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+H,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+R+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),w=h.low=w+V,h.high=F+j+(w>>>0>>0?1:0),x=u.low=x+_,u.high=E+L+(x>>>0<_>>>0?1:0),A=c.low=A+M,c.high=b+K+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+k+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,w=(n=h.words,u.words),E=r.words,x=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+E[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+x[i]]|0,I=16>i?I+((y^(v|~m))+w[0]):32>i?I+((y&m|v&~m)+w[1]):48>i?I+(((y|~v)^m)+w[2]):64>i?I+((y&v|~y&m)+w[3]):I+((y^v^m)+w[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],w=d[F],E=257*d[m]^16843008*m;s[p]=E<<24|E>>>8,a[p]=E<<16|E>>>16,o[p]=E<<8|E>>>24,h[p]=E,E=16843009*w^65537*F^257*S^16843008*p,u[m]=E<<24|E>>>8,c[m]=E<<16|E>>>16,l[m]=E<<8|E>>>24,f[m]=E,p?(p=S^d[d[d[w^S]]],v^=d[d[v]]):p=v=1}var x=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=x[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],w=t[s+13],E=t[s+14],x=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,w,12,u[13]),I=e(I,A,b,C,E,17,u[14]),b=i(b,C=e(C,I,A,b,x,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,x,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,E,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,w,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,E,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,w,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,x,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,E,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,x,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,w,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,w=h.low,E=u.high,x=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,R=p,H=y,B=v,N=m,O=S,j=F,V=w,L=E,_=x,K=b,M=A,k=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&K,Q=V&_^~V&M,z=D&P^D&H^P&H;var tt=T&R^T&B^R&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=k+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),k=K,U=M,K=L,M=_,L=j,_=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=H,O=B,H=P,B=R,P=D,R=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+R,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+H+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),w=h.low=w+V,h.high=F+j+(w>>>0>>0?1:0),x=u.low=x+_,u.high=E+L+(x>>>0<_>>>0?1:0),A=c.low=A+M,c.high=b+K+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+k+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,w=(n=h.words,u.words),E=r.words,x=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+E[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+x[i]]|0,I=16>i?I+((y^(v|~m))+w[0]):32>i?I+((y&m|v&~m)+w[1]):48>i?I+(((y|~v)^m)+w[2]):64>i?I+((y&v|~y&m)+w[3]):I+((y^v^m)+w[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function w(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function E(t){var e,i=w(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(x.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(x.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),x.prototype.DB=v,x.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function K(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function M(){}function k(t){return t}function U(t){this.r2=b(),this.q3=b(),x.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(x.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},x.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},x.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},x.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},x.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},x.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},x.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},x.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},x.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),x.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&x.ZERO.subTo(i,i)}}},x.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},x.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},x.prototype.exp=function(t,e){if(t>4294967295||t<1)return x.ONE;var i=b(),n=b(),r=e.convert(this),s=R(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},x.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},x.prototype.negate=function(){var t=b();return x.ZERO.subTo(this,t),t},x.prototype.abs=function(){return this.s<0?this.negate():this},x.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},x.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+R(this[this.t-1]^this.s&this.DM)},x.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(x.ZERO)>0&&t.subTo(e,e),e},x.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},x.ZERO=H(0),x.ONE=H(1),M.prototype.convert=k,M.prototype.revert=k,M.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},M.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; +var v,m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",S="=";function F(t){var e,i,n="";for(e=0;e+3<=t.length;e+=3)i=parseInt(t.substring(e,e+3),16),n+=m.charAt(i>>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function w(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function E(t){var e,i=w(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(x.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(x.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),x.prototype.DB=v,x.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function K(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function M(){}function k(t){return t}function U(t){this.r2=b(),this.q3=b(),x.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(x.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},x.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},x.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},x.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},x.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},x.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},x.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},x.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},x.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),x.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&x.ZERO.subTo(i,i)}}},x.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},x.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},x.prototype.exp=function(t,e){if(t>4294967295||t<1)return x.ONE;var i=b(),n=b(),r=e.convert(this),s=H(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},x.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},x.prototype.negate=function(){var t=b();return x.ZERO.subTo(this,t),t},x.prototype.abs=function(){return this.s<0?this.negate():this},x.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},x.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+H(this[this.t-1]^this.s&this.DM)},x.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(x.ZERO)>0&&t.subTo(e,e),e},x.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},x.ZERO=R(0),x.ONE=R(1),M.prototype.convert=k,M.prototype.revert=k,M.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},M.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ -function Y(){this.i=0,this.j=0,this.S=new Array}x.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},x.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),n=H(i),r=b(),s=b(),a="";for(this.divRemTo(n,r,s);r.signum()>0;)a=(i+s.intValue()).toString(t).substr(1)+a,r.divRemTo(n,r,s);return s.intValue().toString(t)+a},x.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),n=Math.pow(e,i),r=!1,s=0,a=0,o=0;o=i&&(this.dMultiply(n),this.dAddOffset(a,0),s=0,a=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(a,0)),r&&x.ZERO.subTo(this,this)},x.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(x.ONE.shiftLeft(t-1),j,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(x.ONE.shiftLeft(t-1),this);else{var n=new Array,r=7&t;n.length=1+(t>>3),e.nextBytes(n),r>0?n[0]&=(1<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[i++]=n:n<-1&&(e[i++]=this.DV+n),e.t=i,e.clamp()},x.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},x.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},x.prototype.multiplyLowerTo=function(t,e,i){var n,r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;r>0;)i[--r]=0;for(n=i.t-this.t;r=0;)i[n]=0;for(n=Math.max(e-this.t,0);n0)if(0==e)i=this[0]%t;else for(var n=this.t-1;n>=0;--n)i=(e*i+this[n])%t;return i},x.prototype.millerRabin=function(t){var e=this.subtract(x.ONE),i=e.getLowestSetBit();if(i<=0)return!1;var n=e.shiftRight(i);(t=t+1>>1)>q.length&&(t=q.length);for(var r=b(),s=0;s36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),n=R(i),r=b(),s=b(),a="";for(this.divRemTo(n,r,s);r.signum()>0;)a=(i+s.intValue()).toString(t).substr(1)+a,r.divRemTo(n,r,s);return s.intValue().toString(t)+a},x.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),n=Math.pow(e,i),r=!1,s=0,a=0,o=0;o=i&&(this.dMultiply(n),this.dAddOffset(a,0),s=0,a=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(a,0)),r&&x.ZERO.subTo(this,this)},x.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(x.ONE.shiftLeft(t-1),j,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(x.ONE.shiftLeft(t-1),this);else{var n=new Array,r=7&t;n.length=1+(t>>3),e.nextBytes(n),r>0?n[0]&=(1<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[i++]=n:n<-1&&(e[i++]=this.DV+n),e.t=i,e.clamp()},x.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},x.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},x.prototype.multiplyLowerTo=function(t,e,i){var n,r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;r>0;)i[--r]=0;for(n=i.t-this.t;r=0;)i[n]=0;for(n=Math.max(e-this.t,0);n0)if(0==e)i=this[0]%t;else for(var n=this.t-1;n>=0;--n)i=(e*i+this[n])%t;return i},x.prototype.millerRabin=function(t){var e=this.subtract(x.ONE),i=e.getLowestSetBit();if(i<=0)return!1;var n=e.shiftRight(i);(t=t+1>>1)>q.length&&(t=q.length);for(var r=b(),s=0;s>24},x.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},x.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},x.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},x.prototype.equals=function(t){return 0==this.compareTo(t)},x.prototype.min=function(t){return this.compareTo(t)<0?this:t},x.prototype.max=function(t){return this.compareTo(t)>0?this:t},x.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},x.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},x.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},x.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},x.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=R(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(x.ONE)?x.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},x.prototype.pow=function(t){return this.exp(t,new M)},x.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},x.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>24},x.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},x.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},x.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},x.prototype.equals=function(t){return 0==this.compareTo(t)},x.prototype.min=function(t){return this.compareTo(t)<0?this:t},x.prototype.max=function(t){return this.compareTo(t)>0?this:t},x.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},x.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},x.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},x.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},x.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=H(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(x.ONE)?x.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},x.prototype.pow=function(t){return this.exp(t,new M)},x.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},x.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>8&255,J[W++]^=t>>16&255,J[W++]^=t>>24&255,W>=X&&(W-=X)}((new Date).getTime())}if(null==J){var $;if(J=new Array,W=0,void 0!==n&&(void 0!==n.crypto||void 0!==n.msCrypto)){var Q=n.crypto||n.msCrypto;if(Q.getRandomValues){var tt=new Uint8Array(32);for(Q.getRandomValues(tt),$=0;$<32;++$)J[W++]=tt[$]}else if("Netscape"==i.appName&&i.appVersion<"5"){var et=n.crypto.random(32);for($=0;$>>8,J[W++]=255&$;W=0,Z()}function it(){if(null==G){for(Z(),(G=new Y).init(J),W=0;Wi.length;)i.unshift(0);return i},i=this.getX().toBigInteger(),n=this.getY().toBigInteger(),r=e(i,32);return t?n.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(e(n,32))),r},ut.decodeFrom=function(t,e){e[0];var i=e.length-1,n=e.slice(1,1+i/2),r=e.slice(1+i/2,1+i);n.unshift(0),r.unshift(0);var s=new x(n),a=new x(r);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.decodeFromHex=function(t,e){e.substr(0,2);var i=e.length-2,n=e.substr(2,i/2),r=e.substr(2+i/2,i/2),s=new x(n,16),a=new x(r,16);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.prototype.add2D=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();var e=t.x.subtract(this.x),i=t.y.subtract(this.y).divide(e),n=i.square().subtract(this.x).subtract(t.x),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=this.curve.fromBigInteger(x.valueOf(2)),e=this.curve.fromBigInteger(x.valueOf(3)),i=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),n=i.square().subtract(this.x.multiply(t)),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new x("3")),r=this.negate(),s=this;for(e=n.bitLength()-2;e>0;--e){s=s.twice();var a=n.testBit(e);a!=i.testBit(e)&&(s=s.add2D(a?this:r))}return s},ut.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),i=this.curve.getA().toBigInteger(),n=this.curve.getB().toBigInteger(),r=this.curve.getQ(),s=e.multiply(e).mod(r),a=t.multiply(t).multiply(t).add(i.multiply(t)).add(n).mod(r);return s.equals(a)},ut.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},ut.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),i=this.getY().toBigInteger();if(e.compareTo(x.ONE)<0||e.compareTo(t.subtract(x.ONE))>0)throw new Error("x coordinate out of bounds");if(i.compareTo(x.ONE)<0||i.compareTo(t.subtract(x.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0}; /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval */ -var lt=function(){var t=new RegExp('(?:false|true|null|[\\{\\}\\[\\]]|(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)|(?:"(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))*"))',"g"),e=new RegExp("\\\\(?:([^u])|u(.{4}))","g"),i={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function n(t,e,n){return e?i[e]:String.fromCharCode(parseInt(n,16))}var r=new String(""),s=(Object,Array,Object.hasOwnProperty);return function(i,a){var o,h,u=i.match(t),c=u[0],l=!1;"{"===c?o={}:"["===c?o=[]:(o=[],l=!0);for(var f=[o],d=1-l,g=u.length;d=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map(function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Rt;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map(function(t){return t.replace("/","\\/")})).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Rt;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Rt(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Ht(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),w=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=w,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var E=0;E1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Rt(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Rt(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Rt,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Rt(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(H=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(H,0,[2],"02"),w=r(H,0,[3],"02"),E=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(H=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(H,0,[2,0],"06"),P=r(H,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var H;S=r(H=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(H,0,[2],"02"),w=r(H,0,[3],"02"),E=r(H,0,[4],"02"),b=r(H,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Ht(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),w=m(t).getEncodedHex(),E="";return E+=Ht(F,"EC PARAMETERS"),E+=Ht(w,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Ht(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Ht(x,"PRIVATE KEY"):Ht(w=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Rt(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e.d=Et(t.d.toString(16)),e.p=Et(t.p.toString(16)),e.q=Et(t.q.toString(16)),e.dp=Et(t.dmp1.toString(16)),e.dq=Et(t.dmq1.toString(16)),e.qi=Et(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e.d=Et(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Rt(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Rt;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=w,e.b64toBA=E,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(E(wt(t)))},e.b64tob64u=Ft,e.b64utob64=wt,e.hex2b64=F,e.hextob64u=Et,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(w(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Ht,e.pemtohex=Rt,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map((function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Ht;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map((function(t){return t.replace("/","\\/")}))).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Ht;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Ht(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Rt(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),w=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=w,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var E=0;E1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Ht(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Ht(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Ht,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Ht(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(R=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(R,0,[2],"02"),w=r(R,0,[3],"02"),E=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(R=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(R,0,[2,0],"06"),P=r(R,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var R;S=r(R=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(R,0,[2],"02"),w=r(R,0,[3],"02"),E=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Rt(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),w=m(t).getEncodedHex(),E="";return E+=Rt(F,"EC PARAMETERS"),E+=Rt(w,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Ht(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e.d=Et(t.d.toString(16)),e.p=Et(t.p.toString(16)),e.q=Et(t.q.toString(16)),e.dp=Et(t.dmp1.toString(16)),e.dq=Et(t.dmq1.toString(16)),e.qi=Et(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e.d=Et(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Ht(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Ht;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=w,e.b64toBA=E,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(E(wt(t)))},e.b64tob64u=Ft,e.b64utob64=wt,e.hex2b64=F,e.hextob64u=Et,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(w(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Rt,e.pemtohex=Ht,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp * @license MIT */ -var n=i(9),r=i(10),s=i(11);function a(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return M(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return k(t).length;default:if(n)return M(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return H(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return w(this,t,e,i);case"latin1":case"binary":return E(this,t,e,i);case"base64":return x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||R(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||R(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||R(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||R(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||R(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||R(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||R(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||R(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||R(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||R(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||R(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||R(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||R(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function k(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(_,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(8))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e){t.exports=class extends Error{constructor({error:t,description:e}){super(e||t),this.error=t,this.description=e}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(17);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){const e=t.height,i=t.width,r=(screen.width-i)/2,s=(screen.height-e)/2;if(this.popup=this.window.open("","popup",`left=${r},top=${s},width=${i},height=${e},resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(19);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}}])}); \ No newline at end of file +var n=i(9),r=i(10),s=i(11);function a(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return M(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return k(t).length;default:if(n)return M(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return w(this,t,e,i);case"latin1":case"binary":return E(this,t,e,i);case"base64":return x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||H(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||H(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||H(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||H(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||H(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||H(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||H(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||H(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||H(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||H(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function k(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(_,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(8))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e){t.exports=class extends Error{constructor({error:t,description:e}){super(e||t),this.error=t,this.description=e}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(17);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){const e=t.height,i=t.width,r=(screen.width-i)/2,s=(screen.height-e)/2;if(this.popup=this.window.open("","popup",`left=${r},top=${s},width=${i},height=${e},resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(19);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}}])})); \ No newline at end of file diff --git a/src/index.js b/src/index.js index 15705f4..2de63c1 100644 --- a/src/index.js +++ b/src/index.js @@ -61,7 +61,7 @@ class AppID { await this.openIdConfigResource.init({discoveryEndpoint, requestHandler: this.request}); this.clientId = clientId; this.popupConfig = popup; - this.utils = new Utils({openId: this.openIdConfigResource, clientId: this.clientId}); + this.utils = new Utils({openId: this.openIdConfigResource, clientId: this.clientId, url: this.URL}); } /** diff --git a/test/AppIdTest.js b/test/AppIdTest.js index 045eb64..9de7599 100644 --- a/test/AppIdTest.js +++ b/test/AppIdTest.js @@ -10,7 +10,40 @@ const RequestHandler = require('./mocks/RequestHandlerMock'); const {URL} = require('url'); describe('AppID tests', () => { - describe('signInWithPopup', () => { + describe('init', () => { + const appID = new AppID({ + popup: new PopupController({invalidState: false, error: false, invalidOrigin: false}), + iframe: new IFrameController({invalidState: false, error: false, invalidOrigin: false}), + tokenValidator: new TokenValidator(), + openID: new OpenIdConfigurationResource(), + utils: new Utils(), + requestHandler: new RequestHandler(), + w: {origin: 'http://localhost:3005'}, + url: URL + }); + + it('should pass', async () => { + await appID.init({clientId: '1234', discoveryEndpoint: 'discoveryEndpoint', popup: {height: 400, width: 300}}); + }); + + it('should return error - missing client id', async () => { + try { + await appID.init({discoveryEndpoint: 'discoveryEndpoint', popup: {height: 400, width: 300}}); + } catch (e) { + assert.equal(e.message, constants.MISSING_CLIENT_ID); + } + }); + + it('should return error - missing discovery endpoint', async () => { + try { + await appID.init({clientId: '1234', popup: {height: 400, width: 300}}); + } catch (e) { + assert.equal(e.message, constants.MISSING_DISCOVERY_ENDPOINT); + } + }); + }); + + describe('signIn', () => { it('should return tokens', async () => { const appID = new AppID({ popup: new PopupController({invalidState: false, error: false, invalidOrigin: false}), diff --git a/test/mocks/OpenIdConfigurationMock.js b/test/mocks/OpenIdConfigurationMock.js index 6b4b484..5794d20 100644 --- a/test/mocks/OpenIdConfigurationMock.js +++ b/test/mocks/OpenIdConfigurationMock.js @@ -1,4 +1,8 @@ class OpenIdConfigurationMock { + init() { + return; + } + getAuthorizationEndpoint() { return 'http://authServer.com/'; } From a9649c933bf41968520cf961d9f4eea72c4dcb38 Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Fri, 27 Sep 2019 09:55:00 -0500 Subject: [PATCH 10/15] readme codacy --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e4bca89..1c508d1 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,12 @@ # appid-clientsdk-js Client-side javascript SDK for the IBM Cloud App ID service. -### Table of Contents +## Table of Contents - [Installation][1] + - [Getting Started][2] + - [API Reference][3] - [init][4] - [signin][5] @@ -58,7 +60,9 @@ Initialize AppID ### Parameters - `options` **[Object][8]** - `options.clientId` **[string][9]** The clientId from the singlepageapp application credentials. + - `options.discoveryEndpoint` **[string][9]** The discoveryEndpoint from the singlepageapp application credentials. + - `options.popup` **[Object][8]** The popup configuration. (optional, default `{height:screen.height*.80,width:400}`) - `options.popup.height` **[Number][11]** The popup height. - `options.popup.width` **[Number][11]** The popup width. @@ -121,7 +125,6 @@ This method will made a GET request to the user info endpoint using the access t ### Parameters - `accessToken` **[string][9]** The App ID access token of the user - - Throws **AppIDError** "Access token must be a string" - Invalid access token. - Throws **RequestError** Any errors during a HTTP request. From 05edd3301dd175a4e21c2b411f9118ac4f4de021 Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Fri, 27 Sep 2019 11:40:43 -0500 Subject: [PATCH 11/15] woot docs --- README.md | 97 ++++------------------------------------------------ jsdoc.json | 11 ++++++ src/index.js | 45 +++++++++++++++--------- 3 files changed, 46 insertions(+), 107 deletions(-) create mode 100644 jsdoc.json diff --git a/README.md b/README.md index 1c508d1..c553600 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,9 @@ Client-side javascript SDK for the IBM Cloud App ID service. - [Getting Started][2] - [API Reference][3] - - [init][4] - - [signin][5] - - [silentSignin][6] - - [getUserInfo][7] + ## Installation -Using npm +Using npm: ```javascript npm install ibmcloud-appid-js ``` @@ -25,9 +22,9 @@ From the CDN: ``` -Or, use the minified files in this repo: +Or for development purposes use the minified file in this repo: ```html - + ``` ## Getting Started @@ -54,90 +51,8 @@ document.getElementById('login').addEventListener('click', async () => { ``` ## API Reference -## init -Initialize AppID - -### Parameters -- `options` **[Object][8]** - - `options.clientId` **[string][9]** The clientId from the singlepageapp application credentials. - - - `options.discoveryEndpoint` **[string][9]** The discoveryEndpoint from the singlepageapp application credentials. - - - `options.popup` **[Object][8]** The popup configuration. (optional, default `{height:screen.height*.80,width:400}`) - - `options.popup.height` **[Number][11]** The popup height. - - `options.popup.width` **[Number][11]** The popup width. - -### Example - -```javascript -await appID.init({ - clientId: '', - discoveryEndpoint: '' -}); -``` - -- Throws **AppIDError** For missing required params. -- Throws **RequestError** Any errors during a HTTP request. - -Returns **[Promise][10]** - -## signin - -This will open a login widget in a popup which will prompt the user to enter their credentials. -After a successful login, the popup will close and tokens are returned. - -### Example - -```javascript -const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.signin(); -``` - -- Throws **AppIDError** AppIDError "Popup closed" - The user closed the popup before authentication was completed. -- Throws **TokenError** Any token validation error. -- Throws **OAuthError** Any errors from the server. e.g. {error: 'server_error', description: ''} -- Throws **RequestError** Any errors during a HTTP request. - -Returns **[Promise][10]** The tokens of the authenticated user or an error. - -## silentSignin - -Silent sign in will attempt to authenticate the user in a hidden iframe. -Sign in will be successful only if there is a Cloud Directory SSO token in the browser. -You will need to enable SSO on the App ID dashboard. - -### Example - -```javascript -const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.silentSignin(); -``` - -- Throws **OAuthError** Any errors from the server. e.g. {error: 'access_denied', description: 'User not signed in'} -- Throws **AppIDError** "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed. -- Throws **TokenError** Any token validation error. -- Throws **RequestError** Any errors during a HTTP request. - -Returns **[Promise][10]** The tokens of the authenticated user. - -## getUserInfo - -This method will made a GET request to the user info endpoint using the access token of the authenticated user. - -### Parameters - -- `accessToken` **[string][9]** The App ID access token of the user -- Throws **AppIDError** "Access token must be a string" - Invalid access token. -- Throws **RequestError** Any errors during a HTTP request. - -Returns **[Promise][10]** The user information for the authenticated user. Example: {sub: '', email: ''} +Checkout our API reference [here](https://ibm-cloud-security.github.io/appid-clientsdk-js/). [1]: #installation [2]: #getting-started -[3]: #api-reference -[4]: #init -[5]: #signin -[6]: #silentsignin -[7]: #getuserinfo -[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise -[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number \ No newline at end of file +[3]: #api-reference \ No newline at end of file diff --git a/jsdoc.json b/jsdoc.json new file mode 100644 index 0000000..e10f14a --- /dev/null +++ b/jsdoc.json @@ -0,0 +1,11 @@ +{ + "plugins": ["plugins/markdown"], + "markdown": { + "parser": "gfm", + "hardwrap": true, + "idInHeadings": true + }, + "docdash": { + "typedefs": true + } +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 2de63c1..2aa3e8b 100644 --- a/src/index.js +++ b/src/index.js @@ -8,9 +8,14 @@ const constants = require('./constants'); const AppIDError = require('./errors/AppIDError'); /** - * Client-side javascript SDK for the IBM Cloud App ID service. + * This class provides functions to support authentication. */ class AppID { + /** + * This creates an instance of AppID. Once created, call init() before attempting to sign in. + * @example + * const appID = new AppID(); + */ constructor( { popup = new PopupController(), @@ -38,7 +43,7 @@ class AppID { * @param {Object} options * @param {string} options.clientId - The clientId from the singlepageapp application credentials. * @param {string} options.discoveryEndpoint - The discoveryEndpoint from the singlepageapp application credentials. - * @param {Object} options.popup - The popup configuration. + * @param {Object} [options.popup] - The popup configuration. * @param {Number} options.popup.height - The popup height. * @param {Number} options.popup.width - The popup width. * @returns {Promise} @@ -46,8 +51,8 @@ class AppID { * @throws {RequestError} Any errors during a HTTP request. * @example * await appID.init({ - * clientId: '', - * discoveryEndpoint: '' + * clientId: '', + * discoveryEndpoint: '' * }); * */ @@ -65,12 +70,20 @@ class AppID { } /** - * This will open a login widget in a popup which will prompt the user to enter their credentials. - * After a successful login, the popup will close and tokens are returned. - * @returns {Promise} The tokens of the authenticated user or an error. - * @throws {AppIDError} "Popup closed" - The user closed the popup before authentication was completed. + * @typedef {Object} Tokens + * @property {string} accessToken A JWT. + * @property {Object} accessTokenPayload The decoded JWT. + * @property {string} idToken A JWT. + * @property {Object} idTokenPayload The decoded JWT. + */ + + /** + * This will open a sign in widget in a popup which will prompt the user to enter their credentials. + * After a successful sign in, the popup will close and tokens are returned. + * @returns {Promise} The tokens of the authenticated user. + * @throws {PopupError} "Popup closed" - The user closed the popup before authentication was completed. * @throws {TokenError} Any token validation error. - * @throws {OAuthError} Any errors from the server. e.g. {error: 'server_error', description: ''} + * @throws {OAuthError} Any errors from the server according to the [OAuth spec]{@link https://tools.ietf.org/html/rfc6749#section-4.1.2.1}. e.g. {error: 'server_error', description: ''} * @throws {RequestError} Any errors during a HTTP request. * @example * const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.signin(); @@ -97,11 +110,11 @@ class AppID { /** * Silent sign in will attempt to authenticate the user in a hidden iframe. - * Sign in will be successful only if there is a Cloud Directory SSO token in the browser. - * You will need to enable SSO on the App ID dashboard. - * @returns {Promise} The tokens of the authenticated user. - * @throws {OAuthError} Any errors from the server. e.g. {error: 'access_denied', description: 'User not signed in'} - * @throws {AppIDError} "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed. + * You will need to enable Cloud Directory SSO. + * Sign in will be successful only if the user has previously signed in using Cloud Directory and their session is not expired. + * @returns {Promise} The tokens of the authenticated user. + * @throws {OAuthError} Any errors from the server according to the [OAuth spec]{@link https://tools.ietf.org/html/rfc6749#section-4.1.2.1}. e.g. {error: 'access_denied', description: 'User not signed in'} + * @throws {IFrameError} "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed. * @throws {TokenError} Any token validation error. * @throws {RequestError} Any errors during a HTTP request. * @example @@ -132,8 +145,8 @@ class AppID { } /** - * This method will made a GET request to the user info endpoint using the access token of the authenticated user. - * @param {string} accessToken - The App ID access token of the user + * This method will made a GET request to the [user info endpoint]{@link https://us-south.appid.cloud.ibm.com/swagger-ui/#/Authorization%20Server%20-%20Authorization%20Server%20V4/oauth-server.userInfo} using the access token of the authenticated user. + * @param {string} accessToken - The App ID access token of the user. * @returns {Promise} The user information for the authenticated user. Example: {sub: '', email: ''} * @throws {AppIDError} "Access token must be a string" Invalid access token. * @throws {RequestError} Any errors during a HTTP request. From f3caecce05bb01ee12c5135b6c77dcd3f1186381 Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Fri, 27 Sep 2019 11:42:48 -0500 Subject: [PATCH 12/15] adding docs --- package-lock.json | 110 +++++++++++++++++++--------------------------- package.json | 2 +- 2 files changed, 45 insertions(+), 67 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2c0f8b2..ff322c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1372,15 +1372,13 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz", "integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=", - "dev": true, - "optional": true + "dev": true }, "is-glob": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz", "integrity": "sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM=", "dev": true, - "optional": true, "requires": { "is-extglob": "^1.0.0" } @@ -1422,7 +1420,6 @@ "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", "dev": true, - "optional": true, "requires": { "remove-trailing-separator": "^1.0.1" } @@ -2071,8 +2068,8 @@ }, "catharsis": { "version": "0.8.11", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/catharsis/-/catharsis-0.8.11.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fcatharsis%2F-%2Fcatharsis-0.8.11.tgz", - "integrity": "sha1-0Os9K4K32no84u+xp7AL7MZkNGg=", + "resolved": "https://registry.npmjs.org/catharsis/-/catharsis-0.8.11.tgz", + "integrity": "sha512-a+xUyMV7hD1BrDQA/3iPV7oc+6W26BgVJO05PGEoatMyIuPScQKsde6i3YorWX1qs+AZjnJ18NqdKoCtKiNh1g==", "dev": true, "requires": { "lodash": "^4.17.14" @@ -2674,8 +2671,8 @@ }, "entities": { "version": "1.1.2", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/entities/-/entities-1.1.2.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fentities%2F-%2Fentities-1.1.2.tgz", - "integrity": "sha1-vfpzUplmTfr9NFKe1PhSKidf6lY=", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==", "dev": true }, "errno": { @@ -3221,8 +3218,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -3243,14 +3239,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3265,20 +3259,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -3395,8 +3386,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -3408,7 +3398,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3423,7 +3412,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3431,14 +3419,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3457,7 +3443,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -3538,8 +3523,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -3551,7 +3535,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -3637,8 +3620,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -3674,7 +3656,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3694,7 +3675,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3738,14 +3718,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, @@ -4547,8 +4525,8 @@ }, "js2xmlparser": { "version": "4.0.0", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/js2xmlparser/-/js2xmlparser-4.0.0.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fjs2xmlparser%2F-%2Fjs2xmlparser-4.0.0.tgz", - "integrity": "sha1-rhTMcRsokgg+7W4hn7yZPYWLw6U=", + "resolved": "https://registry.npmjs.org/js2xmlparser/-/js2xmlparser-4.0.0.tgz", + "integrity": "sha512-WuNgdZOXVmBk5kUPMcTcVUpbGRzLfNkv7+7APq7WiDihpXVKrgxo6wwRpRl9OQeEBgKCVk9mR7RbzrnNWC8oBw==", "dev": true, "requires": { "xmlcreate": "^2.0.0" @@ -4562,8 +4540,8 @@ }, "jsdoc": { "version": "3.6.3", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/jsdoc/-/jsdoc-3.6.3.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fjsdoc%2F-%2Fjsdoc-3.6.3.tgz", - "integrity": "sha1-3M6pfQ5i1j0wa4s+0VJxc7XiGQ0=", + "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.3.tgz", + "integrity": "sha512-Yf1ZKA3r9nvtMWHO1kEuMZTlHOF8uoQ0vyo5eH7SQy5YeIiHM+B0DgKnn+X6y6KDYZcF7G2SPkKF+JORCXWE/A==", "dev": true, "requires": { "@babel/parser": "^7.4.4", @@ -4584,14 +4562,14 @@ "dependencies": { "escape-string-regexp": { "version": "2.0.0", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fescape-string-regexp%2F-%2Fescape-string-regexp-2.0.0.tgz", - "integrity": "sha1-owME6Z2qMuI7L9IPUbq9B8/8o0Q=", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", + "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", "dev": true }, "strip-json-comments": { "version": "3.0.1", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/strip-json-comments/-/strip-json-comments-3.0.1.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fstrip-json-comments%2F-%2Fstrip-json-comments-3.0.1.tgz", - "integrity": "sha1-hXE5dakfuHvxswXMp3OV5A0qZKc=", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.0.1.tgz", + "integrity": "sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==", "dev": true } } @@ -4668,8 +4646,8 @@ }, "klaw": { "version": "3.0.0", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/klaw/-/klaw-3.0.0.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fklaw%2F-%2Fklaw-3.0.0.tgz", - "integrity": "sha1-sRvsnPJJLwZ1bW6Amrc6KRAlkUY=", + "resolved": "https://registry.npmjs.org/klaw/-/klaw-3.0.0.tgz", + "integrity": "sha512-0Fo5oir+O9jnXu5EefYbVK+mHMBeEVEy2cmctR1O1NECcCkPRreJKrS6Qt/j3KC2C148Dfo9i3pCmCMsdqGr0g==", "dev": true, "requires": { "graceful-fs": "^4.1.9" @@ -4692,8 +4670,8 @@ }, "linkify-it": { "version": "2.2.0", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/linkify-it/-/linkify-it-2.2.0.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Flinkify-it%2F-%2Flinkify-it-2.2.0.tgz", - "integrity": "sha1-47VGl+eL+RXHCjis14/QngBYsc8=", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.2.0.tgz", + "integrity": "sha512-GnAl/knGn+i1U/wjBz3akz2stz+HrHLsxMwHQGofCDfPvlf+gDKN58UtfmUquTY4/MXeE2x7k19KQmeoZi94Iw==", "dev": true, "requires": { "uc.micro": "^1.0.1" @@ -4851,8 +4829,8 @@ }, "markdown-it": { "version": "8.4.2", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/markdown-it/-/markdown-it-8.4.2.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fmarkdown-it%2F-%2Fmarkdown-it-8.4.2.tgz", - "integrity": "sha1-OG+YmY3BWjdyKqdyIIT0Agvdm1Q=", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.2.tgz", + "integrity": "sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==", "dev": true, "requires": { "argparse": "^1.0.7", @@ -4864,14 +4842,14 @@ }, "markdown-it-anchor": { "version": "5.2.4", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/markdown-it-anchor/-/markdown-it-anchor-5.2.4.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fmarkdown-it-anchor%2F-%2Fmarkdown-it-anchor-5.2.4.tgz", - "integrity": "sha1-05MG/kwZlwW0R50wNoQs803Lok8=", + "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-5.2.4.tgz", + "integrity": "sha512-n8zCGjxA3T+Mx1pG8HEgbJbkB8JFUuRkeTZQuIM8iPY6oQ8sWOPRZJDFC9a/pNg2QkHEjjGkhBEl/RSyzaDZ3A==", "dev": true }, "marked": { "version": "0.7.0", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/marked/-/marked-0.7.0.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fmarked%2F-%2Fmarked-0.7.0.tgz", - "integrity": "sha1-tkIB8FHScbHtwQoE0a6bdLuOXA4=", + "resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz", + "integrity": "sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg==", "dev": true }, "math-random": { @@ -4893,7 +4871,7 @@ }, "mdurl": { "version": "1.0.1", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/mdurl/-/mdurl-1.0.1.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fmdurl%2F-%2Fmdurl-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=", "dev": true }, @@ -6103,8 +6081,8 @@ }, "requizzle": { "version": "0.2.3", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/requizzle/-/requizzle-0.2.3.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Frequizzle%2F-%2Frequizzle-0.2.3.tgz", - "integrity": "sha1-RnXJCqyvssA2vTm6LapKHLd3/e0=", + "resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.3.tgz", + "integrity": "sha512-YanoyJjykPxGHii0fZP0uUPEXpvqfBDxWV7s6GKAiiOsiqhX6vHNyW3Qzdmqp/iq/ExbhaGbVrjB4ruEVSM4GQ==", "dev": true, "requires": { "lodash": "^4.17.14" @@ -6701,7 +6679,7 @@ }, "taffydb": { "version": "2.6.2", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/taffydb/-/taffydb-2.6.2.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Ftaffydb%2F-%2Ftaffydb-2.6.2.tgz", + "resolved": "https://registry.npmjs.org/taffydb/-/taffydb-2.6.2.tgz", "integrity": "sha1-fLy2S1oUG2ou/CxdLGe04VCyomg=", "dev": true }, @@ -6905,8 +6883,8 @@ }, "uc.micro": { "version": "1.0.6", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/uc.micro/-/uc.micro-1.0.6.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fuc.micro%2F-%2Fuc.micro-1.0.6.tgz", - "integrity": "sha1-nEEagCpAmpH8bPdAgbq6NLJEmaw=", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", + "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", "dev": true }, "uglify-js": { @@ -6931,8 +6909,8 @@ }, "underscore": { "version": "1.9.1", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/underscore/-/underscore-1.9.1.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Funderscore%2F-%2Funderscore-1.9.1.tgz", - "integrity": "sha1-BtzjSg5op7q8KbNluOdLiSUgOWE=", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.1.tgz", + "integrity": "sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg==", "dev": true }, "unicode-canonical-property-names-ecmascript": { @@ -7421,8 +7399,8 @@ }, "xmlcreate": { "version": "2.0.1", - "resolved": "https://na.artifactory.swg-devops.com:443/artifactory/api/npm/wcp-sec-srv-npm-virtual/xmlcreate/-/xmlcreate-2.0.1.tgz?dl=https%3A%2F%2Fregistry.npmjs.org%2Fxmlcreate%2F-%2Fxmlcreate-2.0.1.tgz", - "integrity": "sha1-LsOL17cI0hP9GpDiQxxK+cCfalI=", + "resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.1.tgz", + "integrity": "sha512-MjGsXhKG8YjTKrDCXseFo3ClbMGvUD4en29H2Cev1dv4P/chlpw6KdYmlCWDkhosBVKRDjM836+3e3pm1cBNJA==", "dev": true }, "xtend": { diff --git a/package.json b/package.json index 4535696..e93248b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "build": "webpack", "test": "mocha", "coverage": "nyc --reporter=lcov mocha", - "docs": "jsdoc src/index.js -t node_modules/docdash --readme README.md --destination doc" + "docs": "jsdoc src/index.js src/errors -t node_modules/docdash --readme README.md --destination docs -c jsdoc.json" }, "repository": { "type": "git", From e90658467d372a96ae2f86ffc43a0b945210bf28 Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Mon, 30 Sep 2019 11:11:53 -0500 Subject: [PATCH 13/15] update tests --- README.md | 5 +++-- dist/appid.min.js | 12 +++++------ dist/appid.umd.min.js | 12 +++++------ src/constants.js | 3 ++- src/index.js | 40 ++++++++++++++++++++++++++++--------- src/utils.js | 25 +++++++++++------------ test/AppIdTest.js | 46 +++++++++++++++++++++++++++++-------------- test/utilsTest.js | 2 +- 8 files changed, 91 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index c553600..27c24c6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a30e7499a5234d3494508b7050975beb)](https://www.codacy.com/app/kajabfab/appid-clientsdk-js?utm_source=github.com&utm_medium=referral&utm_content=ibm-cloud-security/appid-clientsdk-js&utm_campaign=Badge_Grade) -# appid-clientsdk-js -Client-side javascript SDK for the IBM Cloud App ID service. +# IBM Cloud App ID Client SDK +Client-side javascript SDK for the IBM Cloud App ID service. +Read the [official documentation](https://console.ng.bluemix.net/docs/services/appid/index.html#gettingstarted) for information about getting started with IBM Cloud App ID Service. ## Table of Contents diff --git a/dist/appid.min.js b/dist/appid.min.js index 3adf3df..cf92b4d 100644 --- a/dist/appid.min.js +++ b/dist/appid.min.js @@ -1,4 +1,4 @@ -var AppID=function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=5)}([function(t,e){t.exports={MALFORMED_TOKEN:"Invalid JWT token. Got only 2 parts.",INVALID_SIGNATURE:"Invalid signature",INVALID_VERSION:"Invalid version",INVALID_ALGORITHM:"Invalid algorithm",INVALID_ISSUER:"Invalid issuer",INVALID_AUDIENCE:"Invalid audience",INVALID_NONCE:"Invalid nonce",EXPIRED_TOKEN:"Expired token",INVALID_STATE:"Invalid state",INVALID_ORIGIN:"Invalid origin",INVALID_TOKEN:"Invalid token",MISSING_PUBLIC_KEY:"Cannot find public key",INVALID_ACCESS_TOKEN:"Access token must be a string",MISSING_CLIENT_ID:"Missing client ID",MISSING_DISCOVERY_ENDPOINT:"Missing discovery endpoint",RESPONSE_TYPE:"code",RESPONSE_MODE:"web_message",PROMPT:"none",SCOPE:"openid",STATE_LENGTH:20,NONCE_LENGTH:20,CODE_VERIFIER_LENGTH:44,CHALLENGE_METHOD:"S256",TOKEN_ALG:"RS256",VERSION:4,MALFORMED_ACCESS_TOKEN:"eyJpc3MiOiJtb2JpbGVjbGllbnRhY2Nlc3Muc3RhZ2UxLm5nLmJsdWVtaXgubmV0IiwiZXhwIjoxNDg3MDg0ODc4LCJhdWQiOiIyNmNiMDEyZWIzMjdjNjEyZDkwYTY4MTkxNjNiNmJjYmQ0ODQ5Y2JiIiwiaWF0IjoxNDg3MDgxMjc4LCJhdXRoX2J5IjoiZmFjZWJvb2siLCJ0ZW5hbnQiOiI0ZGJhOTQzMC01NGU2LTRjZjItYTUxNi02ZjczZmViNzAyYmIiLCJzY29wZSI6ImFwcGlkX2RlZmF1bHQgYXBwaWRfcmVhZHByb2ZpbGUgYXBwaWRfcmVhZHVzZXJhdHRyIGFwcGlkX3dyaXRldXNlcmF0dHIifQ.HHterec250JSDY1965cM2DadBznl2wTKmzKNSnfjpdTAqax9VZvV3EwuFbEnGp9-i6AC-OlsVj7xvbALkdjwG2lZvpQx0M_gRc_3E0NiYuOGVolcm0wEXtbtDUFFqZQAf9BYYOPZ8OintdBiwUGETbH1ZRVtUvt3nalIko1OPE1Q12LvuRlhz5MClNHmvxJcXc7kucxCx4s4UFFy_HJA1gow7HWFqc9-PZf4JMWA-siYqPrdw_zYeBTBzE5co92F6JBEtGLLCjhJVz9eYgLLECXbak3z6hOaY9352Weuj7AgMOWxzw56jKKsiixMtvzrCzLVIcRUG96UJszwPHtPlA",INVALID_SIGNATURE_TOKEN:"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTU2NjMxMDg5NSwiZXhwIjoxNTY2MzE0NDk1LCJpYXQiOjE1NjYzMTA4OTUsImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciIsImF1ZCI6WyJodHRwOi8vZm9vMS5jb20iLCJodHRwOi8vZm9vMi5jb20iXX0.NBDYg8VZxW770qcbIl40OFvaQntO-FVYUUJocE5ZgcyrvFTuomwF997OcEJghO8BE_Y2m67PbfPFsbN0VI6j"}},function(t,e,i){(function(t){var i={userAgent:!1},n={}; +var AppID=function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=5)}([function(t,e){t.exports={MALFORMED_TOKEN:"Invalid JWT token. Got only 2 parts.",INVALID_SIGNATURE:"Invalid signature",INVALID_VERSION:"Invalid version",INVALID_ALGORITHM:"Invalid algorithm",INVALID_ISSUER:"Invalid issuer",INVALID_AUDIENCE:"Invalid audience",INVALID_NONCE:"Invalid nonce",EXPIRED_TOKEN:"Expired token",INVALID_STATE:"Invalid state",INVALID_ORIGIN:"Invalid origin",INVALID_TOKEN:"Invalid token",MISSING_PUBLIC_KEY:"Cannot find public key",INVALID_ACCESS_TOKEN:"Access token must be a string",MISSING_CLIENT_ID:"Missing client ID",INVALID_DISCOVERY_ENDPOINT:"Invalid discovery endpoint",RESPONSE_TYPE:"code",RESPONSE_MODE:"web_message",PROMPT:"none",SCOPE:"openid",STATE_LENGTH:20,NONCE_LENGTH:20,CODE_VERIFIER_LENGTH:44,CHALLENGE_METHOD:"S256",TOKEN_ALG:"RS256",VERSION:4,MALFORMED_ACCESS_TOKEN:"eyJpc3MiOiJtb2JpbGVjbGllbnRhY2Nlc3Muc3RhZ2UxLm5nLmJsdWVtaXgubmV0IiwiZXhwIjoxNDg3MDg0ODc4LCJhdWQiOiIyNmNiMDEyZWIzMjdjNjEyZDkwYTY4MTkxNjNiNmJjYmQ0ODQ5Y2JiIiwiaWF0IjoxNDg3MDgxMjc4LCJhdXRoX2J5IjoiZmFjZWJvb2siLCJ0ZW5hbnQiOiI0ZGJhOTQzMC01NGU2LTRjZjItYTUxNi02ZjczZmViNzAyYmIiLCJzY29wZSI6ImFwcGlkX2RlZmF1bHQgYXBwaWRfcmVhZHByb2ZpbGUgYXBwaWRfcmVhZHVzZXJhdHRyIGFwcGlkX3dyaXRldXNlcmF0dHIifQ.HHterec250JSDY1965cM2DadBznl2wTKmzKNSnfjpdTAqax9VZvV3EwuFbEnGp9-i6AC-OlsVj7xvbALkdjwG2lZvpQx0M_gRc_3E0NiYuOGVolcm0wEXtbtDUFFqZQAf9BYYOPZ8OintdBiwUGETbH1ZRVtUvt3nalIko1OPE1Q12LvuRlhz5MClNHmvxJcXc7kucxCx4s4UFFy_HJA1gow7HWFqc9-PZf4JMWA-siYqPrdw_zYeBTBzE5co92F6JBEtGLLCjhJVz9eYgLLECXbak3z6hOaY9352Weuj7AgMOWxzw56jKKsiixMtvzrCzLVIcRUG96UJszwPHtPlA",INVALID_SIGNATURE_TOKEN:"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTU2NjMxMDg5NSwiZXhwIjoxNTY2MzE0NDk1LCJpYXQiOjE1NjYzMTA4OTUsImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciIsImF1ZCI6WyJodHRwOi8vZm9vMS5jb20iLCJodHRwOi8vZm9vMi5jb20iXX0.NBDYg8VZxW770qcbIl40OFvaQntO-FVYUUJocE5ZgcyrvFTuomwF997OcEJghO8BE_Y2m67PbfPFsbN0VI6j"}},function(t,e,i){(function(t){var i={userAgent:!1},n={}; /*! Copyright (c) 2011, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: @@ -14,16 +14,16 @@ if(void 0===r)var r={};r.lang={extend:function(t,e,n){if(!e||!t)throw new Error( * https://code.google.com/p/crypto-js/issues/detail?id=84 * https://crypto-js.googlecode.com/svn-history/r667/branches/3.x/src/core.js */ -var s,a,o,h,u,c,l,f,d,g,p,y=y||(s=Math,o=(a={}).lib={},h=o.Base=function(){function t(){}return{extend:function(e){t.prototype=this;var i=new t;return e&&i.mixIn(e),i.hasOwnProperty("init")||(i.init=function(){i.$super.init.apply(this,arguments)}),i.init.prototype=i,i.$super=this,i},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),u=o.WordArray=h.extend({init:function(t,e){t=this.words=t||[],this.sigBytes=null!=e?e:4*t.length},toString:function(t){return(t||l).stringify(this)},concat:function(t){var e=this.words,i=t.words,n=this.sigBytes,r=t.sigBytes;if(this.clamp(),n%4)for(var s=0;s>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],E=d[F],w=257*d[m]^16843008*m;s[p]=w<<24|w>>>8,a[p]=w<<16|w>>>16,o[p]=w<<8|w>>>24,h[p]=w,w=16843009*E^65537*F^257*S^16843008*p,u[m]=w<<24|w>>>8,c[m]=w<<16|w>>>16,l[m]=w<<8|w>>>24,f[m]=w,p?(p=S^d[d[d[E^S]]],v^=d[d[v]]):p=v=1}var x=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=x[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],E=t[s+13],w=t[s+14],x=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,E,12,u[13]),I=e(I,A,b,C,w,17,u[14]),b=i(b,C=e(C,I,A,b,x,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,x,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,w,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,E,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,w,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,E,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,x,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,w,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,x,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,E,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,E=h.low,w=u.high,x=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,R=p,H=y,B=v,N=m,O=S,j=F,V=E,L=w,_=x,K=b,M=A,k=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&K,Q=V&_^~V&M,z=D&P^D&H^P&H;var tt=T&R^T&B^R&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=k+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),k=K,U=M,K=L,M=_,L=j,_=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=H,O=B,H=P,B=R,P=D,R=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+R,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+H+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),E=h.low=E+V,h.high=F+j+(E>>>0>>0?1:0),x=u.low=x+_,u.high=w+L+(x>>>0<_>>>0?1:0),A=c.low=A+M,c.high=b+K+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+k+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,E=(n=h.words,u.words),w=r.words,x=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+w[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+x[i]]|0,I=16>i?I+((y^(v|~m))+E[0]):32>i?I+((y&m|v&~m)+E[1]):48>i?I+(((y|~v)^m)+E[2]):64>i?I+((y&v|~y&m)+E[3]):I+((y^v^m)+E[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],w=d[F],E=257*d[m]^16843008*m;s[p]=E<<24|E>>>8,a[p]=E<<16|E>>>16,o[p]=E<<8|E>>>24,h[p]=E,E=16843009*w^65537*F^257*S^16843008*p,u[m]=E<<24|E>>>8,c[m]=E<<16|E>>>16,l[m]=E<<8|E>>>24,f[m]=E,p?(p=S^d[d[d[w^S]]],v^=d[d[v]]):p=v=1}var x=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=x[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],w=t[s+13],E=t[s+14],x=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,w,12,u[13]),I=e(I,A,b,C,E,17,u[14]),b=i(b,C=e(C,I,A,b,x,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,x,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,E,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,w,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,E,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,w,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,x,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,E,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,x,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,w,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,w=h.low,E=u.high,x=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,R=p,H=y,B=v,N=m,O=S,j=F,V=w,L=E,_=x,K=b,k=A,M=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&K,Q=V&_^~V&k,z=D&P^D&H^P&H;var tt=T&R^T&B^R&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=M+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),M=K,U=k,K=L,k=_,L=j,_=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=H,O=B,H=P,B=R,P=D,R=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+R,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+H+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),w=h.low=w+V,h.high=F+j+(w>>>0>>0?1:0),x=u.low=x+_,u.high=E+L+(x>>>0<_>>>0?1:0),A=c.low=A+k,c.high=b+K+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+M+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,w=(n=h.words,u.words),E=r.words,x=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+E[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+x[i]]|0,I=16>i?I+((y^(v|~m))+w[0]):32>i?I+((y&m|v&~m)+w[1]):48>i?I+(((y|~v)^m)+w[2]):64>i?I+((y&v|~y&m)+w[3]):I+((y^v^m)+w[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function E(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function w(t){var e,i=E(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(x.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(x.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),x.prototype.DB=v,x.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function K(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function M(){}function k(t){return t}function U(t){this.r2=b(),this.q3=b(),x.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(x.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},x.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},x.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},x.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},x.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},x.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},x.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},x.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},x.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),x.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&x.ZERO.subTo(i,i)}}},x.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},x.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},x.prototype.exp=function(t,e){if(t>4294967295||t<1)return x.ONE;var i=b(),n=b(),r=e.convert(this),s=H(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},x.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},x.prototype.negate=function(){var t=b();return x.ZERO.subTo(this,t),t},x.prototype.abs=function(){return this.s<0?this.negate():this},x.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},x.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+H(this[this.t-1]^this.s&this.DM)},x.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(x.ZERO)>0&&t.subTo(e,e),e},x.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},x.ZERO=R(0),x.ONE=R(1),M.prototype.convert=k,M.prototype.revert=k,M.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},M.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; +var v,m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",S="=";function F(t){var e,i,n="";for(e=0;e+3<=t.length;e+=3)i=parseInt(t.substring(e,e+3),16),n+=m.charAt(i>>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function w(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function E(t){var e,i=w(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(x.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(x.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),x.prototype.DB=v,x.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function K(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function k(){}function M(t){return t}function U(t){this.r2=b(),this.q3=b(),x.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(x.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},x.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},x.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},x.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},x.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},x.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},x.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},x.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},x.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),x.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&x.ZERO.subTo(i,i)}}},x.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},x.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},x.prototype.exp=function(t,e){if(t>4294967295||t<1)return x.ONE;var i=b(),n=b(),r=e.convert(this),s=H(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},x.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},x.prototype.negate=function(){var t=b();return x.ZERO.subTo(this,t),t},x.prototype.abs=function(){return this.s<0?this.negate():this},x.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},x.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+H(this[this.t-1]^this.s&this.DM)},x.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(x.ZERO)>0&&t.subTo(e,e),e},x.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},x.ZERO=R(0),x.ONE=R(1),k.prototype.convert=M,k.prototype.revert=M,k.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},k.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ function Y(){this.i=0,this.j=0,this.S=new Array}x.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},x.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),n=R(i),r=b(),s=b(),a="";for(this.divRemTo(n,r,s);r.signum()>0;)a=(i+s.intValue()).toString(t).substr(1)+a,r.divRemTo(n,r,s);return s.intValue().toString(t)+a},x.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),n=Math.pow(e,i),r=!1,s=0,a=0,o=0;o=i&&(this.dMultiply(n),this.dAddOffset(a,0),s=0,a=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(a,0)),r&&x.ZERO.subTo(this,this)},x.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(x.ONE.shiftLeft(t-1),j,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(x.ONE.shiftLeft(t-1),this);else{var n=new Array,r=7&t;n.length=1+(t>>3),e.nextBytes(n),r>0?n[0]&=(1<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[i++]=n:n<-1&&(e[i++]=this.DV+n),e.t=i,e.clamp()},x.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},x.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},x.prototype.multiplyLowerTo=function(t,e,i){var n,r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;r>0;)i[--r]=0;for(n=i.t-this.t;r=0;)i[n]=0;for(n=Math.max(e-this.t,0);n0)if(0==e)i=this[0]%t;else for(var n=this.t-1;n>=0;--n)i=(e*i+this[n])%t;return i},x.prototype.millerRabin=function(t){var e=this.subtract(x.ONE),i=e.getLowestSetBit();if(i<=0)return!1;var n=e.shiftRight(i);(t=t+1>>1)>q.length&&(t=q.length);for(var r=b(),s=0;s>24},x.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},x.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},x.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},x.prototype.equals=function(t){return 0==this.compareTo(t)},x.prototype.min=function(t){return this.compareTo(t)<0?this:t},x.prototype.max=function(t){return this.compareTo(t)>0?this:t},x.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},x.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},x.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},x.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},x.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=H(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(x.ONE)?x.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},x.prototype.pow=function(t){return this.exp(t,new M)},x.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},x.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>24},x.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},x.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},x.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},x.prototype.equals=function(t){return 0==this.compareTo(t)},x.prototype.min=function(t){return this.compareTo(t)<0?this:t},x.prototype.max=function(t){return this.compareTo(t)>0?this:t},x.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},x.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},x.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},x.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},x.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=H(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(x.ONE)?x.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},x.prototype.pow=function(t){return this.exp(t,new k)},x.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},x.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>8&255,J[W++]^=t>>16&255,J[W++]^=t>>24&255,W>=X&&(W-=X)}((new Date).getTime())}if(null==J){var $;if(J=new Array,W=0,void 0!==n&&(void 0!==n.crypto||void 0!==n.msCrypto)){var Q=n.crypto||n.msCrypto;if(Q.getRandomValues){var tt=new Uint8Array(32);for(Q.getRandomValues(tt),$=0;$<32;++$)J[W++]=tt[$]}else if("Netscape"==i.appName&&i.appVersion<"5"){var et=n.crypto.random(32);for($=0;$>>8,J[W++]=255&$;W=0,Z()}function it(){if(null==G){for(Z(),(G=new Y).init(J),W=0;Wi.length;)i.unshift(0);return i},i=this.getX().toBigInteger(),n=this.getY().toBigInteger(),r=e(i,32);return t?n.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(e(n,32))),r},ut.decodeFrom=function(t,e){e[0];var i=e.length-1,n=e.slice(1,1+i/2),r=e.slice(1+i/2,1+i);n.unshift(0),r.unshift(0);var s=new x(n),a=new x(r);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.decodeFromHex=function(t,e){e.substr(0,2);var i=e.length-2,n=e.substr(2,i/2),r=e.substr(2+i/2,i/2),s=new x(n,16),a=new x(r,16);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.prototype.add2D=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();var e=t.x.subtract(this.x),i=t.y.subtract(this.y).divide(e),n=i.square().subtract(this.x).subtract(t.x),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=this.curve.fromBigInteger(x.valueOf(2)),e=this.curve.fromBigInteger(x.valueOf(3)),i=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),n=i.square().subtract(this.x.multiply(t)),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new x("3")),r=this.negate(),s=this;for(e=n.bitLength()-2;e>0;--e){s=s.twice();var a=n.testBit(e);a!=i.testBit(e)&&(s=s.add2D(a?this:r))}return s},ut.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),i=this.curve.getA().toBigInteger(),n=this.curve.getB().toBigInteger(),r=this.curve.getQ(),s=e.multiply(e).mod(r),a=t.multiply(t).multiply(t).add(i.multiply(t)).add(n).mod(r);return s.equals(a)},ut.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},ut.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),i=this.getY().toBigInteger();if(e.compareTo(x.ONE)<0||e.compareTo(t.subtract(x.ONE))>0)throw new Error("x coordinate out of bounds");if(i.compareTo(x.ONE)<0||i.compareTo(t.subtract(x.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0}; /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval */ -var lt=function(){var t=new RegExp('(?:false|true|null|[\\{\\}\\[\\]]|(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)|(?:"(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))*"))',"g"),e=new RegExp("\\\\(?:([^u])|u(.{4}))","g"),i={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function n(t,e,n){return e?i[e]:String.fromCharCode(parseInt(n,16))}var r=new String(""),s=(Object,Array,Object.hasOwnProperty);return function(i,a){var o,h,u=i.match(t),c=u[0],l=!1;"{"===c?o={}:"["===c?o=[]:(o=[],l=!0);for(var f=[o],d=1-l,g=u.length;d=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map((function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Ht;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map((function(t){return t.replace("/","\\/")}))).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Ht;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Ht(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Rt(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),E=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=E,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var w=0;w1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Ht(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Ht(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Ht,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Ht(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(R=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(R,0,[2],"02"),E=r(R,0,[3],"02"),w=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(R=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(R,0,[2,0],"06"),P=r(R,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var R;S=r(R=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(R,0,[2],"02"),E=r(R,0,[3],"02"),w=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(E,16),new x(w,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Rt(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),E=m(t).getEncodedHex(),w="";return w+=Rt(F,"EC PARAMETERS"),w+=Rt(E,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(E=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(E=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Ht(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e.d=wt(t.d.toString(16)),e.p=wt(t.p.toString(16)),e.q=wt(t.q.toString(16)),e.dp=wt(t.dmp1.toString(16)),e.dq=wt(t.dmq1.toString(16)),e.qi=wt(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=wt(t.n.toString(16)),e.e=wt(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e.d=wt(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=wt(i.x),e.y=wt(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Ht(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Ht;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=E,e.b64toBA=w,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(w(Et(t)))},e.b64tob64u=Ft,e.b64utob64=Et,e.hex2b64=F,e.hextob64u=wt,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(E(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Rt,e.pemtohex=Ht,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function Mt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map((function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Ht;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map((function(t){return t.replace("/","\\/")}))).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Ht;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=Mt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Ht(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Rt(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),w=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=w,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var E=0;E1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Ht(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Ht(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Ht,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Ht(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(R=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(R,0,[2],"02"),w=r(R,0,[3],"02"),E=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(R=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(R,0,[2,0],"06"),P=r(R,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var R;S=r(R=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(R,0,[2],"02"),w=r(R,0,[3],"02"),E=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Rt(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),w=m(t).getEncodedHex(),E="";return E+=Rt(F,"EC PARAMETERS"),E+=Rt(w,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Ht(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e.d=Et(t.d.toString(16)),e.p=Et(t.p.toString(16)),e.q=Et(t.q.toString(16)),e.dp=Et(t.dmp1.toString(16)),e.dq=Et(t.dmq1.toString(16)),e.qi=Et(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e.d=Et(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Ht(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Ht;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=w,e.b64toBA=E,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(E(wt(t)))},e.b64tob64u=Ft,e.b64utob64=wt,e.hex2b64=F,e.hextob64u=Et,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(w(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Rt,e.pemtohex=Ht,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp * @license MIT */ -var n=i(9),r=i(10),s=i(11);function a(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return M(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return k(t).length;default:if(n)return M(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return E(this,t,e,i);case"latin1":case"binary":return w(this,t,e,i);case"base64":return x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||H(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||H(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||H(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||H(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||H(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||H(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||H(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||H(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||H(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||H(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function k(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(_,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(8))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e){t.exports=class extends Error{constructor({error:t,description:e}){super(e||t),this.error=t,this.description=e}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(17);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){const e=t.height,i=t.width,r=(screen.width-i)/2,s=(screen.height-e)/2;if(this.popup=this.window.open("","popup",`left=${r},top=${s},width=${i},height=${e},resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(19);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}}]); \ No newline at end of file +var n=i(9),r=i(10),s=i(11);function a(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return k(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return M(t).length;default:if(n)return k(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return w(this,t,e,i);case"latin1":case"binary":return E(this,t,e,i);case"base64":return x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||H(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||H(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||H(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||H(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||H(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||H(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||H(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||H(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||H(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||H(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function M(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(_,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(8))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e){t.exports=class extends Error{constructor({error:t,description:e}){super(e||t),this.error=t,this.description=e}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(17);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){const e=t.height,i=t.width,r=(screen.width-i)/2,s=(screen.height-e)/2;if(this.popup=this.window.open("","popup",`left=${r},top=${s},width=${i},height=${e},resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(19);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}}]); \ No newline at end of file diff --git a/dist/appid.umd.min.js b/dist/appid.umd.min.js index c283e6e..ff83b16 100644 --- a/dist/appid.umd.min.js +++ b/dist/appid.umd.min.js @@ -1,4 +1,4 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AppID=e():t.AppID=e()}(window,(function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=5)}([function(t,e){t.exports={MALFORMED_TOKEN:"Invalid JWT token. Got only 2 parts.",INVALID_SIGNATURE:"Invalid signature",INVALID_VERSION:"Invalid version",INVALID_ALGORITHM:"Invalid algorithm",INVALID_ISSUER:"Invalid issuer",INVALID_AUDIENCE:"Invalid audience",INVALID_NONCE:"Invalid nonce",EXPIRED_TOKEN:"Expired token",INVALID_STATE:"Invalid state",INVALID_ORIGIN:"Invalid origin",INVALID_TOKEN:"Invalid token",MISSING_PUBLIC_KEY:"Cannot find public key",INVALID_ACCESS_TOKEN:"Access token must be a string",MISSING_CLIENT_ID:"Missing client ID",MISSING_DISCOVERY_ENDPOINT:"Missing discovery endpoint",RESPONSE_TYPE:"code",RESPONSE_MODE:"web_message",PROMPT:"none",SCOPE:"openid",STATE_LENGTH:20,NONCE_LENGTH:20,CODE_VERIFIER_LENGTH:44,CHALLENGE_METHOD:"S256",TOKEN_ALG:"RS256",VERSION:4,MALFORMED_ACCESS_TOKEN:"eyJpc3MiOiJtb2JpbGVjbGllbnRhY2Nlc3Muc3RhZ2UxLm5nLmJsdWVtaXgubmV0IiwiZXhwIjoxNDg3MDg0ODc4LCJhdWQiOiIyNmNiMDEyZWIzMjdjNjEyZDkwYTY4MTkxNjNiNmJjYmQ0ODQ5Y2JiIiwiaWF0IjoxNDg3MDgxMjc4LCJhdXRoX2J5IjoiZmFjZWJvb2siLCJ0ZW5hbnQiOiI0ZGJhOTQzMC01NGU2LTRjZjItYTUxNi02ZjczZmViNzAyYmIiLCJzY29wZSI6ImFwcGlkX2RlZmF1bHQgYXBwaWRfcmVhZHByb2ZpbGUgYXBwaWRfcmVhZHVzZXJhdHRyIGFwcGlkX3dyaXRldXNlcmF0dHIifQ.HHterec250JSDY1965cM2DadBznl2wTKmzKNSnfjpdTAqax9VZvV3EwuFbEnGp9-i6AC-OlsVj7xvbALkdjwG2lZvpQx0M_gRc_3E0NiYuOGVolcm0wEXtbtDUFFqZQAf9BYYOPZ8OintdBiwUGETbH1ZRVtUvt3nalIko1OPE1Q12LvuRlhz5MClNHmvxJcXc7kucxCx4s4UFFy_HJA1gow7HWFqc9-PZf4JMWA-siYqPrdw_zYeBTBzE5co92F6JBEtGLLCjhJVz9eYgLLECXbak3z6hOaY9352Weuj7AgMOWxzw56jKKsiixMtvzrCzLVIcRUG96UJszwPHtPlA",INVALID_SIGNATURE_TOKEN:"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTU2NjMxMDg5NSwiZXhwIjoxNTY2MzE0NDk1LCJpYXQiOjE1NjYzMTA4OTUsImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciIsImF1ZCI6WyJodHRwOi8vZm9vMS5jb20iLCJodHRwOi8vZm9vMi5jb20iXX0.NBDYg8VZxW770qcbIl40OFvaQntO-FVYUUJocE5ZgcyrvFTuomwF997OcEJghO8BE_Y2m67PbfPFsbN0VI6j"}},function(t,e,i){(function(t){var i={userAgent:!1},n={}; +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AppID=e():t.AppID=e()}(window,(function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=5)}([function(t,e){t.exports={MALFORMED_TOKEN:"Invalid JWT token. Got only 2 parts.",INVALID_SIGNATURE:"Invalid signature",INVALID_VERSION:"Invalid version",INVALID_ALGORITHM:"Invalid algorithm",INVALID_ISSUER:"Invalid issuer",INVALID_AUDIENCE:"Invalid audience",INVALID_NONCE:"Invalid nonce",EXPIRED_TOKEN:"Expired token",INVALID_STATE:"Invalid state",INVALID_ORIGIN:"Invalid origin",INVALID_TOKEN:"Invalid token",MISSING_PUBLIC_KEY:"Cannot find public key",INVALID_ACCESS_TOKEN:"Access token must be a string",MISSING_CLIENT_ID:"Missing client ID",INVALID_DISCOVERY_ENDPOINT:"Invalid discovery endpoint",RESPONSE_TYPE:"code",RESPONSE_MODE:"web_message",PROMPT:"none",SCOPE:"openid",STATE_LENGTH:20,NONCE_LENGTH:20,CODE_VERIFIER_LENGTH:44,CHALLENGE_METHOD:"S256",TOKEN_ALG:"RS256",VERSION:4,MALFORMED_ACCESS_TOKEN:"eyJpc3MiOiJtb2JpbGVjbGllbnRhY2Nlc3Muc3RhZ2UxLm5nLmJsdWVtaXgubmV0IiwiZXhwIjoxNDg3MDg0ODc4LCJhdWQiOiIyNmNiMDEyZWIzMjdjNjEyZDkwYTY4MTkxNjNiNmJjYmQ0ODQ5Y2JiIiwiaWF0IjoxNDg3MDgxMjc4LCJhdXRoX2J5IjoiZmFjZWJvb2siLCJ0ZW5hbnQiOiI0ZGJhOTQzMC01NGU2LTRjZjItYTUxNi02ZjczZmViNzAyYmIiLCJzY29wZSI6ImFwcGlkX2RlZmF1bHQgYXBwaWRfcmVhZHByb2ZpbGUgYXBwaWRfcmVhZHVzZXJhdHRyIGFwcGlkX3dyaXRldXNlcmF0dHIifQ.HHterec250JSDY1965cM2DadBznl2wTKmzKNSnfjpdTAqax9VZvV3EwuFbEnGp9-i6AC-OlsVj7xvbALkdjwG2lZvpQx0M_gRc_3E0NiYuOGVolcm0wEXtbtDUFFqZQAf9BYYOPZ8OintdBiwUGETbH1ZRVtUvt3nalIko1OPE1Q12LvuRlhz5MClNHmvxJcXc7kucxCx4s4UFFy_HJA1gow7HWFqc9-PZf4JMWA-siYqPrdw_zYeBTBzE5co92F6JBEtGLLCjhJVz9eYgLLECXbak3z6hOaY9352Weuj7AgMOWxzw56jKKsiixMtvzrCzLVIcRUG96UJszwPHtPlA",INVALID_SIGNATURE_TOKEN:"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTU2NjMxMDg5NSwiZXhwIjoxNTY2MzE0NDk1LCJpYXQiOjE1NjYzMTA4OTUsImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciIsImF1ZCI6WyJodHRwOi8vZm9vMS5jb20iLCJodHRwOi8vZm9vMi5jb20iXX0.NBDYg8VZxW770qcbIl40OFvaQntO-FVYUUJocE5ZgcyrvFTuomwF997OcEJghO8BE_Y2m67PbfPFsbN0VI6j"}},function(t,e,i){(function(t){var i={userAgent:!1},n={}; /*! Copyright (c) 2011, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: @@ -14,16 +14,16 @@ if(void 0===r)var r={};r.lang={extend:function(t,e,n){if(!e||!t)throw new Error( * https://code.google.com/p/crypto-js/issues/detail?id=84 * https://crypto-js.googlecode.com/svn-history/r667/branches/3.x/src/core.js */ -var s,a,o,h,u,c,l,f,d,g,p,y=y||(s=Math,o=(a={}).lib={},h=o.Base=function(){function t(){}return{extend:function(e){t.prototype=this;var i=new t;return e&&i.mixIn(e),i.hasOwnProperty("init")||(i.init=function(){i.$super.init.apply(this,arguments)}),i.init.prototype=i,i.$super=this,i},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),u=o.WordArray=h.extend({init:function(t,e){t=this.words=t||[],this.sigBytes=null!=e?e:4*t.length},toString:function(t){return(t||l).stringify(this)},concat:function(t){var e=this.words,i=t.words,n=this.sigBytes,r=t.sigBytes;if(this.clamp(),n%4)for(var s=0;s>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],w=d[F],E=257*d[m]^16843008*m;s[p]=E<<24|E>>>8,a[p]=E<<16|E>>>16,o[p]=E<<8|E>>>24,h[p]=E,E=16843009*w^65537*F^257*S^16843008*p,u[m]=E<<24|E>>>8,c[m]=E<<16|E>>>16,l[m]=E<<8|E>>>24,f[m]=E,p?(p=S^d[d[d[w^S]]],v^=d[d[v]]):p=v=1}var x=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=x[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],w=t[s+13],E=t[s+14],x=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,w,12,u[13]),I=e(I,A,b,C,E,17,u[14]),b=i(b,C=e(C,I,A,b,x,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,x,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,E,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,w,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,E,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,w,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,x,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,E,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,x,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,w,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,w=h.low,E=u.high,x=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,R=p,H=y,B=v,N=m,O=S,j=F,V=w,L=E,_=x,K=b,M=A,k=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&K,Q=V&_^~V&M,z=D&P^D&H^P&H;var tt=T&R^T&B^R&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=k+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),k=K,U=M,K=L,M=_,L=j,_=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=H,O=B,H=P,B=R,P=D,R=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+R,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+H+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),w=h.low=w+V,h.high=F+j+(w>>>0>>0?1:0),x=u.low=x+_,u.high=E+L+(x>>>0<_>>>0?1:0),A=c.low=A+M,c.high=b+K+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+k+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,w=(n=h.words,u.words),E=r.words,x=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+E[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+x[i]]|0,I=16>i?I+((y^(v|~m))+w[0]):32>i?I+((y&m|v&~m)+w[1]):48>i?I+(((y|~v)^m)+w[2]):64>i?I+((y&v|~y&m)+w[3]):I+((y^v^m)+w[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>>2]>>>24-s%4*8&255;e[n+s>>>2]|=a<<24-(n+s)%4*8}else for(s=0;s>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-e%4*8,t.length=s.ceil(e/4)},clone:function(){var t=h.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i>>2]>>>24-r%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new u.init(i,e/2)}},f=c.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],r=0;r>>2]>>>24-r%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new u.init(i,e)}},d=c.Utf8={stringify:function(t){try{return decodeURIComponent(escape(f.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return f.parse(unescape(encodeURIComponent(t)))}},g=o.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=d.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(t){var e=this._data,i=e.words,n=e.sigBytes,r=this.blockSize,a=n/(4*r),o=(a=t?s.ceil(a):s.max((0|a)-this._minBufferSize,0))*r,h=s.min(4*o,n);if(o){for(var c=0;c>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:h,padding:c}),reset:function(){o.reset.call(this);var t=(e=this.cfg).iv,e=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else i=e.createDecryptor,this._minBufferSize=1;this._mode=i.call(e,this,t&&t.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else e=this._process(!0),t.unpad(e);return e},blockSize:4});var l=e.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),f=(h=(d.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext;return((t=t.salt)?n.create([1398893684,1701076831]).concat(t).concat(e):e).toString(s)},parse:function(t){var e=(t=s.parse(t)).words;if(1398893684==e[0]&&1701076831==e[1]){var i=n.create(e.slice(2,4));e.splice(0,4),t.sigBytes-=16}return l.create({ciphertext:t,salt:i})}},e.SerializableCipher=i.extend({cfg:i.extend({format:h}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var r=t.createEncryptor(i,n);return e=r.finalize(e),r=r.cfg,l.create({ciphertext:e,key:i,iv:r.iv,algorithm:t,mode:r.mode,padding:r.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}})),d=(d.kdf={}).OpenSSL={execute:function(t,e,i,r){return r||(r=n.random(8)),t=a.create({keySize:e+i}).compute(t,r),i=n.create(t.words.slice(e),4*i),t.sigBytes=4*e,l.create({key:t,iv:i,salt:r})}},g=e.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:d}),encrypt:function(t,e,i,n){return i=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize),n.iv=i.iv,(t=f.encrypt.call(this,t,e,i.key,n)).mixIn(i),t},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),i=n.kdf.execute(i,t.keySize,t.ivSize,e.salt),n.iv=i.iv,f.decrypt.call(this,t,e,i.key,n)}})}(),function(){for(var t=y,e=t.lib.BlockCipher,i=t.algo,n=[],r=[],s=[],a=[],o=[],h=[],u=[],c=[],l=[],f=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;var p=0,v=0;for(g=0;256>g;g++){var m=(m=v^v<<1^v<<2^v<<3^v<<4)>>>8^255&m^99;n[p]=m,r[m]=p;var S=d[p],F=d[S],w=d[F],E=257*d[m]^16843008*m;s[p]=E<<24|E>>>8,a[p]=E<<16|E>>>16,o[p]=E<<8|E>>>24,h[p]=E,E=16843009*w^65537*F^257*S^16843008*p,u[m]=E<<24|E>>>8,c[m]=E<<16|E>>>16,l[m]=E<<8|E>>>24,f[m]=E,p?(p=S^d[d[d[w^S]]],v^=d[d[v]]):p=v=1}var x=[0,1,2,4,8,16,32,64,128,27,54];i=i.AES=e.extend({_doReset:function(){for(var t=(i=this._key).words,e=i.sigBytes/4,i=4*((this._nRounds=e+6)+1),r=this._keySchedule=[],s=0;s>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a]):(a=n[(a=a<<8|a>>>24)>>>24]<<24|n[a>>>16&255]<<16|n[a>>>8&255]<<8|n[255&a],a^=x[s/e|0]<<24),r[s]=r[s-e]^a}for(t=this._invKeySchedule=[],e=0;ee||4>=s?a:u[n[a>>>24]]^c[n[a>>>16&255]]^l[n[a>>>8&255]]^f[n[255&a]]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,s,a,o,h,n)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,u,c,l,f,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,r,s,a,o){for(var h=this._nRounds,u=t[e]^i[0],c=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],d=4,g=1;g>>24]^r[c>>>16&255]^s[l>>>8&255]^a[255&f]^i[d++],y=n[c>>>24]^r[l>>>16&255]^s[f>>>8&255]^a[255&u]^i[d++],v=n[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^a[255&c]^i[d++];f=n[f>>>24]^r[u>>>16&255]^s[c>>>8&255]^a[255&l]^i[d++],u=p,c=y,l=v}p=(o[u>>>24]<<24|o[c>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[d++],y=(o[c>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&u])^i[d++],v=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[u>>>8&255]<<8|o[255&c])^i[d++],f=(o[f>>>24]<<24|o[u>>>16&255]<<16|o[c>>>8&255]<<8|o[255&l])^i[d++],t[e]=p,t[e+1]=y,t[e+2]=v,t[e+3]=f},keySize:8});t.AES=e._createHelper(i)}(),function(){function t(t,e){var i=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=i,this._lBlock^=i<>>t^this._lBlock)&e;this._lBlock^=i,this._rBlock^=i<i;i++){var n=a[i]-1;e[i]=t[n>>>5]>>>31-n%32&1}for(t=this._subKeys=[],n=0;16>n;n++){var r=t[n]=[],s=h[n];for(i=0;24>i;i++)r[i/6|0]|=e[(o[i]-1+s)%28]<<31-i%6,r[4+(i/6|0)]|=e[28+(o[i+24]-1+s)%28]<<31-i%6;for(r[0]=r[0]<<1|r[0]>>>31,i=1;7>i;i++)r[i]>>>=4*(i-1)+3;r[7]=r[7]<<5|r[7]>>>27}for(e=this._invSubKeys=[],i=0;16>i;i++)e[i]=t[15-i]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(i,n,r){this._lBlock=i[n],this._rBlock=i[n+1],t.call(this,4,252645135),t.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),t.call(this,1,1431655765);for(var s=0;16>s;s++){for(var a=r[s],o=this._lBlock,h=this._rBlock,l=0,f=0;8>f;f++)l|=u[f][((h^a[f])&c[f])>>>0];this._lBlock=h,this._rBlock=o^l}r=this._lBlock,this._lBlock=this._rBlock,this._rBlock=r,t.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),t.call(this,16,65535),t.call(this,4,252645135),i[n]=this._lBlock,i[n+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=r._createHelper(l),s=s.TripleDES=r.extend({_doReset:function(){var t=this._key.words;this._des1=l.createEncryptor(n.create(t.slice(0,2))),this._des2=l.createEncryptor(n.create(t.slice(2,4))),this._des3=l.createEncryptor(n.create(t.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2}),i.TripleDES=r._createHelper(s)}(),function(){var t=y,e=t.lib.WordArray;t.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp(),t=[];for(var r=0;r>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(e=n.charAt(64))for(;t.length%4;)t.push(e);return t.join("")},parse:function(t){var i=t.length,n=this._map;(r=n.charAt(64))&&(-1!=(r=t.indexOf(r))&&(i=r));for(var r=[],s=0,a=0;a>>6-a%4*2;r[s>>>2]|=(o|h)<<24-s%4*8,s++}return e.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(t){function e(t,e,i,n,r,s,a){return((t=t+(e&i|~e&n)+r+a)<>>32-s)+e}function i(t,e,i,n,r,s,a){return((t=t+(e&n|i&~n)+r+a)<>>32-s)+e}function n(t,e,i,n,r,s,a){return((t=t+(e^i^n)+r+a)<>>32-s)+e}function r(t,e,i,n,r,s,a){return((t=t+(i^(e|~n))+r+a)<>>32-s)+e}for(var s=y,a=(h=s.lib).WordArray,o=h.Hasher,h=s.algo,u=[],c=0;64>c;c++)u[c]=4294967296*t.abs(t.sin(c+1))|0;h=h.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,s){for(var a=0;16>a;a++){var o=t[h=s+a];t[h]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var h=t[s+0],c=(o=t[s+1],t[s+2]),l=t[s+3],f=t[s+4],d=t[s+5],g=t[s+6],p=t[s+7],y=t[s+8],v=t[s+9],m=t[s+10],S=t[s+11],F=t[s+12],w=t[s+13],E=t[s+14],x=t[s+15],b=e(b=a[0],C=a[1],I=a[2],A=a[3],h,7,u[0]),A=e(A,b,C,I,o,12,u[1]),I=e(I,A,b,C,c,17,u[2]),C=e(C,I,A,b,l,22,u[3]);b=e(b,C,I,A,f,7,u[4]),A=e(A,b,C,I,d,12,u[5]),I=e(I,A,b,C,g,17,u[6]),C=e(C,I,A,b,p,22,u[7]),b=e(b,C,I,A,y,7,u[8]),A=e(A,b,C,I,v,12,u[9]),I=e(I,A,b,C,m,17,u[10]),C=e(C,I,A,b,S,22,u[11]),b=e(b,C,I,A,F,7,u[12]),A=e(A,b,C,I,w,12,u[13]),I=e(I,A,b,C,E,17,u[14]),b=i(b,C=e(C,I,A,b,x,22,u[15]),I,A,o,5,u[16]),A=i(A,b,C,I,g,9,u[17]),I=i(I,A,b,C,S,14,u[18]),C=i(C,I,A,b,h,20,u[19]),b=i(b,C,I,A,d,5,u[20]),A=i(A,b,C,I,m,9,u[21]),I=i(I,A,b,C,x,14,u[22]),C=i(C,I,A,b,f,20,u[23]),b=i(b,C,I,A,v,5,u[24]),A=i(A,b,C,I,E,9,u[25]),I=i(I,A,b,C,l,14,u[26]),C=i(C,I,A,b,y,20,u[27]),b=i(b,C,I,A,w,5,u[28]),A=i(A,b,C,I,c,9,u[29]),I=i(I,A,b,C,p,14,u[30]),b=n(b,C=i(C,I,A,b,F,20,u[31]),I,A,d,4,u[32]),A=n(A,b,C,I,y,11,u[33]),I=n(I,A,b,C,S,16,u[34]),C=n(C,I,A,b,E,23,u[35]),b=n(b,C,I,A,o,4,u[36]),A=n(A,b,C,I,f,11,u[37]),I=n(I,A,b,C,p,16,u[38]),C=n(C,I,A,b,m,23,u[39]),b=n(b,C,I,A,w,4,u[40]),A=n(A,b,C,I,h,11,u[41]),I=n(I,A,b,C,l,16,u[42]),C=n(C,I,A,b,g,23,u[43]),b=n(b,C,I,A,v,4,u[44]),A=n(A,b,C,I,F,11,u[45]),I=n(I,A,b,C,x,16,u[46]),b=r(b,C=n(C,I,A,b,c,23,u[47]),I,A,h,6,u[48]),A=r(A,b,C,I,p,10,u[49]),I=r(I,A,b,C,E,15,u[50]),C=r(C,I,A,b,d,21,u[51]),b=r(b,C,I,A,F,6,u[52]),A=r(A,b,C,I,l,10,u[53]),I=r(I,A,b,C,m,15,u[54]),C=r(C,I,A,b,o,21,u[55]),b=r(b,C,I,A,y,6,u[56]),A=r(A,b,C,I,x,10,u[57]),I=r(I,A,b,C,g,15,u[58]),C=r(C,I,A,b,w,21,u[59]),b=r(b,C,I,A,f,6,u[60]),A=r(A,b,C,I,S,10,u[61]),I=r(I,A,b,C,c,15,u[62]),C=r(C,I,A,b,v,21,u[63]);a[0]=a[0]+b|0,a[1]=a[1]+C|0,a[2]=a[2]+I|0,a[3]=a[3]+A|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;i[r>>>5]|=128<<24-r%32;var s=t.floor(n/4294967296);for(i[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),i[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),e.sigBytes=4*(i.length+1),this._process(),i=(e=this._hash).words,n=0;4>n;n++)r=i[n],i[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return e},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}}),s.MD5=o._createHelper(h),s.HmacMD5=o._createHmacHelper(h)}(Math),function(){var t=y,e=(r=t.lib).WordArray,i=r.Hasher,n=[],r=t.algo.SHA1=i.extend({_doReset:function(){this._hash=new e.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,r=i[0],s=i[1],a=i[2],o=i[3],h=i[4],u=0;80>u;u++){if(16>u)n[u]=0|t[e+u];else{var c=n[u-3]^n[u-8]^n[u-14]^n[u-16];n[u]=c<<1|c>>>31}c=(r<<5|r>>>27)+h+n[u],c=20>u?c+(1518500249+(s&a|~s&o)):40>u?c+(1859775393+(s^a^o)):60>u?c+((s&a|s&o|a&o)-1894007588):c+((s^a^o)-899497514),h=o,o=a,a=s<<30|s>>>2,s=r,r=c}i[0]=i[0]+r|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.SHA1=i._createHelper(r),t.HmacSHA1=i._createHmacHelper(r)}(),function(t){for(var e=y,i=(r=e.lib).WordArray,n=r.Hasher,r=e.algo,s=[],a=[],o=function(t){return 4294967296*(t-(0|t))|0},h=2,u=0;64>u;){var c;t:{c=h;for(var l=t.sqrt(c),f=2;f<=l;f++)if(!(c%f)){c=!1;break t}c=!0}c&&(8>u&&(s[u]=o(t.pow(h,.5))),a[u]=o(t.pow(h,1/3)),u++),h++}var d=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new i.init(s.slice(0))},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],r=i[1],s=i[2],o=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=0;64>f;f++){if(16>f)d[f]=0|t[e+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=l+((h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25))+(h&u^~h&c)+a[f]+d[f],p=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&s^r&s),l=c,c=u,u=h,h=o+g|0,o=s,s=r,r=n,n=g+p|0}i[0]=i[0]+n|0,i[1]=i[1]+r|0,i[2]=i[2]+s|0,i[3]=i[3]+o|0,i[4]=i[4]+h|0,i[5]=i[5]+u|0,i[6]=i[6]+c|0,i[7]=i[7]+l|0},_doFinalize:function(){var e=this._data,i=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return i[r>>>5]|=128<<24-r%32,i[14+(r+64>>>9<<4)]=t.floor(n/4294967296),i[15+(r+64>>>9<<4)]=n,e.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=n._createHelper(r),e.HmacSHA256=n._createHmacHelper(r)}(Math),function(){var t=y,e=t.lib.WordArray,i=(n=t.algo).SHA256,n=n.SHA224=i.extend({_doReset:function(){this._hash=new e.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=i._doFinalize.call(this);return t.sigBytes-=4,t}});t.SHA224=i._createHelper(n),t.HmacSHA224=i._createHmacHelper(n)}(),function(){function t(){return n.create.apply(n,arguments)}for(var e=y,i=e.lib.Hasher,n=(s=e.x64).Word,r=s.WordArray,s=e.algo,a=[t(1116352408,3609767458),t(1899447441,602891725),t(3049323471,3964484399),t(3921009573,2173295548),t(961987163,4081628472),t(1508970993,3053834265),t(2453635748,2937671579),t(2870763221,3664609560),t(3624381080,2734883394),t(310598401,1164996542),t(607225278,1323610764),t(1426881987,3590304994),t(1925078388,4068182383),t(2162078206,991336113),t(2614888103,633803317),t(3248222580,3479774868),t(3835390401,2666613458),t(4022224774,944711139),t(264347078,2341262773),t(604807628,2007800933),t(770255983,1495990901),t(1249150122,1856431235),t(1555081692,3175218132),t(1996064986,2198950837),t(2554220882,3999719339),t(2821834349,766784016),t(2952996808,2566594879),t(3210313671,3203337956),t(3336571891,1034457026),t(3584528711,2466948901),t(113926993,3758326383),t(338241895,168717936),t(666307205,1188179964),t(773529912,1546045734),t(1294757372,1522805485),t(1396182291,2643833823),t(1695183700,2343527390),t(1986661051,1014477480),t(2177026350,1206759142),t(2456956037,344077627),t(2730485921,1290863460),t(2820302411,3158454273),t(3259730800,3505952657),t(3345764771,106217008),t(3516065817,3606008344),t(3600352804,1432725776),t(4094571909,1467031594),t(275423344,851169720),t(430227734,3100823752),t(506948616,1363258195),t(659060556,3750685593),t(883997877,3785050280),t(958139571,3318307427),t(1322822218,3812723403),t(1537002063,2003034995),t(1747873779,3602036899),t(1955562222,1575990012),t(2024104815,1125592928),t(2227730452,2716904306),t(2361852424,442776044),t(2428436474,593698344),t(2756734187,3733110249),t(3204031479,2999351573),t(3329325298,3815920427),t(3391569614,3928383900),t(3515267271,566280711),t(3940187606,3454069534),t(4118630271,4000239992),t(116418474,1914138554),t(174292421,2731055270),t(289380356,3203993006),t(460393269,320620315),t(685471733,587496836),t(852142971,1086792851),t(1017036298,365543100),t(1126000580,2618297676),t(1288033470,3409855158),t(1501505948,4234509866),t(1607167915,987167468),t(1816402316,1246189591)],o=[],h=0;80>h;h++)o[h]=t();s=s.SHA512=i.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var i=(l=this._hash.words)[0],n=l[1],r=l[2],s=l[3],h=l[4],u=l[5],c=l[6],l=l[7],f=i.high,d=i.low,g=n.high,p=n.low,y=r.high,v=r.low,m=s.high,S=s.low,F=h.high,w=h.low,E=u.high,x=u.low,b=c.high,A=c.low,I=l.high,C=l.low,D=f,T=d,P=g,R=p,H=y,B=v,N=m,O=S,j=F,V=w,L=E,_=x,K=b,k=A,M=I,U=C,q=0;80>q;q++){var z=o[q];if(16>q)var Y=z.high=0|t[e+2*q],G=z.low=0|t[e+2*q+1];else{Y=((G=(Y=o[q-15]).high)>>>1|(J=Y.low)<<31)^(G>>>8|J<<24)^G>>>7;var J=(J>>>1|G<<31)^(J>>>8|G<<24)^(J>>>7|G<<25),W=((G=(W=o[q-2]).high)>>>19|(X=W.low)<<13)^(G<<3|X>>>29)^G>>>6,X=(X>>>19|G<<13)^(X<<3|G>>>29)^(X>>>6|G<<26),Z=(G=o[q-7]).high,$=(Q=o[q-16]).high,Q=Q.low;Y=(Y=(Y=Y+Z+((G=J+G.low)>>>0>>0?1:0))+W+((G=G+X)>>>0>>0?1:0))+$+((G=G+Q)>>>0>>0?1:0);z.high=Y,z.low=G}Z=j&L^~j&K,Q=V&_^~V&k,z=D&P^D&H^P&H;var tt=T&R^T&B^R&B,et=(J=(D>>>28|T<<4)^(D<<30|T>>>2)^(D<<25|T>>>7),W=(T>>>28|D<<4)^(T<<30|D>>>2)^(T<<25|D>>>7),(X=a[q]).high),it=X.low;$=M+((j>>>14|V<<18)^(j>>>18|V<<14)^(j<<23|V>>>9))+((X=U+((V>>>14|j<<18)^(V>>>18|j<<14)^(V<<23|j>>>9)))>>>0>>0?1:0),M=K,U=k,K=L,k=_,L=j,_=V,j=N+($=($=($=$+Z+((X=X+Q)>>>0>>0?1:0))+et+((X=X+it)>>>0>>0?1:0))+Y+((X=X+G)>>>0>>0?1:0))+((V=O+X|0)>>>0>>0?1:0)|0,N=H,O=B,H=P,B=R,P=D,R=T,D=$+(z=J+z+((G=W+tt)>>>0>>0?1:0))+((T=X+G|0)>>>0>>0?1:0)|0}d=i.low=d+T,i.high=f+D+(d>>>0>>0?1:0),p=n.low=p+R,n.high=g+P+(p>>>0>>0?1:0),v=r.low=v+B,r.high=y+H+(v>>>0>>0?1:0),S=s.low=S+O,s.high=m+N+(S>>>0>>0?1:0),w=h.low=w+V,h.high=F+j+(w>>>0>>0?1:0),x=u.low=x+_,u.high=E+L+(x>>>0<_>>>0?1:0),A=c.low=A+k,c.high=b+K+(A>>>0>>0?1:0),C=l.low=C+U,l.high=I+M+(C>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),e[31+(n+128>>>10<<5)]=i,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32}),e.SHA512=i._createHelper(s),e.HmacSHA512=i._createHmacHelper(s)}(),function(){var t=y,e=(r=t.x64).Word,i=r.WordArray,n=(r=t.algo).SHA512,r=r.SHA384=n.extend({_doReset:function(){this._hash=new i.init([new e.init(3418070365,3238371032),new e.init(1654270250,914150663),new e.init(2438529370,812702999),new e.init(355462360,4144912697),new e.init(1731405415,4290775857),new e.init(2394180231,1750603025),new e.init(3675008525,1694076839),new e.init(1203062813,3204075428)])},_doFinalize:function(){var t=n._doFinalize.call(this);return t.sigBytes-=16,t}});t.SHA384=n._createHelper(r),t.HmacSHA384=n._createHmacHelper(r)}(),function(){var t=y,e=(n=t.lib).WordArray,i=n.Hasher,n=t.algo,r=e.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),s=e.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),a=e.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),o=e.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),h=e.create([0,1518500249,1859775393,2400959708,2840853838]),u=e.create([1352829926,1548603684,1836072691,2053994217,0]);n=n.RIPEMD160=i.extend({_doReset:function(){this._hash=e.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=0;16>i;i++){var n=t[F=e+i];t[F]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var c,l,f,d,g,p,y,v,m,S,F=this._hash.words,w=(n=h.words,u.words),E=r.words,x=s.words,b=a.words,A=o.words;p=c=F[0],y=l=F[1],v=f=F[2],m=d=F[3],S=g=F[4];var I;for(i=0;80>i;i+=1)I=c+t[e+E[i]]|0,I=16>i?I+((l^f^d)+n[0]):32>i?I+((l&f|~l&d)+n[1]):48>i?I+(((l|~f)^d)+n[2]):64>i?I+((l&d|f&~d)+n[3]):I+((l^(f|~d))+n[4]),I=(I=(I|=0)<>>32-b[i])+g|0,c=g,g=d,d=f<<10|f>>>22,f=l,l=I,I=p+t[e+x[i]]|0,I=16>i?I+((y^(v|~m))+w[0]):32>i?I+((y&m|v&~m)+w[1]):48>i?I+(((y|~v)^m)+w[2]):64>i?I+((y&v|~y&m)+w[3]):I+((y^v^m)+w[4]),I=(I=(I|=0)<>>32-A[i])+S|0,p=S,S=m,m=v<<10|v>>>22,v=y,y=I;I=F[1]+f+m|0,F[1]=F[2]+d+S|0,F[2]=F[3]+g+p|0,F[3]=F[4]+c+y|0,F[4]=F[0]+l+v|0,F[0]=I},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;for(e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(e.length+1),this._process(),e=(t=this._hash).words,i=0;5>i;i++)n=e[i],e[i]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);return t},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});t.RIPEMD160=i._createHelper(n),t.HmacRIPEMD160=i._createHmacHelper(n)}(Math),function(){var t=y,e=t.enc.Utf8;t.algo.HMAC=t.lib.Base.extend({init:function(t,i){t=this._hasher=new t.init,"string"==typeof i&&(i=e.parse(i));var n=t.blockSize,r=4*n;i.sigBytes>r&&(i=t.finalize(i)),i.clamp();for(var s=this._oKey=i.clone(),a=this._iKey=i.clone(),o=s.words,h=a.words,u=0;u>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function w(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function E(t){var e,i=w(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(x.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(x.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),x.prototype.DB=v,x.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function K(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function M(){}function k(t){return t}function U(t){this.r2=b(),this.q3=b(),x.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(x.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},x.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},x.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},x.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},x.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},x.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},x.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},x.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},x.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),x.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&x.ZERO.subTo(i,i)}}},x.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},x.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},x.prototype.exp=function(t,e){if(t>4294967295||t<1)return x.ONE;var i=b(),n=b(),r=e.convert(this),s=H(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},x.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},x.prototype.negate=function(){var t=b();return x.ZERO.subTo(this,t),t},x.prototype.abs=function(){return this.s<0?this.negate():this},x.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},x.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+H(this[this.t-1]^this.s&this.DM)},x.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(x.ZERO)>0&&t.subTo(e,e),e},x.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},x.ZERO=R(0),x.ONE=R(1),M.prototype.convert=k,M.prototype.revert=k,M.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},M.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; +var v,m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",S="=";function F(t){var e,i,n="";for(e=0;e+3<=t.length;e+=3)i=parseInt(t.substring(e,e+3),16),n+=m.charAt(i>>6)+m.charAt(63&i);if(e+1==t.length?(i=parseInt(t.substring(e,e+1),16),n+=m.charAt(i<<2)):e+2==t.length&&(i=parseInt(t.substring(e,e+2),16),n+=m.charAt(i>>2)+m.charAt((3&i)<<4)),S)for(;(3&n.length)>0;)n+=S;return n}function w(t){var e,i,n,r="",s=0;for(e=0;e>2),i=3&n,s=1):1==s?(r+=T(i<<2|n>>4),i=15&n,s=2):2==s?(r+=T(i),r+=T(n>>2),i=3&n,s=3):(r+=T(i<<2|n>>4),r+=T(15&n),s=0));return 1==s&&(r+=T(i<<2)),r}function E(t){var e,i=w(t),n=new Array;for(e=0;2*e>15;--s>=0;){var h=32767&this[t],u=this[t++]>>15,c=o*h+u*a;r=((h=a*h+((32767&c)<<15)+i[n]+(1073741823&r))>>>30)+(c>>>15)+o*u+(r>>>30),i[n++]=1073741823&h}return r},v=30):"Netscape"!=i.appName?(x.prototype.am=function(t,e,i,n,r,s){for(;--s>=0;){var a=e*this[t++]+i[n]+r;r=Math.floor(a/67108864),i[n++]=67108863&a}return r},v=26):(x.prototype.am=function(t,e,i,n,r,s){for(var a=16383&e,o=e>>14;--s>=0;){var h=16383&this[t],u=this[t++]>>14,c=o*h+u*a;r=((h=a*h+((16383&c)<<14)+i[n]+r)>>28)+(c>>14)+o*u,i[n++]=268435455&h}return r},v=28),x.prototype.DB=v,x.prototype.DM=(1<>>16)&&(t=e,i+=16),0!=(e=t>>8)&&(t=e,i+=8),0!=(e=t>>4)&&(t=e,i+=4),0!=(e=t>>2)&&(t=e,i+=2),0!=(e=t>>1)&&(t=e,i+=1),i}function B(t){this.m=t}function N(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function K(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function k(){}function M(t){return t}function U(t){this.r2=b(),this.q3=b(),x.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}B.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},B.prototype.revert=function(t){return t},B.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},B.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},B.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},N.prototype.convert=function(t){var e=b();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(x.ZERO)>0&&this.m.subTo(e,e),e},N.prototype.revert=function(t){var e=b();return t.copyTo(e),this.reduce(e),e},N.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},N.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},N.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},x.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},x.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},x.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var n=t.length,r=!1,s=0;--n>=0;){var a=8==i?255&t[n]:P(t,n);a<0?"-"==t.charAt(n)&&(r=!0):(r=!1,0==s?this[this.t++]=a:s+i>this.DB?(this[this.t-1]|=(a&(1<>this.DB-s):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==i&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<0&&this[this.t-1]==t;)--this.t},x.prototype.dlShiftTo=function(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s},x.prototype.drShiftTo=function(t,e){for(var i=t;i=0;--i)e[i+a+1]=this[i]>>r|o,o=(this[i]&s)<=0;--i)e[i]=0;e[a]=o,e.t=this.t+a+1,e.s=this.s,e.clamp()},x.prototype.rShiftTo=function(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)e.t=0;else{var n=t%this.DB,r=this.DB-n,s=(1<>n;for(var a=i+1;a>n;n>0&&(e[this.t-i-1]|=(this.s&s)<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[i++]=this.DV+n:n>0&&(e[i++]=n),e.t=i,e.clamp()},x.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),r=i.t;for(e.t=r+n.t;--r>=0;)e[r]=0;for(r=0;r=0;)t[i]=0;for(i=0;i=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()},x.prototype.divRemTo=function(t,e,i){var n=t.abs();if(!(n.t<=0)){var r=this.abs();if(r.t0?(n.lShiftTo(h,s),r.lShiftTo(h,i)):(n.copyTo(s),r.copyTo(i));var u=s.t,c=s[u-1];if(0!=c){var l=c*(1<1?s[u-2]>>this.F2:0),f=this.FV/l,d=(1<=0&&(i[i.t++]=1,i.subTo(v,i)),x.ONE.dlShiftTo(u,v),v.subTo(s,s);s.t=0;){var m=i[--p]==c?this.DM:Math.floor(i[p]*f+(i[p-1]+g)*d);if((i[p]+=s.am(0,m,i,y,0,u))0&&i.rShiftTo(h,i),a<0&&x.ZERO.subTo(i,i)}}},x.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},x.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},x.prototype.exp=function(t,e){if(t>4294967295||t<1)return x.ONE;var i=b(),n=b(),r=e.convert(this),s=H(t)-1;for(r.copyTo(i);--s>=0;)if(e.sqrTo(i,n),(t&1<0)e.mulTo(n,r,i);else{var a=i;i=n,n=a}return e.revert(i)},x.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var i,n=(1<0)for(o>o)>0&&(r=!0,s=T(i));a>=0;)o>(o+=this.DB-e)):(i=this[a]>>(o-=e)&n,o<=0&&(o+=this.DB,--a)),i>0&&(r=!0),r&&(s+=T(i));return r?s:"0"},x.prototype.negate=function(){var t=b();return x.ZERO.subTo(this,t),t},x.prototype.abs=function(){return this.s<0?this.negate():this},x.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var i=this.t;if(0!=(e=i-t.t))return this.s<0?-e:e;for(;--i>=0;)if(0!=(e=this[i]-t[i]))return e;return 0},x.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+H(this[this.t-1]^this.s&this.DM)},x.prototype.mod=function(t){var e=b();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(x.ZERO)>0&&t.subTo(e,e),e},x.prototype.modPowInt=function(t,e){var i;return i=t<256||e.isEven()?new B(e):new N(e),this.exp(t,i)},x.ZERO=R(0),x.ONE=R(1),k.prototype.convert=M,k.prototype.revert=M,k.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i)},k.prototype.sqrTo=function(t,e){t.squareTo(e)},U.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=b();return t.copyTo(e),this.reduce(e),e},U.prototype.revert=function(t){return t},U.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},U.prototype.mulTo=function(t,e,i){t.multiplyTo(e,i),this.reduce(i)},U.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],z=(1<<26)/q[q.length-1]; /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ function Y(){this.i=0,this.j=0,this.S=new Array}x.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},x.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),n=R(i),r=b(),s=b(),a="";for(this.divRemTo(n,r,s);r.signum()>0;)a=(i+s.intValue()).toString(t).substr(1)+a,r.divRemTo(n,r,s);return s.intValue().toString(t)+a},x.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),n=Math.pow(e,i),r=!1,s=0,a=0,o=0;o=i&&(this.dMultiply(n),this.dAddOffset(a,0),s=0,a=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(a,0)),r&&x.ZERO.subTo(this,this)},x.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(x.ONE.shiftLeft(t-1),j,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(x.ONE.shiftLeft(t-1),this);else{var n=new Array,r=7&t;n.length=1+(t>>3),e.nextBytes(n),r>0?n[0]&=(1<>=this.DB;if(t.t>=this.DB;n+=this.s}else{for(n+=this.s;i>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[i++]=n:n<-1&&(e[i++]=this.DV+n),e.t=i,e.clamp()},x.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},x.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},x.prototype.multiplyLowerTo=function(t,e,i){var n,r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;r>0;)i[--r]=0;for(n=i.t-this.t;r=0;)i[n]=0;for(n=Math.max(e-this.t,0);n0)if(0==e)i=this[0]%t;else for(var n=this.t-1;n>=0;--n)i=(e*i+this[n])%t;return i},x.prototype.millerRabin=function(t){var e=this.subtract(x.ONE),i=e.getLowestSetBit();if(i<=0)return!1;var n=e.shiftRight(i);(t=t+1>>1)>q.length&&(t=q.length);for(var r=b(),s=0;s>24},x.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},x.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},x.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},x.prototype.equals=function(t){return 0==this.compareTo(t)},x.prototype.min=function(t){return this.compareTo(t)<0?this:t},x.prototype.max=function(t){return this.compareTo(t)>0?this:t},x.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},x.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},x.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},x.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},x.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=H(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(x.ONE)?x.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},x.prototype.pow=function(t){return this.exp(t,new M)},x.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},x.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>24},x.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},x.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},x.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var i,n=this.DB-t*this.DB%8,r=0;if(t-- >0)for(n>n)!=(this.s&this.DM)>>n&&(e[r++]=i|this.s<=0;)n<8?(i=(this[t]&(1<>(n+=this.DB-8)):(i=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==r&&(128&this.s)!=(128&i)&&++r,(r>0||i!=this.s)&&(e[r++]=i);return e},x.prototype.equals=function(t){return 0==this.compareTo(t)},x.prototype.min=function(t){return this.compareTo(t)<0?this:t},x.prototype.max=function(t){return this.compareTo(t)>0?this:t},x.prototype.and=function(t){var e=b();return this.bitwiseTo(t,O,e),e},x.prototype.or=function(t){var e=b();return this.bitwiseTo(t,j,e),e},x.prototype.xor=function(t){var e=b();return this.bitwiseTo(t,V,e),e},x.prototype.andNot=function(t){var e=b();return this.bitwiseTo(t,L,e),e},x.prototype.not=function(){for(var t=b(),e=0;e=this.t?0!=this.s:0!=(this[e]&1<1){var c=b();for(n.sqrTo(a[1],c);o<=u;)a[o]=b(),n.mulTo(c,a[o-2],a[o]),o+=2}var l,f,d=t.t-1,g=!0,p=b();for(r=H(t[d])-1;d>=0;){for(r>=h?l=t[d]>>r-h&u:(l=(t[d]&(1<0&&(l|=t[d-1]>>this.DB+r-h)),o=i;0==(1&l);)l>>=1,--o;if((r-=o)<0&&(r+=this.DB,--d),g)a[l].copyTo(s),g=!1;else{for(;o>1;)n.sqrTo(s,p),n.sqrTo(p,s),o-=2;o>0?n.sqrTo(s,p):(f=s,s=p,p=f),n.mulTo(p,a[l],s)}for(;d>=0&&0==(t[d]&1<=0?(i.subTo(n,i),e&&r.subTo(a,r),s.subTo(o,s)):(n.subTo(i,n),e&&a.subTo(r,a),o.subTo(s,o))}return 0!=n.compareTo(x.ONE)?x.ZERO:o.compareTo(t)>=0?o.subtract(t):o.signum()<0?(o.addTo(t,o),o.signum()<0?o.add(t):o):o},x.prototype.pow=function(t){return this.exp(t,new k)},x.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var n=e;e=i,i=n}var r=e.getLowestSetBit(),s=i.getLowestSetBit();if(s<0)return e;for(r0&&(e.rShiftTo(s,e),i.rShiftTo(s,i));e.signum()>0;)(r=e.getLowestSetBit())>0&&e.rShiftTo(r,e),(r=i.getLowestSetBit())>0&&i.rShiftTo(r,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return s>0&&i.lShiftTo(s,i),i},x.prototype.isProbablePrime=function(t){var e,i=this.abs();if(1==i.t&&i[0]<=q[q.length-1]){for(e=0;e>8&255,J[W++]^=t>>16&255,J[W++]^=t>>24&255,W>=X&&(W-=X)}((new Date).getTime())}if(null==J){var $;if(J=new Array,W=0,void 0!==n&&(void 0!==n.crypto||void 0!==n.msCrypto)){var Q=n.crypto||n.msCrypto;if(Q.getRandomValues){var tt=new Uint8Array(32);for(Q.getRandomValues(tt),$=0;$<32;++$)J[W++]=tt[$]}else if("Netscape"==i.appName&&i.appVersion<"5"){var et=n.crypto.random(32);for($=0;$>>8,J[W++]=255&$;W=0,Z()}function it(){if(null==G){for(Z(),(G=new Y).init(J),W=0;Wi.length;)i.unshift(0);return i},i=this.getX().toBigInteger(),n=this.getY().toBigInteger(),r=e(i,32);return t?n.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(e(n,32))),r},ut.decodeFrom=function(t,e){e[0];var i=e.length-1,n=e.slice(1,1+i/2),r=e.slice(1+i/2,1+i);n.unshift(0),r.unshift(0);var s=new x(n),a=new x(r);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.decodeFromHex=function(t,e){e.substr(0,2);var i=e.length-2,n=e.substr(2,i/2),r=e.substr(2+i/2,i/2),s=new x(n,16),a=new x(r,16);return new ut(t,t.fromBigInteger(s),t.fromBigInteger(a))},ut.prototype.add2D=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();var e=t.x.subtract(this.x),i=t.y.subtract(this.y).divide(e),n=i.square().subtract(this.x).subtract(t.x),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=this.curve.fromBigInteger(x.valueOf(2)),e=this.curve.fromBigInteger(x.valueOf(3)),i=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),n=i.square().subtract(this.x.multiply(t)),r=i.multiply(this.x.subtract(n)).subtract(this.y);return new ut(this.curve,n,r)},ut.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,i=t,n=i.multiply(new x("3")),r=this.negate(),s=this;for(e=n.bitLength()-2;e>0;--e){s=s.twice();var a=n.testBit(e);a!=i.testBit(e)&&(s=s.add2D(a?this:r))}return s},ut.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),i=this.curve.getA().toBigInteger(),n=this.curve.getB().toBigInteger(),r=this.curve.getQ(),s=e.multiply(e).mod(r),a=t.multiply(t).multiply(t).add(i.multiply(t)).add(n).mod(r);return s.equals(a)},ut.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},ut.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),i=this.getY().toBigInteger();if(e.compareTo(x.ONE)<0||e.compareTo(t.subtract(x.ONE))>0)throw new Error("x coordinate out of bounds");if(i.compareTo(x.ONE)<0||i.compareTo(t.subtract(x.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0}; /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval */ -var lt=function(){var t=new RegExp('(?:false|true|null|[\\{\\}\\[\\]]|(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)|(?:"(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))*"))',"g"),e=new RegExp("\\\\(?:([^u])|u(.{4}))","g"),i={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function n(t,e,n){return e?i[e]:String.fromCharCode(parseInt(n,16))}var r=new String(""),s=(Object,Array,Object.hasOwnProperty);return function(i,a){var o,h,u=i.match(t),c=u[0],l=!1;"{"===c?o={}:"["===c?o=[]:(o=[],l=!0);for(var f=[o],d=1-l,g=u.length;d=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function kt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map((function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Ht;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map((function(t){return t.replace("/","\\/")}))).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Ht;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=kt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Ht(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Rt(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),w=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=w,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var E=0;E1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Ht(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Ht(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Ht,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Ht(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(R=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(R,0,[2],"02"),w=r(R,0,[3],"02"),E=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(R=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(R,0,[2,0],"06"),P=r(R,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var R;S=r(R=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(R,0,[2],"02"),w=r(R,0,[3],"02"),E=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Rt(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),w=m(t).getEncodedHex(),E="";return E+=Rt(F,"EC PARAMETERS"),E+=Rt(w,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Ht(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e.d=Et(t.d.toString(16)),e.p=Et(t.p.toString(16)),e.q=Et(t.q.toString(16)),e.dp=Et(t.dmp1.toString(16)),e.dq=Et(t.dmq1.toString(16)),e.qi=Et(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e.d=Et(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Ht(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Ht;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=w,e.b64toBA=E,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(E(wt(t)))},e.b64tob64u=Ft,e.b64utob64=wt,e.hex2b64=F,e.hextob64u=Et,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(w(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Rt,e.pemtohex=Ht,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp=0;)delete i[n[h]]}return a.call(t,e,i)};o=y({"":o},"")}return o}}();void 0!==ft&&ft||(ft={}),void 0!==ft.asn1&&ft.asn1||(ft.asn1={}),ft.asn1.ASN1Util=new function(){this.integerToByteHex=function(t){var e=t.toString(16);return e.length%2==1&&(e="0"+e),e},this.bigIntToMinTwosComplementsHex=function(t){var e=t.toString(16);if("-"!=e.substr(0,1))e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{var i=e.substr(1).length;i%2==1?i+=1:e.match(/^[0-7]/)||(i+=2);for(var n="",r=0;r15)throw"ASN.1 length too long to represent by 8x: n = "+t.toString(16);return(128+i).toString(16)+e},this.getEncodedHex=function(){return(null==this.hTLV||this.isModified)&&(this.hV=this.getFreshValueHex(),this.hL=this.getLengthHexFromValue(),this.hTLV=this.hT+this.hL+this.hV,this.isModified=!1),this.hTLV},this.getValueHex=function(){return this.getEncodedHex(),this.hV},this.getFreshValueHex=function(){return""}},ft.asn1.DERAbstractString=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=bt(this.s).toLowerCase()},this.setStringHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&("string"==typeof t?this.setString(t):void 0!==t.str?this.setString(t.str):void 0!==t.hex&&this.setStringHex(t.hex))},r.lang.extend(ft.asn1.DERAbstractString,ft.asn1.ASN1Object),ft.asn1.DERAbstractTime=function(t){ft.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(t){return utc=t.getTime()+6e4*t.getTimezoneOffset(),new Date(utc)},this.formatDate=function(t,e,i){var n=this.zeroPadding,r=this.localDateToUTC(t),s=String(r.getFullYear());"utc"==e&&(s=s.substr(2,2));var a=s+n(String(r.getMonth()+1),2)+n(String(r.getDate()),2)+n(String(r.getHours()),2)+n(String(r.getMinutes()),2)+n(String(r.getSeconds()),2);if(!0===i){var o=r.getMilliseconds();if(0!=o){var h=n(String(o),3);a=a+"."+(h=h.replace(/[0]+$/,""))}}return a+"Z"},this.zeroPadding=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},this.getString=function(){return this.s},this.setString=function(t){this.hTLV=null,this.isModified=!0,this.s=t,this.hV=St(t)},this.setByDateValue=function(t,e,i,n,r,s){var a=new Date(Date.UTC(t,e-1,i,n,r,s,0));this.setByDate(a)},this.getFreshValueHex=function(){return this.hV}},r.lang.extend(ft.asn1.DERAbstractTime,ft.asn1.ASN1Object),ft.asn1.DERAbstractStructured=function(t){ft.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array=t},this.appendASN1Object=function(t){this.hTLV=null,this.isModified=!0,this.asn1Array.push(t)},this.asn1Array=new Array,void 0!==t&&void 0!==t.array&&(this.asn1Array=t.array)},r.lang.extend(ft.asn1.DERAbstractStructured,ft.asn1.ASN1Object),ft.asn1.DERBoolean=function(){ft.asn1.DERBoolean.superclass.constructor.call(this),this.hT="01",this.hTLV="0101ff"},r.lang.extend(ft.asn1.DERBoolean,ft.asn1.ASN1Object),ft.asn1.DERInteger=function(t){ft.asn1.DERInteger.superclass.constructor.call(this),this.hT="02",this.setByBigInteger=function(t){this.hTLV=null,this.isModified=!0,this.hV=ft.asn1.ASN1Util.bigIntToMinTwosComplementsHex(t)},this.setByInteger=function(t){var e=new x(String(t),10);this.setByBigInteger(e)},this.setValueHex=function(t){this.hV=t},this.getFreshValueHex=function(){return this.hV},void 0!==t&&(void 0!==t.bigint?this.setByBigInteger(t.bigint):void 0!==t.int?this.setByInteger(t.int):"number"==typeof t?this.setByInteger(t):void 0!==t.hex&&this.setValueHex(t.hex))},r.lang.extend(ft.asn1.DERInteger,ft.asn1.ASN1Object),ft.asn1.DERBitString=function(t){if(void 0!==t&&void 0!==t.obj){var e=ft.asn1.ASN1Util.newObject(t.obj);t.hex="00"+e.getEncodedHex()}ft.asn1.DERBitString.superclass.constructor.call(this),this.hT="03",this.setHexValueIncludingUnusedBits=function(t){this.hTLV=null,this.isModified=!0,this.hV=t},this.setUnusedBitsAndHexValue=function(t,e){if(t<0||7r.length&&(r=n[i]);return(t=t.replace(r,"::")).slice(1,-1)}function _t(t){var e="malformed hex value";if(!t.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw e;if(8!=t.length)return 32==t.length?Lt(t):t;try{return parseInt(t.substr(0,2),16)+"."+parseInt(t.substr(2,2),16)+"."+parseInt(t.substr(4,2),16)+"."+parseInt(t.substr(6,2),16)}catch(t){throw e}}function Kt(t){for(var e=encodeURIComponent(t),i="",n=0;n"7"?"00"+t:t}function Mt(t){t=(t=(t=t.replace(/^\s*\[\s*/,"")).replace(/\s*\]\s*$/,"")).replace(/\s*/g,"");try{return t.split(/,/).map((function(t,e,i){var n=parseInt(t);if(n<0||255=2*s)break;if(o>=200)break;n.push(h),a=h,o++}return n},pt.getNthChildIdx=function(t,e,i){return pt.getChildIdx(t,e)[i]},pt.getIdxbyList=function(t,e,i,n){var r,s,a=pt;if(0==i.length){if(void 0!==n&&t.substr(e,2)!==n)throw"checking tag doesn't match: "+t.substr(e,2)+"!="+n;return e}return r=i.shift(),s=a.getChildIdx(t,e),a.getIdxbyList(t,s[r],i,n)},pt.getTLVbyList=function(t,e,i,n){var r=pt,s=r.getIdxbyList(t,e,i);if(void 0===s)throw"can't find nthList object";if(void 0!==n&&t.substr(s,2)!=n)throw"checking tag doesn't match: "+t.substr(s,2)+"!="+n;return r.getTLV(t,s)},pt.getVbyList=function(t,e,i,n,r){var s,a,o=pt;if(void 0===(s=o.getIdxbyList(t,e,i,n)))throw"can't find nthList object";return a=o.getV(t,s),!0===r&&(a=a.substr(2)),a},pt.hextooidstr=function(t){var e=function(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t},i=[],n=t.substr(0,2),r=parseInt(n,16);i[0]=new String(Math.floor(r/40)),i[1]=new String(r%40);for(var s=t.substr(2),a=[],o=0;o0&&(c=c+"."+h.join(".")),c},pt.dump=function(t,e,i,n){var r=pt,s=r.getV,a=r.dump,o=r.getChildIdx,h=t;t instanceof ft.asn1.ASN1Object&&(h=t.getEncodedHex());var u=function(t,e){return t.length<=2*e?t:t.substr(0,e)+"..(total "+t.length/2+"bytes).."+t.substr(t.length-e,e)};void 0===e&&(e={ommit_long_octet:32}),void 0===i&&(i=0),void 0===n&&(n="");var c=e.ommit_long_octet;if("01"==h.substr(i,2))return"00"==(l=s(h,i))?n+"BOOLEAN FALSE\n":n+"BOOLEAN TRUE\n";if("02"==h.substr(i,2))return n+"INTEGER "+u(l=s(h,i),c)+"\n";if("03"==h.substr(i,2))return n+"BITSTRING "+u(l=s(h,i),c)+"\n";if("04"==h.substr(i,2)){var l=s(h,i);if(r.isASN1HEX(l)){var f=n+"OCTETSTRING, encapsulates\n";return f+=a(l,e,0,n+" ")}return n+"OCTETSTRING "+u(l,c)+"\n"}if("05"==h.substr(i,2))return n+"NULL\n";if("06"==h.substr(i,2)){var d=s(h,i),g=ft.asn1.ASN1Util.oidHexToInt(d),p=ft.asn1.x509.OID.oid2name(g),y=g.replace(/\./g," ");return""!=p?n+"ObjectIdentifier "+p+" ("+y+")\n":n+"ObjectIdentifier ("+y+")\n"}if("0c"==h.substr(i,2))return n+"UTF8String '"+At(s(h,i))+"'\n";if("13"==h.substr(i,2))return n+"PrintableString '"+At(s(h,i))+"'\n";if("14"==h.substr(i,2))return n+"TeletexString '"+At(s(h,i))+"'\n";if("16"==h.substr(i,2))return n+"IA5String '"+At(s(h,i))+"'\n";if("17"==h.substr(i,2))return n+"UTCTime "+At(s(h,i))+"\n";if("18"==h.substr(i,2))return n+"GeneralizedTime "+At(s(h,i))+"\n";if("30"==h.substr(i,2)){if("3000"==h.substr(i,4))return n+"SEQUENCE {}\n";f=n+"SEQUENCE\n";var v=e;if((2==(F=o(h,i)).length||3==F.length)&&"06"==h.substr(F[0],2)&&"04"==h.substr(F[F.length-1],2)){p=r.oidname(s(h,F[0]));var m=JSON.parse(JSON.stringify(e));m.x509ExtName=p,v=m}for(var S=0;S0){var e=new i({array:this.extensionsArray}),n=new r({explicit:!0,tag:"a3",obj:e});this.asn1Array.push(n)}var s=new i({array:this.asn1Array});return this.hTLV=s.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertificate,ft.asn1.ASN1Object),ft.asn1.x509.Extension=function(t){ft.asn1.x509.Extension.superclass.constructor.call(this);var e=ft.asn1,i=e.DERObjectIdentifier,n=e.DEROctetString,r=(e.DERBitString,e.DERBoolean),s=e.DERSequence;this.getEncodedHex=function(){var t=new i({oid:this.oid}),e=new n({hex:this.getExtnValueHex()}),a=new Array;return a.push(t),this.critical&&a.push(new r),a.push(e),new s({array:a}).getEncodedHex()},this.critical=!1,void 0!==t&&void 0!==t.critical&&(this.critical=t.critical)},r.lang.extend(ft.asn1.x509.Extension,ft.asn1.ASN1Object),ft.asn1.x509.Extension.appendByNameToArray=function(t,e,i){var n=t.toLowerCase(),r=ft.asn1.x509;if("basicconstraints"==n){var s=new r.BasicConstraints(e);i.push(s)}else if("keyusage"==n){s=new r.KeyUsage(e);i.push(s)}else if("crldistributionpoints"==n){s=new r.CRLDistributionPoints(e);i.push(s)}else if("extkeyusage"==n){s=new r.ExtKeyUsage(e);i.push(s)}else if("authoritykeyidentifier"==n){s=new r.AuthorityKeyIdentifier(e);i.push(s)}else if("authorityinfoaccess"==n){s=new r.AuthorityInfoAccess(e);i.push(s)}else if("subjectaltname"==n){s=new r.SubjectAltName(e);i.push(s)}else{if("issueraltname"!=n)throw"unsupported extension name: "+t;s=new r.IssuerAltName(e);i.push(s)}},ft.asn1.x509.KeyUsage=function(t){ft.asn1.x509.KeyUsage.superclass.constructor.call(this,t);var e=Jt.KEYUSAGE_NAME;if(this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.15",void 0!==t&&(void 0!==t.bin&&(this.asn1ExtnValue=new ft.asn1.DERBitString(t)),void 0!==t.names&&void 0!==t.names.length)){for(var i=t.names,n="000000000",r=0;r-1&&t.push(new ft.asn1.DERInteger({int:this.pathLen}));var e=new ft.asn1.DERSequence({array:t});return this.asn1ExtnValue=e,this.asn1ExtnValue.getEncodedHex()},this.oid="2.5.29.19",this.cA=!1,this.pathLen=-1,void 0!==t&&(void 0!==t.cA&&(this.cA=t.cA),void 0!==t.pathLen&&(this.pathLen=t.pathLen))},r.lang.extend(ft.asn1.x509.BasicConstraints,ft.asn1.x509.Extension),ft.asn1.x509.CRLDistributionPoints=function(t){ft.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,t);var e=ft.asn1,i=e.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()},this.setByDPArray=function(t){this.asn1ExtnValue=new e.DERSequence({array:t})},this.setByOneURI=function(t){var e=new i.GeneralNames([{uri:t}]),n=new i.DistributionPointName(e),r=new i.DistributionPoint({dpobj:n});this.setByDPArray([r])},this.oid="2.5.29.31",void 0!==t&&(void 0!==t.array?this.setByDPArray(t.array):void 0!==t.uri&&this.setByOneURI(t.uri))},r.lang.extend(ft.asn1.x509.CRLDistributionPoints,ft.asn1.x509.Extension),ft.asn1.x509.ExtKeyUsage=function(t){ft.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,t);var e=ft.asn1;this.setPurposeArray=function(t){this.asn1ExtnValue=new e.DERSequence;for(var i=0;i0){var t=new i({array:this.aRevokedCert});this.asn1Array.push(t)}var e=new i({array:this.asn1Array});return this.hTLV=e.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize=function(){this.asn1Version=null,this.asn1SignatureAlg=null,this.asn1Issuer=null,this.asn1ThisUpdate=null,this.asn1NextUpdate=null,this.aRevokedCert=new Array},this._initialize()},r.lang.extend(ft.asn1.x509.TBSCertList,ft.asn1.ASN1Object),ft.asn1.x509.CRLEntry=function(t){ft.asn1.x509.CRLEntry.superclass.constructor.call(this);var e=ft.asn1;this.setCertSerial=function(t){this.sn=new e.DERInteger(t)},this.setRevocationDate=function(t){this.time=new e.x509.Time(t)},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.sn,this.time]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&(void 0!==t.time&&this.setRevocationDate(t.time),void 0!==t.sn&&this.setCertSerial(t.sn))},r.lang.extend(ft.asn1.x509.CRLEntry,ft.asn1.ASN1Object),ft.asn1.x509.X500Name=function(t){ft.asn1.x509.X500Name.superclass.constructor.call(this),this.asn1Array=new Array;var e=ft.asn1,i=e.x509,n=Ht;if(this.setByString=function(t){var e=t.split("/");e.shift();for(var n=[],r=0;r0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+","+s).replace(/\\,/g,",");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}return(n=n.map((function(t){return t.replace("/","\\/")}))).reverse(),"/"+n.join("/")},ft.asn1.x509.RDN=function(t){ft.asn1.x509.RDN.superclass.constructor.call(this),this.asn1Array=new Array,this.addByString=function(t){this.asn1Array.push(new ft.asn1.x509.AttributeTypeAndValue({str:t}))},this.addByMultiValuedString=function(t){for(var e=ft.asn1.x509.RDN.parseString(t),i=0;i0;r++){var s=e.shift();if(!0===i){var a=(n.pop()+"+"+s).replace(/\\\+/g,"+");n.push(a),i=!1}else n.push(s);"\\"===s.substr(-1,1)&&(i=!0)}var o=!1,h=[];for(r=0;n.length>0;r++){s=n.shift();if(!0===o){var u=h.pop();if(s.match(/"$/)){a=(u+"+"+s).replace(/^([^=]+)="(.*)"$/,"$1=$2");h.push(a),o=!1}else h.push(u+"+"+s)}else h.push(s);s.match(/^[^=]+="/)&&(o=!0)}return h},ft.asn1.x509.AttributeTypeAndValue=function(t){ft.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var e=ft.asn1;this.setByString=function(t){var e=t.match(/^([^=]+)=(.+)$/);if(!e)throw"malformed attrTypeAndValueStr: "+t;this.setByAttrTypeAndValueStr(e[1],e[2])},this.setByAttrTypeAndValueStr=function(t,e){this.typeObj=ft.asn1.x509.OID.atype2obj(t);var i="utf8";"C"==t&&(i="prn"),this.valueObj=this.getValueObj(i,e)},this.getValueObj=function(t,i){if("utf8"==t)return new e.DERUTF8String({str:i});if("prn"==t)return new e.DERPrintableString({str:i});if("tel"==t)return new e.DERTeletexString({str:i});if("ia5"==t)return new e.DERIA5String({str:i});throw"unsupported directory string type: type="+t+" value="+i},this.getEncodedHex=function(){var t=new e.DERSequence({array:[this.typeObj,this.valueObj]});return this.TLV=t.getEncodedHex(),this.TLV},void 0!==t&&void 0!==t.str&&this.setByString(t.str)},r.lang.extend(ft.asn1.x509.AttributeTypeAndValue,ft.asn1.ASN1Object),ft.asn1.x509.SubjectPublicKeyInfo=function(t){ft.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var e=ft,i=e.asn1,n=i.DERInteger,r=i.DERBitString,s=i.DERObjectIdentifier,a=i.DERSequence,o=i.ASN1Util.newObject,h=i.x509.AlgorithmIdentifier,u=e.crypto;u.ECDSA,u.DSA;this.getASN1Object=function(){if(null==this.asn1AlgId||null==this.asn1SubjPKey)throw"algId and/or subjPubKey not set";return new a({array:[this.asn1AlgId,this.asn1SubjPKey]})},this.getEncodedHex=function(){var t=this.getASN1Object();return this.hTLV=t.getEncodedHex(),this.hTLV},this.setPubKey=function(t){try{if(t instanceof at){var e=o({seq:[{int:{bigint:t.n}},{int:{int:t.e}}]}).getEncodedHex();this.asn1AlgId=new h({name:"rsaEncryption"}),this.asn1SubjPKey=new r({hex:"00"+e})}}catch(t){}try{if(t instanceof ft.crypto.ECDSA){var i=new s({name:t.curveName});this.asn1AlgId=new h({name:"ecPublicKey",asn1params:i}),this.asn1SubjPKey=new r({hex:"00"+t.pubKeyHex})}}catch(t){}try{if(t instanceof ft.crypto.DSA){i=new o({seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]});this.asn1AlgId=new h({name:"dsa",asn1params:i});var a=new n({bigint:t.y});this.asn1SubjPKey=new r({hex:"00"+a.getEncodedHex()})}}catch(t){}},void 0!==t&&this.setPubKey(t)},r.lang.extend(ft.asn1.x509.SubjectPublicKeyInfo,ft.asn1.ASN1Object),ft.asn1.x509.Time=function(t){ft.asn1.x509.Time.superclass.constructor.call(this);var e=ft.asn1,i=e.DERUTCTime,n=e.DERGeneralizedTime;this.setTimeParams=function(t){this.timeParams=t},this.getEncodedHex=function(){var t=null;return t=null!=this.timeParams?"utc"==this.type?new i(this.timeParams):new n(this.timeParams):"utc"==this.type?new i:new n,this.TLV=t.getEncodedHex(),this.TLV},this.type="utc",void 0!==t&&(void 0!==t.type?this.type=t.type:void 0!==t.str&&(t.str.match(/^[0-9]{12}Z$/)&&(this.type="utc"),t.str.match(/^[0-9]{14}Z$/)&&(this.type="gen")),this.timeParams=t)},r.lang.extend(ft.asn1.x509.Time,ft.asn1.ASN1Object),ft.asn1.x509.AlgorithmIdentifier=function(t){ft.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this),this.nameAlg=null,this.asn1Alg=null,this.asn1Params=null,this.paramEmpty=!1;var e=ft.asn1;if(this.getEncodedHex=function(){if(null===this.nameAlg&&null===this.asn1Alg)throw"algorithm not specified";null!==this.nameAlg&&null===this.asn1Alg&&(this.asn1Alg=e.x509.OID.name2obj(this.nameAlg));var t=[this.asn1Alg];null!==this.asn1Params&&t.push(this.asn1Params);var i=new e.DERSequence({array:t});return this.hTLV=i.getEncodedHex(),this.hTLV},void 0!==t&&(void 0!==t.name&&(this.nameAlg=t.name),void 0!==t.asn1params&&(this.asn1Params=t.asn1params),void 0!==t.paramempty&&(this.paramEmpty=t.paramempty)),null===this.asn1Params&&!1===this.paramEmpty&&null!==this.nameAlg){var i=this.nameAlg.toLowerCase();"withdsa"!==i.substr(-7,7)&&"withecdsa"!==i.substr(-9,9)&&(this.asn1Params=new e.DERNull)}},r.lang.extend(ft.asn1.x509.AlgorithmIdentifier,ft.asn1.ASN1Object),ft.asn1.x509.GeneralName=function(t){ft.asn1.x509.GeneralName.superclass.constructor.call(this);var e={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},i=ft.asn1,n=(i.DERSequence,i.DEROctetString),r=i.DERIA5String,s=i.DERTaggedObject,a=i.ASN1Object,o=i.x509.X500Name,h=Ht;this.explicit=!1,this.setByParam=function(t){var i=null;if(void 0!==t){if(void 0!==t.rfc822&&(this.type="rfc822",i=new r({str:t[this.type]})),void 0!==t.dns&&(this.type="dns",i=new r({str:t[this.type]})),void 0!==t.uri&&(this.type="uri",i=new r({str:t[this.type]})),void 0!==t.dn&&(this.type="dn",this.explicit=!0,i=new o({str:t.dn})),void 0!==t.ldapdn&&(this.type="dn",this.explicit=!0,i=new o({ldapstr:t.ldapdn})),void 0!==t.certissuer){this.type="dn",this.explicit=!0;var u=null;if((l=t.certissuer).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certissuer param not cert";(f=new Jt).hex=u;var c=f.getIssuerHex();(i=new a).hTLV=c}if(void 0!==t.certsubj){this.type="dn",this.explicit=!0;var l,f;u=null;if((l=t.certsubj).match(/^[0-9A-Fa-f]+$/),-1!=l.indexOf("-----BEGIN ")&&(u=h(l)),null==u)throw"certsubj param not cert";(f=new Jt).hex=u;c=f.getSubjectHex();(i=new a).hTLV=c}if(void 0!==t.ip){this.type="ip",this.explicit=!1;var d,g=t.ip,p="malformed IP address";if(g.match(/^[0-9.]+[.][0-9.]+$/)){if(8!==(d=Mt("["+g.split(".").join(",")+"]")).length)throw p}else if(g.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/))d=Vt(g);else{if(!g.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/))throw p;d=g}i=new n({hex:d})}if(null==this.type)throw"unsupported type in params="+t;this.asn1Obj=new s({explicit:this.explicit,tag:e[this.type],obj:i})}},this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()},void 0!==t&&this.setByParam(t)},r.lang.extend(ft.asn1.x509.GeneralName,ft.asn1.ASN1Object),ft.asn1.x509.GeneralNames=function(t){ft.asn1.x509.GeneralNames.superclass.constructor.call(this);var e=ft.asn1;this.setByParamArray=function(t){for(var i=0;i0&&(e=new n({obj:this.dUnsignedAttrs,tag:"a1",explicit:!1}));var r=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,t,this.dSigAlg,this.dSig];null!=e&&r.push(e);var a=new i.DERSequence({array:r});return this.hTLV=a.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.SignerInfo,ft.asn1.ASN1Object),ft.asn1.cms.EncapsulatedContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.DERObjectIdentifier,s=e.DEROctetString;e.cms.EncapsulatedContentInfo.superclass.constructor.call(this),this.dEContentType=new r({name:"data"}),this.dEContent=null,this.isDetached=!1,this.eContentValueHex=null,this.setContentType=function(t){t.match(/^[0-2][.][0-9.]+$/)?this.dEContentType=new r({oid:t}):this.dEContentType=new r({name:t})},this.setContentValue=function(t){void 0!==t&&("string"==typeof t.hex?this.eContentValueHex=t.hex:"string"==typeof t.str&&(this.eContentValueHex=bt(t.str)))},this.setContentValueHex=function(t){this.eContentValueHex=t},this.setContentValueStr=function(t){this.eContentValueHex=bt(t)},this.getEncodedHex=function(){if("string"!=typeof this.eContentValueHex)throw"eContentValue not yet set";var t=new s({hex:this.eContentValueHex});this.dEContent=new i({obj:t,tag:"a0",explicit:!0});var e=[this.dEContentType];this.isDetached||e.push(this.dEContent);var r=new n({array:e});return this.hTLV=r.getEncodedHex(),this.hTLV}},r.lang.extend(ft.asn1.cms.EncapsulatedContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.ContentInfo=function(t){var e=ft.asn1,i=e.DERTaggedObject,n=e.DERSequence,r=e.x509;ft.asn1.cms.ContentInfo.superclass.constructor.call(this),this.dContentType=null,this.dContent=null,this.setContentType=function(t){"string"==typeof t&&(this.dContentType=r.OID.name2obj(t))},this.getEncodedHex=function(){var t=new i({obj:this.dContent,tag:"a0",explicit:!0}),e=new n({array:[this.dContentType,t]});return this.hTLV=e.getEncodedHex(),this.hTLV},void 0!==t&&(t.type&&this.setContentType(t.type),t.obj&&t.obj instanceof e.ASN1Object&&(this.dContent=t.obj))},r.lang.extend(ft.asn1.cms.ContentInfo,ft.asn1.ASN1Object),ft.asn1.cms.SignedData=function(t){var e=ft.asn1,i=e.ASN1Object,n=e.DERInteger,r=e.DERSet,s=e.DERSequence,a=e.DERTaggedObject,o=e.cms,h=o.EncapsulatedContentInfo,u=o.SignerInfo,c=o.ContentInfo,l=e.x509.AlgorithmIdentifier;ft.asn1.cms.SignedData.superclass.constructor.call(this),this.dCMSVersion=new n({int:1}),this.dDigestAlgs=null,this.digestAlgNameList=[],this.dEncapContentInfo=new h,this.dCerts=null,this.certificateList=[],this.crlList=[],this.signerInfoList=[new u],this.addCertificatesByPEM=function(t){var e=Ht(t),n=new i;n.hTLV=e,this.certificateList.push(n)},this.getEncodedHex=function(){if("string"==typeof this.hTLV)return this.hTLV;if(null==this.dDigestAlgs){for(var t=[],e=0;e0){var h=new r({array:this.certificateList});this.dCerts=new a({obj:h,tag:"a0",explicit:!1})}null!=this.dCerts&&o.push(this.dCerts);var u=new r({array:this.signerInfoList});o.push(u);var c=new s({array:o});return this.hTLV=c.getEncodedHex(),this.hTLV},this.getContentInfo=function(){return this.getEncodedHex(),new c({type:"signed-data",obj:this})},this.getContentInfoEncodedHex=function(){return this.getContentInfo().getEncodedHex()},this.getPEM=function(){return Rt(this.getContentInfoEncodedHex(),"CMS")}},r.lang.extend(ft.asn1.cms.SignedData,ft.asn1.ASN1Object),ft.asn1.cms.CMSUtil=new function(){},ft.asn1.cms.CMSUtil.newSignedData=function(t){var e=ft.asn1,i=e.cms,n=i.SignerInfo,r=i.SignedData,s=i.SigningTime,a=i.SigningCertificate,o=i.SigningCertificateV2,h=e.cades.SignaturePolicyIdentifier,u=new r;if(u.dEncapContentInfo.setContentValue(t.content),"object"==typeof t.certs)for(var c=0;c0){var t=new n({array:this.extensionsArray}),e=new r({array:[t]}),i=new n({array:[new o({oid:"1.2.840.113549.1.9.14"}),e]}),h=new a({explicit:!0,tag:"a0",obj:i});this.asn1Array.push(h)}else{h=new a({explicit:!1,tag:"a0",obj:new s});this.asn1Array.push(h)}var u=new n({array:this.asn1Array});return this.hTLV=u.getEncodedHex(),this.isModified=!1,this.hTLV},this._initialize()},r.lang.extend(ft.asn1.csr.CertificationRequestInfo,ft.asn1.ASN1Object),ft.asn1.csr.CSRUtil=new function(){},ft.asn1.csr.CSRUtil.newCSRPEM=function(t){var e=Ut,i=ft.asn1.csr;if(void 0===t.subject)throw"parameter subject undefined";if(void 0===t.sbjpubkey)throw"parameter sbjpubkey undefined";if(void 0===t.sigalg)throw"parameter sigalg undefined";if(void 0===t.sbjprvkey)throw"parameter sbjpubkey undefined";var n=new i.CertificationRequestInfo;if(n.setSubjectByParam(t.subject),n.setSubjectPublicKeyByGetKey(t.sbjpubkey),void 0!==t.ext&&void 0!==t.ext.length)for(var r=0;rr)throw"key is too short for SigAlg: keylen="+i+","+e;for(var s="0001",a="00"+n,o="",h=r-s.length-a.length,u=0;u=0)return!1;if(i.compareTo(x.ONE)<0||i.compareTo(r)>=0)return!1;var a=i.modInverse(r),o=t.multiply(a).mod(r),h=e.multiply(a).mod(r);return s.multiply(o).add(n.multiply(h)).getX().toBigInteger().mod(r).equals(e)},this.serializeSig=function(t,e){var i=t.toByteArraySigned(),n=e.toByteArraySigned(),r=[];return r.push(2),r.push(i.length),(r=r.concat(i)).push(2),r.push(n.length),(r=r.concat(n)).unshift(r.length),r.unshift(48),r},this.parseSig=function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(2!=t[e=2])throw new Error("First element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);if(2!=t[e+=2+t[e+1]])throw new Error("Second element in signature must be a DERInteger");var n=t.slice(e+2,e+2+t[e+1]);return e+=2+t[e+1],{r:x.fromByteArrayUnsigned(i),s:x.fromByteArrayUnsigned(n)}},this.parseSigCompact=function(t){if(65!==t.length)throw"Signature has the wrong length";var e=t[0]-27;if(e<0||e>7)throw"Invalid signature type";var i=this.ecparams.n;return{r:x.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s:x.fromByteArrayUnsigned(t.slice(33,65)).mod(i),i:e}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[2,0],"06"),i=a(t,0,[1],"04");try{n=a(t,0,[3,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#1/5 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{a(t,0,[1,0],"06"),e=a(t,0,[1,1],"06"),i=a(t,0,[2,0,1],"04");try{n=a(t,0,[2,0,2,0],"03").substr(2)}catch(t){}}catch(t){throw"malformed PKCS#8 plain ECC private key"}if(this.curveName=s(e),void 0===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n),this.setPrivateKeyHex(i),this.isPublic=!1},this.readPKCS8PubKeyHex=function(t){var e,i,n=pt,r=ft.crypto.ECDSA.getName,s=n.getVbyList;if(!1===n.isASN1HEX(t))throw"not ASN.1 hex string";try{s(t,0,[0,0],"06"),e=s(t,0,[0,1],"06"),i=s(t,0,[1],"03").substr(2)}catch(t){throw"malformed PKCS#8 ECC public key"}if(this.curveName=r(e),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(i)},this.readCertPubKeyHex=function(t,e){5!==e&&(e=6);var i,n,r=pt,s=ft.crypto.ECDSA.getName,a=r.getVbyList;if(!1===r.isASN1HEX(t))throw"not ASN.1 hex string";try{i=a(t,0,[0,e,0,1],"06"),n=a(t,0,[0,e,1],"03").substr(2)}catch(t){throw"malformed X.509 certificate ECC public key"}if(this.curveName=s(i),null===this.curveName)throw"unsupported curve name";this.setNamedCurve(this.curveName),this.setPublicKeyHex(n)},void 0!==t&&void 0!==t.curve&&(this.curveName=t.curve),void 0===this.curveName&&(this.curveName="secp256r1"),this.setNamedCurve(this.curveName),void 0!==t&&(void 0!==t.prv&&this.setPrivateKeyHex(t.prv),void 0!==t.pub&&this.setPublicKeyHex(t.pub))},ft.crypto.ECDSA.parseSigHex=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t);return{r:new x(e.r,16),s:new x(e.s,16)}},ft.crypto.ECDSA.parseSigHexInHexRS=function(t){var e=pt,i=e.getChildIdx,n=e.getV;if("30"!=t.substr(0,2))throw"signature is not a ASN.1 sequence";var r=i(t,0);if(2!=r.length)throw"number of signature ASN.1 sequence elements seem wrong";var s=r[0],a=r[1];if("02"!=t.substr(s,2))throw"1st item of sequene of signature is not ASN.1 integer";if("02"!=t.substr(a,2))throw"2nd item of sequene of signature is not ASN.1 integer";return{r:n(t,s),s:n(t,a)}},ft.crypto.ECDSA.asn1SigToConcatSig=function(t){var e=ft.crypto.ECDSA.parseSigHexInHexRS(t),i=e.r,n=e.s;if("00"==i.substr(0,2)&&i.length%32==2&&(i=i.substr(2)),"00"==n.substr(0,2)&&n.length%32==2&&(n=n.substr(2)),i.length%32==30&&(i="00"+i),n.length%32==30&&(n="00"+n),i.length%32!=0)throw"unknown ECDSA sig r length error";if(n.length%32!=0)throw"unknown ECDSA sig s length error";return i+n},ft.crypto.ECDSA.concatSigToASN1Sig=function(t){if(t.length/2*8%128!=0)throw"unknown ECDSA concatinated r-s sig length error";var e=t.substr(0,t.length/2),i=t.substr(t.length/2);return ft.crypto.ECDSA.hexRSSigToASN1Sig(e,i)},ft.crypto.ECDSA.hexRSSigToASN1Sig=function(t,e){var i=new x(t,16),n=new x(e,16);return ft.crypto.ECDSA.biRSSigToASN1Sig(i,n)},ft.crypto.ECDSA.biRSSigToASN1Sig=function(t,e){var i=ft.asn1,n=new i.DERInteger({bigint:t}),r=new i.DERInteger({bigint:e});return new i.DERSequence({array:[n,r]}).getEncodedHex()},ft.crypto.ECDSA.getName=function(t){return"2a8648ce3d030107"===t?"secp256r1":"2b8104000a"===t?"secp256k1":"2b81040022"===t?"secp384r1":-1!=="|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(t)?"secp256r1":-1!=="|secp256k1|".indexOf(t)?"secp256k1":-1!=="|secp384r1|NIST P-384|P-384|".indexOf(t)?"secp384r1":null},void 0!==ft&&ft||(ft={}),void 0!==ft.crypto&&ft.crypto||(ft.crypto={}),ft.crypto.ECParameterDB=new function(){var t={},e={};function i(t){return new x(t,16)}this.getByName=function(i){var n=i;if(void 0!==e[n]&&(n=e[i]),void 0!==t[n])return t[n];throw"unregistered EC curve name: "+n},this.regist=function(n,r,s,a,o,h,u,c,l,f,d,g){t[n]={};var p=i(s),y=i(a),v=i(o),m=i(h),S=i(u),F=new ct(p,y,v),w=F.decodePointHex("04"+c+l);t[n].name=n,t[n].keylen=r,t[n].curve=F,t[n].G=w,t[n].n=m,t[n].h=S,t[n].oid=d,t[n].info=g;for(var E=0;E1?new x(n,16):null,u=new x(r,16),this.setPrivate(s,a,o,h,u)},this.setPublic=function(t,e,i,n){this.isPublic=!0,this.p=t,this.q=e,this.g=i,this.y=n,this.x=null},this.setPublicHex=function(t,e,i,n){var r,s,a,o;r=new x(t,16),s=new x(e,16),a=new x(i,16),o=new x(n,16),this.setPublic(r,s,a,o)},this.signWithMessageHash=function(t){var e=this.p,i=this.q,n=this.g,r=(this.y,this.x),s=ft.crypto.Util.getRandomBigIntegerMinToMax(x.ONE.add(x.ONE),i.subtract(x.ONE)),a=new x(t.substr(0,i.bitLength()/4),16),o=n.modPow(s,e).mod(i),h=s.modInverse(i).multiply(a.add(r.multiply(o))).mod(i);return ft.asn1.ASN1Util.jsonToASN1HEX({seq:[{int:{bigint:o}},{int:{bigint:h}}]})},this.verifyWithMessageHash=function(t,e){var i=this.p,n=this.q,r=this.g,s=this.y,a=this.parseASN1Signature(e),o=a[0],h=a[1],u=new x(t.substr(0,n.bitLength()/4),16);if(x.ZERO.compareTo(o)>0||o.compareTo(n)>0)throw"invalid DSA signature";if(x.ZERO.compareTo(h)>=0||h.compareTo(n)>0)throw"invalid DSA signature";var c=h.modInverse(n),l=u.multiply(c).mod(n),f=o.multiply(c).mod(n);return 0==r.modPow(l,i).multiply(s.modPow(f,i)).mod(i).mod(n).compareTo(o)},this.parseASN1Signature=function(t){try{return[new x(pt.getVbyList(t,0,[0],"02"),16),new x(pt.getVbyList(t,0,[1],"02"),16)]}catch(t){throw"malformed ASN.1 DSA signature"}},this.readPKCS5PrvKeyHex=function(t){var e,i,n,r,s,a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{e=o(t,0,[1],"02"),i=o(t,0,[2],"02"),n=o(t,0,[3],"02"),r=o(t,0,[4],"02"),s=o(t,0,[5],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(e,i,n,r,s)},this.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[1,1,0],"02"),i=a(t,0,[1,1,1],"02"),n=a(t,0,[1,1,2],"02"),r=a(t,0,[2,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(e,i,n,null,r)},this.readPKCS8PubKeyHex=function(t){var e,i,n,r,s=pt,a=s.getVbyList;if(!1===s.isASN1HEX(t))throw"not ASN.1 hex string";try{e=a(t,0,[0,1,0],"02"),i=a(t,0,[0,1,1],"02"),n=a(t,0,[0,1,2],"02"),r=a(t,0,[1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed PKCS#8 DSA public key"}this.setPublicHex(e,i,n,r)},this.readCertPubKeyHex=function(t,e){var i,n,r,s;5!==e&&(e=6);var a=pt,o=a.getVbyList;if(!1===a.isASN1HEX(t))throw"not ASN.1 hex string";try{i=o(t,0,[0,e,0,1,0],"02"),n=o(t,0,[0,e,0,1,1],"02"),r=o(t,0,[0,e,0,1,2],"02"),s=o(t,0,[0,e,1,0],"02")}catch(t){throw console.log("EXCEPTION:"+t),"malformed X.509 certificate DSA public key"}this.setPublicHex(i,n,r,s)}};var Ut=function(){var t=function(t,i,n){return e(y.AES,t,i,n)},e=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o={};o.key=s,o.iv=a,o.ciphertext=r;var h=t.decrypt(o,s,{iv:a});return y.enc.Hex.stringify(h)},i=function(t,e,i){return n(y.AES,t,e,i)},n=function(t,e,i,n){var r=y.enc.Hex.parse(e),s=y.enc.Hex.parse(i),a=y.enc.Hex.parse(n),o=t.encrypt(r,s,{iv:a}),h=y.enc.Hex.parse(o.toString());return y.enc.Base64.stringify(h)},r={"AES-256-CBC":{proc:t,eproc:i,keylen:32,ivlen:16},"AES-192-CBC":{proc:t,eproc:i,keylen:24,ivlen:16},"AES-128-CBC":{proc:t,eproc:i,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:function(t,i,n){return e(y.TripleDES,t,i,n)},eproc:function(t,e,i){return n(y.TripleDES,t,e,i)},keylen:24,ivlen:8},"DES-CBC":{proc:function(t,i,n){return e(y.DES,t,i,n)},eproc:function(t,e,i){return n(y.DES,t,e,i)},keylen:8,ivlen:8}},s=function(t){var e={},i=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));i&&(e.cipher=i[1],e.ivsalt=i[2]);var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));n&&(e.type=n[1]);var r=-1,s=0;-1!=t.indexOf("\r\n\r\n")&&(r=t.indexOf("\r\n\r\n"),s=2),-1!=t.indexOf("\n\n")&&(r=t.indexOf("\n\n"),s=1);var a=t.indexOf("-----END");if(-1!=r&&-1!=a){var o=t.substring(r+2*s,a-s);o=o.replace(/\s+/g,""),e.data=o}return e},a=function(t,e,i){for(var n=i.substring(0,16),s=y.enc.Hex.parse(n),a=y.enc.Utf8.parse(e),o=r[t].keylen+r[t].ivlen,h="",u=null;;){var c=y.algo.MD5.create();if(null!=u&&c.update(u),c.update(a),c.update(s),u=c.finalize(),(h+=y.enc.Hex.stringify(u)).length>=2*o)break}var l={};return l.keyhex=h.substr(0,2*r[t].keylen),l.ivhex=h.substr(2*r[t].keylen,2*r[t].ivlen),l},o=function(t,e,i,n){var s=y.enc.Base64.parse(t),a=y.enc.Hex.stringify(s);return(0,r[e].proc)(a,i,n)};return{version:"1.0.0",parsePKCS5PEM:function(t){return s(t)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(t,e,i){return a(t,e,i)},decryptKeyB64:function(t,e,i,n){return o(t,e,i,n)},getDecryptedKeyHex:function(t,e){var i=s(t),n=(i.type,i.cipher),r=i.ivsalt,h=i.data,u=a(n,e,r).keyhex;return o(h,n,u,r)},getEncryptedPKCS5PEMFromPrvKeyHex:function(t,e,i,n,s){var o="";if(void 0!==n&&null!=n||(n="AES-256-CBC"),void 0===r[n])throw"KEYUTIL unsupported algorithm: "+n;void 0!==s&&null!=s||(s=function(t){var e=y.lib.WordArray.random(t);return y.enc.Hex.stringify(e)}(r[n].ivlen).toUpperCase());var h=function(t,e,i,n){return(0,r[e].eproc)(t,i,n)}(e,n,a(n,i,s).keyhex,s);o="-----BEGIN "+t+" PRIVATE KEY-----\r\n";return o+="Proc-Type: 4,ENCRYPTED\r\n",o+="DEK-Info: "+n+","+s+"\r\n",o+="\r\n",o+=h.replace(/(.{64})/g,"$1\r\n"),o+="\r\n-----END "+t+" PRIVATE KEY-----\r\n"},parseHexOfEncryptedPKCS8:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={},s=i(t,0);if(2!=s.length)throw"malformed format: SEQUENCE(0).items != 2: "+s.length;r.ciphertext=n(t,s[1]);var a=i(t,s[0]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0).items != 2: "+a.length;if("2a864886f70d01050d"!=n(t,a[0]))throw"this only supports pkcs5PBES2";var o=i(t,a[1]);if(2!=a.length)throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length;var h=i(t,o[1]);if(2!=h.length)throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+h.length;if("2a864886f70d0307"!=n(t,h[0]))throw"this only supports TripleDES";r.encryptionSchemeAlg="TripleDES",r.encryptionSchemeIV=n(t,h[1]);var u=i(t,o[0]);if(2!=u.length)throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+u.length;if("2a864886f70d01050c"!=n(t,u[0]))throw"this only supports pkcs5PBKDF2";var c=i(t,u[1]);if(c.length<2)throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+c.length;r.pbkdf2Salt=n(t,c[0]);var l=n(t,c[1]);try{r.pbkdf2Iter=parseInt(l,16)}catch(t){throw"malformed format pbkdf2Iter: "+l}return r},getPBKDF2KeyHexFromParam:function(t,e){var i=y.enc.Hex.parse(t.pbkdf2Salt),n=t.pbkdf2Iter,r=y.PBKDF2(e,i,{keySize:6,iterations:n});return y.enc.Hex.stringify(r)},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(t,e){var i=Ht(t,"ENCRYPTED PRIVATE KEY"),n=this.parseHexOfEncryptedPKCS8(i),r=Ut.getPBKDF2KeyHexFromParam(n,e),s={};s.ciphertext=y.enc.Hex.parse(n.ciphertext);var a=y.enc.Hex.parse(r),o=y.enc.Hex.parse(n.encryptionSchemeIV),h=y.TripleDES.decrypt(s,a,{iv:o});return y.enc.Hex.stringify(h)},getKeyFromEncryptedPKCS8PEM:function(t,e){var i=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(t,e);return this.getKeyFromPlainPrivatePKCS8Hex(i)},parsePlainPrivatePKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null};if("30"!=t.substr(0,2))throw"malformed plain PKCS8 private key(code:001)";var s=i(t,0);if(3!=s.length)throw"malformed plain PKCS8 private key(code:002)";if("30"!=t.substr(s[1],2))throw"malformed PKCS8 private key(code:003)";var a=i(t,s[1]);if(2!=a.length)throw"malformed PKCS8 private key(code:004)";if("06"!=t.substr(a[0],2))throw"malformed PKCS8 private key(code:005)";if(r.algoid=n(t,a[0]),"06"==t.substr(a[1],2)&&(r.algparam=n(t,a[1])),"04"!=t.substr(s[2],2))throw"malformed PKCS8 private key(code:006)";return r.keyidx=e.getVidx(t,s[2]),r},getKeyFromPlainPrivatePKCS8PEM:function(t){var e=Ht(t,"PRIVATE KEY");return this.getKeyFromPlainPrivatePKCS8Hex(e)},getKeyFromPlainPrivatePKCS8Hex:function(t){var e,i=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==i.algoid)e=new at;else if("2a8648ce380401"==i.algoid)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!=i.algoid)throw"unsupported private key algorithm";e=new ft.crypto.ECDSA}return e.readPKCS8PrvKeyHex(t),e},_getKeyFromPublicPKCS8Hex:function(t){var e,i=pt.getVbyList(t,0,[0,0],"06");if("2a864886f70d010101"===i)e=new at;else if("2a8648ce380401"===i)e=new ft.crypto.DSA;else{if("2a8648ce3d0201"!==i)throw"unsupported PKCS#8 public key hex";e=new ft.crypto.ECDSA}return e.readPKCS8PubKeyHex(t),e},parsePublicRawRSAKeyHex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";var s=i(t,0);if(2!=s.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(s[0],2))throw"malformed RSA key(code:003)";if(r.n=n(t,s[0]),"02"!=t.substr(s[1],2))throw"malformed RSA key(code:004)";return r.e=n(t,s[1]),r},parsePublicPKCS8Hex:function(t){var e=pt,i=e.getChildIdx,n=e.getV,r={algparam:null},s=i(t,0);if(2!=s.length)throw"outer DERSequence shall have 2 elements: "+s.length;var a=s[0];if("30"!=t.substr(a,2))throw"malformed PKCS8 public key(code:001)";var o=i(t,a);if(2!=o.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(o[0],2))throw"malformed PKCS8 public key(code:003)";if(r.algoid=n(t,o[0]),"06"==t.substr(o[1],2)?r.algparam=n(t,o[1]):"30"==t.substr(o[1],2)&&(r.algparam={},r.algparam.p=e.getVbyList(t,o[1],[0],"02"),r.algparam.q=e.getVbyList(t,o[1],[1],"02"),r.algparam.g=e.getVbyList(t,o[1],[2],"02")),"03"!=t.substr(s[1],2))throw"malformed PKCS8 public key(code:004)";return r.key=n(t,s[1]).substr(2),r}}}();Ut.getKey=function(t,e,i){var n=(y=pt).getChildIdx,r=(y.getV,y.getVbyList),s=ft.crypto,a=s.ECDSA,o=s.DSA,h=at,u=Ht,c=Ut;if(void 0!==h&&t instanceof h)return t;if(void 0!==a&&t instanceof a)return t;if(void 0!==o&&t instanceof o)return t;if(void 0!==t.curve&&void 0!==t.xy&&void 0===t.d)return new a({pub:t.xy,curve:t.curve});if(void 0!==t.curve&&void 0!==t.d)return new a({prv:t.d,curve:t.curve});if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(t.n,t.e),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.co&&void 0===t.qi)return(D=new h).setPrivateEx(t.n,t.e,t.d,t.p,t.q,t.dp,t.dq,t.co),D;if(void 0===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0===t.p)return(D=new h).setPrivate(t.n,t.e,t.d),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0===t.x)return(D=new o).setPublic(t.p,t.q,t.g,t.y),D;if(void 0!==t.p&&void 0!==t.q&&void 0!==t.g&&void 0!==t.y&&void 0!==t.x)return(D=new o).setPrivate(t.p,t.q,t.g,t.y,t.x),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0===t.d)return(D=new h).setPublic(xt(t.n),xt(t.e)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d&&void 0!==t.p&&void 0!==t.q&&void 0!==t.dp&&void 0!==t.dq&&void 0!==t.qi)return(D=new h).setPrivateEx(xt(t.n),xt(t.e),xt(t.d),xt(t.p),xt(t.q),xt(t.dp),xt(t.dq),xt(t.qi)),D;if("RSA"===t.kty&&void 0!==t.n&&void 0!==t.e&&void 0!==t.d)return(D=new h).setPrivate(xt(t.n),xt(t.e),xt(t.d)),D;if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0===t.d){var l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);return C.setPublicKeyHex(f),C}if("EC"===t.kty&&void 0!==t.crv&&void 0!==t.x&&void 0!==t.y&&void 0!==t.d){l=(C=new a({curve:t.crv})).ecparams.keylen/4,f="04"+("0000000000"+xt(t.x)).slice(-l)+("0000000000"+xt(t.y)).slice(-l);var d=("0000000000"+xt(t.d)).slice(-l);return C.setPublicKeyHex(f),C.setPrivateKeyHex(d),C}if("pkcs5prv"===i){var g,p=t,y=pt;if(9===(g=n(p,0)).length)(D=new h).readPKCS5PrvKeyHex(p);else if(6===g.length)(D=new o).readPKCS5PrvKeyHex(p);else{if(!(g.length>2&&"04"===p.substr(g[1],2)))throw"unsupported PKCS#1/5 hexadecimal key";(D=new a).readPKCS5PrvKeyHex(p)}return D}if("pkcs8prv"===i)return D=c.getKeyFromPlainPrivatePKCS8Hex(t);if("pkcs8pub"===i)return c._getKeyFromPublicPKCS8Hex(t);if("x509pub"===i)return Jt.getPublicKeyFromCertHex(t);if(-1!=t.indexOf("-END CERTIFICATE-",0)||-1!=t.indexOf("-END X509 CERTIFICATE-",0)||-1!=t.indexOf("-END TRUSTED CERTIFICATE-",0))return Jt.getPublicKeyFromCertPEM(t);if(-1!=t.indexOf("-END PUBLIC KEY-")){var v=Ht(t,"PUBLIC KEY");return c._getKeyFromPublicPKCS8Hex(v)}if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var m=u(t,"RSA PRIVATE KEY");return c.getKey(m,null,"pkcs5prv")}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1==t.indexOf("4,ENCRYPTED")){var S=r(R=u(t,"DSA PRIVATE KEY"),0,[1],"02"),F=r(R,0,[2],"02"),w=r(R,0,[3],"02"),E=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END PRIVATE KEY-"))return c.getKeyFromPlainPrivatePKCS8PEM(t);if(-1!=t.indexOf("-END RSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var A=c.getDecryptedKeyHex(t,e),I=new at;return I.readPKCS5PrvKeyHex(A),I}if(-1!=t.indexOf("-END EC PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var C,D=r(R=c.getDecryptedKeyHex(t,e),0,[1],"04"),T=r(R,0,[2,0],"06"),P=r(R,0,[3,0],"03").substr(2);if(void 0===ft.crypto.OID.oidhex2name[T])throw"undefined OID(hex) in KJUR.crypto.OID: "+T;return(C=new a({curve:ft.crypto.OID.oidhex2name[T]})).setPublicKeyHex(P),C.setPrivateKeyHex(D),C.isPublic=!1,C}if(-1!=t.indexOf("-END DSA PRIVATE KEY-")&&-1!=t.indexOf("4,ENCRYPTED")){var R;S=r(R=c.getDecryptedKeyHex(t,e),0,[1],"02"),F=r(R,0,[2],"02"),w=r(R,0,[3],"02"),E=r(R,0,[4],"02"),b=r(R,0,[5],"02");return(D=new o).setPrivate(new x(S,16),new x(F,16),new x(w,16),new x(E,16),new x(b,16)),D}if(-1!=t.indexOf("-END ENCRYPTED PRIVATE KEY-"))return c.getKeyFromEncryptedPKCS8PEM(t,e);throw"not supported argument"},Ut.generateKeypair=function(t,e){if("RSA"==t){var i=e;(a=new at).generate(i,"10001"),a.isPrivate=!0,a.isPublic=!0;var n=new at,r=a.n.toString(16),s=a.e.toString(16);return n.setPublic(r,s),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}if("EC"==t){var a,o,h=e,u=new ft.crypto.ECDSA({curve:h}).generateKeyPairHex();return(a=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),a.setPrivateKeyHex(u.ecprvhex),a.isPrivate=!0,a.isPublic=!1,(n=new ft.crypto.ECDSA({curve:h})).setPublicKeyHex(u.ecpubhex),n.isPrivate=!1,n.isPublic=!0,(o={}).prvKeyObj=a,o.pubKeyObj=n,o}throw"unknown algorithm: "+t},Ut.getPEM=function(t,e,i,n,r,s){var a=ft,o=a.asn1,h=o.DERObjectIdentifier,u=o.DERInteger,c=o.ASN1Util.newObject,l=o.x509.SubjectPublicKeyInfo,f=a.crypto,d=f.DSA,g=f.ECDSA,p=at;function v(t){return c({seq:[{int:0},{int:{bigint:t.n}},{int:t.e},{int:{bigint:t.d}},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.dmp1}},{int:{bigint:t.dmq1}},{int:{bigint:t.coeff}}]})}function m(t){return c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a0",!0,{oid:{name:t.curveName}}]},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]})}function S(t){return c({seq:[{int:0},{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}},{int:{bigint:t.y}},{int:{bigint:t.x}}]})}if((void 0!==p&&t instanceof p||void 0!==d&&t instanceof d||void 0!==g&&t instanceof g)&&1==t.isPublic&&(void 0===e||"PKCS8PUB"==e))return Rt(x=new l(t).getEncodedHex(),"PUBLIC KEY");if("PKCS1PRV"==e&&void 0!==p&&t instanceof p&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=v(t).getEncodedHex(),"RSA PRIVATE KEY");if("PKCS1PRV"==e&&void 0!==g&&t instanceof g&&(void 0===i||null==i)&&1==t.isPrivate){var F=new h({name:t.curveName}).getEncodedHex(),w=m(t).getEncodedHex(),E="";return E+=Rt(F,"EC PARAMETERS"),E+=Rt(w,"EC PRIVATE KEY")}if("PKCS1PRV"==e&&void 0!==d&&t instanceof d&&(void 0===i||null==i)&&1==t.isPrivate)return Rt(x=S(t).getEncodedHex(),"DSA PRIVATE KEY");if("PKCS5PRV"==e&&void 0!==p&&t instanceof p&&void 0!==i&&null!=i&&1==t.isPrivate){var x=v(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==g&&t instanceof g&&void 0!==i&&null!=i&&1==t.isPrivate){x=m(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",x,i,n,s)}if("PKCS5PRV"==e&&void 0!==d&&t instanceof d&&void 0!==i&&null!=i&&1==t.isPrivate){x=S(t).getEncodedHex();return void 0===n&&(n="DES-EDE3-CBC"),this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",x,i,n,s)}var b=function(t,e){var i=A(t,e);return new c({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:i.pbkdf2Salt}},{int:i.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:i.encryptionSchemeIV}}]}]}]},{octstr:{hex:i.ciphertext}}]}).getEncodedHex()},A=function(t,e){var i=y.lib.WordArray.random(8),n=y.lib.WordArray.random(8),r=y.PBKDF2(e,i,{keySize:6,iterations:100}),s=y.enc.Hex.parse(t),a=y.TripleDES.encrypt(s,r,{iv:n})+"",o={};return o.ciphertext=a,o.pbkdf2Salt=y.enc.Hex.stringify(i),o.pbkdf2Iter=100,o.encryptionSchemeAlg="DES-EDE3-CBC",o.encryptionSchemeIV=y.enc.Hex.stringify(n),o};if("PKCS8PRV"==e&&null!=p&&t instanceof p&&1==t.isPrivate){var I=v(t).getEncodedHex();x=c({seq:[{int:0},{seq:[{oid:{name:"rsaEncryption"}},{null:!0}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==g&&t instanceof g&&1==t.isPrivate){I=new c({seq:[{int:1},{octstr:{hex:t.prvKeyHex}},{tag:["a1",!0,{bitstr:{hex:"00"+t.pubKeyHex}}]}]}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:t.curveName}}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}if("PKCS8PRV"==e&&void 0!==d&&t instanceof d&&1==t.isPrivate){I=new u({bigint:t.x}).getEncodedHex(),x=c({seq:[{int:0},{seq:[{oid:{name:"dsa"}},{seq:[{int:{bigint:t.p}},{int:{bigint:t.q}},{int:{bigint:t.g}}]}]},{octstr:{hex:I}}]}).getEncodedHex();return void 0===i||null==i?Rt(x,"PRIVATE KEY"):Rt(w=b(x,i),"ENCRYPTED PRIVATE KEY")}throw"unsupported object nor format"},Ut.getKeyFromCSRPEM=function(t){var e=Ht(t,"CERTIFICATE REQUEST");return Ut.getKeyFromCSRHex(e)},Ut.getKeyFromCSRHex=function(t){var e=Ut.parseCSRHex(t);return Ut.getKey(e.p8pubkeyhex,null,"pkcs8pub")},Ut.parseCSRHex=function(t){var e=pt,i=e.getChildIdx,n=e.getTLV,r={},s=t;if("30"!=s.substr(0,2))throw"malformed CSR(code:001)";var a=i(s,0);if(a.length<1)throw"malformed CSR(code:002)";if("30"!=s.substr(a[0],2))throw"malformed CSR(code:003)";var o=i(s,a[0]);if(o.length<3)throw"malformed CSR(code:004)";return r.p8pubkeyhex=n(s,o[2]),r},Ut.getJWKFromKey=function(t){var e={};if(t instanceof at&&t.isPrivate)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e.d=Et(t.d.toString(16)),e.p=Et(t.p.toString(16)),e.q=Et(t.q.toString(16)),e.dp=Et(t.dmp1.toString(16)),e.dq=Et(t.dmq1.toString(16)),e.qi=Et(t.coeff.toString(16)),e;if(t instanceof at&&t.isPublic)return e.kty="RSA",e.n=Et(t.n.toString(16)),e.e=Et(t.e.toString(16)),e;if(t instanceof ft.crypto.ECDSA&&t.isPrivate){if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;var i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e.d=Et(t.prvKeyHex),e}if(t instanceof ft.crypto.ECDSA&&t.isPublic){var n;if("P-256"!==(n=t.getShortNISTPCurveName())&&"P-384"!==n)throw"unsupported curve name for JWT: "+n;i=t.getPublicKeyXYHex();return e.kty="EC",e.crv=n,e.x=Et(i.x),e.y=Et(i.y),e}throw"not supported key object"},at.getPosArrayOfChildrenFromHex=function(t){return pt.getChildIdx(t,0)},at.getHexValueArrayOfChildrenFromHex=function(t){var e,i=pt.getV,n=i(t,(e=at.getPosArrayOfChildrenFromHex(t))[0]),r=i(t,e[1]),s=i(t,e[2]),a=i(t,e[3]),o=i(t,e[4]),h=i(t,e[5]),u=i(t,e[6]),c=i(t,e[7]),l=i(t,e[8]);return(e=new Array).push(n,r,s,a,o,h,u,c,l),e},at.prototype.readPrivateKeyFromPEMString=function(t){var e=Ht(t),i=at.getHexValueArrayOfChildrenFromHex(e);this.setPrivateEx(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])},at.prototype.readPKCS5PrvKeyHex=function(t){var e=at.getHexValueArrayOfChildrenFromHex(t);this.setPrivateEx(e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])},at.prototype.readPKCS8PrvKeyHex=function(t){var e,i,n,r,s,a,o,h,u=pt,c=u.getVbyList;if(!1===u.isASN1HEX(t))throw"not ASN.1 hex string";try{e=c(t,0,[2,0,1],"02"),i=c(t,0,[2,0,2],"02"),n=c(t,0,[2,0,3],"02"),r=c(t,0,[2,0,4],"02"),s=c(t,0,[2,0,5],"02"),a=c(t,0,[2,0,6],"02"),o=c(t,0,[2,0,7],"02"),h=c(t,0,[2,0,8],"02")}catch(t){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(e,i,n,r,s,a,o,h)},at.prototype.readPKCS5PubKeyHex=function(t){var e=pt,i=e.getV;if(!1===e.isASN1HEX(t))throw"keyHex is not ASN.1 hex string";var n=e.getChildIdx(t,0);if(2!==n.length||"02"!==t.substr(n[0],2)||"02"!==t.substr(n[1],2))throw"wrong hex for PKCS#5 public key";var r=i(t,n[0]),s=i(t,n[1]);this.setPublic(r,s)},at.prototype.readPKCS8PubKeyHex=function(t){var e=pt;if(!1===e.isASN1HEX(t))throw"not ASN.1 hex string";if("06092a864886f70d010101"!==e.getTLVbyList(t,0,[0,0]))throw"not PKCS8 RSA public key";var i=e.getTLVbyList(t,0,[1,0]);this.readPKCS5PubKeyHex(i)},at.prototype.readCertPubKeyHex=function(t,e){var i,n;(i=new Jt).readCertHex(t),n=i.getPublicKeyHex(),this.readPKCS8PubKeyHex(n)};var qt=new RegExp("");function zt(t,e){for(var i="",n=e/4-t.length,r=0;r>24,(16711680&r)>>16,(65280&r)>>8,255&r])))),r+=1;return n}function Gt(t){for(var e in ft.crypto.Util.DIGESTINFOHEAD){var i=ft.crypto.Util.DIGESTINFOHEAD[e],n=i.length;if(t.substring(0,n)==i)return[e,t.substring(n)]}return[]}function Jt(){var t=pt,e=t.getChildIdx,i=t.getV,n=t.getTLV,r=t.getVbyList,s=t.getTLVbyList,a=t.getIdxbyList,o=t.getVidx,h=t.oidname,u=Jt,c=Ht;this.hex=null,this.version=0,this.foffset=0,this.aExtInfo=null,this.getVersion=function(){return null===this.hex||0!==this.version?this.version:"a003020102"!==s(this.hex,0,[0,0])?(this.version=1,this.foffset=-1,1):(this.version=3,3)},this.getSerialNumberHex=function(){return r(this.hex,0,[0,1+this.foffset],"02")},this.getSignatureAlgorithmField=function(){return h(r(this.hex,0,[0,2+this.foffset,0],"06"))},this.getIssuerHex=function(){return s(this.hex,0,[0,3+this.foffset],"30")},this.getIssuerString=function(){return u.hex2dn(this.getIssuerHex())},this.getSubjectHex=function(){return s(this.hex,0,[0,5+this.foffset],"30")},this.getSubjectString=function(){return u.hex2dn(this.getSubjectHex())},this.getNotBefore=function(){var t=r(this.hex,0,[0,4+this.foffset,0]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getNotAfter=function(){var t=r(this.hex,0,[0,4+this.foffset,1]);return t=t.replace(/(..)/g,"%$1"),t=decodeURIComponent(t)},this.getPublicKeyHex=function(){return t.getTLVbyList(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyIdx=function(){return a(this.hex,0,[0,6+this.foffset],"30")},this.getPublicKeyContentIdx=function(){var t=this.getPublicKeyIdx();return a(this.hex,t,[1,0],"30")},this.getPublicKey=function(){return Ut.getKey(this.getPublicKeyHex(),null,"pkcs8pub")},this.getSignatureAlgorithmName=function(){return h(r(this.hex,0,[1,0],"06"))},this.getSignatureValueHex=function(){return r(this.hex,0,[2],"03",!0)},this.verifySignature=function(t){var e=this.getSignatureAlgorithmName(),i=this.getSignatureValueHex(),n=s(this.hex,0,[0],"30"),r=new ft.crypto.Signature({alg:e});return r.init(t),r.updateHex(n),r.verify(i)},this.parseExt=function(){if(3!==this.version)return-1;var i=a(this.hex,0,[0,7,0],"30"),n=e(this.hex,i);this.aExtInfo=new Array;for(var s=0;s0&&(u=new Array(i),(new nt).nextBytes(u),u=String.fromCharCode.apply(String,u));var c=It(h(Ct("\0\0\0\0\0\0\0\0"+r+u))),l=[];for(n=0;n>8*o-a&255;for(g[0]&=~p,n=0;nthis.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;var r=n[0];return n[1]==function(t){return ft.crypto.Util.hashString(t,r)}(t)},at.prototype.verifyWithMessageHash=function(t,e){var i=rt(e=(e=e.replace(qt,"")).replace(/[ \n]+/g,""),16);if(i.bitLength()>this.n.bitLength())return 0;var n=Gt(this.doPublic(i).toString(16).replace(/^1f+00/,""));if(0==n.length)return!1;n[0];return n[1]==t},at.prototype.verifyPSS=function(t,e,i,n){var r,s=(r=Ct(t),ft.crypto.Util.hashHex(r,i));return void 0===n&&(n=-1),this.verifyWithMessageHashPSS(s,e,i,n)},at.prototype.verifyWithMessageHashPSS=function(t,e,i,n){var r=new x(e,16);if(r.bitLength()>this.n.bitLength())return!1;var s,a=function(t){return ft.crypto.Util.hashHex(t,i)},o=It(t),h=o.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===n||void 0===n)n=h;else if(-2===n)n=c-h-2;else if(n<-2)throw"invalid salt length";if(c>8*c-u&255;if(0!=(f.charCodeAt(0)&g))throw"bits beyond keysize not zero";var p=Yt(d,f.length,a),y=[];for(s=0;s0)&&-1==(":"+i.join(":")+":").indexOf(":"+p+":"))throw"algorithm '"+p+"' not accepted in the list";if("none"!=p&&null===e)throw"key shall be specified to verify.";if("string"==typeof e&&-1!=e.indexOf("-----BEGIN ")&&(e=Ut.getKey(e)),!("RS"!=y&&"PS"!=y||e instanceof n))throw"key shall be a RSAKey obj for RS* and PS* algs";if("ES"==y&&!(e instanceof h))throw"key shall be a ECDSA obj for ES* algs";var v=null;if(void 0===s.jwsalg2sigalg[g.alg])throw"unsupported alg name: "+p;if("none"==(v=s.jwsalg2sigalg[p]))throw"not supported";if("Hmac"==v.substr(0,4)){if(void 0===e)throw"hexadecimal key shall be specified for HMAC";var m=new u({alg:v,pass:e});return m.updateString(f),d==m.doFinal()}if(-1!=v.indexOf("withECDSA")){var S,F=null;try{F=h.concatSigToASN1Sig(d)}catch(t){return!1}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(F)}return(S=new c({alg:v})).init(e),S.updateString(f),S.verify(d)},ft.jws.JWS.parse=function(t){var e,i,n,r=t.split("."),s={};if(2!=r.length&&3!=r.length)throw"malformed sJWS: wrong number of '.' splitted elements";return e=r[0],i=r[1],3==r.length&&(n=r[2]),s.headerObj=ft.jws.JWS.readSafeJSONString(gt(e)),s.payloadObj=ft.jws.JWS.readSafeJSONString(gt(i)),s.headerPP=JSON.stringify(s.headerObj,null," "),null==s.payloadObj?s.payloadPP=gt(i):s.payloadPP=JSON.stringify(s.payloadObj,null," "),void 0!==n&&(s.sigHex=xt(n)),s},ft.jws.JWS.verifyJWT=function(t,e,i){var n=ft.jws,r=n.JWS,s=r.readSafeJSONString,a=r.inArray,o=r.includedArray,h=t.split("."),u=h[0],c=h[1],l=(xt(h[2]),s(gt(u))),f=s(gt(c));if(void 0===l.alg)return!1;if(void 0===i.alg)throw"acceptField.alg shall be specified";if(!a(l.alg,i.alg))return!1;if(void 0!==f.iss&&"object"==typeof i.iss&&!a(f.iss,i.iss))return!1;if(void 0!==f.sub&&"object"==typeof i.sub&&!a(f.sub,i.sub))return!1;if(void 0!==f.aud&&"object"==typeof i.aud)if("string"==typeof f.aud){if(!a(f.aud,i.aud))return!1}else if("object"==typeof f.aud&&!o(f.aud,i.aud))return!1;var d=n.IntDate.getNow();return void 0!==i.verifyAt&&"number"==typeof i.verifyAt&&(d=i.verifyAt),void 0!==i.gracePeriod&&"number"==typeof i.gracePeriod||(i.gracePeriod=0),!(void 0!==f.exp&&"number"==typeof f.exp&&f.exp+i.gracePeriodr&&this.aHeader.pop(),this.aSignature.length>r&&this.aSignature.pop(),"addSignature failed: "+t}},this.verifyAll=function(t){if(this.aHeader.length!==t.length||this.aSignature.length!==t.length)return!1;for(var e=0;e0))throw"malformed header";if(this.aHeader=t.headers,"string"!=typeof t.payload)throw"malformed signatures";if(this.sPayload=t.payload,!(t.signatures.length>0))throw"malformed signatures";this.aSignatures=t.signatures}catch(t){throw"malformed JWS-JS JSON object: "+t}},this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}},this.isEmpty=function(){return 0==this.aHeader.length?1:0}},e.SecureRandom=nt,e.rng_seed_time=Z,e.BigInteger=x,e.RSAKey=at,e.ECDSA=ft.crypto.ECDSA,e.DSA=ft.crypto.DSA,e.Signature=ft.crypto.Signature,e.MessageDigest=ft.crypto.MessageDigest,e.Mac=ft.crypto.Mac,e.Cipher=ft.crypto.Cipher,e.KEYUTIL=Ut,e.ASN1HEX=pt,e.X509=Jt,e.CryptoJS=y,e.b64tohex=w,e.b64toBA=E,e.stoBA=yt,e.BAtos=vt,e.BAtohex=mt,e.stohex=St,e.stob64=function(t){return F(St(t))},e.stob64u=function(t){return Ft(F(St(t)))},e.b64utos=function(t){return vt(E(wt(t)))},e.b64tob64u=Ft,e.b64utob64=wt,e.hex2b64=F,e.hextob64u=Et,e.b64utohex=xt,e.utf8tob64u=dt,e.b64utoutf8=gt,e.utf8tob64=function(t){return F(Ot(Kt(t)))},e.b64toutf8=function(t){return decodeURIComponent(jt(w(t)))},e.utf8tohex=bt,e.hextoutf8=At,e.hextorstr=It,e.rstrtohex=Ct,e.hextob64=Dt,e.hextob64nl=Tt,e.b64nltohex=Pt,e.hextopem=Rt,e.pemtohex=Ht,e.hextoArrayBuffer=function(t){if(t.length%2!=0)throw"input is not even length";if(null==t.match(/^[0-9A-Fa-f]+$/))throw"input is not hexadecimal";for(var e=new ArrayBuffer(t.length/2),i=new DataView(e),n=0;ne.length&&(i=e.length);for(var n=0;n300)throw new r(`Failed to fetch ${t}. Response=${s}`,i.status);try{return JSON.parse(s)}catch(e){throw new r(`Invalid response while trying to fetch ${t}. Response=${s}`,i.status)}}}},function(t,e,i){const n=i(0),r=i(15);t.exports=class{constructor({jwt:t=i(1)}={}){this.jwt=t}decodeAndValidate({token:t,publicKeys:e,issuer:i,clientId:s,nonce:a}){const o=Math.floor(Date.now()/1e3),h=t.split(".");if(3!==h.length)throw new r(`Invalid JWT token. Got only ${h.length} parts.`);const u=this.jwt.KJUR.jws.JWS.parse(t);if(!u.headerObj)throw new r(n.INVALID_TOKEN);const c=u.headerObj.kid,l=this.getPublicKey(e.keys,c),f=this.jwt.KEYUTIL.getKey(l);if(!this.jwt.KJUR.jws.JWS.verify(t,f,{alg:[n.TOKEN_ALG]}))throw new r(n.INVALID_SIGNATURE);if(u.payloadObj.exp * @license MIT */ -var n=i(9),r=i(10),s=i(11);function a(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return M(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return k(t).length;default:if(n)return M(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return w(this,t,e,i);case"latin1":case"binary":return E(this,t,e,i);case"base64":return x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||H(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||H(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||H(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||H(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||H(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||H(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||H(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||H(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||H(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||H(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function k(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(_,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(8))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e){t.exports=class extends Error{constructor({error:t,description:e}){super(e||t),this.error=t,this.description=e}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(17);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){const e=t.height,i=t.width,r=(screen.width-i)/2,s=(screen.height-e)/2;if(this.popup=this.window.open("","popup",`left=${r},top=${s},width=${i},height=${e},resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(19);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}}])})); \ No newline at end of file +var n=i(9),r=i(10),s=i(11);function a(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return k(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return M(t).length;default:if(n)return k(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,i);case"utf8":case"utf-8":return I(this,e,i);case"ascii":return D(this,e,i);case"latin1":case"binary":return T(this,e,i);case"base64":return A(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function v(t,e,i,n,r){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:m(t,e,i,n,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):m(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,i,n,r){var s,a=1,o=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,o/=2,h/=2,i/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var c=-1;for(s=i;so&&(i=o-h),s=i;s>=0;s--){for(var l=!0,f=0;fr&&(n=r):n=r;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var a=0;a>8,r=i%256,s.push(r),s.push(n);return s}(e,t.length-i),t,i,n)}function A(t,e,i){return 0===e&&i===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,i))}function I(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;r239?4:u>223?3:u>191?2:1;if(r+l<=i)switch(l){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[r+1],a=t[r+2],128==(192&s)&&128==(192&a)&&(h=(15&u)<<12|(63&s)<<6|63&a)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[r+1],a=t[r+2],o=t[r+3],128==(192&s)&&128==(192&a)&&128==(192&o)&&(h=(15&u)<<18|(63&s)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(c=h)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),r+=l}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var i="",n=0;for(;n0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),""},h.prototype.compare=function(t,e,i,n,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var s=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),o=Math.min(s,a),u=this.slice(n,r),c=t.slice(e,i),l=0;lr)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return S(this,t,e,i);case"utf8":case"utf-8":return F(this,t,e,i);case"ascii":return w(this,t,e,i);case"latin1":case"binary":return E(this,t,e,i);case"base64":return x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function D(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",s=e;si)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,n,r,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function N(t,e,i,n){e<0&&(e=65535+e+1);for(var r=0,s=Math.min(t.length-i,2);r>>8*(n?r:1-r)}function O(t,e,i,n){e<0&&(e=4294967295+e+1);for(var r=0,s=Math.min(t.length-i,4);r>>8*(n?r:3-r)&255}function j(t,e,i,n,r,s){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function V(t,e,i,n,s){return s||j(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function L(t,e,i,n,s){return s||j(t,0,i,8),r.write(t,e,i,n,52,8),i+8}h.prototype.slice=function(t,e){var i,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(r*=256);)n+=this[t+--e]*r;return n},h.prototype.readUInt8=function(t,e){return e||H(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||H(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||H(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||H(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||H(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=this[t],r=1,s=0;++s=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||H(t,e,this.length);for(var n=e,r=1,s=this[t+--n];n>0&&(r*=256);)s+=this[t+--n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||H(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||H(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||H(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||H(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||H(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||H(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||H(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,n){(t=+t,e|=0,i|=0,n)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+r]=t/s&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):O(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=0,a=1,o=0;for(this[e]=255&t;++s>0)-o&255;return e+i},h.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e|=0,!n){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var s=i-1,a=1,o=0;for(this[e+s]=255&t;--s>=0&&(a*=256);)t<0&&0===o&&0!==this[e+s+1]&&(o=1),this[e+s]=(t/a>>0)-o&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):O(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):O(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return V(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return V(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,n){if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&s.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&s.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;s.push(i)}else if(i<2048){if((e-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function M(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(_,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function U(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(8))},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){"use strict";e.byteLength=function(t){var e=u(t),i=e[0],n=e[1];return 3*(i+n)/4-n},e.toByteArray=function(t){var e,i,n=u(t),a=n[0],o=n[1],h=new s(function(t,e,i){return 3*(e+i)/4-i}(0,a,o)),c=0,l=o>0?a-4:a;for(i=0;i>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===o&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[c++]=255&e);1===o&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,s=[],a=0,o=i-r;ao?o:a+16383));1===r?(e=t[i-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function c(t,e,i){for(var r,s,a=[],o=e;o>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,i,n,r){var s,a,o=8*r-n-1,h=(1<>1,c=-7,l=i?r-1:0,f=i?-1:1,d=t[e+l];for(l+=f,s=d&(1<<-c)-1,d>>=-c,c+=o;c>0;s=256*s+t[e+l],l+=f,c-=8);for(a=s&(1<<-c)-1,s>>=-c,c+=n;c>0;a=256*a+t[e+l],l+=f,c-=8);if(0===s)s=1-u;else{if(s===h)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),s-=u}return(d?-1:1)*a*Math.pow(2,s-n)},e.write=function(t,e,i,n,r,s){var a,o,h,u=8*s-r-1,c=(1<>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,g=n?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-a))<1&&(a--,h*=2),(e+=a+l>=1?f/h:f*Math.pow(2,1-l))*h>=2&&(a++,h/=2),a+l>=c?(o=0,a=c):a+l>=1?(o=(e*h-1)*Math.pow(2,r),a+=l):(o=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[i+d]=255&o,d+=g,o/=256,r-=8);for(a=a<0;t[i+d]=255&a,d+=g,a/=256,u-=8);t[i+d-g]|=128*p}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e){t.exports=class extends Error{constructor({error:t,description:e}){super(e||t),this.error=t,this.description=e}}},function(t,e,i){"use strict";var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,e.default=n.fetch.bind(n),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},function(t,e){t.exports=class extends Error{constructor(t,e){super(t),this.status=e}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(17);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){const e=t.height,i=t.width,r=(screen.width-i)/2,s=(screen.height-e)/2;if(this.popup=this.window.open("","popup",`left=${r},top=${s},width=${i},height=${e},resizable,scrollbars=yes,status=1`),!this.popup)throw new n("Unable to open popup")}navigate({authUrl:t}){this.popup.location.href=t}close(){this.popup.close()}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{this.popup.closed&&(clearInterval(r),i(new n("Popup closed")))},1e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&e(i)})})}}},function(t,e){t.exports=class extends Error{}},function(t,e,i){const n=i(19);t.exports=class{constructor({w:t=window}={}){this.window=t}open(t){this.iFrame=this.window.document.createElement("iframe"),this.iFrame.src=t,this.iFrame.width=0,this.iFrame.height=0,this.window.document.body.appendChild(this.iFrame)}remove(){window.document.body.removeChild(this.iFrame)}async waitForMessage({messageType:t}){return new Promise((e,i)=>{const r=setInterval(()=>{i(new n("Silent sign-in timed out"))},5e3);window.addEventListener("message",i=>{i.data&&i.data.type===t&&(clearInterval(r),e(i))})})}}},function(t,e){t.exports=class extends Error{}},function(t,e){t.exports=class{async init({discoveryEndpoint:t,requestHandler:e}){this.openIdConfig=await e(t),this.publicKeys=e(this.getJwksEndpoint())}getAuthorizationEndpoint(){return this.openIdConfig.authorization_endpoint}getUserInfoEndpoint(){return this.openIdConfig.userinfo_endpoint}getJwksEndpoint(){return this.openIdConfig.jwks_uri}getTokenEndpoint(){return this.openIdConfig.token_endpoint}getIssuer(){return this.openIdConfig.issuer}async getPublicKeys(){return await this.publicKeys}}}])})); \ No newline at end of file diff --git a/src/constants.js b/src/constants.js index 338a87f..1e7dbbb 100644 --- a/src/constants.js +++ b/src/constants.js @@ -13,7 +13,8 @@ module.exports = { MISSING_PUBLIC_KEY: 'Cannot find public key', INVALID_ACCESS_TOKEN: 'Access token must be a string', MISSING_CLIENT_ID: 'Missing client ID', - MISSING_DISCOVERY_ENDPOINT: 'Missing discovery endpoint', + INVALID_DISCOVERY_ENDPOINT: 'Invalid discovery endpoint', + FAIL_TO_INITIALIZE: 'You must call and wait for init() before calling this function.', RESPONSE_TYPE: 'code', RESPONSE_MODE: 'web_message', PROMPT: 'none', diff --git a/src/index.js b/src/index.js index 2aa3e8b..3192da5 100644 --- a/src/index.js +++ b/src/index.js @@ -21,8 +21,8 @@ class AppID { popup = new PopupController(), iframe = new IFrameController(), tokenValidator = new TokenValidator(), - openID = new OpenIdConfigurationResource(), - utils = new Utils(), + openIdConfigResource = new OpenIdConfigurationResource(), + utils, requestHandler = new RequestHandler(), w = window, url = URL @@ -31,22 +31,26 @@ class AppID { this.popup = popup; this.iframe = iframe; this.tokenValidator = tokenValidator; - this.openIdConfigResource = openID; + this.openIdConfigResource = openIdConfigResource; + this.URL = url; this.utils = utils; + if (!utils) { + this.utils = new Utils({openIdConfigResource: this.openIdConfigResource, url: this.URL}); + } this.request = requestHandler.request; this.window = w; - this.URL = url; + this.initialized = false; } /** - * Initialize AppID + * Initialize AppID. Call this function before attempting to sign in. You must wait for the promise to resolve. * @param {Object} options * @param {string} options.clientId - The clientId from the singlepageapp application credentials. * @param {string} options.discoveryEndpoint - The discoveryEndpoint from the singlepageapp application credentials. * @param {Object} [options.popup] - The popup configuration. * @param {Number} options.popup.height - The popup height. * @param {Number} options.popup.width - The popup width. - * @returns {Promise} + * @returns {Promise} * @throws {AppIDError} For missing required params. * @throws {RequestError} Any errors during a HTTP request. * @example @@ -60,13 +64,16 @@ class AppID { if (!clientId) { throw new AppIDError(constants.MISSING_CLIENT_ID); } - if (!discoveryEndpoint) { - throw new AppIDError(constants.MISSING_DISCOVERY_ENDPOINT); + try { + new this.URL(discoveryEndpoint) + } catch (e) { + throw new AppIDError(constants.INVALID_DISCOVERY_ENDPOINT); } + await this.openIdConfigResource.init({discoveryEndpoint, requestHandler: this.request}); this.clientId = clientId; this.popupConfig = popup; - this.utils = new Utils({openId: this.openIdConfigResource, clientId: this.clientId, url: this.URL}); + this.initialized = true; } /** @@ -89,6 +96,8 @@ class AppID { * const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.signin(); */ async signin() { + this._validateInitalize(); + const {codeVerifier, nonce, state, authUrl} = this.utils.getAuthParams(this.clientId, this.window.origin); this.popup.open(this.popupConfig); @@ -101,6 +110,7 @@ class AppID { let authCode = message.data.code; return await this.utils.exchangeTokens({ + clientId: this.clientId, authCode, codeVerifier, nonce, @@ -121,6 +131,7 @@ class AppID { * const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.silentSignin(); */ async silentSignin() { + this._validateInitalize(); const {codeVerifier, nonce, state, authUrl} = this.utils.getAuthParams(this.clientId, this.window.origin, constants.PROMPT); this.iframe.open(authUrl); @@ -152,6 +163,7 @@ class AppID { * @throws {RequestError} Any errors during a HTTP request. */ async getUserInfo(accessToken) { + this._validateInitalize(); if (typeof accessToken !== 'string') { throw new AppIDError(constants.INVALID_ACCESS_TOKEN); } @@ -162,6 +174,16 @@ class AppID { } }); } + + /** + * + * @private + */ + _validateInitalize() { + if (!this.initialized) { + throw new AppIDError(constants.FAIL_TO_INITIALIZE); + } + } } module.exports = AppID; diff --git a/src/utils.js b/src/utils.js index 93a5cb5..9ac621a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -11,14 +11,12 @@ class Utils { requestHandler = new RequestHandler(), tokenValidator = new TokenValidator(), url = URL, - openId, - clientId + openIdConfigResource } = {}) { this.URL = url; this.request = requestHandler.request; this.tokenValidator = tokenValidator; - this.openId = openId; - this.clientId = clientId; + this.openIdConfigResource = openIdConfigResource; }; buildParams(params) { @@ -40,7 +38,6 @@ class Utils { const codeChallenge = this.sha256(codeVerifier); const nonce = this.getRandomString(constants.NONCE_LENGTH); const state = this.getRandomString(constants.STATE_LENGTH); - this.clientId = clientId; let authParams = { client_id: clientId, @@ -58,7 +55,7 @@ class Utils { authParams.prompt = prompt; } - const authUrl = this.openId.getAuthorizationEndpoint() + '?' + this.buildParams(authParams); + const authUrl = this.openIdConfigResource.getAuthorizationEndpoint() + '?' + this.buildParams(authParams); return { codeVerifier, nonce, @@ -76,13 +73,13 @@ class Utils { throw new AppIDError(constants.INVALID_STATE); } - if (message.origin !== new this.URL(this.openId.getAuthorizationEndpoint()).origin) { + if (message.origin !== new this.URL(this.openIdConfigResource.getAuthorizationEndpoint()).origin) { throw new AppIDError(constants.INVALID_ORIGIN); } } - async exchangeTokens({authCode, nonce, codeVerifier, windowOrigin}) { - let issuer = this.openId.getIssuer(); + async exchangeTokens({clientId, authCode, nonce, codeVerifier, windowOrigin}) { + let issuer = this.openIdConfigResource.getIssuer(); let params = { grant_type: 'authorization_code', redirect_uri: windowOrigin, @@ -91,23 +88,23 @@ class Utils { }; const requestParams = this.buildParams(params); - const tokenEndpoint = this.openId.getTokenEndpoint(); + const tokenEndpoint = this.openIdConfigResource.getTokenEndpoint(); const tokens = await this.request(tokenEndpoint, { method: 'POST', headers: { - 'Authorization': 'Basic ' + rs.stob64(`${this.clientId}:${codeVerifier}`), + 'Authorization': 'Basic ' + rs.stob64(`${clientId}:${codeVerifier}`), 'Content-Type': 'application/x-www-form-urlencoded' }, body: requestParams }); - const publicKeys = await this.openId.getPublicKeys(); + const publicKeys = await this.openIdConfigResource.getPublicKeys(); const accessTokenPayload = this.tokenValidator.decodeAndValidate({ token: tokens.access_token, publicKeys, issuer, - clientId: this.clientId, + clientId, nonce }); @@ -115,7 +112,7 @@ class Utils { token: tokens.id_token, publicKeys, issuer, - clientId: this.clientId, + clientId, nonce }); diff --git a/test/AppIdTest.js b/test/AppIdTest.js index 9de7599..ad67c1a 100644 --- a/test/AppIdTest.js +++ b/test/AppIdTest.js @@ -8,37 +8,45 @@ const OpenIdConfigurationResource = require('./mocks/OpenIdConfigurationMock'); const TokenValidator = require('./mocks/TokenValidatorMock'); const RequestHandler = require('./mocks/RequestHandlerMock'); const {URL} = require('url'); - +const defaultInit = {clientId: '1234', discoveryEndpoint: 'http://authServer.com/', popup: {height: 400, width: 300}}; describe('AppID tests', () => { describe('init', () => { const appID = new AppID({ popup: new PopupController({invalidState: false, error: false, invalidOrigin: false}), iframe: new IFrameController({invalidState: false, error: false, invalidOrigin: false}), tokenValidator: new TokenValidator(), - openID: new OpenIdConfigurationResource(), + openIdConfigResource: new OpenIdConfigurationResource(), utils: new Utils(), requestHandler: new RequestHandler(), w: {origin: 'http://localhost:3005'}, url: URL }); + it('should return error - must call init before sign in', async () => { + try { + await appID.signin(); + } catch (e) { + assert.equal(e.message, constants.FAIL_TO_INITIALIZE); + } + }); + it('should pass', async () => { - await appID.init({clientId: '1234', discoveryEndpoint: 'discoveryEndpoint', popup: {height: 400, width: 300}}); + await appID.init(defaultInit); }); it('should return error - missing client id', async () => { try { - await appID.init({discoveryEndpoint: 'discoveryEndpoint', popup: {height: 400, width: 300}}); + await appID.init({discoveryEndpoint: 'http://authServer.com/', popup: {height: 400, width: 300}}); } catch (e) { assert.equal(e.message, constants.MISSING_CLIENT_ID); } }); - it('should return error - missing discovery endpoint', async () => { + it('should return error - invalid discovery endpoint', async () => { try { await appID.init({clientId: '1234', popup: {height: 400, width: 300}}); } catch (e) { - assert.equal(e.message, constants.MISSING_DISCOVERY_ENDPOINT); + assert.equal(e.message, constants.INVALID_DISCOVERY_ENDPOINT); } }); }); @@ -49,12 +57,13 @@ describe('AppID tests', () => { popup: new PopupController({invalidState: false, error: false, invalidOrigin: false}), iframe: new IFrameController({invalidState: false, error: false, invalidOrigin: false}), tokenValidator: new TokenValidator(), - openID: new OpenIdConfigurationResource(), + openIdConfigResource: new OpenIdConfigurationResource(), utils: new Utils(), requestHandler: new RequestHandler(), w: {origin: 'http://localhost:3005'}, url: URL }); + await appID.init(defaultInit); let res = await appID.signin(); assert.equal(res.accessToken, 'accessToken'); assert.equal(res.idToken, 'idToken'); @@ -66,13 +75,14 @@ describe('AppID tests', () => { popup: new PopupController({invalidState: true, error: false}), iframe: new IFrameController({invalidState: false, error: false, invalidOrigin: false}), tokenValidator: new TokenValidator(), - openID: new OpenIdConfigurationResource(), + openIdConfigResource: new OpenIdConfigurationResource(), utils: new Utils(), requestHandler: new RequestHandler(), w: {origin: 'localhost'}, url: URL }); try { + await appID.init(defaultInit); await appID.signin(); } catch (e) { assert.equal(e.description, constants.INVALID_STATE); @@ -84,13 +94,14 @@ describe('AppID tests', () => { popup: new PopupController({invalidState: false, error: true}), iframe: new IFrameController({invalidState: false, error: false, invalidOrigin: false}), tokenValidator: new TokenValidator(), - openID: new OpenIdConfigurationResource(), + openIdConfigResource: new OpenIdConfigurationResource(), utils: new Utils(), requestHandler: new RequestHandler(), w: {origin: 'localhost'}, url: URL }); try { + await appID.init(defaultInit); await appID.signin(); } catch (e) { assert.equal(e.error, 'access_denied'); @@ -106,12 +117,13 @@ describe('AppID tests', () => { popup: new PopupController({invalidState: false, error: true}), iframe: new IFrameController({invalidState: false, error: false, invalidOrigin: false}), tokenValidator: new TokenValidator(), - openID: new OpenIdConfigurationResource(), + openIdConfigResource: new OpenIdConfigurationResource(), utils: new Utils(), requestHandler: new RequestHandler(), w: {origin: 'localhost'}, url: URL }); + await appID.init(defaultInit); let res = await appID.silentSignin(); assert.equal(res.accessToken, 'accessToken'); assert.equal(res.idToken, 'idToken'); @@ -123,13 +135,14 @@ describe('AppID tests', () => { popup: new PopupController({invalidState: false, error: true}), iframe: new IFrameController({invalidState: false, error: true, invalidOrigin: false}), tokenValidator: new TokenValidator(), - openID: new OpenIdConfigurationResource(), + openIdConfigResource: new OpenIdConfigurationResource(), utils: new Utils(), requestHandler: new RequestHandler(), w: {origin: 'localhost'}, url: URL }); try { + await appID.init(defaultInit); await appID.silentSignin(); } catch (e) { assert.equal(e.description, 'Unable to log in due to time out. Try again'); @@ -141,13 +154,14 @@ describe('AppID tests', () => { popup: new PopupController({invalidState: false, error: true}), iframe: new IFrameController({invalidState: false, error: false, invalidOrigin: true}), tokenValidator: new TokenValidator(), - openID: new OpenIdConfigurationResource(), + openIdConfigResource: new OpenIdConfigurationResource(), utils: new Utils(), requestHandler: new RequestHandler(), w: {origin: 'https://localhost'}, url: URL }); try { + await appID.init(defaultInit); await appID.silentSignin(); } catch (e) { assert.equal(e.description, 'Invalid origin'); @@ -159,13 +173,14 @@ describe('AppID tests', () => { popup: new PopupController({invalidState: false, error: true}), iframe: new IFrameController({invalidState: true, error: false, invalidOrigin: false}), tokenValidator: new TokenValidator(), - openID: new OpenIdConfigurationResource(), + openIdConfigResource: new OpenIdConfigurationResource(), utils: new Utils(), requestHandler: new RequestHandler(), w: {origin: 'localhost'}, url: URL }); try { + await appID.init(defaultInit); await appID.silentSignin(); } catch (e) { assert.equal(e.description, 'Invalid state'); @@ -175,17 +190,18 @@ describe('AppID tests', () => { describe('getUserInfo', () => { let appID; - beforeEach(() => { + beforeEach(async () => { appID = new AppID({ popup: new PopupController({invalidState: false, error: false}), iframe: new IFrameController({invalidState: false, error: false, invalidOrigin: false}), tokenValidator: new TokenValidator(), - openID: new OpenIdConfigurationResource(), + openIdConfigResource: new OpenIdConfigurationResource(), utils: new Utils(), requestHandler: new RequestHandler(), w: {origin: 'localhost'}, url: URL }); + await appID.init(defaultInit); }); it('should return user info', async () => { diff --git a/test/utilsTest.js b/test/utilsTest.js index b1517f5..f1f4d08 100644 --- a/test/utilsTest.js +++ b/test/utilsTest.js @@ -8,7 +8,7 @@ const utils = new Utils( { requestHandler: new RequestHandler(), tokenValidator: new TokenValidator(), - openId: new OpenIdConfigurationResource(), + openIdConfigResource: new OpenIdConfigurationResource(), clientId: '1234', url: URL }); From d4200760f221a1508be248c52df3f5115151c378 Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Mon, 30 Sep 2019 11:14:55 -0500 Subject: [PATCH 14/15] adding /docs --- docs/AppID.html | 1282 ++++++++++++++++++ docs/global.html | 342 +++++ docs/index.html | 131 ++ docs/index.js.html | 258 ++++ docs/scripts/collapse.js | 20 + docs/scripts/linenumber.js | 25 + docs/scripts/nav.js | 12 + docs/scripts/polyfill.js | 4 + docs/scripts/prettify/Apache-License-2.0.txt | 202 +++ docs/scripts/prettify/lang-css.js | 2 + docs/scripts/prettify/prettify.js | 28 + docs/scripts/search.js | 83 ++ docs/styles/jsdoc.css | 671 +++++++++ docs/styles/prettify.css | 79 ++ 14 files changed, 3139 insertions(+) create mode 100644 docs/AppID.html create mode 100644 docs/global.html create mode 100644 docs/index.html create mode 100644 docs/index.js.html create mode 100644 docs/scripts/collapse.js create mode 100644 docs/scripts/linenumber.js create mode 100644 docs/scripts/nav.js create mode 100644 docs/scripts/polyfill.js create mode 100644 docs/scripts/prettify/Apache-License-2.0.txt create mode 100644 docs/scripts/prettify/lang-css.js create mode 100644 docs/scripts/prettify/prettify.js create mode 100644 docs/scripts/search.js create mode 100644 docs/styles/jsdoc.css create mode 100644 docs/styles/prettify.css diff --git a/docs/AppID.html b/docs/AppID.html new file mode 100644 index 0000000..aa7ce12 --- /dev/null +++ b/docs/AppID.html @@ -0,0 +1,1282 @@ + + + + + + AppID - Documentation + + + + + + + + + + + + + + + + + + + +
+ +

AppID

+ + + + + + + +
+ +
+ +

+ AppID +

+ +

This class provides functions to support authentication.

+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

new AppID()

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

This creates an instance of AppID. Once created, call init() before attempting to sign in.

+
+ + + + + + + + + +
Example
+ +
const appID = new AppID();
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

(async) getUserInfo(accessToken) → {Promise}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

This method will made a GET request to the user info endpoint using the access token of the authenticated user.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
accessToken + + +string + + + +

The App ID access token of the user.

+ + + + + + + + + + + + + + +
Throws:
+
    +
  • + +
    +
    +
    +

    "Access token must be a string" Invalid access token.

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +AppIDError + + +
    +
    +
    +
    +
    + +
  • + +
  • + +
    +
    +
    +

    Any errors during a HTTP request.

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +RequestError + + +
    +
    +
    +
    +
    + +
  • +
+ + +
Returns:
+ + +
+

The user information for the authenticated user. Example: {sub: '', email: ''}

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

(async) init(options) → {Promise.<void>}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Initialize AppID. Call this function before attempting to sign in. You must wait for the promise to resolve.

+
+ + + + + + + + + +
Example
+ +
await appID.init({
+	clientId: '<SPA_CLIENT_ID>',
+	discoveryEndpoint: '<WELL_KNOWN_ENDPOINT>'
+});
+ + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
options + + +Object + + + + +
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
clientId + + +string + + + + + + + + + +

The clientId from the singlepageapp application credentials.

discoveryEndpoint + + +string + + + + + + + + + +

The discoveryEndpoint from the singlepageapp application credentials.

popup + + +Object + + + + + + <optional>
+ + + + + +

The popup configuration.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
height + + +Number + + + +

The popup height.

width + + +Number + + + +

The popup width.

+ +
+ +
+ + + + + + + + + + + + + + +
Throws:
+
    +
  • + +
    +
    +
    +

    For missing required params.

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +AppIDError + + +
    +
    +
    +
    +
    + +
  • + +
  • + +
    +
    +
    +

    Any errors during a HTTP request.

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +RequestError + + +
    +
    +
    +
    +
    + +
  • +
+ + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<void> + + +
+
+ + + + + + + + + + +

(async) signin() → {Promise.<Tokens>}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

This will open a sign in widget in a popup which will prompt the user to enter their credentials.
+After a successful sign in, the popup will close and tokens are returned.

+
+ + + + + + + + + +
Example
+ +
const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.signin();
+ + + + + + + + + + + + + + + + +
Throws:
+
    +
  • + +
    +
    +
    +

    "Popup closed" - The user closed the popup before authentication was completed.

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +PopupError + + +
    +
    +
    +
    +
    + +
  • + +
  • + +
    +
    +
    +

    Any token validation error.

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +TokenError + + +
    +
    +
    +
    +
    + +
  • + +
  • + +
    +
    +
    +

    Any errors from the server according to the OAuth spec. e.g. {error: 'server_error', description: ''}

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +OAuthError + + +
    +
    +
    +
    +
    + +
  • + +
  • + +
    +
    +
    +

    Any errors during a HTTP request.

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +RequestError + + +
    +
    +
    +
    +
    + +
  • +
+ + +
Returns:
+ + +
+

The tokens of the authenticated user.

+
+ + + +
+
+ Type +
+
+ +Promise.<Tokens> + + +
+
+ + + + + + + + + + +

(async) silentSignin() → {Promise.<Tokens>}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Silent sign in will attempt to authenticate the user in a hidden iframe.
+You will need to enable Cloud Directory SSO.
+Sign in will be successful only if the user has previously signed in using Cloud Directory and their session is not expired.

+
+ + + + + + + + + +
Example
+ +
const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.silentSignin();
+ + + + + + + + + + + + + + + + +
Throws:
+
    +
  • + +
    +
    +
    +

    Any errors from the server according to the OAuth spec. e.g. {error: 'access_denied', description: 'User not signed in'}

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +OAuthError + + +
    +
    +
    +
    +
    + +
  • + +
  • + +
    +
    +
    +

    "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed.

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +IFrameError + + +
    +
    +
    +
    +
    + +
  • + +
  • + +
    +
    +
    +

    Any token validation error.

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +TokenError + + +
    +
    +
    +
    +
    + +
  • + +
  • + +
    +
    +
    +

    Any errors during a HTTP request.

    +
    +
    +
    +
    +
    +
    + Type +
    +
    + +RequestError + + +
    +
    +
    +
    +
    + +
  • +
+ + +
Returns:
+ + +
+

The tokens of the authenticated user.

+
+ + + +
+
+ Type +
+
+ +Promise.<Tokens> + + +
+
+ + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ +
+ Documentation generated by JSDoc 3.6.3 on Mon Sep 30 2019 11:14:22 GMT-0500 (CDT) using the docdash theme. +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/global.html b/docs/global.html new file mode 100644 index 0000000..f57f619 --- /dev/null +++ b/docs/global.html @@ -0,0 +1,342 @@ + + + + + + Global - Documentation + + + + + + + + + + + + + + + + + + + +
+ +

Global

+ + + + + + + +
+ +
+ +

+ +

+ + +
+ +
+ +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +

Type Definitions

+ + + +

Tokens

+ + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
accessToken + + +string + + + +

A JWT.

accessTokenPayload + + +Object + + + +

The decoded JWT.

idToken + + +string + + + +

A JWT.

idTokenPayload + + +Object + + + +

The decoded JWT.

+ + + + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ +
+ Documentation generated by JSDoc 3.6.3 on Mon Sep 30 2019 11:14:22 GMT-0500 (CDT) using the docdash theme. +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..ae0524b --- /dev/null +++ b/docs/index.html @@ -0,0 +1,131 @@ + + + + + + Home - Documentation + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+

+
+ + + + + + + + + + + + + +
+

Codacy Badge

+

IBM Cloud App ID Client SDK

+

Client-side javascript SDK for the IBM Cloud App ID service.
+Read the official documentation for information about getting started with IBM Cloud App ID Service.

+

Table of Contents

+ +

Installation

+

Using npm:

+
npm install ibmcloud-appid-js
+
+

From the CDN:

+
<script src="""></script>
+
+

Or for development purposes use the minified file in this repo:

+
<script type='text/javascript' src="dist/appid.min.js"></script>
+
+

Getting Started

+

A simple sample application can be found in the sample folder in this repo.

+

You will need an IBM Cloud App ID instance with a singlepageapp application created.
+Use the clientId and discoveryEndpoint from the application credentials to initialize the AppID instance.

+
const appID = new AppID();
+await appID.init({
+    clientId: '<SPA_CLIENT_ID>',
+    discoveryEndpoint: '<WELL_KNOWN_ENDPOINT>'
+});
+
+

Using the signin() in your app to start authentication:

+
document.getElementById('login').addEventListener('click', async () => {
+    try {
+        const tokens = await appID.signin();
+    } catch (e) {
+        ...
+    }
+});
+
+

API Reference

+

Checkout our API reference here.

+
+ + + + + + + + +
+ +
+ +
+ Documentation generated by JSDoc 3.6.3 on Mon Sep 30 2019 11:14:22 GMT-0500 (CDT) using the docdash theme. +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/index.js.html b/docs/index.js.html new file mode 100644 index 0000000..5a79265 --- /dev/null +++ b/docs/index.js.html @@ -0,0 +1,258 @@ + + + + + + index.js - Documentation + + + + + + + + + + + + + + + + + + + +
+ +

index.js

+ + + + + + + +
+
+
const Utils = require('./utils');
+const RequestHandler = require('./RequestHandler');
+const PopupController = require('./PopupController');
+const IFrameController = require('./IFrameController');
+const OpenIdConfigurationResource = require('./OpenIDConfigurationResource');
+const TokenValidator = require('./TokenValidator');
+const constants = require('./constants');
+const AppIDError = require('./errors/AppIDError');
+
+/**
+ * This class provides functions to support authentication.
+ */
+class AppID {
+	/**
+	 * This creates an instance of AppID. Once created, call init() before attempting to sign in.
+	 * @example
+	 * const appID = new AppID();
+	 */
+	constructor(
+		{
+			popup = new PopupController(),
+			iframe = new IFrameController(),
+			tokenValidator = new TokenValidator(),
+			openIdConfigResource = new OpenIdConfigurationResource(),
+			utils,
+			requestHandler = new RequestHandler(),
+			w = window,
+			url = URL
+		} = {}) {
+
+		this.popup = popup;
+		this.iframe = iframe;
+		this.tokenValidator = tokenValidator;
+		this.openIdConfigResource = openIdConfigResource;
+		this.URL = url;
+		this.utils = utils;
+		if (!utils) {
+			this.utils = new Utils({openIdConfigResource: this.openIdConfigResource, url: this.URL});
+		}
+		this.request = requestHandler.request;
+		this.window = w;
+		this.initialized = false;
+	}
+
+	/**
+	 * Initialize AppID. Call this function before attempting to sign in. You must wait for the promise to resolve.
+	 * @param {Object} options
+	 * @param {string} options.clientId - The clientId from the singlepageapp application credentials.
+	 * @param {string} options.discoveryEndpoint - The discoveryEndpoint from the singlepageapp application credentials.
+	 * @param {Object} [options.popup] - The popup configuration.
+	 * @param {Number} options.popup.height - The popup height.
+	 * @param {Number} options.popup.width - The popup width.
+	 * @returns {Promise<void>}
+	 * @throws {AppIDError} For missing required params.
+	 * @throws {RequestError} Any errors during a HTTP request.
+	 * @example
+	 * await appID.init({
+	 * 	clientId: '<SPA_CLIENT_ID>',
+	 * 	discoveryEndpoint: '<WELL_KNOWN_ENDPOINT>'
+	 * });
+	 *
+	 */
+	async init({clientId, discoveryEndpoint, popup = {height: screen.height * .80, width: 400}}) {
+		if (!clientId) {
+			throw new AppIDError(constants.MISSING_CLIENT_ID);
+		}
+		try {
+			new this.URL(discoveryEndpoint)
+		} catch (e) {
+			throw new AppIDError(constants.INVALID_DISCOVERY_ENDPOINT);
+		}
+
+		await this.openIdConfigResource.init({discoveryEndpoint, requestHandler: this.request});
+		this.clientId = clientId;
+		this.popupConfig = popup;
+		this.initialized = true;
+	}
+
+	/**
+	 * @typedef {Object} Tokens
+	 * @property {string} accessToken A JWT.
+	 * @property {Object} accessTokenPayload The decoded JWT.
+	 * @property {string} idToken A JWT.
+	 * @property {Object} idTokenPayload The decoded JWT.
+	 */
+
+	/**
+	 * This will open a sign in widget in a popup which will prompt the user to enter their credentials.
+	 * After a successful sign in, the popup will close and tokens are returned.
+	 * @returns {Promise<Tokens>} The tokens of the authenticated user.
+	 * @throws {PopupError} "Popup closed" - The user closed the popup before authentication was completed.
+	 * @throws {TokenError} Any token validation error.
+	 * @throws {OAuthError} Any errors from the server according to the [OAuth spec]{@link https://tools.ietf.org/html/rfc6749#section-4.1.2.1}. e.g. {error: 'server_error', description: ''}
+	 * @throws {RequestError} Any errors during a HTTP request.
+	 * @example
+	 * const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.signin();
+	 */
+	async signin() {
+		this._validateInitalize();
+
+		const {codeVerifier, nonce, state, authUrl} = this.utils.getAuthParams(this.clientId, this.window.origin);
+
+		this.popup.open(this.popupConfig);
+		this.popup.navigate({authUrl});
+		const message = await this.popup.waitForMessage({messageType: 'authorization_response'});
+		this.popup.close();
+
+		this.utils.verifyMessage({message, state});
+
+		let authCode = message.data.code;
+
+		return await this.utils.exchangeTokens({
+			clientId: this.clientId,
+			authCode,
+			codeVerifier,
+			nonce,
+			windowOrigin: this.window.origin
+		});
+	}
+
+	/**
+	 * Silent sign in will attempt to authenticate the user in a hidden iframe.
+	 * You will need to enable Cloud Directory SSO.
+	 * Sign in will be successful only if the user has previously signed in using Cloud Directory and their session is not expired.
+	 * @returns {Promise<Tokens>} The tokens of the authenticated user.
+	 * @throws {OAuthError} Any errors from the server according to the [OAuth spec]{@link https://tools.ietf.org/html/rfc6749#section-4.1.2.1}. e.g. {error: 'access_denied', description: 'User not signed in'}
+	 * @throws {IFrameError} "Silent sign-in timed out" - The iframe will close after 5 seconds if authentication could not be completed.
+	 * @throws {TokenError} Any token validation error.
+	 * @throws {RequestError} Any errors during a HTTP request.
+	 * @example
+	 * const {accessToken, accessTokenPayload, idToken, idTokenPayload} = await appID.silentSignin();
+	 */
+	async silentSignin() {
+		this._validateInitalize();
+		const {codeVerifier, nonce, state, authUrl} = this.utils.getAuthParams(this.clientId, this.window.origin, constants.PROMPT);
+
+		this.iframe.open(authUrl);
+
+		let message;
+		try {
+			message = await this.iframe.waitForMessage({messageType: 'authorization_response'});
+		} finally {
+			this.iframe.remove();
+		}
+		this.utils.verifyMessage({message, state});
+		let authCode = message.data.code;
+
+		return await this.utils.exchangeTokens({
+			clientId: this.clientId,
+			authCode,
+			codeVerifier,
+			nonce,
+			openId: this.openIdConfigResource,
+			windowOrigin: this.window.origin
+		});
+	}
+
+	/**
+	 * This method will made a GET request to the [user info endpoint]{@link https://us-south.appid.cloud.ibm.com/swagger-ui/#/Authorization%20Server%20-%20Authorization%20Server%20V4/oauth-server.userInfo} using the access token of the authenticated user.
+	 * @param {string} accessToken - The App ID access token of the user.
+	 * @returns {Promise} The user information for the authenticated user. Example: {sub: '', email: ''}
+	 * @throws {AppIDError} "Access token must be a string" Invalid access token.
+	 * @throws {RequestError} Any errors during a HTTP request.
+	 */
+	async getUserInfo(accessToken) {
+		this._validateInitalize();
+		if (typeof accessToken !== 'string') {
+			throw new AppIDError(constants.INVALID_ACCESS_TOKEN);
+		}
+
+		return await this.request(this.openIdConfigResource.getUserInfoEndpoint(), {
+			headers: {
+				'Authorization': 'Bearer ' + accessToken
+			}
+		});
+	}
+
+	/**
+	 *
+	 * @private
+	 */
+	_validateInitalize() {
+		if (!this.initialized) {
+			throw new AppIDError(constants.FAIL_TO_INITIALIZE);
+		}
+	}
+}
+
+module.exports = AppID;
+
+
+
+ + + + + + +
+ +
+ +
+ Documentation generated by JSDoc 3.6.3 on Mon Sep 30 2019 11:14:22 GMT-0500 (CDT) using the docdash theme. +
+ + + + + + + + + diff --git a/docs/scripts/collapse.js b/docs/scripts/collapse.js new file mode 100644 index 0000000..327039f --- /dev/null +++ b/docs/scripts/collapse.js @@ -0,0 +1,20 @@ +function hideAllButCurrent(){ + //by default all submenut items are hidden + //but we need to rehide them for search + document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) { + parent.style.display = "none"; + }); + + //only current page (if it exists) should be opened + var file = window.location.pathname.split("/").pop().replace(/\.html/, ''); + document.querySelectorAll("nav > ul > li > a").forEach(function(parent) { + var href = parent.attributes.href.value.replace(/\.html/, ''); + if (file === href) { + parent.parentNode.querySelectorAll("ul li").forEach(function(elem) { + elem.style.display = "block"; + }); + } + }); +} + +hideAllButCurrent(); \ No newline at end of file diff --git a/docs/scripts/linenumber.js b/docs/scripts/linenumber.js new file mode 100644 index 0000000..8d52f7e --- /dev/null +++ b/docs/scripts/linenumber.js @@ -0,0 +1,25 @@ +/*global document */ +(function() { + var source = document.getElementsByClassName('prettyprint source linenums'); + var i = 0; + var lineNumber = 0; + var lineId; + var lines; + var totalLines; + var anchorHash; + + if (source && source[0]) { + anchorHash = document.location.hash.substring(1); + lines = source[0].getElementsByTagName('li'); + totalLines = lines.length; + + for (; i < totalLines; i++) { + lineNumber++; + lineId = 'line' + lineNumber; + lines[i].id = lineId; + if (lineId === anchorHash) { + lines[i].className += ' selected'; + } + } + } +})(); diff --git a/docs/scripts/nav.js b/docs/scripts/nav.js new file mode 100644 index 0000000..6dd8313 --- /dev/null +++ b/docs/scripts/nav.js @@ -0,0 +1,12 @@ +function scrollToNavItem() { + var path = window.location.href.split('/').pop().replace(/\.html/, ''); + document.querySelectorAll('nav a').forEach(function(link) { + var href = link.attributes.href.value.replace(/\.html/, ''); + if (path === href) { + link.scrollIntoView({block: 'center'}); + return; + } + }) + } + + scrollToNavItem(); diff --git a/docs/scripts/polyfill.js b/docs/scripts/polyfill.js new file mode 100644 index 0000000..44b4c92 --- /dev/null +++ b/docs/scripts/polyfill.js @@ -0,0 +1,4 @@ +//IE Fix, src: https://www.reddit.com/r/programminghorror/comments/6abmcr/nodelist_lacks_foreach_in_internet_explorer/ +if (typeof(NodeList.prototype.forEach)!==typeof(alert)){ + NodeList.prototype.forEach=Array.prototype.forEach; +} \ No newline at end of file diff --git a/docs/scripts/prettify/Apache-License-2.0.txt b/docs/scripts/prettify/Apache-License-2.0.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/docs/scripts/prettify/Apache-License-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/docs/scripts/prettify/lang-css.js b/docs/scripts/prettify/lang-css.js new file mode 100644 index 0000000..041e1f5 --- /dev/null +++ b/docs/scripts/prettify/lang-css.js @@ -0,0 +1,2 @@ +PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", +/^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/docs/scripts/prettify/prettify.js b/docs/scripts/prettify/prettify.js new file mode 100644 index 0000000..eef5ad7 --- /dev/null +++ b/docs/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p ul > li:not(.level-hide)").forEach(function(elem) { + elem.style.display = "block"; + }); + + if (typeof hideAllButCurrent === "function"){ + //let's do what ever collapse wants to do + hideAllButCurrent(); + } else { + //menu by default should be opened + document.querySelectorAll("nav > ul > li > ul li").forEach(function(elem) { + elem.style.display = "block"; + }); + } + } else { + //we are searching + document.documentElement.setAttribute(searchAttr, ''); + + //show all parents + document.querySelectorAll("nav > ul > li").forEach(function(elem) { + elem.style.display = "block"; + }); + //hide all results + document.querySelectorAll("nav > ul > li > ul li").forEach(function(elem) { + elem.style.display = "none"; + }); + //show results matching filter + document.querySelectorAll("nav > ul > li > ul a").forEach(function(elem) { + if (!contains(elem.parentNode, search)) { + return; + } + elem.parentNode.style.display = "block"; + }); + //hide parents without children + document.querySelectorAll("nav > ul > li").forEach(function(parent) { + var countSearchA = 0; + parent.querySelectorAll("a").forEach(function(elem) { + if (contains(elem, search)) { + countSearchA++; + } + }); + + var countUl = 0; + var countUlVisible = 0; + parent.querySelectorAll("ul").forEach(function(ulP) { + // count all elements that match the search + if (contains(ulP, search)) { + countUl++; + } + + // count all visible elements + var children = ulP.children + for (i=0; i ul { + padding: 0 10px; +} + +nav > ul > li > a { + color: #606; + margin-top: 10px; +} + +nav ul ul a { + color: hsl(207, 1%, 60%); + border-left: 1px solid hsl(207, 10%, 86%); +} + +nav ul ul a, +nav ul ul a:active { + padding-left: 20px +} + +nav h2 { + font-size: 13px; + margin: 10px 0 0 0; + padding: 0; +} + +nav > h2 > a { + margin: 10px 0 -10px; + color: #606 !important; +} + +footer { + color: hsl(0, 0%, 28%); + margin-left: 250px; + display: block; + padding: 15px; + font-style: italic; + font-size: 90%; +} + +.ancestors { + color: #999 +} + +.ancestors a { + color: #999 !important; +} + +.clear { + clear: both +} + +.important { + font-weight: bold; + color: #950B02; +} + +.yes-def { + text-indent: -1000px +} + +.type-signature { + color: #CA79CA +} + +.type-signature:last-child { + color: #eee; +} + +.name, .signature { + font-family: Consolas, Monaco, 'Andale Mono', monospace +} + +.signature { + color: #fc83ff; +} + +.details { + margin-top: 6px; + border-left: 2px solid #DDD; + line-height: 20px; + font-size: 14px; +} + +.details dt { + width: auto; + float: left; + padding-left: 10px; +} + +.details dd { + margin-left: 70px; + margin-top: 6px; + margin-bottom: 6px; +} + +.details ul { + margin: 0 +} + +.details ul { + list-style-type: none +} + +.details pre.prettyprint { + margin: 0 +} + +.details .object-value { + padding-top: 0 +} + +.description { + margin-bottom: 1em; + margin-top: 1em; +} + +.code-caption { + font-style: italic; + font-size: 107%; + margin: 0; +} + +.prettyprint { + font-size: 14px; + overflow: auto; +} + +.prettyprint.source { + width: inherit; + line-height: 18px; + display: block; + background-color: #0d152a; + color: #aeaeae; +} + +.prettyprint code { + line-height: 18px; + display: block; + background-color: #0d152a; + color: #4D4E53; +} + +.prettyprint > code { + padding: 15px; +} + +.prettyprint .linenums code { + padding: 0 15px +} + +.prettyprint .linenums li:first-of-type code { + padding-top: 15px +} + +.prettyprint code span.line { + display: inline-block +} + +.prettyprint.linenums { + padding-left: 70px; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.prettyprint.linenums ol { + padding-left: 0 +} + +.prettyprint.linenums li { + border-left: 3px #34446B solid; +} + +.prettyprint.linenums li.selected, .prettyprint.linenums li.selected * { + background-color: #34446B; +} + +.prettyprint.linenums li * { + -webkit-user-select: text; + -moz-user-select: text; + -ms-user-select: text; + user-select: text; +} + +table { + border-spacing: 0; + border: 1px solid #ddd; + border-collapse: collapse; + border-radius: 3px; + box-shadow: 0 1px 3px rgba(0,0,0,0.1); + width: 100%; + font-size: 14px; + margin: 1em 0; +} + +td, th { + margin: 0px; + text-align: left; + vertical-align: top; + padding: 10px; + display: table-cell; +} + +thead tr, thead tr { + background-color: #fff; + font-weight: bold; + border-bottom: 1px solid #ddd; +} + +.params .type { + white-space: nowrap; +} + +.params code { + white-space: pre; +} + +.params td, .params .name, .props .name, .name code { + color: #4D4E53; + font-family: Consolas, Monaco, 'Andale Mono', monospace; + font-size: 100%; +} + +.params td { + border-top: 1px solid #eee +} + +.params td.description > p:first-child, .props td.description > p:first-child { + margin-top: 0; + padding-top: 0; +} + +.params td.description > p:last-child, .props td.description > p:last-child { + margin-bottom: 0; + padding-bottom: 0; +} + +span.param-type, .params td .param-type, .param-type dd { + color: #606; + font-family: Consolas, Monaco, 'Andale Mono', monospace +} + +.param-type dt, .param-type dd { + display: inline-block +} + +.param-type { + margin: 14px 0; +} + +.disabled { + color: #454545 +} + +/* navicon button */ +.navicon-button { + display: none; + position: relative; + padding: 2.0625rem 1.5rem; + transition: 0.25s; + cursor: pointer; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + opacity: .8; +} +.navicon-button .navicon:before, .navicon-button .navicon:after { + transition: 0.25s; +} +.navicon-button:hover { + transition: 0.5s; + opacity: 1; +} +.navicon-button:hover .navicon:before, .navicon-button:hover .navicon:after { + transition: 0.25s; +} +.navicon-button:hover .navicon:before { + top: .825rem; +} +.navicon-button:hover .navicon:after { + top: -.825rem; +} + +/* navicon */ +.navicon { + position: relative; + width: 2.5em; + height: .3125rem; + background: #000; + transition: 0.3s; + border-radius: 2.5rem; +} +.navicon:before, .navicon:after { + display: block; + content: ""; + height: .3125rem; + width: 2.5rem; + background: #000; + position: absolute; + z-index: -1; + transition: 0.3s 0.25s; + border-radius: 1rem; +} +.navicon:before { + top: .625rem; +} +.navicon:after { + top: -.625rem; +} + +/* open */ +.nav-trigger:checked + label:not(.steps) .navicon:before, +.nav-trigger:checked + label:not(.steps) .navicon:after { + top: 0 !important; +} + +.nav-trigger:checked + label .navicon:before, +.nav-trigger:checked + label .navicon:after { + transition: 0.5s; +} + +/* Minus */ +.nav-trigger:checked + label { + -webkit-transform: scale(0.75); + transform: scale(0.75); +} + +/* × and + */ +.nav-trigger:checked + label.plus .navicon, +.nav-trigger:checked + label.x .navicon { + background: transparent; +} + +.nav-trigger:checked + label.plus .navicon:before, +.nav-trigger:checked + label.x .navicon:before { + -webkit-transform: rotate(-45deg); + transform: rotate(-45deg); + background: #FFF; +} + +.nav-trigger:checked + label.plus .navicon:after, +.nav-trigger:checked + label.x .navicon:after { + -webkit-transform: rotate(45deg); + transform: rotate(45deg); + background: #FFF; +} + +.nav-trigger:checked + label.plus { + -webkit-transform: scale(0.75) rotate(45deg); + transform: scale(0.75) rotate(45deg); +} + +.nav-trigger:checked ~ nav { + left: 0 !important; +} + +.nav-trigger:checked ~ .overlay { + display: block; +} + +.nav-trigger { + position: fixed; + top: 0; + clip: rect(0, 0, 0, 0); +} + +.overlay { + display: none; + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + width: 100%; + height: 100%; + background: hsla(0, 0%, 0%, 0.5); + z-index: 1; +} + +/* nav level */ +.level-hide { + display: none; +} +html[data-search-mode] .level-hide { + display: block; +} + + +@media only screen and (min-width: 320px) and (max-width: 680px) { + body { + overflow-x: hidden; + } + + nav { + background: #FFF; + width: 250px; + height: 100%; + position: fixed; + top: 0; + right: 0; + bottom: 0; + left: -250px; + z-index: 3; + padding: 0 10px; + transition: left 0.2s; + } + + .navicon-button { + display: inline-block; + position: fixed; + top: 1.5em; + right: 0; + z-index: 2; + } + + #main { + width: 100%; + min-width: 360px; + } + + #main h1.page-title { + margin: 1em 0; + } + + #main section { + padding: 0; + } + + footer { + margin-left: 0; + } +} + +/** Add a '#' to static members */ +[data-type="member"] a::before { + content: '#'; + display: inline-block; + margin-left: -14px; + margin-right: 5px; +} + +#disqus_thread{ + margin-left: 30px; +} diff --git a/docs/styles/prettify.css b/docs/styles/prettify.css new file mode 100644 index 0000000..d9521ec --- /dev/null +++ b/docs/styles/prettify.css @@ -0,0 +1,79 @@ +.pln { + color: #ddd; +} + +/* string content */ +.str { + color: #61ce3c; +} + +/* a keyword */ +.kwd { + color: #fbde2d; +} + +/* a comment */ +.com { + color: #aeaeae; +} + +/* a type name */ +.typ { + color: #8da6ce; +} + +/* a literal value */ +.lit { + color: #fbde2d; +} + +/* punctuation */ +.pun { + color: #ddd; +} + +/* lisp open bracket */ +.opn { + color: #000000; +} + +/* lisp close bracket */ +.clo { + color: #000000; +} + +/* a markup tag name */ +.tag { + color: #8da6ce; +} + +/* a markup attribute name */ +.atn { + color: #fbde2d; +} + +/* a markup attribute value */ +.atv { + color: #ddd; +} + +/* a declaration */ +.dec { + color: #EF5050; +} + +/* a variable name */ +.var { + color: #c82829; +} + +/* a function name */ +.fun { + color: #4271ae; +} + +/* Specify class=linenums on a pre to get line numbering */ +ol.linenums { + margin-top: 0; + margin-bottom: 0; +} From 81f366ec3b16bfa0ba0dafddcdd65bb2fdbdeeb7 Mon Sep 17 00:00:00 2001 From: Joyce Huang Date: Mon, 30 Sep 2019 11:32:22 -0500 Subject: [PATCH 15/15] adding utils test --- test/utilsTest.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/utilsTest.js b/test/utilsTest.js index f1f4d08..c0f6f4c 100644 --- a/test/utilsTest.js +++ b/test/utilsTest.js @@ -19,7 +19,7 @@ describe('Utils tests', () => { assert.deepEqual(res, 'param1=test¶m2=test¶m3=test'); }); - it('should return auth params', () => { + it('should return auth params with prompt', () => { let res = utils.getAuthParams('1234', 'http://origin.com', 'none'); assert.exists(res.codeVerifier, 'returned code verifier'); assert.exists(res.nonce, 'returned nonce'); @@ -27,6 +27,14 @@ describe('Utils tests', () => { assert.include(res.authUrl, 'prompt=none'); }); + it('should return auth params without prompt', () => { + let res = utils.getAuthParams('1234', 'http://origin.com'); + assert.exists(res.codeVerifier, 'returned code verifier'); + assert.exists(res.nonce, 'returned nonce'); + assert.exists(res.state, 'returned state'); + assert.notInclude(res.authUrl, 'prompt'); + }); + it('should return tokens', async () => { let params = { authCode: 'code', @@ -52,6 +60,11 @@ describe('Utils tests', () => { origin: 'http://invalidorigin' }; + const validData = { + data: {state: 'dmFsaWRTdGF0ZQ=='}, + origin: 'http://authserver.com' + }; + it('should throw error', () => { try { utils.verifyMessage({message: error}); @@ -70,10 +83,15 @@ describe('Utils tests', () => { it('should throw error - invalid origin', function () { try { - utils.verifyMessage({message: originError, state: 'validState', authEndpoint: 'http://validorigin'}); + utils.verifyMessage({message: originError, state: 'validState'}); } catch (e) { assert.equal(e.message, 'Invalid origin'); } }); + + it('should pass', function () { + let res = utils.verifyMessage({message: validData, state: 'validState'}); + console.log(res) + }); }); }); \ No newline at end of file