@tmsfe/tms-core 0.0.170 → 0.0.171
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/aes.js +84 -0
- package/src/encrypt.js +327 -0
- package/src/index.js +2 -1
- package/src/jsencrypt.min.js +2 -0
- package/src/md5.js +1 -1
- package/src/report/helper.ts +8 -1
- package/src/report/types.ts +4 -0
- package/src/request.js +175 -60
- package/src/runtime/login.ts +2 -0
- package/src/traceUtils.js +23 -0
- package/src/encrypt/encrypt-util.js +0 -566
- package/src/encrypt/index.js +0 -168
- package/src/encrypt/md5.js +0 -2
- package/src/encrypt/nacl-util.min.js +0 -2
- package/src/encrypt/nacl.min.js +0 -2
- package/src/encrypt/traceUtils.js +0 -24
package/package.json
CHANGED
package/src/aes.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CryptoJS v3.1.2
|
|
3
|
+
code.google.com/p/crypto-js
|
|
4
|
+
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
|
5
|
+
code.google.com/p/crypto-js/wiki/License
|
|
6
|
+
*/
|
|
7
|
+
/* eslint-disable */
|
|
8
|
+
var CryptoJS=CryptoJS||function(u,p){var d={},l=d.lib={},s=function(){},t=l.Base={extend:function(a){s.prototype=this;var c=new s;a&&c.mixIn(a);c.hasOwnProperty("init")||(c.init=function(){c.$super.init.apply(this,arguments)});c.init.prototype=c;c.$super=this;return c},create:function(){var a=this.extend();a.init.apply(a,arguments);return a},init:function(){},mixIn:function(a){for(var c in a)a.hasOwnProperty(c)&&(this[c]=a[c]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.init.prototype.extend(this)}},
|
|
9
|
+
r=l.WordArray=t.extend({init:function(a,c){a=this.words=a||[];this.sigBytes=c!=p?c:4*a.length},toString:function(a){return(a||v).stringify(this)},concat:function(a){var c=this.words,e=a.words,j=this.sigBytes;a=a.sigBytes;this.clamp();if(j%4)for(var k=0;k<a;k++)c[j+k>>>2]|=(e[k>>>2]>>>24-8*(k%4)&255)<<24-8*((j+k)%4);else if(65535<e.length)for(k=0;k<a;k+=4)c[j+k>>>2]=e[k>>>2];else c.push.apply(c,e);this.sigBytes+=a;return this},clamp:function(){var a=this.words,c=this.sigBytes;a[c>>>2]&=4294967295<<
|
|
10
|
+
32-8*(c%4);a.length=u.ceil(c/4)},clone:function(){var a=t.clone.call(this);a.words=this.words.slice(0);return a},random:function(a){for(var c=[],e=0;e<a;e+=4)c.push(4294967296*u.random()|0);return new r.init(c,a)}}),w=d.enc={},v=w.Hex={stringify:function(a){var c=a.words;a=a.sigBytes;for(var e=[],j=0;j<a;j++){var k=c[j>>>2]>>>24-8*(j%4)&255;e.push((k>>>4).toString(16));e.push((k&15).toString(16))}return e.join("")},parse:function(a){for(var c=a.length,e=[],j=0;j<c;j+=2)e[j>>>3]|=parseInt(a.substr(j,
|
|
11
|
+
2),16)<<24-4*(j%8);return new r.init(e,c/2)}},b=w.Latin1={stringify:function(a){var c=a.words;a=a.sigBytes;for(var e=[],j=0;j<a;j++)e.push(String.fromCharCode(c[j>>>2]>>>24-8*(j%4)&255));return e.join("")},parse:function(a){for(var c=a.length,e=[],j=0;j<c;j++)e[j>>>2]|=(a.charCodeAt(j)&255)<<24-8*(j%4);return new r.init(e,c)}},x=w.Utf8={stringify:function(a){try{return decodeURIComponent(escape(b.stringify(a)))}catch(c){throw Error("Malformed UTF-8 data");}},parse:function(a){return b.parse(unescape(encodeURIComponent(a)))}},
|
|
12
|
+
q=l.BufferedBlockAlgorithm=t.extend({reset:function(){this._data=new r.init;this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=x.parse(a));this._data.concat(a);this._nDataBytes+=a.sigBytes},_process:function(a){var c=this._data,e=c.words,j=c.sigBytes,k=this.blockSize,b=j/(4*k),b=a?u.ceil(b):u.max((b|0)-this._minBufferSize,0);a=b*k;j=u.min(4*a,j);if(a){for(var q=0;q<a;q+=k)this._doProcessBlock(e,q);q=e.splice(0,a);c.sigBytes-=j}return new r.init(q,j)},clone:function(){var a=t.clone.call(this);
|
|
13
|
+
a._data=this._data.clone();return a},_minBufferSize:0});l.Hasher=q.extend({cfg:t.extend(),init:function(a){this.cfg=this.cfg.extend(a);this.reset()},reset:function(){q.reset.call(this);this._doReset()},update:function(a){this._append(a);this._process();return this},finalize:function(a){a&&this._append(a);return this._doFinalize()},blockSize:16,_createHelper:function(a){return function(b,e){return(new a.init(e)).finalize(b)}},_createHmacHelper:function(a){return function(b,e){return(new n.HMAC.init(a,
|
|
14
|
+
e)).finalize(b)}}});var n=d.algo={};return d}(Math);
|
|
15
|
+
(function(){var u=CryptoJS,p=u.lib.WordArray;u.enc.Base64={stringify:function(d){var l=d.words,p=d.sigBytes,t=this._map;d.clamp();d=[];for(var r=0;r<p;r+=3)for(var w=(l[r>>>2]>>>24-8*(r%4)&255)<<16|(l[r+1>>>2]>>>24-8*((r+1)%4)&255)<<8|l[r+2>>>2]>>>24-8*((r+2)%4)&255,v=0;4>v&&r+0.75*v<p;v++)d.push(t.charAt(w>>>6*(3-v)&63));if(l=t.charAt(64))for(;d.length%4;)d.push(l);return d.join("")},parse:function(d){var l=d.length,s=this._map,t=s.charAt(64);t&&(t=d.indexOf(t),-1!=t&&(l=t));for(var t=[],r=0,w=0;w<
|
|
16
|
+
l;w++)if(w%4){var v=s.indexOf(d.charAt(w-1))<<2*(w%4),b=s.indexOf(d.charAt(w))>>>6-2*(w%4);t[r>>>2]|=(v|b)<<24-8*(r%4);r++}return p.create(t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}})();
|
|
17
|
+
(function(u){function p(b,n,a,c,e,j,k){b=b+(n&a|~n&c)+e+k;return(b<<j|b>>>32-j)+n}function d(b,n,a,c,e,j,k){b=b+(n&c|a&~c)+e+k;return(b<<j|b>>>32-j)+n}function l(b,n,a,c,e,j,k){b=b+(n^a^c)+e+k;return(b<<j|b>>>32-j)+n}function s(b,n,a,c,e,j,k){b=b+(a^(n|~c))+e+k;return(b<<j|b>>>32-j)+n}for(var t=CryptoJS,r=t.lib,w=r.WordArray,v=r.Hasher,r=t.algo,b=[],x=0;64>x;x++)b[x]=4294967296*u.abs(u.sin(x+1))|0;r=r.MD5=v.extend({_doReset:function(){this._hash=new w.init([1732584193,4023233417,2562383102,271733878])},
|
|
18
|
+
_doProcessBlock:function(q,n){for(var a=0;16>a;a++){var c=n+a,e=q[c];q[c]=(e<<8|e>>>24)&16711935|(e<<24|e>>>8)&4278255360}var a=this._hash.words,c=q[n+0],e=q[n+1],j=q[n+2],k=q[n+3],z=q[n+4],r=q[n+5],t=q[n+6],w=q[n+7],v=q[n+8],A=q[n+9],B=q[n+10],C=q[n+11],u=q[n+12],D=q[n+13],E=q[n+14],x=q[n+15],f=a[0],m=a[1],g=a[2],h=a[3],f=p(f,m,g,h,c,7,b[0]),h=p(h,f,m,g,e,12,b[1]),g=p(g,h,f,m,j,17,b[2]),m=p(m,g,h,f,k,22,b[3]),f=p(f,m,g,h,z,7,b[4]),h=p(h,f,m,g,r,12,b[5]),g=p(g,h,f,m,t,17,b[6]),m=p(m,g,h,f,w,22,b[7]),
|
|
19
|
+
f=p(f,m,g,h,v,7,b[8]),h=p(h,f,m,g,A,12,b[9]),g=p(g,h,f,m,B,17,b[10]),m=p(m,g,h,f,C,22,b[11]),f=p(f,m,g,h,u,7,b[12]),h=p(h,f,m,g,D,12,b[13]),g=p(g,h,f,m,E,17,b[14]),m=p(m,g,h,f,x,22,b[15]),f=d(f,m,g,h,e,5,b[16]),h=d(h,f,m,g,t,9,b[17]),g=d(g,h,f,m,C,14,b[18]),m=d(m,g,h,f,c,20,b[19]),f=d(f,m,g,h,r,5,b[20]),h=d(h,f,m,g,B,9,b[21]),g=d(g,h,f,m,x,14,b[22]),m=d(m,g,h,f,z,20,b[23]),f=d(f,m,g,h,A,5,b[24]),h=d(h,f,m,g,E,9,b[25]),g=d(g,h,f,m,k,14,b[26]),m=d(m,g,h,f,v,20,b[27]),f=d(f,m,g,h,D,5,b[28]),h=d(h,f,
|
|
20
|
+
m,g,j,9,b[29]),g=d(g,h,f,m,w,14,b[30]),m=d(m,g,h,f,u,20,b[31]),f=l(f,m,g,h,r,4,b[32]),h=l(h,f,m,g,v,11,b[33]),g=l(g,h,f,m,C,16,b[34]),m=l(m,g,h,f,E,23,b[35]),f=l(f,m,g,h,e,4,b[36]),h=l(h,f,m,g,z,11,b[37]),g=l(g,h,f,m,w,16,b[38]),m=l(m,g,h,f,B,23,b[39]),f=l(f,m,g,h,D,4,b[40]),h=l(h,f,m,g,c,11,b[41]),g=l(g,h,f,m,k,16,b[42]),m=l(m,g,h,f,t,23,b[43]),f=l(f,m,g,h,A,4,b[44]),h=l(h,f,m,g,u,11,b[45]),g=l(g,h,f,m,x,16,b[46]),m=l(m,g,h,f,j,23,b[47]),f=s(f,m,g,h,c,6,b[48]),h=s(h,f,m,g,w,10,b[49]),g=s(g,h,f,m,
|
|
21
|
+
E,15,b[50]),m=s(m,g,h,f,r,21,b[51]),f=s(f,m,g,h,u,6,b[52]),h=s(h,f,m,g,k,10,b[53]),g=s(g,h,f,m,B,15,b[54]),m=s(m,g,h,f,e,21,b[55]),f=s(f,m,g,h,v,6,b[56]),h=s(h,f,m,g,x,10,b[57]),g=s(g,h,f,m,t,15,b[58]),m=s(m,g,h,f,D,21,b[59]),f=s(f,m,g,h,z,6,b[60]),h=s(h,f,m,g,C,10,b[61]),g=s(g,h,f,m,j,15,b[62]),m=s(m,g,h,f,A,21,b[63]);a[0]=a[0]+f|0;a[1]=a[1]+m|0;a[2]=a[2]+g|0;a[3]=a[3]+h|0},_doFinalize:function(){var b=this._data,n=b.words,a=8*this._nDataBytes,c=8*b.sigBytes;n[c>>>5]|=128<<24-c%32;var e=u.floor(a/
|
|
22
|
+
4294967296);n[(c+64>>>9<<4)+15]=(e<<8|e>>>24)&16711935|(e<<24|e>>>8)&4278255360;n[(c+64>>>9<<4)+14]=(a<<8|a>>>24)&16711935|(a<<24|a>>>8)&4278255360;b.sigBytes=4*(n.length+1);this._process();b=this._hash;n=b.words;for(a=0;4>a;a++)c=n[a],n[a]=(c<<8|c>>>24)&16711935|(c<<24|c>>>8)&4278255360;return b},clone:function(){var b=v.clone.call(this);b._hash=this._hash.clone();return b}});t.MD5=v._createHelper(r);t.HmacMD5=v._createHmacHelper(r)})(Math);
|
|
23
|
+
(function(){var u=CryptoJS,p=u.lib,d=p.Base,l=p.WordArray,p=u.algo,s=p.EvpKDF=d.extend({cfg:d.extend({keySize:4,hasher:p.MD5,iterations:1}),init:function(d){this.cfg=this.cfg.extend(d)},compute:function(d,r){for(var p=this.cfg,s=p.hasher.create(),b=l.create(),u=b.words,q=p.keySize,p=p.iterations;u.length<q;){n&&s.update(n);var n=s.update(d).finalize(r);s.reset();for(var a=1;a<p;a++)n=s.finalize(n),s.reset();b.concat(n)}b.sigBytes=4*q;return b}});u.EvpKDF=function(d,l,p){return s.create(p).compute(d,
|
|
24
|
+
l)}})();
|
|
25
|
+
CryptoJS.lib.Cipher||function(u){var p=CryptoJS,d=p.lib,l=d.Base,s=d.WordArray,t=d.BufferedBlockAlgorithm,r=p.enc.Base64,w=p.algo.EvpKDF,v=d.Cipher=t.extend({cfg:l.extend(),createEncryptor:function(e,a){return this.create(this._ENC_XFORM_MODE,e,a)},createDecryptor:function(e,a){return this.create(this._DEC_XFORM_MODE,e,a)},init:function(e,a,b){this.cfg=this.cfg.extend(b);this._xformMode=e;this._key=a;this.reset()},reset:function(){t.reset.call(this);this._doReset()},process:function(e){this._append(e);return this._process()},
|
|
26
|
+
finalize:function(e){e&&this._append(e);return this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(e){return{encrypt:function(b,k,d){return("string"==typeof k?c:a).encrypt(e,b,k,d)},decrypt:function(b,k,d){return("string"==typeof k?c:a).decrypt(e,b,k,d)}}}});d.StreamCipher=v.extend({_doFinalize:function(){return this._process(!0)},blockSize:1});var b=p.mode={},x=function(e,a,b){var c=this._iv;c?this._iv=u:c=this._prevBlock;for(var d=0;d<b;d++)e[a+d]^=
|
|
27
|
+
c[d]},q=(d.BlockCipherMode=l.extend({createEncryptor:function(e,a){return this.Encryptor.create(e,a)},createDecryptor:function(e,a){return this.Decryptor.create(e,a)},init:function(e,a){this._cipher=e;this._iv=a}})).extend();q.Encryptor=q.extend({processBlock:function(e,a){var b=this._cipher,c=b.blockSize;x.call(this,e,a,c);b.encryptBlock(e,a);this._prevBlock=e.slice(a,a+c)}});q.Decryptor=q.extend({processBlock:function(e,a){var b=this._cipher,c=b.blockSize,d=e.slice(a,a+c);b.decryptBlock(e,a);x.call(this,
|
|
28
|
+
e,a,c);this._prevBlock=d}});b=b.CBC=q;q=(p.pad={}).Pkcs7={pad:function(a,b){for(var c=4*b,c=c-a.sigBytes%c,d=c<<24|c<<16|c<<8|c,l=[],n=0;n<c;n+=4)l.push(d);c=s.create(l,c);a.concat(c)},unpad:function(a){a.sigBytes-=a.words[a.sigBytes-1>>>2]&255}};d.BlockCipher=v.extend({cfg:v.cfg.extend({mode:b,padding:q}),reset:function(){v.reset.call(this);var a=this.cfg,b=a.iv,a=a.mode;if(this._xformMode==this._ENC_XFORM_MODE)var c=a.createEncryptor;else c=a.createDecryptor,this._minBufferSize=1;this._mode=c.call(a,
|
|
29
|
+
this,b&&b.words)},_doProcessBlock:function(a,b){this._mode.processBlock(a,b)},_doFinalize:function(){var a=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){a.pad(this._data,this.blockSize);var b=this._process(!0)}else b=this._process(!0),a.unpad(b);return b},blockSize:4});var n=d.CipherParams=l.extend({init:function(a){this.mixIn(a)},toString:function(a){return(a||this.formatter).stringify(this)}}),b=(p.format={}).OpenSSL={stringify:function(a){var b=a.ciphertext;a=a.salt;return(a?s.create([1398893684,
|
|
30
|
+
1701076831]).concat(a).concat(b):b).toString(r)},parse:function(a){a=r.parse(a);var b=a.words;if(1398893684==b[0]&&1701076831==b[1]){var c=s.create(b.slice(2,4));b.splice(0,4);a.sigBytes-=16}return n.create({ciphertext:a,salt:c})}},a=d.SerializableCipher=l.extend({cfg:l.extend({format:b}),encrypt:function(a,b,c,d){d=this.cfg.extend(d);var l=a.createEncryptor(c,d);b=l.finalize(b);l=l.cfg;return n.create({ciphertext:b,key:c,iv:l.iv,algorithm:a,mode:l.mode,padding:l.padding,blockSize:a.blockSize,formatter:d.format})},
|
|
31
|
+
decrypt:function(a,b,c,d){d=this.cfg.extend(d);b=this._parse(b,d.format);return a.createDecryptor(c,d).finalize(b.ciphertext)},_parse:function(a,b){return"string"==typeof a?b.parse(a,this):a}}),p=(p.kdf={}).OpenSSL={execute:function(a,b,c,d){d||(d=s.random(8));a=w.create({keySize:b+c}).compute(a,d);c=s.create(a.words.slice(b),4*c);a.sigBytes=4*b;return n.create({key:a,iv:c,salt:d})}},c=d.PasswordBasedCipher=a.extend({cfg:a.cfg.extend({kdf:p}),encrypt:function(b,c,d,l){l=this.cfg.extend(l);d=l.kdf.execute(d,
|
|
32
|
+
b.keySize,b.ivSize);l.iv=d.iv;b=a.encrypt.call(this,b,c,d.key,l);b.mixIn(d);return b},decrypt:function(b,c,d,l){l=this.cfg.extend(l);c=this._parse(c,l.format);d=l.kdf.execute(d,b.keySize,b.ivSize,c.salt);l.iv=d.iv;return a.decrypt.call(this,b,c,d.key,l)}})}();
|
|
33
|
+
(function(){for(var u=CryptoJS,p=u.lib.BlockCipher,d=u.algo,l=[],s=[],t=[],r=[],w=[],v=[],b=[],x=[],q=[],n=[],a=[],c=0;256>c;c++)a[c]=128>c?c<<1:c<<1^283;for(var e=0,j=0,c=0;256>c;c++){var k=j^j<<1^j<<2^j<<3^j<<4,k=k>>>8^k&255^99;l[e]=k;s[k]=e;var z=a[e],F=a[z],G=a[F],y=257*a[k]^16843008*k;t[e]=y<<24|y>>>8;r[e]=y<<16|y>>>16;w[e]=y<<8|y>>>24;v[e]=y;y=16843009*G^65537*F^257*z^16843008*e;b[k]=y<<24|y>>>8;x[k]=y<<16|y>>>16;q[k]=y<<8|y>>>24;n[k]=y;e?(e=z^a[a[a[G^z]]],j^=a[a[j]]):e=j=1}var H=[0,1,2,4,8,
|
|
34
|
+
16,32,64,128,27,54],d=d.AES=p.extend({_doReset:function(){for(var a=this._key,c=a.words,d=a.sigBytes/4,a=4*((this._nRounds=d+6)+1),e=this._keySchedule=[],j=0;j<a;j++)if(j<d)e[j]=c[j];else{var k=e[j-1];j%d?6<d&&4==j%d&&(k=l[k>>>24]<<24|l[k>>>16&255]<<16|l[k>>>8&255]<<8|l[k&255]):(k=k<<8|k>>>24,k=l[k>>>24]<<24|l[k>>>16&255]<<16|l[k>>>8&255]<<8|l[k&255],k^=H[j/d|0]<<24);e[j]=e[j-d]^k}c=this._invKeySchedule=[];for(d=0;d<a;d++)j=a-d,k=d%4?e[j]:e[j-4],c[d]=4>d||4>=j?k:b[l[k>>>24]]^x[l[k>>>16&255]]^q[l[k>>>
|
|
35
|
+
8&255]]^n[l[k&255]]},encryptBlock:function(a,b){this._doCryptBlock(a,b,this._keySchedule,t,r,w,v,l)},decryptBlock:function(a,c){var d=a[c+1];a[c+1]=a[c+3];a[c+3]=d;this._doCryptBlock(a,c,this._invKeySchedule,b,x,q,n,s);d=a[c+1];a[c+1]=a[c+3];a[c+3]=d},_doCryptBlock:function(a,b,c,d,e,j,l,f){for(var m=this._nRounds,g=a[b]^c[0],h=a[b+1]^c[1],k=a[b+2]^c[2],n=a[b+3]^c[3],p=4,r=1;r<m;r++)var q=d[g>>>24]^e[h>>>16&255]^j[k>>>8&255]^l[n&255]^c[p++],s=d[h>>>24]^e[k>>>16&255]^j[n>>>8&255]^l[g&255]^c[p++],t=
|
|
36
|
+
d[k>>>24]^e[n>>>16&255]^j[g>>>8&255]^l[h&255]^c[p++],n=d[n>>>24]^e[g>>>16&255]^j[h>>>8&255]^l[k&255]^c[p++],g=q,h=s,k=t;q=(f[g>>>24]<<24|f[h>>>16&255]<<16|f[k>>>8&255]<<8|f[n&255])^c[p++];s=(f[h>>>24]<<24|f[k>>>16&255]<<16|f[n>>>8&255]<<8|f[g&255])^c[p++];t=(f[k>>>24]<<24|f[n>>>16&255]<<16|f[g>>>8&255]<<8|f[h&255])^c[p++];n=(f[n>>>24]<<24|f[g>>>16&255]<<16|f[h>>>8&255]<<8|f[k&255])^c[p++];a[b]=q;a[b+1]=s;a[b+2]=t;a[b+3]=n},keySize:8});u.AES=p._createHelper(d)})();
|
|
37
|
+
CryptoJS.mode.CBC = (function () {
|
|
38
|
+
var CBC = CryptoJS.lib.BlockCipherMode.extend();
|
|
39
|
+
|
|
40
|
+
CBC.Encryptor = CBC.extend({
|
|
41
|
+
processBlock: function (words, offset) {
|
|
42
|
+
var cipher = this._cipher;
|
|
43
|
+
var blockSize = cipher.blockSize;
|
|
44
|
+
|
|
45
|
+
xorBlock.call(this, words, offset, blockSize);
|
|
46
|
+
cipher.encryptBlock(words, offset);
|
|
47
|
+
|
|
48
|
+
this._prevBlock = words.slice(offset, offset + blockSize);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
CBC.Decryptor = CBC.extend({
|
|
53
|
+
processBlock: function (words, offset) {
|
|
54
|
+
var cipher = this._cipher;
|
|
55
|
+
var blockSize = cipher.blockSize;
|
|
56
|
+
|
|
57
|
+
var thisBlock = words.slice(offset, offset + blockSize);
|
|
58
|
+
cipher.decryptBlock(words, offset);
|
|
59
|
+
xorBlock.call(this, words, offset, blockSize);
|
|
60
|
+
|
|
61
|
+
this._prevBlock = thisBlock;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
function xorBlock(words, offset, blockSize) {
|
|
66
|
+
var block;
|
|
67
|
+
|
|
68
|
+
if (this._iv) {
|
|
69
|
+
block = this._iv;
|
|
70
|
+
this._iv = undefined;
|
|
71
|
+
} else {
|
|
72
|
+
block = this._prevBlock;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (var i = 0; i < blockSize; i++) {
|
|
76
|
+
words[offset + i] ^= block[i];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return CBC;
|
|
81
|
+
}());
|
|
82
|
+
module.exports = {
|
|
83
|
+
CryptoJS: CryptoJS
|
|
84
|
+
}
|
package/src/encrypt.js
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @desc: 请求加密
|
|
3
|
+
* jsencrypt用于非对称公钥加密
|
|
4
|
+
* aes目前只保留ecb模式,用于对称加密
|
|
5
|
+
* -------------------------------
|
|
6
|
+
* 1. 获取登录接口拿到的公钥
|
|
7
|
+
* 2. 随机生成一个私钥,保存在整个runtime中
|
|
8
|
+
* 3. 使用私钥加密请求参数,请求header(按需)
|
|
9
|
+
* 4. 使用公钥加密私钥
|
|
10
|
+
* 5. 使用私钥解密返回内容(按需)
|
|
11
|
+
*/
|
|
12
|
+
import JSEncrypt from './jsencrypt.min.js';
|
|
13
|
+
const funAes = require('./aes.js');
|
|
14
|
+
// 加密模式
|
|
15
|
+
const ENCRYPT_MODE_ENUM = {
|
|
16
|
+
ASYMMETRIC_ENCRYPT_1: '1', // 非对称加密
|
|
17
|
+
NO_ENCRYPT_0: '0', // 不加密
|
|
18
|
+
ENCRYPT_COMPRESS: '1', // 加密压缩
|
|
19
|
+
ENCRYPT_NOCOMPRESS_2: '2', // 加密不压缩
|
|
20
|
+
NOENCRYPT_NOCOMPRESS_0: '0', // 不加密不压缩
|
|
21
|
+
};
|
|
22
|
+
// -----------------------------------------------工具函数定义开始-----------------------------------------------------
|
|
23
|
+
// -----------------------------------------------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
// 生成随机的 AES 密钥
|
|
26
|
+
function _generateRandomKey() {
|
|
27
|
+
const keyLength = 16; // AES-128 使用 16 字节的密钥长度
|
|
28
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
29
|
+
let key = '';
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < keyLength; i++) {
|
|
32
|
+
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
33
|
+
key += characters.charAt(randomIndex);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return key;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 使用公钥加密 AES 密钥
|
|
40
|
+
function _encryptWithPublicKey(aesKey, eccPublicKey) {
|
|
41
|
+
const encryptor = new JSEncrypt();
|
|
42
|
+
encryptor.setPublicKey(eccPublicKey);
|
|
43
|
+
const encryptedAesKey = encryptor.encrypt(aesKey)
|
|
44
|
+
.toString(funAes.CryptoJS.enc.Base64)
|
|
45
|
+
.replace(/\+/g, '-')
|
|
46
|
+
.replace(/\//g, '_')
|
|
47
|
+
.replace(/=+$/, '');
|
|
48
|
+
|
|
49
|
+
return encryptedAesKey;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 当前运行时的公钥的管理
|
|
53
|
+
function _getEccPublicKey() {
|
|
54
|
+
return wx.$_publicKey && wx.$_publicKey.publicKey;
|
|
55
|
+
}
|
|
56
|
+
function _getEccPublicId() {
|
|
57
|
+
return wx.$_publicKey && wx.$_publicKey.id;
|
|
58
|
+
}
|
|
59
|
+
// 检查path是否符合下发的路由前缀
|
|
60
|
+
function _checkPathInEnablePrefix(path) {
|
|
61
|
+
if (!_getEccPublicKey()) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (wx.$_publicKey && wx.$_publicKey.path === '*') {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
const prefixArr = wx.$_publicKey && wx.$_publicKey.path ? wx.$_publicKey.path.split(',').map(item => item.trim()) : [];
|
|
68
|
+
for (let i = 0, len = prefixArr.length; i < len; i++) {
|
|
69
|
+
if (path.indexOf(prefixArr[i]) > -1) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 获取私钥
|
|
77
|
+
let privateKeyInfo = null;
|
|
78
|
+
const _getPrivateKeyInfo = (enforceUpdate) => {
|
|
79
|
+
if (!privateKeyInfo || enforceUpdate || privateKeyInfo.publicKeyId !== _getEccPublicId()) {
|
|
80
|
+
const aesKey = _generateRandomKey();
|
|
81
|
+
const encryptAesKey = _encryptWithPublicKey(aesKey, _getEccPublicKey());
|
|
82
|
+
privateKeyInfo = {
|
|
83
|
+
aesKey,
|
|
84
|
+
encryptAesKey,
|
|
85
|
+
publicKeyId: _getEccPublicId(),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return privateKeyInfo;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// 使用 AES 密钥加密 header 和 body
|
|
92
|
+
function _aesEncrypt(word, aesKey) {
|
|
93
|
+
// 使用 _generateRandomKey 生成随机的 IV
|
|
94
|
+
let iv = _generateRandomKey();
|
|
95
|
+
const key = funAes.CryptoJS.enc.Utf8.parse(aesKey);
|
|
96
|
+
iv = funAes.CryptoJS.enc.Utf8.parse(iv);
|
|
97
|
+
const srcs = funAes.CryptoJS.enc.Utf8.parse(word);
|
|
98
|
+
const encrypted = funAes.CryptoJS.AES.encrypt(srcs, key, {
|
|
99
|
+
iv, mode: funAes.CryptoJS.mode.CBC, padding: funAes.CryptoJS.pad.Pkcs7,
|
|
100
|
+
});
|
|
101
|
+
const combined = iv.concat(encrypted.ciphertext);
|
|
102
|
+
return combined.toString(funAes.CryptoJS.enc.Base64)
|
|
103
|
+
.replace(/\+/g, '-')
|
|
104
|
+
.replace(/\//g, '_')
|
|
105
|
+
.replace(/=+$/, '');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 解密
|
|
109
|
+
const _aesDecrypt = (cipherText, aesKey) => {
|
|
110
|
+
function decodeBase64URL(input) {
|
|
111
|
+
// 添加适当的填充
|
|
112
|
+
const paddedInput = input + '='.repeat((4 - input.length % 4) % 4);
|
|
113
|
+
// 使用Base64URL解码
|
|
114
|
+
return funAes.CryptoJS.enc.Base64.parse(paddedInput.replace(/-/g, '+').replace(/_/g, '/'));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const key = funAes.CryptoJS.enc.Utf8.parse(aesKey);
|
|
118
|
+
// 解析Base64URL格式的密文
|
|
119
|
+
const cipherBytes = decodeBase64URL(cipherText);
|
|
120
|
+
// 分离IV和密文
|
|
121
|
+
const blockSize = 16; // AES的块大小是16字节
|
|
122
|
+
const iv = funAes.CryptoJS.lib.WordArray.create(cipherBytes.words.slice(0, blockSize / 4));
|
|
123
|
+
const encryptedBytes = funAes.CryptoJS.lib.WordArray.create(cipherBytes.words.slice(blockSize / 4));
|
|
124
|
+
|
|
125
|
+
// 使用CBC模式和PKCS7填充解密
|
|
126
|
+
const decrypted = funAes.CryptoJS.AES.decrypt({ ciphertext: encryptedBytes }, key, {
|
|
127
|
+
iv,
|
|
128
|
+
mode: funAes.CryptoJS.mode.CBC,
|
|
129
|
+
padding: funAes.CryptoJS.pad.Pkcs7,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// 去除PKCS7填充
|
|
133
|
+
const decryptedText = decrypted.toString(funAes.CryptoJS.enc.Utf8);
|
|
134
|
+
return decryptedText;
|
|
135
|
+
};
|
|
136
|
+
// -----------------------------------------------------------------------------------------------------------------
|
|
137
|
+
// -----------------------------------------------工具函数定义结束-----------------------------------------------------
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 加密请求内容
|
|
141
|
+
* @param {String} method 请求方式,同wx.request
|
|
142
|
+
* @param {string/object/ArrayBuffer} params 请求参数
|
|
143
|
+
* @param {Object} header 用户自定义请求header
|
|
144
|
+
* @param {String} encryptedResponseHeaderName 期望加密的返回响应头,多个Header用,分隔
|
|
145
|
+
* @returns {header: Object, data: String}
|
|
146
|
+
*/
|
|
147
|
+
const reqEncrypt = (method, params = {}, header = {}, encryptedResponseHeaderName = '') => {
|
|
148
|
+
let finalData = params;
|
|
149
|
+
const { aesKey, encryptAesKey, publicKeyId } = _getPrivateKeyInfo();
|
|
150
|
+
// 1. 处理请求参数
|
|
151
|
+
if (method.toUpperCase() === 'GET') {
|
|
152
|
+
const searchParams = Object.keys(params)
|
|
153
|
+
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
|
|
154
|
+
.join('&');
|
|
155
|
+
const encodedParams = _aesEncrypt(searchParams, aesKey);
|
|
156
|
+
finalData = { tmsec: encodedParams };
|
|
157
|
+
} else {
|
|
158
|
+
finalData = _aesEncrypt(JSON.stringify(params), aesKey);
|
|
159
|
+
}
|
|
160
|
+
// 2. 处理Headers
|
|
161
|
+
const encodedHeaders = _aesEncrypt(JSON.stringify(header), aesKey);
|
|
162
|
+
return {
|
|
163
|
+
header: {
|
|
164
|
+
'X-Encrypt-Mode': ENCRYPT_MODE_ENUM.ASYMMETRIC_ENCRYPT_1,
|
|
165
|
+
'X-Compress-Mode': 'none',
|
|
166
|
+
'X-Encrypted-Headers': encodedHeaders,
|
|
167
|
+
'X-Encrypt-Pub': publicKeyId,
|
|
168
|
+
'X-Encrypt-Key': encryptAesKey,
|
|
169
|
+
'X-Encrypt-Response': ENCRYPT_MODE_ENUM.ENCRYPT_NOCOMPRESS_2,
|
|
170
|
+
'X-Response-Header-Name': encryptedResponseHeaderName,
|
|
171
|
+
},
|
|
172
|
+
data: finalData,
|
|
173
|
+
aesKey,
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// 解密请求结果
|
|
178
|
+
const resDecrypt = (aesKey, header, data) => {
|
|
179
|
+
const formatHeader = {};
|
|
180
|
+
Object.keys(header).forEach((key) => {
|
|
181
|
+
formatHeader[key.toLocaleLowerCase()] = header[key];
|
|
182
|
+
});
|
|
183
|
+
const {
|
|
184
|
+
// 'x-encrypt-key': encryptKey, // 使用ECC公钥加密后的AES秘钥
|
|
185
|
+
'x-encrypt-response': encryptResponse, // 期望的响应加密模式1: 加密、压缩 2: 加密、不压缩
|
|
186
|
+
'x-response-headfer-name': encryptedResponseHeaderName, // 需要加密的响应Header: X-Header1,X-Header2
|
|
187
|
+
'x-encrypted-headers': encryptedHeaders, // 加密后的Header信息
|
|
188
|
+
} = formatHeader;
|
|
189
|
+
if (!encryptResponse || encryptResponse === ENCRYPT_MODE_ENUM.NOENCRYPT_NOCOMPRESS_0) {
|
|
190
|
+
// 不需要解密,直接返回
|
|
191
|
+
return {
|
|
192
|
+
success: true,
|
|
193
|
+
errMsg: 'success',
|
|
194
|
+
header,
|
|
195
|
+
data,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
let decryptedHeaders = {};
|
|
200
|
+
if (encryptedResponseHeaderName) {
|
|
201
|
+
// 解密响应Header
|
|
202
|
+
decryptedHeaders = JSON.parse(_aesDecrypt(encryptedHeaders, aesKey));
|
|
203
|
+
}
|
|
204
|
+
// 解密响应Body
|
|
205
|
+
const decryptedBody = _aesDecrypt(data, aesKey);
|
|
206
|
+
return {
|
|
207
|
+
success: true,
|
|
208
|
+
errMsg: 'success',
|
|
209
|
+
header: {
|
|
210
|
+
...header,
|
|
211
|
+
...decryptedHeaders,
|
|
212
|
+
},
|
|
213
|
+
data: JSON.parse(decryptedBody),
|
|
214
|
+
};
|
|
215
|
+
} catch (err) {
|
|
216
|
+
return {
|
|
217
|
+
success: false,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 更新秘钥信息:更新公钥,同时生成新的私钥
|
|
224
|
+
* @param {String: publicKey, Number: expireDate, String: id } param0
|
|
225
|
+
*/
|
|
226
|
+
const updateDecryptKey = (publicKeyInfo) => {
|
|
227
|
+
if (!publicKeyInfo) {
|
|
228
|
+
wx.$_publicKey = null;
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const { publicKey, expireDate, id, path } = publicKeyInfo;
|
|
232
|
+
// 1. 存储新的公钥
|
|
233
|
+
wx.$_publicKey = {
|
|
234
|
+
publicKey,
|
|
235
|
+
expireDate,
|
|
236
|
+
id,
|
|
237
|
+
path,
|
|
238
|
+
};
|
|
239
|
+
// 2. 生成新的私钥
|
|
240
|
+
_getPrivateKeyInfo(true);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// 不参与加密的请求路径规则
|
|
244
|
+
const encryptPathRule = {
|
|
245
|
+
'tim.map.qq.com': ['^/user/login', '^/api/getClientConfigs', '^/basic/crypto/lastkey'],
|
|
246
|
+
'tim.sparta.html5.qq.com': [
|
|
247
|
+
'^/user/login',
|
|
248
|
+
'^/cnabroad', '^~/ReChargeCard/', '^/gasolinerecharge/v2/', '^/gasolinerecharge/rechargecard/',
|
|
249
|
+
'^/tde', '^/basic/crypto/lastkey',
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
function needsEncryption(url, params) {
|
|
253
|
+
// 判断是否属于加密白名单, 如果不符合,直接返回false, 如果符合,则走下面的逻辑
|
|
254
|
+
const enablePathPrefix = _checkPathInEnablePrefix(url);
|
|
255
|
+
if (!enablePathPrefix) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
// 如果是日志上报接口,需要过滤性能日志,不需要加密
|
|
259
|
+
if (url.indexOf('basic/event/upload') > -1) {
|
|
260
|
+
if (params.batch?.length === 1 && params.batch[0][31] === 'tms-performance-log') {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
// 使用正则表达式解析URL
|
|
266
|
+
const urlPattern = /^(https?:\/\/)?([^/?#]+)([/?#].*)?$/;
|
|
267
|
+
const matches = url.match(urlPattern);
|
|
268
|
+
|
|
269
|
+
if (!matches) {
|
|
270
|
+
console.error('Invalid URL:', url);
|
|
271
|
+
return false; // 如果URL无效,默认返回false
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const domain = matches[2];
|
|
275
|
+
const path = matches[3] || '/';
|
|
276
|
+
|
|
277
|
+
if (encryptPathRule[domain]) {
|
|
278
|
+
const pathRules = encryptPathRule[domain];
|
|
279
|
+
for (const rule of pathRules) {
|
|
280
|
+
const regex = new RegExp(rule);
|
|
281
|
+
if (regex.test(path)) {
|
|
282
|
+
return false; // 匹配到规则,不需要加密
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return true; // 此域名下,默认需要加密
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return false; // 没有匹配到规则,不需要加密
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// 判断是否是加密相关的错误类型(因为rawresponse的配置,需要errcode和errmessage共同来确定加密错误类型)
|
|
292
|
+
const ErrCodeType = {
|
|
293
|
+
pubKeyIdInvalid: '11_Invalid public key!',
|
|
294
|
+
pubKeyExpired: '12_Expired public key!',
|
|
295
|
+
aesCipherInvalid: '13_Invalid AES cipher!',
|
|
296
|
+
decryptError: '14_Decrypt error!',
|
|
297
|
+
cryptoDisabled: '15_Crypto disabled!',
|
|
298
|
+
};
|
|
299
|
+
const reqErrType = {
|
|
300
|
+
pubKeyInvalid: 'pubKeyInvalid',
|
|
301
|
+
decryptError: 'decryptError',
|
|
302
|
+
cryptoDisabled: 'cryptoDisabled',
|
|
303
|
+
};
|
|
304
|
+
const getErrcodeType = (errCode, errMsg) => {
|
|
305
|
+
const errType = `${errCode}_${errMsg}`;
|
|
306
|
+
if (ErrCodeType.decryptError === errType) {
|
|
307
|
+
return reqErrType.decryptError;
|
|
308
|
+
}
|
|
309
|
+
if (ErrCodeType.cryptoDisabled === errType) {
|
|
310
|
+
return reqErrType.cryptoDisabled;
|
|
311
|
+
}
|
|
312
|
+
if ([ErrCodeType.pubKeyIdInvalid, ErrCodeType.pubKeyExpired, ErrCodeType.aesCipherInvalid].indexOf(errType) > -1) {
|
|
313
|
+
return reqErrType.pubKeyInvalid;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const encryptObj = {
|
|
318
|
+
reqEncrypt,
|
|
319
|
+
resDecrypt,
|
|
320
|
+
updateDecryptKey,
|
|
321
|
+
needsEncryption,
|
|
322
|
+
getErrcodeType,
|
|
323
|
+
reqErrType,
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
export default encryptObj;
|
package/src/index.js
CHANGED
|
@@ -110,6 +110,7 @@ const getLocationBaseClass = () => LocationBase;
|
|
|
110
110
|
const init = (options = {}) => {
|
|
111
111
|
const {
|
|
112
112
|
appVersion, wxAppId, secretKey = '', client, defaultHost, cloudEnvId, appEnv, appPagePaths, homePage,
|
|
113
|
+
requestEncryptOpen,
|
|
113
114
|
} = options;
|
|
114
115
|
const envInfo = {
|
|
115
116
|
wxAppId,
|
|
@@ -151,7 +152,7 @@ const init = (options = {}) => {
|
|
|
151
152
|
|
|
152
153
|
Request.defaultHost = defaultHost;
|
|
153
154
|
Request.defaultSecretKey = secretKey;
|
|
154
|
-
Request.
|
|
155
|
+
Request.requestEncryptOpen = requestEncryptOpen;
|
|
155
156
|
// 初始化云环境
|
|
156
157
|
wx.cloud.init({ env: cloudEnvId });
|
|
157
158
|
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(t.JSEncrypt={})}(this,(function(t){"use strict";function r(t){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t)}var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var e,o=function(t,r){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var i in r)r.hasOwnProperty(i)&&(t[i]=r[i])})(t,r)},n={decode:function(t){var r;if(void 0===e){var i="= \f\n\r\t \u2028\u2029";for(e=Object.create(null),r=0;r<64;++r)e["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r)]=r;for(r=0;r<9;++r)e[i.charAt(r)]=-1}var o=[],n=0,s=0;for(r=0;r<t.length;++r){var h=t.charAt(r);if("="==h)break;if(-1!=(h=e[h])){if(void 0===h)throw new Error("ico"+r);n|=h,4<=++s?(o[o.length]=n>>16,o[o.length]=n>>8&255,o[o.length]=255&n,s=n=0):n<<=6}}switch(s){case 1:throw new Error("bee");case 2:o[o.length]=n>>10;break;case 3:o[o.length]=n>>16,o[o.length]=n>>8&255}return o},re:/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,unarmor:function(t){var r=n.re.exec(t);if(r)if(r[1])t=r[1];else{if(!r[2])throw new Error("ros");t=r[2]}return n.decode(t)}};var s=function(){function t(r,i){this.hexDigits="0123456789ABCDEF",r instanceof t?(this.enc=r.enc,this.pos=r.pos):(this.enc=r,this.pos=i)}return t.prototype.get=function(t){if(void 0===t&&(t=this.pos++),t>=this.enc.length)throw new Error("Requesting byte offset "+t+" on a stream of length "+this.enc.length);return"string"==typeof this.enc?this.enc.charCodeAt(t):this.enc[t]},t.prototype.hexByte=function(t){return this.hexDigits.charAt(t>>4&15)+this.hexDigits.charAt(15&t)},t.prototype.hexDump=function(t,r,i){for(var e="",o=t;o<r;++o)if(e+=this.hexByte(this.get(o)),!0!==i)switch(15&o){case 7:e+=" ";break;case 15:e+="\n";break;default:e+=" "}return e},t}(),h=function(){function t(t,r,i,e,o){if(!(e instanceof u))throw new Error("iv");this.stream=t,this.header=r,this.length=i,this.tag=e,this.sub=o}return t.prototype.posStart=function(){return this.stream.pos},t.prototype.posEnd=function(){return this.stream.pos+this.header+Math.abs(this.length)},t.prototype.toHexString=function(){return this.stream.hexDump(this.posStart(),this.posEnd(),!0)},t.decodeLength=function(t){var r=t.get(),i=127&r;if(i==r)return i;if(6<i)throw new Error("lns"+(t.pos-1));if(0===i)return null;for(var e=r=0;e<i;++e)r=256*r+t.get();return r},t.prototype.getHexStringValue=function(){var t=this.toHexString(),r=2*this.header,i=2*this.length;return t.substr(r,i)},t.decode=function(r){var i;i=r instanceof s?r:new s(r,0);var e=new s(i),o=new u(i),n=t.decodeLength(i),h=i.pos,f=h-e.pos,a=null,p=function(){var r=[];if(null!==n){for(var e=h+n;i.pos<e;)r[r.length]=t.decode(i);if(i.pos!=e)throw new Error("Content size is not correct for container starting at offset "+h)}else try{for(;;){var o=t.decode(i);if(o.tag.isEOC())break;r[r.length]=o}n=h-i.pos}catch(r){throw new Error("Exception while decoding undefined length content: "+r)}return r};if(o.tagConstructed)a=p();else if(o.isUniversal()&&(3==o.tagNumber||4==o.tagNumber))try{if(3==o.tagNumber&&0!=i.get())throw new Error("bsu");a=p();for(var c=0;c<a.length;++c)if(a[c].tag.isEOC())throw new Error("EOC")}catch(r){a=null}if(null===a){if(null===n)throw new Error("a"+h);i.pos=h+Math.abs(n)}return new t(e,f,n,o,a)},t}(),u=function(){function t(t){var r=t.get();if(this.tagClass=r>>6,this.tagConstructed=!!(32&r),this.tagNumber=31&r,31==this.tagNumber){for(var i=new y;r=t.get(),i.mulAdd(128,127&r),128&r;);this.tagNumber=i.simplify()}}return t.prototype.isUniversal=function(){return 0===this.tagClass},t.prototype.isEOC=function(){return 0===this.tagClass&&0===this.tagNumber},t}(),f=function(){function t(t,r,i){null!=t&&("number"==typeof t?this.fromNumber(t,r,i):null==r&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,r))}return t.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var i;if(16==t)i=4;else if(8==t)i=3;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return this.toRadix(t);i=2}var e,o=(1<<i)-1,n=!1,s="",h=this.t,u=this.DB-h*this.DB%i;if(0<h--)for(u<this.DB&&0<(e=this[h]>>u)&&(n=!0,s=r(e));0<=h;)u<i?(e=(this[h]&(1<<u)-1)<<i-u,e|=this[--h]>>(u+=this.DB-i)):(e=this[h]>>(u-=i)&o,u<=0&&(u+=this.DB,--h)),0<e&&(n=!0),n&&(s+=r(e));return n?s:"0"},t.prototype.abs=function(){return this.s<0?this.negate():this},t.prototype.compareTo=function(t){var r=this.s-t.s;if(0!=r)return r;var i=this.t;if(0!=(r=i-t.t))return this.s<0?-r:r;for(;0<=--i;)if(0!=(r=this[i]-t[i]))return r;return 0},t.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+S(this[this.t-1]^this.s&this.DM)},t.prototype.modPowInt=function(t,r){var i;return i=t<256||r.isEven()?new a(r):new p(r),this.exp(t,i)},t.prototype.copyTo=function(t){for(var r=this.t-1;0<=r;--r)t[r]=this[r];t.t=this.t,t.s=this.s},t.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,0<t?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},t.prototype.fromString=function(r,i){var e;if(16==i)e=4;else if(8==i)e=3;else if(256==i)e=8;else if(2==i)e=1;else if(32==i)e=5;else{if(4!=i)return void this.fromRadix(r,i);e=2}this.t=0,this.s=0;for(var o=r.length,n=!1,s=0;0<=--o;){var h=8==e?255&+r[o]:b(r,o);h<0?"-"==r.charAt(o)&&(n=!0):(n=!1,0==s?this[this.t++]=h:s+e>this.DB?(this[this.t-1]|=(h&(1<<this.DB-s)-1)<<s,this[this.t++]=h>>this.DB-s):this[this.t-1]|=h<<s,(s+=e)>=this.DB&&(s-=this.DB))}8==e&&!!(128&+r[0])&&(this.s=-1,0<s&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),n&&t.ZERO.subTo(this,this)},t.prototype.clamp=function(){for(var t=this.s&this.DM;0<this.t&&this[this.t-1]==t;)--this.t},t.prototype.dlShiftTo=function(t,r){var i;for(i=this.t-1;0<=i;--i)r[i+t]=this[i];for(i=t-1;0<=i;--i)r[i]=0;r.t=this.t+t,r.s=this.s},t.prototype.drShiftTo=function(t,r){for(var i=t;i<this.t;++i)r[i-t]=this[i];r.t=Math.max(this.t-t,0),r.s=this.s},t.prototype.lShiftTo=function(t,r){for(var i=t%this.DB,e=this.DB-i,o=(1<<e)-1,n=Math.floor(t/this.DB),s=this.s<<i&this.DM,h=this.t-1;0<=h;--h)r[h+n+1]=this[h]>>e|s,s=(this[h]&o)<<i;for(h=n-1;0<=h;--h)r[h]=0;r[n]=s,r.t=this.t+n+1,r.s=this.s,r.clamp()},t.prototype.rShiftTo=function(t,r){r.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)r.t=0;else{var e=t%this.DB,o=this.DB-e,n=(1<<e)-1;r[0]=this[i]>>e;for(var s=i+1;s<this.t;++s)r[s-i-1]|=(this[s]&n)<<o,r[s-i]=this[s]>>e;0<e&&(r[this.t-i-1]|=(this.s&n)<<o),r.t=this.t-i,r.clamp()}},t.prototype.subTo=function(t,r){for(var i=0,e=0,o=Math.min(t.t,this.t);i<o;)e+=this[i]-t[i],r[i++]=e&this.DM,e>>=this.DB;if(t.t<this.t){for(e-=t.s;i<this.t;)e+=this[i],r[i++]=e&this.DM,e>>=this.DB;e+=this.s}else{for(e+=this.s;i<t.t;)e-=t[i],r[i++]=e&this.DM,e>>=this.DB;e-=t.s}r.s=e<0?-1:0,e<-1?r[i++]=this.DV+e:0<e&&(r[i++]=e),r.t=i,r.clamp()},t.prototype.multiplyTo=function(r,i){var e=this.abs(),o=r.abs(),n=e.t;for(i.t=n+o.t;0<=--n;)i[n]=0;for(n=0;n<o.t;++n)i[n+e.t]=e.am(0,o[n],i,n,0,e.t);i.s=0,i.clamp(),this.s!=r.s&&t.ZERO.subTo(i,i)},t.prototype.squareTo=function(t){for(var r=this.abs(),i=t.t=2*r.t;0<=--i;)t[i]=0;for(i=0;i<r.t-1;++i){var e=r.am(i,r[i],t,2*i,0,1);(t[i+r.t]+=r.am(i+1,2*r[i],t,2*i+1,e,r.t-i-1))>=r.DV&&(t[i+r.t]-=r.DV,t[i+r.t+1]=1)}0<t.t&&(t[t.t-1]+=r.am(i,r[i],t,2*i,0,1)),t.s=0,t.clamp()},t.prototype.divRemTo=function(r,i,e){var o=r.abs();if(!(o.t<=0)){var n=this.abs();if(n.t<o.t)return null!=i&&i.fromInt(0),void(null!=e&&this.copyTo(e));null==e&&(e=c());var s=c(),h=this.s,u=r.s,f=this.DB-S(o[o.t-1]);0<f?(o.lShiftTo(f,s),n.lShiftTo(f,e)):(o.copyTo(s),n.copyTo(e));var a=s.t,p=s[a-1];if(0!=p){var l=p*(1<<this.F1)+(1<a?s[a-2]>>this.F2:0),y=this.FV/l,m=(1<<this.F1)/l,g=1<<this.F2,v=e.t,d=v-a,b=null==i?c():i;for(s.dlShiftTo(d,b),0<=e.compareTo(b)&&(e[e.t++]=1,e.subTo(b,e)),t.ONE.dlShiftTo(a,b),b.subTo(s,s);s.t<a;)s[s.t++]=0;for(;0<=--d;){var T=e[--v]==p?this.DM:Math.floor(e[v]*y+(e[v-1]+g)*m);if((e[v]+=s.am(0,T,e,d,0,a))<T)for(s.dlShiftTo(d,b),e.subTo(b,e);e[v]<--T;)e.subTo(b,e)}null!=i&&(e.drShiftTo(a,i),h!=u&&t.ZERO.subTo(i,i)),e.t=a,e.clamp(),0<f&&e.rShiftTo(f,e),h<0&&t.ZERO.subTo(e,e)}}},t.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var r=3&t;return 0<(r=(r=(r=(r=r*(2-(15&t)*r)&15)*(2-(255&t)*r)&255)*(2-((65535&t)*r&65535))&65535)*(2-t*r%this.DV)%this.DV)?this.DV-r:-r},t.prototype.isEven=function(){return 0==(0<this.t?1&this[0]:this.s)},t.prototype.exp=function(r,i){if(4294967295<r||r<1)return t.ONE;var e=c(),o=c(),n=i.convert(this),s=S(r)-1;for(n.copyTo(e);0<=--s;)if(i.sqrTo(e,o),0<(r&1<<s))i.mulTo(o,n,e);else{var h=e;e=o,o=h}return i.revert(e)},t}(),a=(function(){function t(){}t.prototype.convert=function(t){return t},t.prototype.revert=function(t){return t},t.prototype.mulTo=function(t,r,i){t.multiplyTo(r,i)},t.prototype.sqrTo=function(t,r){t.squareTo(r)}}(),function(){function t(t){this.m=t}return t.prototype.convert=function(t){return t.s<0||0<=t.compareTo(this.m)?t.mod(this.m):t},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},t.prototype.mulTo=function(t,r,i){t.multiplyTo(r,i),this.reduce(i)},t.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},t}()),p=function(){function t(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}return t.prototype.convert=function(t){var r=c();return t.abs().dlShiftTo(this.m.t,r),r.divRemTo(this.m,null,r),t.s<0&&0<r.compareTo(f.ZERO)&&this.m.subTo(r,r),r},t.prototype.revert=function(t){var r=c();return t.copyTo(r),this.reduce(r),r},t.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var r=0;r<this.m.t;++r){var i=32767&t[r],e=i*this.mpl+((i*this.mph+(t[r]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[i=r+this.m.t]+=this.m.am(0,e,t,r,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),0<=t.compareTo(this.m)&&t.subTo(this.m,t)},t.prototype.mulTo=function(t,r,i){t.multiplyTo(r,i),this.reduce(i)},t.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},t}();!function(){function t(t){this.m=t,this.r2=c(),this.q3=c(),f.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t)}t.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var r=c();return t.copyTo(r),this.reduce(r),r},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);0<=t.compareTo(this.m);)t.subTo(this.m,t)},t.prototype.mulTo=function(t,r,i){t.multiplyTo(r,i),this.reduce(i)},t.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)}}();function c(){return new f(null)}function l(t,r){return new f(t,r)}f.prototype.am=function(t,r,i,e,o,n){for(var s=16383&r,h=r>>14;0<=--n;){var u=16383&this[t],f=this[t++]>>14,a=h*u+f*s;o=((u=s*u+((16383&a)<<14)+i[e]+o)>>28)+(a>>14)+h*f,i[e++]=268435455&u}return o},f.prototype.DB=28,f.prototype.DM=268435455,f.prototype.DV=1<<28,f.prototype.FV=Math.pow(2,52),f.prototype.F1=24,f.prototype.F2=4;var m,g,v=[];for(m="0".charCodeAt(0),g=0;g<=9;++g)v[m++]=g;for(m="a".charCodeAt(0),g=10;g<36;++g)v[m++]=g;for(m="A".charCodeAt(0),g=10;g<36;++g)v[m++]=g;function b(t,r){var i=v[t.charCodeAt(r)];return null==i?-1:i}function T(t){var r=c();return r.fromInt(t),r}function S(t){var r,i=1;return 0!=(r=t>>>16)&&(t=r,i+=16),0!=(r=t>>8)&&(t=r,i+=8),0!=(r=t>>4)&&(t=r,i+=4),0!=(r=t>>2)&&(t=r,i+=2),0!=(r=t>>1)&&(t=r,i+=1),i}f.ZERO=T(0),f.ONE=T(1);var w,D,x=function(){function t(){this.i=0,this.j=0,this.S=[]}return t.prototype.init=function(t){var r,i,e;for(r=0;r<256;++r)this.S[r]=r;for(r=i=0;r<256;++r)i=i+this.S[r]+t[r%t.length]&255,e=this.S[r],this.S[r]=this.S[i],this.S[i]=e;this.i=0,this.j=0},t.prototype.next=function(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]},t}(),E=256,A=null;if(null==A){A=[];D=0;!function(t){for(var r=0,i=t.length;r<i;r++)t[r]=Math.floor(256*Math.random())}(E=new Uint32Array(256))}function B(){if(null==w){for(w=new x;D<E;){var t=Math.floor(65536*Math.random());A[D++]=255&t}for(w.init(A),D=0;D<A.length;++D)A[D]=0;D=0}return w.next()}var _=function(){function t(){}return t.prototype.nextBytes=function(t){for(var r=0;r<t.length;++r)t[r]=B()},t}(),M=function(){function t(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}return t.prototype.doPublic=function(t){return t.modPowInt(this.e,this.n)},t.prototype.setPublic=function(t,r){null!=t&&null!=r&&0<t.length&&0<r.length?(this.n=l(t,16),this.e=parseInt(r,16)):console.error("Invalid RSA public key")},t.prototype.encrypt=function(t){var r=function(t,r){if(r<t.length+11)return console.error("Message too long for RSA"),null;for(var i=[],e=t.length-1;0<=e&&0<r;){var o=t.charCodeAt(e--);o<128?i[--r]=o:127<o&&o<2048?(i[--r]=63&o|128,i[--r]=o>>6|192):(i[--r]=63&o|128,i[--r]=o>>6&63|128,i[--r]=o>>12|224)}i[--r]=0;for(var n=new _,s=[];2<r;){for(s[0]=0;0==s[0];)n.nextBytes(s);i[--r]=s[0]}return i[--r]=2,i[--r]=0,new f(i)}(t,this.n.bitLength()+7>>3);if(null==r)return null;var i=this.doPublic(r);if(null==i)return null;var e=i.toString(16);return 1&e.length?"0"+e:e},t}(),O=function(t){function r(i){var e=t.call(this)||this;return i&&("string"==typeof i?e.parseKey(i):r.hasPublicKeyProperty(i)&&e.parsePropertiesFrom(i)),e}return function(t,r){function i(){this.constructor=t}o(t,r),t.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}(r,t),r.prototype.parseKey=function(t){try{var r=0,i=0,e=/^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/.test(t)?d(t):n.unarmor(t),o=h.decode(e);if(3===o.sub.length&&(o=o.sub[2].sub[0]),9===o.sub.length){r=o.sub[1].getHexStringValue(),this.n=l(r,16),i=o.sub[2].getHexStringValue(),this.e=parseInt(i,16);var s=o.sub[3].getHexStringValue();this.d=l(s,16);var u=o.sub[4].getHexStringValue();this.p=l(u,16);var f=o.sub[5].getHexStringValue();this.q=l(f,16);var a=o.sub[6].getHexStringValue();this.dmp1=l(a,16);var p=o.sub[7].getHexStringValue();this.dmq1=l(p,16);var c=o.sub[8].getHexStringValue();this.coeff=l(c,16)}else{if(2!==o.sub.length)return!1;var y=o.sub[1].sub[0];r=y.sub[0].getHexStringValue(),this.n=l(r,16),i=y.sub[1].getHexStringValue(),this.e=parseInt(i,16)}return!0}catch(t){return!1}},r.wordwrap=function(t,r){if(!t)return t;var i="(.{1,"+(r=r||64)+"})( +|$\n?)|(.{1,"+r+"})";return t.match(RegExp(i,"g")).join("\n")},r.hasPublicKeyProperty=function(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")},r}(M),V=function(){function t(t){t=t||{},this.default_key_size=parseInt(t.default_key_size,10)||1024,this.default_public_exponent=t.default_public_exponent||"010001",this.log=t.log||!1,this.key=null}return t.prototype.setKey=function(t){this.log&&this.key&&console.warn("a"),this.key=new O(t)},t.prototype.setPublicKey=function(t){this.setKey(t)},t.prototype.encrypt=function(t){try{return function(t){var r,e,o="";for(r=0;r+3<=t.length;r+=3)e=parseInt(t.substring(r,r+3),16),o+=i.charAt(e>>6)+i.charAt(63&e);for(r+1==t.length?(e=parseInt(t.substring(r,r+1),16),o+=i.charAt(e<<2)):r+2==t.length&&(e=parseInt(t.substring(r,r+2),16),o+=i.charAt(e>>2)+i.charAt((3&e)<<4));0<(3&o.length);)o+="=";return o}(this.getKey().encrypt(t))}catch(t){return!1}},t.prototype.getKey=function(t){if(!this.key){if(this.key=new O,t&&"[object Function]"==={}.toString.call(t))return void this.key.generateAsync(this.default_key_size,this.default_public_exponent,t);this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},t}();t.JSEncrypt=V,t.default=V,Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/src/md5.js
CHANGED
|
@@ -356,7 +356,7 @@ function hexHMACMD5(k, d) {
|
|
|
356
356
|
*
|
|
357
357
|
* @param {string} string Input string
|
|
358
358
|
* @param {string} [key] HMAC key
|
|
359
|
-
* @param {
|
|
359
|
+
* @param {boolean} [raw] Raw output switch
|
|
360
360
|
* @returns {string} MD5 output
|
|
361
361
|
*/
|
|
362
362
|
function md5(string, key, raw) {
|
package/src/report/helper.ts
CHANGED
|
@@ -45,7 +45,14 @@ function getSystemInfo(): ISystemInfo {
|
|
|
45
45
|
const system = wx.getSystemInfoSync() as any;
|
|
46
46
|
// eslint-disable-next-line
|
|
47
47
|
const { model = '', version: wxVersion = '', platform = '', SDKVersion = '', host } = system;
|
|
48
|
-
systemInfo = {
|
|
48
|
+
systemInfo = {
|
|
49
|
+
model,
|
|
50
|
+
wxVersion,
|
|
51
|
+
platform,
|
|
52
|
+
SDKVersion,
|
|
53
|
+
host,
|
|
54
|
+
open_app_id: initOptions?.openAppId || '',
|
|
55
|
+
};
|
|
49
56
|
}
|
|
50
57
|
return systemInfo;
|
|
51
58
|
}
|
package/src/report/types.ts
CHANGED
|
@@ -4,6 +4,8 @@ export type DataItem = any;
|
|
|
4
4
|
* 初始化参数对象
|
|
5
5
|
*/
|
|
6
6
|
export interface IInitOptions {
|
|
7
|
+
// 外输应用key
|
|
8
|
+
openAppId?: string;
|
|
7
9
|
// 小程序项目名,如:sinan、mycar等
|
|
8
10
|
client: string,
|
|
9
11
|
// 小程序版本号
|
|
@@ -48,6 +50,8 @@ export interface ISystemInfo {
|
|
|
48
50
|
SDKVersion: string,
|
|
49
51
|
// 开发环境下为空
|
|
50
52
|
host: object,
|
|
53
|
+
// 外输应用key, 玉爽就要下划线格式不要驼峰
|
|
54
|
+
open_app_id: string,
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
export interface ILocation {
|