1 |
- var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.owns=function(g,l){return Object.prototype.hasOwnProperty.call(g,l)};$jscomp.assign="function"==typeof Object.assign?Object.assign:function(g,l){for(var k=1;k<arguments.length;k++){var d=arguments[k];if(d)for(var e in d)$jscomp.owns(d,e)&&(g[e]=d[e])}return g};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(g,l,k){g!=Array.prototype&&g!=Object.prototype&&(g[l]=k.value)};$jscomp.getGlobal=function(g){return"undefined"!=typeof window&&window===g?g:"undefined"!=typeof global&&null!=global?global:g};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(g,l,k,d){if(l){k=$jscomp.global;g=g.split(".");for(d=0;d<g.length-1;d++){var e=g[d];e in k||(k[e]={});k=k[e]}g=g[g.length-1];d=k[g];l=l(d);l!=d&&null!=l&&$jscomp.defineProperty(k,g,{configurable:!0,writable:!0,value:l})}};$jscomp.polyfill("Object.assign",function(g){return g||$jscomp.assign},"es6","es3");(function(){function g(d){var e=d.jsustoolkitErrCode=d.jsustoolkitErrCode||{},a=d.asn1,b=d.cmp=d.cmp||{},g=d.oids=d.oids||{},k=d.util=d.util||{};b.info={version:0,id:[],certReqId:[0,1],referenceValue:[],secretValue:[],signature_algorithm:[],key_size:[],km_key_gen:[],km_key_backup:[],passwd_len:[],passwd_num_len:[],allow_suspend:[],dir_server_addr:[]};b.revReason={unspecified:0,keyCompromise:1,caCompromise:2,affiliationChanged:3,superseded:4,cessationOfOperation:5,certificateHold:6,unused:7,removeFromCRL:8,privilegeWithdrawn:9,aACompromise:10};b.user={};b.ca={};b.messageFromBase64=function(c){if(null==c||"undefined"==typeof c)throw{code:"114001",message:e["114001"]};c=a.fromDer(k.createBuffer(k.decode64(c)));return b.messageFromAsn1(c)};b.messageToBase64=function(b){if(null==b||"undefined"==typeof b)throw{code:"114002",message:e["114002"]};b=a.toDer(b.toAsn1());return k.encode64(b.getBytes())};b.messageFromAsn1=function(c){if(null==c||"undefined"==typeof c)throw{code:"114003",message:e["114003"]};"string"==typeof c&&(c=a.fromDer(k.createBuffer(c)));var f={},h=[];if(!a.validate(c,b.asn1.PKIMessage,f,h))throw{code:"114004",message:e["114004"],errors:h};c=f.body.type;switch(c){case b.asn1.PKIBodyType.genp:_freeTextSplit(f.header.value[3].value[0].value[0].value);b.info.caSignCert=f.body.value[0].value[0].value[1];f.body.value[0].value[1]&&(b.info.caEncCert=f.body.value[0].value[1].value[1]);break;case b.asn1.PKIBodyType.ip:_parseIPMessage(f);break;case b.asn1.PKIBodyType.kup:_parseKUPMessage(f);break;case b.asn1.PKIBodyType.conf:null==f.body.value[0]&&(b.info.certstate=!0);break;case b.asn1.PKIBodyType.rp:_parseRPMessage(f);break;case b.asn1.PKIBodyType.error:b.info.certstate=!1;_parseErrMessage(f);break;default:throw{code:"114005",message:e["114005"]+"("+c+")"};}};b.createGenmMessage=function(c,f,h,n,m){if(null==c||"undefined"==typeof c)throw{code:"114006",message:e["114006"]};if(null==f||"undefined"==typeof f)throw{code:"114007",message:e["114007"]};if(null==h||"undefined"==typeof h)throw{code:"114008",message:e["114008"]};if("undefined"==typeof n||""==n||null==m)n="";"undefined"==typeof m||""==m||null==m?(b.info.sender="",b.info.signpair={},b.info.kmpair={},b.info.secret="",b.info.newsignpair=null,b.info.newkmpair=null):(b.info.signCert=m.signCert,b.info.signpair={},b.info.signpair.publicKey=m.signCert.publicKey,"undefined"!=typeof m.signKey&&""!=m.signKey&&null!=m.signKey&&(b.info.signpair.privateKey=d.pki.privateKeyFromAsn1(d.pkcs8.decryptPrivateKeyInfo(m.signKey,m.pw))),b.info.sender=m.signCert.subject,"undefined"!=typeof m.kmCert&&(b.info.kmCert=m.kmCert,b.info.kmpair={},b.info.kmpair.publicKey=m.kmCert.publicKey,"undefined"!=typeof m.signKey&&""!=m.signKey&&null!=m.signKey&&(b.info.kmpair.privateKey=d.pki.privateKeyFromAsn1(d.pkcs8.decryptPrivateKeyInfo(m.kmKey,m.pw)))));m=null;b.info.referenceValue=c;b.info.secretValue=f;b.info.text=h;b.info.mediaType=n;return m={type:b.asn1.PKIBodyType.genm,version:0,toAsn1:function(){var c=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]),f=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.INTEGER,!1,String.fromCharCode(b.info.version))]);""==b.info.sender?f.value.push(a.create(a.Class.CONTEXT_SPECIFIC,1,!1,String.fromCharCode(32))):f.value.push(a.create(a.Class.CONTEXT_SPECIFIC,4,!0,[d.pki.distinguishedNameToAsn1({attributes:b.info.sender.attributes})]));f.value.push(a.create(a.Class.CONTEXT_SPECIFIC,1,!1,String.fromCharCode(32)));f.value.push(a.create(a.Class.CONTEXT_SPECIFIC,2,!0,[a.create(a.Class.UNIVERSAL,a.Type.OCTETSTRING,!1,b.info.referenceValue)]));if(""!=b.info.mediaType){var h=a.create(a.Class.CONTEXT_SPECIFIC,7,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.UTF8,!1,mediaType)])]);f.value.push(h)}h=a.create(a.Class.CONTEXT_SPECIFIC,21,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.OID,!1,a.oidToDer(g.caProtEncCert).getBytes())])])]);c.value.push(f);c.value.push(h);return c}}};b.createIRMessage=function(c,f){var h=null;b.info.snonce=d.random.getBytes(16);null==c||"undefined"==typeof c?b.info.signpair=d.pki.rsa.generateKeyPair(b.info.key_size):(b.info.signpair={},b.info.signpair.publicKey=c(b.info.key_size));0!=b.info.km_key_gen.length&&"user"==b.info.km_key_gen&&(b.info.kmpair=d.pki.rsa.generateKeyPair(b.info.key_size),Object.assign({},b.info.kmpair));return h={type:b.asn1.PKIBodyType.ir,version:0,toAsn1:function(){var c=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]),h=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.INTEGER,!1,String.fromCharCode(b.info.version)),a.create(a.Class.CONTEXT_SPECIFIC,1,!1,String.fromCharCode(32)),a.create(a.Class.CONTEXT_SPECIFIC,1,!1,String.fromCharCode(32)),a.create(a.Class.CONTEXT_SPECIFIC,0,!0,[a.create(a.Class.UNIVERSAL,a.Type.GENERALIZEDTIME,!1,a.dateToGeneralizedTime(new Date))]),a.create(a.Class.CONTEXT_SPECIFIC,2,!0,[a.create(a.Class.UNIVERSAL,a.Type.OCTETSTRING,!1,b.info.referenceValue)]),a.create(a.Class.CONTEXT_SPECIFIC,5,!0,[a.create(a.Class.UNIVERSAL,a.Type.OCTETSTRING,!1,b.info.snonce)])]);var d=b.info.caEncCert?a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[_CertRequest("Sign"),_proofOfPossession(1,"Sign","new",f),a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[_attributeTypeAndValue("encryptedVID",_encryptedVID())])])]):a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[_CertRequest("Sign"),_proofOfPossession(1,"Sign","new",f)])]);if(0!=b.info.km_key_gen.length&&"user"==b.info.km_key_gen){var e=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[_CertRequest("KM"),_proofOfPossession(1,"KM","new")]);d.value.push(e)}e=a.create(a.Class.CONTEXT_SPECIFIC,0,!0,[]);e.value.push(d);c.value.push(h);c.value.push(e);h=a.create(a.Class.CONTEXT_SPECIFIC,0,!0,[a.create(a.Class.UNIVERSAL,a.Type.BITSTRING,!1,String.fromCharCode(0)+_processProtection("MAC",a.toDer(c).getBytes()))]);c.value.push(h);return c}}};b.createConfirmMessage=function(c){var f=null;return f={type:b.asn1.PKIBodyType.conf,version:0,toAsn1:function(){var f=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]),d=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.INTEGER,!1,String.fromCharCode(b.info.version)),a.create(a.Class.CONTEXT_SPECIFIC,1,!1,String.fromCharCode(32)),a.create(a.Class.CONTEXT_SPECIFIC,1,!1,String.fromCharCode(32)),a.create(a.Class.CONTEXT_SPECIFIC,0,!0,[a.create(a.Class.UNIVERSAL,a.Type.GENERALIZEDTIME,!1,a.dateToGeneralizedTime(new Date))])]);"undefined"!=typeof b.info.newsignpair&&null!=b.info.newsignpair||d.value.push(a.create(a.Class.CONTEXT_SPECIFIC,2,!0,[a.create(a.Class.UNIVERSAL,a.Type.OCTETSTRING,!1,b.info.referenceValue)]));d.value.push(a.create(a.Class.CONTEXT_SPECIFIC,5,!0,[a.create(a.Class.UNIVERSAL,a.Type.OCTETSTRING,!1,b.info.snonce)]));d.value.push(a.create(a.Class.CONTEXT_SPECIFIC,6,!0,[a.create(a.Class.UNIVERSAL,a.Type.OCTETSTRING,!1,b.info.rnonce)]));var e=a.create(a.Class.UNIVERSAL,a.Type.NULL,!1,""),g=a.create(a.Class.CONTEXT_SPECIFIC,19,!0,[]);g.value.push(e);f.value.push(d);f.value.push(g);d=a.create(a.Class.CONTEXT_SPECIFIC,0,!0,[]);"undefined"==typeof b.info.newsignpair||null==b.info.newsignpair?d.value.push(a.create(a.Class.UNIVERSAL,a.Type.BITSTRING,!1,String.fromCharCode(0)+_processProtection("MAC",a.toDer(f).getBytes()))):d.value.push(a.create(a.Class.UNIVERSAL,a.Type.BITSTRING,!1,String.fromCharCode(0)+_processProtection("Sign",f,c)));f.value.push(d);b.info.signpair.privateKey="";null!=b.info.kmCert&&"undefined"!=typeof b.info.kmCert&&(b.info.kmpair.privateKey="");return f}}};b.createRRMessage=function(c,f,h,n,m,g){if(null==c||"undefined"==typeof c)throw{code:"114010",message:e["114010"]};if(null==f||"undefined"==typeof f)throw{code:"114011",message:e["114011"]};if(null==n||"undefined"==typeof n)throw{code:"114012",message:e["114012"]};if(null==m||"undefined"==typeof m)throw{code:"114013",message:e["114013"]};var r=null;b.info.signCert=c;b.info.kmCert=h;b.info.revokeNum=m;b.info.signpair={};if(null==g||"undefined"==typeof g)b.info.signpair.privateKey=d.pki.privateKeyFromAsn1(d.pkcs8.decryptPrivateKeyInfo(f,n));b.info.signature_algorithm=d.pki.oids[c.siginfo.algorithmOid];var k=d.random.getBytes(16);return r={type:b.asn1.PKIBodyType.rr,version:0,toAsn1:function(){var c=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]),f=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.INTEGER,!1,String.fromCharCode(b.info.version)),a.create(a.Class.CONTEXT_SPECIFIC,4,!0,[d.pki.distinguishedNameToAsn1({attributes:b.info.signCert.subject.attributes})]),a.create(a.Class.CONTEXT_SPECIFIC,1,!1,String.fromCharCode(32)),a.create(a.Class.CONTEXT_SPECIFIC,5,!0,[a.create(a.Class.UNIVERSAL,a.Type.OCTETSTRING,!1,k)])]),h=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]);h.value.push(_RevDetails(b.info.signCert.serialNumber,b.info.revokeNum));null!=b.info.kmCert&&"undefined"!=typeof b.info.kmCert&&h.value.push(_RevDetails(b.info.kmCert.serialNumber,b.info.revokeNum));var e=a.create(a.Class.CONTEXT_SPECIFIC,11,!0,[]);e.value.push(h);c.value.push(f);c.value.push(e);f=a.create(a.Class.CONTEXT_SPECIFIC,0,!0,[a.create(a.Class.UNIVERSAL,a.Type.BITSTRING,!1,String.fromCharCode(0)+_processProtection("Sign",c,g))]);c.value.push(f);return c}}};b.createKURMessage=function(c,f,h){var e=null;b.info.snonce=d.random.getBytes(16);null==c||"undefined"==typeof c?b.info.newsignpair=d.pki.rsa.generateKeyPair(b.info.key_size):(b.info.newsignpair={},b.info.newsignpair.publicKey=c(b.info.key_size));0!=b.info.km_key_gen.length&&"user"==b.info.km_key_gen&&(b.info.newkmpair=d.pki.rsa.generateKeyPair(b.info.key_size));return e={type:b.asn1.PKIBodyType.kur,version:0,toAsn1:function(){var c=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]),n=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.INTEGER,!1,String.fromCharCode(b.info.version)),a.create(a.Class.CONTEXT_SPECIFIC,4,!0,[d.pki.distinguishedNameToAsn1({attributes:b.info.signCert.subject.attributes})]),a.create(a.Class.CONTEXT_SPECIFIC,1,!1,String.fromCharCode(32)),a.create(a.Class.CONTEXT_SPECIFIC,0,!0,[a.create(a.Class.UNIVERSAL,a.Type.GENERALIZEDTIME,!1,a.dateToGeneralizedTime(new Date))]),a.create(a.Class.CONTEXT_SPECIFIC,5,!0,[a.create(a.Class.UNIVERSAL,a.Type.OCTETSTRING,!1,b.info.snonce)])]);var g=b.info.caEncCert?a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[_CertRequest("Sign",e.type),_proofOfPossession(1,"Sign","keyupdate",f),a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[_attributeTypeAndValue("encryptedVID",_encryptedVID())])])]):a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[_CertRequest("Sign",e.type),_proofOfPossession(1,"Sign","keyupdate",f)])]);if(0!=b.info.km_key_gen.length&&"user"==b.info.km_key_gen){var k=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[_CertRequest("KM"),_proofOfPossession(1,"KM","keyupdate")]);g.value.push(k)}k=a.create(a.Class.CONTEXT_SPECIFIC,e.type,!0,[]);k.value.push(g);c.value.push(n);c.value.push(k);n=a.create(a.Class.CONTEXT_SPECIFIC,0,!0,[a.create(a.Class.UNIVERSAL,a.Type.BITSTRING,!1,String.fromCharCode(0)+_processProtection("Sign",c,h))]);c.value.push(n);return c}}};_RevDetails=function(b,f){return a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.CONTEXT_SPECIFIC,1,!1,d.util.hexToBytes(b))]),a.create(a.Class.UNIVERSAL,a.Type.BITSTRING,!1,_genRevokeNum(f))])};_genRevokeNum=function(a){switch(a){case 0:a="80";var b=7;break;case 1:a="40";b=6;break;case 2:a="20";b=5;break;case 3:a="10";b=4;break;case 4:a="08";b=3;break;case 5:a="04";b=2;break;case 6:a="02";b=1;break;case 7:a="01";b=0;break;case 8:a="8000";b=15;break;default:throw{code:"114014",message:e["114014"]+"("+a+")"};}return String.fromCharCode(b)+d.util.hexToBytes(a)};_parseIPMessage=function(c){if(null==c||"undefined"==typeof c)throw{code:"114015",message:e["114015"]};var f={},h=[];if(!a.validate(c.header,b.asn1.PKIHeader,f,h))throw{code:"114051",message:e["114051"],errors:h};var d=a.derToOid(f.protectionAlg.value[0].value[0].value);if(b.info.snonce!=f.recipNonce.value[0].value)throw{code:"114052",message:e["114052"],errors:h};b.info.rnonce=f.senderNonce.value[0].value;f=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]);f.value.push(c.header);f.value.push(c.body);if("passwordBasedMac"==g[d])d=_processProtection("MAC",a.toDer(f).getBytes());else throw{code:"114016",message:e["114016"]+"("+d+")"};if(d==c.protection.value[0].value.substring(1))_processCertRepMessage(c,b.asn1.PKIBodyType.ip);else throw{code:"114027",message:e["114027"]};};_parseRPMessage=function(c){var f={},h=[];if(!a.validate(c.body.value[0],b.asn1.RevRepContent,f,h))throw{code:"114028",message:e["114028"],errors:h};for(c=0;c<f.status.value.length;c++){var d={};if(!a.validate(f.status.value[c],b.asn1.PKIStatusInfo,d,h))throw{code:"114029",message:e["114029"],errors:h};if(0!=d.status&&(d=_parsePKIFreeText(d.statusString),"granted"!=d[0]))throw{code:"114030",message:e["114030"]+d[0],errors:h};}};_processCertRepMessage=function(c,f){var h={},n={},g={},k=[];if(!a.validate(c.body.value[0],b.asn1.CertRepMessage,h,k))throw{code:"114017",message:e["114017"],errors:k};null!=h.caPubs&&_getCAPubs(h.caPubs);for(c=0;c<h.response.value.length;c++){if(!a.validate(h.response.value[c],b.asn1.CertResponse,n,k))throw{code:"114018",message:e["114018"],errors:k};if(b.info.certReqId[c]==n.certReqId.charCodeAt()){if(!a.validate(n.status,b.asn1.PKIStatusInfo,g,k))throw{code:"114019",message:e["114019"],errors:k};if(0==g.status.charCodeAt()){var l={};if(!a.validate(n.certifiedKeyPair,b.asn1.CertifiedKeyPair,l,k))throw{code:"114020",message:e["114020"],errors:k};if(null!=l.certificate)if(b.user.signcert=d.pki.certificateToBase64(d.pki.certificateFromAsn1(l.certificate[0])),null==b.info.signpair.privateKey||"undefined"==typeof b.info.signpair.privateKey)b.user.vidr=b.info.r;else if(b.asn1.PKIBodyType.ip==f)b.user.signpri=d.pkcs8.encryptRsaPrivateKey(b.info.signpair.privateKey,b.info.r,b.info.text,{algorithm:"seed"},"base64");else if(b.asn1.PKIBodyType.kup==f)b.user.signpri=d.pkcs8.encryptRsaPrivateKey(b.info.newsignpair.privateKey,b.info.r,b.info.text,{algorithm:"seed"},"base64"),console.debug("signCertUpdate : "+b.user.signcert),console.debug("signpriUpdate : "+b.user.signpri);else throw{code:"114049",message:e["114049"],errors:k};else if(null!=l.EncryptedCert){var p={};if(!a.validate(l.EncryptedCert.value[0],b.asn1.EncryptedValue,p,k))throw{code:"114021",message:e["114021"],errors:k};l=p.encSymmKey.substring(1);p=p.encValue.substring(1);if(b.asn1.PKIBodyType.ip==f)var q=b.info.kmpair.privateKey;else if(b.asn1.PKIBodyType.kup==f)q=b.info.newkmpair.privateKey;else throw{code:"114050",message:e["114050"],errors:k};l=q.decrypt(l);b.info.secret=l;l=d.cipher.algorithms.desofb.startEncrypting(l,"01234567");l.update(d.util.createBuffer(p));l.finish();b.user.kmcert=d.pki.certificateToBase64(d.pki.certificateFromAsn1(a.fromDer(d.util.createBuffer(l.output.data))));if(b.asn1.PKIBodyType.ip==f)b.user.kmpri=d.pkcs8.encryptRsaPrivateKey(b.info.kmpair.privateKey,b.info.r,b.info.text,{algorithm:"seed"},"base64");else if(b.asn1.PKIBodyType.kup==f)b.user.kmpri=d.pkcs8.encryptRsaPrivateKey(b.info.newkmpair.privateKey,b.info.r,b.info.text,{algorithm:"seed"},"base64");else throw{code:"114050",message:e["114050"],errors:k};}else throw{code:"114022",message:e["114022"],errors:k};}else{if(2==g.status.charCodeAt()){if(null!=g.statusString){f=_parsePKIFreeText(g.statusString);if(null!=g.failInfo)throw{code:"114023",message:e["114023"]+f[0]+"(PKIFailureInfo : "+g.failInfo.charCodeAt()+")",errors:k};throw{code:"114024",message:e["114024"]+f[0],errors:k};}throw{code:"114025",message:e["114025"]+g.failInfo.charCodeAt(),errors:k};}throw{code:"114026",message:e["114026"]+"(CertResponse status:"+n.status.value[0].value.charCodeAt()+")",errors:k};}}}b.info.r="";b.info.text=""};_parseKUPMessage=function(c){if(null==c||"undefined"==typeof c)throw{code:"114045",message:e["114045"]};var f={},h=[];if(!a.validate(c.header,b.asn1.PKIHeader,f,h))throw{code:"114053",message:e["114053"],errors:h};var d=a.derToOid(f.protectionAlg.value[0].value[0].value);if(b.info.snonce!=f.recipNonce.value[0].value)throw{code:"114054",message:e["114054"],errors:h};b.info.rnonce=f.senderNonce.value[0].value;f=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]);f.value.push(c.header);f.value.push(c.body);if("sha256WithRSAEncryption"==g[d])d=_processProtectionVerify(a.toDer(f).getBytes(),c.protection.value[0].value.substring(1));else throw{code:"114046",message:e["114046"]+"("+d+")"};if(1==d)_processCertRepMessage(c,b.asn1.PKIBodyType.kup);else throw{code:"114047",message:e["114047"]};};_parseErrMessage=function(c){var f={},h={},d=[];if(!a.validate(c.body.value[0],b.asn1.ErrorMsgContent,f,d))throw{code:"114031",message:e["114031"],errors:d};if(!a.validate(f.status,b.asn1.PKIStatusInfo,h,d))throw{code:"114032",message:e["114032"],errors:d};c=_parsePKIFreeText(h.statusString);throw{code:"114033",message:e["114033"]+c[0],errors:d};};_parsePKIFreeText=function(a){if(null==a||"undefined"==typeof a)throw{code:"114034",message:e["114034"]};for(var b=[],c,d=0;d<a.value.length;++d)c=a.value[d],b.push(c.value);return b};_CertRequest=function(c,f){if(null==c||"undefined"==typeof c)throw{code:"114035",message:e["114035"]};var h=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.INTEGER,!1,String.fromCharCode("Sign"==c?b.info.certReqId[0]:b.info.certReqId[1])),_CertTemplate(c)]);b.asn1.PKIBodyType.kur==f&&"Sign"==c&&(c=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.OID,!1,a.oidToDer(g.oldCertID).getBytes()),a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.CONTEXT_SPECIFIC,4,!0,[d.pki.distinguishedNameToAsn1({attributes:b.info.signCert.issuer.attributes})]),a.create(a.Class.UNIVERSAL,a.Type.INTEGER,!1,d.util.hexToBytes(b.info.signCert.serialNumber))])])]),h.value.push(c));return h};_CertTemplate=function(b){var c=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]);c.value.push(_setCertTemplate(6,b));return c};_setCertTemplate=function(a,f){f="Sign"==f?"undefined"!=typeof b.info.newsignpair&&null!=b.info.newsignpair&&null!=b.info.newsignpair.publicKey&&""!=b.info.newsignpair.publicKey?d.pki.publicKeyToAsn1(b.info.newsignpair.publicKey):d.pki.publicKeyToAsn1(b.info.signpair.publicKey):"undefined"!=typeof b.info.newkmpair&&null!=b.info.newkmpair&&null!=b.info.newkmpair.publicKey&&""!=b.info.newkmpair.publicKey?d.pki.publicKeyToAsn1(b.info.newkmpair.publicKey):d.pki.publicKeyToAsn1(b.info.kmpair.publicKey);switch(a){case 6:if(-1<b.info.signature_algorithm.indexOf("RSA"))return _change(f);throw{code:"114036",message:e["114036"],errors:errors};}};_change=function(b){if(null==b||"undefined"==typeof b)throw{code:"114037",message:e["114037"]};var c=a.create(a.Class.CONTEXT_SPECIFIC,6,!0,[]);c.value.push(a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[b.value[0].value[0]]));c.value.push(b.value[1]);return c};_freeTextSplit=function(a){a=a.split("$");for(var c=0;c<a.length;c++)if(""!=a[c]){var d=a[c].split("=");if("signature_algorithm"==d[0])b.info.signature_algorithm=d[1];else if("key_size"==d[0])b.info.key_size=d[1];else if("km_key_gen"==d[0])b.info.km_key_gen=d[1];else if("km_key_backup"==d[0])b.info.km_key_backup=d[1];else if("passwd_len"==d[0])b.info.passwd_len=d[1];else if("passwd_num_len"==d[0])b.info.passwd_num_len=d[1];else if("allow_suspend"==d[0])b.info.allow_suspend=d[1];else if("dir_server_addr"==d[0])b.info.dir_server_addr=d[1];else throw{code:"114038",message:e["114038"]+"("+d[0]+":"+d[1]+")",errors:errors};}};_proofOfPossession=function(c,d,h,k){"undefined"==typeof h&&(h="new");var f=a.create(a.Class.CONTEXT_SPECIFIC,c,!0,[]);switch(c){case 0:throw{code:"114039",message:e["114039"]};case 1:c=_popoSigningKeyInput(0,d);f.value.push(a.create(a.Class.CONTEXT_SPECIFIC,0,!0,[c.value[0],c.value[1]]));f.value.push(a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.OID,!1,a.oidToDer(g[b.info.signature_algorithm]).getBytes())]));f.value.push(a.create(a.Class.UNIVERSAL,a.Type.BITSTRING,!1,String.fromCharCode(0)+_signature(c,d,h,k)));break;case 2:throw{code:"114040",message:e["114040"]};case 3:throw{code:"114041",message:e["114041"]};default:throw{code:"114042",message:e["114042"]};}return f};_popoSigningKeyInput=function(c,f){var h=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]);switch(c){case 0:h.value.push(a.create(a.Class.CONTEXT_SPECIFIC,c,!0,[a.create(a.Class.CONTEXT_SPECIFIC,1,!1,String.fromCharCode(32))]));break;default:throw{code:"114043",message:e["114043"]};}publickeyValue="Sign"==f?"undefined"!=typeof b.info.newsignpair&&null!=b.info.newsignpair&&null!=b.info.newsignpair.publicKey&&""!=b.info.newsignpair.publicKey?d.pki.publicKeyToAsn1(b.info.newsignpair.publicKey):d.pki.publicKeyToAsn1(b.info.signpair.publicKey):"undefined"!=typeof b.info.newkmpair&&null!=b.info.newkmpair&&null!=b.info.newkmpair.publicKey&&""!=b.info.newkmpair.publicKey?d.pki.publicKeyToAsn1(b.info.newkmpair.publicKey):d.pki.publicKeyToAsn1(b.info.kmpair.publicKey);c=_change(publickeyValue);h.value.push(a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[c.value[0],c.value[1]]));return h};_signature=function(c,f,h,e){var g=b.info.signature_algorithm.split("With");if("Sign"==f)if("keyupdate"==h){if(null==e||"undefined"==typeof e)var k=b.info.newsignpair.privateKey}else{if(null==e||"undefined"==typeof e)k=b.info.signpair.privateKey}else k="keyupdate"==h?b.info.newkmpair.privateKey:b.info.kmpair.privateKey;f=d.md.algorithms[g[0]].create();f.start();f.update(a.toDer(c).getBytes());return null==e||"undefined"==typeof e?k.sign(f):e(f)};_attributeTypeAndValue=function(b,d){var c=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]);c.value.push(a.create(a.Class.UNIVERSAL,a.Type.OID,!1,a.oidToDer(g[b]).getBytes()));null!=d&&c.value.push(d);return c};_encryptedVID=function(){var c=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[]);c.value.push(a.create(a.Class.CONTEXT_SPECIFIC,0,!0,[a.create(a.Class.UNIVERSAL,a.Type.INTEGER,!1,String.fromCharCode(0))]));c.value.push(a.create(a.Class.CONTEXT_SPECIFIC,2,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.OID,!1,a.oidToDer(g.RSAEncryption).getBytes()),a.create(a.Class.UNIVERSAL,a.Type.NULL,!1,"")])]));c.value.push(a.create(a.Class.CONTEXT_SPECIFIC,3,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[b.info.caEncCert.value[0].value[3],b.info.caEncCert.value[0].value[1]])]));c.value.push(a.create(a.Class.CONTEXT_SPECIFIC,4,!0,[a.create(a.Class.UNIVERSAL,a.Type.OCTETSTRING,!1,_encVID())]));return c};_encVID=function(){var c=b.info.signature_algorithm.split("With");b.info.r=d.random.getBytes(20);var f=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.PRINTABLESTRING,!1,"1234561234567"),a.create(a.Class.UNIVERSAL,a.Type.BITSTRING,!1,String.fromCharCode(0)+b.info.r)]),e=d.md.algorithms[c[0]].create();e.start();e.update(a.toDer(f).getBytes());f=e.digest();e.start();e.update(f.bytes());f=e.digest();c=a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.SEQUENCE,!0,[a.create(a.Class.UNIVERSAL,a.Type.OID,!1,a.oidToDer(g[c[0]]).getBytes())]),a.create(a.Class.CONTEXT_SPECIFIC,0,!0,[a.create(a.Class.UNIVERSAL,a.Type.OCTETSTRING,!1,f.bytes())])]),a.create(a.Class.UNIVERSAL,a.Type.BITSTRING,!1,String.fromCharCode(0)+b.info.r)]);return d.pki.certificateFromAsn1(b.info.caEncCert).publicKey.encrypt(a.toDer(c).getBytes())};_processProtection=function(a,b,d){if("Sign"==a)a=_processProtectionSign(b,d);else if("MAC"==a)a=_processProtectionMac(b);else throw{code:"114044",message:e["114044"],errors:errors};return a};_processProtectionVerify=function(a,f){var c=d.pki.certificateFromAsn1(b.info.caSignCert),e=g[c.signatureOid].split("With");e=d.md.algorithms[e[0]].create();e.start();e.update(a);return c.publicKey.verify(e.digest().getBytes(),f)};_processProtectionSign=function(a,b){return _signature(a,"Sign","new",b)};_processProtectionMac=function(a){if(""!=b.info.secret&&"undefined"!==typeof b.info.secret){var c="aaaaabbbbb"+d.util.bytesToHex(b.info.secret);b.info.secret=""}else c="aaaaabbbbb"+b.info.secretValue;for(var e=d.md.algorithms.sha1.create(),g=0;2>g;g++)e.start(),e.update(c),c=e.digest(),c=c.bytes();c=d.cipher.algorithms.des.startEncrypting(c.substring(0,8),d.util.hexToBytes("0000000000000000"));c.update(d.util.createBuffer(a));c.finish(_zero_padding);c=c.output.data;return c.substring(c.length-8,c.length)};_zero_padding=function(a,b,d){d||(a=b.length()==a?0:a-b.length(),b.fillWithByte(0,a));return!0};_getCAPubs=function(a){for(var c={certs:{}},e=0;e<a.value[0].value.length;e++){var g=d.x509Certificate.parser(a.value[0].value[e],"ASN1");""==d.x509Certificate.getAuthorityKeyIdentifier()?b.ca.RootCA=d.pki.certificateToPem(g):(c.certs[g.subject.hash]=d.pki.certificateToPem(g),e==a.value[0].value.length-1&&(b.ca.CA=c))}}}var l="./asn1 ./oids ./cmpasn1 ./pki ./util ./random ./jsustoolkitErrCode".split(" "),k=null;"function"!==typeof define&&("object"===typeof module&&module.exports?k=function(d,e){e(require,module)}:(crosscert=window.crosscert=window.crosscert||{},g(crosscert)));(k||"function"===typeof define)&&(k||define)(["require","module"].concat(l),function(d,e){e.exports=function(a){var b=l.map(function(a){return d(a)}).concat(g);a=a||{};a.defined=a.defined||{};if(a.defined.cmp)return a.cmp;a.defined.cmp=!0;for(var e=0;e<b.length;++e)b[e](a);return a.cmp}})})();
|