-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathjws-1.1.min.js
3 lines (3 loc) · 3.68 KB
/
jws-1.1.min.js
1
2
3
/*! jws-1.1 (c) 2012 Kenji Urushima | kjur.github.com/jsjws/license
*/
function _getSignatureInputByString(b,a){return utf8tob64u(b)+"."+utf8tob64u(a)}function _getHashBySignatureInput(c,b){var a=_RSASIGN_HASHHEXFUNC[b];if(a==null){throw"hash function not defined in jsrsasign: "+b}return a(c)}function _jws_verifySignature(g,d,a,e,c){var f=_getSignatureInputByString(g,d);var b=parseBigInt(a,16);return _rsasign_verifySignatureWithArgs(f,b,e,c)}function _jws_getEncodedSignatureValueFromJWS(a){if(a.match(/^[^.]+\.[^.]+\.([^.]+)$/)==null){throw"JWS signature is not a form of 'Head.Payload.SigValue'."}return RegExp.$1}function _jws_parseJWS(d){if(d.match(/^([^.]+)\.([^.]+)\.([^.]+)$/)==null){throw"JWS signature is not a form of 'Head.Payload.SigValue'."}var f=RegExp.$1;var b=RegExp.$2;var g=RegExp.$3;var i=f+"."+b;this.parsedJWS={};this.parsedJWS.headB64U=f;this.parsedJWS.payloadB64U=b;this.parsedJWS.sigvalB64U=g;this.parsedJWS.si=i;var e=b64utohex(g);var c=parseBigInt(e,16);this.parsedJWS.sigvalH=e;this.parsedJWS.sigvalBI=c;var a=b64utoutf8(f);var h=b64utoutf8(b);this.parsedJWS.headS=a;this.parsedJWS.payloadS=h;if(!this.isSafeJSONString(a)){throw"malformed JSON string for JWS Head: "+a}}function _jws_verifyJWSByNE(c,b,a){this.parseJWS(c);return _rsasign_verifySignatureWithArgs(this.parsedJWS.si,this.parsedJWS.sigvalBI,b,a)}function _jws_verifyJWSByPemX509Cert(c,a){this.parseJWS(c);var b=new X509();b.readCertPEM(a);return b.subjectPublicKeyRSA.verifyString(this.parsedJWS.si,this.parsedJWS.sigvalH)}function _jws_getHashAlgFromHead(d){var b=jsonParse(d);var c=b.alg;var a="";if(c!="RS256"&&c!="RS512"){throw"JWS signature algorithm not supported: "+c}if(c=="RS256"){a="sha256"}if(c=="RS512"){a="sha512"}return a}function _jws_generateSignatureValueBySI_NED(a,f,i,c,g,h){var d=new RSAKey();d.setPrivate(c,g,h);var b=_jws_getHashAlgFromHead(a);var e=d.signString(i,b);return e}function _jws_generateSignatureValueByNED(f,c,e,b,d){var a=_getSignatureInputByString(f,c);return _jws_generateSignatureValueBySI_NED(f,c,a,e,b,d)}function _jws_generateJWSByNED(h,d,g,c,f){if(!this.isSafeJSONString(h)){throw"JWS Head is not safe JSON string: "+h}var b=_getSignatureInputByString(h,d);var e=_jws_generateSignatureValueBySI_NED(h,d,b,g,c,f);var a=hextob64u(e);this.parsedJWS={};this.parsedJWS.headB64U=b.split(".")[0];this.parsedJWS.payloadB64U=b.split(".")[1];this.parsedJWS.sigvalB64U=a;return b+"."+a}function _jws_generateSignatureValueBySI_PemPrvKey(g,f,e,b){var d=new RSAKey();d.readPrivateKeyFromPEMString(b);var a=_jws_getHashAlgFromHead(g);var c=d.signString(e,a);return c}function _jws_generateJWSByP1PrvKey(f,d,a){if(!this.isSafeJSONString(f)){throw"JWS Head is not safe JSON string: "+f}var c=_getSignatureInputByString(f,d);var e=_jws_generateSignatureValueBySI_PemPrvKey(f,d,c,a);var b=hextob64u(e);this.parsedJWS={};this.parsedJWS.headB64U=c.split(".")[0];this.parsedJWS.payloadB64U=c.split(".")[1];this.parsedJWS.sigvalB64U=b;return c+"."+b}function _jws_isSafeJSONString(b){var c=null;try{c=jsonParse(b);if(typeof c!="object"){return 0}if(c.constructor===Array){return 0}return 1}catch(a){return 0}}function _jws_readSafeJSONString(b){var c=null;try{c=jsonParse(b);if(typeof c!="object"){return null}if(c.constructor===Array){return null}return c}catch(a){return null}}function JWS(){}JWS.prototype.isSafeJSONString=_jws_isSafeJSONString;JWS.prototype.readSafeJSONString=_jws_readSafeJSONString;JWS.prototype.getEncodedSignatureValueFromJWS=_jws_getEncodedSignatureValueFromJWS;JWS.prototype.parseJWS=_jws_parseJWS;JWS.prototype.generateJWSByNED=_jws_generateJWSByNED;JWS.prototype.generateJWSByP1PrvKey=_jws_generateJWSByP1PrvKey;JWS.prototype.verifyJWSByNE=_jws_verifyJWSByNE;JWS.prototype.verifyJWSByPemX509Cert=_jws_verifyJWSByPemX509Cert;