function BigInteger(e,t,r){null!=e&&("number"==typeof e?this.fromNumber(e,t,r):null==t&&"string"!=typeof e?this.fromString(e,256):this.fromString(e,t))}function nbi(){return new BigInteger(null)}function am1(e,t,r,n,i,a){for(;--a>=0;){var s=t*this[e++]+r[n]+i;i=Math.floor(s/67108864),r[n++]=67108863&s}return i}function am2(e,t,r,n,i,a){for(var s=32767&t,o=t>>15;--a>=0;){var u=32767&this[e],c=this[e++]>>15,l=o*u+c*s;u=s*u+((32767&l)<<15)+r[n]+(1073741823&i),i=(u>>>30)+(l>>>15)+o*c+(i>>>30),r[n++]=1073741823&u}return i}function am3(e,t,r,n,i,a){for(var s=16383&t,o=t>>14;--a>=0;){var u=16383&this[e],c=this[e++]>>14,l=o*u+c*s;u=s*u+((16383&l)<<14)+r[n]+i,i=(u>>28)+(l>>14)+o*c,r[n++]=268435455&u}return i}function int2char(e){return BI_RM.charAt(e)}function intAt(e,t){var r=BI_RC[e.charCodeAt(t)];return null==r?-1:r}function bnpCopyTo(e){for(var t=this.t-1;t>=0;--t)e[t]=this[t];e.t=this.t,e.s=this.s}function bnpFromInt(e){this.t=1,this.s=0>e?-1:0,e>0?this[0]=e:-1>e?this[0]=e+this.DV:this.t=0}function nbv(e){var t=nbi();return t.fromInt(e),t}function bnpFromString(e,t){var r;if(16==t)r=4;else if(8==t)r=3;else if(256==t)r=8;else if(2==t)r=1;else if(32==t)r=5;else{if(4!=t)return this.fromRadix(e,t),void 0;r=2}this.t=0,this.s=0;for(var n=e.length,i=!1,a=0;--n>=0;){var s=8==r?255&e[n]:intAt(e,n);0>s?"-"==e.charAt(n)&&(i=!0):(i=!1,0==a?this[this.t++]=s:a+r>this.DB?(this[this.t-1]|=(s&(1<<this.DB-a)-1)<<a,this[this.t++]=s>>this.DB-a):this[this.t-1]|=s<<a,a+=r,a>=this.DB&&(a-=this.DB))}8==r&&0!=(128&e[0])&&(this.s=-1,a>0&&(this[this.t-1]|=(1<<this.DB-a)-1<<a)),this.clamp(),i&&BigInteger.ZERO.subTo(this,this)}function bnpClamp(){for(var e=this.s&this.DM;this.t>0&&this[this.t-1]==e;)--this.t}function bnToString(e){if(this.s<0)return"-"+this.negate().toString(e);var t;if(16==e)t=4;else if(8==e)t=3;else if(2==e)t=1;else if(32==e)t=5;else{if(4!=e)return this.toRadix(e);t=2}var r,n=(1<<t)-1,i=!1,a="",s=this.t,o=this.DB-s*this.DB%t;if(s-->0)for(o<this.DB&&(r=this[s]>>o)>0&&(i=!0,a=int2char(r));s>=0;)t>o?(r=(this[s]&(1<<o)-1)<<t-o,r|=this[--s]>>(o+=this.DB-t)):(r=this[s]>>(o-=t)&n,0>=o&&(o+=this.DB,--s)),r>0&&(i=!0),i&&(a+=int2char(r));return i?a:"0"}function bnNegate(){var e=nbi();return BigInteger.ZERO.subTo(this,e),e}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(e){var t=this.s-e.s;if(0!=t)return t;var r=this.t;if(t=r-e.t,0!=t)return this.s<0?-t:t;for(;--r>=0;)if(0!=(t=this[r]-e[r]))return t;return 0}function nbits(e){var t,r=1;return 0!=(t=e>>>16)&&(e=t,r+=16),0!=(t=e>>8)&&(e=t,r+=8),0!=(t=e>>4)&&(e=t,r+=4),0!=(t=e>>2)&&(e=t,r+=2),0!=(t=e>>1)&&(e=t,r+=1),r}function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(e,t){var r;for(r=this.t-1;r>=0;--r)t[r+e]=this[r];for(r=e-1;r>=0;--r)t[r]=0;t.t=this.t+e,t.s=this.s}function bnpDRShiftTo(e,t){for(var r=e;r<this.t;++r)t[r-e]=this[r];t.t=Math.max(this.t-e,0),t.s=this.s}function bnpLShiftTo(e,t){var r,n=e%this.DB,i=this.DB-n,a=(1<<i)-1,s=Math.floor(e/this.DB),o=this.s<<n&this.DM;for(r=this.t-1;r>=0;--r)t[r+s+1]=this[r]>>i|o,o=(this[r]&a)<<n;for(r=s-1;r>=0;--r)t[r]=0;t[s]=o,t.t=this.t+s+1,t.s=this.s,t.clamp()}function bnpRShiftTo(e,t){t.s=this.s;var r=Math.floor(e/this.DB);if(r>=this.t)return t.t=0,void 0;var n=e%this.DB,i=this.DB-n,a=(1<<n)-1;t[0]=this[r]>>n;for(var s=r+1;s<this.t;++s)t[s-r-1]|=(this[s]&a)<<i,t[s-r]=this[s]>>n;n>0&&(t[this.t-r-1]|=(this.s&a)<<i),t.t=this.t-r,t.clamp()}function bnpSubTo(e,t){for(var r=0,n=0,i=Math.min(e.t,this.t);i>r;)n+=this[r]-e[r],t[r++]=n&this.DM,n>>=this.DB;if(e.t<this.t){for(n-=e.s;r<this.t;)n+=this[r],t[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<e.t;)n-=e[r],t[r++]=n&this.DM,n>>=this.DB;n-=e.s}t.s=0>n?-1:0,-1>n?t[r++]=this.DV+n:n>0&&(t[r++]=n),t.t=r,t.clamp()}function bnpMultiplyTo(e,t){var r=this.abs(),n=e.abs(),i=r.t;for(t.t=i+n.t;--i>=0;)t[i]=0;for(i=0;i<n.t;++i)t[i+r.t]=r.am(0,n[i],t,i,0,r.t);t.s=0,t.clamp(),this.s!=e.s&&BigInteger.ZERO.subTo(t,t)}function bnpSquareTo(e){for(var t=this.abs(),r=e.t=2*t.t;--r>=0;)e[r]=0;for(r=0;r<t.t-1;++r){var n=t.am(r,t[r],e,2*r,0,1);(e[r+t.t]+=t.am(r+1,2*t[r],e,2*r+1,n,t.t-r-1))>=t.DV&&(e[r+t.t]-=t.DV,e[r+t.t+1]=1)}e.t>0&&(e[e.t-1]+=t.am(r,t[r],e,2*r,0,1)),e.s=0,e.clamp()}function bnpDivRemTo(e,t,r){var n=e.abs();if(!(n.t<=0)){var i=this.abs();if(i.t<n.t)return null!=t&&t.fromInt(0),null!=r&&this.copyTo(r),void 0;null==r&&(r=nbi());var a=nbi(),s=this.s,o=e.s,u=this.DB-nbits(n[n.t-1]);u>0?(n.lShiftTo(u,a),i.lShiftTo(u,r)):(n.copyTo(a),i.copyTo(r));var c=a.t,l=a[c-1];if(0!=l){var p=l*(1<<this.F1)+(c>1?a[c-2]>>this.F2:0),f=this.FV/p,d=(1<<this.F1)/p,h=1<<this.F2,g=r.t,y=g-c,m=null==t?nbi():t;for(a.dlShiftTo(y,m),r.compareTo(m)>=0&&(r[r.t++]=1,r.subTo(m,r)),BigInteger.ONE.dlShiftTo(c,m),m.subTo(a,a);a.t<c;)a[a.t++]=0;for(;--y>=0;){var v=r[--g]==l?this.DM:Math.floor(r[g]*f+(r[g-1]+h)*d);if((r[g]+=a.am(0,v,r,y,0,c))<v)for(a.dlShiftTo(y,m),r.subTo(m,r);r[g]<--v;)r.subTo(m,r)}null!=t&&(r.drShiftTo(c,t),s!=o&&BigInteger.ZERO.subTo(t,t)),r.t=c,r.clamp(),u>0&&r.rShiftTo(u,r),0>s&&BigInteger.ZERO.subTo(r,r)}}}function bnMod(e){var t=nbi();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(BigInteger.ZERO)>0&&e.subTo(t,t),t}function Classic(e){this.m=e}function cConvert(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e}function cRevert(e){return e}function cReduce(e){e.divRemTo(this.m,null,e)}function cMulTo(e,t,r){e.multiplyTo(t,r),this.reduce(r)}function cSqrTo(e,t){e.squareTo(t),this.reduce(t)}function bnpInvDigit(){if(this.t<1)return 0;var e=this[0];if(0==(1&e))return 0;var t=3&e;return t=t*(2-(15&e)*t)&15,t=t*(2-(255&e)*t)&255,t=t*(2-((65535&e)*t&65535))&65535,t=t*(2-e*t%this.DV)%this.DV,t>0?this.DV-t:-t}function Montgomery(e){this.m=e,this.mp=e.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<e.DB-15)-1,this.mt2=2*e.t}function montConvert(e){var t=nbi();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(BigInteger.ZERO)>0&&this.m.subTo(t,t),t}function montRevert(e){var t=nbi();return e.copyTo(t),this.reduce(t),t}function montReduce(e){for(;e.t<=this.mt2;)e[e.t++]=0;for(var t=0;t<this.m.t;++t){var r=32767&e[t],n=r*this.mpl+((r*this.mph+(e[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(r=t+this.m.t,e[r]+=this.m.am(0,n,e,t,0,this.m.t);e[r]>=e.DV;)e[r]-=e.DV,e[++r]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)}function montSqrTo(e,t){e.squareTo(t),this.reduce(t)}function montMulTo(e,t,r){e.multiplyTo(t,r),this.reduce(r)}function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)}function bnpExp(e,t){if(e>4294967295||1>e)return BigInteger.ONE;var r=nbi(),n=nbi(),i=t.convert(this),a=nbits(e)-1;for(i.copyTo(r);--a>=0;)if(t.sqrTo(r,n),(e&1<<a)>0)t.mulTo(n,i,r);else{var s=r;r=n,n=s}return t.revert(r)}function bnModPowInt(e,t){var r;return r=256>e||t.isEven()?new Classic(t):new Montgomery(t),this.exp(e,r)}function bnClone(){var e=nbi();return this.copyTo(e),e}function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function bnByteValue(){return 0==this.t?this.s:this[0]<<24>>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(e){return Math.floor(Math.LN2*this.DB/Math.log(e))}function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function bnpToRadix(e){if(null==e&&(e=10),0==this.signum()||2>e||e>36)return"0";var t=this.chunkSize(e),r=Math.pow(e,t),n=nbv(r),i=nbi(),a=nbi(),s="";for(this.divRemTo(n,i,a);i.signum()>0;)s=(r+a.intValue()).toString(e).substr(1)+s,i.divRemTo(n,i,a);return a.intValue().toString(e)+s}function bnpFromRadix(e,t){this.fromInt(0),null==t&&(t=10);for(var r=this.chunkSize(t),n=Math.pow(t,r),i=!1,a=0,s=0,o=0;o<e.length;++o){var u=intAt(e,o);0>u?"-"==e.charAt(o)&&0==this.signum()&&(i=!0):(s=t*s+u,++a>=r&&(this.dMultiply(n),this.dAddOffset(s,0),a=0,s=0))}a>0&&(this.dMultiply(Math.pow(t,a)),this.dAddOffset(s,0)),i&&BigInteger.ZERO.subTo(this,this)}function bnpFromNumber(e,t,r){if("number"==typeof t)if(2>e)this.fromInt(1);else for(this.fromNumber(e,r),this.testBit(e-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(e-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(t);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(BigInteger.ONE.shiftLeft(e-1),this);else{var n=new Array,i=7&e;n.length=(e>>3)+1,t.nextBytes(n),i>0?n[0]&=(1<<i)-1:n[0]=0,this.fromString(n,256)}}function bnToByteArray(){var e=this.t,t=new Array;t[0]=this.s;var r,n=this.DB-e*this.DB%8,i=0;if(e-->0)for(n<this.DB&&(r=this[e]>>n)!=(this.s&this.DM)>>n&&(t[i++]=r|this.s<<this.DB-n);e>=0;)8>n?(r=(this[e]&(1<<n)-1)<<8-n,r|=this[--e]>>(n+=this.DB-8)):(r=this[e]>>(n-=8)&255,0>=n&&(n+=this.DB,--e)),0!=(128&r)&&(r|=-256),0==i&&(128&this.s)!=(128&r)&&++i,(i>0||r!=this.s)&&(t[i++]=r);return t}function bnEquals(e){return 0==this.compareTo(e)}function bnMin(e){return this.compareTo(e)<0?this:e}function bnMax(e){return this.compareTo(e)>0?this:e}function bnpBitwiseTo(e,t,r){var n,i,a=Math.min(e.t,this.t);for(n=0;a>n;++n)r[n]=t(this[n],e[n]);if(e.t<this.t){for(i=e.s&this.DM,n=a;n<this.t;++n)r[n]=t(this[n],i);r.t=this.t}else{for(i=this.s&this.DM,n=a;n<e.t;++n)r[n]=t(i,e[n]);r.t=e.t}r.s=t(this.s,e.s),r.clamp()}function op_and(e,t){return e&t}function bnAnd(e){var t=nbi();return this.bitwiseTo(e,op_and,t),t}function op_or(e,t){return e|t}function bnOr(e){var t=nbi();return this.bitwiseTo(e,op_or,t),t}function op_xor(e,t){return e^t}function bnXor(e){var t=nbi();return this.bitwiseTo(e,op_xor,t),t}function op_andnot(e,t){return e&~t}function bnAndNot(e){var t=nbi();return this.bitwiseTo(e,op_andnot,t),t}function bnNot(){for(var e=nbi(),t=0;t<this.t;++t)e[t]=this.DM&~this[t];return e.t=this.t,e.s=~this.s,e}function bnShiftLeft(e){var t=nbi();return 0>e?this.rShiftTo(-e,t):this.lShiftTo(e,t),t}function bnShiftRight(e){var t=nbi();return 0>e?this.lShiftTo(-e,t):this.rShiftTo(e,t),t}function lbit(e){if(0==e)return-1;var t=0;return 0==(65535&e)&&(e>>=16,t+=16),0==(255&e)&&(e>>=8,t+=8),0==(15&e)&&(e>>=4,t+=4),0==(3&e)&&(e>>=2,t+=2),0==(1&e)&&++t,t}function bnGetLowestSetBit(){for(var e=0;e<this.t;++e)if(0!=this[e])return e*this.DB+lbit(this[e]);return this.s<0?this.t*this.DB:-1}function cbit(e){for(var t=0;0!=e;)e&=e-1,++t;return t}function bnBitCount(){for(var e=0,t=this.s&this.DM,r=0;r<this.t;++r)e+=cbit(this[r]^t);return e}function bnTestBit(e){var t=Math.floor(e/this.DB);return t>=this.t?0!=this.s:0!=(this[t]&1<<e%this.DB)}function bnpChangeBit(e,t){var r=BigInteger.ONE.shiftLeft(e);return this.bitwiseTo(r,t,r),r}function bnSetBit(e){return this.changeBit(e,op_or)}function bnClearBit(e){return this.changeBit(e,op_andnot)}function bnFlipBit(e){return this.changeBit(e,op_xor)}function bnpAddTo(e,t){for(var r=0,n=0,i=Math.min(e.t,this.t);i>r;)n+=this[r]+e[r],t[r++]=n&this.DM,n>>=this.DB;if(e.t<this.t){for(n+=e.s;r<this.t;)n+=this[r],t[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<e.t;)n+=e[r],t[r++]=n&this.DM,n>>=this.DB;n+=e.s}t.s=0>n?-1:0,n>0?t[r++]=n:-1>n&&(t[r++]=this.DV+n),t.t=r,t.clamp()}function bnAdd(e){var t=nbi();return this.addTo(e,t),t}function bnSubtract(e){var t=nbi();return this.subTo(e,t),t}function bnMultiply(e){var t=nbi();return this.multiplyTo(e,t),t}function bnSquare(){var e=nbi();return this.squareTo(e),e}function bnDivide(e){var t=nbi();return this.divRemTo(e,t,null),t}function bnRemainder(e){var t=nbi();return this.divRemTo(e,null,t),t}function bnDivideAndRemainder(e){var t=nbi(),r=nbi();return this.divRemTo(e,t,r),new Array(t,r)}function bnpDMultiply(e){this[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()}function bnpDAddOffset(e,t){if(0!=e){for(;this.t<=t;)this[this.t++]=0;for(this[t]+=e;this[t]>=this.DV;)this[t]-=this.DV,++t>=this.t&&(this[this.t++]=0),++this[t]}}function NullExp(){}function nNop(e){return e}function nMulTo(e,t,r){e.multiplyTo(t,r)}function nSqrTo(e,t){e.squareTo(t)}function bnPow(e){return this.exp(e,new NullExp)}function bnpMultiplyLowerTo(e,t,r){var n=Math.min(this.t+e.t,t);for(r.s=0,r.t=n;n>0;)r[--n]=0;var i;for(i=r.t-this.t;i>n;++n)r[n+this.t]=this.am(0,e[n],r,n,0,this.t);for(i=Math.min(e.t,t);i>n;++n)this.am(0,e[n],r,n,0,t-n);r.clamp()}function bnpMultiplyUpperTo(e,t,r){--t;var n=r.t=this.t+e.t-t;for(r.s=0;--n>=0;)r[n]=0;for(n=Math.max(t-this.t,0);n<e.t;++n)r[this.t+n-t]=this.am(t-n,e[n],r,0,0,this.t+n-t);r.clamp(),r.drShiftTo(1,r)}function Barrett(e){this.r2=nbi(),this.q3=nbi(),BigInteger.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}function barrettConvert(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=nbi();return e.copyTo(t),this.reduce(t),t}function barrettRevert(e){return e}function barrettReduce(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)}function barrettSqrTo(e,t){e.squareTo(t),this.reduce(t)}function barrettMulTo(e,t,r){e.multiplyTo(t,r),this.reduce(r)}function bnModPow(e,t){var r,n,i=e.bitLength(),a=nbv(1);if(0>=i)return a;r=18>i?1:48>i?3:144>i?4:768>i?5:6,n=8>i?new Classic(t):t.isEven()?new Barrett(t):new Montgomery(t);var s=new Array,o=3,u=r-1,c=(1<<r)-1;if(s[1]=n.convert(this),r>1){var l=nbi();for(n.sqrTo(s[1],l);c>=o;)s[o]=nbi(),n.mulTo(l,s[o-2],s[o]),o+=2}var p,f,d=e.t-1,h=!0,g=nbi();for(i=nbits(e[d])-1;d>=0;){for(i>=u?p=e[d]>>i-u&c:(p=(e[d]&(1<<i+1)-1)<<u-i,d>0&&(p|=e[d-1]>>this.DB+i-u)),o=r;0==(1&p);)p>>=1,--o;if((i-=o)<0&&(i+=this.DB,--d),h)s[p].copyTo(a),h=!1;else{for(;o>1;)n.sqrTo(a,g),n.sqrTo(g,a),o-=2;o>0?n.sqrTo(a,g):(f=a,a=g,g=f),n.mulTo(g,s[p],a)}for(;d>=0&&0==(e[d]&1<<i);)n.sqrTo(a,g),f=a,a=g,g=f,--i<0&&(i=this.DB-1,--d)}return n.revert(a)}function bnGCD(e){var t=this.s<0?this.negate():this.clone(),r=e.s<0?e.negate():e.clone();if(t.compareTo(r)<0){var n=t;t=r,r=n}var i=t.getLowestSetBit(),a=r.getLowestSetBit();if(0>a)return t;for(a>i&&(a=i),a>0&&(t.rShiftTo(a,t),r.rShiftTo(a,r));t.signum()>0;)(i=t.getLowestSetBit())>0&&t.rShiftTo(i,t),(i=r.getLowestSetBit())>0&&r.rShiftTo(i,r),t.compareTo(r)>=0?(t.subTo(r,t),t.rShiftTo(1,t)):(r.subTo(t,r),r.rShiftTo(1,r));return a>0&&r.lShiftTo(a,r),r}function bnpModInt(e){if(0>=e)return 0;var t=this.DV%e,r=this.s<0?e-1:0;if(this.t>0)if(0==t)r=this[0]%e;else for(var n=this.t-1;n>=0;--n)r=(t*r+this[n])%e;return r}function bnModInverse(e){var t=e.isEven();if(this.isEven()&&t||0==e.signum())return BigInteger.ZERO;for(var r=e.clone(),n=this.clone(),i=nbv(1),a=nbv(0),s=nbv(0),o=nbv(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),t?(i.isEven()&&a.isEven()||(i.addTo(this,i),a.subTo(e,a)),i.rShiftTo(1,i)):a.isEven()||a.subTo(e,a),a.rShiftTo(1,a);for(;n.isEven();)n.rShiftTo(1,n),t?(s.isEven()&&o.isEven()||(s.addTo(this,s),o.subTo(e,o)),s.rShiftTo(1,s)):o.isEven()||o.subTo(e,o),o.rShiftTo(1,o);r.compareTo(n)>=0?(r.subTo(n,r),t&&i.subTo(s,i),a.subTo(o,a)):(n.subTo(r,n),t&&s.subTo(i,s),o.subTo(a,o))}return 0!=n.compareTo(BigInteger.ONE)?BigInteger.ZERO:o.compareTo(e)>=0?o.subtract(e):o.signum()<0?(o.addTo(e,o),o.signum()<0?o.add(e):o):o}function bnIsProbablePrime(e){var t,r=this.abs();if(1==r.t&&r[0]<=lowprimes[lowprimes.length-1]){for(t=0;t<lowprimes.length;++t)if(r[0]==lowprimes[t])return!0;return!1}if(r.isEven())return!1;for(t=1;t<lowprimes.length;){for(var n=lowprimes[t],i=t+1;i<lowprimes.length&&lplim>n;)n*=lowprimes[i++];for(n=r.modInt(n);i>t;)if(n%lowprimes[t++]==0)return!1}return r.millerRabin(e)}function bnpMillerRabin(e){var t=this.subtract(BigInteger.ONE),r=t.getLowestSetBit();if(0>=r)return!1;var n=t.shiftRight(r);e=e+1>>1,e>lowprimes.length&&(e=lowprimes.length);for(var i=nbi(),a=0;e>a;++a){i.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var s=i.modPow(n,this);if(0!=s.compareTo(BigInteger.ONE)&&0!=s.compareTo(t)){for(var o=1;o++<r&&0!=s.compareTo(t);)if(s=s.modPowInt(2,this),0==s.compareTo(BigInteger.ONE))return!1;if(0!=s.compareTo(t))return!1}}return!0}function ECFieldElementFp(e,t){this.x=t,this.q=e}function feFpEquals(e){return e==this?!0:this.q.equals(e.q)&&this.x.equals(e.x)}function feFpToBigInteger(){return this.x}function feFpNegate(){return new ECFieldElementFp(this.q,this.x.negate().mod(this.q))}function feFpAdd(e){return new ECFieldElementFp(this.q,this.x.add(e.toBigInteger()).mod(this.q))}function feFpSubtract(e){return new ECFieldElementFp(this.q,this.x.subtract(e.toBigInteger()).mod(this.q))}function feFpMultiply(e){return new ECFieldElementFp(this.q,this.x.multiply(e.toBigInteger()).mod(this.q))}function feFpSquare(){return new ECFieldElementFp(this.q,this.x.square().mod(this.q))}function feFpDivide(e){return new ECFieldElementFp(this.q,this.x.multiply(e.toBigInteger().modInverse(this.q)).mod(this.q))}function ECPointFp(e,t,r,n){this.curve=e,this.x=t,this.y=r,this.z=null==n?BigInteger.ONE:n,this.zinv=null}function pointFpGetX(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var e=this.x.toBigInteger().multiply(this.zinv);return this.curve.reduce(e),this.curve.fromBigInteger(e)}function pointFpGetY(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var e=this.y.toBigInteger().multiply(this.zinv);return this.curve.reduce(e),this.curve.fromBigInteger(e)}function pointFpEquals(e){if(e==this)return!0;if(this.isInfinity())return e.isInfinity();if(e.isInfinity())return this.isInfinity();var t,r;return t=e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q),t.equals(BigInteger.ZERO)?(r=e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q),r.equals(BigInteger.ZERO)):!1}function pointFpIsInfinity(){return null==this.x&&null==this.y?!0:this.z.equals(BigInteger.ZERO)&&!this.y.toBigInteger().equals(BigInteger.ZERO)}function pointFpNegate(){return new ECPointFp(this.curve,this.x,this.y.negate(),this.z)}function pointFpAdd(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var t=e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q),r=e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q);if(BigInteger.ZERO.equals(r))return BigInteger.ZERO.equals(t)?this.twice():this.curve.getInfinity();var n=new BigInteger("3"),i=this.x.toBigInteger(),a=this.y.toBigInteger(),s=(e.x.toBigInteger(),e.y.toBigInteger(),r.square()),o=s.multiply(r),u=i.multiply(s),c=t.square().multiply(this.z),l=c.subtract(u.shiftLeft(1)).multiply(e.z).subtract(o).multiply(r).mod(this.curve.q),p=u.multiply(n).multiply(t).subtract(a.multiply(o)).subtract(c.multiply(t)).multiply(e.z).add(t.multiply(o)).mod(this.curve.q),f=o.multiply(this.z).multiply(e.z).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(l),this.curve.fromBigInteger(p),f)}function pointFpTwice(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var e=new BigInteger("3"),t=this.x.toBigInteger(),r=this.y.toBigInteger(),n=r.multiply(this.z),i=n.multiply(r).mod(this.curve.q),a=this.curve.a.toBigInteger(),s=t.square().multiply(e);BigInteger.ZERO.equals(a)||(s=s.add(this.z.square().multiply(a))),s=s.mod(this.curve.q);var o=s.square().subtract(t.shiftLeft(3).multiply(i)).shiftLeft(1).multiply(n).mod(this.curve.q),u=s.multiply(e).multiply(t).subtract(i.shiftLeft(1)).shiftLeft(2).multiply(i).subtract(s.square().multiply(s)).mod(this.curve.q),c=n.square().multiply(n).shiftLeft(3).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(o),this.curve.fromBigInteger(u),c)}function pointFpMultiply(e){if(this.isInfinity())return this;if(0==e.signum())return this.curve.getInfinity();var t,r=e,n=r.multiply(new BigInteger("3")),i=this.negate(),a=this;for(t=n.bitLength()-2;t>0;--t){a=a.twice();var s=n.testBit(t),o=r.testBit(t);s!=o&&(a=a.add(s?this:i))}return a}function pointFpMultiplyTwo(e,t,r){var n;n=e.bitLength()>r.bitLength()?e.bitLength()-1:r.bitLength()-1;for(var i=this.curve.getInfinity(),a=this.add(t);n>=0;)i=i.twice(),e.testBit(n)?i=r.testBit(n)?i.add(a):i.add(this):r.testBit(n)&&(i=i.add(t)),--n;return i}function ECCurveFp(e,t,r){this.q=e,this.a=this.fromBigInteger(t),this.b=this.fromBigInteger(r),this.infinity=new ECPointFp(this,null,null),this.reducer=new Barrett(this.q)}function curveFpGetQ(){return this.q}function curveFpGetA(){return this.a}function curveFpGetB(){return this.b}function curveFpEquals(e){return e==this?!0:this.q.equals(e.q)&&this.a.equals(e.a)&&this.b.equals(e.b)}function curveFpGetInfinity(){return this.infinity}function curveFpFromBigInteger(e){return new ECFieldElementFp(this.q,e)}function curveReduce(e){this.reducer.reduce(e)}function curveFpDecodePointHex(e){switch(parseInt(e.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var t=(e.length-2)/2,r=e.substr(2,t),n=e.substr(t+2,t);return new ECPointFp(this,this.fromBigInteger(new BigInteger(r,16)),this.fromBigInteger(new BigInteger(n,16)));default:return null}}function curveFpEncodePointHex(e){if(e.isInfinity())return"00";var t=e.getX().toBigInteger().toString(16),r=e.getY().toBigInteger().toString(16),n=this.getQ().toString(16).length;for(n%2!=0&&n++;t.length<n;)t="0"+t;for(;r.length<n;)r="0"+r;return"04"+t+r}function X9ECParameters(e,t,r,n){this.curve=e,this.g=t,this.n=r,this.h=n}function x9getCurve(){return this.curve}function x9getG(){return this.g}function x9getN(){return this.n}function x9getH(){return this.h}function fromHex(e){return new BigInteger(e,16)}function secp128r1(){var e=fromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF"),t=fromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC"),r=fromHex("E87579C11079F43DD824993C2CEE5ED3"),n=fromHex("FFFFFFFE0000000075A30D1B9038A115"),i=BigInteger.ONE,a=new ECCurveFp(e,t,r),s=a.decodePointHex("04161FF7528B899B2D0C28607CA52C5B86CF5AC8395BAFEB13C02DA292DDED7A83");return new X9ECParameters(a,s,n,i)}function secp160k1(){var e=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73"),t=BigInteger.ZERO,r=fromHex("7"),n=fromHex("0100000000000000000001B8FA16DFAB9ACA16B6B3"),i=BigInteger.ONE,a=new ECCurveFp(e,t,r),s=a.decodePointHex("043B4C382CE37AA192A4019E763036F4F5DD4D7EBB938CF935318FDCED6BC28286531733C3F03C4FEE");return new X9ECParameters(a,s,n,i)}function secp160r1(){var e=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF"),t=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC"),r=fromHex("1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45"),n=fromHex("0100000000000000000001F4C8F927AED3CA752257"),i=BigInteger.ONE,a=new ECCurveFp(e,t,r),s=a.decodePointHex("044A96B5688EF573284664698968C38BB913CBFC8223A628553168947D59DCC912042351377AC5FB32");return new X9ECParameters(a,s,n,i)}function secp192k1(){var e=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37"),t=BigInteger.ZERO,r=fromHex("3"),n=fromHex("FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D"),i=BigInteger.ONE,a=new ECCurveFp(e,t,r),s=a.decodePointHex("04DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D");return new X9ECParameters(a,s,n,i)}function secp192r1(){var e=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF"),t=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC"),r=fromHex("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1"),n=fromHex("FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831"),i=BigInteger.ONE,a=new ECCurveFp(e,t,r),s=a.decodePointHex("04188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF101207192B95FFC8DA78631011ED6B24CDD573F977A11E794811");return new X9ECParameters(a,s,n,i)}function secp224r1(){var e=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001"),t=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE"),r=fromHex("B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4"),n=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D"),i=BigInteger.ONE,a=new ECCurveFp(e,t,r),s=a.decodePointHex("04B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34");return new X9ECParameters(a,s,n,i)}function secp256r1(){var e=fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF"),t=fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC"),r=fromHex("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B"),n=fromHex("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551"),i=BigInteger.ONE,a=new ECCurveFp(e,t,r),s=a.decodePointHex("046B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C2964FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5");return new X9ECParameters(a,s,n,i)}function getSECCurveByName(e){return"secp128r1"==e?secp128r1():"secp160k1"==e?secp160k1():"secp160r1"==e?secp160r1():"secp192k1"==e?secp192k1():"secp192r1"==e?secp192r1():"secp224r1"==e?secp224r1():"secp256r1"==e?secp256r1():null}function Arcfour(){this.i=0,this.j=0,this.S=new Array}function ARC4init(e){var t,r,n;for(t=0;256>t;++t)this.S[t]=t;for(r=0,t=0;256>t;++t)r=r+this.S[t]+e[t%e.length]&255,n=this.S[t],this.S[t]=this.S[r],this.S[r]=n;this.i=0,this.j=0}function ARC4next(){var e;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,e=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=e,this.S[e+this.S[this.i]&255]}function prng_newstate(){return new Arcfour}function rng_seed_int(e){rng_pool[rng_pptr++]^=255&e,rng_pool[rng_pptr++]^=e>>8&255,rng_pool[rng_pptr++]^=e>>16&255,rng_pool[rng_pptr++]^=e>>24&255,rng_pptr>=rng_psize&&(rng_pptr-=rng_psize)}function rng_seed_time(){rng_seed_int((new Date).getTime())}function rng_get_byte(){if(null==rng_state){for(rng_seed_time(),rng_state=prng_newstate(),rng_state.init(rng_pool),rng_pptr=0;rng_pptr<rng_pool.length;++rng_pptr)rng_pool[rng_pptr]=0;rng_pptr=0}return rng_state.next()}function rng_get_bytes(e){var t;for(t=0;t<e.length;++t)e[t]=rng_get_byte()}function SecureRandom(){}!function(){function e(e){var t=e.util=e.util||{};"undefined"!=typeof process&&process.nextTick?(t.nextTick=process.nextTick,t.setImmediate="function"==typeof setImmediate?setImmediate:t.nextTick):"function"==typeof setImmediate?(t.setImmediate=setImmediate,t.nextTick=function(e){return setImmediate(e)}):(t.setImmediate=function(e){setTimeout(e,0)},t.nextTick=t.setImmediate),t.isArray=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},t.ByteBuffer=function(e){this.data=e||"",this.read=0},t.ByteBuffer.prototype.length=function(){return this.data.length-this.read},t.ByteBuffer.prototype.isEmpty=function(){return this.length()<=0},t.ByteBuffer.prototype.putByte=function(e){return this.data+=String.fromCharCode(e),this},t.ByteBuffer.prototype.fillWithByte=function(e,t){e=String.fromCharCode(e);for(var r=this.data;t>0;)1&t&&(r+=e),t>>>=1,t>0&&(e+=e);return this.data=r,this},t.ByteBuffer.prototype.putBytes=function(e){return this.data+=e,this},t.ByteBuffer.prototype.putString=function(e){return this.data+=t.encodeUtf8(e),this},t.ByteBuffer.prototype.putInt16=function(e){return this.data+=String.fromCharCode(e>>8&255)+String.fromCharCode(255&e),this},t.ByteBuffer.prototype.putInt24=function(e){return this.data+=String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e),this},t.ByteBuffer.prototype.putInt32=function(e){return this.data+=String.fromCharCode(e>>24&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e),this},t.ByteBuffer.prototype.putInt16Le=function(e){return this.data+=String.fromCharCode(255&e)+String.fromCharCode(e>>8&255),this},t.ByteBuffer.prototype.putInt24Le=function(e){return this.data+=String.fromCharCode(255&e)+String.fromCharCode(e>>8&255)+String.fromCharCode(e>>16&255),this},t.ByteBuffer.prototype.putInt32Le=function(e){return this.data+=String.fromCharCode(255&e)+String.fromCharCode(e>>8&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>24&255),this},t.ByteBuffer.prototype.putInt=function(e,t){do t-=8,this.data+=String.fromCharCode(e>>t&255);while(t>0);return this},t.ByteBuffer.prototype.putBuffer=function(e){return this.data+=e.getBytes(),this},t.ByteBuffer.prototype.getByte=function(){return this.data.charCodeAt(this.read++)},t.ByteBuffer.prototype.getInt16=function(){var e=this.data.charCodeAt(this.read)<<8^this.data.charCodeAt(this.read+1);return this.read+=2,e},t.ByteBuffer.prototype.getInt24=function(){var e=this.data.charCodeAt(this.read)<<16^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2);return this.read+=3,e},t.ByteBuffer.prototype.getInt32=function(){var e=this.data.charCodeAt(this.read)<<24^this.data.charCodeAt(this.read+1)<<16^this.data.charCodeAt(this.read+2)<<8^this.data.charCodeAt(this.read+3);return this.read+=4,e},t.ByteBuffer.prototype.getInt16Le=function(){var e=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8;return this.read+=2,e},t.ByteBuffer.prototype.getInt24Le=function(){var e=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16;return this.read+=3,e},t.ByteBuffer.prototype.getInt32Le=function(){var e=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16^this.data.charCodeAt(this.read+3)<<24;return this.read+=4,e},t.ByteBuffer.prototype.getInt=function(e){var t=0;do t=(t<<8)+this.data.charCodeAt(this.read++),e-=8;while(e>0);return t},t.ByteBuffer.prototype.getBytes=function(e){var t;return e?(e=Math.min(this.length(),e),t=this.data.slice(this.read,this.read+e),this.read+=e):0===e?t="":(t=0===this.read?this.data:this.data.slice(this.read),this.clear()),t},t.ByteBuffer.prototype.bytes=function(e){return"undefined"==typeof e?this.data.slice(this.read):this.data.slice(this.read,this.read+e)},t.ByteBuffer.prototype.at=function(e){return this.data.charCodeAt(this.read+e)},t.ByteBuffer.prototype.setAt=function(e,t){return this.data=this.data.substr(0,this.read+e)+String.fromCharCode(t)+this.data.substr(this.read+e+1),this},t.ByteBuffer.prototype.last=function(){return this.data.charCodeAt(this.data.length-1)},t.ByteBuffer.prototype.copy=function(){var e=t.createBuffer(this.data);return e.read=this.read,e},t.ByteBuffer.prototype.compact=function(){return this.read>0&&(this.data=this.data.slice(this.read),this.read=0),this},t.ByteBuffer.prototype.clear=function(){return this.data="",this.read=0,this},t.ByteBuffer.prototype.truncate=function(e){var t=Math.max(0,this.length()-e);return this.data=this.data.substr(this.read,t),this.read=0,this},t.ByteBuffer.prototype.toHex=function(){for(var e="",t=this.read;t<this.data.length;++t){var r=this.data.charCodeAt(t);16>r&&(e+="0"),e+=r.toString(16)}return e},t.ByteBuffer.prototype.toString=function(){return t.decodeUtf8(this.bytes())},t.createBuffer=function(e,r){return r=r||"raw",void 0!==e&&"utf8"===r&&(e=t.encodeUtf8(e)),new t.ByteBuffer(e)},t.fillString=function(e,t){for(var r="";t>0;)1&t&&(r+=e),t>>>=1,t>0&&(e+=e);return r},t.xorBytes=function(e,t,r){for(var n="",i="",a="",s=0,o=0;r>0;--r,++s)i=e.charCodeAt(s)^t.charCodeAt(s),o>=10&&(n+=a,a="",o=0),a+=String.fromCharCode(i),++o;return n+=a},t.hexToBytes=function(e){var t="",r=0;for(e.length&!0&&(r=1,t+=String.fromCharCode(parseInt(e[0],16)));r<e.length;r+=2)t+=String.fromCharCode(parseInt(e.substr(r,2),16));return t},t.bytesToHex=function(e){return t.createBuffer(e).toHex()},t.int32ToBytes=function(e){return String.fromCharCode(e>>24&255)+String.fromCharCode(e>>16&255)+String.fromCharCode(e>>8&255)+String.fromCharCode(255&e)};var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",n=[62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,64,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51];t.encode64=function(e,t){for(var n,i,a,s="",o="",u=0;u<e.length;)n=e.charCodeAt(u++),i=e.charCodeAt(u++),a=e.charCodeAt(u++),s+=r.charAt(n>>2),s+=r.charAt((3&n)<<4|i>>4),isNaN(i)?s+="==":(s+=r.charAt((15&i)<<2|a>>6),s+=isNaN(a)?"=":r.charAt(63&a)),t&&s.length>t&&(o+=s.substr(0,t)+"\r\n",s=s.substr(t));
return o+=s},t.decode64=function(e){e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var t,r,i,a,s="",o=0;o<e.length;)t=n[e.charCodeAt(o++)-43],r=n[e.charCodeAt(o++)-43],i=n[e.charCodeAt(o++)-43],a=n[e.charCodeAt(o++)-43],s+=String.fromCharCode(t<<2|r>>4),64!==i&&(s+=String.fromCharCode((15&r)<<4|i>>2),64!==a&&(s+=String.fromCharCode((3&i)<<6|a)));return s},t.encodeUtf8=function(e){return unescape(encodeURIComponent(e))},t.decodeUtf8=function(e){return decodeURIComponent(escape(e))},t.deflate=function(e,r,n){if(r=t.decode64(e.deflate(t.encode64(r)).rval),n){var i=2,a=r.charCodeAt(1);32&a&&(i=6),r=r.substring(i,r.length-4)}return r},t.inflate=function(e,r){var n=e.inflate(t.encode64(r)).rval;return null===n?null:t.decode64(n)};var i=function(e,r,n){if(!e)throw{message:"WebStorage not available."};var i;if(null===n?i=e.removeItem(r):(n=t.encode64(JSON.stringify(n)),i=e.setItem(r,n)),"undefined"!=typeof i&&i.rval!==!0)throw i.error},a=function(e,r){if(!e)throw{message:"WebStorage not available."};var n=e.getItem(r);if(e.init)if(null===n.rval){if(n.error)throw n.error;n=null}else n=n.rval;return null!==n&&(n=JSON.parse(t.decode64(n))),n},s=function(e,t,r,n){var s=a(e,t);null===s&&(s={}),s[r]=n,i(e,t,s)},o=function(e,t,r){var n=a(e,t);return null!==n&&(n=r in n?n[r]:null),n},u=function(e,t,r){var n=a(e,t);if(null!==n&&r in n){delete n[r];var s=!0;for(var o in n){s=!1;break}s&&(n=null),i(e,t,n)}},c=function(e,t){i(e,t,null)},l=function(e,t,r){var n=null;"undefined"==typeof r&&(r=["web","flash"]);var i,a=!1,s=null;for(var o in r){i=r[o];try{if("flash"===i||"both"===i){if(null===t[0])throw{message:"Flash local storage not available."};n=e.apply(this,t),a="flash"===i}("web"===i||"both"===i)&&(t[0]=localStorage,n=e.apply(this,t),a=!0)}catch(u){s=u}if(a)break}if(!a)throw s;return n};t.setItem=function(e,t,r,n,i){l(s,arguments,i)},t.getItem=function(e,t,r,n){return l(o,arguments,n)},t.removeItem=function(e,t,r,n){l(u,arguments,n)},t.clearItems=function(e,t,r){l(c,arguments,r)},t.parseUrl=function(e){var t=/^(https?):\/\/([^:&^\/]*):?(\d*)(.*)$/g;t.lastIndex=0;var r=t.exec(e),n=null===r?null:{full:e,scheme:r[1],host:r[2],port:r[3],path:r[4]};return n&&(n.fullHost=n.host,n.port?80!==n.port&&"http"===n.scheme?n.fullHost+=":"+n.port:443!==n.port&&"https"===n.scheme&&(n.fullHost+=":"+n.port):"http"===n.scheme?n.port=80:"https"===n.scheme&&(n.port=443),n.full=n.scheme+"://"+n.fullHost),n};var p=null;t.getQueryVariables=function(e){var t,r=function(e){for(var t={},r=e.split("&"),n=0;n<r.length;n++){var i,a,s=r[n].indexOf("=");s>0?(i=r[n].substring(0,s),a=r[n].substring(s+1)):(i=r[n],a=null),i in t||(t[i]=[]),!(i in Object.prototype)&&null!==a&&t[i].push(unescape(a))}return t};return"undefined"==typeof e?(null===p&&(p="undefined"==typeof window?{}:r(window.location.search.substring(1))),t=p):t=r(e),t},t.parseFragment=function(e){var r=e,n="",i=e.indexOf("?");i>0&&(r=e.substring(0,i),n=e.substring(i+1));var a=r.split("/");a.length>0&&""===a[0]&&a.shift();var s=""===n?{}:t.getQueryVariables(n);return{pathString:r,queryString:n,path:a,query:s}},t.makeRequest=function(e){var r=t.parseFragment(e),n={path:r.pathString,query:r.queryString,getPath:function(e){return"undefined"==typeof e?r.path:r.path[e]},getQuery:function(e,t){var n;return"undefined"==typeof e?n=r.query:(n=r.query[e],n&&"undefined"!=typeof t&&(n=n[t])),n},getQueryLast:function(e,t){var r,i=n.getQuery(e);return r=i?i[i.length-1]:t}};return n},t.makeLink=function(e,t,r){e=jQuery.isArray(e)?e.join("/"):e;var n=jQuery.param(t||{});return r=r||"",e+(n.length>0?"?"+n:"")+(r.length>0?"#"+r:"")},t.setPath=function(e,t,r){if("object"==typeof e&&null!==e)for(var n=0,i=t.length;i>n;){var a=t[n++];if(n==i)e[a]=r;else{var s=a in e;(!s||s&&"object"!=typeof e[a]||s&&null===e[a])&&(e[a]={}),e=e[a]}}},t.getPath=function(e,t,r){for(var n=0,i=t.length,a=!0;a&&i>n&&"object"==typeof e&&null!==e;){var s=t[n++];a=s in e,a&&(e=e[s])}return a?e:r},t.deletePath=function(e,t){if("object"==typeof e&&null!==e)for(var r=0,n=t.length;n>r;){var i=t[r++];if(r==n)delete e[i];else{if(!(i in e&&"object"==typeof e[i]&&null!==e[i]))break;e=e[i]}}},t.isEmpty=function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},t.format=function(e){for(var t,r,n=/%./g,i=0,a=[],s=0;t=n.exec(e);){r=e.substring(s,n.lastIndex-2),r.length>0&&a.push(r),s=n.lastIndex;var o=t[0][1];switch(o){case"s":case"o":i<arguments.length?a.push(arguments[i++ +1]):a.push("<?>");break;case"%":a.push("%");break;default:a.push("<%"+o+"?>")}}return a.push(e.substring(s)),a.join("")},t.formatNumber=function(e,t,r,n){var i=e,a=isNaN(t=Math.abs(t))?2:t,s=void 0===r?",":r,o=void 0===n?".":n,u=0>i?"-":"",c=parseInt(i=Math.abs(+i||0).toFixed(a),10)+"",l=c.length>3?c.length%3:0;return u+(l?c.substr(0,l)+o:"")+c.substr(l).replace(/(\d{3})(?=\d)/g,"$1"+o)+(a?s+Math.abs(i-c).toFixed(a).slice(2):"")},t.formatSize=function(e){return e=e>=1073741824?t.formatNumber(e/1073741824,2,".","")+" GiB":e>=1048576?t.formatNumber(e/1048576,2,".","")+" MiB":e>=1024?t.formatNumber(e/1024,0)+" KiB":t.formatNumber(e,0)+" bytes"}}var t="util";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/util",["require","module"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t,r,n,i,a,s=!1,o=4,u=function(){s=!0,n=[0,1,2,4,8,16,32,64,128,27,54];for(var e=new Array(256),o=0;128>o;++o)e[o]=o<<1,e[o+128]=o+128<<1^283;t=new Array(256),r=new Array(256),i=new Array(4),a=new Array(4);for(var o=0;4>o;++o)i[o]=new Array(256),a[o]=new Array(256);for(var u,c,l,p,f,d,h,g=0,y=0,o=0;256>o;++o){p=y^y<<1^y<<2^y<<3^y<<4,p=p>>8^255&p^99,t[g]=p,r[p]=g,f=e[p],u=e[g],c=e[u],l=e[c],d=f<<24^p<<16^p<<8^(p^f),h=(u^c^l)<<24^(g^l)<<16^(g^c^l)<<8^(g^u^l);for(var m=0;4>m;++m)i[m][g]=d,a[m][p]=h,d=d<<24|d>>>8,h=h<<24|h>>>8;0===g?g=y=1:(g=u^e[e[e[u^l]]],y^=e[e[y]])}},c=function(e,r){for(var i,s=e.slice(0),u=1,c=s.length,l=c+6+1,p=o*l,f=c;p>f;++f)i=s[f-1],f%c===0?(i=t[i>>>16&255]<<24^t[i>>>8&255]<<16^t[255&i]<<8^t[i>>>24]^n[u]<<24,u++):c>6&&f%c===4&&(i=t[i>>>24]<<24^t[i>>>16&255]<<16^t[i>>>8&255]<<8^t[255&i]),s[f]=s[f-c]^i;if(r){for(var d,h=a[0],g=a[1],y=a[2],m=a[3],v=s.slice(0),p=s.length,f=0,C=p-o;p>f;f+=o,C-=o)if(0===f||f===p-o)v[f]=s[C],v[f+1]=s[C+3],v[f+2]=s[C+2],v[f+3]=s[C+1];else for(var E=0;o>E;++E)d=s[C+E],v[f+(3&-E)]=h[t[d>>>24]]^g[t[d>>>16&255]]^y[t[d>>>8&255]]^m[t[255&d]];s=v}return s},l=function(e,n,s,o){var u,c,l,p,f,d=e.length/4-1;o?(u=a[0],c=a[1],l=a[2],p=a[3],f=r):(u=i[0],c=i[1],l=i[2],p=i[3],f=t);var h,g,y,m,v,C,E;h=n[0]^e[0],g=n[o?3:1]^e[1],y=n[2]^e[2],m=n[o?1:3]^e[3];for(var b=3,T=1;d>T;++T)v=u[h>>>24]^c[g>>>16&255]^l[y>>>8&255]^p[255&m]^e[++b],C=u[g>>>24]^c[y>>>16&255]^l[m>>>8&255]^p[255&h]^e[++b],E=u[y>>>24]^c[m>>>16&255]^l[h>>>8&255]^p[255&g]^e[++b],m=u[m>>>24]^c[h>>>16&255]^l[g>>>8&255]^p[255&y]^e[++b],h=v,g=C,y=E;s[0]=f[h>>>24]<<24^f[g>>>16&255]<<16^f[y>>>8&255]<<8^f[255&m]^e[++b],s[o?3:1]=f[g>>>24]<<24^f[y>>>16&255]<<16^f[m>>>8&255]<<8^f[255&h]^e[++b],s[2]=f[y>>>24]<<24^f[m>>>16&255]<<16^f[h>>>8&255]<<8^f[255&g]^e[++b],s[o?1:3]=f[m>>>24]<<24^f[h>>>16&255]<<16^f[g>>>8&255]<<8^f[255&y]^e[++b]},p=function(t,r,n,i,a){function p(){if(i)for(var e=0;o>e;++e)b[e]=C.getInt32();else for(var e=0;o>e;++e)b[e]=S[e]^C.getInt32();if(l(N,b,T,i),i){for(var e=0;o>e;++e)E.putInt32(S[e]^T[e]);S=b.slice(0)}else{for(var e=0;o>e;++e)E.putInt32(T[e]);S=T}}function f(){l(N,b,T,!1);for(var e=0;o>e;++e)b[e]=C.getInt32();for(var e=0;o>e;++e){var t=b[e]^T[e];i||(b[e]=t),E.putInt32(t)}}function d(){l(N,b,T,!1);for(var e=0;o>e;++e)b[e]=C.getInt32();for(var e=0;o>e;++e)E.putInt32(b[e]^T[e]),b[e]=T[e]}function h(){l(N,b,T,!1);for(var e=o-1;e>=0;--e){if(4294967295!==b[e]){++b[e];break}b[e]=0}for(var e=0;o>e;++e)E.putInt32(C.getInt32()^T[e])}var g=null;if(s||u(),a=(a||"CBC").toUpperCase(),"string"!=typeof t||16!==t.length&&24!==t.length&&32!==t.length){if(e.util.isArray(t)&&(16===t.length||24===t.length||32===t.length))for(var y=t,t=e.util.createBuffer(),m=0;m<y.length;++m)t.putByte(y[m])}else t=e.util.createBuffer(t);if(!e.util.isArray(t)){var y=t;t=[];var v=y.length();if(16===v||24===v||32===v){v>>>=2;for(var m=0;v>m;++m)t.push(y.getInt32())}}if(!e.util.isArray(t)||4!==t.length&&6!==t.length&&8!==t.length)return g;var C,E,b,T,S,I,B,A=-1!==["CFB","OFB","CTR"].indexOf(a),F="CBC"===a,N=c(t,i&&!A),R=o<<2;if(g={output:null},"CBC"===a)B=p;else if("CFB"===a)B=f;else if("OFB"===a)B=d;else{if("CTR"!==a)throw{message:'Unsupported block cipher mode of operation: "'+a+'"'};B=h}return g.update=function(e){for(I||C.putBuffer(e);C.length()>=R||C.length()>0&&I;)B()},g.finish=function(e){var t=!0,r=C.length()%R;if(!i)if(e)t=e(R,C,i);else if(F){var n=C.length()===R?R:R-C.length();C.fillWithByte(n,n)}if(t&&(I=!0,g.update()),i&&(F&&(t=0===r),t))if(e)t=e(R,E,i);else if(F){var a=E.length(),s=E.at(a-1);s>o<<2?t=!1:E.truncate(s)}return!F&&!e&&r>0&&E.truncate(R-r),t},g.start=function(t,r){if(null===t&&(t=S.slice(0)),"string"==typeof t&&16===t.length)t=e.util.createBuffer(t);else if(e.util.isArray(t)&&16===t.length)for(var n=t,t=e.util.createBuffer(),i=0;16>i;++i)t.putByte(n[i]);if(!e.util.isArray(t)){var n=t;t=new Array(4),t[0]=n.getInt32(),t[1]=n.getInt32(),t[2]=n.getInt32(),t[3]=n.getInt32()}if(C=e.util.createBuffer(),E=r||e.util.createBuffer(),S=t.slice(0),b=new Array(o),T=new Array(o),I=!1,g.output=E,-1!==["CFB","OFB","CTR"].indexOf(a)){for(var i=0;o>i;++i)b[i]=S[i];S=null}},null!==r&&g.start(r,n),g};e.aes=e.aes||{},e.aes.startEncrypting=function(e,t,r,n){return p(e,t,r,!1,n)},e.aes.createEncryptionCipher=function(e,t){return p(e,null,null,!1,t)},e.aes.startDecrypting=function(e,t,r,n){return p(e,t,r,!0,n)},e.aes.createDecryptionCipher=function(e,t){return p(e,null,null,!0,t)},e.aes._expandKey=function(e,t){return s||u(),c(e,t)},e.aes._updateBlock=l}var t="aes";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/aes",["require","module","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){e.pki=e.pki||{};var t=e.pki.oids=e.oids=e.oids||{};t["1.2.840.113549.1.1.1"]="rsaEncryption",t.rsaEncryption="1.2.840.113549.1.1.1",t["1.2.840.113549.1.1.4"]="md5WithRSAEncryption",t.md5WithRSAEncryption="1.2.840.113549.1.1.4",t["1.2.840.113549.1.1.5"]="sha1WithRSAEncryption",t.sha1WithRSAEncryption="1.2.840.113549.1.1.5",t["1.2.840.113549.1.1.7"]="RSAES-OAEP",t["RSAES-OAEP"]="1.2.840.113549.1.1.7",t["1.2.840.113549.1.1.8"]="mgf1",t.mgf1="1.2.840.113549.1.1.8",t["1.2.840.113549.1.1.9"]="pSpecified",t.pSpecified="1.2.840.113549.1.1.9",t["1.2.840.113549.1.1.10"]="RSASSA-PSS",t["RSASSA-PSS"]="1.2.840.113549.1.1.10",t["1.2.840.113549.1.1.11"]="sha256WithRSAEncryption",t.sha256WithRSAEncryption="1.2.840.113549.1.1.11",t["1.2.840.113549.1.1.12"]="sha384WithRSAEncryption",t.sha384WithRSAEncryption="1.2.840.113549.1.1.12",t["1.2.840.113549.1.1.13"]="sha512WithRSAEncryption",t.sha512WithRSAEncryption="1.2.840.113549.1.1.13",t["1.3.14.3.2.26"]="sha1",t.sha1="1.3.14.3.2.26",t["2.16.840.1.101.3.4.2.1"]="sha256",t.sha256="2.16.840.1.101.3.4.2.1",t["2.16.840.1.101.3.4.2.2"]="sha384",t.sha384="2.16.840.1.101.3.4.2.2",t["2.16.840.1.101.3.4.2.3"]="sha512",t.sha512="2.16.840.1.101.3.4.2.3",t["1.2.840.113549.2.5"]="md5",t.md5="1.2.840.113549.2.5",t["1.2.840.113549.1.7.1"]="data",t.data="1.2.840.113549.1.7.1",t["1.2.840.113549.1.7.2"]="signedData",t.signedData="1.2.840.113549.1.7.2",t["1.2.840.113549.1.7.3"]="envelopedData",t.envelopedData="1.2.840.113549.1.7.3",t["1.2.840.113549.1.7.4"]="signedAndEnvelopedData",t.signedAndEnvelopedData="1.2.840.113549.1.7.4",t["1.2.840.113549.1.7.5"]="digestedData",t.digestedData="1.2.840.113549.1.7.5",t["1.2.840.113549.1.7.6"]="encryptedData",t.encryptedData="1.2.840.113549.1.7.6",t["1.2.840.113549.1.9.1"]="emailAddress",t.emailAddress="1.2.840.113549.1.9.1",t["1.2.840.113549.1.9.2"]="unstructuredName",t.unstructuredName="1.2.840.113549.1.9.2",t["1.2.840.113549.1.9.3"]="contentType",t.contentType="1.2.840.113549.1.9.3",t["1.2.840.113549.1.9.4"]="messageDigest",t.messageDigest="1.2.840.113549.1.9.4",t["1.2.840.113549.1.9.5"]="signingTime",t.signingTime="1.2.840.113549.1.9.5",t["1.2.840.113549.1.9.6"]="counterSignature",t.counterSignature="1.2.840.113549.1.9.6",t["1.2.840.113549.1.9.7"]="challengePassword",t.challengePassword="1.2.840.113549.1.9.7",t["1.2.840.113549.1.9.8"]="unstructuredAddress",t.unstructuredAddress="1.2.840.113549.1.9.8",t["1.2.840.113549.1.9.20"]="friendlyName",t.friendlyName="1.2.840.113549.1.9.20",t["1.2.840.113549.1.9.21"]="localKeyId",t.localKeyId="1.2.840.113549.1.9.21",t["1.2.840.113549.1.9.22.1"]="x509Certificate",t.x509Certificate="1.2.840.113549.1.9.22.1",t["1.2.840.113549.1.12.10.1.1"]="keyBag",t.keyBag="1.2.840.113549.1.12.10.1.1",t["1.2.840.113549.1.12.10.1.2"]="pkcs8ShroudedKeyBag",t.pkcs8ShroudedKeyBag="1.2.840.113549.1.12.10.1.2",t["1.2.840.113549.1.12.10.1.3"]="certBag",t.certBag="1.2.840.113549.1.12.10.1.3",t["1.2.840.113549.1.12.10.1.4"]="crlBag",t.crlBag="1.2.840.113549.1.12.10.1.4",t["1.2.840.113549.1.12.10.1.5"]="secretBag",t.secretBag="1.2.840.113549.1.12.10.1.5",t["1.2.840.113549.1.12.10.1.6"]="safeContentsBag",t.safeContentsBag="1.2.840.113549.1.12.10.1.6",t["1.2.840.113549.1.5.13"]="pkcs5PBES2",t.pkcs5PBES2="1.2.840.113549.1.5.13",t["1.2.840.113549.1.5.12"]="pkcs5PBKDF2",t.pkcs5PBKDF2="1.2.840.113549.1.5.12",t["1.2.840.113549.1.12.1.1"]="pbeWithSHAAnd128BitRC4",t.pbeWithSHAAnd128BitRC4="1.2.840.113549.1.12.1.1",t["1.2.840.113549.1.12.1.2"]="pbeWithSHAAnd40BitRC4",t.pbeWithSHAAnd40BitRC4="1.2.840.113549.1.12.1.2",t["1.2.840.113549.1.12.1.3"]="pbeWithSHAAnd3-KeyTripleDES-CBC",t["pbeWithSHAAnd3-KeyTripleDES-CBC"]="1.2.840.113549.1.12.1.3",t["1.2.840.113549.1.12.1.4"]="pbeWithSHAAnd2-KeyTripleDES-CBC",t["pbeWithSHAAnd2-KeyTripleDES-CBC"]="1.2.840.113549.1.12.1.4",t["1.2.840.113549.1.12.1.5"]="pbeWithSHAAnd128BitRC2-CBC",t["pbeWithSHAAnd128BitRC2-CBC"]="1.2.840.113549.1.12.1.5",t["1.2.840.113549.1.12.1.6"]="pbewithSHAAnd40BitRC2-CBC",t["pbewithSHAAnd40BitRC2-CBC"]="1.2.840.113549.1.12.1.6",t["1.2.840.113549.3.7"]="des-EDE3-CBC",t["des-EDE3-CBC"]="1.2.840.113549.3.7",t["2.16.840.1.101.3.4.1.2"]="aes128-CBC",t["aes128-CBC"]="2.16.840.1.101.3.4.1.2",t["2.16.840.1.101.3.4.1.22"]="aes192-CBC",t["aes192-CBC"]="2.16.840.1.101.3.4.1.22",t["2.16.840.1.101.3.4.1.42"]="aes256-CBC",t["aes256-CBC"]="2.16.840.1.101.3.4.1.42",t["2.5.4.3"]="commonName",t.commonName="2.5.4.3",t["2.5.4.5"]="serialName",t.serialName="2.5.4.5",t["2.5.4.6"]="countryName",t.countryName="2.5.4.6",t["2.5.4.7"]="localityName",t.localityName="2.5.4.7",t["2.5.4.8"]="stateOrProvinceName",t.stateOrProvinceName="2.5.4.8",t["2.5.4.10"]="organizationName",t.organizationName="2.5.4.10",t["2.5.4.11"]="organizationalUnitName",t.organizationalUnitName="2.5.4.11",t["2.16.840.1.113730.1.1"]="nsCertType",t.nsCertType="2.16.840.1.113730.1.1",t["2.5.29.1"]="authorityKeyIdentifier",t["2.5.29.2"]="keyAttributes",t["2.5.29.3"]="certificatePolicies",t["2.5.29.4"]="keyUsageRestriction",t["2.5.29.5"]="policyMapping",t["2.5.29.6"]="subtreesConstraint",t["2.5.29.7"]="subjectAltName",t["2.5.29.8"]="issuerAltName",t["2.5.29.9"]="subjectDirectoryAttributes",t["2.5.29.10"]="basicConstraints",t["2.5.29.11"]="nameConstraints",t["2.5.29.12"]="policyConstraints",t["2.5.29.13"]="basicConstraints",t["2.5.29.14"]="subjectKeyIdentifier",t.subjectKeyIdentifier="2.5.29.14",t["2.5.29.15"]="keyUsage",t.keyUsage="2.5.29.15",t["2.5.29.16"]="privateKeyUsagePeriod",t["2.5.29.17"]="subjectAltName",t.subjectAltName="2.5.29.17",t["2.5.29.18"]="issuerAltName",t.issuerAltName="2.5.29.18",t["2.5.29.19"]="basicConstraints",t.basicConstraints="2.5.29.19",t["2.5.29.20"]="cRLNumber",t["2.5.29.21"]="cRLReason",t["2.5.29.22"]="expirationDate",t["2.5.29.23"]="instructionCode",t["2.5.29.24"]="invalidityDate",t["2.5.29.25"]="cRLDistributionPoints",t["2.5.29.26"]="issuingDistributionPoint",t["2.5.29.27"]="deltaCRLIndicator",t["2.5.29.28"]="issuingDistributionPoint",t["2.5.29.29"]="certificateIssuer",t["2.5.29.30"]="nameConstraints",t["2.5.29.31"]="cRLDistributionPoints",t["2.5.29.32"]="certificatePolicies",t["2.5.29.33"]="policyMappings",t["2.5.29.34"]="policyConstraints",t["2.5.29.35"]="authorityKeyIdentifier",t["2.5.29.36"]="policyConstraints",t["2.5.29.37"]="extKeyUsage",t.extKeyUsage="2.5.29.37",t["2.5.29.46"]="freshestCRL",t["2.5.29.54"]="inhibitAnyPolicy",t["1.3.6.1.5.5.7.3.1"]="serverAuth",t.serverAuth="1.3.6.1.5.5.7.3.1",t["1.3.6.1.5.5.7.3.2"]="clientAuth",t.clientAuth="1.3.6.1.5.5.7.3.2",t["1.3.6.1.5.5.7.3.3"]="codeSigning",t.codeSigning="1.3.6.1.5.5.7.3.3",t["1.3.6.1.5.5.7.3.4"]="emailProtection",t.emailProtection="1.3.6.1.5.5.7.3.4",t["1.3.6.1.5.5.7.3.8"]="timeStamping",t.timeStamping="1.3.6.1.5.5.7.3.8"}var t="oids";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/oids",["require","module"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t=e.asn1=e.asn1||{};t.Class={UNIVERSAL:0,APPLICATION:64,CONTEXT_SPECIFIC:128,PRIVATE:192},t.Type={NONE:0,BOOLEAN:1,INTEGER:2,BITSTRING:3,OCTETSTRING:4,NULL:5,OID:6,ODESC:7,EXTERNAL:8,REAL:9,ENUMERATED:10,EMBEDDED:11,UTF8:12,ROID:13,SEQUENCE:16,SET:17,PRINTABLESTRING:19,IA5STRING:22,UTCTIME:23,GENERALIZEDTIME:24,BMPSTRING:30},t.create=function(t,r,n,i){if(e.util.isArray(i)){for(var a=[],s=0;s<i.length;++s)void 0!==i[s]&&a.push(i[s]);i=a}return{tagClass:t,type:r,constructed:n,composed:n||e.util.isArray(i),value:i}};var r=function(e){var t=e.getByte();if(128===t)return void 0;var r,n=128&t;return r=n?e.getInt((127&t)<<3):t};t.fromDer=function(n,i){if(void 0===i&&(i=!0),"string"==typeof n&&(n=e.util.createBuffer(n)),n.length()<2)throw{message:"Too few bytes to parse DER.",bytes:n.length()};var a=n.getByte(),s=192&a,o=31&a,u=r(n);if(n.length()<u){if(i)throw{message:"Too few bytes to read ASN.1 value.",detail:n.length()+" < "+u};u=n.length()}var c,l=32===(32&a),p=l;if(!p&&s===t.Class.UNIVERSAL&&o===t.Type.BITSTRING&&u>1){var f=n.read,d=n.getByte();if(0===d){a=n.getByte();var h=192&a;if(h===t.Class.UNIVERSAL||h===t.Class.CONTEXT_SPECIFIC)try{var g=r(n);p=g===u-(n.read-f),p&&(++f,--u)}catch(y){}}n.read=f}if(p)if(c=[],void 0===u)for(;;){if(n.bytes(2)===String.fromCharCode(0,0)){n.getBytes(2);break}c.push(t.fromDer(n,i))}else for(var m=n.length();u>0;)c.push(t.fromDer(n,i)),u-=m-n.length(),m=n.length();else{if(void 0===u)throw{message:"Non-constructed ASN.1 object of indefinite length."};if(o===t.Type.BMPSTRING){c="";for(var v=0;u>v;v+=2)c+=String.fromCharCode(n.getInt16())}else c=n.getBytes(u)}return t.create(s,o,l,c)},t.toDer=function(r){var n=e.util.createBuffer(),i=r.tagClass|r.type,a=e.util.createBuffer();if(r.composed){r.constructed?i|=32:a.putByte(0);for(var s=0;s<r.value.length;++s)void 0!==r.value[s]&&a.putBuffer(t.toDer(r.value[s]))}else if(r.type===t.Type.BMPSTRING)for(var s=0;s<r.value.length;++s)a.putInt16(r.value.charCodeAt(s));else a.putBytes(r.value);if(n.putByte(i),a.length()<=127)n.putByte(127&a.length());else{var o=a.length(),u="";do u+=String.fromCharCode(255&o),o>>>=8;while(o>0);n.putByte(128|u.length);for(var s=u.length-1;s>=0;--s)n.putByte(u.charCodeAt(s))}return n.putBuffer(a),n},t.oidToDer=function(t){var r=t.split("."),n=e.util.createBuffer();n.putByte(40*parseInt(r[0],10)+parseInt(r[1],10));for(var i,a,s,o,u=2;u<r.length;++u){i=!0,a=[],s=parseInt(r[u],10);do o=127&s,s>>>=7,i||(o|=128),a.push(o),i=!1;while(s>0);for(var c=a.length-1;c>=0;--c)n.putByte(a[c])}return n},t.derToOid=function(t){var r;"string"==typeof t&&(t=e.util.createBuffer(t));var n=t.getByte();r=Math.floor(n/40)+"."+n%40;for(var i=0;t.length()>0;)n=t.getByte(),i<<=7,128&n?i+=127&n:(r+="."+(i+n),i=0);return r},t.utcTimeToDate=function(e){var t=new Date,r=parseInt(e.substr(0,2),10);r=r>=50?1900+r:2e3+r;var n=parseInt(e.substr(2,2),10)-1,i=parseInt(e.substr(4,2),10),a=parseInt(e.substr(6,2),10),s=parseInt(e.substr(8,2),10),o=0;if(e.length>11){var u=e.charAt(10),c=10;"+"!==u&&"-"!==u&&(o=parseInt(e.substr(10,2),10),c+=2)}if(t.setUTCFullYear(r,n,i),t.setUTCHours(a,s,o,0),c&&(u=e.charAt(c),"+"===u||"-"===u)){var l=parseInt(e.substr(c+1,2),10),p=parseInt(e.substr(c+4,2),10),f=60*l+p;f*=6e4,"+"===u?t.setTime(+t-f):t.setTime(+t+f)}return t},t.generalizedTimeToDate=function(e){var t=new Date,r=parseInt(e.substr(0,4),10),n=parseInt(e.substr(4,2),10)-1,i=parseInt(e.substr(6,2),10),a=parseInt(e.substr(8,2),10),s=parseInt(e.substr(10,2),10),o=parseInt(e.substr(12,2),10),u=0,c=0,l=!1;"Z"===e.charAt(e.length-1)&&(l=!0);var p=e.length-5,f=e.charAt(p);if("+"===f||"-"===f){var d=parseInt(e.substr(p+1,2),10),h=parseInt(e.substr(p+4,2),10);c=60*d+h,c*=6e4,"+"===f&&(c*=-1),l=!0}return"."===e.charAt(14)&&(u=1e3*parseFloat(e.substr(14),10)),l?(t.setUTCFullYear(r,n,i),t.setUTCHours(a,s,o,u),t.setTime(+t+c)):(t.setFullYear(r,n,i),t.setHours(a,s,o,u)),t},t.dateToUtcTime=function(e){var t="",r=[];r.push((""+e.getUTCFullYear()).substr(2)),r.push(""+(e.getUTCMonth()+1)),r.push(""+e.getUTCDate()),r.push(""+e.getUTCHours()),r.push(""+e.getUTCMinutes()),r.push(""+e.getUTCSeconds());for(var n=0;n<r.length;++n)r[n].length<2&&(t+="0"),t+=r[n];return t+="Z"},t.validate=function(r,n,i,a){var s=!1;if(r.tagClass!==n.tagClass&&"undefined"!=typeof n.tagClass||r.type!==n.type&&"undefined"!=typeof n.type)a&&(r.tagClass!==n.tagClass&&a.push("["+n.name+'] Expected tag class "'+n.tagClass+'", got "'+r.tagClass+'"'),r.type!==n.type&&a.push("["+n.name+'] Expected type "'+n.type+'", got "'+r.type+'"'));else if(r.constructed===n.constructed||"undefined"==typeof n.constructed){if(s=!0,n.value&&e.util.isArray(n.value))for(var o=0,u=0;s&&u<n.value.length;++u)s=n.value[u].optional||!1,r.value[o]&&(s=t.validate(r.value[o],n.value[u],i,a),s?++o:n.value[u].optional&&(s=!0)),!s&&a&&a.push("["+n.name+'] Tag class "'+n.tagClass+'", type "'+n.type+'" expected value length "'+n.value.length+'", got "'+r.value.length+'"');s&&i&&(n.capture&&(i[n.capture]=r.value),n.captureAsn1&&(i[n.captureAsn1]=r))}else a&&a.push("["+n.name+'] Expected constructed "'+n.constructed+'", got "'+r.constructed+'"');return s};var n=/[^\\u0000-\\u00ff]/;t.prettyPrint=function(r,i,a){var s="";i=i||0,a=a||2,i>0&&(s+="\n");for(var o="",u=0;i*a>u;++u)o+=" ";switch(s+=o+"Tag: ",r.tagClass){case t.Class.UNIVERSAL:s+="Universal:";break;case t.Class.APPLICATION:s+="Application:";break;case t.Class.CONTEXT_SPECIFIC:s+="Context-Specific:";break;case t.Class.PRIVATE:s+="Private:"}if(r.tagClass===t.Class.UNIVERSAL)switch(s+=r.type,r.type){case t.Type.NONE:s+=" (None)";break;case t.Type.BOOLEAN:s+=" (Boolean)";break;case t.Type.BITSTRING:s+=" (Bit string)";break;case t.Type.INTEGER:s+=" (Integer)";break;case t.Type.OCTETSTRING:s+=" (Octet string)";break;case t.Type.NULL:s+=" (Null)";break;case t.Type.OID:s+=" (Object Identifier)";break;case t.Type.ODESC:s+=" (Object Descriptor)";break;case t.Type.EXTERNAL:s+=" (External or Instance of)";break;case t.Type.REAL:s+=" (Real)";break;case t.Type.ENUMERATED:s+=" (Enumerated)";break;case t.Type.EMBEDDED:s+=" (Embedded PDV)";break;case t.Type.UTF8:s+=" (UTF8)";break;case t.Type.ROID:s+=" (Relative Object Identifier)";break;case t.Type.SEQUENCE:s+=" (Sequence)";break;case t.Type.SET:s+=" (Set)";break;case t.Type.PRINTABLESTRING:s+=" (Printable String)";break;case t.Type.IA5String:s+=" (IA5String (ASCII))";break;case t.Type.UTCTIME:s+=" (UTC time)";break;case t.Type.GENERALIZEDTIME:s+=" (Generalized time)";break;case t.Type.BMPSTRING:s+=" (BMP String)"}else s+=r.type;if(s+="\n",s+=o+"Constructed: "+r.constructed+"\n",r.composed){for(var c=0,l="",u=0;u<r.value.length;++u)void 0!==r.value[u]&&(c+=1,l+=t.prettyPrint(r.value[u],i+1,a),u+1<r.value.length&&(l+=","));s+=o+"Sub values: "+c+l}else if(s+=o+"Value: ",r.type===t.Type.OID){var p=t.derToOid(r.value);s+=p,e.pki&&e.pki.oids&&p in e.pki.oids&&(s+=" ("+e.pki.oids[p]+")")}else s+=n.test(r.value)?"0x"+e.util.createBuffer(r.value,"utf8").toHex():0===r.value.length?"[null]":r.value;return s}}var t="asn1";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/asn1",["require","module","./util","./oids"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t=e.md5=e.md5||{};e.md=e.md||{},e.md.algorithms=e.md.algorithms||{},e.md.md5=e.md.algorithms.md5=t;var r=null,n=null,i=null,a=null,s=!1,o=function(){r=String.fromCharCode(128),r+=e.util.fillString(String.fromCharCode(0),64),n=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1,6,11,0,5,10,15,4,9,14,3,8,13,2,7,12,5,8,11,14,1,4,7,10,13,0,3,6,9,12,15,2,0,7,14,5,12,3,10,1,8,15,6,13,4,11,2,9],i=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21],a=new Array(64);for(var t=0;64>t;++t)a[t]=Math.floor(4294967296*Math.abs(Math.sin(t+1)));s=!0},u=function(e,t,r){for(var s,o,u,c,l,p,f,d,h=r.length();h>=64;){for(o=e.h0,u=e.h1,c=e.h2,l=e.h3,d=0;16>d;++d)t[d]=r.getInt32Le(),p=l^u&(c^l),s=o+p+a[d]+t[d],f=i[d],o=l,l=c,c=u,u+=s<<f|s>>>32-f;for(;32>d;++d)p=c^l&(u^c),s=o+p+a[d]+t[n[d]],f=i[d],o=l,l=c,c=u,u+=s<<f|s>>>32-f;for(;48>d;++d)p=u^c^l,s=o+p+a[d]+t[n[d]],f=i[d],o=l,l=c,c=u,u+=s<<f|s>>>32-f;for(;64>d;++d)p=c^(u|~l),s=o+p+a[d]+t[n[d]],f=i[d],o=l,l=c,c=u,u+=s<<f|s>>>32-f;e.h0=e.h0+o&4294967295,e.h1=e.h1+u&4294967295,e.h2=e.h2+c&4294967295,e.h3=e.h3+l&4294967295,h-=64}};t.create=function(){s||o();var t=null,n=e.util.createBuffer(),i=new Array(16),a={algorithm:"md5",blockLength:64,digestLength:16,messageLength:0};return a.start=function(){return a.messageLength=0,n=e.util.createBuffer(),t={h0:1732584193,h1:4023233417,h2:2562383102,h3:271733878},a},a.start(),a.update=function(r,s){return"utf8"===s&&(r=e.util.encodeUtf8(r)),a.messageLength+=r.length,n.putBytes(r),u(t,i,n),(n.read>2048||0===n.length())&&n.compact(),a},a.digest=function(){var s=a.messageLength,o=e.util.createBuffer();o.putBytes(n.bytes()),o.putBytes(r.substr(0,64-(s+8)%64)),o.putInt32Le(s<<3&4294967295),o.putInt32Le(s>>>29&255);var c={h0:t.h0,h1:t.h1,h2:t.h2,h3:t.h3};u(c,i,o);var l=e.util.createBuffer();return l.putInt32Le(c.h0),l.putInt32Le(c.h1),l.putInt32Le(c.h2),l.putInt32Le(c.h3),l},a}}var t="md5";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/md5",["require","module","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t=e.sha1=e.sha1||{};e.md=e.md||{},e.md.algorithms=e.md.algorithms||{},e.md.sha1=e.md.algorithms.sha1=t;var r=null,n=!1,i=function(){r=String.fromCharCode(128),r+=e.util.fillString(String.fromCharCode(0),64),n=!0},a=function(e,t,r){for(var n,i,a,s,o,u,c,l,p=r.length();p>=64;){for(i=e.h0,a=e.h1,s=e.h2,o=e.h3,u=e.h4,l=0;16>l;++l)n=r.getInt32(),t[l]=n,c=o^a&(s^o),n=(i<<5|i>>>27)+c+u+1518500249+n,u=o,o=s,s=a<<30|a>>>2,a=i,i=n;for(;20>l;++l)n=t[l-3]^t[l-8]^t[l-14]^t[l-16],n=n<<1|n>>>31,t[l]=n,c=o^a&(s^o),n=(i<<5|i>>>27)+c+u+1518500249+n,u=o,o=s,s=a<<30|a>>>2,a=i,i=n;for(;32>l;++l)n=t[l-3]^t[l-8]^t[l-14]^t[l-16],n=n<<1|n>>>31,t[l]=n,c=a^s^o,n=(i<<5|i>>>27)+c+u+1859775393+n,u=o,o=s,s=a<<30|a>>>2,a=i,i=n;for(;40>l;++l)n=t[l-6]^t[l-16]^t[l-28]^t[l-32],n=n<<2|n>>>30,t[l]=n,c=a^s^o,n=(i<<5|i>>>27)+c+u+1859775393+n,u=o,o=s,s=a<<30|a>>>2,a=i,i=n;for(;60>l;++l)n=t[l-6]^t[l-16]^t[l-28]^t[l-32],n=n<<2|n>>>30,t[l]=n,c=a&s|o&(a^s),n=(i<<5|i>>>27)+c+u+2400959708+n,u=o,o=s,s=a<<30|a>>>2,a=i,i=n;for(;80>l;++l)n=t[l-6]^t[l-16]^t[l-28]^t[l-32],n=n<<2|n>>>30,t[l]=n,c=a^s^o,n=(i<<5|i>>>27)+c+u+3395469782+n,u=o,o=s,s=a<<30|a>>>2,a=i,i=n;e.h0+=i,e.h1+=a,e.h2+=s,e.h3+=o,e.h4+=u,p-=64}};t.create=function(){n||i();var t=null,s=e.util.createBuffer(),o=new Array(80),u={algorithm:"sha1",blockLength:64,digestLength:20,messageLength:0};return u.start=function(){return u.messageLength=0,s=e.util.createBuffer(),t={h0:1732584193,h1:4023233417,h2:2562383102,h3:271733878,h4:3285377520},u},u.start(),u.update=function(r,n){return"utf8"===n&&(r=e.util.encodeUtf8(r)),u.messageLength+=r.length,s.putBytes(r),a(t,o,s),(s.read>2048||0===s.length())&&s.compact(),u},u.digest=function(){var n=u.messageLength,i=e.util.createBuffer();i.putBytes(s.bytes()),i.putBytes(r.substr(0,64-(n+8)%64)),i.putInt32(n>>>29&255),i.putInt32(n<<3&4294967295);var c={h0:t.h0,h1:t.h1,h2:t.h2,h3:t.h3,h4:t.h4};a(c,o,i);var l=e.util.createBuffer();return l.putInt32(c.h0),l.putInt32(c.h1),l.putInt32(c.h2),l.putInt32(c.h3),l.putInt32(c.h4),l},u}}var t="sha1";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/sha1",["require","module","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t=e.sha256=e.sha256||{};e.md=e.md||{},e.md.algorithms=e.md.algorithms||{},e.md.sha256=e.md.algorithms.sha256=t;var r=null,n=!1,i=null,a=function(){r=String.fromCharCode(128),r+=e.util.fillString(String.fromCharCode(0),64),i=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],n=!0
},s=function(e,t,r){for(var n,a,s,o,u,c,l,p,f,d,h,g,y,m,v,C=r.length();C>=64;){for(l=0;16>l;++l)t[l]=r.getInt32();for(;64>l;++l)n=t[l-2],n=(n>>>17|n<<15)^(n>>>19|n<<13)^n>>>10,a=t[l-15],a=(a>>>7|a<<25)^(a>>>18|a<<14)^a>>>3,t[l]=n+t[l-7]+a+t[l-16]&4294967295;for(p=e.h0,f=e.h1,d=e.h2,h=e.h3,g=e.h4,y=e.h5,m=e.h6,v=e.h7,l=0;64>l;++l)o=(g>>>6|g<<26)^(g>>>11|g<<21)^(g>>>25|g<<7),u=m^g&(y^m),s=(p>>>2|p<<30)^(p>>>13|p<<19)^(p>>>22|p<<10),c=p&f|d&(p^f),n=v+o+u+i[l]+t[l],a=s+c,v=m,m=y,y=g,g=h+n&4294967295,h=d,d=f,f=p,p=n+a&4294967295;e.h0=e.h0+p&4294967295,e.h1=e.h1+f&4294967295,e.h2=e.h2+d&4294967295,e.h3=e.h3+h&4294967295,e.h4=e.h4+g&4294967295,e.h5=e.h5+y&4294967295,e.h6=e.h6+m&4294967295,e.h7=e.h7+v&4294967295,C-=64}};t.create=function(){n||a();var t=null,i=e.util.createBuffer(),o=new Array(64),u={algorithm:"sha256",blockLength:64,digestLength:32,messageLength:0};return u.start=function(){return u.messageLength=0,i=e.util.createBuffer(),t={h0:1779033703,h1:3144134277,h2:1013904242,h3:2773480762,h4:1359893119,h5:2600822924,h6:528734635,h7:1541459225},u},u.start(),u.update=function(r,n){return"utf8"===n&&(r=e.util.encodeUtf8(r)),u.messageLength+=r.length,i.putBytes(r),s(t,o,i),(i.read>2048||0===i.length())&&i.compact(),u},u.digest=function(){var n=u.messageLength,a=e.util.createBuffer();a.putBytes(i.bytes()),a.putBytes(r.substr(0,64-(n+8)%64)),a.putInt32(n>>>29&255),a.putInt32(n<<3&4294967295);var c={h0:t.h0,h1:t.h1,h2:t.h2,h3:t.h3,h4:t.h4,h5:t.h5,h6:t.h6,h7:t.h7};s(c,o,a);var l=e.util.createBuffer();return l.putInt32(c.h0),l.putInt32(c.h1),l.putInt32(c.h2),l.putInt32(c.h3),l.putInt32(c.h4),l.putInt32(c.h5),l.putInt32(c.h6),l.putInt32(c.h7),l},u}}var t="sha256";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/sha256",["require","module","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){e.md=e.md||{},e.md.algorithms={md5:e.md5,sha1:e.sha1,sha256:e.sha256},e.md.md5=e.md5,e.md.sha1=e.sha1,e.md.sha256=e.sha256}var t="md";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/md",["require","module","./md5","./sha1","./sha256"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t=e.hmac=e.hmac||{};t.create=function(){var t=null,r=null,n=null,i=null,a={};return a.start=function(a,s){if(null!==a)if("string"==typeof a){if(a=a.toLowerCase(),!(a in e.md.algorithms))throw'Unknown hash algorithm "'+a+'"';r=e.md.algorithms[a].create()}else r=a;if(null===s)s=t;else{if("string"==typeof s)s=e.util.createBuffer(s);else if(e.util.isArray(s)){var o=s;s=e.util.createBuffer();for(var u=0;u<o.length;++u)s.putByte(o[u])}var c=s.length();c>r.blockLength&&(r.start(),r.update(s.bytes()),s=r.digest()),n=e.util.createBuffer(),i=e.util.createBuffer(),c=s.length();for(var u=0;c>u;++u){var o=s.at(u);n.putByte(54^o),i.putByte(92^o)}if(c<r.blockLength)for(var o=r.blockLength-c,u=0;o>u;++u)n.putByte(54),i.putByte(92);t=s,n=n.bytes(),i=i.bytes()}r.start(),r.update(n)},a.update=function(e){r.update(e)},a.getMac=function(){var e=r.digest().bytes();return r.start(),r.update(i),r.update(e),r.digest()},a.digest=a.getMac,a}}var t="hmac";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/hmac",["require","module","./md","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){function t(e){for(var t=e.name+": ",r=[],n=0;n<e.values.length;++n)r.push(e.values[n].replace(/^(\S+\r\n)/,function(e,t){return" "+t}));t+=r.join(",")+"\r\n";for(var i=0,a=-1,n=0;n<t.length;++n,++i)if(i>65&&-1!==a){var s=t[a];","===s?(++a,t=t.substr(0,a)+"\r\n "+t.substr(a)):t=t.substr(0,a)+"\r\n"+s+t.substr(a+1),i=n-a-1,a=-1,++n}else(" "===t[n]||"	"===t[n]||","===t[n])&&(a=n);return t}function r(e){return e.replace(/^\s+/,"")}var n=e.pem=e.pem||{};n.encode=function(r,n){n=n||{};var i,a="-----BEGIN "+r.type+"-----\r\n";if(r.procType&&(i={name:"Proc-Type",values:[String(r.procType.version),r.procType.type]},a+=t(i)),r.contentDomain&&(i={name:"Content-Domain",values:[r.contentDomain]},a+=t(i)),r.dekInfo&&(i={name:"DEK-Info",values:[r.dekInfo.algorithm]},r.dekInfo.parameters&&i.values.push(r.dekInfo.parameters),a+=t(i)),r.headers)for(var s=0;s<r.headers.length;++s)a+=t(r.headers[s]);return r.procType&&(a+="\r\n"),a+=e.util.encode64(r.body,n.maxline||64)+"\r\n",a+="-----END "+r.type+"-----\r\n"},n.decode=function(t){for(var n,i=[],a=/\s*-----BEGIN ([A-Z0-9- ]+)-----\r?\n([\x21-\x7e\s]+?(?:\r?\n\r?\n))?([:A-Za-z0-9+\/=\s]+?)-----END \1-----/g,s=/([\x21-\x7e]+):\s*([\x21-\x7e\s^:]+)/,o=/\r?\n/;n=a.exec(t),n;){var u={type:n[1],procType:null,contentDomain:null,dekInfo:null,headers:[],body:e.util.decode64(n[3])};if(i.push(u),n[2]){for(var c=n[2].split(o),l=0;n&&l<c.length;){for(var p=c[l].replace(/\s+$/,""),f=l+1;f<c.length;++f){var d=c[f];if(!/\s/.test(d[0]))break;p+=d,l=f}if(n=p.match(s)){for(var h={name:n[1],values:[]},g=n[2].split(","),y=0;y<g.length;++y)h.values.push(r(g[y]));if(u.procType)if(u.contentDomain||"Content-Domain"!==h.name)if(u.dekInfo||"DEK-Info"!==h.name)u.headers.push(h);else{if(0===h.values.length)throw{message:'Invalid PEM formatted message. The "DEK-Info" header must have at least one subfield.'};u.dekInfo={algorithm:g[0],parameters:g[1]||null}}else u.contentDomain=g[0]||"";else{if("Proc-Type"!==h.name)throw{message:'Invalid PEM formatted message. The first encapsulated header must be "Proc-Type".'};if(2!==h.values.length)throw{message:'Invalid PEM formatted message. The "Proc-Type" header must have two subfields.'};u.procType={version:g[0],type:g[1]}}}++l}if("ENCRYPTED"===u.procType&&!u.dekInfo)throw{message:'Invalid PEM formatted message. The "DEK-Info" header must be present if "Proc-Type" is "ENCRYPTED".'}}}if(0===i.length)throw{message:"Invalid PEM formatted message."};return i}}var t="pem";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/pem",["require","module","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){function t(e){for(var t,r=[0,4,536870912,536870916,65536,65540,536936448,536936452,512,516,536871424,536871428,66048,66052,536936960,536936964],n=[0,1,1048576,1048577,67108864,67108865,68157440,68157441,256,257,1048832,1048833,67109120,67109121,68157696,68157697],i=[0,8,2048,2056,16777216,16777224,16779264,16779272,0,8,2048,2056,16777216,16777224,16779264,16779272],a=[0,2097152,134217728,136314880,8192,2105344,134225920,136323072,131072,2228224,134348800,136445952,139264,2236416,134356992,136454144],s=[0,262144,16,262160,0,262144,16,262160,4096,266240,4112,266256,4096,266240,4112,266256],o=[0,1024,32,1056,0,1024,32,1056,33554432,33555456,33554464,33555488,33554432,33555456,33554464,33555488],u=[0,268435456,524288,268959744,2,268435458,524290,268959746,0,268435456,524288,268959744,2,268435458,524290,268959746],c=[0,65536,2048,67584,536870912,536936448,536872960,536938496,131072,196608,133120,198656,537001984,537067520,537004032,537069568],l=[0,262144,0,262144,2,262146,2,262146,33554432,33816576,33554432,33816576,33554434,33816578,33554434,33816578],p=[0,268435456,8,268435464,0,268435456,8,268435464,1024,268436480,1032,268436488,1024,268436480,1032,268436488],f=[0,32,0,32,1048576,1048608,1048576,1048608,8192,8224,8192,8224,1056768,1056800,1056768,1056800],d=[0,16777216,512,16777728,2097152,18874368,2097664,18874880,67108864,83886080,67109376,83886592,69206016,85983232,69206528,85983744],h=[0,4096,134217728,134221824,524288,528384,134742016,134746112,16,4112,134217744,134221840,524304,528400,134742032,134746128],g=[0,4,256,260,0,4,256,260,1,5,257,261,1,5,257,261],y=e.length()>8?3:1,m=[],v=[0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0],C=0,E=0;y>E;E++){var b=e.getInt32(),T=e.getInt32();t=252645135&(b>>>4^T),T^=t,b^=t<<4,t=65535&(T>>>-16^b),b^=t,T^=t<<-16,t=858993459&(b>>>2^T),T^=t,b^=t<<2,t=65535&(T>>>-16^b),b^=t,T^=t<<-16,t=1431655765&(b>>>1^T),T^=t,b^=t<<1,t=16711935&(T>>>8^b),b^=t,T^=t<<8,t=1431655765&(b>>>1^T),T^=t,b^=t<<1,t=b<<8|T>>>20&240,b=T<<24|T<<8&16711680|T>>>8&65280|T>>>24&240,T=t;for(var S=0;S<v.length;S++){v[S]?(b=b<<2|b>>>26,T=T<<2|T>>>26):(b=b<<1|b>>>27,T=T<<1|T>>>27),b&=-15,T&=-15;var I=r[b>>>28]|n[b>>>24&15]|i[b>>>20&15]|a[b>>>16&15]|s[b>>>12&15]|o[b>>>8&15]|u[b>>>4&15],B=c[T>>>28]|l[T>>>24&15]|p[T>>>20&15]|f[T>>>16&15]|d[T>>>12&15]|h[T>>>8&15]|g[T>>>4&15];t=65535&(B>>>16^I),m[C++]=I^t,m[C++]=B^t<<16}}return m}var r=[16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756],n=[-2146402272,-2147450880,32768,1081376,1048576,32,-2146435040,-2147450848,-2147483616,-2146402272,-2146402304,-2147483648,-2147450880,1048576,32,-2146435040,1081344,1048608,-2147450848,0,-2147483648,32768,1081376,-2146435072,1048608,-2147483616,0,1081344,32800,-2146402304,-2146435072,32800,0,1081376,-2146435040,1048576,-2147450848,-2146435072,-2146402304,32768,-2146435072,-2147450880,32,-2146402272,1081376,32,32768,-2147483648,32800,-2146402304,1048576,-2147483616,1048608,-2147450848,-2147483616,1048608,1081344,0,-2147450880,32800,-2147483648,-2146435040,-2146402272,1081344],i=[520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584],a=[8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928],s=[256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080],o=[536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312],u=[2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154],c=[268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696],l=function(l,p){"string"==typeof l&&(8===l.length||24===l.length)&&(l=e.util.createBuffer(l));var f,d=t(l),h=1,g=0,y=0,m=0,v=0,C=!1,E=null,b=null,T=32===d.length?3:9;f=3===T?p?[0,32,2]:[30,-2,-2]:p?[0,32,2,62,30,-2,64,96,2]:[94,62,-2,32,64,2,30,-2,-2];var S=null;return S={start:function(t,r){t?("string"==typeof t&&8===t.length&&(t=e.util.createBuffer(t)),h=1,g=t.getInt32(),m=t.getInt32()):h=0,C=!1,E=e.util.createBuffer(),b=r||e.util.createBuffer(),S.output=b},update:function(e){for(C||E.putBuffer(e);E.length()>=8;){var t,l=E.getInt32(),S=E.getInt32();1===h&&(p?(l^=g,S^=m):(y=g,v=m,g=l,m=S)),t=252645135&(l>>>4^S),S^=t,l^=t<<4,t=65535&(l>>>16^S),S^=t,l^=t<<16,t=858993459&(S>>>2^l),l^=t,S^=t<<2,t=16711935&(S>>>8^l),l^=t,S^=t<<8,t=1431655765&(l>>>1^S),S^=t,l^=t<<1,l=l<<1|l>>>31,S=S<<1|S>>>31;for(var I=0;T>I;I+=3){for(var B=f[I+1],A=f[I+2],F=f[I];F!=B;F+=A){var N=S^d[F],R=(S>>>4|S<<28)^d[F+1];t=l,l=S,S=t^(n[N>>>24&63]|a[N>>>16&63]|o[N>>>8&63]|c[63&N]|r[R>>>24&63]|i[R>>>16&63]|s[R>>>8&63]|u[63&R])}t=l,l=S,S=t}l=l>>>1|l<<31,S=S>>>1|S<<31,t=1431655765&(l>>>1^S),S^=t,l^=t<<1,t=16711935&(S>>>8^l),l^=t,S^=t<<8,t=858993459&(S>>>2^l),l^=t,S^=t<<2,t=65535&(l>>>16^S),S^=t,l^=t<<16,t=252645135&(l>>>4^S),S^=t,l^=t<<4,1===h&&(p?(g=l,m=S):(l^=y,S^=v)),b.putInt32(l),b.putInt32(S)}},finish:function(e){var t=!0;if(p)if(e)t=e(8,E,!p);else{var r=8===E.length()?8:8-E.length();E.fillWithByte(r,r)}if(t&&(C=!0,S.update()),!p&&(t=0===E.length()))if(e)t=e(8,b,!p);else{var n=b.length(),i=b.at(n-1);i>n?t=!1:b.truncate(i)}return t}}};e.des=e.des||{},e.des.startEncrypting=function(e,t,r){var n=l(e,!0);return n.start(t,r),n},e.des.createEncryptionCipher=function(e){return l(e,!0)},e.des.startDecrypting=function(e,t,r){var n=l(e,!1);return n.start(t,r),n},e.des.createDecryptionCipher=function(e){return l(e,!1)}}var t="des";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/des",["require","module","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){function t(e,t,r){this.data=[],null!=e&&("number"==typeof e?this.fromNumber(e,t,r):null==t&&"string"!=typeof e?this.fromString(e,256):this.fromString(e,t))}function r(){return new t(null)}function n(e,t,r,n,i,a){for(;--a>=0;){var s=t*this.data[e++]+r.data[n]+i;i=Math.floor(s/67108864),r.data[n++]=67108863&s}return i}function i(e,t,r,n,i,a){for(var s=32767&t,o=t>>15;--a>=0;){var u=32767&this.data[e],c=this.data[e++]>>15,l=o*u+c*s;u=s*u+((32767&l)<<15)+r.data[n]+(1073741823&i),i=(u>>>30)+(l>>>15)+o*c+(i>>>30),r.data[n++]=1073741823&u}return i}function a(e,t,r,n,i,a){for(var s=16383&t,o=t>>14;--a>=0;){var u=16383&this.data[e],c=this.data[e++]>>14,l=o*u+c*s;u=s*u+((16383&l)<<14)+r.data[n]+i,i=(u>>28)+(l>>14)+o*c,r.data[n++]=268435455&u}return i}function s(e){return ir.charAt(e)}function o(e,t){var r=ar[e.charCodeAt(t)];return null==r?-1:r}function u(e){for(var t=this.t-1;t>=0;--t)e.data[t]=this.data[t];e.t=this.t,e.s=this.s}function c(e){this.t=1,this.s=0>e?-1:0,e>0?this.data[0]=e:-1>e?this.data[0]=e+DV:this.t=0}function l(e){var t=r();return t.fromInt(e),t}function p(e,r){var n;if(16==r)n=4;else if(8==r)n=3;else if(256==r)n=8;else if(2==r)n=1;else if(32==r)n=5;else{if(4!=r)return this.fromRadix(e,r),void 0;n=2}this.t=0,this.s=0;for(var i=e.length,a=!1,s=0;--i>=0;){var u=8==n?255&e[i]:o(e,i);0>u?"-"==e.charAt(i)&&(a=!0):(a=!1,0==s?this.data[this.t++]=u:s+n>this.DB?(this.data[this.t-1]|=(u&(1<<this.DB-s)-1)<<s,this.data[this.t++]=u>>this.DB-s):this.data[this.t-1]|=u<<s,s+=n,s>=this.DB&&(s-=this.DB))}8==n&&0!=(128&e[0])&&(this.s=-1,s>0&&(this.data[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),a&&t.ZERO.subTo(this,this)}function f(){for(var e=this.s&this.DM;this.t>0&&this.data[this.t-1]==e;)--this.t}function d(e){if(this.s<0)return"-"+this.negate().toString(e);var t;if(16==e)t=4;else if(8==e)t=3;else if(2==e)t=1;else if(32==e)t=5;else{if(4!=e)return this.toRadix(e);t=2}var r,n=(1<<t)-1,i=!1,a="",o=this.t,u=this.DB-o*this.DB%t;if(o-->0)for(u<this.DB&&(r=this.data[o]>>u)>0&&(i=!0,a=s(r));o>=0;)t>u?(r=(this.data[o]&(1<<u)-1)<<t-u,r|=this.data[--o]>>(u+=this.DB-t)):(r=this.data[o]>>(u-=t)&n,0>=u&&(u+=this.DB,--o)),r>0&&(i=!0),i&&(a+=s(r));return i?a:"0"}function h(){var e=r();return t.ZERO.subTo(this,e),e}function g(){return this.s<0?this.negate():this}function y(e){var t=this.s-e.s;if(0!=t)return t;var r=this.t;if(t=r-e.t,0!=t)return this.s<0?-t:t;for(;--r>=0;)if(0!=(t=this.data[r]-e.data[r]))return t;return 0}function m(e){var t,r=1;return 0!=(t=e>>>16)&&(e=t,r+=16),0!=(t=e>>8)&&(e=t,r+=8),0!=(t=e>>4)&&(e=t,r+=4),0!=(t=e>>2)&&(e=t,r+=2),0!=(t=e>>1)&&(e=t,r+=1),r}function v(){return this.t<=0?0:this.DB*(this.t-1)+m(this.data[this.t-1]^this.s&this.DM)}function C(e,t){var r;for(r=this.t-1;r>=0;--r)t.data[r+e]=this.data[r];for(r=e-1;r>=0;--r)t.data[r]=0;t.t=this.t+e,t.s=this.s}function E(e,t){for(var r=e;r<this.t;++r)t.data[r-e]=this.data[r];t.t=Math.max(this.t-e,0),t.s=this.s}function b(e,t){var r,n=e%this.DB,i=this.DB-n,a=(1<<i)-1,s=Math.floor(e/this.DB),o=this.s<<n&this.DM;for(r=this.t-1;r>=0;--r)t.data[r+s+1]=this.data[r]>>i|o,o=(this.data[r]&a)<<n;for(r=s-1;r>=0;--r)t.data[r]=0;t.data[s]=o,t.t=this.t+s+1,t.s=this.s,t.clamp()}function T(e,t){t.s=this.s;var r=Math.floor(e/this.DB);if(r>=this.t)return t.t=0,void 0;var n=e%this.DB,i=this.DB-n,a=(1<<n)-1;t.data[0]=this.data[r]>>n;for(var s=r+1;s<this.t;++s)t.data[s-r-1]|=(this.data[s]&a)<<i,t.data[s-r]=this.data[s]>>n;n>0&&(t.data[this.t-r-1]|=(this.s&a)<<i),t.t=this.t-r,t.clamp()}function S(e,t){for(var r=0,n=0,i=Math.min(e.t,this.t);i>r;)n+=this.data[r]-e.data[r],t.data[r++]=n&this.DM,n>>=this.DB;if(e.t<this.t){for(n-=e.s;r<this.t;)n+=this.data[r],t.data[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<e.t;)n-=e.data[r],t.data[r++]=n&this.DM,n>>=this.DB;n-=e.s}t.s=0>n?-1:0,-1>n?t.data[r++]=this.DV+n:n>0&&(t.data[r++]=n),t.t=r,t.clamp()}function I(e,r){var n=this.abs(),i=e.abs(),a=n.t;for(r.t=a+i.t;--a>=0;)r.data[a]=0;for(a=0;a<i.t;++a)r.data[a+n.t]=n.am(0,i.data[a],r,a,0,n.t);r.s=0,r.clamp(),this.s!=e.s&&t.ZERO.subTo(r,r)}function B(e){for(var t=this.abs(),r=e.t=2*t.t;--r>=0;)e.data[r]=0;for(r=0;r<t.t-1;++r){var n=t.am(r,t.data[r],e,2*r,0,1);(e.data[r+t.t]+=t.am(r+1,2*t.data[r],e,2*r+1,n,t.t-r-1))>=t.DV&&(e.data[r+t.t]-=t.DV,e.data[r+t.t+1]=1)}e.t>0&&(e.data[e.t-1]+=t.am(r,t.data[r],e,2*r,0,1)),e.s=0,e.clamp()}function A(e,n,i){var a=e.abs();if(!(a.t<=0)){var s=this.abs();if(s.t<a.t)return null!=n&&n.fromInt(0),null!=i&&this.copyTo(i),void 0;null==i&&(i=r());var o=r(),u=this.s,c=e.s,l=this.DB-m(a.data[a.t-1]);l>0?(a.lShiftTo(l,o),s.lShiftTo(l,i)):(a.copyTo(o),s.copyTo(i));var p=o.t,f=o.data[p-1];if(0!=f){var d=f*(1<<this.F1)+(p>1?o.data[p-2]>>this.F2:0),h=this.FV/d,g=(1<<this.F1)/d,y=1<<this.F2,v=i.t,C=v-p,E=null==n?r():n;for(o.dlShiftTo(C,E),i.compareTo(E)>=0&&(i.data[i.t++]=1,i.subTo(E,i)),t.ONE.dlShiftTo(p,E),E.subTo(o,o);o.t<p;)o.data[o.t++]=0;for(;--C>=0;){var b=i.data[--v]==f?this.DM:Math.floor(i.data[v]*h+(i.data[v-1]+y)*g);if((i.data[v]+=o.am(0,b,i,C,0,p))<b)for(o.dlShiftTo(C,E),i.subTo(E,i);i.data[v]<--b;)i.subTo(E,i)}null!=n&&(i.drShiftTo(p,n),u!=c&&t.ZERO.subTo(n,n)),i.t=p,i.clamp(),l>0&&i.rShiftTo(l,i),0>u&&t.ZERO.subTo(i,i)}}}function F(e){var n=r();return this.abs().divRemTo(e,null,n),this.s<0&&n.compareTo(t.ZERO)>0&&e.subTo(n,n),n}function N(e){this.m=e}function R(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e}function k(e){return e}function D(e){e.divRemTo(this.m,null,e)}function w(e,t,r){e.multiplyTo(t,r),this.reduce(r)}function L(e,t){e.squareTo(t),this.reduce(t)}function U(){if(this.t<1)return 0;var e=this.data[0];if(0==(1&e))return 0;var t=3&e;return t=t*(2-(15&e)*t)&15,t=t*(2-(255&e)*t)&255,t=t*(2-((65535&e)*t&65535))&65535,t=t*(2-e*t%this.DV)%this.DV,t>0?this.DV-t:-t}function _(e){this.m=e,this.mp=e.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<e.DB-15)-1,this.mt2=2*e.t}function O(e){var n=r();return e.abs().dlShiftTo(this.m.t,n),n.divRemTo(this.m,null,n),e.s<0&&n.compareTo(t.ZERO)>0&&this.m.subTo(n,n),n}function P(e){var t=r();return e.copyTo(t),this.reduce(t),t}function x(e){for(;e.t<=this.mt2;)e.data[e.t++]=0;for(var t=0;t<this.m.t;++t){var r=32767&e.data[t],n=r*this.mpl+((r*this.mph+(e.data[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(r=t+this.m.t,e.data[r]+=this.m.am(0,n,e,t,0,this.m.t);e.data[r]>=e.DV;)e.data[r]-=e.DV,e.data[++r]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)}function V(e,t){e.squareTo(t),this.reduce(t)}function j(e,t,r){e.multiplyTo(t,r),this.reduce(r)}function q(){return 0==(this.t>0?1&this.data[0]:this.s)}function K(e,n){if(e>4294967295||1>e)return t.ONE;var i=r(),a=r(),s=n.convert(this),o=m(e)-1;for(s.copyTo(i);--o>=0;)if(n.sqrTo(i,a),(e&1<<o)>0)n.mulTo(a,s,i);else{var u=i;i=a,a=u}return n.revert(i)}function M(e,t){var r;return r=256>e||t.isEven()?new N(t):new _(t),this.exp(e,r)}function G(){var e=r();return this.copyTo(e),e}function H(){if(this.s<0){if(1==this.t)return this.data[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this.data[0];if(0==this.t)return 0}return(this.data[1]&(1<<32-this.DB)-1)<<this.DB|this.data[0]}function Q(){return 0==this.t?this.s:this.data[0]<<24>>24}function X(){return 0==this.t?this.s:this.data[0]<<16>>16}function z(e){return Math.floor(Math.LN2*this.DB/Math.log(e))}function W(){return this.s<0?-1:this.t<=0||1==this.t&&this.data[0]<=0?0:1}function Y(e){if(null==e&&(e=10),0==this.signum()||2>e||e>36)return"0";var t=this.chunkSize(e),n=Math.pow(e,t),i=l(n),a=r(),s=r(),o="";for(this.divRemTo(i,a,s);a.signum()>0;)o=(n+s.intValue()).toString(e).substr(1)+o,a.divRemTo(i,a,s);return s.intValue().toString(e)+o}function Z(e,r){this.fromInt(0),null==r&&(r=10);for(var n=this.chunkSize(r),i=Math.pow(r,n),a=!1,s=0,u=0,c=0;c<e.length;++c){var l=o(e,c);0>l?"-"==e.charAt(c)&&0==this.signum()&&(a=!0):(u=r*u+l,++s>=n&&(this.dMultiply(i),this.dAddOffset(u,0),s=0,u=0))}s>0&&(this.dMultiply(Math.pow(r,s)),this.dAddOffset(u,0)),a&&t.ZERO.subTo(this,this)}function J(e,r,n){if("number"==typeof r)if(2>e)this.fromInt(1);else for(this.fromNumber(e,n),this.testBit(e-1)||this.bitwiseTo(t.ONE.shiftLeft(e-1),st,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(r);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(t.ONE.shiftLeft(e-1),this);else{var i=new Array,a=7&e;i.length=(e>>3)+1,r.nextBytes(i),a>0?i[0]&=(1<<a)-1:i[0]=0,this.fromString(i,256)}}function $(){var e=this.t,t=new Array;t[0]=this.s;var r,n=this.DB-e*this.DB%8,i=0;if(e-->0)for(n<this.DB&&(r=this.data[e]>>n)!=(this.s&this.DM)>>n&&(t[i++]=r|this.s<<this.DB-n);e>=0;)8>n?(r=(this.data[e]&(1<<n)-1)<<8-n,r|=this.data[--e]>>(n+=this.DB-8)):(r=this.data[e]>>(n-=8)&255,0>=n&&(n+=this.DB,--e)),0!=(128&r)&&(r|=-256),0==i&&(128&this.s)!=(128&r)&&++i,(i>0||r!=this.s)&&(t[i++]=r);return t}function et(e){return 0==this.compareTo(e)}function tt(e){return this.compareTo(e)<0?this:e}function rt(e){return this.compareTo(e)>0?this:e}function nt(e,t,r){var n,i,a=Math.min(e.t,this.t);for(n=0;a>n;++n)r.data[n]=t(this.data[n],e.data[n]);if(e.t<this.t){for(i=e.s&this.DM,n=a;n<this.t;++n)r.data[n]=t(this.data[n],i);r.t=this.t}else{for(i=this.s&this.DM,n=a;n<e.t;++n)r.data[n]=t(i,e.data[n]);r.t=e.t}r.s=t(this.s,e.s),r.clamp()}function it(e,t){return e&t}function at(e){var t=r();return this.bitwiseTo(e,it,t),t}function st(e,t){return e|t}function ot(e){var t=r();return this.bitwiseTo(e,st,t),t}function ut(e,t){return e^t}function ct(e){var t=r();return this.bitwiseTo(e,ut,t),t}function lt(e,t){return e&~t}function pt(e){var t=r();return this.bitwiseTo(e,lt,t),t}function ft(){for(var e=r(),t=0;t<this.t;++t)e.data[t]=this.DM&~this.data[t];return e.t=this.t,e.s=~this.s,e}function dt(e){var t=r();return 0>e?this.rShiftTo(-e,t):this.lShiftTo(e,t),t}function ht(e){var t=r();return 0>e?this.lShiftTo(-e,t):this.rShiftTo(e,t),t}function gt(e){if(0==e)return-1;var t=0;return 0==(65535&e)&&(e>>=16,t+=16),0==(255&e)&&(e>>=8,t+=8),0==(15&e)&&(e>>=4,t+=4),0==(3&e)&&(e>>=2,t+=2),0==(1&e)&&++t,t}function yt(){for(var e=0;e<this.t;++e)if(0!=this.data[e])return e*this.DB+gt(this.data[e]);return this.s<0?this.t*this.DB:-1}function mt(e){for(var t=0;0!=e;)e&=e-1,++t;return t}function vt(){for(var e=0,t=this.s&this.DM,r=0;r<this.t;++r)e+=mt(this.data[r]^t);return e}function Ct(e){var t=Math.floor(e/this.DB);return t>=this.t?0!=this.s:0!=(this.data[t]&1<<e%this.DB)}function Et(e,r){var n=t.ONE.shiftLeft(e);return this.bitwiseTo(n,r,n),n}function bt(e){return this.changeBit(e,st)}function Tt(e){return this.changeBit(e,lt)}function St(e){return this.changeBit(e,ut)}function It(e,t){for(var r=0,n=0,i=Math.min(e.t,this.t);i>r;)n+=this.data[r]+e.data[r],t.data[r++]=n&this.DM,n>>=this.DB;if(e.t<this.t){for(n+=e.s;r<this.t;)n+=this.data[r],t.data[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<e.t;)n+=e.data[r],t.data[r++]=n&this.DM,n>>=this.DB;n+=e.s}t.s=0>n?-1:0,n>0?t.data[r++]=n:-1>n&&(t.data[r++]=this.DV+n),t.t=r,t.clamp()}function Bt(e){var t=r();return this.addTo(e,t),t}function At(e){var t=r();return this.subTo(e,t),t}function Ft(e){var t=r();return this.multiplyTo(e,t),t}function Nt(e){var t=r();return this.divRemTo(e,t,null),t}function Rt(e){var t=r();return this.divRemTo(e,null,t),t}function kt(e){var t=r(),n=r();return this.divRemTo(e,t,n),new Array(t,n)}function Dt(e){this.data[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()}function wt(e,t){if(0!=e){for(;this.t<=t;)this.data[this.t++]=0;for(this.data[t]+=e;this.data[t]>=this.DV;)this.data[t]-=this.DV,++t>=this.t&&(this.data[this.t++]=0),++this.data[t]}}function Lt(){}function Ut(e){return e}function _t(e,t,r){e.multiplyTo(t,r)}function Ot(e,t){e.squareTo(t)}function Pt(e){return this.exp(e,new Lt)}function xt(e,t,r){var n=Math.min(this.t+e.t,t);for(r.s=0,r.t=n;n>0;)r.data[--n]=0;var i;for(i=r.t-this.t;i>n;++n)r.data[n+this.t]=this.am(0,e.data[n],r,n,0,this.t);for(i=Math.min(e.t,t);i>n;++n)this.am(0,e.data[n],r,n,0,t-n);r.clamp()}function Vt(e,t,r){--t;var n=r.t=this.t+e.t-t;for(r.s=0;--n>=0;)r.data[n]=0;for(n=Math.max(t-this.t,0);n<e.t;++n)r.data[this.t+n-t]=this.am(t-n,e.data[n],r,0,0,this.t+n-t);r.clamp(),r.drShiftTo(1,r)}function jt(e){this.r2=r(),this.q3=r(),t.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}function qt(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=r();return e.copyTo(t),this.reduce(t),t}function Kt(e){return e}function Mt(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)}function Gt(e,t){e.squareTo(t),this.reduce(t)}function Ht(e,t,r){e.multiplyTo(t,r),this.reduce(r)}function Qt(e,t){var n,i,a=e.bitLength(),s=l(1);if(0>=a)return s;n=18>a?1:48>a?3:144>a?4:768>a?5:6,i=8>a?new N(t):t.isEven()?new jt(t):new _(t);var o=new Array,u=3,c=n-1,p=(1<<n)-1;if(o[1]=i.convert(this),n>1){var f=r();for(i.sqrTo(o[1],f);p>=u;)o[u]=r(),i.mulTo(f,o[u-2],o[u]),u+=2}var d,h,g=e.t-1,y=!0,v=r();for(a=m(e.data[g])-1;g>=0;){for(a>=c?d=e.data[g]>>a-c&p:(d=(e.data[g]&(1<<a+1)-1)<<c-a,g>0&&(d|=e.data[g-1]>>this.DB+a-c)),u=n;0==(1&d);)d>>=1,--u;if((a-=u)<0&&(a+=this.DB,--g),y)o[d].copyTo(s),y=!1;else{for(;u>1;)i.sqrTo(s,v),i.sqrTo(v,s),u-=2;u>0?i.sqrTo(s,v):(h=s,s=v,v=h),i.mulTo(v,o[d],s)}for(;g>=0&&0==(e.data[g]&1<<a);)i.sqrTo(s,v),h=s,s=v,v=h,--a<0&&(a=this.DB-1,--g)}return i.revert(s)}function Xt(e){var t=this.s<0?this.negate():this.clone(),r=e.s<0?e.negate():e.clone();if(t.compareTo(r)<0){var n=t;t=r,r=n}var i=t.getLowestSetBit(),a=r.getLowestSetBit();if(0>a)return t;for(a>i&&(a=i),a>0&&(t.rShiftTo(a,t),r.rShiftTo(a,r));t.signum()>0;)(i=t.getLowestSetBit())>0&&t.rShiftTo(i,t),(i=r.getLowestSetBit())>0&&r.rShiftTo(i,r),t.compareTo(r)>=0?(t.subTo(r,t),t.rShiftTo(1,t)):(r.subTo(t,r),r.rShiftTo(1,r));return a>0&&r.lShiftTo(a,r),r}function zt(e){if(0>=e)return 0;var t=this.DV%e,r=this.s<0?e-1:0;if(this.t>0)if(0==t)r=this.data[0]%e;else for(var n=this.t-1;n>=0;--n)r=(t*r+this.data[n])%e;return r}function Wt(e){var r=e.isEven();if(this.isEven()&&r||0==e.signum())return t.ZERO;for(var n=e.clone(),i=this.clone(),a=l(1),s=l(0),o=l(0),u=l(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),r?(a.isEven()&&s.isEven()||(a.addTo(this,a),s.subTo(e,s)),a.rShiftTo(1,a)):s.isEven()||s.subTo(e,s),s.rShiftTo(1,s);for(;i.isEven();)i.rShiftTo(1,i),r?(o.isEven()&&u.isEven()||(o.addTo(this,o),u.subTo(e,u)),o.rShiftTo(1,o)):u.isEven()||u.subTo(e,u),u.rShiftTo(1,u);n.compareTo(i)>=0?(n.subTo(i,n),r&&a.subTo(o,a),s.subTo(u,s)):(i.subTo(n,i),r&&o.subTo(a,o),u.subTo(s,u))}return 0!=i.compareTo(t.ONE)?t.ZERO:u.compareTo(e)>=0?u.subtract(e):u.signum()<0?(u.addTo(e,u),u.signum()<0?u.add(e):u):u}function Yt(e){var t,r=this.abs();
if(1==r.t&&r.data[0]<=sr[sr.length-1]){for(t=0;t<sr.length;++t)if(r.data[0]==sr[t])return!0;return!1}if(r.isEven())return!1;for(t=1;t<sr.length;){for(var n=sr[t],i=t+1;i<sr.length&&or>n;)n*=sr[i++];for(n=r.modInt(n);i>t;)if(n%sr[t++]==0)return!1}return r.millerRabin(e)}function Zt(e){var n=this.subtract(t.ONE),i=n.getLowestSetBit();if(0>=i)return!1;var a=n.shiftRight(i);e=e+1>>1,e>sr.length&&(e=sr.length);for(var s=r(),o=0;e>o;++o){s.fromInt(sr[o]);var u=s.modPow(a,this);if(0!=u.compareTo(t.ONE)&&0!=u.compareTo(n)){for(var c=1;c++<i&&0!=u.compareTo(n);)if(u=u.modPowInt(2,this),0==u.compareTo(t.ONE))return!1;if(0!=u.compareTo(n))return!1}}return!0}var Jt,$t=0xdeadbeefcafe,er=15715070==(16777215&$t);"undefined"==typeof navigator?(t.prototype.am=a,Jt=28):er&&"Microsoft Internet Explorer"==navigator.appName?(t.prototype.am=i,Jt=30):er&&"Netscape"!=navigator.appName?(t.prototype.am=n,Jt=26):(t.prototype.am=a,Jt=28),t.prototype.DB=Jt,t.prototype.DM=(1<<Jt)-1,t.prototype.DV=1<<Jt;var tr=52;t.prototype.FV=Math.pow(2,tr),t.prototype.F1=tr-Jt,t.prototype.F2=2*Jt-tr;var rr,nr,ir="0123456789abcdefghijklmnopqrstuvwxyz",ar=new Array;for(rr="0".charCodeAt(0),nr=0;9>=nr;++nr)ar[rr++]=nr;for(rr="a".charCodeAt(0),nr=10;36>nr;++nr)ar[rr++]=nr;for(rr="A".charCodeAt(0),nr=10;36>nr;++nr)ar[rr++]=nr;N.prototype.convert=R,N.prototype.revert=k,N.prototype.reduce=D,N.prototype.mulTo=w,N.prototype.sqrTo=L,_.prototype.convert=O,_.prototype.revert=P,_.prototype.reduce=x,_.prototype.mulTo=j,_.prototype.sqrTo=V,t.prototype.copyTo=u,t.prototype.fromInt=c,t.prototype.fromString=p,t.prototype.clamp=f,t.prototype.dlShiftTo=C,t.prototype.drShiftTo=E,t.prototype.lShiftTo=b,t.prototype.rShiftTo=T,t.prototype.subTo=S,t.prototype.multiplyTo=I,t.prototype.squareTo=B,t.prototype.divRemTo=A,t.prototype.invDigit=U,t.prototype.isEven=q,t.prototype.exp=K,t.prototype.toString=d,t.prototype.negate=h,t.prototype.abs=g,t.prototype.compareTo=y,t.prototype.bitLength=v,t.prototype.mod=F,t.prototype.modPowInt=M,t.ZERO=l(0),t.ONE=l(1),Lt.prototype.convert=Ut,Lt.prototype.revert=Ut,Lt.prototype.mulTo=_t,Lt.prototype.sqrTo=Ot,jt.prototype.convert=qt,jt.prototype.revert=Kt,jt.prototype.reduce=Mt,jt.prototype.mulTo=Ht,jt.prototype.sqrTo=Gt;var sr=[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],or=(1<<26)/sr[sr.length-1];t.prototype.chunkSize=z,t.prototype.toRadix=Y,t.prototype.fromRadix=Z,t.prototype.fromNumber=J,t.prototype.bitwiseTo=nt,t.prototype.changeBit=Et,t.prototype.addTo=It,t.prototype.dMultiply=Dt,t.prototype.dAddOffset=wt,t.prototype.multiplyLowerTo=xt,t.prototype.multiplyUpperTo=Vt,t.prototype.modInt=zt,t.prototype.millerRabin=Zt,t.prototype.clone=G,t.prototype.intValue=H,t.prototype.byteValue=Q,t.prototype.shortValue=X,t.prototype.signum=W,t.prototype.toByteArray=$,t.prototype.equals=et,t.prototype.min=tt,t.prototype.max=rt,t.prototype.and=at,t.prototype.or=ot,t.prototype.xor=ct,t.prototype.andNot=pt,t.prototype.not=ft,t.prototype.shiftLeft=dt,t.prototype.shiftRight=ht,t.prototype.getLowestSetBit=yt,t.prototype.bitCount=vt,t.prototype.testBit=Ct,t.prototype.setBit=bt,t.prototype.clearBit=Tt,t.prototype.flipBit=St,t.prototype.add=Bt,t.prototype.subtract=At,t.prototype.multiply=Ft,t.prototype.divide=Nt,t.prototype.remainder=Rt,t.prototype.divideAndRemainder=kt,t.prototype.modPow=Qt,t.prototype.modInverse=Wt,t.prototype.pow=Pt,t.prototype.gcd=Xt,t.prototype.isProbablePrime=Yt,e.jsbn=e.jsbn||{},e.jsbn.BigInteger=t}var t="jsbn";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/jsbn",["require","module"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){e.mgf=e.mgf||{};var t=e.mgf.mgf1=e.mgf1=e.mgf1||{};t.create=function(t){var r={generate:function(r,n){for(var i=new e.util.ByteBuffer,a=Math.ceil(n/t.digestLength),s=0;a>s;s++){var o=new e.util.ByteBuffer;o.putInt32(s),t.start(),t.update(r+o.getBytes()),i.putBuffer(t.digest())}return i.truncate(i.length()-n),i.getBytes()}};return r}}var t="mgf1";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/mgf1",["require","module","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){e.mgf=e.mgf||{},e.mgf.mgf1=e.mgf1}var t="mgf";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/mgf",["require","module","./mgf1"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t=e.pkcs5=e.pkcs5||{};e.pbkdf2=t.pbkdf2=function(t,r,n,i,a){("undefined"==typeof a||null===a)&&(a=e.md.sha1.create());var s=a.digestLength;if(i>4294967295*s)throw{message:"Derived key is too long."};var o=Math.ceil(i/s),u=i-(o-1)*s,c=e.hmac.create();c.start(a,t);for(var l,p,f,d="",h=1;o>=h;++h){c.update(r),c.update(e.util.int32ToBytes(h)),l=f=c.digest().getBytes();for(var g=2;n>=g;++g)c.start(null,null),c.update(f),p=c.digest().getBytes(),l=e.util.xorBytes(l,p,s),f=p;d+=o>h?l:l.substr(0,u)}return d}}var t="pbkdf2";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/pbkdf2",["require","module","./hmac","./md","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t=e.asn1,r=e.pkcs7asn1=e.pkcs7asn1||{};e.pkcs7=e.pkcs7||{},e.pkcs7.asn1=r;var n={name:"ContentInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"ContentInfo.ContentType",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"contentType"},{name:"ContentInfo.content",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,captureAsn1:"content"}]};r.contentInfoValidator=n;var i={name:"EncryptedContentInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedContentInfo.contentType",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"contentType"},{name:"EncryptedContentInfo.contentEncryptionAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedContentInfo.contentEncryptionAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"encAlgorithm"},{name:"EncryptedContentInfo.contentEncryptionAlgorithm.parameter",tagClass:t.Class.UNIVERSAL,captureAsn1:"encParameter"}]},{name:"EncryptedContentInfo.encryptedContent",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,capture:"encContent"}]};r.envelopedDataValidator={name:"EnvelopedData",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EnvelopedData.Version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"},{name:"EnvelopedData.RecipientInfos",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0,captureAsn1:"recipientInfos"}].concat(i)},r.encryptedDataValidator={name:"EncryptedData",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedData.Version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"}].concat(i)};var a={name:"SignerInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SignerInfo.Version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1},{name:"SignerInfo.IssuerAndSerialNumber",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0},{name:"SignerInfo.DigestAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0},{name:"SignerInfo.AuthenticatedAttributes",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,capture:"authenticatedAttributes"},{name:"SignerInfo.DigestEncryptionAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0},{name:"SignerInfo.EncryptedDigest",tagClass:t.Class.UNIVERSAL,type:t.Type.OCTETSTRING,constructed:!1,capture:"signature"},{name:"SignerInfo.UnauthenticatedAttributes",tagClass:t.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,optional:!0}]};r.signedDataValidator={name:"SignedData",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"SignedData.Version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"},{name:"SignedData.DigestAlgorithms",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,constructed:!0,captureAsn1:"digestAlgorithms"},n,{name:"SignedData.Certificates",tagClass:t.Class.CONTEXT_SPECIFIC,type:0,optional:!0,captureAsn1:"certificates"},{name:"SignedData.CertificateRevocationLists",tagClass:t.Class.CONTEXT_SPECIFIC,type:1,optional:!0,captureAsn1:"crls"},{name:"SignedData.SignerInfos",tagClass:t.Class.UNIVERSAL,type:t.Type.SET,capture:"signerInfos",value:[a]}]},r.recipientInfoValidator={name:"RecipientInfo",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.version",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"version"},{name:"RecipientInfo.issuerAndSerial",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.issuerAndSerial.issuer",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,captureAsn1:"issuer"},{name:"RecipientInfo.issuerAndSerial.serialNumber",tagClass:t.Class.UNIVERSAL,type:t.Type.INTEGER,constructed:!1,capture:"serial"}]},{name:"RecipientInfo.keyEncryptionAlgorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.SEQUENCE,constructed:!0,value:[{name:"RecipientInfo.keyEncryptionAlgorithm.algorithm",tagClass:t.Class.UNIVERSAL,type:t.Type.OID,constructed:!1,capture:"encAlgorithm"},{name:"RecipientInfo.keyEncryptionAlgorithm.parameter",tagClass:t.Class.UNIVERSAL,constructed:!1,captureAsn1:"encParameter"}]},{name:"RecipientInfo.encryptedKey",tagClass:t.Class.UNIVERSAL,type:t.Type.OCTETSTRING,constructed:!1,capture:"encKey"}]}}var t="pkcs7asn1";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/pkcs7asn1",["require","module","./asn1","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t="undefined"!=typeof process&&process.versions&&process.versions.node,r=null;!e.disableNativeCode&&t&&(r=require("crypto"));var n=e.prng=e.prng||{};n.create=function(t){function n(e){if(o.pools[0].messageLength>=32)return a(),e();var t=32-o.pools[0].messageLength<<5;o.seedFile(t,function(t,r){return t?e(t):(o.collect(r),a(),e(),void 0)})}function i(){if(o.pools[0].messageLength>=32)return a();var e=32-o.pools[0].messageLength<<5;o.collect(o.seedFileSync(e)),a()}function a(){var t=e.md.sha1.create();t.update(o.pools[0].digest().getBytes()),o.pools[0].start();for(var r=1,n=1;32>n;++n)r=31===r?2147483648:r<<2,r%o.reseeds===0&&(t.update(o.pools[n].digest().getBytes()),o.pools[n].start());var i=t.digest().getBytes();t.start(),t.update(i);var a=t.digest().getBytes();o.key=o.plugin.formatKey(i),o.seed=o.plugin.formatSeed(a),++o.reseeds,o.generated=0,o.time=+new Date}function s(t){var r=e.util.createBuffer();if("undefined"!=typeof window&&window.crypto&&window.crypto.getRandomValues){var n=new Uint32Array(t/4);try{window.crypto.getRandomValues(n);for(var i=0;i<n.length;++i)r.putInt32(n[i])}catch(a){}}if(r.length()<t)for(var s,o,u,c=Math.floor(65535*Math.random());r.length()<t;){o=16807*(65535&c),s=16807*(c>>16),o+=(32767&s)<<16,o+=s>>15,o=(2147483647&o)+(o>>31),c=4294967295&o;for(var i=0;3>i;++i)u=c>>>(i<<3),u^=Math.floor(255*Math.random()),r.putByte(String.fromCharCode(255&u))}return r.getBytes()}for(var o={plugin:t,key:null,seed:null,time:null,reseeds:0,generated:0},u=t.md,c=new Array(32),l=0;32>l;++l)c[l]=u.create();return o.pools=c,o.pool=0,o.generate=function(t,r){function i(p){if(p)return r(p);if(l.length()>=t)return r(null,l.getBytes(t));if(o.generated>=1048576){var f=+new Date;(null===o.time||f-o.time>100)&&(o.key=null)}if(null===o.key)return n(i);var d=a(o.key,o.seed);o.generated+=d.length,l.putBytes(d),o.key=u(a(o.key,s(o.seed))),o.seed=c(a(o.key,o.seed)),e.util.setImmediate(i)}if(!r)return o.generateSync(t);var a=o.plugin.cipher,s=o.plugin.increment,u=o.plugin.formatKey,c=o.plugin.formatSeed,l=e.util.createBuffer();i()},o.generateSync=function(t){for(var r=o.plugin.cipher,n=o.plugin.increment,a=o.plugin.formatKey,s=o.plugin.formatSeed,u=e.util.createBuffer();u.length()<t;){if(o.generated>=1048576){var c=+new Date;(null===o.time||c-o.time>100)&&(o.key=null)}null===o.key&&i();var l=r(o.key,o.seed);o.generated+=l.length,u.putBytes(l),o.key=a(r(o.key,n(o.seed))),o.seed=s(r(o.key,o.seed))}return u.getBytes(t)},r?(o.seedFile=function(e,t){r.randomBytes(e,function(e,r){return e?t(e):(t(null,r.toString()),void 0)})},o.seedFileSync=function(e){return r.randomBytes(e).toString()}):(o.seedFile=function(e,t){try{t(null,s(e))}catch(r){t(r)}},o.seedFileSync=s),o.collect=function(e){for(var t=e.length,r=0;t>r;++r)o.pools[o.pool].update(e.substr(r,1)),o.pool=31===o.pool?0:o.pool+1},o.collectInt=function(e,t){for(var r="",n=0;t>n;n+=8)r+=String.fromCharCode(e>>n&255);o.collect(r)},o.registerWorker=function(e){function t(t){var r=t.data;r.forge&&r.forge.prng&&o.seedFile(r.forge.prng.needed,function(t,r){e.postMessage({forge:{prng:{err:t,bytes:r}}})})}e===self?o.seedFile=function(e,t){function r(e){var n=e.data;n.forge&&n.forge.prng&&(self.removeEventListener("message",r),t(n.forge.prng.err,n.forge.prng.bytes))}self.addEventListener("message",r),self.postMessage({forge:{prng:{needed:e}}})}:e.addEventListener("message",t)},o}}var t="prng";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/prng",["require","module","./md","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){e.random&&e.random.getBytes||!function(t){var r={},n=new Array(4),i=e.util.createBuffer();r.formatKey=function(t){var r=e.util.createBuffer(t);return t=new Array(4),t[0]=r.getInt32(),t[1]=r.getInt32(),t[2]=r.getInt32(),t[3]=r.getInt32(),e.aes._expandKey(t,!1)},r.formatSeed=function(t){var r=e.util.createBuffer(t);return t=new Array(4),t[0]=r.getInt32(),t[1]=r.getInt32(),t[2]=r.getInt32(),t[3]=r.getInt32(),t},r.cipher=function(t,r){return e.aes._updateBlock(t,r,n,!1),i.putInt32(n[0]),i.putInt32(n[1]),i.putInt32(n[2]),i.putInt32(n[3]),i.getBytes()},r.increment=function(e){return++e[3],e},r.md=e.md.sha1;var a=e.prng.create(r),s="undefined"!=typeof process&&process.versions&&process.versions.node;if(e.disableNativeCode||!s&&("undefined"==typeof window||!window.crypto||!window.crypto.getRandomValues)){if("undefined"==typeof window||void 0===window.document,a.collectInt(+new Date,32),"undefined"!=typeof navigator){var o="";for(var u in navigator)try{"string"==typeof navigator[u]&&(o+=navigator[u])}catch(c){}a.collect(o),o=null}t&&(t().mousemove(function(e){a.collectInt(e.clientX,16),a.collectInt(e.clientY,16)}),t().keypress(function(e){a.collectInt(e.charCode,8)}))}if(e.random)for(var u in a)e.random[u]=a[u];else e.random=a;e.random.getBytes=function(t,r){return e.random.generate(t,r)},e.random.getBytesSync=function(t){return e.random.generate(t)}}("undefined"!=typeof jQuery?jQuery:null)}var t="random";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/random",["require","module","./aes","./md","./prng","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){function t(e,t,r,n){for(var i=[],a=0;a<e.length;a++)for(var s=0;s<e[a].safeBags.length;s++){var o=e[a].safeBags[s];(void 0===n||o.type===n)&&void 0!==o.attributes[t]&&o.attributes[t].indexOf(r)>=0&&i.push(o)}return i}function r(e,t,r,a){if(t=s.fromDer(t,r),t.tagClass!==s.Class.UNIVERSAL||t.type!==s.Type.SEQUENCE||t.constructed!==!0)throw{message:"PKCS#12 AuthenticatedSafe expected to be a SEQUENCE OF ContentInfo"};for(var u=0;u<t.value.length;u++){var l=t.value[u],p={},f=[];if(!s.validate(l,c,p,f))throw{message:"Cannot read ContentInfo.",errors:f};var d={encrypted:!1},h=null,g=p.content.value[0];switch(s.derToOid(p.contentType)){case o.oids.data:if(g.tagClass!==s.Class.UNIVERSAL||g.type!==s.Type.OCTETSTRING)throw{message:"PKCS#12 SafeContents Data is not an OCTET STRING."};h=g.value;break;case o.oids.encryptedData:if(void 0===a)throw{message:"Found PKCS#12 Encrypted SafeContents Data but no password available."};h=n(g,a),d.encrypted=!0;break;default:throw{message:"Unsupported PKCS#12 contentType.",contentType:s.derToOid(p.contentType)}}d.safeBags=i(h,r,a),e.safeContents.push(d)}}function n(t,r){var n={},i=[];if(!s.validate(t,e.pkcs7.asn1.encryptedDataValidator,n,i))throw{message:"Cannot read EncryptedContentInfo. ",errors:i};var a=s.derToOid(n.contentType);if(a!==o.oids.data)throw{message:"PKCS#12 EncryptedContentInfo ContentType is not Data.",oid:a};a=s.derToOid(n.encAlgorithm);var u=o.pbe.getCipher(a,n.encParameter,r),c=e.util.createBuffer(n.encContent);if(u.update(c),!u.finish())throw{message:"Failed to decrypt PKCS#12 SafeContents."};return u.output.getBytes()}function i(e,t,r){if(e=s.fromDer(e,t),e.tagClass!==s.Class.UNIVERSAL||e.type!==s.Type.SEQUENCE||e.constructed!==!0)throw{message:"PKCS#12 SafeContents expected to be a SEQUENCE OF SafeBag"};for(var n=[],i=0;i<e.value.length;i++){var u=e.value[i],c={},l=[];if(!s.validate(u,p,c,l))throw{message:"Cannot read SafeBag.",errors:l};var f={type:s.derToOid(c.bagId),attributes:a(c.bagAttributes)};n.push(f);var h,g,y=c.bagValue.value[0];switch(f.type){case o.oids.pkcs8ShroudedKeyBag:if(void 0===r)throw{message:"Found PKCS#8 ShroudedKeyBag but no password available."};if(y=o.decryptPrivateKeyInfo(y,r),null===y)throw{message:"Unable to decrypt PKCS#8 ShroudedKeyBag, wrong password?"};case o.oids.keyBag:f.key=o.privateKeyFromAsn1(y);continue;case o.oids.certBag:h=d,g=function(){if(s.derToOid(c.certId)!==o.oids.x509Certificate)throw{message:"Unsupported certificate type, only X.509 supported.",oid:s.derToOid(c.certId)};f.cert=o.certificateFromAsn1(s.fromDer(c.cert,t),!0)};break;default:throw{message:"Unsupported PKCS#12 SafeBag type.",oid:f.type}}if(void 0!==h&&!s.validate(y,h,c,l))throw{message:"Cannot read PKCS#12 "+h.name,errors:l};g()}return n}function a(e){var t={};if(void 0!==e)for(var r=0;r<e.length;++r){var n={},i=[];if(!s.validate(e[r],f,n,i))throw{message:"Cannot read PKCS#12 BagAttribute.",errors:i};var a=s.derToOid(n.oid);if(void 0!==o.oids[a]){t[o.oids[a]]=[];for(var u=0;u<n.values.length;++u)t[o.oids[a]].push(n.values[u].value)}}return t}var s=e.asn1,o=e.pki,u=e.pkcs12=e.pkcs12||{},c={name:"ContentInfo",tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:"ContentInfo.contentType",tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:"contentType"},{name:"ContentInfo.content",tagClass:s.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:"content"}]},l={name:"PFX",tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.version",tagClass:s.Class.UNIVERSAL,type:s.Type.INTEGER,constructed:!1,capture:"version"},c,{name:"PFX.macData",tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,optional:!0,captureAsn1:"mac",value:[{name:"PFX.macData.mac",tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.macData.mac.digestAlgorithm",tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:"PFX.macData.mac.digestAlgorithm.algorithm",tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:"macAlgorithm"},{name:"PFX.macData.mac.digestAlgorithm.parameters",tagClass:s.Class.UNIVERSAL,captureAsn1:"macAlgorithmParameters"}]},{name:"PFX.macData.mac.digest",tagClass:s.Class.UNIVERSAL,type:s.Type.OCTETSTRING,constructed:!1,capture:"macDigest"}]},{name:"PFX.macData.macSalt",tagClass:s.Class.UNIVERSAL,type:s.Type.OCTETSTRING,constructed:!1,capture:"macSalt"},{name:"PFX.macData.iterations",tagClass:s.Class.UNIVERSAL,type:s.Type.INTEGER,constructed:!1,optional:!0,capture:"macIterations"}]}]},p={name:"SafeBag",tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:"SafeBag.bagId",tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:"bagId"},{name:"SafeBag.bagValue",tagClass:s.Class.CONTEXT_SPECIFIC,constructed:!0,captureAsn1:"bagValue"},{name:"SafeBag.bagAttributes",tagClass:s.Class.UNIVERSAL,type:s.Type.SET,constructed:!0,optional:!0,capture:"bagAttributes"}]},f={name:"Attribute",tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:"Attribute.attrId",tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:"oid"},{name:"Attribute.attrValues",tagClass:s.Class.UNIVERSAL,type:s.Type.SET,constructed:!0,capture:"values"}]},d={name:"CertBag",tagClass:s.Class.UNIVERSAL,type:s.Type.SEQUENCE,constructed:!0,value:[{name:"CertBag.certId",tagClass:s.Class.UNIVERSAL,type:s.Type.OID,constructed:!1,capture:"certId"},{name:"CertBag.certValue",tagClass:s.Class.CONTEXT_SPECIFIC,constructed:!0,value:[{name:"CertBag.certValue[0]",tagClass:s.Class.UNIVERSAL,type:s.Class.OCTETSTRING,constructed:!1,capture:"cert"}]}]};u.pkcs12FromAsn1=function(n,i,a){"string"==typeof i?(a=i,i=!0):void 0===i&&(i=!0);var c={},p=[];if(!s.validate(n,l,c,p))throw{message:"Cannot read PKCS#12 PFX. ASN.1 object is not an PKCS#12 PFX.",errors:p};var f={version:c.version.charCodeAt(0),safeContents:[],getBags:function(r){var n,i={};return"localKeyId"in r?n=r.localKeyId:"localKeyIdHex"in r&&(n=e.util.hexToBytes(r.localKeyIdHex)),void 0!==n&&(i.localKeyId=t(f.safeContents,"localKeyId",n,r.bagType)),"friendlyName"in r&&(i.friendlyName=t(f.safeContents,"friendlyName",r.friendlyName,r.bagType)),i},getBagsByFriendlyName:function(e,r){return t(f.safeContents,"friendlyName",e,r)},getBagsByLocalKeyId:function(e,r){return t(f.safeContents,"localKeyId",e,r)}};if(3!==c.version.charCodeAt(0))throw{message:"PKCS#12 PFX of version other than 3 not supported.",version:c.version.charCodeAt(0)};if(s.derToOid(c.contentType)!==o.oids.data)throw{message:"Only PKCS#12 PFX in password integrity mode supported.",oid:s.derToOid(c.contentType)};var d=c.content.value[0];if(d.tagClass!==s.Class.UNIVERSAL||d.type!==s.Type.OCTETSTRING)throw{message:"PKCS#12 authSafe content data is not an OCTET STRING."};if(c.mac){var h=null,g=0,y=s.derToOid(c.macAlgorithm);switch(y){case o.oids.sha1:h=e.md.sha1.create(),g=20;break;case o.oids.sha256:h=e.md.sha256.create(),g=32;break;case o.oids.sha384:h=e.md.sha384.create(),g=48;break;case o.oids.sha512:h=e.md.sha512.create(),g=64;break;case o.oids.md5:h=e.md.md5.create(),g=16}if(null===h)throw{message:"PKCS#12 uses unsupported MAC algorithm: "+y};var m=new e.util.ByteBuffer(c.macSalt),v="macIterations"in c?parseInt(e.util.bytesToHex(c.macIterations),16):1,C=u.generateKey(a||"",m,3,v,g,h),E=e.hmac.create();E.start(h,C),E.update(d.value);var b=E.getMac();if(b.getBytes()!==c.macDigest)throw{message:"PKCS#12 MAC could not be verified. Invalid password?"}}return r(f,d.value,i,a),f},u.toPkcs12Asn1=function(t,r,n,i){i=i||{},i.saltSize=i.saltSize||8,i.count=i.count||2048,i.algorithm=i.algorithm||i.encAlgorithm||"aes128","useMac"in i||(i.useMac=!0),"localKeyId"in i||(i.localKeyId=null),"generateLocalKeyId"in i||(i.generateLocalKeyId=!0);var a=i.localKeyId,c=void 0;if(null!==a)a=e.util.hexToBytes(a);else if(i.generateLocalKeyId)if(r){var l=e.util.isArray(r)?r[0]:r;"string"==typeof l&&(l=o.certificateFromPem(l));var p=e.md.sha1.create();p.update(s.toDer(o.certificateToAsn1(l)).getBytes()),a=p.digest().getBytes()}else a=e.random.getBytes(20);var f=[];null!==a&&f.push(s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(o.oids.localKeyId).getBytes()),s.create(s.Class.UNIVERSAL,s.Type.SET,!0,[s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,a)])])),"friendlyName"in i&&f.push(s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(o.oids.friendlyName).getBytes()),s.create(s.Class.UNIVERSAL,s.Type.SET,!0,[s.create(s.Class.UNIVERSAL,s.Type.BMPSTRING,!1,i.friendlyName)])])),f.length>0&&(c=s.create(s.Class.UNIVERSAL,s.Type.SET,!0,f));var d=[],h=[];null!==r&&(h=e.util.isArray(r)?r:[r]);for(var g=[],y=0;y<h.length;++y){r=h[y],"string"==typeof r&&(r=o.certificateFromPem(r));var m=0===y?c:void 0,v=o.certificateToAsn1(r),C=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(o.oids.certBag).getBytes()),s.create(s.Class.CONTEXT_SPECIFIC,0,!0,[s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(o.oids.x509Certificate).getBytes()),s.create(s.Class.CONTEXT_SPECIFIC,0,!0,[s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,s.toDer(v).getBytes())])])]),m]);g.push(C)}if(g.length>0){var E=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,g),b=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(o.oids.data).getBytes()),s.create(s.Class.CONTEXT_SPECIFIC,0,!0,[s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,s.toDer(E).getBytes())])]);d.push(b)}var T=null;if(null!==t){var S=o.wrapRsaPrivateKey(o.privateKeyToAsn1(t));T=null===n?s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(o.oids.keyBag).getBytes()),s.create(s.Class.CONTEXT_SPECIFIC,0,!0,[S]),c]):s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(o.oids.pkcs8ShroudedKeyBag).getBytes()),s.create(s.Class.CONTEXT_SPECIFIC,0,!0,[o.encryptPrivateKeyInfo(S,n,i)]),c]);var I=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[T]),B=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(o.oids.data).getBytes()),s.create(s.Class.CONTEXT_SPECIFIC,0,!0,[s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,s.toDer(I).getBytes())])]);d.push(B)}var A=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,d),F=void 0;if(i.useMac){var p=e.md.sha1.create(),N=new e.util.ByteBuffer(e.random.getBytes(i.saltSize)),R=i.count,t=u.generateKey(n||"",N,3,R,20),k=e.hmac.create();k.start(p,t),k.update(s.toDer(A).getBytes());var D=k.getMac();F=s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(o.oids.sha1).getBytes()),s.create(s.Class.UNIVERSAL,s.Type.NULL,!1,"")]),s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,D.getBytes())]),s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,N.getBytes()),s.create(s.Class.UNIVERSAL,s.Type.INTEGER,!1,e.util.hexToBytes(R.toString(16)))])}return s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.INTEGER,!1,String.fromCharCode(3)),s.create(s.Class.UNIVERSAL,s.Type.SEQUENCE,!0,[s.create(s.Class.UNIVERSAL,s.Type.OID,!1,s.oidToDer(o.oids.data).getBytes()),s.create(s.Class.CONTEXT_SPECIFIC,0,!0,[s.create(s.Class.UNIVERSAL,s.Type.OCTETSTRING,!1,s.toDer(A).getBytes())])]),F])},u.generateKey=function(t,r,n,i,a,s){var o,u;("undefined"==typeof s||null===s)&&(s=e.md.sha1.create());var c=s.digestLength,l=s.blockLength,p=new e.util.ByteBuffer,f=new e.util.ByteBuffer;for(u=0;u<t.length;u++)f.putInt16(t.charCodeAt(u));f.putInt16(0);var d=f.length(),h=r.length(),g=new e.util.ByteBuffer;g.fillWithByte(n,l);var y=l*Math.ceil(h/l),m=new e.util.ByteBuffer;for(u=0;y>u;u++)m.putByte(r.at(u%h));var v=l*Math.ceil(d/l),C=new e.util.ByteBuffer;for(u=0;v>u;u++)C.putByte(f.at(u%d));var E=m;E.putBuffer(C);for(var b=Math.ceil(a/c),T=1;b>=T;T++){var S=new e.util.ByteBuffer;S.putBytes(g.bytes()),S.putBytes(E.bytes());for(var I=0;i>I;I++)s.start(),s.update(S.getBytes()),S=s.digest();var B=new e.util.ByteBuffer;for(u=0;l>u;u++)B.putByte(S.at(u%c));var A=Math.ceil(h/l)+Math.ceil(d/l),F=new e.util.ByteBuffer;for(o=0;A>o;o++){var N=new e.util.ByteBuffer(E.getBytes(l)),R=511;for(u=B.length()-1;u>=0;u--)R>>=8,R+=B.at(u)+N.at(u),N.setAt(u,255&R);F.putBuffer(N)}E=F,p.putBuffer(S)}return p.truncate(p.length()-a),p}}var t="pkcs12";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)
}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/pkcs12",["require","module","./asn1","./sha1","./pkcs7asn1","./pki","./util","./random","./hmac"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t=e.pss=e.pss||{};t.create=function(t,r,n){var i=t.digestLength,a={};return a.verify=function(a,s,o){var u,c=o-1,l=Math.ceil(c/8);if(s=s.substr(-l),i+n+2>l)throw{message:"Inconsistent parameters to PSS signature verification."};if(188!==s.charCodeAt(l-1))throw{message:"Encoded message does not end in 0xBC."};var p=l-i-1,f=s.substr(0,p),d=s.substr(p,i),h=65280>>8*l-c&255;if(0!==(f.charCodeAt(0)&h))throw{message:"Bits beyond keysize not zero as expected."};var g=r.generate(d,p),y="";for(u=0;p>u;u++)y+=String.fromCharCode(f.charCodeAt(u)^g.charCodeAt(u));y=String.fromCharCode(y.charCodeAt(0)&~h)+y.substr(1);var m=l-i-n-2;for(u=0;m>u;u++)if(0!==y.charCodeAt(u))throw{message:"Leftmost octets not zero as expected"};if(1!==y.charCodeAt(m))throw{message:"Inconsistent PSS signature, 0x01 marker not found"};var v=y.substr(-n),C=new e.util.ByteBuffer;C.fillWithByte(0,8),C.putBytes(a),C.putBytes(v),t.start(),t.update(C.getBytes());var E=t.digest().getBytes();return d===E},a.encode=function(a,s){var o,u=s-1,c=Math.ceil(u/8),l=a.digest().getBytes();if(i+n+2>c)throw{message:"Message is too long to encrypt"};var p=e.random.getBytes(n),f=new e.util.ByteBuffer;f.fillWithByte(0,8),f.putBytes(l),f.putBytes(p),t.start(),t.update(f.getBytes());var d=t.digest().getBytes(),h=new e.util.ByteBuffer;h.fillWithByte(0,c-n-i-2),h.putByte(1),h.putBytes(p);var g=h.getBytes(),y=c-i-1,m=r.generate(d,y),v="";for(o=0;y>o;o++)v+=String.fromCharCode(g.charCodeAt(o)^m.charCodeAt(o));var C=65280>>8*c-u&255;return v=String.fromCharCode(v.charCodeAt(0)&~C)+v.substr(1),v+d+String.fromCharCode(188)},a}}var t="pss";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/pss",["require","module","./random","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t=[217,120,249,196,25,221,181,237,40,233,253,121,74,160,216,157,198,126,55,131,43,118,83,142,98,76,100,136,68,139,251,162,23,154,89,245,135,179,79,19,97,69,109,141,9,129,125,50,189,143,64,235,134,183,123,11,240,149,33,34,92,107,78,130,84,214,101,147,206,96,178,28,115,86,192,20,167,140,241,220,18,117,202,31,59,190,228,209,66,61,212,48,163,60,182,38,111,191,14,218,70,105,7,87,39,242,29,155,188,148,67,3,248,17,199,246,144,239,62,231,6,195,213,47,200,102,30,215,8,232,234,222,128,82,238,247,132,170,114,172,53,77,106,42,150,26,210,113,90,21,73,116,75,159,208,94,4,24,164,236,194,224,65,110,15,81,203,204,36,145,175,80,161,244,112,57,153,124,58,133,35,184,180,122,252,2,54,91,37,85,151,49,45,93,250,152,227,138,146,174,5,223,41,16,103,108,186,201,211,0,230,207,225,158,168,44,99,22,1,63,88,226,137,169,13,56,52,27,171,51,255,176,187,72,12,95,185,177,205,46,197,243,219,71,229,165,156,119,10,166,32,104,254,127,193,173],r=[1,2,3,5],n=function(e,t){return e<<t&65535|(65535&e)>>16-t},i=function(e,t){return(65535&e)>>t|e<<16-t&65535};e.rc2=e.rc2||{},e.rc2.expandKey=function(r,n){"string"==typeof r&&(r=e.util.createBuffer(r)),n=n||128;var i,a=r,s=r.length(),o=n,u=Math.ceil(o/8),c=255>>(7&o);for(i=s;128>i;i++)a.putByte(t[a.at(i-1)+a.at(i-s)&255]);for(a.setAt(128-u,t[a.at(128-u)&c]),i=127-u;i>=0;i--)a.setAt(i,t[a.at(i+1)^a.at(i+u)]);return a};var a=function(t,a,s){var o,u,c,l,p=!1,f=null,d=null,h=null,g=[];for(t=e.rc2.expandKey(t,a),c=0;64>c;c++)g.push(t.getInt16Le());s?(o=function(e){for(c=0;4>c;c++)e[c]+=g[l]+(e[(c+3)%4]&e[(c+2)%4])+(~e[(c+3)%4]&e[(c+1)%4]),e[c]=n(e[c],r[c]),l++},u=function(e){for(c=0;4>c;c++)e[c]+=g[63&e[(c+3)%4]]}):(o=function(e){for(c=3;c>=0;c--)e[c]=i(e[c],r[c]),e[c]-=g[l]+(e[(c+3)%4]&e[(c+2)%4])+(~e[(c+3)%4]&e[(c+1)%4]),l--},u=function(e){for(c=3;c>=0;c--)e[c]-=g[63&e[(c+3)%4]]});var y=function(e){var t=[];for(c=0;4>c;c++){var r=f.getInt16Le();null!==h&&(s?r^=h.getInt16Le():h.putInt16Le(r)),t.push(65535&r)}l=s?0:63;for(var n=0;n<e.length;n++)for(var i=0;i<e[n][0];i++)e[n][1](t);for(c=0;4>c;c++)null!==h&&(s?h.putInt16Le(t[c]):t[c]^=h.getInt16Le()),d.putInt16Le(t[c])},m=null;return m={start:function(r,n){r&&"string"==typeof t&&8===r.length&&(r=e.util.createBuffer(r)),p=!1,f=e.util.createBuffer(),d=n||new e.util.createBuffer,h=r,m.output=d},update:function(e){for(p||f.putBuffer(e);f.length()>=8;)y([[5,o],[1,u],[6,o],[1,u],[5,o]])},finish:function(e){var t=!0;if(s)if(e)t=e(8,f,!s);else{var r=8===f.length()?8:8-f.length();f.fillWithByte(r,r)}if(t&&(p=!0,m.update()),!s&&(t=0===f.length()))if(e)t=e(8,d,!s);else{var n=d.length(),i=d.at(n-1);i>n?t=!1:d.truncate(i)}return t}}};e.rc2.startEncrypting=function(t,r,n){var i=e.rc2.createEncryptionCipher(t,128);return i.start(r,n),i},e.rc2.createEncryptionCipher=function(e,t){return a(e,t,!0)},e.rc2.startDecrypting=function(t,r,n){var i=e.rc2.createDecryptionCipher(t,128);return i.start(r,n),i},e.rc2.createDecryptionCipher=function(e,t){return a(e,t,!1)}}var t="rc2";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/rc2",["require","module","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){function t(e,t,r){for(var n="",i=Math.ceil(t/r.digestLength),a=0;i>a;++a){var s=String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,255&a);r.start(),r.update(e+s),n+=r.digest().getBytes()}return n.substring(0,t)}var r=e.pkcs1=e.pkcs1||{};r.encode_rsa_oaep=function(r,n,i){var a=void 0,s=void 0,o=void 0;"string"==typeof i?(a=i,s=arguments[3]||void 0,o=arguments[4]||void 0):i&&(a=i.label||void 0,s=i.seed||void 0,o=i.md||void 0),o?o.start():o=e.md.sha1.create();var u=Math.ceil(r.n.bitLength()/8),c=u-2*o.digestLength-2;if(n.length>c)throw{message:"RSAES-OAEP input message length is too long.",length:n.length,maxLength:c};a||(a=""),o.update(a,"raw");for(var l=o.digest(),p="",f=c-n.length,d=0;f>d;d++)p+="\x00";var h=l.getBytes()+p+""+n;if(s){if(s.length!==o.digestLength)throw{message:"Invalid RSAES-OAEP seed. The seed length must match the digest length.",seedLength:s.length,digestLength:o.digestLength}}else s=e.random.getBytes(o.digestLength);var g=t(s,u-o.digestLength-1,o),y=e.util.xorBytes(h,g,h.length),m=t(y,o.digestLength,o),v=e.util.xorBytes(s,m,s.length);return"\x00"+v+y},r.decode_rsa_oaep=function(r,n,i){var a=void 0,s=void 0;"string"==typeof i?(a=i,s=arguments[3]||void 0):i&&(a=i.label||void 0,s=i.md||void 0);var o=Math.ceil(r.n.bitLength()/8);if(n.length!==o)throw{message:"RSAES-OAEP encoded message length is invalid.",length:n.length,expectedLength:o};if(void 0===s?s=e.md.sha1.create():s.start(),o<2*s.digestLength+2)throw{message:"RSAES-OAEP key is too short for the hash function."};a||(a=""),s.update(a,"raw");for(var u=s.digest().getBytes(),c=n.charAt(0),l=n.substring(1,s.digestLength+1),p=n.substring(1+s.digestLength),f=t(p,s.digestLength,s),d=e.util.xorBytes(l,f,l.length),h=t(d,o-s.digestLength-1,s),g=e.util.xorBytes(p,h,p.length),y=g.substring(0,s.digestLength),m="\x00"!==c,v=0;v<s.digestLength;++v)m|=u.charAt(v)!==y.charAt(v);for(var C=1,E=s.digestLength,b=s.digestLength;b<g.length;b++){var T=g.charCodeAt(b),S=1&T^1,I=C?65534:0;m|=T&I,C&=S,E+=C}if(m||1!==g.charCodeAt(E))throw{message:"Invalid RSAES-OAEP padding."};return g.substring(E+1)}}var t="pkcs1";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/pkcs1",["require","module","./util","./random","./sha1"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){function t(t,r,n){var i=e.util.createBuffer(),a=Math.ceil(r.n.bitLength()/8);if(t.length>a-11)throw{message:"Message is too long for PKCS#1 v1.5 padding.",length:t.length,max:a-11};i.putByte(0),i.putByte(n);var s,o=a-3-t.length;if(0===n||1===n){s=0===n?0:255;for(var u=0;o>u;++u)i.putByte(s)}else for(var u=0;o>u;++u)s=Math.floor(255*Math.random())+1,i.putByte(s);return i.putByte(0),i.putBytes(t),i}function r(t,r,n,i){var a=Math.ceil(r.n.bitLength()/8),s=e.util.createBuffer(t),o=s.getByte(),u=s.getByte();if(0!==o||n&&0!==u&&1!==u||!n&&2!=u||n&&0===u&&"undefined"==typeof i)throw{message:"Encryption block is invalid."};var c=0;if(0===u){c=a-3-i;for(var l=0;c>l;++l)if(0!==s.getByte())throw{message:"Encryption block is invalid."}}else if(1===u)for(c=0;s.length()>1;){if(255!==s.getByte()){--s.read;break}++c}else if(2===u)for(c=0;s.length()>1;){if(0===s.getByte()){--s.read;break}++c}var p=s.getByte();if(0!==p||c!==a-3-s.length())throw{message:"Encryption block is invalid."};return s.getBytes()}function n(t,r,n){function i(){a(t.pBits,function(e,r){return e?n(e):(t.p=r,a(t.qBits,s),void 0)})}function a(e,r){function n(){var r=e-1,n=new BigInteger(e,t.rng);return n.testBit(r)||n.bitwiseTo(BigInteger.ONE.shiftLeft(r),d,n),n.dAddOffset(31-n.mod(f).byteValue(),0),n}function i(i){if(!g){--o;var s=i.data;if(s.found){for(var u=0;u<a.length;++u)a[u].terminate();return g=!0,r(null,new BigInteger(s.prime,16))}h.bitLength()>e&&(h=n());var p=h.toString(16);i.target.postMessage({e:t.eInt,hex:p,workLoad:c}),h.dAddOffset(l,0)}}for(var a=[],s=0;u>s;++s)a[s]=new Worker(p);for(var o=u,h=n(),s=0;u>s;++s)a[s].addEventListener("message",i);var g=!1}function s(r,o){if(t.q=o,t.p.compareTo(t.q)<0){var u=t.p;t.p=t.q,t.q=u}if(t.p1=t.p.subtract(BigInteger.ONE),t.q1=t.q.subtract(BigInteger.ONE),t.phi=t.p1.multiply(t.q1),0!==t.phi.gcd(t.e).compareTo(BigInteger.ONE))return t.p=t.q=null,i(),void 0;if(t.n=t.p.multiply(t.q),t.n.bitLength()!==t.bits)return t.q=null,a(t.qBits,s),void 0;var c=t.e.modInverse(t.phi);t.keys={privateKey:e.pki.rsa.setPrivateKey(t.n,t.e,c,t.p,t.q,c.mod(t.p1),c.mod(t.q1),t.q.modInverse(t.p)),publicKey:e.pki.rsa.setPublicKey(t.n,t.e)},n(null,t.keys)}function o(){return e.pki.rsa.stepKeyPairGenerationState(t,10)?n(null,t.keys):(e.util.setImmediate(o),void 0)}if("function"==typeof r&&(n=r,r={}),"undefined"==typeof Worker)return o();var u=r.workers||2,c=r.workLoad||100,l=30*c/8,p=r.workerScript||"forge/prime.worker.js",f=new BigInteger(null);f.fromInt(30);var d=function(e,t){return e|t};i()}"undefined"==typeof BigInteger&&(BigInteger=e.jsbn.BigInteger);var i=e.asn1;e.pki=e.pki||{},e.pki.rsa=e.rsa=e.rsa||{};var a=e.pki,s=[6,4,2,4,2,4,6,2],o=function(t){var r;if(t.algorithm in e.pki.oids){r=e.pki.oids[t.algorithm];var n=i.oidToDer(r).getBytes(),a=i.create(i.Class.UNIVERSAL,i.Type.SEQUENCE,!0,[]),s=i.create(i.Class.UNIVERSAL,i.Type.SEQUENCE,!0,[]);s.value.push(i.create(i.Class.UNIVERSAL,i.Type.OID,!1,n)),s.value.push(i.create(i.Class.UNIVERSAL,i.Type.NULL,!1,""));var o=i.create(i.Class.UNIVERSAL,i.Type.OCTETSTRING,!1,t.digest().getBytes());return a.value.push(s),a.value.push(o),i.toDer(a).getBytes()}throw{message:"Unknown message digest algorithm.",algorithm:t.algorithm}},u=function(e,t,r){var n;if(r)n=e.modPow(t.e,t.n);else{t.dP||(t.dP=t.d.mod(t.p.subtract(BigInteger.ONE))),t.dQ||(t.dQ=t.d.mod(t.q.subtract(BigInteger.ONE))),t.qInv||(t.qInv=t.q.modInverse(t.p));for(var i=e.mod(t.p).modPow(t.dP,t.p),a=e.mod(t.q).modPow(t.dQ,t.q);i.compareTo(a)<0;)i=i.add(t.p);n=i.subtract(a).multiply(t.qInv).mod(t.p).multiply(t.q).add(a)}return n};a.rsa.encrypt=function(r,n,i){var a,s=i,o=Math.ceil(n.n.bitLength()/8);i!==!1&&i!==!0?(s=2===i,a=t(r,n,i)):(a=e.util.createBuffer(),a.putBytes(r));for(var c=new BigInteger(a.toHex(),16),l=u(c,n,s),p=l.toString(16),f=e.util.createBuffer(),d=o-Math.ceil(p.length/2);d>0;)f.putByte(0),--d;return f.putBytes(e.util.hexToBytes(p)),f.getBytes()},a.rsa.decrypt=function(t,n,i,a){var s=Math.ceil(n.n.bitLength()/8);if(t.length!==s)throw{message:"Encrypted message length is invalid.",length:t.length,expected:s};var o=new BigInteger(e.util.createBuffer(t).toHex(),16);if(o.compareTo(n.n)>=0)throw{message:"Encrypted message is invalid."};for(var c=u(o,n,i),l=c.toString(16),p=e.util.createBuffer(),f=s-Math.ceil(l.length/2);f>0;)p.putByte(0),--f;return p.putBytes(e.util.hexToBytes(l)),a!==!1?r(p.getBytes(),n,i):p.getBytes()},a.rsa.createKeyPairGenerationState=function(t,r){"string"==typeof t&&(t=parseInt(t,10)),t=t||1024;var n={nextBytes:function(t){for(var r=e.random.getBytes(t.length),n=0;n<t.length;++n)t[n]=r.charCodeAt(n)}},i={state:0,bits:t,rng:n,eInt:r||65537,e:new BigInteger(null),p:null,q:null,qBits:t>>1,pBits:t-(t>>1),pqState:0,num:null,keys:null};return i.e.fromInt(i.eInt),i},a.rsa.stepKeyPairGenerationState=function(t,r){var n=new BigInteger(null);n.fromInt(30);for(var i,a=0,o=function(e,t){return e|t},u=+new Date,c=0;null===t.keys&&(0>=r||r>c);){if(0===t.state){var l=null===t.p?t.pBits:t.qBits,p=l-1;0===t.pqState?(t.num=new BigInteger(l,t.rng),t.num.testBit(p)||t.num.bitwiseTo(BigInteger.ONE.shiftLeft(p),o,t.num),t.num.dAddOffset(31-t.num.mod(n).byteValue(),0),a=0,++t.pqState):1===t.pqState?t.num.bitLength()>l?t.pqState=0:t.num.isProbablePrime(1)?++t.pqState:t.num.dAddOffset(s[a++%8],0):2===t.pqState?t.pqState=0===t.num.subtract(BigInteger.ONE).gcd(t.e).compareTo(BigInteger.ONE)?3:0:3===t.pqState&&(t.pqState=0,t.num.isProbablePrime(10)&&(null===t.p?t.p=t.num:t.q=t.num,null!==t.p&&null!==t.q&&++t.state),t.num=null)}else if(1===t.state)t.p.compareTo(t.q)<0&&(t.num=t.p,t.p=t.q,t.q=t.num),++t.state;else if(2===t.state)t.p1=t.p.subtract(BigInteger.ONE),t.q1=t.q.subtract(BigInteger.ONE),t.phi=t.p1.multiply(t.q1),++t.state;else if(3===t.state)0===t.phi.gcd(t.e).compareTo(BigInteger.ONE)?++t.state:(t.p=null,t.q=null,t.state=0);else if(4===t.state)t.n=t.p.multiply(t.q),t.n.bitLength()===t.bits?++t.state:(t.q=null,t.state=0);else if(5===t.state){var f=t.e.modInverse(t.phi);t.keys={privateKey:e.pki.rsa.setPrivateKey(t.n,t.e,f,t.p,t.q,f.mod(t.p1),f.mod(t.q1),t.q.modInverse(t.p)),publicKey:e.pki.rsa.setPublicKey(t.n,t.e)}}i=+new Date,c+=i-u,u=i}return null!==t.keys},a.rsa.generateKeyPair=function(e,t,r,i){1===arguments.length?"object"==typeof e?(r=e,e=void 0):"function"==typeof e&&(i=e,e=void 0):2===arguments.length?("number"==typeof e?"function"==typeof t?i=t:r=t:(r=e,i=t,e=void 0),t=void 0):3===arguments.length&&("number"==typeof t?"function"==typeof r&&(i=r,r=void 0):(i=r,r=t,t=void 0)),r=r||{},void 0===e&&(e=r.bits||1024),void 0===t&&(t=r.e||65537);var s=a.rsa.createKeyPairGenerationState(e,t);return i?(n(s,r,i),void 0):(a.rsa.stepKeyPairGenerationState(s,0),s.keys)},a.rsa.setPublicKey=function(n,s){var o={n:n,e:s};return o.encrypt=function(r,n,i){if("string"==typeof n?n=n.toUpperCase():void 0===n&&(n="RSAES-PKCS1-V1_5"),"RSAES-PKCS1-V1_5"===n)n={encode:function(e,r){return t(e,r,2).getBytes()}};else if("RSA-OAEP"===n||"RSAES-OAEP"===n)n={encode:function(t,r){return e.pkcs1.encode_rsa_oaep(r,t,i)}};else{if(-1===["RAW","NONE","NULL",null].indexOf(n))throw{message:'Unsupported encryption scheme: "'+n+'".'};n={encode:function(e){return e}}}var s=n.encode(r,o,!0);return a.rsa.encrypt(s,o,!0)},o.verify=function(e,t,n){"string"==typeof n?n=n.toUpperCase():void 0===n&&(n="RSASSA-PKCS1-V1_5"),"RSASSA-PKCS1-V1_5"===n?n={verify:function(e,t){t=r(t,o,!0);var n=i.fromDer(t);return e===n.value[1].value}}:("NONE"===n||"NULL"===n||null===n)&&(n={verify:function(e,t){return t=r(t,o,!0),e===t}});var s=a.rsa.decrypt(t,o,!0,!1);return n.verify(e,s,o.n.bitLength())},o},a.rsa.setPrivateKey=function(t,n,i,s,u,c,l,p){var f={n:t,e:n,d:i,p:s,q:u,dP:c,dQ:l,qInv:p};return f.decrypt=function(t,n,i){"string"==typeof n?n=n.toUpperCase():void 0===n&&(n="RSAES-PKCS1-V1_5");var s=a.rsa.decrypt(t,f,!1,!1);if("RSAES-PKCS1-V1_5"===n)n={decode:r};else if("RSA-OAEP"===n||"RSAES-OAEP"===n)n={decode:function(t,r){return e.pkcs1.decode_rsa_oaep(r,t,i)}};else{if(-1===["RAW","NONE","NULL",null].indexOf(n))throw{message:'Unsupported encryption scheme: "'+n+'".'};n={decode:function(e){return e}}}return n.decode(s,f,!1)},f.sign=function(e,t){var r=!1;"string"==typeof t&&(t=t.toUpperCase()),void 0===t||"RSASSA-PKCS1-V1_5"===t?(t={encode:o},r=1):("NONE"===t||"NULL"===t||null===t)&&(t={encode:function(){return e}},r=1);var n=t.encode(e,f.n.bitLength());return a.rsa.encrypt(n,f,r)},f}}var t="rsa";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/rsa",["require","module","./asn1","./oids","./random","./util","./jsbn","./pkcs1"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){function t(t){for(var r,n,i=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[]),a=t.attributes,s=0;s<a.length;++s){r=a[s];var u=r.value,c=o.Type.PRINTABLESTRING;"valueTagClass"in r&&(c=r.valueTagClass,c===o.Type.UTF8&&(u=e.util.encodeUtf8(u))),n=o.create(o.Class.UNIVERSAL,o.Type.SET,!0,[o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(r.type).getBytes()),o.create(o.Class.UNIVERSAL,c,!1,u)])]),i.value.push(n)}return i}function r(e){var t=o.create(o.Class.CONTEXT_SPECIFIC,3,!0,[]),r=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[]);t.value.push(r);for(var n,i,a=0;a<e.length;++a){n=e[a],i=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[]),r.value.push(i),i.value.push(o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(n.id).getBytes())),n.critical&&i.value.push(o.create(o.Class.UNIVERSAL,o.Type.BOOLEAN,!1,String.fromCharCode(255)));var s=n.value;"string"!=typeof n.value&&(s=o.toDer(s).getBytes()),i.value.push(o.create(o.Class.UNIVERSAL,o.Type.OCTETSTRING,!1,s))}return t}function n(e,t){switch(e){case c["RSASSA-PSS"]:var r=[];return void 0!==t.hash.algorithmOid&&r.push(o.create(o.Class.CONTEXT_SPECIFIC,0,!0,[o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(t.hash.algorithmOid).getBytes()),o.create(o.Class.UNIVERSAL,o.Type.NULL,!1,"")])])),void 0!==t.mgf.algorithmOid&&r.push(o.create(o.Class.CONTEXT_SPECIFIC,1,!0,[o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(t.mgf.algorithmOid).getBytes()),o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(t.mgf.hash.algorithmOid).getBytes()),o.create(o.Class.UNIVERSAL,o.Type.NULL,!1,"")])])])),void 0!==t.saltLength&&r.push(o.create(o.Class.CONTEXT_SPECIFIC,2,!0,[o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,String.fromCharCode(t.saltLength))])),o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,r);default:return o.create(o.Class.UNIVERSAL,o.Type.NULL,!1,"")}}function i(t){var r=o.create(o.Class.CONTEXT_SPECIFIC,0,!0,[]);if(0===t.attributes.length)return r;for(var n=t.attributes,i=0;i<n.length;++i){var a=n[i],s=a.value,u=o.Type.UTF8;"valueTagClass"in a&&(u=a.valueTagClass),u===o.Type.UTF8&&(s=e.util.encodeUtf8(s));var c=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(a.type).getBytes()),o.create(o.Class.UNIVERSAL,o.Type.SET,!0,[o.create(o.Class.UNIVERSAL,u,!1,s)])]);r.value.push(c)}return r}function a(e,t,r){for(var n=[s(e+t)],i=16,a=1;r>i;++a,i+=16)n.push(s(n[a-1]+e+t));return n.join("").substr(0,r)}function s(t){return e.md.md5.create().update(t).digest().getBytes()}"undefined"==typeof BigInteger&&(BigInteger=e.jsbn.BigInteger);var o=e.asn1,u=e.pki=e.pki||{},c=u.oids;u.pbe={};var l={};l.CN=c.commonName,l.commonName="CN",l.C=c.countryName,l.countryName="C",l.L=c.localityName,l.localityName="L",l.ST=c.stateOrProvinceName,l.stateOrProvinceName="ST",l.O=c.organizationName,l.organizationName="O",l.OU=c.organizationalUnitName,l.organizationalUnitName="OU",l.E=c.emailAddress,l.emailAddress="E";var p={name:"SubjectPublicKeyInfo",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,captureAsn1:"subjectPublicKeyInfo",value:[{name:"SubjectPublicKeyInfo.AlgorithmIdentifier",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1,capture:"publicKeyOid"}]},{name:"SubjectPublicKeyInfo.subjectPublicKey",tagClass:o.Class.UNIVERSAL,type:o.Type.BITSTRING,constructed:!1,value:[{name:"SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,optional:!0,captureAsn1:"rsaPublicKey"}]}]},f={name:"RSAPublicKey",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPublicKey.modulus",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"publicKeyModulus"},{name:"RSAPublicKey.exponent",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"publicKeyExponent"}]},d={name:"Certificate",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,captureAsn1:"tbsCertificate",value:[{name:"Certificate.TBSCertificate.version",tagClass:o.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.version.integer",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"certVersion"}]},{name:"Certificate.TBSCertificate.serialNumber",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"certSerialNumber"},{name:"Certificate.TBSCertificate.signature",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate.signature.algorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1,capture:"certinfoSignatureOid"},{name:"Certificate.TBSCertificate.signature.parameters",tagClass:o.Class.UNIVERSAL,optional:!0,captureAsn1:"certinfoSignatureParams"}]},{name:"Certificate.TBSCertificate.issuer",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,captureAsn1:"certIssuer"},{name:"Certificate.TBSCertificate.validity",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate.validity.notBefore (utc)",tagClass:o.Class.UNIVERSAL,type:o.Type.UTCTIME,constructed:!1,optional:!0,capture:"certValidity1UTCTime"},{name:"Certificate.TBSCertificate.validity.notBefore (generalized)",tagClass:o.Class.UNIVERSAL,type:o.Type.GENERALIZEDTIME,constructed:!1,optional:!0,capture:"certValidity2GeneralizedTime"},{name:"Certificate.TBSCertificate.validity.notAfter (utc)",tagClass:o.Class.UNIVERSAL,type:o.Type.UTCTIME,constructed:!1,optional:!0,capture:"certValidity3UTCTime"},{name:"Certificate.TBSCertificate.validity.notAfter (generalized)",tagClass:o.Class.UNIVERSAL,type:o.Type.GENERALIZEDTIME,constructed:!1,optional:!0,capture:"certValidity4GeneralizedTime"}]},{name:"Certificate.TBSCertificate.subject",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,captureAsn1:"certSubject"},p,{name:"Certificate.TBSCertificate.issuerUniqueID",tagClass:o.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.issuerUniqueID.id",tagClass:o.Class.UNIVERSAL,type:o.Type.BITSTRING,constructed:!1,capture:"certIssuerUniqueId"}]},{name:"Certificate.TBSCertificate.subjectUniqueID",tagClass:o.Class.CONTEXT_SPECIFIC,type:2,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.subjectUniqueID.id",tagClass:o.Class.UNIVERSAL,type:o.Type.BITSTRING,constructed:!1,capture:"certSubjectUniqueId"}]},{name:"Certificate.TBSCertificate.extensions",tagClass:o.Class.CONTEXT_SPECIFIC,type:3,constructed:!0,captureAsn1:"certExtensions",optional:!0}]},{name:"Certificate.signatureAlgorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.signatureAlgorithm.algorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1,capture:"certSignatureOid"},{name:"Certificate.TBSCertificate.signature.parameters",tagClass:o.Class.UNIVERSAL,optional:!0,captureAsn1:"certSignatureParams"}]},{name:"Certificate.signatureValue",tagClass:o.Class.UNIVERSAL,type:o.Type.BITSTRING,constructed:!1,capture:"certSignature"}]},h={name:"PrivateKeyInfo",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"PrivateKeyInfo.version",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"PrivateKeyInfo.privateKeyAlgorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1,capture:"privateKeyOid"}]},{name:"PrivateKeyInfo",tagClass:o.Class.UNIVERSAL,type:o.Type.OCTETSTRING,constructed:!1,capture:"privateKey"}]},g={name:"RSAPrivateKey",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPrivateKey.version",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"RSAPrivateKey.modulus",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"privateKeyModulus"},{name:"RSAPrivateKey.publicExponent",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"privateKeyPublicExponent"},{name:"RSAPrivateKey.privateExponent",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"privateKeyPrivateExponent"},{name:"RSAPrivateKey.prime1",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"privateKeyPrime1"},{name:"RSAPrivateKey.prime2",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"privateKeyPrime2"},{name:"RSAPrivateKey.exponent1",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"privateKeyExponent1"},{name:"RSAPrivateKey.exponent2",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"privateKeyExponent2"},{name:"RSAPrivateKey.coefficient",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"privateKeyCoefficient"}]},y={name:"EncryptedPrivateKeyInfo",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedPrivateKeyInfo.encryptionAlgorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1,capture:"encryptionOid"},{name:"AlgorithmIdentifier.parameters",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,captureAsn1:"encryptionParams"}]},{name:"EncryptedPrivateKeyInfo.encryptedData",tagClass:o.Class.UNIVERSAL,type:o.Type.OCTETSTRING,constructed:!1,capture:"encryptedData"}]},m={name:"PBES2Algorithms",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc.oid",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1,capture:"kdfOid"},{name:"PBES2Algorithms.params",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.params.salt",tagClass:o.Class.UNIVERSAL,type:o.Type.OCTETSTRING,constructed:!1,capture:"kdfSalt"},{name:"PBES2Algorithms.params.iterationCount",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,onstructed:!0,capture:"kdfIterationCount"}]}]},{name:"PBES2Algorithms.encryptionScheme",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.encryptionScheme.oid",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1,capture:"encOid"},{name:"PBES2Algorithms.encryptionScheme.iv",tagClass:o.Class.UNIVERSAL,type:o.Type.OCTETSTRING,constructed:!1,capture:"encIv"}]}]},v={name:"pkcs-12PbeParams",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"pkcs-12PbeParams.salt",tagClass:o.Class.UNIVERSAL,type:o.Type.OCTETSTRING,constructed:!1,capture:"salt"},{name:"pkcs-12PbeParams.iterations",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"iterations"}]},C={name:"rsapss",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"rsapss.hashAlgorithm",tagClass:o.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,value:[{name:"rsapss.hashAlgorithm.AlgorithmIdentifier",tagClass:o.Class.UNIVERSAL,type:o.Class.SEQUENCE,constructed:!0,optional:!0,value:[{name:"rsapss.hashAlgorithm.AlgorithmIdentifier.algorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1,capture:"hashOid"}]}]},{name:"rsapss.maskGenAlgorithm",tagClass:o.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier",tagClass:o.Class.UNIVERSAL,type:o.Class.SEQUENCE,constructed:!0,optional:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.algorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1,capture:"maskGenOid"},{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.params",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.params.algorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1,capture:"maskGenHashOid"}]}]}]},{name:"rsapss.saltLength",tagClass:o.Class.CONTEXT_SPECIFIC,type:2,optional:!0,value:[{name:"rsapss.saltLength.saltLength",tagClass:o.Class.UNIVERSAL,type:o.Class.INTEGER,constructed:!1,capture:"saltLength"}]},{name:"rsapss.trailerField",tagClass:o.Class.CONTEXT_SPECIFIC,type:3,optional:!0,value:[{name:"rsapss.trailer.trailer",tagClass:o.Class.UNIVERSAL,type:o.Class.INTEGER,constructed:!1,capture:"trailer"}]}]},E={name:"CertificationRequestInfo",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,captureAsn1:"certificationRequestInfo",value:[{name:"CertificationRequestInfo.integer",tagClass:o.Class.UNIVERSAL,type:o.Type.INTEGER,constructed:!1,capture:"certificationRequestInfoVersion"},{name:"CertificationRequestInfo.subject",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,captureAsn1:"certificationRequestInfoSubject"},p,{name:"CertificationRequestInfo.attributes",tagClass:o.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,capture:"certificationRequestInfoAttributes",value:[{name:"CertificationRequestInfo.attributes",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"CertificationRequestInfo.attributes.type",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1},{name:"CertificationRequestInfo.attributes.value",tagClass:o.Class.UNIVERSAL,type:o.Type.SET,constructed:!0}]}]}]},b={name:"CertificationRequest",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,captureAsn1:"csr",value:[E,{name:"CertificationRequest.signatureAlgorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.SEQUENCE,constructed:!0,value:[{name:"CertificationRequest.signatureAlgorithm.algorithm",tagClass:o.Class.UNIVERSAL,type:o.Type.OID,constructed:!1,capture:"csrSignatureOid"},{name:"CertificationRequest.signatureAlgorithm.parameters",tagClass:o.Class.UNIVERSAL,optional:!0,captureAsn1:"csrSignatureParams"}]},{name:"CertificationRequest.signature",tagClass:o.Class.UNIVERSAL,type:o.Type.BITSTRING,constructed:!1,capture:"csrSignature"}]};
u.RDNAttributesAsArray=function(e,t){for(var r,n,i,a=[],s=0;s<e.value.length;++s){r=e.value[s];for(var u=0;u<r.value.length;++u)i={},n=r.value[u],i.type=o.derToOid(n.value[0].value),i.value=n.value[1].value,i.valueTagClass=n.value[1].type,i.type in c&&(i.name=c[i.type],i.name in l&&(i.shortName=l[i.name])),t&&(t.update(i.type),t.update(i.value)),a.push(i)}return a},u.CRIAttributesAsArray=function(e){for(var t=[],r=0;r<e.length;++r)for(var n=e[r],i=o.derToOid(n.value[0].value),a=n.value[1].value,s=0;s<a.length;++s){var u={};u.type=i,u.value=a[s].value,u.valueTagClass=a[s].type,u.type in c&&(u.name=c[u.type],u.name in l&&(u.shortName=l[u.name])),t.push(u)}return t};var T=function(e,t){"string"==typeof t&&(t={shortName:t});for(var r,n=null,i=0;null===n&&i<e.attributes.length;++i)r=e.attributes[i],t.type&&t.type===r.type?n=r:t.name&&t.name===r.name?n=r:t.shortName&&t.shortName===r.shortName&&(n=r);return n},S=function(t){for(var r,n,i,a=[],s=0;s<t.value.length;++s){i=t.value[s];for(var u=0;u<i.value.length;++u){if(n=i.value[u],r={},r.id=o.derToOid(n.value[0].value),r.critical=!1,n.value[1].type===o.Type.BOOLEAN?(r.critical=0!==n.value[1].value.charCodeAt(0),r.value=n.value[2].value):r.value=n.value[1].value,r.id in c)if(r.name=c[r.id],"keyUsage"===r.name){var l=o.fromDer(r.value),p=0,f=0;l.value.length>1&&(p=l.value.charCodeAt(1),f=l.value.length>2?l.value.charCodeAt(2):0),r.digitalSignature=128===(128&p),r.nonRepudiation=64===(64&p),r.keyEncipherment=32===(32&p),r.dataEncipherment=16===(16&p),r.keyAgreement=8===(8&p),r.keyCertSign=4===(4&p),r.cRLSign=2===(2&p),r.encipherOnly=1===(1&p),r.decipherOnly=128===(128&f)}else if("basicConstraints"===r.name){var l=o.fromDer(r.value);if(r.cA=l.value.length>0?0!==l.value[0].value.charCodeAt(0):!1,l.value.length>1){var d=e.util.createBuffer(l.value[1].value);r.pathLenConstraint=d.getInt(d.length()<<3)}}else if("extKeyUsage"===r.name)for(var l=o.fromDer(r.value),h=0;h<l.value.length;++h){var g=o.derToOid(l.value[h].value);g in c?r[c[g]]=!0:r[g]=!0}else if("nsCertType"===r.name){var l=o.fromDer(r.value),p=0;l.value.length>1&&(p=l.value.charCodeAt(1)),r.client=128===(128&p),r.server=64===(64&p),r.email=32===(32&p),r.objsign=16===(16&p),r.reserved=8===(8&p),r.sslCA=4===(4&p),r.emailCA=2===(2&p),r.objCA=1===(1&p)}else if("subjectAltName"===r.name||"issuerAltName"===r.name){r.altNames=[];for(var y,l=o.fromDer(r.value),m=0;m<l.value.length;++m){y=l.value[m];var v={type:y.type,value:y.value};switch(r.altNames.push(v),y.type){case 1:case 2:case 6:break;case 7:break;case 8:v.oid=o.derToOid(y.value)}}}else if("subjectKeyIdentifier"===r.name){var l=o.fromDer(r.value);r.subjectKeyIdentifier=e.util.bytesToHex(l.value)}a.push(r)}}return a};u.pemToDer=function(t){var r=e.pem.decode(t)[0];if(r.procType&&"ENCRYPTED"===r.procType.type)throw{message:"Could not convert PEM to DER; PEM is encrypted."};return e.util.createBuffer(r.body)};var I=function(t){var r=t.toString(16);return r[0]>="8"&&(r="00"+r),e.util.hexToBytes(r)},B=function(e,t,r){var n={};if(e!==c["RSASSA-PSS"])return n;r&&(n={hash:{algorithmOid:c.sha1},mgf:{algorithmOid:c.mgf1,hash:{algorithmOid:c.sha1}},saltLength:20});var i={},a=[];if(!o.validate(t,C,i,a))throw{message:"Cannot read RSASSA-PSS parameter block.",errors:a};return void 0!==i.hashOid&&(n.hash=n.hash||{},n.hash.algorithmOid=o.derToOid(i.hashOid)),void 0!==i.maskGenOid&&(n.mgf=n.mgf||{},n.mgf.algorithmOid=o.derToOid(i.maskGenOid),n.mgf.hash=n.mgf.hash||{},n.mgf.hash.algorithmOid=o.derToOid(i.maskGenHashOid)),void 0!==i.saltLength&&(n.saltLength=i.saltLength.charCodeAt(0)),n};u.certificateFromPem=function(t,r,n){var i=e.pem.decode(t)[0];if("CERTIFICATE"!==i.type&&"X509 CERTIFICATE"!==i.type&&"TRUSTED CERTIFICATE"!==i.type)throw{message:'Could not convert certificate from PEM; PEM header type is not "CERTIFICATE", "X509 CERTIFICATE", or "TRUSTED CERTIFICATE".',headerType:i.type};if(i.procType&&"ENCRYPTED"===i.procType.type)throw{message:"Could not convert certificate from PEM; PEM is encrypted."};var a=o.fromDer(i.body,n);return u.certificateFromAsn1(a,r)},u.certificateToPem=function(t,r){var n={type:"CERTIFICATE",body:o.toDer(u.certificateToAsn1(t)).getBytes()};return e.pem.encode(n,{maxline:r})},u.publicKeyFromPem=function(t){var r=e.pem.decode(t)[0];if("PUBLIC KEY"!==r.type&&"RSA PUBLIC KEY"!==r.type)throw{message:'Could not convert public key from PEM; PEM header type is not "PUBLIC KEY" or "RSA PUBLIC KEY".',headerType:r.type};if(r.procType&&"ENCRYPTED"===r.procType.type)throw{message:"Could not convert public key from PEM; PEM is encrypted."};var n=o.fromDer(r.body);return u.publicKeyFromAsn1(n)},u.publicKeyToPem=function(t,r){var n={type:"PUBLIC KEY",body:o.toDer(u.publicKeyToAsn1(t)).getBytes()};return e.pem.encode(n,{maxline:r})},u.publicKeyToRSAPublicKeyPem=function(t,r){var n={type:"RSA PUBLIC KEY",body:o.toDer(u.publicKeyToRSAPublicKey(t)).getBytes()};return e.pem.encode(n,{maxline:r})},u.privateKeyFromPem=function(t){var r=e.pem.decode(t)[0];if("PRIVATE KEY"!==r.type&&"RSA PRIVATE KEY"!==r.type)throw{message:'Could not convert private key from PEM; PEM header type is not "PRIVATE KEY" or "RSA PRIVATE KEY".',headerType:r.type};if(r.procType&&"ENCRYPTED"===r.procType.type)throw{message:"Could not convert private key from PEM; PEM is encrypted."};var n=o.fromDer(r.body);return u.privateKeyFromAsn1(n)},u.privateKeyToPem=function(t,r){var n={type:"RSA PRIVATE KEY",body:o.toDer(u.privateKeyToAsn1(t)).getBytes()};return e.pem.encode(n,{maxline:r})},u.certificationRequestFromPem=function(t,r,n){var i=e.pem.decode(t)[0];if("CERTIFICATE REQUEST"!==i.type)throw{message:'Could not convert certification request from PEM; PEM header type is not "CERTIFICATE REQUEST".',headerType:i.type};if(i.procType&&"ENCRYPTED"===i.procType.type)throw{message:"Could not convert certification request from PEM; PEM is encrypted."};var a=o.fromDer(i.body,n);return u.certificationRequestFromAsn1(a,r)},u.certificationRequestToPem=function(t,r){var n={type:"CERTIFICATE REQUEST",body:o.toDer(u.certificationRequestToAsn1(t)).getBytes()};return e.pem.encode(n,{maxline:r})},u.createCertificate=function(){var t={};t.version=2,t.serialNumber="00",t.signatureOid=null,t.signature=null,t.siginfo={},t.siginfo.algorithmOid=null,t.validity={},t.validity.notBefore=new Date,t.validity.notAfter=new Date,t.issuer={},t.issuer.getField=function(e){return T(t.issuer,e)},t.issuer.addField=function(e){r([e]),t.issuer.attributes.push(e)},t.issuer.attributes=[],t.issuer.hash=null,t.subject={},t.subject.getField=function(e){return T(t.subject,e)},t.subject.addField=function(e){r([e]),t.subject.attributes.push(e)},t.subject.attributes=[],t.subject.hash=null,t.extensions=[],t.publicKey=null,t.md=null;var r=function(e){for(var t,r=0;r<e.length;++r){if(t=e[r],"undefined"==typeof t.name&&(t.type&&t.type in u.oids?t.name=u.oids[t.type]:t.shortName&&t.shortName in l&&(t.name=u.oids[l[t.shortName]])),"undefined"==typeof t.type){if(!(t.name&&t.name in u.oids))throw{message:"Attribute type not specified.",attribute:t};t.type=u.oids[t.name]}if("undefined"==typeof t.shortName&&t.name&&t.name in l&&(t.shortName=l[t.name]),"undefined"==typeof t.value)throw{message:"Attribute value not specified.",attribute:t}}};return t.setSubject=function(e,n){r(e),t.subject.attributes=e,delete t.subject.uniqueId,n&&(t.subject.uniqueId=n),t.subject.hash=null},t.setIssuer=function(e,n){r(e),t.issuer.attributes=e,delete t.issuer.uniqueId,n&&(t.issuer.uniqueId=n),t.issuer.hash=null},t.setExtensions=function(r){for(var n,i=0;i<r.length;++i){if(n=r[i],"undefined"==typeof n.name&&n.id&&n.id in u.oids&&(n.name=u.oids[n.id]),"undefined"==typeof n.id){if(!(n.name&&n.name in u.oids))throw{message:"Extension ID not specified.",extension:n};n.id=u.oids[n.name]}if("undefined"==typeof n.value){if("keyUsage"===n.name){var a=0,s=0,l=0;n.digitalSignature&&(s|=128,a=7),n.nonRepudiation&&(s|=64,a=6),n.keyEncipherment&&(s|=32,a=5),n.dataEncipherment&&(s|=16,a=4),n.keyAgreement&&(s|=8,a=3),n.keyCertSign&&(s|=4,a=2),n.cRLSign&&(s|=2,a=1),n.encipherOnly&&(s|=1,a=0),n.decipherOnly&&(l|=128,a=7);var p=String.fromCharCode(a);0!==l?p+=String.fromCharCode(s)+String.fromCharCode(l):0!==s&&(p+=String.fromCharCode(s)),n.value=o.create(o.Class.UNIVERSAL,o.Type.BITSTRING,!1,p)}else if("basicConstraints"===n.name){if(n.value=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[]),n.cA&&n.value.value.push(o.create(o.Class.UNIVERSAL,o.Type.BOOLEAN,!1,String.fromCharCode(255))),n.pathLenConstraint){var f=n.pathLenConstraint,d=e.util.createBuffer();d.putInt(f,f.toString(2).length),n.value.value.push(o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,d.getBytes()))}}else if("extKeyUsage"===n.name){n.value=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[]);var h=n.value.value;for(var g in n)n[g]===!0&&(g in c?h.push(o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(c[g]).getBytes())):-1!==g.indexOf(".")&&h.push(o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(g).getBytes())))}else if("nsCertType"===n.name){var a=0,s=0;n.client&&(s|=128,a=7),n.server&&(s|=64,a=6),n.email&&(s|=32,a=5),n.objsign&&(s|=16,a=4),n.reserved&&(s|=8,a=3),n.sslCA&&(s|=4,a=2),n.emailCA&&(s|=2,a=1),n.objCA&&(s|=1,a=0);var p=String.fromCharCode(a);0!==s&&(p+=String.fromCharCode(s)),n.value=o.create(o.Class.UNIVERSAL,o.Type.BITSTRING,!1,p)}else if("subjectAltName"===n.name||"issuerAltName"===n.name){n.value=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[]);for(var y,m=0;m<n.altNames.length;++m){y=n.altNames[m];var p=y.value;8===y.type&&(p=o.oidToDer(p)),n.value.value.push(o.create(o.Class.CONTEXT_SPECIFIC,y.type,!1,p))}}else if("subjectKeyIdentifier"===n.name){var v=t.generateSubjectKeyIdentifier();n.subjectKeyIdentifier=v.toHex(),n.value=o.create(o.Class.UNIVERSAL,o.Type.OCTETSTRING,!1,v.getBytes())}if("undefined"==typeof n.value)throw{message:"Extension value not specified.",extension:n}}}t.extensions=r},t.getExtension=function(e){"string"==typeof e&&(e={name:e});for(var r,n=null,i=0;null===n&&i<t.extensions.length;++i)r=t.extensions[i],e.id&&r.id===e.id?n=r:e.name&&r.name===e.name&&(n=r);return n},t.sign=function(r,n){t.md=n||e.md.sha1.create();var i=c[t.md.algorithm+"WithRSAEncryption"];if(!i)throw{message:"Could not compute certificate digest. Unknown message digest algorithm OID.",algorithm:t.md.algorithm};t.signatureOid=t.siginfo.algorithmOid=i,t.tbsCertificate=u.getTBSCertificate(t);var a=o.toDer(t.tbsCertificate);t.md.update(a.getBytes()),t.signature=r.sign(t.md)},t.verify=function(r){var n=!1,i=r.md;if(null===i){if(r.signatureOid in c){var a=c[r.signatureOid];switch(a){case"sha1WithRSAEncryption":i=e.md.sha1.create();break;case"md5WithRSAEncryption":i=e.md.md5.create();break;case"sha256WithRSAEncryption":i=e.md.sha256.create();break;case"RSASSA-PSS":i=e.md.sha256.create()}}if(null===i)throw{message:"Could not compute certificate digest. Unknown signature OID.",signatureOid:r.signatureOid};var s=r.tbsCertificate||u.getTBSCertificate(r),l=o.toDer(s);i.update(l.getBytes())}if(null!==i){var p=void 0;switch(r.signatureOid){case c.sha1WithRSAEncryption:p=void 0;break;case c["RSASSA-PSS"]:var f,d;if(f=c[r.signatureParameters.mgf.hash.algorithmOid],void 0===f||void 0===e.md[f])throw{message:"Unsupported MGF hash function.",oid:r.signatureParameters.mgf.hash.algorithmOid,name:f};if(d=c[r.signatureParameters.mgf.algorithmOid],void 0===d||void 0===e.mgf[d])throw{message:"Unsupported MGF function.",oid:r.signatureParameters.mgf.algorithmOid,name:d};if(d=e.mgf[d].create(e.md[f].create()),f=c[r.signatureParameters.hash.algorithmOid],void 0===f||void 0===e.md[f])throw{message:"Unsupported RSASSA-PSS hash function.",oid:r.signatureParameters.hash.algorithmOid,name:f};p=e.pss.create(e.md[f].create(),d,r.signatureParameters.saltLength)}n=t.publicKey.verify(i.digest().getBytes(),r.signature,p)}return n},t.isIssuer=function(e){var r=!1,n=t.issuer,i=e.subject;if(n.hash&&i.hash)r=n.hash===i.hash;else if(n.attributes.length===i.attributes.length){r=!0;for(var a,s,o=0;r&&o<n.attributes.length;++o)a=n.attributes[o],s=i.attributes[o],(a.type!==s.type||a.value!==s.value)&&(r=!1)}return r},t.generateSubjectKeyIdentifier=function(){var r=o.toDer(u.publicKeyToRSAPublicKey(t.publicKey)),n=e.md.sha1.create();return n.update(r.getBytes()),n.digest()},t.verifySubjectKeyIdentifier=function(){for(var r=c.subjectKeyIdentifier,n=0;n<t.extensions.length;++n){var i=t.extensions[n];if(i.id===r){var a=t.generateSubjectKeyIdentifier().getBytes();return e.util.hexToBytes(i.subjectKeyIdentifier)===a}}return!1},t},u.certificateFromAsn1=function(t,r){var n={},i=[];if(!o.validate(t,d,n,i))throw{message:"Cannot read X.509 certificate. ASN.1 object is not an X509v3 Certificate.",errors:i};if("string"!=typeof n.certSignature){for(var a="\x00",s=0;s<n.certSignature.length;++s)a+=o.toDer(n.certSignature[s]).getBytes();n.certSignature=a}var l=o.derToOid(n.publicKeyOid);if(l!==u.oids.rsaEncryption)throw{message:"Cannot read public key. OID is not RSA."};var p=u.createCertificate();p.version=n.certVersion?n.certVersion.charCodeAt(0):0;var f=e.util.createBuffer(n.certSerialNumber);p.serialNumber=f.toHex(),p.signatureOid=e.asn1.derToOid(n.certSignatureOid),p.signatureParameters=B(p.signatureOid,n.certSignatureParams,!0),p.siginfo.algorithmOid=e.asn1.derToOid(n.certinfoSignatureOid),p.siginfo.parameters=B(p.siginfo.algorithmOid,n.certinfoSignatureParams,!1);var h=e.util.createBuffer(n.certSignature);++h.read,p.signature=h.getBytes();var g=[];if(void 0!==n.certValidity1UTCTime&&g.push(o.utcTimeToDate(n.certValidity1UTCTime)),void 0!==n.certValidity2GeneralizedTime&&g.push(o.generalizedTimeToDate(n.certValidity2GeneralizedTime)),void 0!==n.certValidity3UTCTime&&g.push(o.utcTimeToDate(n.certValidity3UTCTime)),void 0!==n.certValidity4GeneralizedTime&&g.push(o.generalizedTimeToDate(n.certValidity4GeneralizedTime)),g.length>2)throw{message:"Cannot read notBefore/notAfter validity times; more than two times were provided in the certificate."};if(g.length<2)throw{message:"Cannot read notBefore/notAfter validity times; they were not provided as either UTCTime or GeneralizedTime."};if(p.validity.notBefore=g[0],p.validity.notAfter=g[1],p.tbsCertificate=n.tbsCertificate,r){if(p.md=null,p.signatureOid in c){var l=c[p.signatureOid];switch(l){case"sha1WithRSAEncryption":p.md=e.md.sha1.create();break;case"md5WithRSAEncryption":p.md=e.md.md5.create();break;case"sha256WithRSAEncryption":p.md=e.md.sha256.create();break;case"RSASSA-PSS":p.md=e.md.sha256.create()}}if(null===p.md)throw{message:"Could not compute certificate digest. Unknown signature OID.",signatureOid:p.signatureOid};var y=o.toDer(p.tbsCertificate);p.md.update(y.getBytes())}var m=e.md.sha1.create();p.issuer.getField=function(e){return T(p.issuer,e)},p.issuer.addField=function(e){_fillMissingFields([e]),p.issuer.attributes.push(e)},p.issuer.attributes=u.RDNAttributesAsArray(n.certIssuer,m),n.certIssuerUniqueId&&(p.issuer.uniqueId=n.certIssuerUniqueId),p.issuer.hash=m.digest().toHex();var v=e.md.sha1.create();return p.subject.getField=function(e){return T(p.subject,e)},p.subject.addField=function(e){_fillMissingFields([e]),p.subject.attributes.push(e)},p.subject.attributes=u.RDNAttributesAsArray(n.certSubject,v),n.certSubjectUniqueId&&(p.subject.uniqueId=n.certSubjectUniqueId),p.subject.hash=v.digest().toHex(),p.extensions=n.certExtensions?S(n.certExtensions):[],p.publicKey=u.publicKeyFromAsn1(n.subjectPublicKeyInfo),p},u.certificationRequestFromAsn1=function(t,r){var n={},i=[];if(!o.validate(t,b,n,i))throw{message:"Cannot read PKCS#10 certificate request. ASN.1 object is not a PKCS#10 CertificationRequest.",errors:i};if("string"!=typeof n.csrSignature){for(var a="\x00",s=0;s<n.csrSignature.length;++s)a+=o.toDer(n.csrSignature[s]).getBytes();n.csrSignature=a}var l=o.derToOid(n.publicKeyOid);if(l!==u.oids.rsaEncryption)throw{message:"Cannot read public key. OID is not RSA."};var p=u.createCertificationRequest();p.version=n.csrVersion?n.csrVersion.charCodeAt(0):0,p.signatureOid=e.asn1.derToOid(n.csrSignatureOid),p.signatureParameters=B(p.signatureOid,n.csrSignatureParams,!0),p.siginfo.algorithmOid=e.asn1.derToOid(n.csrSignatureOid),p.siginfo.parameters=B(p.siginfo.algorithmOid,n.csrSignatureParams,!1);var f=e.util.createBuffer(n.csrSignature);if(++f.read,p.signature=f.getBytes(),p.certificationRequestInfo=n.certificationRequestInfo,r){if(p.md=null,p.signatureOid in c){var l=c[p.signatureOid];switch(l){case"sha1WithRSAEncryption":p.md=e.md.sha1.create();break;case"md5WithRSAEncryption":p.md=e.md.md5.create();break;case"sha256WithRSAEncryption":p.md=e.md.sha256.create();break;case"RSASSA-PSS":p.md=e.md.sha256.create()}}if(null===p.md)throw{message:"Could not compute certification request digest. Unknown signature OID.",signatureOid:p.signatureOid};var d=o.toDer(p.certificationRequestInfo);p.md.update(d.getBytes())}var h=e.md.sha1.create();return p.subject.getField=function(e){return T(p.subject,e)},p.subject.addField=function(e){_fillMissingFields([e]),p.subject.attributes.push(e)},p.subject.attributes=u.RDNAttributesAsArray(n.certificationRequestInfoSubject,h),p.subject.hash=h.digest().toHex(),p.publicKey=u.publicKeyFromAsn1(n.subjectPublicKeyInfo),p.getAttribute=function(e){return T(p.attributes,e)},p.addAttribute=function(e){_fillMissingFields([e]),p.attributes.push(e)},p.attributes=u.CRIAttributesAsArray(n.certificationRequestInfoAttributes),p},u.createCertificationRequest=function(){var t={};t.version=0,t.signatureOid=null,t.signature=null,t.siginfo={},t.siginfo.algorithmOid=null,t.subject={},t.subject.getField=function(e){return T(t.subject,e)},t.subject.addField=function(e){r([e]),t.subject.attributes.push(e)},t.subject.attributes=[],t.subject.hash=null,t.publicKey=null,t.attributes=[],t.getAttribute=function(e){return T(t.attributes,e)},t.addAttribute=function(e){r([e]),t.attributes.push(e)},t.md=null;var r=function(e){for(var t,r=0;r<e.length;++r){if(t=e[r],"undefined"==typeof t.name&&(t.type&&t.type in u.oids?t.name=u.oids[t.type]:t.shortName&&t.shortName in l&&(t.name=u.oids[l[t.shortName]])),"undefined"==typeof t.type){if(!(t.name&&t.name in u.oids))throw{message:"Attribute type not specified.",attribute:t};t.type=u.oids[t.name]}if("undefined"==typeof t.shortName&&t.name&&t.name in l&&(t.shortName=l[t.name]),"undefined"==typeof t.value)throw{message:"Attribute value not specified.",attribute:t}}};return t.setSubject=function(e){r(e),t.subject.attributes=e,t.subject.hash=null},t.setAttributes=function(e){r(e),t.attributes=e},t.sign=function(r,n){t.md=n||e.md.sha1.create();var i=c[t.md.algorithm+"WithRSAEncryption"];if(!i)throw{message:"Could not compute certification request digest. Unknown message digest algorithm OID.",algorithm:t.md.algorithm};t.signatureOid=t.siginfo.algorithmOid=i,t.certificationRequestInfo=u.getCertificationRequestInfo(t);var a=o.toDer(t.certificationRequestInfo);t.md.update(a.getBytes()),t.signature=r.sign(t.md)},t.verify=function(){var r=!1,n=t.md;if(null===n){if(t.signatureOid in c){var i=c[t.signatureOid];switch(i){case"sha1WithRSAEncryption":n=e.md.sha1.create();break;case"md5WithRSAEncryption":n=e.md.md5.create();break;case"sha256WithRSAEncryption":n=e.md.sha256.create();break;case"RSASSA-PSS":n=e.md.sha256.create()}}if(null===n)throw{message:"Could not compute certification request digest. Unknown signature OID.",signatureOid:t.signatureOid};var a=t.certificationRequestInfo||u.getCertificationRequestInfo(t),s=o.toDer(a);n.update(s.getBytes())}if(null!==n){var l=void 0;switch(t.signatureOid){case c.sha1WithRSAEncryption:l=void 0;break;case c["RSASSA-PSS"]:var p,f;if(p=c[t.signatureParameters.mgf.hash.algorithmOid],void 0===p||void 0===e.md[p])throw{message:"Unsupported MGF hash function.",oid:t.signatureParameters.mgf.hash.algorithmOid,name:p};if(f=c[t.signatureParameters.mgf.algorithmOid],void 0===f||void 0===e.mgf[f])throw{message:"Unsupported MGF function.",oid:t.signatureParameters.mgf.algorithmOid,name:f};if(f=e.mgf[f].create(e.md[p].create()),p=c[t.signatureParameters.hash.algorithmOid],void 0===p||void 0===e.md[p])throw{message:"Unsupported RSASSA-PSS hash function.",oid:t.signatureParameters.hash.algorithmOid,name:p};l=e.pss.create(e.md[p].create(),f,t.signatureParameters.saltLength)}r=t.publicKey.verify(n.digest().getBytes(),t.signature,l)}return r},t},u.getTBSCertificate=function(i){var a=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.CONTEXT_SPECIFIC,0,!0,[o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,String.fromCharCode(i.version))]),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,e.util.hexToBytes(i.serialNumber)),o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(i.siginfo.algorithmOid).getBytes()),n(i.siginfo.algorithmOid,i.siginfo.parameters)]),t(i.issuer),o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.UTCTIME,!1,o.dateToUtcTime(i.validity.notBefore)),o.create(o.Class.UNIVERSAL,o.Type.UTCTIME,!1,o.dateToUtcTime(i.validity.notAfter))]),t(i.subject),u.publicKeyToAsn1(i.publicKey)]);return i.issuer.uniqueId&&a.value.push(o.create(o.Class.CONTEXT_SPECIFIC,1,!0,[o.create(o.Class.UNIVERSAL,o.Type.BITSTRING,!1,String.fromCharCode(0)+i.issuer.uniqueId)])),i.subject.uniqueId&&a.value.push(o.create(o.Class.CONTEXT_SPECIFIC,2,!0,[o.create(o.Class.UNIVERSAL,o.Type.BITSTRING,!1,String.fromCharCode(0)+i.subject.uniqueId)])),i.extensions.length>0&&a.value.push(r(i.extensions)),a},u.getCertificationRequestInfo=function(e){var r=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,String.fromCharCode(e.version)),t(e.subject),u.publicKeyToAsn1(e.publicKey),i(e)]);return r},u.distinguishedNameToAsn1=function(e){return t(e)},u.certificateToAsn1=function(e){var t=e.tbsCertificate||u.getTBSCertificate(e);return o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[t,o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(e.signatureOid).getBytes()),n(e.signatureOid,e.signatureParameters)]),o.create(o.Class.UNIVERSAL,o.Type.BITSTRING,!1,String.fromCharCode(0)+e.signature)])},u.certificationRequestToAsn1=function(e){var t=e.certificationRequestInfo||u.getCertificationRequestInfo(e);return o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[t,o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(e.signatureOid).getBytes()),n(e.signatureOid,e.signatureParameters)]),o.create(o.Class.UNIVERSAL,o.Type.BITSTRING,!1,String.fromCharCode(0)+e.signature)])},u.createCaStore=function(r){var n={certs:{}};if(n.getIssuer=function(r){var i=null;if(!r.issuer.hash){var a=e.md.sha1.create();r.issuer.attributes=u.RDNAttributesAsArray(t(r.issuer),a),r.issuer.hash=a.digest().toHex()}if(r.issuer.hash in n.certs&&(i=n.certs[r.issuer.hash],e.util.isArray(i)))throw{message:"Resolving multiple issuer matches not implemented yet."};return i},n.addCertificate=function(r){if("string"==typeof r&&(r=e.pki.certificateFromPem(r)),!r.subject.hash){var i=e.md.sha1.create();r.subject.attributes=u.RDNAttributesAsArray(t(r.subject),i),r.subject.hash=i.digest().toHex()}if(r.subject.hash in n.certs){var a=n.certs[r.subject.hash];e.util.isArray(a)||(a=[a]),a.push(r)}else n.certs[r.subject.hash]=r},r)for(var i=0;i<r.length;++i){var a=r[i];n.addCertificate(a)}return n},u.certificateError={bad_certificate:"forge.pki.BadCertificate",unsupported_certificate:"forge.pki.UnsupportedCertificate",certificate_revoked:"forge.pki.CertificateRevoked",certificate_expired:"forge.pki.CertificateExpired",certificate_unknown:"forge.pki.CertificateUnknown",unknown_ca:"forge.pki.UnknownCertificateAuthority"},u.verifyCertificateChain=function(t,r,n){r=r.slice(0);var i=r.slice(0),a=new Date,s=!0,o=null,c=0,l=null;do{var p=r.shift();if(a<p.validity.notBefore||a>p.validity.notAfter)o={message:"Certificate is not valid yet or has expired.",error:u.certificateError.certificate_expired,notBefore:p.validity.notBefore,notAfter:p.validity.notAfter,now:a};else{var f=!1;if(r.length>0){l=r[0];try{f=l.verify(p)}catch(d){}}else{var h=t.getIssuer(p);if(null===h)o={message:"Certificate is not trusted.",error:u.certificateError.unknown_ca};else for(e.util.isArray(h)||(h=[h]);!f&&h.length>0;){l=h.shift();try{f=l.verify(p)}catch(d){}}}null===o&&!f&&(o={message:"Certificate signature is invalid.",error:u.certificateError.bad_certificate})}if(null===o&&!p.isIssuer(l)&&(o={message:"Certificate issuer is invalid.",error:u.certificateError.bad_certificate}),null===o)for(var g={keyUsage:!0,basicConstraints:!0},y=0;null===o&&y<p.extensions.length;++y){var m=p.extensions[y];m.critical&&!(m.name in g)&&(o={message:"Certificate has an unsupported critical extension.",error:u.certificateError.unsupported_certificate})}if(!s||0===r.length&&!l){var v=p.getExtension("basicConstraints"),C=p.getExtension("keyUsage");null!==C&&(!C.keyCertSign||null===v)&&(o={message:"Certificate keyUsage or basicConstraints conflict or indicate that the certificate is not a CA. If the certificate is the only one in the chain or isn't the first then the certificate must be a valid CA.",error:u.certificateError.bad_certificate}),null===o&&null!==v&&!v.cA&&(o={message:"Certificate basicConstraints indicates the certificate is not a CA.",error:u.certificateError.bad_certificate})}var E=null===o?!0:o.error,b=n?n(E,c,i):E;if(b!==!0)throw E===!0&&(o={message:"The application rejected the certificate.",error:u.certificateError.bad_certificate}),(b||0===b)&&("object"!=typeof b||e.util.isArray(b)?"string"==typeof b&&(o.error=b):(b.message&&(o.message=b.message),b.error&&(o.error=b.error))),o;o=null,s=!1,++c}while(r.length>0);return!0},u.publicKeyFromAsn1=function(t){var r={},n=[];if(o.validate(t,p,r,n)){var i=o.derToOid(r.publicKeyOid);if(i!==u.oids.rsaEncryption)throw{message:"Cannot read public key. Unknown OID.",oid:i};t=r.rsaPublicKey}if(n=[],!o.validate(t,f,r,n))throw{message:"Cannot read public key. ASN.1 object does not contain an RSAPublicKey.",errors:n};var a=e.util.createBuffer(r.publicKeyModulus).toHex(),s=e.util.createBuffer(r.publicKeyExponent).toHex();return u.setRsaPublicKey(new BigInteger(a,16),new BigInteger(s,16))},u.publicKeyToAsn1=u.publicKeyToSubjectPublicKeyInfo=function(e){return o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(u.oids.rsaEncryption).getBytes()),o.create(o.Class.UNIVERSAL,o.Type.NULL,!1,"")]),o.create(o.Class.UNIVERSAL,o.Type.BITSTRING,!1,[u.publicKeyToRSAPublicKey(e)])])},u.publicKeyToRSAPublicKey=function(e){return o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,I(e.n)),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,I(e.e))])},u.privateKeyFromAsn1=function(t){var r={},n=[];if(o.validate(t,h,r,n)&&(t=o.fromDer(e.util.createBuffer(r.privateKey))),r={},n=[],!o.validate(t,g,r,n))throw{message:"Cannot read private key. ASN.1 object does not contain an RSAPrivateKey.",errors:n};var i,a,s,c,l,p,f,d;return i=e.util.createBuffer(r.privateKeyModulus).toHex(),a=e.util.createBuffer(r.privateKeyPublicExponent).toHex(),s=e.util.createBuffer(r.privateKeyPrivateExponent).toHex(),c=e.util.createBuffer(r.privateKeyPrime1).toHex(),l=e.util.createBuffer(r.privateKeyPrime2).toHex(),p=e.util.createBuffer(r.privateKeyExponent1).toHex(),f=e.util.createBuffer(r.privateKeyExponent2).toHex(),d=e.util.createBuffer(r.privateKeyCoefficient).toHex(),u.setRsaPrivateKey(new BigInteger(i,16),new BigInteger(a,16),new BigInteger(s,16),new BigInteger(c,16),new BigInteger(l,16),new BigInteger(p,16),new BigInteger(f,16),new BigInteger(d,16))},u.privateKeyToAsn1=u.privateKeyToRSAPrivateKey=function(e){return o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,String.fromCharCode(0)),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,I(e.n)),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,I(e.e)),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,I(e.d)),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,I(e.p)),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,I(e.q)),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,I(e.dP)),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,I(e.dQ)),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,I(e.qInv))])},u.wrapRsaPrivateKey=function(e){return o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,"\x00"),o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(c.rsaEncryption).getBytes()),o.create(o.Class.UNIVERSAL,o.Type.NULL,!1,"")]),o.create(o.Class.UNIVERSAL,o.Type.OCTETSTRING,!1,o.toDer(e).getBytes())])},u.encryptPrivateKeyInfo=function(t,r,n){n=n||{},n.saltSize=n.saltSize||8,n.count=n.count||2048,n.algorithm=n.algorithm||"aes128";var i=e.random.getBytes(n.saltSize),a=n.count,s=e.util.createBuffer();s.putInt16(a);var u,l,p;if(0===n.algorithm.indexOf("aes")){var f;if("aes128"===n.algorithm)u=16,f=c["aes128-CBC"];else if("aes192"===n.algorithm)u=24,f=c["aes192-CBC"];else{if("aes256"!==n.algorithm)throw{message:"Cannot encrypt private key. Unknown encryption algorithm.",algorithm:n.algorithm};u=32,f=c["aes256-CBC"]}var d=e.pkcs5.pbkdf2(r,i,a,u),h=e.random.getBytes(16),g=e.aes.createEncryptionCipher(d);g.start(h),g.update(o.toDer(t)),g.finish(),p=g.output.getBytes(),l=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(c.pkcs5PBES2).getBytes()),o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(c.pkcs5PBKDF2).getBytes()),o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OCTETSTRING,!1,i),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,s.getBytes())])]),o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(f).getBytes()),o.create(o.Class.UNIVERSAL,o.Type.OCTETSTRING,!1,h)])])])}else{if("3des"!==n.algorithm)throw{message:"Cannot encrypt private key. Unknown encryption algorithm.",algorithm:n.algorithm};u=24;var y=new e.util.ByteBuffer(i),d=e.pkcs12.generateKey(r,y,1,a,u),h=e.pkcs12.generateKey(r,y,2,a,u),g=e.des.createEncryptionCipher(d);g.start(h),g.update(o.toDer(t)),g.finish(),p=g.output.getBytes(),l=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OID,!1,o.oidToDer(c["pbeWithSHAAnd3-KeyTripleDES-CBC"]).getBytes()),o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[o.create(o.Class.UNIVERSAL,o.Type.OCTETSTRING,!1,i),o.create(o.Class.UNIVERSAL,o.Type.INTEGER,!1,s.getBytes())])])}var m=o.create(o.Class.UNIVERSAL,o.Type.SEQUENCE,!0,[l,o.create(o.Class.UNIVERSAL,o.Type.OCTETSTRING,!1,p)]);return m},u.pbe.getCipherForPBES2=function(t,r,n){var i={},a=[];if(!o.validate(r,m,i,a))throw{message:"Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.",errors:a};if(t=o.derToOid(i.kdfOid),t!==u.oids.pkcs5PBKDF2)throw{message:"Cannot read encrypted private key. Unsupported key derivation function OID.",oid:t,supportedOids:["pkcs5PBKDF2"]};if(t=o.derToOid(i.encOid),t!==u.oids["aes128-CBC"]&&t!==u.oids["aes192-CBC"]&&t!==u.oids["aes256-CBC"])throw{message:"Cannot read encrypted private key. Unsupported encryption scheme OID.",oid:t,supportedOids:["aes128-CBC","aes192-CBC","aes256-CBC"]};var s=i.kdfSalt,c=e.util.createBuffer(i.kdfIterationCount);c=c.getInt(c.length()<<3);var l;t===u.oids["aes128-CBC"]?l=16:t===u.oids["aes192-CBC"]?l=24:t===u.oids["aes256-CBC"]&&(l=32);var p=e.pkcs5.pbkdf2(n,s,c,l),f=i.encIv,d=e.aes.createDecryptionCipher(p);return d.start(f),d},u.pbe.getCipherForPKCS12PBE=function(t,r,n){var i={},a=[];if(!o.validate(r,v,i,a))throw{message:"Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.",errors:a};var s=e.util.createBuffer(i.salt),c=e.util.createBuffer(i.iterations);c=c.getInt(c.length()<<3);var l,p,f;switch(t){case u.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:l=24,p=8,f=e.des.startDecrypting;
break;case u.oids["pbewithSHAAnd40BitRC2-CBC"]:l=5,p=8,f=function(t,r){var n=e.rc2.createDecryptionCipher(t,40);return n.start(r,null),n};break;default:throw{message:"Cannot read PKCS #12 PBE data block. Unsupported OID.",oid:t}}var d=e.pkcs12.generateKey(n,s,1,c,l),h=e.pkcs12.generateKey(n,s,2,c,p);return f(d,h)},u.pbe.getCipher=function(e,t,r){switch(e){case u.oids.pkcs5PBES2:return u.pbe.getCipherForPBES2(e,t,r);case u.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:case u.oids["pbewithSHAAnd40BitRC2-CBC"]:return u.pbe.getCipherForPKCS12PBE(e,t,r);default:throw{message:"Cannot read encrypted PBE data block. Unsupported OID.",oid:e,supportedOids:["pkcs5PBES2","pbeWithSHAAnd3-KeyTripleDES-CBC","pbewithSHAAnd40BitRC2-CBC"]}}},u.decryptPrivateKeyInfo=function(t,r){var n=null,i={},a=[];if(!o.validate(t,y,i,a))throw{message:"Cannot read encrypted private key. ASN.1 object is not a supported EncryptedPrivateKeyInfo.",errors:a};var s=o.derToOid(i.encryptionOid),c=u.pbe.getCipher(s,i.encryptionParams,r),l=e.util.createBuffer(i.encryptedData);return c.update(l),c.finish()&&(n=o.fromDer(c.output)),n},u.encryptedPrivateKeyToPem=function(t,r){var n={type:"ENCRYPTED PRIVATE KEY",body:o.toDer(t).getBytes()};return e.pem.encode(n,{maxline:r})},u.encryptedPrivateKeyFromPem=function(t){var r=e.pem.decode(t)[0];if("ENCRYPTED PRIVATE KEY"!==r.type)throw{message:'Could not convert encrypted private key from PEM; PEM header type is "ENCRYPTED PRIVATE KEY".',headerType:r.type};if(r.procType&&"ENCRYPTED"===r.procType.type)throw{message:"Could not convert encrypted private key from PEM; PEM is encrypted."};return o.fromDer(r.body)},u.encryptRsaPrivateKey=function(t,r,n){if(n=n||{},!n.legacy){var i=u.wrapRsaPrivateKey(u.privateKeyToAsn1(t));return i=u.encryptPrivateKeyInfo(i,r,n),u.encryptedPrivateKeyToPem(i)}var s,c,l,p;switch(n.algorithm){case"aes128":s="AES-128-CBC",l=16,c=e.random.getBytes(16),p=e.aes.createEncryptionCipher;break;case"aes192":s="AES-192-CBC",l=24,c=e.random.getBytes(16),p=e.aes.createEncryptionCipher;break;case"aes256":s="AES-256-CBC",l=32,c=e.random.getBytes(16),p=e.aes.createEncryptionCipher;break;case"3des":s="DES-EDE3-CBC",l=24,c=e.random.getBytes(8),p=e.des.createEncryptionCipher;break;default:throw{message:'Could not encrypt RSA private key; unsupported encryption algorithm "'+n.algorithm+'".',algorithm:n.algorithm}}var f=a(r,c.substr(0,8),l),d=p(f);d.start(c),d.update(o.toDer(u.privateKeyToAsn1(t))),d.finish();var h={type:"RSA PRIVATE KEY",procType:{version:"4",type:"ENCRYPTED"},dekInfo:{algorithm:s,parameters:e.util.bytesToHex(c).toUpperCase()},body:d.output.getBytes()};return e.pem.encode(h)},u.decryptRsaPrivateKey=function(t,r){var n=null,i=e.pem.decode(t)[0];if("ENCRYPTED PRIVATE KEY"!==i.type&&"PRIVATE KEY"!==i.type&&"RSA PRIVATE KEY"!==i.type)throw{message:'Could not convert private key from PEM; PEM header type is not "ENCRYPTED PRIVATE KEY", "PRIVATE KEY", or "RSA PRIVATE KEY".',headerType:i.type};if(i.procType&&"ENCRYPTED"===i.procType.type){var s,c;switch(i.dekInfo.algorithm){case"DES-EDE3-CBC":s=24,c=e.des.createDecryptionCipher;break;case"AES-128-CBC":s=16,c=e.aes.createDecryptionCipher;break;case"AES-192-CBC":s=24,c=e.aes.createDecryptionCipher;break;case"AES-256-CBC":s=32,c=e.aes.createDecryptionCipher;break;case"RC2-40-CBC":s=5,c=function(t){return e.rc2.createDecryptionCipher(t,40)};break;case"RC2-64-CBC":s=8,c=function(t){return e.rc2.createDecryptionCipher(t,64)};break;case"RC2-128-CBC":s=16,c=function(t){return e.rc2.createDecryptionCipher(t,128)};break;default:throw{message:'Could not decrypt private key; unsupported encryption algorithm "'+i.dekInfo.algorithm+'".',algorithm:i.dekInfo.algorithm}}var l=e.util.hexToBytes(i.dekInfo.parameters),p=a(r,l.substr(0,8),s),f=c(p);if(f.start(l),f.update(e.util.createBuffer(i.body)),!f.finish())return n;n=f.output.getBytes()}else n=i.body;return n="ENCRYPTED PRIVATE KEY"===i.type?u.decryptPrivateKeyInfo(o.fromDer(n),r):o.fromDer(n),null!==n&&(n=u.privateKeyFromAsn1(n)),n},u.setRsaPublicKey=u.rsa.setPublicKey,u.setRsaPrivateKey=u.rsa.setPrivateKey}var t="pki";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/pki",["require","module","./aes","./asn1","./des","./jsbn","./md","./mgf","./oids","./pem","./pbkdf2","./pkcs12","./pss","./random","./rc2","./rsa","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t=function(t,r,n,i){var a=e.util.createBuffer(),s=t.length>>1,o=s+(1&t.length),u=t.substr(0,o),c=t.substr(s,o),l=e.util.createBuffer(),p=e.hmac.create();n=r+n;var f=Math.ceil(i/16),d=Math.ceil(i/20);p.start("MD5",u);var h=e.util.createBuffer();l.putBytes(n);for(var g=0;f>g;++g)p.start(null,null),p.update(l.getBytes()),l.putBuffer(p.digest()),p.start(null,null),p.update(l.bytes()+n),h.putBuffer(p.digest());p.start("SHA1",c);var y=e.util.createBuffer();l.clear(),l.putBytes(n);for(var g=0;d>g;++g)p.start(null,null),p.update(l.getBytes()),l.putBuffer(p.digest()),p.start(null,null),p.update(l.bytes()+n),y.putBuffer(p.digest());return a.putBytes(e.util.xorBytes(h.getBytes(),y.getBytes(),i)),a},r=function(t,r,n){var i=e.hmac.create();i.start("SHA1",t);var a=e.util.createBuffer();return a.putInt32(r[0]),a.putInt32(r[1]),a.putByte(n.type),a.putByte(n.version.major),a.putByte(n.version.minor),a.putInt16(n.length),a.putBytes(n.fragment.bytes()),i.update(a.getBytes()),i.digest().getBytes()},n=function(t,r){var n=!1;try{var i=t.deflate(r.fragment.getBytes());r.fragment=e.util.createBuffer(i),r.length=i.length,n=!0}catch(a){}return n},i=function(t,r){var n=!1;try{var i=t.inflate(r.fragment.getBytes());r.fragment=e.util.createBuffer(i),r.length=i.length,n=!0}catch(a){}return n},a=function(t,r){var n=0;switch(r){case 1:n=t.getByte();break;case 2:n=t.getInt16();break;case 3:n=t.getInt24();break;case 4:n=t.getInt32()}return e.util.createBuffer(t.getBytes(n))},s=function(e,t,r){e.putInt(r.length(),t<<3),e.putBuffer(r)},o={};o.Version={major:3,minor:1},o.MaxFragment=15360,o.ConnectionEnd={server:0,client:1},o.PRFAlgorithm={tls_prf_sha256:0},o.BulkCipherAlgorithm={none:null,rc4:0,des3:1,aes:2},o.CipherType={stream:0,block:1,aead:2},o.MACAlgorithm={none:null,hmac_md5:0,hmac_sha1:1,hmac_sha256:2,hmac_sha384:3,hmac_sha512:4},o.CompressionMethod={none:0,deflate:1},o.ContentType={change_cipher_spec:20,alert:21,handshake:22,application_data:23},o.HandshakeType={hello_request:0,client_hello:1,server_hello:2,certificate:11,server_key_exchange:12,certificate_request:13,server_hello_done:14,certificate_verify:15,client_key_exchange:16,finished:20},o.Alert={},o.Alert.Level={warning:1,fatal:2},o.Alert.Description={close_notify:0,unexpected_message:10,bad_record_mac:20,decryption_failed:21,record_overflow:22,decompression_failure:30,handshake_failure:40,bad_certificate:42,unsupported_certificate:43,certificate_revoked:44,certificate_expired:45,certificate_unknown:46,illegal_parameter:47,unknown_ca:48,access_denied:49,decode_error:50,decrypt_error:51,export_restriction:60,protocol_version:70,insufficient_security:71,internal_error:80,user_canceled:90,no_renegotiation:100},o.CipherSuites={},o.getCipherSuite=function(e){var t=null;for(var r in o.CipherSuites){var n=o.CipherSuites[r];if(n.id[0]===e.charCodeAt(0)&&n.id[1]===e.charCodeAt(1)){t=n;break}}return t},o.handleUnexpected=function(e){var t=!e.open&&e.entity===o.ConnectionEnd.client;t||e.error(e,{message:"Unexpected message. Received TLS record out of order.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.unexpected_message}})},o.handleHelloRequest=function(e){!e.handshaking&&e.handshakes>0&&(o.queue(e,o.createAlert({level:o.Alert.Level.warning,description:o.Alert.Description.no_renegotiation})),o.flush(e)),e.process()},o.parseHelloMessage=function(t,r,n){var i=null,s=t.entity===o.ConnectionEnd.client;if(38>n)t.error(t,{message:s?"Invalid ServerHello message. Message too short.":"Invalid ClientHello message. Message too short.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.illegal_parameter}});else{var u=r.fragment,c=u.length();if(i={version:{major:u.getByte(),minor:u.getByte()},random:e.util.createBuffer(u.getBytes(32)),session_id:a(u,1),extensions:[]},s?(i.cipher_suite=u.getBytes(2),i.compression_method=u.getByte()):(i.cipher_suites=a(u,2),i.compression_methods=a(u,1)),c=n-(c-u.length()),c>0){for(var l=a(u,2);l.length()>0;)i.extensions.push({type:[l.getByte(),l.getByte()],data:a(l,2)});if(!s)for(var p=0;p<i.extensions.length;++p){var f=i.extensions[p];if(0===f.type[0]&&0===f.type[1])for(var d=a(f.data,2);d.length()>0;){var h=d.getByte();if(0!==h)break;t.session.serverNameList.push(a(d,2).getBytes())}}}if((i.version.major!==o.Version.major||i.version.minor!==o.Version.minor)&&t.error(t,{message:"Incompatible TLS version.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.protocol_version}}),s)t.session.cipherSuite=o.getCipherSuite(i.cipher_suite);else for(var g=e.util.createBuffer(i.cipher_suites.bytes());g.length()>0&&(t.session.cipherSuite=o.getCipherSuite(g.getBytes(2)),null===t.session.cipherSuite););if(null===t.session.cipherSuite)return t.error(t,{message:"No cipher suites in common.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.handshake_failure},cipherSuite:e.util.bytesToHex(i.cipher_suite)});t.session.compressionMethod=s?i.compression_method:o.CompressionMethod.none}return i},o.createSecurityParameters=function(e,t){var r=e.entity===o.ConnectionEnd.client,n=t.random.bytes(),i=r?e.session.sp.client_random:n,a=r?n:o.createRandom().getBytes();e.session.sp={entity:e.entity,prf_algorithm:o.PRFAlgorithm.tls_prf_sha256,bulk_cipher_algorithm:null,cipher_type:null,enc_key_length:null,block_length:null,fixed_iv_length:null,record_iv_length:null,mac_algorithm:null,mac_length:null,mac_key_length:null,compression_algorithm:e.session.compressionMethod,pre_master_secret:null,master_secret:null,client_random:i,server_random:a}},o.handleServerHello=function(e,t,r){var n=o.parseHelloMessage(e,t,r);if(!e.fail){var i=n.session_id.bytes();i===e.session.id?(e.expect=d,e.session.resuming=!0,e.session.sp.server_random=n.random.bytes()):(e.expect=c,e.session.resuming=!1,o.createSecurityParameters(e,n)),e.session.id=i,e.process()}},o.handleClientHello=function(t,r,n){var i=o.parseHelloMessage(t,r,n);if(!t.fail){var a=i.session_id.bytes(),s=null;t.sessionCache&&(s=t.sessionCache.getSession(a),null===s&&(a="")),0===a.length&&(a=e.random.getBytes(32)),t.session.id=a,t.session.clientHelloVersion=i.version,t.session.sp=s?s.sp:{},null!==s?(t.expect=b,t.session.resuming=!0,t.session.sp.client_random=i.random.bytes()):(t.expect=t.verifyClient!==!1?v:C,t.session.resuming=!1,o.createSecurityParameters(t,i)),t.open=!0,o.queue(t,o.createRecord({type:o.ContentType.handshake,data:o.createServerHello(t)})),t.session.resuming?(o.queue(t,o.createRecord({type:o.ContentType.change_cipher_spec,data:o.createChangeCipherSpec()})),t.state.pending=o.createConnectionState(t),t.state.current.write=t.state.pending.write,o.queue(t,o.createRecord({type:o.ContentType.handshake,data:o.createFinished(t)}))):(o.queue(t,o.createRecord({type:o.ContentType.handshake,data:o.createCertificate(t)})),t.fail||(o.queue(t,o.createRecord({type:o.ContentType.handshake,data:o.createServerKeyExchange(t)})),t.verifyClient!==!1&&o.queue(t,o.createRecord({type:o.ContentType.handshake,data:o.createCertificateRequest(t)})),o.queue(t,o.createRecord({type:o.ContentType.handshake,data:o.createServerHelloDone(t)})))),o.flush(t),t.process()}},o.handleCertificate=function(t,r,n){if(3>n)t.error(t,{message:"Invalid Certificate message. Message too short.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.illegal_parameter}});else{var i,s,u=r.fragment,c={certificate_list:a(u,3)},p=[];try{for(;c.certificate_list.length()>0;)i=a(c.certificate_list,3),s=e.asn1.fromDer(i),i=e.pki.certificateFromAsn1(s,!0),p.push(i)}catch(f){t.error(t,{message:"Could not parse certificate list.",cause:f,send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.bad_certificate}})}if(!t.fail){var d=t.entity===o.ConnectionEnd.client;!d&&t.verifyClient!==!0||0!==p.length?0===p.length?t.expect=d?l:C:(d?t.session.serverCertificate=p[0]:t.session.clientCertificate=p[0],o.verifyCertificateChain(t,p)&&(t.expect=d?l:C)):t.error(t,{message:d?"No server certificate provided.":"No client certificate provided.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.illegal_parameter}}),t.process()}}},o.handleServerKeyExchange=function(e,t,r){r>0?e.error(e,{message:"Invalid key parameters. Only RSA is supported.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.unsupported_certificate}}):(e.expect=p,e.process())},o.handleClientKeyExchange=function(t,r,n){if(48>n)t.error(t,{message:"Invalid key parameters. Only RSA is supported.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.unsupported_certificate}});else{var i=r.fragment,s={enc_pre_master_secret:a(i,2).getBytes()},u=null;if(t.getPrivateKey)try{u=t.getPrivateKey(t,t.session.serverCertificate),u=e.pki.privateKeyFromPem(u)}catch(c){t.error(t,{message:"Could not get private key.",cause:c,send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.internal_error}})}if(null===u)t.error(t,{message:"No private key set.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.internal_error}});else try{var l=t.session.sp;l.pre_master_secret=u.decrypt(s.enc_pre_master_secret);var p=t.session.clientHelloVersion;if(p.major!==l.pre_master_secret.charCodeAt(0)||p.minor!==l.pre_master_secret.charCodeAt(1))throw{message:"TLS version rollback attack detected."}}catch(c){l.pre_master_secret=e.random.getBytes(48)}}t.fail||(t.expect=b,null!==t.session.clientCertificate&&(t.expect=E),t.process())},o.handleCertificateRequest=function(e,t,r){if(3>r)e.error(e,{message:"Invalid CertificateRequest. Message too short.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.illegal_parameter}});else{var n=t.fragment,i={certificate_types:a(n,1),certificate_authorities:a(n,2)};e.session.certificateRequest=i,e.expect=f,e.process()}},o.handleCertificateVerify=function(t,r,n){if(2>n)t.error(t,{message:"Invalid CertificateVerify. Message too short.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.illegal_parameter}});else{var i=r.fragment;i.read-=4;var s=i.bytes();i.read+=4;var u={signature:a(i,2).getBytes()},c=e.util.createBuffer();c.putBuffer(t.session.md5.digest()),c.putBuffer(t.session.sha1.digest()),c=c.getBytes();try{var l=t.session.clientCertificate;if(!l.publicKey.verify(c,u.signature,"NONE"))throw{message:"CertificateVerify signature does not match."};t.session.md5.update(s),t.session.sha1.update(s)}catch(p){t.error(t,{message:"Bad signature in CertificateVerify.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.handshake_failure}})}t.fail||(t.expect=b,t.process())}},o.handleServerHelloDone=function(t,r,n){if(n>0)t.error(t,{message:"Invalid ServerHelloDone message. Invalid length.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.record_overflow}});else if(null===t.serverCertificate){var i={message:"No server certificate provided. Not enough security.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.insufficient_security}},a=t.verify(t,i.alert.description,depth,[]);a===!0?i=null:((a||0===a)&&("object"!=typeof a||e.util.isArray(a)?"number"==typeof a&&(i.alert.description=a):(a.message&&(i.message=a.message),a.alert&&(i.alert.description=a.alert))),t.error(t,i))}if(!t.fail&&null!==t.session.certificateRequest&&(r=o.createRecord({type:o.ContentType.handshake,data:o.createCertificate(t)}),o.queue(t,r)),!t.fail){r=o.createRecord({type:o.ContentType.handshake,data:o.createClientKeyExchange(t)}),o.queue(t,r),t.expect=y;var s=function(e,t){null!==e.session.certificateRequest&&null!==e.session.clientCertificate&&o.queue(e,o.createRecord({type:o.ContentType.handshake,data:o.createCertificateVerify(e,t)})),o.queue(e,o.createRecord({type:o.ContentType.change_cipher_spec,data:o.createChangeCipherSpec()})),e.state.pending=o.createConnectionState(e),e.state.current.write=e.state.pending.write,o.queue(e,o.createRecord({type:o.ContentType.handshake,data:o.createFinished(e)})),e.expect=d,o.flush(e),e.process()};null===t.session.certificateRequest||null===t.session.clientCertificate?s(t,null):o.getClientSignature(t,s)}},o.handleChangeCipherSpec=function(e,t){if(1!==t.fragment.getByte())e.error(e,{message:"Invalid ChangeCipherSpec message received.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.illegal_parameter}});else{var r=e.entity===o.ConnectionEnd.client;(e.session.resuming&&r||!e.session.resuming&&!r)&&(e.state.pending=o.createConnectionState(e)),e.state.current.read=e.state.pending.read,(!e.session.resuming&&r||e.session.resuming&&!r)&&(e.state.pending=null),e.expect=r?h:T,e.process()}},o.handleFinished=function(r,n){var i=n.fragment;i.read-=4;var a=i.bytes();i.read+=4;var s=n.fragment.getBytes();i=e.util.createBuffer(),i.putBuffer(r.session.md5.digest()),i.putBuffer(r.session.sha1.digest());var u=r.entity===o.ConnectionEnd.client,c=u?"server finished":"client finished",l=r.session.sp,p=12,f=t;i=f(l.master_secret,c,i.getBytes(),p),i.getBytes()!==s?r.error(r,{message:"Invalid verify_data in Finished message.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.decrypt_error}}):(r.session.md5.update(a),r.session.sha1.update(a),(r.session.resuming&&u||!r.session.resuming&&!u)&&(o.queue(r,o.createRecord({type:o.ContentType.change_cipher_spec,data:o.createChangeCipherSpec()})),r.state.current.write=r.state.pending.write,r.state.pending=null,o.queue(r,o.createRecord({type:o.ContentType.handshake,data:o.createFinished(r)}))),r.expect=u?g:S,r.handshaking=!1,++r.handshakes,r.peerCertificate=u?r.session.serverCertificate:r.session.clientCertificate,r.sessionCache?(r.session={id:r.session.id,sp:r.session.sp},r.session.sp.keys=null):r.session=null,o.flush(r),r.isConnected=!0,r.connected(r),r.process())},o.handleAlert=function(e,t){var r,n=t.fragment,i={level:n.getByte(),description:n.getByte()};switch(i.description){case o.Alert.Description.close_notify:r="Connection closed.";break;case o.Alert.Description.unexpected_message:r="Unexpected message.";break;case o.Alert.Description.bad_record_mac:r="Bad record MAC.";break;case o.Alert.Description.decryption_failed:r="Decryption failed.";break;case o.Alert.Description.record_overflow:r="Record overflow.";break;case o.Alert.Description.decompression_failure:r="Decompression failed.";break;case o.Alert.Description.handshake_failure:r="Handshake failure.";break;case o.Alert.Description.bad_certificate:r="Bad certificate.";break;case o.Alert.Description.unsupported_certificate:r="Unsupported certificate.";break;case o.Alert.Description.certificate_revoked:r="Certificate revoked.";break;case o.Alert.Description.certificate_expired:r="Certificate expired.";break;case o.Alert.Description.certificate_unknown:r="Certificate unknown.";break;case o.Alert.Description.illegal_parameter:r="Illegal parameter.";break;case o.Alert.Description.unknown_ca:r="Unknown certificate authority.";break;case o.Alert.Description.access_denied:r="Access denied.";break;case o.Alert.Description.decode_error:r="Decode error.";break;case o.Alert.Description.decrypt_error:r="Decrypt error.";break;case o.Alert.Description.export_restriction:r="Export restriction.";break;case o.Alert.Description.protocol_version:r="Unsupported protocol version.";break;case o.Alert.Description.insufficient_security:r="Insufficient security.";break;case o.Alert.Description.internal_error:r="Internal error.";break;case o.Alert.Description.user_canceled:r="User canceled.";break;case o.Alert.Description.no_renegotiation:r="Renegotiation not supported.";break;default:r="Unknown error."}i.description===o.Alert.Description.close_notify?e.close():(e.error(e,{message:r,send:!1,origin:e.entity===o.ConnectionEnd.client?"server":"client",alert:i}),e.process())},o.handleHandshake=function(t,r){var n=r.fragment,i=n.getByte(),a=n.getInt24();if(a>n.length())t.fragmented=r,r.fragment=e.util.createBuffer(),n.read-=4,t.process();else{t.fragmented=null,n.read-=4;var s=n.bytes(a+4);n.read+=4,i in P[t.entity][t.expect]?(t.entity===o.ConnectionEnd.server&&!t.open&&!t.fail&&(t.handshaking=!0,t.session={serverNameList:[],cipherSuite:null,compressionMethod:null,serverCertificate:null,clientCertificate:null,md5:e.md.md5.create(),sha1:e.md.sha1.create()}),i!==o.HandshakeType.hello_request&&i!==o.HandshakeType.certificate_verify&&i!==o.HandshakeType.finished&&(t.session.md5.update(s),t.session.sha1.update(s)),P[t.entity][t.expect][i](t,r,a)):o.handleUnexpected(t,r)}},o.handleApplicationData=function(e,t){e.data.putBuffer(t.fragment),e.dataReady(e),e.process()};var u=0,c=1,l=2,p=3,f=4,d=5,h=6,g=7,y=8,m=0,v=1,C=2,E=3,b=4,T=5,S=6,I=o.handleUnexpected,B=o.handleChangeCipherSpec,A=o.handleAlert,F=o.handleHandshake,N=o.handleApplicationData,R=[];R[o.ConnectionEnd.client]=[[I,A,F,I],[I,A,F,I],[I,A,F,I],[I,A,F,I],[I,A,F,I],[B,A,I,I],[I,A,F,I],[I,A,F,N],[I,A,F,I]],R[o.ConnectionEnd.server]=[[I,A,F,I],[I,A,F,I],[I,A,F,I],[I,A,F,I],[B,A,I,I],[I,A,F,I],[I,A,F,N],[I,A,F,I]];var k=o.handleHelloRequest,D=o.handleServerHello,w=o.handleCertificate,L=o.handleServerKeyExchange,U=o.handleCertificateRequest,_=o.handleServerHelloDone,O=o.handleFinished,P=[];P[o.ConnectionEnd.client]=[[I,I,D,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I],[k,I,I,I,I,I,I,I,I,I,I,w,L,U,_,I,I,I,I,I,I],[k,I,I,I,I,I,I,I,I,I,I,I,L,U,_,I,I,I,I,I,I],[k,I,I,I,I,I,I,I,I,I,I,I,I,U,_,I,I,I,I,I,I],[k,I,I,I,I,I,I,I,I,I,I,I,I,I,_,I,I,I,I,I,I],[k,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I],[k,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,O],[k,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I],[k,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I]];var x=o.handleClientHello,V=o.handleClientKeyExchange,j=o.handleCertificateVerify;P[o.ConnectionEnd.server]=[[I,x,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I],[I,I,I,I,I,I,I,I,I,I,I,w,I,I,I,I,I,I,I,I,I],[I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,V,I,I,I,I],[I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,j,I,I,I,I,I],[I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I],[I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,O],[I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I],[I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I]],o.generateKeys=function(e,r){var n=t,i=r.client_random+r.server_random;e.session.resuming||(r.master_secret=n(r.pre_master_secret,"master secret",i,48).bytes(),r.pre_master_secret=null),i=r.server_random+r.client_random;var a=2*r.mac_key_length+2*r.enc_key_length+2*r.fixed_iv_length,s=n(r.master_secret,"key expansion",i,a);return{client_write_MAC_key:s.getBytes(r.mac_key_length),server_write_MAC_key:s.getBytes(r.mac_key_length),client_write_key:s.getBytes(r.enc_key_length),server_write_key:s.getBytes(r.enc_key_length),client_write_IV:s.getBytes(r.fixed_iv_length),server_write_IV:s.getBytes(r.fixed_iv_length)}},o.createConnectionState=function(e){var t=e.entity===o.ConnectionEnd.client,r=function(){var e={sequenceNumber:[0,0],macKey:null,macLength:0,macFunction:null,cipherState:null,cipherFunction:function(){return!0},compressionState:null,compressFunction:function(){return!0},updateSequenceNumber:function(){4294967295===e.sequenceNumber[1]?(e.sequenceNumber[1]=0,++e.sequenceNumber[0]):++e.sequenceNumber[1]}};return e},a={read:r(),write:r()};if(a.read.update=function(e,t){return a.read.cipherFunction(t,a.read)?a.read.compressFunction(e,t,a.read)||e.error(e,{message:"Could not decompress record.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.decompression_failure}}):e.error(e,{message:"Could not decrypt record or bad MAC.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.bad_record_mac}}),!e.fail},a.write.update=function(e,t){return a.write.compressFunction(e,t,a.write)?a.write.cipherFunction(t,a.write)||e.error(e,{message:"Could not encrypt record.",send:!1,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.internal_error}}):e.error(e,{message:"Could not compress record.",send:!1,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.internal_error}}),!e.fail},e.session){var s=e.session.sp;switch(e.session.cipherSuite.initSecurityParameters(s),s.keys=o.generateKeys(e,s),a.read.macKey=t?s.keys.server_write_MAC_key:s.keys.client_write_MAC_key,a.write.macKey=t?s.keys.client_write_MAC_key:s.keys.server_write_MAC_key,e.session.cipherSuite.initConnectionState(a,e,s),s.compression_algorithm){case o.CompressionMethod.none:break;case o.CompressionMethod.deflate:a.read.compressFunction=i,a.write.compressFunction=n;break;default:throw{message:"Unsupported compression algorithm."}}}return a},o.createRandom=function(){var t=new Date,r=+t+6e4*t.getTimezoneOffset(),n=e.util.createBuffer();return n.putInt32(r),n.putBytes(e.random.getBytes(28)),n},o.createRecord=function(e){if(!e.data)return null;var t={type:e.type,version:{major:o.Version.major,minor:o.Version.minor},length:e.data.length(),fragment:e.data};return t},o.createAlert=function(t){var r=e.util.createBuffer();return r.putByte(t.level),r.putByte(t.description),o.createRecord({type:o.ContentType.alert,data:r})},o.createClientHello=function(t){for(var r=e.util.createBuffer(),n=0;n<t.cipherSuites.length;++n){var i=t.cipherSuites[n];r.putByte(i.id[0]),r.putByte(i.id[1])}var a=r.length(),u=e.util.createBuffer();u.putByte(o.CompressionMethod.none);var c=u.length(),l=e.util.createBuffer();if(t.virtualHost){var p=e.util.createBuffer();p.putByte(0),p.putByte(0);var f=e.util.createBuffer();f.putByte(0),s(f,2,e.util.createBuffer(t.virtualHost));var d=e.util.createBuffer();s(d,2,f),s(p,2,d),l.putBuffer(p)}var h=l.length();h>0&&(h+=2);var g=t.session.id,y=g.length+1+2+4+28+2+a+1+c+h,m=e.util.createBuffer();return m.putByte(o.HandshakeType.client_hello),m.putInt24(y),m.putByte(o.Version.major),m.putByte(o.Version.minor),m.putBytes(t.session.sp.client_random),s(m,1,e.util.createBuffer(g)),s(m,2,r),s(m,1,u),h>0&&s(m,2,l),m},o.createServerHello=function(t){var r=t.session.id,n=r.length+1+2+4+28+2+1,i=e.util.createBuffer();return i.putByte(o.HandshakeType.server_hello),i.putInt24(n),i.putByte(o.Version.major),i.putByte(o.Version.minor),i.putBytes(t.session.sp.server_random),s(i,1,e.util.createBuffer(r)),i.putByte(t.session.cipherSuite.id[0]),i.putByte(t.session.cipherSuite.id[1]),i.putByte(t.session.compressionMethod),i},o.createCertificate=function(t){var r=t.entity===o.ConnectionEnd.client,n=null;t.getCertificate&&(n=t.getCertificate(t,r?t.session.certificateRequest:t.session.serverNameList));var i=e.util.createBuffer();if(null!==n)try{e.util.isArray(n)||(n=[n]);for(var a=null,u=0;u<n.length;++u){var c=e.pem.decode(n[u])[0];if("CERTIFICATE"!==c.type&&"X509 CERTIFICATE"!==c.type&&"TRUSTED CERTIFICATE"!==c.type)throw{message:'Could not convert certificate from PEM; PEM header type is not "CERTIFICATE", "X509 CERTIFICATE", or "TRUSTED CERTIFICATE".',headerType:c.type};if(c.procType&&"ENCRYPTED"===c.procType.type)throw{message:"Could not convert certificate from PEM; PEM is encrypted."};var l=e.util.createBuffer(c.body);null===a&&(a=e.asn1.fromDer(l.bytes(),!1));var p=e.util.createBuffer();s(p,3,l),i.putBuffer(p)}n=e.pki.certificateFromAsn1(a),r?t.session.clientCertificate=n:t.session.serverCertificate=n}catch(f){return t.error(t,{message:"Could not send certificate list.",cause:f,send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.bad_certificate}})}var d=3+i.length(),h=e.util.createBuffer();return h.putByte(o.HandshakeType.certificate),h.putInt24(d),s(h,3,i),h},o.createClientKeyExchange=function(t){var r=e.util.createBuffer();r.putByte(o.Version.major),r.putByte(o.Version.minor),r.putBytes(e.random.getBytes(46));var n=t.session.sp;n.pre_master_secret=r.getBytes();var i=t.session.serverCertificate.publicKey;r=i.encrypt(n.pre_master_secret);var a=r.length+2,s=e.util.createBuffer();return s.putByte(o.HandshakeType.client_key_exchange),s.putInt24(a),s.putInt16(r.length),s.putBytes(r),s},o.createServerKeyExchange=function(){var t=0,r=e.util.createBuffer();return t>0&&(r.putByte(o.HandshakeType.server_key_exchange),r.putInt24(t)),r},o.getClientSignature=function(t,r){var n=e.util.createBuffer();n.putBuffer(t.session.md5.digest()),n.putBuffer(t.session.sha1.digest()),n=n.getBytes(),t.getSignature=t.getSignature||function(t,r,n){var i=null;if(t.getPrivateKey)try{i=t.getPrivateKey(t,t.session.clientCertificate),i=e.pki.privateKeyFromPem(i)}catch(a){t.error(t,{message:"Could not get private key.",cause:a,send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.internal_error}})}null===i?t.error(t,{message:"No private key set.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.internal_error}}):r=i.sign(r,null),n(t,r)},t.getSignature(t,n,r)},o.createCertificateVerify=function(t,r){var n=r.length+2,i=e.util.createBuffer();return i.putByte(o.HandshakeType.certificate_verify),i.putInt24(n),i.putInt16(r.length),i.putBytes(r),i},o.createCertificateRequest=function(t){var r=e.util.createBuffer();r.putByte(1);var n=e.util.createBuffer();for(var i in t.caStore.certs){var a=t.caStore.certs[i],u=e.pki.distinguishedNameToAsn1(a.subject);n.putBuffer(e.asn1.toDer(u))}var c=1+r.length()+2+n.length(),l=e.util.createBuffer();return l.putByte(o.HandshakeType.certificate_request),l.putInt24(c),s(l,1,r),s(l,2,n),l},o.createServerHelloDone=function(){var t=e.util.createBuffer();return t.putByte(o.HandshakeType.server_hello_done),t.putInt24(0),t},o.createChangeCipherSpec=function(){var t=e.util.createBuffer();return t.putByte(1),t},o.createFinished=function(r){var n=e.util.createBuffer();n.putBuffer(r.session.md5.digest()),n.putBuffer(r.session.sha1.digest());var i=r.entity===o.ConnectionEnd.client,a=r.session.sp,s=12,u=t,c=i?"client finished":"server finished";n=u(a.master_secret,c,n.getBytes(),s);var l=e.util.createBuffer();return l.putByte(o.HandshakeType.finished),l.putInt24(n.length()),l.putBuffer(n),l},o.queue=function(t,r){if(r){if(r.type===o.ContentType.handshake){var n=r.fragment.bytes();t.session.md5.update(n),t.session.sha1.update(n),n=null}var i;if(r.fragment.length()<=o.MaxFragment)i=[r];else{i=[];for(var a=r.fragment.bytes();a.length>o.MaxFragment;)i.push(o.createRecord({type:r.type,data:e.util.createBuffer(a.slice(0,o.MaxFragment))})),a=a.slice(o.MaxFragment);a.length>0&&i.push(o.createRecord({type:r.type,data:e.util.createBuffer(a)}))}for(var s=0;s<i.length&&!t.fail;++s){var u=i[s],c=t.state.current.write;c.update(t,u)&&t.records.push(u)}}},o.flush=function(e){for(var t=0;t<e.records.length;++t){var r=e.records[t];e.tlsData.putByte(r.type),e.tlsData.putByte(r.version.major),e.tlsData.putByte(r.version.minor),e.tlsData.putInt16(r.fragment.length()),e.tlsData.putBuffer(e.records[t].fragment)}return e.records=[],e.tlsDataReady(e)};var q=function(t){switch(t){case!0:return!0;case e.pki.certificateError.bad_certificate:return o.Alert.Description.bad_certificate;case e.pki.certificateError.unsupported_certificate:return o.Alert.Description.unsupported_certificate;case e.pki.certificateError.certificate_revoked:return o.Alert.Description.certificate_revoked;case e.pki.certificateError.certificate_expired:return o.Alert.Description.certificate_expired;case e.pki.certificateError.certificate_unknown:return o.Alert.Description.certificate_unknown;
case e.pki.certificateError.unknown_ca:return o.Alert.Description.unknown_ca;default:return o.Alert.Description.bad_certificate}},K=function(t){switch(t){case!0:return!0;case o.Alert.Description.bad_certificate:return e.pki.certificateError.bad_certificate;case o.Alert.Description.unsupported_certificate:return e.pki.certificateError.unsupported_certificate;case o.Alert.Description.certificate_revoked:return e.pki.certificateError.certificate_revoked;case o.Alert.Description.certificate_expired:return e.pki.certificateError.certificate_expired;case o.Alert.Description.certificate_unknown:return e.pki.certificateError.certificate_unknown;case o.Alert.Description.unknown_ca:return e.pki.certificateError.unknown_ca;default:return e.pki.certificateError.bad_certificate}};o.verifyCertificateChain=function(t,r){try{e.pki.verifyCertificateChain(t.caStore,r,function(r,n,i){var a=(q(r),t.verify(t,r,n,i));if(a!==!0){if("object"==typeof a&&!e.util.isArray(a)){var s={message:"The application rejected the certificate.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.bad_certificate}};throw a.message&&(s.message=a.message),a.alert&&(s.alert.description=a.alert),s}a!==r&&(a=K(a))}return a})}catch(n){("object"!=typeof n||e.util.isArray(n))&&(n={send:!0,alert:{level:o.Alert.Level.fatal,description:q(n)}}),"send"in n||(n.send=!0),"alert"in n||(n.alert={level:o.Alert.Level.fatal,description:q(n.error)}),t.error(t,n)}return!t.fail},o.createSessionCache=function(t,r){var n=null;if(t&&t.getSession&&t.setSession&&t.order)n=t;else{n={},n.cache=t||{},n.capacity=Math.max(r||100,1),n.order=[];for(var i in t)n.order.length<=r?n.order.push(i):delete t[i];n.getSession=function(t){var r=null,i=null;if(t?i=e.util.bytesToHex(t):n.order.length>0&&(i=n.order[0]),null!==i&&i in n.cache){r=n.cache[i],delete n.cache[i];for(var a in n.order)if(n.order[a]===i){n.order.splice(a,1);break}}return r},n.setSession=function(t,r){if(n.order.length===n.capacity){var i=n.order.shift();delete n.cache[i]}var i=e.util.bytesToHex(t);n.order.push(i),n.cache[i]=r}}return n},o.createConnection=function(t){var r=null;r=t.caStore?e.util.isArray(t.caStore)?e.pki.createCaStore(t.caStore):t.caStore:e.pki.createCaStore();var n=t.cipherSuites||null;if(null===n){n=[];for(var i in o.CipherSuites)n.push(o.CipherSuites[i])}var a=t.server?o.ConnectionEnd.server:o.ConnectionEnd.client,s=t.sessionCache?o.createSessionCache(t.sessionCache):null,c={entity:a,sessionId:t.sessionId,caStore:r,sessionCache:s,cipherSuites:n,connected:t.connected,virtualHost:t.virtualHost||null,verifyClient:t.verifyClient||!1,verify:t.verify||function(e,t){return t},getCertificate:t.getCertificate||null,getPrivateKey:t.getPrivateKey||null,getSignature:t.getSignature||null,input:e.util.createBuffer(),tlsData:e.util.createBuffer(),data:e.util.createBuffer(),tlsDataReady:t.tlsDataReady,dataReady:t.dataReady,closed:t.closed,error:function(e,r){r.origin=r.origin||(e.entity===o.ConnectionEnd.client?"client":"server"),r.send&&(o.queue(e,o.createAlert(r.alert)),o.flush(e));var n=r.fatal!==!1;n&&(e.fail=!0),t.error(e,r),n&&e.close(!1)},deflate:t.deflate||null,inflate:t.inflate||null};c.reset=function(e){c.record=null,c.session=null,c.peerCertificate=null,c.state={pending:null,current:null},c.expect=c.entity===o.ConnectionEnd.client?u:m,c.fragmented=null,c.records=[],c.open=!1,c.handshakes=0,c.handshaking=!1,c.isConnected=!1,c.fail=!e&&"undefined"!=typeof e,c.input.clear(),c.tlsData.clear(),c.data.clear(),c.state.current=o.createConnectionState(c)},c.reset();var l=function(e,t){var r=t.type-o.ContentType.change_cipher_spec,n=R[e.entity][e.expect];r in n?n[r](e,t):o.handleUnexpected(e,t)},p=function(t){var r=0,n=t.input,i=n.length();return 5>i?r=5-i:(t.record={type:n.getByte(),version:{major:n.getByte(),minor:n.getByte()},length:n.getInt16(),fragment:e.util.createBuffer(),ready:!1},(t.record.version.major!==o.Version.major||t.record.version.minor!==o.Version.minor)&&t.error(t,{message:"Incompatible TLS version.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.protocol_version}})),r},f=function(e){var t=0,r=e.input,n=r.length();if(n<e.record.length)t=e.record.length-n;else{e.record.fragment.putBytes(r.getBytes(e.record.length));var i=e.state.current.read;i.update(e,e.record)&&(null!==e.fragmented&&(e.fragmented.type===e.record.type?(e.fragmented.fragment.putBuffer(e.record.fragment),e.record=e.fragmented):e.error(e,{message:"Invalid fragmented record.",send:!0,alert:{level:o.Alert.Level.fatal,description:o.Alert.Description.unexpected_message}})),e.record.ready=!0)}return t};return c.handshake=function(t){if(c.entity!==o.ConnectionEnd.client)c.error(c,{message:"Cannot initiate handshake as a server.",fatal:!1});else if(c.handshaking)c.error(c,{message:"Handshake already in progress.",fatal:!1});else{c.fail&&!c.open&&0===c.handshakes&&(c.fail=!1),c.handshaking=!0,t=t||"";var r=null;t.length>0&&(c.sessionCache&&(r=c.sessionCache.getSession(t)),null===r&&(t="")),0===t.length&&c.sessionCache&&(r=c.sessionCache.getSession(),null!==r&&(t=r.id)),c.session={id:t,cipherSuite:null,compressionMethod:null,serverCertificate:null,certificateRequest:null,clientCertificate:null,sp:r?r.sp:{},md5:e.md.md5.create(),sha1:e.md.sha1.create()},c.session.sp.client_random=o.createRandom().getBytes(),c.open=!0,o.queue(c,o.createRecord({type:o.ContentType.handshake,data:o.createClientHello(c)})),o.flush(c)}},c.process=function(e){var t=0;return e&&c.input.putBytes(e),c.fail||(null!==c.record&&c.record.ready&&c.record.fragment.isEmpty()&&(c.record=null),null===c.record&&(t=p(c)),!c.fail&&null!==c.record&&!c.record.ready&&(t=f(c)),!c.fail&&null!==c.record&&c.record.ready&&l(c,c.record)),t},c.prepare=function(t){return o.queue(c,o.createRecord({type:o.ContentType.application_data,data:e.util.createBuffer(t)})),o.flush(c)},c.close=function(e){!c.fail&&c.sessionCache&&c.session&&c.sessionCache.setSession(c.session.id,c.session),c.open&&(c.open=!1,c.input.clear(),(c.isConnected||c.handshaking)&&(c.isConnected=c.handshaking=!1,o.queue(c,o.createAlert({level:o.Alert.Level.warning,description:o.Alert.Description.close_notify})),o.flush(c)),c.closed(c)),c.reset(e)},c},e.tls=e.tls||{};for(var M in o)"function"!=typeof o[M]&&(e.tls[M]=o[M]);e.tls.prf_tls1=t,e.tls.hmac_sha1=r,e.tls.createSessionCache=o.createSessionCache,e.tls.createConnection=o.createConnection}var t="tls";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/tls",["require","module","./asn1","./hmac","./md","./pem","./pki","./random","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){function t(t,n,i){var o=n.entity===e.tls.ConnectionEnd.client;t.read.cipherState={init:!1,cipher:e.aes.createDecryptionCipher(o?i.keys.server_write_key:i.keys.client_write_key),iv:o?i.keys.server_write_IV:i.keys.client_write_IV},t.write.cipherState={init:!1,cipher:e.aes.createEncryptionCipher(o?i.keys.client_write_key:i.keys.server_write_key),iv:o?i.keys.client_write_IV:i.keys.server_write_IV},t.read.cipherFunction=a,t.write.cipherFunction=r,t.read.macLength=t.write.macLength=i.mac_length,t.read.macFunction=t.write.macFunction=s.hmac_sha1}function r(t,r){var i=!1,a=r.macFunction(r.macKey,r.sequenceNumber,t);t.fragment.putBytes(a),r.updateSequenceNumber();var s;s=t.version.minor>1?e.random.getBytes(16):r.cipherState.init?null:r.cipherState.iv,r.cipherState.init=!0;var o=r.cipherState.cipher;return o.start(s),t.version.minor>1&&o.output.putBytes(s),o.update(t.fragment),o.finish(n)&&(t.fragment=o.output,t.length=t.fragment.length(),i=!0),i}function n(e,t,r){if(!r){var n=e-t.length()%e;t.fillWithByte(n-1,n)}return!0}function i(e,t,r){var n=!0;if(r){for(var i=t.length(),a=t.last(),s=i-1-a;i-1>s;++s)n=n&&t.at(s)==a;n&&t.truncate(a+1)}return n}function a(t,r){var n=!1,a=r.cipherState.init?null:r.cipherState.iv;r.cipherState.init=!0;var s=r.cipherState.cipher;s.start(a),s.update(t.fragment),n=s.finish(i);for(var o=r.macLength,u="",c=0;o>c;++c)u+=String.fromCharCode(0);var l=s.output.length();l>=o?(t.fragment=s.output.getBytes(l-o),u=s.output.getBytes(o)):t.fragment=s.output.getBytes(),t.fragment=e.util.createBuffer(t.fragment),t.length=t.fragment.length();var p=r.macFunction(r.macKey,r.sequenceNumber,t);return r.updateSequenceNumber(),n=p===u&&n}var s=e.tls;s.CipherSuites.TLS_RSA_WITH_AES_128_CBC_SHA={id:[0,47],name:"TLS_RSA_WITH_AES_128_CBC_SHA",initSecurityParameters:function(e){e.bulk_cipher_algorithm=s.BulkCipherAlgorithm.aes,e.cipher_type=s.CipherType.block,e.enc_key_length=16,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=s.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:t},s.CipherSuites.TLS_RSA_WITH_AES_256_CBC_SHA={id:[0,53],name:"TLS_RSA_WITH_AES_256_CBC_SHA",initSecurityParameters:function(e){e.bulk_cipher_algorithm=s.BulkCipherAlgorithm.aes,e.cipher_type=s.CipherType.block,e.enc_key_length=32,e.block_length=16,e.fixed_iv_length=16,e.record_iv_length=16,e.mac_algorithm=s.MACAlgorithm.hmac_sha1,e.mac_length=20,e.mac_key_length=20},initConnectionState:t}}var t="aesCipherSuites";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/aesCipherSuites",["require","module","./aes","./tls"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){e.debug=e.debug||{},e.debug.storage={},e.debug.get=function(t,r){var n;return"undefined"==typeof t?n=e.debug.storage:t in e.debug.storage&&(n="undefined"==typeof r?e.debug.storage[t]:e.debug.storage[t][r]),n},e.debug.set=function(t,r,n){t in e.debug.storage||(e.debug.storage[t]={}),e.debug.storage[t][r]=n},e.debug.clear=function(t,r){"undefined"==typeof t?e.debug.storage={}:t in e.debug.storage&&("undefined"==typeof r?delete e.debug.storage[t]:delete e.debug.storage[t][r])}}var t="debug";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/debug",["require","module"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){e.log=e.log||{},e.log.levels=["none","error","warning","info","debug","verbose","max"];var t={},r=[],n=null;e.log.LEVEL_LOCKED=2,e.log.NO_LEVEL_CHECK=4,e.log.INTERPOLATE=8;for(var i=0;i<e.log.levels.length;++i){var a=e.log.levels[i];t[a]={index:i,name:a.toUpperCase()}}e.log.logMessage=function(n){for(var i=t[n.level].index,a=0;a<r.length;++a){var s=r[a];if(s.flags&e.log.NO_LEVEL_CHECK)s.f(n);else{var o=t[s.level].index;o>=i&&s.f(s,n)}}},e.log.prepareStandard=function(e){"standard"in e||(e.standard=t[e.level].name+" ["+e.category+"] "+e.message)},e.log.prepareFull=function(t){if(!("full"in t)){var r=[t.message];r=r.concat([]||t.arguments),t.full=e.util.format.apply(this,r)}},e.log.prepareStandardFull=function(t){"standardFull"in t||(e.log.prepareStandard(t),t.standardFull=t.standard)};for(var s=["error","warning","info","debug","verbose"],i=0;i<s.length;++i)(function(t){e.log[t]=function(r,n){var i=Array.prototype.slice.call(arguments).slice(2),a={timestamp:new Date,level:t,category:r,message:n,arguments:i};e.log.logMessage(a)}})(s[i]);if(e.log.makeLogger=function(t){var r={flags:0,f:t};return e.log.setLevel(r,"none"),r},e.log.setLevel=function(t,r){var n=!1;if(t&&!(t.flags&e.log.LEVEL_LOCKED))for(var i=0;i<e.log.levels.length;++i){var a=e.log.levels[i];if(r==a){t.level=r,n=!0;break}}return n},e.log.lock=function(t,r){"undefined"==typeof r||r?t.flags|=e.log.LEVEL_LOCKED:t.flags&=~e.log.LEVEL_LOCKED},e.log.addLogger=function(e){r.push(e)},"undefined"!=typeof console&&"log"in console){var o;if(console.error&&console.warn&&console.info&&console.debug){var u={error:console.error,warning:console.warn,info:console.info,debug:console.debug,verbose:console.debug},c=function(t,r){e.log.prepareStandard(r);var n=u[r.level],i=[r.standard];i=i.concat(r.arguments.slice()),n.apply(console,i)};o=e.log.makeLogger(c)}else{var c=function(t,r){e.log.prepareStandardFull(r),console.log(r.standardFull)};o=e.log.makeLogger(c)}e.log.setLevel(o,"debug"),e.log.addLogger(o),n=o}else console={log:function(){}};if(null!==n){var l=e.util.getQueryVariables();if("console.level"in l&&e.log.setLevel(n,l["console.level"].slice(-1)[0]),"console.lock"in l){var p=l["console.lock"].slice(-1)[0];"true"==p&&e.log.lock(n)}}e.log.consoleLogger=n}var t="log";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/log",["require","module","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t=e.asn1,r=e.pkcs7=e.pkcs7||{};r.messageFromPem=function(n){var i=e.pem.decode(n)[0];if("PKCS7"!==i.type)throw{message:'Could not convert PKCS#7 message from PEM; PEM header type is not "PKCS#7".',headerType:i.type};if(i.procType&&"ENCRYPTED"===i.procType.type)throw{message:"Could not convert PKCS#7 message from PEM; PEM is encrypted."};var a=t.fromDer(i.body);return r.messageFromAsn1(a)},r.messageToPem=function(r,n){var i={type:"PKCS7",body:t.toDer(r.toAsn1()).getBytes()};return e.pem.encode(i,{maxline:n})},r.messageFromAsn1=function(n){var i={},a=[];if(!t.validate(n,r.asn1.contentInfoValidator,i,a))throw{message:"Cannot read PKCS#7 message. ASN.1 object is not an PKCS#7 ContentInfo.",errors:a};var s,o=t.derToOid(i.contentType);switch(o){case e.pki.oids.envelopedData:s=r.createEnvelopedData();break;case e.pki.oids.encryptedData:s=r.createEncryptedData();break;case e.pki.oids.signedData:s=r.createSignedData();break;default:throw{message:"Cannot read PKCS#7 message. ContentType with OID "+o+" is not (yet) supported."}}return s.fromAsn1(i.content.value[0]),s};var n=function(n){var i={},a=[];if(!t.validate(n,r.asn1.recipientInfoValidator,i,a))throw{message:"Cannot read PKCS#7 message. ASN.1 object is not an PKCS#7 EnvelopedData.",errors:a};return{version:i.version.charCodeAt(0),issuer:e.pki.RDNAttributesAsArray(i.issuer),serialNumber:e.util.createBuffer(i.serial).toHex(),encContent:{algorithm:t.derToOid(i.encAlgorithm),parameter:i.encParameter.value,content:i.encKey}}},i=function(r){return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,String.fromCharCode(r.version)),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[e.pki.distinguishedNameToAsn1({attributes:r.issuer}),t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,e.util.hexToBytes(r.serialNumber))]),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(r.encContent.algorithm).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.NULL,!1,"")]),t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,r.encContent.content)])},a=function(e){for(var t=[],r=0;r<e.length;r++)t.push(n(e[r]));return t},s=function(e){for(var t=[],r=0;r<e.length;r++)t.push(i(e[r]));return t},o=function(r){return[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(e.pki.oids.data).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(r.algorithm).getBytes()),t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,r.parameter.getBytes())]),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.OCTETSTRING,!1,r.content.getBytes())])]},u=function(r,n,i){var a={},s=[];if(!t.validate(n,i,a,s))throw{message:"Cannot read PKCS#7 message. ASN.1 object is not an PKCS#7 EnvelopedData.",errors:s};var o=t.derToOid(a.contentType);if(o!==e.pki.oids.data)throw{message:"Unsupported PKCS#7 message. Only contentType Data supported within EnvelopedData."};if(a.encContent){var u="";if(e.util.isArray(a.encContent))for(var c=0;c<a.encContent.length;++c){if(a.encContent[c].type!==t.Type.OCTETSTRING)throw{message:"Malformed PKCS#7 message, expecting encrypted content constructed of only OCTET STRING objects."};u+=a.encContent[c].value}else u=a.encContent;r.encContent={algorithm:t.derToOid(a.encAlgorithm),parameter:e.util.createBuffer(a.encParameter.value),content:e.util.createBuffer(u)}}if(a.content){var u="";if(e.util.isArray(a.content))for(var c=0;c<a.content.length;++c){if(a.content[c].type!==t.Type.OCTETSTRING)throw{message:"Malformed PKCS#7 message, expecting content constructed of only OCTET STRING objects."};u+=a.content[c].value}else u=a.content;r.content=e.util.createBuffer(u)}return r.version=a.version.charCodeAt(0),r.rawCapture=a,a},c=function(t){if(void 0===t.encContent.key)throw{message:"Symmetric key not available."};if(void 0===t.content){var r;switch(t.encContent.algorithm){case e.pki.oids["aes128-CBC"]:case e.pki.oids["aes192-CBC"]:case e.pki.oids["aes256-CBC"]:r=e.aes.createDecryptionCipher(t.encContent.key);break;case e.pki.oids["des-EDE3-CBC"]:r=e.des.createDecryptionCipher(t.encContent.key);break;default:throw{message:"Unsupported symmetric cipher, OID "+t.encContent.algorithm}}if(r.start(t.encContent.parameter),r.update(t.encContent.content),!r.finish())throw{message:"Symmetric decryption failed."};t.content=r.output}};r.createSignedData=function(){var t=null;return t={type:e.pki.oids.signedData,version:1,fromAsn1:function(e){u(t,e,r.asn1.signedDataValidator)}}},r.createEncryptedData=function(){var t=null;return t={type:e.pki.oids.encryptedData,version:0,encContent:{algorithm:e.pki.oids["aes256-CBC"]},fromAsn1:function(e){u(t,e,r.asn1.encryptedDataValidator)},decrypt:function(e){void 0!==e&&(t.encContent.key=e),c(t)}}},r.createEnvelopedData=function(){var n=null;return n={type:e.pki.oids.envelopedData,version:0,recipients:[],encContent:{algorithm:e.pki.oids["aes256-CBC"]},fromAsn1:function(e){var t=u(n,e,r.asn1.envelopedDataValidator);n.recipients=a(t.recipientInfos.value)},toAsn1:function(){return t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.OID,!1,t.oidToDer(n.type).getBytes()),t.create(t.Class.CONTEXT_SPECIFIC,0,!0,[t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,[t.create(t.Class.UNIVERSAL,t.Type.INTEGER,!1,String.fromCharCode(n.version)),t.create(t.Class.UNIVERSAL,t.Type.SET,!0,s(n.recipients)),t.create(t.Class.UNIVERSAL,t.Type.SEQUENCE,!0,o(n.encContent))])])])},findRecipient:function(e){for(var t=e.issuer.attributes,r=0;r<n.recipients.length;++r){var i=n.recipients[r],a=i.issuer;if(i.serialNumber===e.serialNumber&&a.length===t.length){for(var s=!0,o=0;o<t.length;++o)if(a[o].type!==t[o].type||a[o].value!==t[o].value){s=!1;break}if(s)return i}}return null},decrypt:function(t,r){if(void 0===n.encContent.key&&void 0!==t&&void 0!==r)switch(t.encContent.algorithm){case e.pki.oids.rsaEncryption:var i=r.decrypt(t.encContent.content);n.encContent.key=e.util.createBuffer(i);break;default:throw{message:"Unsupported asymmetric cipher, OID "+t.encContent.algorithm}}c(n)},addRecipient:function(t){n.recipients.push({version:0,issuer:t.subject.attributes,serialNumber:t.serialNumber,encContent:{algorithm:e.pki.oids.rsaEncryption,key:t.publicKey}})},encrypt:function(t,r){if(void 0===n.encContent.content){r=r||n.encContent.algorithm,t=t||n.encContent.key;var i,a,s;switch(r){case e.pki.oids["aes128-CBC"]:i=16,a=16,s=e.aes.createEncryptionCipher;break;case e.pki.oids["aes192-CBC"]:i=24,a=16,s=e.aes.createEncryptionCipher;break;case e.pki.oids["aes256-CBC"]:i=32,a=16,s=e.aes.createEncryptionCipher;break;case e.pki.oids["des-EDE3-CBC"]:i=24,a=8,s=e.des.createEncryptionCipher;break;default:throw{message:"Unsupported symmetric cipher, OID "+r}}if(void 0===t)t=e.util.createBuffer(e.random.getBytes(i));else if(t.length()!=i)throw{message:"Symmetric key has wrong length, got "+t.length()+" bytes, expected "+i};n.encContent.algorithm=r,n.encContent.key=t,n.encContent.parameter=e.util.createBuffer(e.random.getBytes(a));var o=s(t);if(o.start(n.encContent.parameter.copy()),o.update(n.content),!o.finish())throw{message:"Symmetric encryption failed."};n.encContent.content=o.output}for(var u=0;u<n.recipients.length;u++){var c=n.recipients[u];if(void 0===c.encContent.content)switch(c.encContent.algorithm){case e.pki.oids.rsaEncryption:c.encContent.content=c.encContent.key.encrypt(n.encContent.key.data);break;default:throw{message:"Unsupported asymmetric cipher, OID "+c.encContent.algorithm}}}}}}}var t="pkcs7";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/pkcs7",["require","module","./aes","./asn1","./des","./pem","./pkcs7asn1","./pki","./random","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){function e(e){var t="forge.task",r=0,n={},i=0;e.debug.set(t,"tasks",n);var a={};e.debug.set(t,"queues",a);var s="?",o=30,u=20,c="ready",l="running",p="blocked",f="sleeping",d="done",h="error",g="stop",y="start",m="block",v="unblock",C="sleep",E="wakeup",b="cancel",T="fail",S={};S[c]={},S[c][g]=c,S[c][y]=l,S[c][b]=d,S[c][T]=h,S[l]={},S[l][g]=c,S[l][y]=l,S[l][m]=p,S[l][v]=l,S[l][C]=f,S[l][E]=l,S[l][b]=d,S[l][T]=h,S[p]={},S[p][g]=p,S[p][y]=p,S[p][m]=p,S[p][v]=p,S[p][C]=p,S[p][E]=p,S[p][b]=d,S[p][T]=h,S[f]={},S[f][g]=f,S[f][y]=f,S[f][m]=f,S[f][v]=f,S[f][C]=f,S[f][E]=f,S[f][b]=d,S[f][T]=h,S[d]={},S[d][g]=d,S[d][y]=d,S[d][m]=d,S[d][v]=d,S[d][C]=d,S[d][E]=d,S[d][b]=d,S[d][T]=h,S[h]={},S[h][g]=h,S[h][y]=h,S[h][m]=h,S[h][v]=h,S[h][C]=h,S[h][E]=h,S[h][b]=h,S[h][T]=h;var I=function(a){this.id=-1,this.name=a.name||s,this.parent=a.parent||null,this.run=a.run,this.subtasks=[],this.error=!1,this.state=c,this.blocks=0,this.timeoutId=null,this.swapTime=null,this.userData=null,this.id=i++,n[this.id]=this,r>=1&&e.log.verbose(t,"[%s][%s] init",this.id,this.name,this)};I.prototype.debug=function(r){r=r||"",e.log.debug(t,r,"[%s][%s] task:",this.id,this.name,this,"subtasks:",this.subtasks.length,"queue:",a)},I.prototype.next=function(e,t){"function"==typeof e&&(t=e,e=this.name);var r=new I({run:t,name:e,parent:this});return r.state=l,r.type=this.type,r.successCallback=this.successCallback||null,r.failureCallback=this.failureCallback||null,this.subtasks.push(r),this},I.prototype.parallel=function(t,r){return e.util.isArray(t)&&(r=t,t=this.name),this.next(t,function(n){var i=n;i.block(r.length);for(var a=function(t,n){e.task.start({type:t,run:function(e){r[n](e)},success:function(){i.unblock()},failure:function(){i.unblock()}})},s=0;s<r.length;s++){var o=t+"__parallel-"+n.id+"-"+s,u=s;a(o,u)}})},I.prototype.stop=function(){this.state=S[this.state][g]},I.prototype.start=function(){this.error=!1,this.state=S[this.state][y],this.state===l&&(this.start=new Date,this.run(this),A(this,0))},I.prototype.block=function(e){e="undefined"==typeof e?1:e,this.blocks+=e,this.blocks>0&&(this.state=S[this.state][m])},I.prototype.unblock=function(e){return e="undefined"==typeof e?1:e,this.blocks-=e,0===this.blocks&&this.state!==d&&(this.state=l,A(this,0)),this.blocks},I.prototype.sleep=function(e){e="undefined"==typeof e?0:e,this.state=S[this.state][C];var t=this;this.timeoutId=setTimeout(function(){t.timeoutId=null,t.state=l,A(t,0)},e)},I.prototype.wait=function(e){e.wait(this)},I.prototype.wakeup=function(){this.state===f&&(cancelTimeout(this.timeoutId),this.timeoutId=null,this.state=l,A(this,0))},I.prototype.cancel=function(){this.state=S[this.state][b],this.permitsNeeded=0,null!==this.timeoutId&&(cancelTimeout(this.timeoutId),this.timeoutId=null),this.subtasks=[]},I.prototype.fail=function(e){if(this.error=!0,F(this,!0),e)e.error=this.error,e.swapTime=this.swapTime,e.userData=this.userData,A(e,0);else{if(null!==this.parent){for(var t=this.parent;null!==t.parent;)t.error=this.error,t.swapTime=this.swapTime,t.userData=this.userData,t=t.parent;F(t,!0)}this.failureCallback&&this.failureCallback(this)}};var B=function(e){e.error=!1,e.state=S[e.state][y],setTimeout(function(){e.state===l&&(e.swapTime=+new Date,e.run(e),A(e,0))},0)},A=function(e,t){var r=t>o||+new Date-e.swapTime>u,n=function(t){if(t++,e.state===l)if(r&&(e.swapTime=+new Date),e.subtasks.length>0){var n=e.subtasks.shift();n.error=e.error,n.swapTime=e.swapTime,n.userData=e.userData,n.run(n),n.error||A(n,t)}else F(e),e.error||null!==e.parent&&(e.parent.error=e.error,e.parent.swapTime=e.swapTime,e.parent.userData=e.userData,A(e.parent,t))};r?setTimeout(n,0):n(t)},F=function(i,s){i.state=d,delete n[i.id],r>=1&&e.log.verbose(t,"[%s][%s] finish",i.id,i.name,i),null===i.parent&&(i.type in a?0===a[i.type].length?e.log.error(t,"[%s][%s] task queue empty [%s]",i.id,i.name,i.type):a[i.type][0]!==i?e.log.error(t,"[%s][%s] task not first in queue [%s]",i.id,i.name,i.type):(a[i.type].shift(),0===a[i.type].length?(r>=1&&e.log.verbose(t,"[%s][%s] delete queue [%s]",i.id,i.name,i.type),delete a[i.type]):(r>=1&&e.log.verbose(t,"[%s][%s] queue start next [%s] remain:%s",i.id,i.name,i.type,a[i.type].length),a[i.type][0].start())):e.log.error(t,"[%s][%s] task queue missing [%s]",i.id,i.name,i.type),s||(i.error&&i.failureCallback?i.failureCallback(i):!i.error&&i.successCallback&&i.successCallback(i)))};e.task=e.task||{},e.task.start=function(n){var i=new I({run:n.run,name:n.name||s});i.type=n.type,i.successCallback=n.success||null,i.failureCallback=n.failure||null,i.type in a?a[n.type].push(i):(r>=1&&e.log.verbose(t,"[%s][%s] create queue [%s]",i.id,i.name,i.type),a[i.type]=[i],B(i))},e.task.cancel=function(e){e in a&&(a[e]=[a[e][0]])},e.task.createCondition=function(){var e={tasks:{}};return e.wait=function(t){t.id in e.tasks||(t.block(),e.tasks[t.id]=t)},e.notify=function(){var t=e.tasks;e.tasks={};for(var r in t)t[r].unblock()},e}}var t="task";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={}),e(forge);var r=!0;define=function(e,t){t(require,module)}}var n,i=function(r,i){i.exports=function(i){var a=n.map(function(e){return r(e)}).concat(e);if(i=i||{},i.defined=i.defined||{},i.defined[t])return i[t];i.defined[t]=!0;for(var s=0;s<a.length;++s)a[s](i);return i[t]}},a=define;(define=function(e,t){return n="string"==typeof e?t.slice(2):e.slice(2),r?(delete define,a.apply(null,Array.prototype.slice.call(arguments,0))):(define=a,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/task",["require","module","./debug","./log","./util"],function(){i.apply(null,Array.prototype.slice.call(arguments,0))})}(),function(){var e="forge";if("function"!=typeof define){if("object"!=typeof module||!module.exports)return"undefined"==typeof forge&&(forge={disableNativeCode:!1}),void 0;var t=!0;define=function(e,t){t(require,module)}}var r,n=function(t,n){n.exports=function(n){var i=r.map(function(e){return t(e)});if(n=n||{},n.defined=n.defined||{},n.defined[e])return n[e];n.defined[e]=!0;for(var a=0;a<i.length;++a)i[a](n);return n},n.exports.disableNativeCode=!1,n.exports(n.exports)},i=define;(define=function(e,n){return r="string"==typeof e?n.slice(2):e.slice(2),t?(delete define,i.apply(null,Array.prototype.slice.call(arguments,0))):(define=i,define.apply(null,Array.prototype.slice.call(arguments,0)))})("../js/forge",["require","module","./aes","./aesCipherSuites","./asn1","./debug","./des","./hmac","./log","./pbkdf2","./pem","./pkcs7","./pkcs1","./pkcs12","./pki","./prng","./pss","./random","./rc2","./task","./tls","./util","./md","./mgf1"],function(){n.apply(null,Array.prototype.slice.call(arguments,0))})}();var dbits,canary=0xdeadbeefcafe,j_lm=15715070==(16777215&canary);j_lm&&"Microsoft Internet Explorer"==navigator.appName?(BigInteger.prototype.am=am2,dbits=30):j_lm&&"Netscape"!=navigator.appName?(BigInteger.prototype.am=am1,dbits=26):(BigInteger.prototype.am=am3,dbits=28),BigInteger.prototype.DB=dbits,BigInteger.prototype.DM=(1<<dbits)-1,BigInteger.prototype.DV=1<<dbits;var BI_FP=52;BigInteger.prototype.FV=Math.pow(2,BI_FP),BigInteger.prototype.F1=BI_FP-dbits,BigInteger.prototype.F2=2*dbits-BI_FP;var BI_RM="0123456789abcdefghijklmnopqrstuvwxyz",BI_RC=new Array,rr,vv;for(rr="0".charCodeAt(0),vv=0;9>=vv;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;36>vv;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;36>vv;++vv)BI_RC[rr++]=vv;Classic.prototype.convert=cConvert,Classic.prototype.revert=cRevert,Classic.prototype.reduce=cReduce,Classic.prototype.mulTo=cMulTo,Classic.prototype.sqrTo=cSqrTo,Montgomery.prototype.convert=montConvert,Montgomery.prototype.revert=montRevert,Montgomery.prototype.reduce=montReduce,Montgomery.prototype.mulTo=montMulTo,Montgomery.prototype.sqrTo=montSqrTo,BigInteger.prototype.copyTo=bnpCopyTo,BigInteger.prototype.fromInt=bnpFromInt,BigInteger.prototype.fromString=bnpFromString,BigInteger.prototype.clamp=bnpClamp,BigInteger.prototype.dlShiftTo=bnpDLShiftTo,BigInteger.prototype.drShiftTo=bnpDRShiftTo,BigInteger.prototype.lShiftTo=bnpLShiftTo,BigInteger.prototype.rShiftTo=bnpRShiftTo,BigInteger.prototype.subTo=bnpSubTo,BigInteger.prototype.multiplyTo=bnpMultiplyTo,BigInteger.prototype.squareTo=bnpSquareTo,BigInteger.prototype.divRemTo=bnpDivRemTo,BigInteger.prototype.invDigit=bnpInvDigit,BigInteger.prototype.isEven=bnpIsEven,BigInteger.prototype.exp=bnpExp,BigInteger.prototype.toString=bnToString,BigInteger.prototype.negate=bnNegate,BigInteger.prototype.abs=bnAbs,BigInteger.prototype.compareTo=bnCompareTo,BigInteger.prototype.bitLength=bnBitLength,BigInteger.prototype.mod=bnMod,BigInteger.prototype.modPowInt=bnModPowInt,BigInteger.ZERO=nbv(0),BigInteger.ONE=nbv(1),NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=nMulTo,NullExp.prototype.sqrTo=nSqrTo,Barrett.prototype.convert=barrettConvert,Barrett.prototype.revert=barrettRevert,Barrett.prototype.reduce=barrettReduce,Barrett.prototype.mulTo=barrettMulTo,Barrett.prototype.sqrTo=barrettSqrTo;
var lowprimes=[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],lplim=(1<<26)/lowprimes[lowprimes.length-1];BigInteger.prototype.chunkSize=bnpChunkSize,BigInteger.prototype.toRadix=bnpToRadix,BigInteger.prototype.fromRadix=bnpFromRadix,BigInteger.prototype.fromNumber=bnpFromNumber,BigInteger.prototype.bitwiseTo=bnpBitwiseTo,BigInteger.prototype.changeBit=bnpChangeBit,BigInteger.prototype.addTo=bnpAddTo,BigInteger.prototype.dMultiply=bnpDMultiply,BigInteger.prototype.dAddOffset=bnpDAddOffset,BigInteger.prototype.multiplyLowerTo=bnpMultiplyLowerTo,BigInteger.prototype.multiplyUpperTo=bnpMultiplyUpperTo,BigInteger.prototype.modInt=bnpModInt,BigInteger.prototype.millerRabin=bnpMillerRabin,BigInteger.prototype.clone=bnClone,BigInteger.prototype.intValue=bnIntValue,BigInteger.prototype.byteValue=bnByteValue,BigInteger.prototype.shortValue=bnShortValue,BigInteger.prototype.signum=bnSigNum,BigInteger.prototype.toByteArray=bnToByteArray,BigInteger.prototype.equals=bnEquals,BigInteger.prototype.min=bnMin,BigInteger.prototype.max=bnMax,BigInteger.prototype.and=bnAnd,BigInteger.prototype.or=bnOr,BigInteger.prototype.xor=bnXor,BigInteger.prototype.andNot=bnAndNot,BigInteger.prototype.not=bnNot,BigInteger.prototype.shiftLeft=bnShiftLeft,BigInteger.prototype.shiftRight=bnShiftRight,BigInteger.prototype.getLowestSetBit=bnGetLowestSetBit,BigInteger.prototype.bitCount=bnBitCount,BigInteger.prototype.testBit=bnTestBit,BigInteger.prototype.setBit=bnSetBit,BigInteger.prototype.clearBit=bnClearBit,BigInteger.prototype.flipBit=bnFlipBit,BigInteger.prototype.add=bnAdd,BigInteger.prototype.subtract=bnSubtract,BigInteger.prototype.multiply=bnMultiply,BigInteger.prototype.divide=bnDivide,BigInteger.prototype.remainder=bnRemainder,BigInteger.prototype.divideAndRemainder=bnDivideAndRemainder,BigInteger.prototype.modPow=bnModPow,BigInteger.prototype.modInverse=bnModInverse,BigInteger.prototype.pow=bnPow,BigInteger.prototype.gcd=bnGCD,BigInteger.prototype.isProbablePrime=bnIsProbablePrime,BigInteger.prototype.square=bnSquare,ECFieldElementFp.prototype.equals=feFpEquals,ECFieldElementFp.prototype.toBigInteger=feFpToBigInteger,ECFieldElementFp.prototype.negate=feFpNegate,ECFieldElementFp.prototype.add=feFpAdd,ECFieldElementFp.prototype.subtract=feFpSubtract,ECFieldElementFp.prototype.multiply=feFpMultiply,ECFieldElementFp.prototype.square=feFpSquare,ECFieldElementFp.prototype.divide=feFpDivide,ECPointFp.prototype.getX=pointFpGetX,ECPointFp.prototype.getY=pointFpGetY,ECPointFp.prototype.equals=pointFpEquals,ECPointFp.prototype.isInfinity=pointFpIsInfinity,ECPointFp.prototype.negate=pointFpNegate,ECPointFp.prototype.add=pointFpAdd,ECPointFp.prototype.twice=pointFpTwice,ECPointFp.prototype.multiply=pointFpMultiply,ECPointFp.prototype.multiplyTwo=pointFpMultiplyTwo,ECCurveFp.prototype.getQ=curveFpGetQ,ECCurveFp.prototype.getA=curveFpGetA,ECCurveFp.prototype.getB=curveFpGetB,ECCurveFp.prototype.equals=curveFpEquals,ECCurveFp.prototype.getInfinity=curveFpGetInfinity,ECCurveFp.prototype.fromBigInteger=curveFpFromBigInteger,ECCurveFp.prototype.reduce=curveReduce,ECCurveFp.prototype.decodePointHex=curveFpDecodePointHex,ECCurveFp.prototype.encodePointHex=curveFpEncodePointHex,X9ECParameters.prototype.getCurve=x9getCurve,X9ECParameters.prototype.getG=x9getG,X9ECParameters.prototype.getN=x9getN,X9ECParameters.prototype.getH=x9getH,Arcfour.prototype.init=ARC4init,Arcfour.prototype.next=ARC4next;var rng_psize=256,rng_state,rng_pool,rng_pptr;if(null==rng_pool){rng_pool=new Array,rng_pptr=0;var t;if(window.crypto&&window.crypto.getRandomValues){var ua=new Uint8Array(32);for(window.crypto.getRandomValues(ua),t=0;32>t;++t)rng_pool[rng_pptr++]=ua[t]}if("Netscape"==navigator.appName&&navigator.appVersion<"5"&&window.crypto){var z=window.crypto.random(32);for(t=0;t<z.length;++t)rng_pool[rng_pptr++]=255&z.charCodeAt(t)}for(;rng_psize>rng_pptr;)t=Math.floor(65536*Math.random()),rng_pool[rng_pptr++]=t>>>8,rng_pool[rng_pptr++]=255&t;rng_pptr=0,rng_seed_time()}SecureRandom.prototype.nextBytes=rng_get_bytes,function e(t,r,n){function i(s,o){if(!r[s]){if(!t[s]){var u="function"==typeof require&&require;if(!o&&u)return u(s,!0);if(a)return a(s,!0);throw new Error("Cannot find module '"+s+"'")}var c=r[s]={exports:{}};t[s][0].call(c.exports,function(e){var r=t[s][1][e];return i(r?r:e)},c,c.exports,e,t,r,n)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(e,t,r){function n(e,t){t.bucket||(t.bucket=i.dhash(e.hashname,t.hashname)),e.buckets[t.bucket]||(e.buckets[t.bucket]=[]),-1==e.buckets[t.bucket].indexOf(t)&&e.buckets[t.bucket].push(t)}var i=e("./utilities");r.bucketize=n},{"./utilities":14}],2:[function(e,t,r){function n(e,t,r){var n=this,i={id:t.id||u.randomHEX(16),inq:[],outq:[],outSeq:0,inDone:-1,outConfirmed:-1,lastAck:-1,callback:r};return n.chans[i.id]=i,i.timeout=t.timeout||a.chan_timeout,t.id||"_"===e.substr(0,1)||(e="_"+e),i.type=e,"_"!=i.type.substr(0,1)&&(i.safe=!0),i.hashname=n.hashname,s.debug("new channel",n.hashname,i.type,i.id),i.wrap=function(e){var t=this;return c[e]?(c[e](t),t):!1},i.done=function(){i.ended||(i.ended=!0,s.debug("channel done",i.id),setTimeout(function(){delete n.chans[i.id]},i.timeout))},i.fail=function(e){i.errored||(i.errored=e,i.callback(e.js.err,e,i,function(){}),i.done())},i.end=function(){i.send({end:!0})},i.err=function(e){i.errored||(i.errored={js:{err:e,c:i.id}},n.send(i.errored),i.done())},i.receive=function(e){if(e.js.err)return i.fail(e);if(i.errored)return i.send(i.errored);e.js.end||(i.lastIn=Date.now());var t=parseInt(e.js.ack);if(t>i.outSeq)return s.warn("bad ack, dropping entirely",i.outSeq,t);var r=Array.isArray(e.js.miss)?e.js.miss:[];if(r.length>100&&(s.warn("too many misses",r.length,i.id,e.from.address),r=r.slice(0,100)),r.length>0||t>i.lastAck){s.debug("miss processing",t,i.lastAck,r,i.outq.length),i.lastAck=t;var n=i.outq;i.outq=[],n.forEach(function(e){return e.js.seq<=t?(e.callback&&e.callback(),void 0):(i.outq.push(e),-1!=r.indexOf(e.js.seq)&&(Date.now()-e.resentAt<1e3||(e.resentAt=Date.now(),i.ack(e))),void 0)})}var o=e.js.seq;if(!(0>o)){if(i.acker||(i.acker=setTimeout(function(){delete i.acker,i.ack()},a.chan_autoack)),o<=i.inDone||i.inq[o-(i.inDone+1)])return i.forceAck=!0,!0;if(o-i.inDone>a.chan_inbuf)return s.warn("chan too far behind, dropping",o,i.inDone,i.id,e.from.address),i.forceAck=!0,!0;i.inq[o-(i.inDone+1)]=e,s.debug("INQ",Object.keys(i.inq),i.inDone,i.handling),i.handler()}},i.handler=function(){if(!i.handling){var e=i.inq[0];!e&&i.inq.length>0&&(i.forceAck=!0),e&&(i.handling=!0,i.safe||(e.js=e.js._||{}),i.callback(e.js.end,e,i,function(){i.inq.shift(),i.inDone++,i.handling=!1,i.handler()}))}},i.resend=function(){if(!i.ended&&i.outq.length){var e=i.outq[i.outq.length-1];if(Date.now()-e.sentAt>i.timeout)return i.fail({js:{err:"timeout"}}),void 0;s.debug("channel resending"),i.ack(e),setTimeout(i.resend,a.chan_resend)}},i.ack=function(e){if(e||s.debug("ACK CHECK",i.id,i.outConfirmed,i.inDone),!e){if(!i.forceAck&&i.outConfirmed==i.inDone)return;e={js:{}}}if(i.forceAck=!1,i.inDone>=0&&(i.outConfirmed=e.js.ack=i.inDone),delete e.js.miss,i.inq.length>0){e.js.miss=[];for(var t=0;t<i.inq.length;t++)i.inq[t]||e.js.miss.push(i.inDone+t+1)}e.js.c=i.id,s.debug("SEND",i.type,JSON.stringify(e.js)),n.send(e),e.js.end&&i.done()},i.send=function(e){if(i.ended)return s.warn("can't send to an ended channel");e||(e={});var t={};return t.js=i.safe?e.js:{_:e.js},e.type&&(t.js.type=e.type),e.end&&(t.js.end=e.end),t.body=e.body,t.callback=e.callback,t.js.seq=i.outSeq++,t.sentAt=Date.now(),i.outq.push(t),i.ack(t),i.resender&&clearTimeout(i.resender),i.resender=setTimeout(i.resend,a.chan_resend),i},t.js&&(t.type=e,i.send(t)),i}function i(e,t,r){function n(){o.timer&&clearTimeout(o.timer),o.timer=setTimeout(function(){i.chans[o.id]&&(delete i.chans[o.id],o.callback("timeout",{js:{err:"timeout"}},o))},o.timeout)}var i=this,o={type:e,callback:r};return o.id=t.id||u.randomHEX(16),i.chans[o.id]=o,o.timeout=t.timeout||a.chan_timeout,o.hashname=i.hashname,s.debug("new unreliable channel",i.hashname,o.type,o.id),o.receive=function(e){(e.js.err||e.js.end)&&delete i.chans[o.id],o.last=e.sender,o.callback(e.js.err||e.js.end,e,o),n()},o.send=function(e){e.js||(e.js={}),e.js.c=o.id,s.debug("SEND",o.type,JSON.stringify(e.js)),!e.to&&o.last&&(e.to=o.last),i.send(e),(e.js.err||e.js.end)&&delete i.chans[o.id],n()},o.fail=function(){},t.js&&(t.js.type=e,o.send(t)),o}var a=e("./defaults"),s=e("./logging"),o=e("./locals"),u=o.local,c={stream:function(e){e.write=function(){},e.callback=function(t,r){return e.read?t.body||t.js.end?(e.read(t.js.err||t.js.end,t.body,r),void 0):r():e.end("no handler")}},bulk:function(e){var t="";e.callback=function(e,r,n,i){i(),r.body&&(t+=r.body),n.onBulk&&e&&n.onBulk(e!==!0?e:!1,t)},e.bulk=function(t,r){for(;t;){var n=t.substr(0,1e3);t=t.substr(1e3);var i={body:n};t||(i.callback=r),e.send(i)}e.end()}},TS:function(e){e.socket={data:"",hashname:e.hashname,id:e.id},e.callback=function(e,t,r,n){0===r.socket.readyState&&(r.socket.readyState=1,r.socket.onopen&&r.socket.onopen()),t.body&&(r.socket.data+=t.body),t.js.done?(r.socket.onmessageack?r.socket.onmessageack(r.socket,n):n(),r.socket.onmessage&&r.socket.onmessage(r.socket),r.socket.data=""):n(),e&&(r.socket.readyState=2,e!==!0&&r.socket.onerror&&r.socket.onerror(e),r.socket.onclose&&r.socket.onclose())},e.socket.readyState=e.lastIn?1:0,e.socket.send=function(t,r){if(1!=e.socket.readyState)return s.debug("sending fail to TS readyState",e.socket.readyState)&&!1;for(;t;){var n=t.substr(0,1e3);t=t.substr(1e3);var i={js:{},body:n};t||(i.callback=r,i.js.done=!0),s.debug("TS SEND",n.length,i.js.done),e.send(i)}},e.socket.close=function(){e.socket.readyState=2,e.done()}}};r.channel=n,r.raw=i,r.channelWraps=c},{"./defaults":5,"./locals":7,"./logging":8}],3:[function(e,t){var r=e("./thforge");r.forge(forge),t.exports=r},{"./thforge":4}],4:[function(e,t,r){!function(e){function t(e,t){var r=E.createKeyPairGenerationState(2048,65537),n=function(){E.stepKeyPairGenerationState(r,100)?e(null,{"public":b.publicKeyToPem(r.keys.publicKey),"private":b.privateKeyToPem(r.keys.privateKey)}):(t&&t(),setTimeout(n,10))};setTimeout(n)}function r(e){var t=C.md.sha256.create();return t.update(e),t.digest().toHex()}function n(e){return b.publicKeyFromPem(e)}function i(e){return b.privateKeyFromPem(e)}function a(e){return"string"==typeof e&&(e=n(e)),T.toDer(b.publicKeyToAsn1(e)).bytes()}function s(e){return b.publicKeyFromAsn1(T.fromDer(e))}function o(e){return a(s(e))}function u(e){return C.util.bytesToHex(C.random.getBytesSync(e))}function c(e,t){return e.length>=t?e:c("0"+e,t)}function l(){var e=getSECCurveByName("secp256r1"),t=e.getN(),r=t.subtract(BigInteger.ONE),n=new BigInteger(t.bitLength(),new SecureRandom),i=n.mod(r).add(BigInteger.ONE),a=e.getG().multiply(i),s="04"+c(a.getX().toBigInteger().toString(16),64)+c(a.getY().toBigInteger().toString(16),64);return a.uncompressed=C.util.hexToBytes(s),{curve:e,"private":i,"public":a}}function p(e,t){t.ecc||(t.ecc=l()),t.lineOut||(t.lineOut=u(16)),t.lineAt||(t.lineAt=Date.now()),t.public||(t.public=s(t.der));var r={};r.at=t.lineAt,r.to=t.hashname,r.line=t.lineOut;var n=m(r,e.der),i={type:"open"},a=C.random.getBytesSync(16);i.iv=C.util.bytesToHex(a);var o=C.md.sha256.create();o.update(t.ecc.public.uncompressed);var c=C.aes.createEncryptionCipher(o.digest(),"CTR");c.start(a),c.update(n),c.finish(),n=c.output;var o=C.md.sha256.create();o.update(n.bytes());var p=e.private.sign(o),o=C.md.sha256.create();o.update(t.ecc.public.uncompressed),o.update(C.util.hexToBytes(t.lineOut));var c=C.aes.createEncryptionCipher(o.digest(),"CTR");c.start(a),c.update(C.util.createBuffer(p)),c.finish(),i.sig=C.util.encode64(c.output.bytes()),i.open=C.util.encode64(t.public.encrypt(t.ecc.public.uncompressed,"RSA-OAEP"));var f=m(i,n);return f}function f(e,t){var r=C.util.decode64(t.js.open),n=e.private.decrypt(r,"RSA-OAEP"),i=C.md.sha256.create();i.update(n);var o=C.aes.createDecryptionCipher(i.digest(),"CTR");o.start(C.util.hexToBytes(t.js.iv)),o.update(C.util.createBuffer(t.body)),o.finish();var u=v(o.output),c=s(u.body),i=C.md.sha256.create();i.update(n),i.update(C.util.hexToBytes(u.js.line));var o=C.aes.createDecryptionCipher(i.digest(),"CTR");o.start(C.util.hexToBytes(t.js.iv)),o.update(C.util.createBuffer(C.util.decode64(t.js.sig))),o.finish();var i=C.md.sha256.create();i.update(t.body);var l=c.verify(i.digest().bytes(),o.output.bytes());return{ecc:n,rsa:a(c),js:u.js,verify:l}}function d(e,t){var r=y(e.ecc.private,t.ecc),n=C.md.sha256.create();n.update(C.util.hexToBytes(r)),n.update(C.util.hexToBytes(e.lineOut)),n.update(C.util.hexToBytes(e.lineIn)),e.encKey=n.digest();var n=C.md.sha256.create();n.update(C.util.hexToBytes(r)),n.update(C.util.hexToBytes(e.lineIn)),n.update(C.util.hexToBytes(e.lineOut)),e.decKey=n.digest()}function h(e,t){var r={type:"line"};r.line=e.lineIn;var n=C.random.getBytesSync(16);r.iv=C.util.bytesToHex(n);var i=m(t.js,t.body),a=C.aes.createEncryptionCipher(e.encKey.copy(),"CTR");return a.start(n),a.update(i),a.finish(),m(r,a.output)}function g(e){var t=C.aes.createDecryptionCipher(e.from.decKey.copy(),"CTR");if(t.start(C.util.hexToBytes(e.js.iv)),t.update(C.util.createBuffer(e.body)),t.finish(),!t.output)return console.log("couldn't decrypt packet",e.js.line,e.sender);var r=v(t.output);return r?(e.js=r.js,e.body=r.body,e.lineok=!0,void 0):console.log("invalid decrypted packet",t.output)}function y(e,t){var r=getSECCurveByName("secp256r1").getCurve(),n=C.util.createBuffer(t);n.getByte();var i=n.getBytes(32),a=n.getBytes(32);if(32!=a.length)return!1;var s=new ECPointFp(r,r.fromBigInteger(new BigInteger(C.util.bytesToHex(i),16)),r.fromBigInteger(new BigInteger(C.util.bytesToHex(a),16))),o=s.multiply(e);return o.getX().toBigInteger().toString(16)}function m(e,t){var r=C.util.createBuffer(e?JSON.stringify(e):"","utf8"),n=r.length(),i=C.util.createBuffer();return i.putInt16(n),i.putBytes(r.getBytes()),"string"==typeof t&&(t=C.util.createBuffer(t)),t&&i.putBytes(t.bytes()),i}function v(e){"string"==typeof e&&(e=C.util.createBuffer(e));var t=e.getInt16(e);if(e.length()<t)return console.log("packet too short",t,e.length(),e)&&!1;var r,n=e.getBytes(t),i=e.getBytes();if(t>0)try{r=JSON.parse(n)}catch(a){return console.log("parse failed",n)&&!1}else r={};return{js:r,body:i}}var C,E,b,T;e.forge=function(t){return C=t,b=t.pki,E=b.rsa,T=t.asn1,e},e.genkey=t,e.pub2key=n,e.pri2key=i,e.der2hn=r,e.key2der=a,e.der2key=s,e.der2der=o,e.randomHEX=u,e.openize=p,e.deopenize=f,e.openline=d,e.lineize=h,e.delineize=g,e.pencode=m,e.pdecode=v}("undefined"==typeof r?this.thforge={}:r)},{}],5:[function(e,t){var r={};r.chan_timeout=1e4,r.seek_timeout=3e3,r.chan_autoack=1e3,r.chan_resend=2e3,r.chan_outbuf=100,r.chan_inbuf=50,r.mesh_timer=25e3,r.nat_timeout=6e4,r.idle_timeout=3e5,r.mesh_max=250,t.exports=r},{}],6:[function(e,t,r){function n(e,t){function r(r,n){n||r.paths.forEach(function(t){(!n||e.possible[t.type])&&(n=e.possible[t.type])}),r.raw("bridge",{js:{to:e.lineIn,from:e.lineOut,path:n}},function(e,n){e!==!0&&o.debug("failed to create bridge",e,r.hashname),e?t(n.sender,r):t(!1,r)})}var n=this;if(o.debug("trying to start a bridge",e.hashname,JSON.stringify(e.possible)),0===Object.keys(e.possible).length)return t();var i;return e.possible.bridge&&e.possible.bridge.via?r(n.whois(e.possible.bridge.via),e.possible.bridge):(Object.keys(n.seeds).forEach(function(e){i||(e=n.seeds[e],e.alive&&e.bridging&&(i=!0,r(e)))}),!i&&e.relay?r(n.whois(e.relay.via)):i?void 0:t())}function i(e,t){if("string"!=typeof t)return o.warn("invalid see address",t);var r=this,n=t.split(",");3!=n.length||4!=n[1].split(".").length||parseInt(n[2]<=0)||n[0]===r.hashname&&(u.isLocalIP(n[1])||(e.isSeed||!r.paths.pub4)&&(o.debug("updating public ipv4",t),r.pathSet({type:"pub4",ip:n[1],port:parseInt(n[2])}),r.address=t))}function a(e,t){function r(){l=l.sort(function(t,r){return u.dhash(e.hashname,t)-u.dhash(e.hashname,r)})}function n(t){Object.keys(s).forEach(function(e){-1==l.indexOf(e)&&l.push(e)}),Object.keys(c).forEach(function(e){-1==l.indexOf(e)&&l.push(e)}),r();for(var n;n=e.seeking.shift();)n(t,l.slice())}function i(t){if(e.seeking.length){if(o.debug("SEEK LOOP",l),0===Object.keys(c).length&&0===l.length)return n("failed to find the hashname");var f=t||l.shift();if(f){if(f==e.hashname)return n();if(s[f]||c[f])return t||i();var d=u.dhash(e.hashname,f);if(d>p)return t||i();a.seeds[f]||(p=d),c[f]=!0;var h=a.whois(f);h.seek(e.hashname,function(e,n){n.forEach(function(e){var t=a.whois(e);if(t!==a){if(!t)return o.warn("bad see",e,h.hashname);t.via(h,e),l.push(t.hashname)}}),r(),s[f]=!0,delete c[f],t||i()})}}}var a=this;"string"==typeof e&&(e=a.whois(e));var s={},c={},l=[],p=255;return a.nearby(e.hashname).forEach(function(t){t!==e&&-1==l.indexOf(t.hashname)&&l.push(t.hashname)}),o.debug("seek starting with",l),r(),e.seeking||(e.seeking=[]),e.seeking.push(t),e===a?n():(e.seeking.length>1||(i(),i(),i(),a.locals.forEach(function(e){i(e.hashname)})),void 0)}function s(e){for(var t=this,r={},n=u.dhash(t.hashname,e);255>=n&&Object.keys(r).length<5;)t.buckets[n]&&t.buckets[n].forEach(function(e){e.alive&&(r[e.hashname]=e)}),n++;Object.keys(r).length<5&&Object.keys(t.lines).forEach(function(e){Object.keys(r).length>=5||t.lines[e].alive&&(r[t.lines[e].hashname]=t.lines[e])});var i=[];return Object.keys(r).forEach(function(e){i.push(r[e])}),i}var o=e("./logging"),u=e("./utilities");r.bridge=n,r.myVia=i,r.seek=a,r.nearby=s},{"./logging":8,"./utilities":14}],7:[function(e,t,r){var n=e("./crypto/node"),i=function(){};r.local=n,r.localize=i},{"./crypto/node":3}],8:[function(e,t,r){var n=function(){console.log.apply(console,arguments)},i=function(){},a=function(){},s=function(e){n=e};r.warn=n,r.debug=i,r.setDebug=a,r.setWarn=s},{}],9:[function(e,t,r){var n=e("./utilities"),i=e("./logging"),a=e("./locals"),s=e("./transport"),o=e("./mesh"),u=e("./defaults"),c=e("./seed"),l=e("./node"),p=e("./dht"),f=e("./channel");r.debug=i.setDebug,r.defaults=u;var d=a.local;r.genkey=d.genkey,r.localize=a.localize,r.isHashname=function(e){return n.isHEX(e,64)},r.channelWraps=f.channelWraps,r.isLocalIP=n.isLocalIP,r.hashname=function(e,t,r){if(!d)return i.warn("thjs.localize() needs to be called first");if(!e||!e.public||!e.private)return i.warn("bad args to hashname, requires key.public and key.private");if(!d.pub2key(e.public)||!d.pri2key(e.private))return i.warn("key.public and key.private must be valid pem strings");if("function"!=typeof t)return i.warn("second arg needs to be a function to send packets, is",typeof t);r||(r={});var a={seeds:[],locals:[],lines:{},bridges:{},all:{},buckets:[],capacity:[],rels:{},raws:{},paths:{},bridgeIVs:{},TSockets:{}};return a.private=d.pri2key(e.private),a.public=d.pub2key(e.public),a.der=d.key2der(a.public),a.address=a.hashname=d.der2hn(a.der),a.nat=!1,a.pcounter=1,a.receive=s.receive,a.send=function(e,r,n){if(!e)return i.warn("send called w/ no network, dropping");if(e.lastOut=Date.now(),"relay"==e.type){var s=a.whois(e.via);return s&&s.chans[e.id]&&s.alive?s.chans[e.id].send({sender:e,js:{type:"relay",to:n.hashname},body:r}):(i.debug("dropping dead relay via",JSON.stringify(e),s&&s.alive),n&&(n.relay=!1),void 0)}"function"==typeof r.length?i.debug("out",r.length()):i.debug("out",r.length,JSON.stringify(e),n&&n.hashname),t(e,r,n)},a.pathSet=function(e){var t=a.paths[e.type]&&JSON.stringify(a.paths[e.type])==JSON.stringify(e);a.paths[e.type]=e,"ipv4"==e.type&&(a.nat=n.isLocalIP(e.ip)),t&&o.meshPing(a)},a.addSeed=c.addSeed,a.whois=l.whois,a.online=l.online,a.listen=function(e,t){return"string"!=typeof e||"function"!=typeof t?i.warn("invalid arguments to listen"):("_"!==e.substr(0,1)&&(e="_"+e),a.rels[e]=t,void 0)},a.raw=function(e,t){return"string"!=typeof e||"function"!=typeof t?i.warn("invalid arguments to raw"):(a.raws[e]=t,void 0)},a.socket=function(e,t){if("string"!=typeof e)return i.warn("invalid TS uri")&&!1;if(0===e.indexOf("ts://")){var r=e.substr(5).split("/"),n=a.whois(r.shift());return n?n.socket(r.join("/")):i.warn("invalid TS hashname")&&!1}return 0!==e.indexOf("/")?i.warn("invalid TS listening uri")&&!1:(i.debug("adding TS listener",e),a.TSockets[e]=t,void 0)},a.rels.ts=s.inTS,a.raws.peer=s.inPeer,a.raws.connect=s.inConnect,a.raws.seek=s.inSeek,a.raws.relay=s.inRelay,a.raws.path=s.inPath,a.raws.bridge=s.inBridge,a.seek=p.seek,a.via=p.myVia,a.bridge=p.bridge,a.nearby=p.nearby,a}},{"./channel":2,"./defaults":5,"./dht":6,"./locals":7,"./logging":8,"./mesh":10,"./node":11,"./seed":12,"./transport":13,"./utilities":14}],10:[function(e,t,r){function n(e){Object.keys(e.lines).forEach(function(t){var r=e.lines[t];(r.elected||Object.keys(r.chans).length>0)&&(Date.now()-r.sentAt+l.mesh_timer<r.timeout()||i(e,r,r))})}function i(e,t,r){o.debug("mesh ping",t.bucket,t.hashname),t.raw("seek",{js:{seek:e.hashname},timeout:3e3},function(n,a){Array.isArray(a.js.see)&&a.js.see.forEach(function(n){var a=e.whois(n);a&&(a.via(t,n),a===e||a.bucket||(a.bucket=u.dhash(e.hashname,r.hashname),void 0===e.capacity[a.bucket]&&(e.capacity[a.bucket]=3),e.capacity[a.bucket]-->=0&&i(e,a,r)))})})}function a(e){e.bridgeIVs={},o.debug("MESHA"),s(e),n(e),o.debug("MESHZ"),setTimeout(function(){a(e)},l.mesh_timer)}function s(e){e.buckets=[],e.capacity=[],Object.keys(e.lines).forEach(function(t){c.bucketize(e,e.lines[t])}),o.debug("BUCKETS",Object.keys(e.buckets));var t=parseInt(l.mesh_max/Object.keys(e.buckets).length);1>=t&&(t=1),Object.keys(e.buckets).forEach(function(r){var n=0;e.buckets[r].forEach(function(e){e.alive&&(e.elected=n++<=t?!0:!1)}),e.capacity[r]=t-n})}var o=e("./logging"),u=e("./utilities"),c=e("./bucket"),l=e("./defaults");r.meshPing=n,r.meshLoop=a},{"./bucket":1,"./defaults":5,"./logging":8,"./utilities":14}],11:[function(e,t,r){function n(e){var t=this;if(!e)return a.warn("whois called without a hashname",e),!1;if("string"!=typeof e)return a.warn("wrong type, should be string",typeof e,e),!1;if(e=e.split(",")[0],!o.isHEX(e,64))return a.warn("whois called without a valid hashname",e),!1;if(e===t.hashname)return t;var r=t.all[e];return r?r:(r=t.all[e]={hashname:e,chans:{},self:t,paths:[],possible:{},isAlive:0},r.address=e,r.at=Date.now(),r.start=p.channel,r.raw=p.raw,r.timeout=function(){var e=r.address.split(",")[1];return e&&t.paths.lan4?o.isLocalIP(t.paths.lan4.ip)&&!o.isLocalIP(e)?u.nat_timeout:u.idle_timeout:u.idle_timeout},r.pathIn=function(e){if(-1==["ipv4","ipv6","http","bridge","relay","webrtc"].indexOf(e.type))return a.warn("unknown path type",JSON.stringify(e)),e;if("relay"==e.type)return r.relay&&r.relay.id==e.id?r.relay:(a.debug("relay incoming",r.hashname,JSON.stringify(e)),r.relay=e,r.alive=!1,setTimeout(function(){a.debug("relay only, trying sync",r.hashname),r.sync(function(){return r.alive?a.debug("relay upgraded, now alive",r.hashname):(t.bridge(r,function(e,t){return a.debug("BRIDGING",r.hashname,e,t&&t.hashname),e?(r.bridge=t.hashname,r.raw("path",{js:{priority:0},direct:e},c.inPath),void 0):a.debug("no bridge")}),void 0)})},10),e);r.alive||a.debug("aliving",r.hashname,JSON.stringify(e)),r.alive=!0;var n=o.pathMatch(e,r.paths);return n||(r.paths.push(e),n=e,r.bridge&&o.pathMatch(e,t.whois(r.bridge).paths)&&(e.priority=-1),"number"!=typeof e.priority&&(e.priority=0),r.paths.length>1&&r.sync(),"ipv4"!=e.type||o.isLocalIP(e.ip)||(r.address=[r.hashname,e.ip,e.port].join(",")),0===e.type.indexOf("ip")&&o.isLocalIP(e.ip)&&(r.isLocal=!0),0!==e.type.indexOf("ip")||o.isLocalIP(e.ip)||(r.isPublic=!0)),n.lastIn=Date.now(),n},r.send=function(e){function n(){if(r.vias){r.sentOpen=!1;var e=r.vias;delete r.vias,Object.keys(e).forEach(function(n){var i=e[n].split(",");if(3==i.length&&4==i[1].split(".").length&&parseInt(i[2])>0){var a={type:"ipv4",ip:i[1],port:parseInt(i[2])};t.send(a,f.pencode()),t.nat&&i[1]==(t.paths.pub4&&t.paths.pub4.ip)&&(r.relayAsk="local")}else r.relayAsk=!0;t.whois(n).peer(r.hashname,r.relayAsk)})}}if(r.lineIn){a.debug("line sending",r.hashname,r.lineIn);var i=e.msg||f.lineize(r,e);if(e.direct)return t.send(e.direct,i,r);r.sentAt=Date.now();for(var s=function(e){return Date.now()-e.lastIn<5e3?!0:e.lastOut?e.lastIn>e.lastOut?!0:e.lastOut-e.lastIn<5e3?!0:!1:!1},o=r.paths.sort(function(t,r){return e.to&&t===e.to?1:t.priority==r.priority?t.lastIn-r.lastIn:r.priority-t.priority}),u=0;u<o.length;u++){var c=o[u],l=s(c);if(l||a.debug("possibly dead path",JSON.stringify(c)),t.send(c,i,r),l)return}if(!r.alive&&r.relay){if(e.sender&&"relay"==e.sender.type)return a.debug("skipping double-relay path",JSON.stringify(e.sender),JSON.stringify(r.relay));if(t.send(r.relay,i,r),r.relay)return}}return a.debug("alive failthrough",r.sendSeek,Object.keys(r.vias||{})),r.alive=!1,r.lastPacket=e,r.open(),r.vias?n():((!r.sendSeek||Date.now()-r.sendSeek>5e3)&&(r.sendSeek=Date.now(),t.seek(r,function(){r.lastPacket&&n()})),void 0)},r.receive=function(e){if(!e.js||!o.isHEX(e.js.c,32))return a.warn("dropping invalid channel packet");a.debug("LINEIN",JSON.stringify(e.js)),r.recvAt=Date.now(),e.sender=r.pathIn(e.sender);var n=r.chans[e.js.c];if(n)return n.receive(e);var i={};if("undefined"==typeof e.js.seq&&(i=t.raws),0===e.js.seq&&(i=t.rels),i[e.js.type]){var s=i==t.raws?"raw":"start";n=r[s](e.js.type,{id:e.js.c},i[e.js.type]),n.receive(e)}else if(!e.js.end&&!e.js.err){a.warn("bouncing unknown channel/type",e.js);var u=e.js.type?"unknown type":"unknown channel";r.send({js:{err:u,c:e.js.c}})}},r.via=function(e,t){return"string"!=typeof t?a.warn("invalid see address",t):(r.vias||(r.vias={}),r.vias[e.hashname]||(r.vias[e.hashname]=t),void 0)},r.seek=function(e,t){function n(){i++,4==i&&t("timed out",[]),i>3||(setTimeout(n,1e3),r.raw("seek",{js:{seek:e}},function(e,r){i>3||(i=5,t(r.js.err,Array.isArray(r.js.see)?r.js.see:[]))}))}var i=0;n()},r.peer=function(e,n){var i={type:"peer",end:!0,peer:e,c:f.randomHEX(16)};i.paths=[],t.paths.pub4&&i.paths.push({type:"ipv4",ip:t.paths.pub4.ip,port:t.paths.pub4.port}),t.paths.pub6&&i.paths.push({type:"ipv6",ip:t.paths.pub6.ip,port:t.paths.pub6.port}),t.paths.http&&i.paths.push({type:"http",http:t.paths.http.http}),r.isLocal&&(t.paths.lan4&&i.paths.push({type:"ipv4",ip:t.paths.lan4.ip,port:t.paths.lan4.port}),t.paths.lan6&&i.paths.push({type:"ipv6",ip:t.paths.lan6.ip,port:t.paths.lan6.port})),(n||0===i.paths.length)&&i.paths.push({type:"relay",id:f.randomHEX(16)}),r.send({js:i})},r.open=function(e){if(r.der){if(!e&&0===r.paths.length)return a.debug("can't open, no path");if(!(r.sentOpen&&Date.now()-r.sentOpen<2e3)){r.sentOpen=Date.now();var n=f.openize(t,r);if(e)if("relay"==e.type){var i=t.whois(e.via);i.raw("relay",{id:e.id,js:{to:r.hashname},body:n},c.inRelayMe)}else t.send(e,n,r);else r.paths.forEach(function(e){t.send(e,n,r)}),r.relay&&t.send(r.relay,n,r)}}},r.sync=function(e){e||(e=function(){}),a.debug("syncing",r.hashname,JSON.stringify(r.paths));var n={};r.paths.forEach(function(e){n[e.type]=!0});var i=r.paths.slice();if(!r.alive&&r.relay&&i.push(r.relay),0===i.length)return e();var s=i.length;i.forEach(function(o){a.debug("PATHLOOP",i.length,JSON.stringify(o));var u={};u.priority="relay"==o.type?0:1;var l=[];!n.ipv4&&t.paths.pub4&&l.push({type:"ipv4",ip:t.paths.pub4.ip,port:t.paths.pub4.port}),!n.ipv6&&t.paths.pub6&&l.push({type:"ipv6",ip:t.paths.pub6.ip,port:t.paths.pub6.port}),!n.http&&t.paths.http&&l.push({type:"http",http:t.paths.http.http}),!n.webrtc&&t.paths.webrtc&&l.push({type:"webrtc",id:f.randomHEX(16)}),"local"==r.relayAsk&&(t.paths.lan4&&l.push({type:"ipv4",ip:t.paths.lan4.ip,port:t.paths.lan4.port}),t.paths.lan6&&l.push({type:"ipv6",ip:t.paths.lan6.ip,port:t.paths.lan6.port})),l.length>0&&(u.paths=l),r.raw("path",{js:u,timeout:3e3,direct:o},function(t,r){t&&t!==!0?o.priority=-10:c.inPath(!0,r),0===--s&&e()})})},r.socket=function(e){e||(e="/");var t=r.start("ts",{id:f.randomHEX(16),js:{path:e}});return t.wrap("TS"),t.socket},r)}function i(e){function t(t){if(n){if(!t)return e(),n=0,void 0;n--,n||e(t)}}var r=this;r.lanToken=f.randomHEX(16),r.send({type:"lan"},f.pencode({type:"lan",lan:r.lanToken})),l.meshLoop(r);var n=r.seeds.length;return n?(r.seeds.forEach(function(e){e.seek(r.hashname,function(n,i){Array.isArray(i)&&i.forEach(function(t){r.via(e,t)}),t(n)})}),void 0):(a.warn("no seeds"),n++,t())}var a=e("./logging"),s=e("./locals"),o=e("./utilities"),u=e("./defaults"),c=e("./transport"),l=e("./mesh"),p=e("./channel"),f=s.local;r.whois=n,r.online=i},{"./channel":2,"./defaults":5,"./locals":7,"./logging":8,"./mesh":10,"./transport":13,"./utilities":14}],12:[function(e,t,r){function n(e){var t=this;if(!e.pubkey)return a.warn("invalid args to addSeed");var r=o.key2der(e.pubkey),n=t.whois(o.der2hn(r));if(!n)return a.warn("invalid seed info",e);if(n!==t){n.der=r;var i;e.ip&&(i={type:"ipv4",ip:e.ip,port:e.port,priority:-2},s.pathMatch(i,n.paths)||n.paths.push(i),n.address=[n.hashname,e.ip,e.port].join(",")),e.ip6&&(i={type:"ipv6",ip:e.ip6,port:e.port6,priority:-1},s.pathMatch(i,n.paths)||n.paths.push(i)),e.http&&(i={type:"http",http:e.http,priority:-2},s.pathMatch(i,n.paths)||n.paths.push(i)),e.bridge&&(n.bridging=!0),n.isSeed=!0,t.seeds.push(n)}}var i=e("./locals"),a=e("./logging"),s=e("./utilities"),o=i.local;r.addSeed=n},{"./locals":7,"./logging":8,"./utilities":14}],13:[function(e,t,r){function n(e,t){var r=this,n=E.pdecode(e);if(!n)return y.warn("failed to decode a packet from",t,e.toString()),void 0;if(0!==Object.keys(n.js).length){n.sender=t,n.id=r.pcounter++,n.at=Date.now(),"function"==typeof e.length?y.debug("in",e.length()):y.debug("in",e.length,n.js.type,n.body&&n.body.length,JSON.stringify(t));var u;switch(n.js.type){case"lan":u=s(r,n);break;case"seed":u=o(r,n);break;case"open":u=a(r,n,t);break;case"line":u=i(r,n,t,e);break;default:y.warn("dropping incoming packet of unknown type",n.js,n.sender)}return u}}function i(e,t,r,n){if("string"!=typeof t.js.iv||32!=t.js.iv.length)return y.warn("missing initialization vector (iv)",r),void 0;var i={};if(i=t.from=e.lines[t.js.line],!i){if(!e.bridges[t.js.line])return y.debug("unknown line received",t.js.line,JSON.stringify(t.sender)),void 0;if(y.debug("BRIDGE",JSON.stringify(e.bridges[t.js.line]),t.js.line),e.bridgeIVs[t.js.iv])return;return e.bridgeIVs[t.js.iv]=!0,e.send(e.bridges[t.js.line],n)}return E.delineize(t),t.lineok?(i.receive(t),void 0):(y.debug("couldn't decrypt line",t.sender),void 0)}function a(e,t,r){if("string"!=typeof t.js.iv||32!=t.js.iv.length)return y.warn("missing initialization vector (iv)",r),void 0;var n=E.deopenize(e,t);if(!n||!n.verify)return y.warn("couldn't decode open",n),void 0;if(!m.isHEX(n.js.line,32))return y.warn("invalid line id enclosed",n.js.line),void 0;if(n.js.to!==e.hashname)return y.warn("open for wrong hashname",n.js.to),void 0;var i=e.whois(E.der2hn(n.rsa));return i?"number"!=typeof n.js.at?(y.warn("invalid at",n.js.at),void 0):(y.debug("inOpen verified",i.hashname),i.recvAt=Date.now(),r=i.pathIn(r),i.openAt&&n.js.at<=i.openAt||(i.openAt=n.js.at,i.der=n.rsa,i.lineIn=n.js.line,i.open(r),E.openline(i,n),y.debug("line open",i.hashname,i.lineOut,i.lineIn),e.lines[i.lineOut]=i,C.bucketize(e,i),i.lastPacket&&(t=i.lastPacket,delete i.lastPacket,i.send(t)),i.local&&-1==e.locals.indexOf(i)&&e.locals.push(i)),void 0):(y.warn("invalid hashname",E.der2hn(n.rsa),n.rsa),void 0)}function s(e,t){t.js.lan!=e.lanToken&&(e.locals.length>0||e.lanSkip!=e.lanToken&&(e.lanSkip=e.lanToken,t.js.type="seed",e.send({type:"lan"},E.pencode(t.js,e.der))))
}function o(e,t){if(t.js.lan==e.lanToken){if(e.locals.length>=5)return y.warn("locals full");if(t.body&&0!==t.body.length){var r=E.der2der(t.body),n=e.whois(E.der2hn(r));return n?(n!==e&&(n.der=r,n.local=!0,y.debug("local seed open",n.hashname,JSON.stringify(t.sender)),n.open(t.sender)),void 0):y.warn("invalid lan request from",t.sender)}}}function u(e,t,r){if(!e){if(!m.isHEX(t.js.seek,64))return y.warn("invalid seek of ",t.js.seek,"from:",t.from.address),void 0;var n={end:!0,see:t.from.self.nearby(t.js.seek).filter(function(e){return e.address}).map(function(e){return e.address}).slice(0,5)};r.send({js:n})}}function c(e,t,r){if(Array.isArray(t.js.paths)&&t.js.paths.forEach(function(e){"string"==typeof e.type&&(m.pathMatch(e,t.from.paths)||(t.from.raw("path",{js:{priority:1},direct:e},c),t.from.possible[e.type]=e))}),"number"==typeof t.js.priority&&(t.sender.priority=t.js.priority),!e){var n="relay"==t.sender.type?0:2;t.from.bridge&&m.pathMatch(t.sender,t.from.self.whois(t.from.bridge).paths)&&(n=1),r.send({js:{end:!0,priority:n}})}}function l(e,t,r){if(!e){var n=t.from.self;if(!m.isHEX(t.js.to,32)||!m.isHEX(t.js.from,32)||"object"!=typeof t.js.path)return y.warn("invalid bridge request",JSON.stringify(t.js),t.from.hashname),void 0;if(!n.bridging&&!t.from.bridging)return r.send({js:{err:"not allowed"}});if("bridge"==t.js.path.type&&t.js.path.local===!0){var i,a=n.whois(t.js.path.id);if(a&&a.paths.forEach(function(e){i||(i=e),e.priority>i.priority&&(i=e)}),!i)return r.send({js:{err:"invalid path"}});t.js.path=i}t.from.bridges||(t.from.bridges={}),t.from.bridges[t.js.to]=t.from.bridges[t.js.from]=!0,y.debug("BRIDGEUP",JSON.stringify(t.js)),n.bridges[t.js.to]=t.js.path,n.bridges[t.js.from]=t.sender,n.bridges[t.js.to].via=n.bridges[t.js.from].via=t.from.hashname,r.send({js:{end:!0}})}}function p(e,t,r,n){if(!e){var i=t.from.self;if(n(),console.log("INTS",t.js),"string"!=typeof t.js.path||!i.TSockets[t.js.path])return r.err("unknown path");r.wrap("TS"),i.TSockets[t.js.path](r.socket),r.send({js:{open:!0}})}}function f(e,t,r){if(!e){if(!t.body)return y.warn("relay in w/ no body",t.js,t.from.address),void 0;var n=t.from.self,i={type:"relay",id:r.id,via:t.from.hashname};n.receive(t.body,i)}}function d(e,t,r){if(!e){var n=t.from.self;if(!m.isHEX(t.js.to,64))return y.warn("invalid relay of",t.js.to,"from",t.from.address),void 0;if(t.js.to==n.hashname)return f(e,t,r);if("relay"==t.sender.type)return y.debug("ignoring relay request from a relay",t.js.to,JSON.stringify(t.sender)),void 0;var i=n.whois(t.js.to);if(i===t.from)return y.warn("can't relay to yourself",t.from.hashname),void 0;if(!i||!i.alive)return y.warn("relay to dead hashname",t.js.to,t.from.address),void 0;if((!t.from.relayed||Date.now()-t.from.relayed>1e3)&&(t.from.relayed=Date.now(),t.from.relays=0),t.from.relays++,t.from.relays>5)return y.debug("relay too fast, dropping",t.from.relays),void 0;y.debug("relay middleman",t.from.hashname,i.hashname),t.from.relayed=Date.now(),i.send(t)}}function h(e,t){if(t.body){var r=t.from.self,n=E.der2der(t.body),i=r.whois(E.der2hn(n));if(!i)return y.warn("invalid connect request from",t.from.address,t.js),void 0;i.der=n;var a=i.sentOpen;Array.isArray(t.js.paths)&&t.js.paths.forEach(function(e){return"string"!=typeof e.type?y.debug("bad path",JSON.stringify(e)):(i.possible[e.type]=e,["bridge","relay"].indexOf(e.type)>=0&&(e.via=t.from.hashname),["bridge","webrtc"].indexOf(e.type)>=0||(i.sentOpen=a,i.open(e)),void 0)}),i.sentOpen==a&&i.open({type:"relay",id:E.randomHEX(16),via:t.from.hashname})}}function g(e,t){if(m.isHEX(t.js.peer,64)){var r=t.from.self,n=r.whois(t.js.peer);if(n.lineIn){var i={type:"connect",end:!0,c:E.randomHEX(16)};if(Array.isArray(t.js.paths)||(t.js.paths=[]),0===t.sender.type.indexOf("ip")){var a=JSON.parse(JSON.stringify(t.sender));delete a.priority,delete a.lastIn,delete a.lastOut,t.js.paths.push(a)}i.paths=[];var s;t.js.paths.forEach(function(e){"string"==typeof e.type&&("relay"!=e.type||"relay"!=t.sender.type)&&(0!==e.type.indexOf("ip")||!m.isLocalIP(e.ip)||n.isLocal)&&("relay"==e.type&&(s=!0),i.paths.push(e))});var o=!1;i.paths.forEach(function(e){n.paths.forEach(function(t){e.type==t.type&&0===e.type.indexOf("ip")&&m.isLocalIP(e.ip)==m.isLocalIP(t.ip)&&(o=[e,t])})}),y.debug("peer viable path results",JSON.stringify(o)),o||(n.bridging=!0,i.paths.push({type:"bridge",id:t.from.hashname,local:!0}),s||"relay"==t.sender.type||i.paths.push({type:"relay",id:E.randomHEX(16)})),n.send({js:i,body:t.from.der})}}}var y=e("./logging"),m=e("./utilities"),v=e("./locals"),C=e("./bucket"),E=v.local;r.receive=n,r.inSeek=u,r.inPath=c,r.inRelayMe=f,r.inRelay=d,r.inTS=p,r.inPeer=g,r.inConnect=h,r.inBridge=l},{"./bucket":1,"./locals":7,"./logging":8,"./utilities":14}],14:[function(e,t,r){function n(e,t){return"string"!=typeof e?!1:e.length!==t?!1:0!==e.replace(/[a-f0-9]+/i,"").length?!1:!0}function i(e,t){var r=a(e),n=a(t);if(!r.length||r.length!=n.length)return-1;for(var i=[-1,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3],s=252,o=0;o<r.length;o++){var u=r[o]^n[o];if(u)return s+i[u];s-=4}return-1}function a(e){for(var t=[],r=0;r<e.length/2;r++){var n=parseInt(e.substr(2*r,2),16);if(isNaN(n))return[];t[t.length]=n>>4,t[t.length]=15&n}return t}function s(e,t){var r;return t.forEach(function(t){switch(e.type){case"ipv4":case"ipv6":e.ip==t.ip&&e.port==t.port&&(r=t);break;case"http":e.http==t.http&&(r=t);break;case"bridge":case"relay":case"webrtc":e.id==t.id&&(r=t)}}),r}function o(e){if(e.indexOf(":")>=0)return 0===e.indexOf("::")?!0:0===e.indexOf("fc00")?!0:0===e.indexOf("fe80")?!0:!1;var t=e.split(".");return"0"==t[0]?!0:"127"==t[0]?!0:"10"==t[0]?!0:"192"==t[0]&&"168"==t[1]?!0:"172"==t[0]&&t[1]>=16&&t[1]<=31?!0:"169"==t[0]&&"254"==t[1]?!0:!1}r.isHEX=n,r.dhash=i,r.isLocalIP=o,r.pathMatch=s},{}],15:[function(e){window.telehash=e("./lib/main")},{"./lib/main":9}]},{},[15]),function(e){function t(e,t){var n=t;return n.send=function(e){n.cached=e},n.chan||e.whois(n.to).start("webrtc",{id:n.id,js:{}},function(t,i,a,s){return s(),t?console.log("rtc error",t):(n.chan=a,r(n,e,!0),void 0)}),n.chan&&r(n,e,!1),n}function r(e,t,r){e.chan.wrap("TS"),e.pch=new thweb.pch({initiate:r,_self:t.hashname,_peer:e.chan.hashname}),e.pch.DEBUG=!0,e.chan.socket.onmessage=function(t){console.log("RTC IN",t);try{t=JSON.parse(t.data)}catch(r){return console.log("rtc parse error",r,t.data),void 0}e.pch.receiveSignal(t)},e.pch.onhavesignal=function(t){console.log("RTC OUT",t.signal,e.chan.socket),e.chan.socket.send(JSON.stringify(t.signal))},e.pch.onconnection=function(){console.log("RTC CONNECTED"),e.send=function(t){e.pch.sendMessage(forge.util.encode64(t))},e.cached&&(e.send(e.cached),delete e.cached)},e.pch.onreceivemessage=function(t){t&&t.data&&me.receive(forge.util.decode64(t.data),{type:"webrtc",id:e.id})}}function n(e,t){return a?(console.log("enabling WebRTC support"),e.paths.webrtc=!0,e.rels.webrtc=function(e,r,n,i){i(),n.send({js:{open:!0}}),t[n.id]=thweb.rtc(me,{chan:n,id:n.id})},void 0):console.log("WebRTC support not found, disabled")}function i(e){e||(e={}),e.reliable=!0;var t={iceServers:[{url:"stun:23.21.150.121"}]},r=e.reliable?{}:{optional:[{RtpDataChannels:!0}]};this._rtc=new a(t,r),this.LOG_SELF=e._self,this.LOG_PEER=e._peer,this._channel=null,this.onhavesignal=null,this.onreceivemessage=null,this.onconnection=null;var n=this,i=this._rtc;e.initiate?this._setupChannel():i.ondatachannel=this._setupChannel.bind(this),i.onnegotiationneeded=function(){n.DEBUG&&console.log(n.LOG_SELF,"saw negotiation trigger and will create an offer"),i.createOffer(function(e){n.DEBUG&&console.log(n.LOG_SELF,"created offer, sending to",n.LOG_PEER),i.setLocalDescription(e,function(){console.log("DONE")}),n._sendSignal(e)},function(e){console.warn(n.LOG_SELF,"failed to create offer",e)})},i.onicecandidate=function(e){e.candidate&&n._sendSignal({candidate:e.candidate})},i.onicechange=function(){n.DEBUG&&console.log(n.LOG_SELF,"ICE change",i.iceGatheringState,i.iceConnectionState)},i.onstatechange=function(){n.DEBUG&&console.log(n.LOG_SELF,"State change",i.signalingState,i.readyState)}}var a=window.mozRTCPeerConnection||window.RTCPeerConnection||window.webkitRTCPeerConnection,s=window.mozRTCSessionDescription||window.RTCSessionDescription||window.webkitRTCSessionDescription,o=window.mozRTCIceCandidate||window.RTCIceCandidate||window.webkitRTCIceCandidate;i.prototype._sendSignal=function(e){if(!this.onhavesignal)throw new Error("Need to send message but `onhavesignal` handler is not set.");this.onhavesignal({target:this,signal:JSON.parse(JSON.stringify(e))})},i.prototype.receiveSignal=function(e){var t=this,r=this._rtc;if(t.DEBUG&&console.log(this.LOG_SELF,"got data",e,"from",this.LOG_PEER),e.sdp)r.setRemoteDescription(new s(e),function(){var e="offer"==r.remoteDescription.type;t.DEBUG&&console.log(t.LOG_SELF,"set offer, now creating answer:",e),e&&r.createAnswer(function(e){t.DEBUG&&console.log(t.LOG_SELF,"got anwer, sending back to",t.LOG_PEER),r.setLocalDescription(e),t._sendSignal(e)},function(e){console.warn(t.LOG_SELF,"couldn't create answer",e)})},function(e){console.warn(t.LOG_SELF,"couldn't set remote description",e)});else if(e.candidate)try{r.addIceCandidate(new o(e.candidate))}catch(n){console.error("Couldn't add candidate",n)}},i.prototype.sendMessage=function(e){var t=this;return this._channel&&"open"===this._channel.readyState?(this._channel.send(e),void 0):(t.DEBUG&&console.log("dropping data, no open channel"),void 0)},i.prototype._setupChannel=function(e){var t=this,r=this._rtc;e&&t.DEBUG&&console.log(this.LOG_SELF,"received data channel",e.channel.readyState),this._channel=e?e.channel:r.createDataChannel("telehash"),this._channel.onopen=function(){t.DEBUG&&console.log(t.LOG_SELF,"DATA CHANNEL IS OPEN",t._channel),t.onconnection&&t.onconnection(t._channel)},this._channel.onmessage=function(e){t.DEBUG&&console.log(t.LOG_SELF,"received message!",e),t.onreceivemessage&&t.onreceivemessage({target:t,data:e.data})},window.mozRTCPeerConnection&&setTimeout(function(){r.onnegotiationneeded()},0),window.dbgChannel=this._channel},i.prototype._tube=function(){var e={},t=this;return e.onmessage=null,e.send=function(e){t.sendMessage(e)},t.onreceivemessage=function(t){e.onmessage&&e.onmessage(t)},e},e.pch=i,e.rtc=t,e.rtcAdd=n}("undefined"==typeof exports?this.thweb={}:exports);var seeds=[{ip:"192.168.0.10",port:42424,ip6:"fe80::22c9:d0ff:fe78:df3b",port6:42424,hashname:"dd1a8765ff03eb3816a620fcf4e94419a961c54ef0f50b81842256e2a935854d",pubkey:"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8IXNQ7Am4ske/3UObgIa\nrhFd6yI6wYjjIRQRRsa57D9FQfWuT3iSX8uXqjhyoRwhqmhn27QBQucloCeki6MX\n431Lh4Tp3ziqnFnf2dvXL2Zop9Yzff0WPkTdkBa+50KdSFvwYZRCKIxhlShAGNqc\nImUSTmCEz0AIH2HSQMY0RfQ1OzSZUm8+BDfObZ+81fxMnzSqh2hTjcQKyz9x0ar4\nZ9vpV0DLrnrd3mc9SDf3nN+7qH2CoIxhqzTv545daQ9PPtc3mvd7a4ta4XeWvRyO\nRNRlknOB7597NUEoSDxjVLBGsLjXOOiVVdv9i1jDdVE0esqjUmjYw6I+iOebGYSN\nEwIDAQAB\n-----END PUBLIC KEY-----\n",http:"http://192.168.0.10:42424",bridge:!0}];