(function(){function y(e){e=window.crosscert||{};var m=e.usWebCMPXMLHttp=e.usWebCMPXMLHttp||{},b=e.usWebCMP=e.usWebCMP||{},k=e.cmp=e.cmp||{},d=e.util||{},t=e.asn1||{},w=null,f=null,A=null,B=null,u=null,C=null,z=null;b.info={version:"0a",pkiReq:"00",pkiRep:"05",flags:"00",CMPUrl:"https://solar1.crosscert.com:8443"};b.revReason=k.revReason;b.issueCert=function(a,g,c,e,l,h,d,q,p,r){try{if(null==h||"undefined"==typeof h)throw{code:"120004",message:"StorageHendler is empty."};w=h;if(null==d||"undefined"==typeof d)throw{code:"120005",message:"The CMP callback function is empty."};f=d;null!=q&&"undefined"!=typeof q&&(A=q);null!=p&&"undefined"!=typeof p&&(B=p);null!=r&&"undefined"!=typeof r&&(u=r);b.info.storageInfo=e;var D=k.createGenmMessage(a,g,c,l),n=_create(D.toAsn1());m.uniSignE2ERequest("POST",n,b.info.CMPUrl+"/GenmGenp.do",_issueCertGenPIR)}catch(x){f(3,"",x)}};_issueCertGenPIR=function(a){if("object"==typeof a)_showErrMSG(a);else try{var g=_parse(a);k.messageFromAsn1(g);try{var c=e.cmp.createIRMessage(A,B),d=_create(c.toAsn1());m.uniSignE2ERequest("POST",d,b.info.CMPUrl+"/IrIp.do",_issueCertIPConf)}catch(l){f(3,"",l)}}catch(l){null!=l.code?_errMsg(l.message):f(3,"",l)}};_issueCertIPConf=function(a){if("object"==typeof a)_showErrMSG(a);else try{var g=_parse(a);k.messageFromAsn1(g);try{var c;if(null==u||"undefined"==typeof u)if(c=_saveCertificate()){var d=e.cmp.createConfirmMessage(),l=_create(d.toAsn1());m.uniSignE2ERequest("POST",l,b.info.CMPUrl+"/Confirm.do",_CMPConfirm)}else _CMPConfirm({status:"-1",statusText:"Fail to Save Certificate"});else u(w,k.user,_getCAName(e.pki.certificateFromBase64(k.user.signcert)),function(a){a?(a=e.cmp.createConfirmMessage(),a=_create(a.toAsn1()),m.uniSignE2ERequest("POST",a,b.info.CMPUrl+"/Confirm.do",_CMPConfirm)):_CMPConfirm({status:"-1",statusText:"Fail to Save Certificate"})})}catch(h){f(3,"",h)}}catch(h){null!=h.code?_errMsg(h.message):f(3,"",h)}};_CMPConfirm=function(a){if("object"==typeof a)_showErrMSG(a);else try{var b=_parse(a);endtime=(new Date).getTime();"00"==d.bytesToHex(b)?f(1,""):f(2,"CMP fail!")}catch(c){null!=c.code?_errMsg(c.message):f(3,"",c)}};_errMsg=function(a){a="EncodingType=utf8&ErrMessage="+encodeURIComponent(b.messageToBase64(e.util.createBuffer(a)));m.uniSignE2ERequest("POST",a,b.info.CMPUrl+"/EncodingErrMsg.do",_showErrMSG,"application/x-www-form-urlencoded;charset=UTF-8")};_showErrMSG=function(a){"object"==typeof a?f(2,(""!=a.statusText?a.statusText:a.responseText)+"(status :"+a.status+")"):f(2,b.messageFromBase64(a).toString())};_create=function(a){var g=d.createBuffer();a=t.toDer(a).getBytes();g.putBuffer(y(a.length+3));g.putBytes(d.hexToBytes(b.info.version));g.putBytes(d.hexToBytes(b.info.flags));g.putBytes(d.hexToBytes(b.info.pkiReq));g.putBytes(a);return b.messageToBase64(g)};_parse=function(a){a=b.messageFromBase64(decodeURIComponent(a));var g=a.getInt32();if(g!=a.length())throw{code:"120001",message:"WebCMP Message has wrong length."};if(a.getBytes(1)!=d.hexToBytes(b.info.version))throw{code:"120002",message:"WebCMP version is not supported."};a.getBytes(1);if(a.getBytes(1)!=d.hexToBytes(b.info.pkiRep))throw{code:"120003",message:"WebCMP message type is not supported."};return a.getBytes(g-3)};_saveCertificate=function(){try{w.SaveUserCert(_getCAName(e.pki.certificateFromBase64(k.user.signcert)),k.user,b.info.storageInfo,!0)}catch(a){throw a;}return!0};_getCertName=function(a){return(new e.x509Certificate.certUtil).getDN(a.subject)};_getCAName=function(a){a=a.subject;for(var b=0;b>>=8;while(0