1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 lines
13 KiB

/*! x509-1.1.9.js (c) 2012-2016 Kenji Urushima | kjur.github.com/jsrsasign/license
*/
function X509(){this.subjectPublicKeyRSA=null;this.subjectPublicKeyRSA_hN=null;this.subjectPublicKeyRSA_hE=null;this.hex=null;this.getSerialNumberHex=function(){return ASN1HEX.getDecendantHexVByNthList(this.hex,0,[0,1])};this.getSignatureAlgorithmField=function(){var b=ASN1HEX.getDecendantHexVByNthList(this.hex,0,[0,2,0]);var a=KJUR.asn1.ASN1Util.oidHexToInt(b);var c=KJUR.asn1.x509.OID.oid2name(a);return c};this.getIssuerHex=function(){return ASN1HEX.getDecendantHexTLVByNthList(this.hex,0,[0,3])};this.getIssuerString=function(){return X509.hex2dn(ASN1HEX.getDecendantHexTLVByNthList(this.hex,0,[0,3]))};this.getSubjectHex=function(){return ASN1HEX.getDecendantHexTLVByNthList(this.hex,0,[0,5])};this.getSubjectString=function(){return X509.hex2dn(ASN1HEX.getDecendantHexTLVByNthList(this.hex,0,[0,5]))};this.getNotBefore=function(){var a=ASN1HEX.getDecendantHexVByNthList(this.hex,0,[0,4,0]);a=a.replace(/(..)/g,"%$1");a=decodeURIComponent(a);return a};this.getNotAfter=function(){var a=ASN1HEX.getDecendantHexVByNthList(this.hex,0,[0,4,1]);a=a.replace(/(..)/g,"%$1");a=decodeURIComponent(a);return a};this.readCertPEM=function(c){var e=X509.pemToHex(c);var b=X509.getPublicKeyHexArrayFromCertHex(e);var d=new RSAKey();d.setPublic(b[0],b[1]);this.subjectPublicKeyRSA=d;this.subjectPublicKeyRSA_hN=b[0];this.subjectPublicKeyRSA_hE=b[1];this.hex=e};this.readCertPEMWithoutRSAInit=function(c){var d=X509.pemToHex(c);var b=X509.getPublicKeyHexArrayFromCertHex(d);this.subjectPublicKeyRSA.setPublic(b[0],b[1]);this.subjectPublicKeyRSA_hN=b[0];this.subjectPublicKeyRSA_hE=b[1];this.hex=d};this.getInfo=function(){var p="Basic Fields\n";p+=" serial number: "+this.getSerialNumberHex()+"\n";p+=" signature algorithm: "+this.getSignatureAlgorithmField()+"\n";p+=" issuer: "+this.getIssuerString()+"\n";p+=" notBefore: "+this.getNotBefore()+"\n";p+=" notAfter: "+this.getNotAfter()+"\n";p+=" subject: "+this.getSubjectString()+"\n";p+=" subject public key info: \n";var j=X509.getSubjectPublicKeyInfoPosFromCertHex(this.hex);var d=ASN1HEX.getHexOfTLV_AtObj(this.hex,j);var n=KEYUTIL.getKey(d,null,"pkcs8pub");if(n instanceof RSAKey){p+=" key algorithm: RSA\n";p+=" n="+n.n.toString(16).substr(0,16)+"...\n";p+=" e="+n.e.toString(16)+"\n"}p+="X509v3 Extensions:\n";var m=X509.getV3ExtInfoListOfCertHex(this.hex);for(var e=0;e<m.length;e++){var b=m[e];var o=KJUR.asn1.x509.OID.oid2name(b.oid);if(o===""){o=b.oid}var k="";if(b.critical===true){k="CRITICAL"}p+=" "+o+" "+k+":\n";if(o==="basicConstraints"){var g=X509.getExtBasicConstraints(this.hex);if(g.cA===undefined){p+=" {}\n"}else{p+=" cA=true";if(g.pathLen!==undefined){p+=", pathLen="+g.pathLen}p+="\n"}}else{if(o==="keyUsage"){p+=" "+X509.getExtKeyUsageString(this.hex)+"\n"}else{if(o==="subjectKeyIdentifier"){p+=" "+X509.getExtSubjectKeyIdentifier(this.hex)+"\n"}else{if(o==="authorityKeyIdentifier"){var a=X509.getExtAuthorityKeyIdentifier(this.hex);if(a.kid!==undefined){p+=" kid="+a.kid+"\n"}}else{if(o==="extKeyUsage"){var h=X509.getExtExtKeyUsageName(this.hex);p+=" "+h.join(", ")+"\n"}else{if(o==="subjectAltName"){var f=X509.getExtSubjectAltName(this.hex);p+=" "+f.join(", ")+"\n"}else{if(o==="cRLDistributionPoints"){var l=X509.getExtCRLDistributionPointsURI(this.hex);p+=" "+l+"\n"}else{if(o==="authorityInfoAccess"){var c=X509.getExtAIAInfo(this.hex);if(c.ocsp!==undefined){p+=" ocsp: "+c.ocsp.join(",")+"\n"}if(c.caissuer!==undefined){p+=" caissuer: "+c.caissuer.join(",")+"\n"}}}}}}}}}}p+="signature algorithm: "+X509.getSignatureAlgorithmName(this.hex)+"\n";p+="signature: "+X509.getSignatureValueHex(this.hex).substr(0,16)+"...\n";return p}}X509.pemToBase64=function(a){var b=a;b=b.replace("-----BEGIN CERTIFICATE-----","");b=b.replace("-----END CERTIFICATE-----","");b=b.replace(/[ \n]+/g,"");return b};X509.pemToHex=function(a){var c=X509.pemToBase64(a);var b=b64tohex(c);return b};X509.getSubjectPublicKeyPosFromCertHex=function(f){var e=X509.getSubjectPublicKeyInfoPosFromCertHex(f);if(e==-1){return -1}var b=ASN1HEX.getPosArrayOfChildren_AtObj(f,e);if(b.length!=2){return -1}v