importcert.js 12 KB

1
  1. var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.checkStringArgs=function(a,d,b){if(null==a)throw new TypeError("The 'this' value for String.prototype."+b+" must not be null or undefined");if(d instanceof RegExp)throw new TypeError("First argument to String.prototype."+b+" must not be a regular expression");return a+""};$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(a,d,b){a!=Array.prototype&&a!=Object.prototype&&(a[d]=b.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(a,d,b,k){if(d){b=$jscomp.global;a=a.split(".");for(k=0;k<a.length-1;k++){var l=a[k];l in b||(b[l]={});b=b[l]}a=a[a.length-1];k=b[a];d=d(k);d!=k&&null!=d&&$jscomp.defineProperty(b,a,{configurable:!0,writable:!0,value:d})}};$jscomp.polyfill("String.prototype.startsWith",function(a){return a?a:function(a,b){var d=$jscomp.checkStringArgs(this,a,"startsWith");a+="";var l=d.length,m=a.length;b=Math.max(0,Math.min(b|0,d.length));for(var r=0;r<m&&b<l;)if(d[b++]!=a[r++])return!1;return r>=m}},"es6","es3");$jscomp.polyfill("String.prototype.endsWith",function(a){return a?a:function(a,b){var d=$jscomp.checkStringArgs(this,a,"endsWith");a+="";void 0===b&&(b=d.length);b=Math.max(0,Math.min(b|0,d.length));for(var l=a.length;0<l&&0<b;)if(d[--b]!=a[--l])return!1;return 0>=l}},"es6","es3");var __importcert=function(a){function d(a,b){a=document.getElementsByClassName(a);for(var c=0;c<a.length;c++)a[c].classList.contains(b)||a[c].classList.add(b)}function b(a,b){a=document.getElementsByClassName(a);for(var c=0;c<a.length;c++)a[c].classList.remove(b)}function k(a,b){return 0==document.getElementsByClassName(a).length?!1:document.getElementsByClassName(a)[0].classList.contains(b)}var l=function(m){function l(a){if(!a)return alert("UI load error."),!1;var g=document.createElement("div");document.body.insertBefore(g,document.body.firstChild);g.innerHTML=a;return!0}function c(a){return document.getElementById(a)}function q(a,b){a=c(a);a.appendChild(document.createTextNode(b));a.setAttribute("tabindex",u++,0);return a}function z(a,b){a=c(a);for(var g=0;g<a.children.length;g++)a.children[g].appendChild(document.createTextNode(b[g]));return a}function C(b,c){b=document.getElementById(b);b.setAttribute("src",a.ESVS.SRCPath+c,0);return b}var G=function(){var b=window.XMLHttpRequest?new window.XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0");b.open("GET",a.ESVS.SRCPath+"unisignweb/rsrc/layout/importCertWithDD.html?V="+a.ver,!1);b.send(null);return b.responseText},H=function(){var b=window.XMLHttpRequest?new window.XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0");b.open("GET",a.ESVS.SRCPath+"unisignweb/rsrc/lang/"+a.ESVS.Language+"/importcert_"+a.ESVS.Language+".js?V="+a.ver,!1);b.send(null);return b.responseText},f=null,u=a.ESVS.TabIndex,h={filelist:[]},A=function(a){var g=new FileReader;g.onload=function(g){h.filelist.push({name:a.name,data:g.target.result.toBase64()});"pfx"==h.type?(D(),b("us-pfx-name","hide"),c("us-txt-pfx-name").classList.remove("hide"),c("us-txt-pfx-name").innerHTML=h.filelist[0].name,d("view-panel","hide"),b("cert-info","hide"),b("us-cert-import-content","drop-here"),b("us-cert-import-content","drag"),d("us-cert-import-content","drop")):"fullpfx"==h.type&&4==h.filelist.length?E():"signpfx"==h.type&&2==h.filelist.length&&E();document.getElementById("us-pw-text").focus()};g.readAsArrayBuffer(a)},D=function(){d("us-list-sublist","hide");d("us-pfx-name","hide");b("password","hide");"searchpfx"!=m.type&&(c("us-div-pfx-download").classList.add("hide"),c("us-cert-import-pfx-download").checked=!1)},E=function(){D();a.usWebToolkit.x509Certificate.parser(v("signCert"),"Base64");h.certattr={issuer:a.certUtil().getO(a.usWebToolkit.x509Certificate.getSubjectName()),expire:a.certUtil().getLocalDate(a.usWebToolkit.x509Certificate.getNotAfter()),name:a.certUtil().getCN(a.usWebToolkit.x509Certificate.getSubjectName()),dn:a.usWebToolkit.x509Certificate.getSubjectName()};c("us-div-pfx-download").classList.remove("hide");b("us-list-sublist","hide");for(var g=document.getElementsByClassName("us-list-sublist"),t=0;t<g.length-1;t++)g[t].children[1].innerHTML=h.certattr[g[t].classList[1]];c("us-cert-import-pfx-download").checked=!1;d("view-panel","hide");b("cert-info","hide");b("us-cert-import-content","drop-here");b("us-cert-import-content","drag");d("us-cert-import-content","drop")},F=function(){var b=c("us-pw-text").value,d=!1;if(1>b.length)return f.IDS_ERROR.INPUT_PASSWORD;if("pfx"==h.type){var p=h.filelist[0].data;try{var n=a.usWebToolkit.util.decode64(p),e=der=crosscert.asn1.fromDer(n);a.usWebToolkit.pkcs12.getCertNKeyFromPKCS12(e,b)}catch(x){return 115010==x.code?f.IDS_ERROR.NO_MATCH_PASSWORD:"Error Message : "+x.message+" \nError Code : "+x.code}"searchpfx"==m.type&&c("us-cert-import-pfx-download").checked&&(d=!0)}else{p=a.usWebToolkit.pkcs8.encryptedPrivateKeyFromBase64(v("signPri"));n=a.usWebToolkit.pkcs8.checkUserCertPassword(p,b);if(!n)return f.IDS_ERROR.NO_MATCH_PASSWORD;e=a.usWebToolkit.pki.certificateFromBase64(v("signCert"));var k=null,l=null;if("fullpfx"==h.type&&(k=a.usWebToolkit.pki.certificateFromBase64(v("kmCert")),l=a.usWebToolkit.pkcs8.encryptedPrivateKeyFromBase64(v("kmPri")),n=a.usWebToolkit.pkcs8.checkUserCertPassword(l,b),!n))return f.IDS_ERROR.NO_MATCH_PASSWORD;p=a.usWebToolkit.pkcs12.makePKCS12(e,p,k,l,b,{useMac:!0,generateLocalKeyId:!0});e=a.usWebToolkit.asn1.toDer(p).getBytes();p=a.usWebToolkit.util.encode64(e);c("us-cert-import-pfx-download").checked&&("searchpfx"==m.type?d=!0:a.fileUtil().save(h.certattr.dn+".pfx",p.toArrayBuffer()))}m.onConfirm(p,b,d);return null},v=function(a){for(var b=0;b<h.filelist.length;b++)if(h.filelist[b].name.startsWith(a))return h.filelist[b].data;return null},B=function(a){if(1==a.length){var b=a[0];return"application/x-pkcs12"==b.type&&(b.name.toLowerCase().endsWith(".pfx")||b.name.toLowerCase().endsWith(".p12"))?(h.type="pfx",null):f.IDS_ERROR.NO_P12_FILE}if(2==a.length||4==a.length){for(var c=0,d=0,e=0;e<a.length;e++)b=a[e],"signcert.der"==b.name.toLowerCase()||"signcert.cer"==b.name.toLowerCase()?c+=1:"signpri.key"==b.name.toLowerCase()?c+=3:"kmcert.der"==b.name.toLowerCase()||"kmcert.cer"==b.name.toLowerCase()?d+=1:"kmpri.key"==b.name.toLowerCase()&&(d+=3);if(0==c)return f.IDS_ERROR.NO_SIGNCERT;if(1==c)return f.IDS_ERROR.NO_SIGNPRIKEY;if(3==c||4!=c)return f.IDS_ERROR.NO_SIGNCERT;if(4==a.length){if(0==d)return f.IDS_ERROR.NO_KMCERT;if(1==d)return f.IDS_ERROR.NO_KMPRIKEY;if(3==d||4!=d)return f.IDS_ERROR.NO_KMCERT;h.type="fullpfx"}else h.type="signpfx"}else return f.IDS_ERROR.INVALID_FILE_COUNT;return null};return function(){var g=a.CustomEval(G);f=a.CustomEval(H,!0);l(g());g=c("us-div-import-cert");var t=q("us-import-cert-lbl-title",f.IDS_TITLE);t.setAttribute("tabindex",u,0);var p=C("us-cls-btn-img","unisignweb/rsrc/img/x-btn.png"),n=document.getElementById("us-cls-btn");n.onclick=function(a){m.onCancel()};n.onkeydown=function(a){if(13==a.keyCode)m.onCancel()};n.setAttribute("tabindex",u+8,0);n.onfocus=function(a){p.style.border="1px dotted white"};z("us-content-basic-notice-ul",f.IDS_CONTENT_NOTICE_UL);z("us-content-drop-plz-ul",f.IDS_CONTENT_DROP_UL);C("us-import-cert-img","unisignweb/rsrc/img/cert_valid.png");for(var e=document.getElementsByClassName("us-list-sublist"),r=0;r<e.length;r++)e[r].children[0].appendChild(document.createTextNode(f.IDS_CERT_INFO[e[r].classList[1]]));a.uiUtil().addCapsLockEvent("us-pw-text","us-import-cert-err-msg-capslock",f.IDS_MSGBOX_CAPSLOCK_ON,null);e=c("us-pw-text");e.setAttribute("tabindex",u+2,0);e.setAttribute("title",f.IDS_CERT_INFO.password,0);e.onkeydown=function(a){13==a.keyCode&&(a=F(),null!=a&&alert(a))};e.onkeyup=function(a){a.getModifierState&&(a.getModifierState("CapsLock")?document.getElementById("us-import-cert-err-msg-capslock").style.display="block":document.getElementById("us-import-cert-err-msg-capslock").style.display="none")};e=null;e="searchpfx"==m.type?q("us-cert-import-pfx-download-txt",f.IDS_PFX_SAVETO):q("us-cert-import-pfx-download-txt",f.IDS_PFX_DOWNLOAD);e.setAttribute("tabindex",u+3,0);e.onclick=function(){c("us-cert-import-pfx-download").checked=!c("us-cert-import-pfx-download").checked};e.onkeydown=function(a){13==a.keyCode&&(c("us-cert-import-pfx-download").checked=!c("us-cert-import-pfx-download").checked)};e=c("us-btn-cert-import");e.value=f.IDS_CERT_IMPORT;e.setAttribute("tabindex",u+4,0);e.onclick=function(a){a.preventDefault();a.returnValue=!1;a.cancelBubble=!0;a=F();null!=a&&alert(a)};var w=c("us-btn-import");w.value=f.IDS_TITLE;w.setAttribute("tabindex",u+6,0);w.onclick=function(a){k("cert-info","hide")&&(document.getElementById("us-cert-import-file").onchange=function(a){if(!a.target.files||0!=a.target.files.length){var b=B(a.target.files);if(null!=b)alert(b);else for(w.style.display="none",b=0;b<a.target.files.length;b++)A(a.target.files[b])}},document.getElementById("us-cert-import-file").click())};var x=c("us-btn-re-try");x.setAttribute("tabindex",u+5,0);x.value=f.IDS_RE_TRY;x.onclick=function(a){a.preventDefault();a.returnValue=!1;a.cancelBubble=!0;h={filelist:[]};b("us-cert-import-content","drop-here");d("us-cert-import-content","drag");d("view-panel","hide");b("basic","hide");c("us-pw-text").value="";w.style.display="block";document.getElementById("us-cert-import-file").value="";return!1};var y=document.getElementsByClassName("us-cert-import-content")[0];y.setAttribute("tabindex",u+1,0);y.onclick=function(a){if("us-cert-import-pfx-download"==a.target.id)return!0;a.preventDefault();k("cert-info","hide")&&(document.getElementById("us-cert-import-file").onchange=function(a){if(!a.target.files||0!=a.target.files.length){var b=B(a.target.files);if(null!=b)alert(b);else for(w.style.display="none",b=0;b<a.target.files.length;b++)A(a.target.files[b])}},document.getElementById("us-cert-import-file").click())};y.onkeydown=function(a){13==a.keyCode&&k("cert-info","hide")&&(document.getElementById("us-cert-import-file").onchange=function(a){if(!a.target.files||0!=a.target.files.length){var b=B(a.target.files);if(null!=b)alert(b);else for(w.style.display="none",b=0;b<a.target.files.length;b++)A(a.target.files[b])}},document.getElementById("us-cert-import-file").click())};y.ondragleave=function(a){a.preventDefault()};y.ondragover=function(a){k("cert-info","hide")&&(d("us-cert-import-content","drop-here"),b("us-cert-import-content","drag"),d("view-panel","hide"),b("drop-plz","hide"));a.preventDefault()};y.ondrop=function(a){a.preventDefault();if(k("cert-info","hide")){b("us-cert-import-content","drop-here");d("us-cert-import-content","drag");d("view-panel","hide");b("basic","hide");a=a.dataTransfer.files;var c=B(a);if(null!=c){alert(c);return}w.style.display="none";for(c=0;c<a.length;c++)A(a[c])}return!1};n.onkeydown=function(a){var b=a||window.event,c=b.which||b.keyCode;9==c&&b.shiftKey&&(n.onblur=function(){p.style.border="";setTimeout(function(){y.classList.contains("hide")?x.focus():w.focus()},10)});9!=c||b.shiftKey||(n.onblur=function(){p.style.border="";setTimeout(function(){t.focus()},10)});13==a.keyCode&&(a.preventDefault(),m.onCancel())};var v=!1;t.onkeyup=function(a){a=a||window.event;9==(a.which||a.keyCode)&&a.shiftKey&&v&&(v=!1,setTimeout(function(){n.focus()},10))};t.onkeydown=function(a){a=a||window.event;if(9==(a.which||a.keyCode)&&a.shiftKey)return a.cancelBubble=!0,v=a.returnValue=!0,!1};b("basic","hide");return g}()};return function(m){var r=a.uiLayerLevel,c=a.uiUtil().getOverlay(r),q=l({type:m.type,args:m.args,onConfirm:m.onConfirm,onCancel:m.onCancel});q.style.zIndex=r+1;a.ESVS.TargetObj.insertBefore(c,a.ESVS.TargetObj.firstChild);c.ondragleave=function(a){null==a.relatedTarget&&k("cert-info","hide")&&(b("us-cert-import-content","drop-here"),d("us-cert-import-content","drag"),d("view-panel","hide"),b("basic","hide"));a.preventDefault()};var z=window.onresize;return{show:function(){draggable(q,document.getElementById("us-div-cert-manage-title"));c.style.display="block";a.uiUtil().offsetResize(q);window.onresize=function(){a.uiUtil().offsetResize(q)};a.uiLayerLevel+=10;a.ESVS.TabIndex+=30;setTimeout(function(){var a=q.getElementsByTagName("p");if(0<a.length)for(var b=0;b<a.length;b++)"us-import-cert-lbl-title"==a[b].id&&a[b].focus()},10)},hide:function(){c.style.display="none";q.style.display="none"},dispose:function(){window.onresize=function(){z&&z()};q.parentNode.parentNode.removeChild(q.parentNode);c.parentNode.removeChild(c);a.uiLayerLevel-=10;a.ESVS.TabIndex-=30}}}};