browsersign.js 3.9 KB

1
  1. var __crosscertlocalstorage=function(t){function g(a,f,b){var c=JSON.parse(a),d={};d.messageNumber=f;d.operation=c.operation;d.certIdentifier=c.certIdentifier?c.certIdentifier:"";d.callback=b;d.valid=!0;10<=l&&(l=0);k[l]=d;l+=1;e+=1;try{document.getElementById("shareframe").contentWindow.postMessage(a,u)}catch(v){null!=b&&b(-1)}}function q(){n--;"function"===typeof window.addEventListener?window.removeEventListener("message",m,!1):window.detachEvent("onmessage",m)}function r(){0<n&&q();"function"===typeof window.addEventListener?window.addEventListener("message",m,!1):window.attachEvent("onmessage",m);n++}var e=0,h=Math.random();ccoperation="GetVersion GetStorageHandler GetCertificateList SaveUserCert SetP12OnMemory DeleteUserCertByIndex IsAvaliable GetP12ForBuToPc GetP12ForBuToMo DeleteUserCertByDN SetP12HexOnMemory".split(" ");var p=!1,c="",d="",l=0,k=[],u=t.ESVS.SHARESTORAGE,n=0,m=function(a){p=!0;if(!(null==a.data||0>=a.data.length)){var f,b=null;a=JSON.parse(a.data);for(f=0;f<k.length;f++)if(k[f].messageNumber==a.messageNumber){if(0==k[f].valid){k[f].callback(-1);return}b=k[f].callback;k[f]=0;break}a.operation==ccoperation[0]?(currentVersion=a.list?a.list[0].version:a.version,a=currentVersion.split("."),currentVersion=a[0]+"."+a[1]+"."+a[2]+".0",b&&b(currentVersion)):a.operation==ccoperation[1]?0!=a.resultCode?(c=a.resultCode,d=a.resultMessage,b(c,0)):b(a.resultCode,a.PFSH):a.operation==ccoperation[2]?0!=a.resultCode?(c=a.resultCode,d=a.resultMessage,b(c,0)):b(a.resultCode,a.userCerts):a.operation==ccoperation[3]?0!=a.resultCode?(c=a.resultCode,d=a.resultMessage,b(c,0)):b(a.resultCode,a.resultMessage):a.operation==ccoperation[4]?0!=a.resultCode?(c=a.resultCode,d=a.resultMessage,b(c,d)):b(a.resultCode,a.resultMessage,a.userCertsInfo):a.operation==ccoperation[5]?0!=a.resultCode?(c=a.resultCode,d=a.resultMessage,b(c,d)):b(a.resultCode,a.resultMessage):a.operation==ccoperation[6]?0!=a.resultCode?(c=a.resultCode,d=a.resultMessage,b(c,d)):b(a.resultCode,a.resultMessage):a.operation==ccoperation[7]?0!=a.resultCode?(c=a.resultCode,d=a.resultMessage,b(c,d)):b(a.resultCode,a.resultMessage,a.dn,a.p12):a.operation==ccoperation[8]?0!=a.resultCode?(c=a.resultCode,d=a.resultMessage,b(c,d)):b(a.resultCode,a.resultMessage,a.p12key,a.p12):a.operation==ccoperation[9]?0!=a.resultCode?(c=a.resultCode,d=a.resultMessage,b(c,d)):b(a.resultCode,a.resultMessage):a.operation==ccoperation[10]&&(0!=a.resultCode?(c=a.resultCode,d=a.resultMessage,b(c,d)):b(a.resultCode,a.resultMessage,a.userCertsInfo))}};r();return{Version:function(a){},GetLastErrorCode:function(){return c},GetLastErrorMessage:function(){return d},IsAvailable:function(){return p},GetIframeLoaded:function(){return p},IsCCPFSHAvailable:function(a){g(JSON.stringify({messageNumber:e,sessionID:""+h,operation:ccoperation[6]}),e,a)},GetCCStorageHandler:function(a,f,b,c){q();r();g(JSON.stringify({messageNumber:e,sessionID:""+h,operation:ccoperation[1],enc_algo:a,hash_algo:f,pki:b}),e,c)},SaveUserCert:function(a,c,b,d){g(JSON.stringify({messageNumber:e,sessionID:""+h,operation:ccoperation[3],caname:a,usercert:c,checkExist:b}),e,d)},GetCertificateList:function(a){g(JSON.stringify({messageNumber:e,sessionID:""+h,operation:ccoperation[2]}),e,a)},SetP12OnMemory:function(a,c,b){g(JSON.stringify({messageNumber:e,sessionID:""+h,operation:ccoperation[4],fileB64Bin:a,pw:c}),e,b)},DeleteUserCertByIndex:function(a,c){g(JSON.stringify({messageNumber:e,sessionID:""+h,operation:ccoperation[5],index:a}),e,c)},GetP12ForBuToPc:function(a,c,b,d){g(JSON.stringify({messageNumber:e,sessionID:""+h,operation:ccoperation[7],index:a,pw:c,retType:b}),e,d)},GetP12ForBuToMo:function(a,c,b){g(JSON.stringify({messageNumber:e,sessionID:""+h,operation:ccoperation[8],index:a,encoding:c}),e,b)},DeleteUserCertByDN:function(a,c,b,d){g(JSON.stringify({messageNumber:e,sessionID:""+h,operation:ccoperation[9],ca:a,dn:c,pw:b}),e,d)},SetP12HexOnMemory:function(a,c,b){g(JSON.stringify({messageNumber:e,sessionID:""+h,operation:ccoperation[10],p12Hex:a,p12Hexkey:c}),e,b)}}};