(function(){function v(g){"undefined"===typeof BigInteger&&(BigInteger=g.jsbn.BigInteger);var a=g.asn1,m=g.jsustoolkitErrCode=g.jsustoolkitErrCode||{},e=g.pki=g.pki||{},l=e.oids,w=g.pkcs8=g.pkcs8||{},y=g.x509Certificate=g.x509Certificate||{},n={};n.cn=l.commonName;n.commonName="cn";n.c=l.countryName;n.countryName="c";n.l=l.localityName;n.localityName="l";n.s=l.stateOrProvinceName;n.stateOrProvinceName="s";n.o=l.organizationName;n.organizationName="o";n.ou=l.organizationalUnitName;n.organizationalUnitName="ou";n.e=l.emailAddress;n.emailAddress="e";n.street=l.street;n.street="street";n.serialNumber=l.serialName;n.serialName="serialNumber";n.dnQualifier=l.dnQualifier;n.dnQualifier="dnQualifier";n.dc=l.domailComponent;n.domailComponent="dc";var v={name:"SubjectPublicKeyInfo",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,captureAsn1:"subjectPublicKeyInfo",value:[{name:"SubjectPublicKeyInfo.AlgorithmIdentifier",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:a.Class.UNIVERSAL,type:a.Type.OID,constructed:!1,capture:"publicKeyOid"}]},{name:"SubjectPublicKeyInfo.subjectPublicKey",tagClass:a.Class.UNIVERSAL,type:a.Type.BITSTRING,constructed:!1,capture:"rsaPublicKey"}]},x={name:"RSAPublicKey",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPublicKey.modulus",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"publicKeyModulus"},{name:"RSAPublicKey.exponent",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"publicKeyExponent"}]},G={name:"Certificate",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,captureAsn1:"tbsCertificate",value:[{name:"Certificate.TBSCertificate.version",tagClass:a.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.version.integer",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"certVersion"}]},{name:"Certificate.TBSCertificate.serialNumber",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"certSerialNumber"},{name:"Certificate.TBSCertificate.signature",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate.signature.algorithm",tagClass:a.Class.UNIVERSAL,type:a.Type.OID,constructed:!1,capture:"certinfoSignatureOid"},{name:"Certificate.TBSCertificate.signature.parameters",tagClass:a.Class.UNIVERSAL,optional:!0,captureAsn1:"certinfoSignatureParams"}]},{name:"Certificate.TBSCertificate.issuer",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,captureAsn1:"certIssuer"},{name:"Certificate.TBSCertificate.validity",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.TBSCertificate.validity.notBefore (utc)",tagClass:a.Class.UNIVERSAL,type:a.Type.UTCTIME,constructed:!1,optional:!0,capture:"certValidity1UTCTime"},{name:"Certificate.TBSCertificate.validity.notBefore (generalized)",tagClass:a.Class.UNIVERSAL,type:a.Type.GENERALIZEDTIME,constructed:!1,optional:!0,capture:"certValidity2GeneralizedTime"},{name:"Certificate.TBSCertificate.validity.notAfter (utc)",tagClass:a.Class.UNIVERSAL,type:a.Type.UTCTIME,constructed:!1,optional:!0,capture:"certValidity3UTCTime"},{name:"Certificate.TBSCertificate.validity.notAfter (generalized)",tagClass:a.Class.UNIVERSAL,type:a.Type.GENERALIZEDTIME,constructed:!1,optional:!0,capture:"certValidity4GeneralizedTime"}]},{name:"Certificate.TBSCertificate.subject",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,captureAsn1:"certSubject"},v,{name:"Certificate.TBSCertificate.issuerUniqueID",tagClass:a.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.issuerUniqueID.id",tagClass:a.Class.UNIVERSAL,type:a.Type.BITSTRING,constructed:!1,capture:"certIssuerUniqueId"}]},{name:"Certificate.TBSCertificate.subjectUniqueID",tagClass:a.Class.CONTEXT_SPECIFIC,type:2,constructed:!0,optional:!0,value:[{name:"Certificate.TBSCertificate.subjectUniqueID.id",tagClass:a.Class.UNIVERSAL,type:a.Type.BITSTRING,constructed:!1,capture:"certSubjectUniqueId"}]},{name:"Certificate.TBSCertificate.extensions",tagClass:a.Class.CONTEXT_SPECIFIC,type:3,constructed:!0,captureAsn1:"certExtensions",optional:!0}]},{name:"Certificate.signatureAlgorithm",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,value:[{name:"Certificate.signatureAlgorithm.algorithm",tagClass:a.Class.UNIVERSAL,type:a.Type.OID,constructed:!1,capture:"certSignatureOid"},{name:"Certificate.TBSCertificate.signature.parameters",tagClass:a.Class.UNIVERSAL,optional:!0,captureAsn1:"certSignatureParams"}]},{name:"Certificate.signatureValue",tagClass:a.Class.UNIVERSAL,type:a.Type.BITSTRING,constructed:!1,capture:"certSignature"}]},H={name:"RSAPrivateKey",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPrivateKey.version",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"RSAPrivateKey.modulus",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"privateKeyModulus"},{name:"RSAPrivateKey.publicExponent",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"privateKeyPublicExponent"},{name:"RSAPrivateKey.privateExponent",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"privateKeyPrivateExponent"},{name:"RSAPrivateKey.prime1",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"privateKeyPrime1"},{name:"RSAPrivateKey.prime2",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"privateKeyPrime2"},{name:"RSAPrivateKey.exponent1",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"privateKeyExponent1"},{name:"RSAPrivateKey.exponent2",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"privateKeyExponent2"},{name:"RSAPrivateKey.coefficient",tagClass:a.Class.UNIVERSAL,type:a.Type.INTEGER,constructed:!1,capture:"privateKeyCoefficient"}]},I={name:"rsapss",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,value:[{name:"rsapss.hashAlgorithm",tagClass:a.Class.CONTEXT_SPECIFIC,type:0,constructed:!0,value:[{name:"rsapss.hashAlgorithm.AlgorithmIdentifier",tagClass:a.Class.UNIVERSAL,type:a.Class.SEQUENCE,constructed:!0,optional:!0,value:[{name:"rsapss.hashAlgorithm.AlgorithmIdentifier.algorithm",tagClass:a.Class.UNIVERSAL,type:a.Type.OID,constructed:!1,capture:"hashOid"}]}]},{name:"rsapss.maskGenAlgorithm",tagClass:a.Class.CONTEXT_SPECIFIC,type:1,constructed:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier",tagClass:a.Class.UNIVERSAL,type:a.Class.SEQUENCE,constructed:!0,optional:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.algorithm",tagClass:a.Class.UNIVERSAL,type:a.Type.OID,constructed:!1,capture:"maskGenOid"},{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.params",tagClass:a.Class.UNIVERSAL,type:a.Type.SEQUENCE,constructed:!0,value:[{name:"rsapss.maskGenAlgorithm.AlgorithmIdentifier.params.algorithm",tagClass:a.Class.UNIVERSAL,type:a.Type.OID,constructed:!1,capture:"maskGenHashOid"}]}]}]},{name:"rsapss.saltLength",tagClass:a.Class.CONTEXT_SPECIFIC,type:2,optional:!0,value:[{name:"rsapss.saltLength.saltLength",tagClass:a.Class.UNIVERSAL,type:a.Class.INTEGER,constructed:!1,capture:"saltLength"}]},{name:"rsapss.trailerField",tagClass:a.Class.CONTEXT_SPECIFIC,type:3,optional:!0,value:[{name:"rsapss.trailer.trailer",tagClass:a.Class.UNIVERSAL,type:a.Class.INTEGER,constructed:!1,capture:"trailer"}]}]};e.RDNAttributesAsArray=function(b,d){if(null==b||"undefined"==typeof b)throw{code:"112001",message:m["112001"]};for(var f=[],c,e,h,k=0;kt.length)throw{code:"112036",message:m["112036"]};c.validity.notBefore=t[0];c.validity.notAfter=t[1];c.publicKeyOid=g.asn1.derToOid(f.publicKeyOid);c.tbsCertificate=f.tbsCertificate;if(d){c.md=null;if(c.signatureOid in l)switch(b=l[c.signatureOid],b){case "sha1WithRSAEncryption":c.md=g.md.sha1.create();break;case "kcdsaWithSHA1":c.md=g.md.sha1.create();break;case "md5WithRSAEncryption":c.md=g.md.md5.create();break;case "sha256WithRSAEncryption":c.md=g.md.sha256.create();break;case "RSASSA-PSS":c.md=g.md.sha256.create()}if(null===c.md)throw{code:"112037",message:m["112037"]+"(signatureOid:"+c.signatureOid+")"};d=a.toDer(c.tbsCertificate);c.md.update(d.getBytes())}d=g.md.sha1.create();c.issuer.attributes=e.RDNAttributesAsArray(f.certIssuer,d);f.certIssuerUniqueId&&(c.issuer.uniqueId=f.certIssuerUniqueId);c.issuer.hash=d.digest().toHex();d=g.md.sha1.create();c.subject.attributes=e.RDNAttributesAsArray(f.certSubject,d);f.certSubjectUniqueId&&(c.subject.uniqueId=f.certSubjectUniqueId);c.subject.hash=d.digest().toHex();if(f.certExtensions){d=f.certExtensions;t=[];for(var h,k,n,B=0;Bd.validity.notAfter?!1:!0};e.verifyCertificateChain=function(a,d,f){var b=new Date,m=!1,h=new y.certUtil;if(_verifyValidity(b,d)){var k=[],l=a.getIssuer(d);if(null===l)error={message:"no parent issuer, so certificate not trusted.",error:e.certificateError.unknown_ca},f(!1,k.length,error.message);else{for(k.push(d);l.issuer.hash!=l.subject.hash;){var n=l;if(_verifyValidity(b,n)){l=a.getIssuer(n);if(null===l){error={message:"no parent issuer, so certificate not trusted.",error:e.certificateError.unknown_ca};break}k.push(n)}else error={message:"Certificate is not valid yet or has expired.",error:e.certificateError.certificate_expired,notBefore:d.validity.notBefore,notAfter:d.validity.notAfter,now:b},f(!1,k.length,error.message)}_verifyValidity(b,l)?k.push(l):(error={message:"Certificate is not valid yet or has expired.",error:e.certificateError.certificate_expired,notBefore:d.validity.notBefore,notAfter:d.validity.notAfter,now:b},f(!1,k.length,error.message));a=[];d=!0;for(b=k.length-1;0<=b;b--){l=k[b];n=l.getExtension("basicConstraints");if(b!=k.length-1&&0!=b){var p=l.getExtension("nameConstraints");if(null!=p){var q=h.getDN(k[b-1].subject);if(null!=p.permittedSubtrees){var r=!0;for(b=0;bq.indexOf(u)&&(r=!1)}1!=r&&(error={message:"Certificate nameConstraints verify : fail!(permittedSubtrees)",error:e.certificateError.bad_certificate},f(!1,k.length,error.message))}if(null!=p.excludedSubtrees){r=!1;for(b=0;b