/** * Zjisti jestli pouzivam MSIE * @return true or false */ /* function _isMSIEBrowser() { return navigator.appVersion.indexOf("MSIE") != -1; } */ //get applet_test applet function _getAppletObject() { return document.getElementById('id_Sing_Applet_Object'); } function getLastError() { var errMessage; errMessage = _getAppletObject().applet_getLastError(); return errMessage; } //call applet_test, true applet is inicialized, false - any error ZBE function _simpleTest() { try { return _getAppletObject().applet_test("test method") == 'test method'; } catch(e) { if (getLastError().indexOf("INFO") != 0) alert("Exception function _simpleTest: " + getLastError()); return false; } } //applet_test of applet_test applet ZBE function testApplet_and_disableButtons() { var IsEnabled = _simpleTest(); if (IsEnabled) { try { document.getElementById('id_div_java_ok').style.display = "block"; } catch(e) { } try { document.getElementById('id_btn_podepsat').disabled = false; } catch(e) { } try { document.getElementById('id_btn_podepsat_soubor').disabled = false; } catch(e) { } try { document.getElementById('id_btn_podepsat_url').disabled = false; } catch(e) { } try { document.getElementById('id_btn_testjs').disabled = false; } catch(e) { } } else { try { document.getElementById('id_div_java_not').style.display = "block"; } catch(e) { } if (getLastError().indexOf("INFO") != 0) alert("Nepodarilo se inicializovat Applet pro podepsani. K uspesne inicializaci je vyzadovana Java 1.6 a vyssi."); //applet neni inicializovan } } /** * private method, podepisi text vybranym certifikatem (volam applet) * @param text k podpisu * @return structure pkcs_7 s signedData objektem vn formatu ASN1 v string kodovanem v Base64 */ function _singString(text, timestamp) { // u appletu predelam jednoduche entery na dvojte text = text.replace(/\r/g, ""); text = text.replace(/\n/g, "\r\n"); return _getAppletObject().applet_signString(text, timestamp); } /** * Podepisi souhrn z text pole a podpis ulozem do jineho text pole jako base64 */ function podepsatSouhrn() { try { var souhrnPodani = document.getElementById("id_textSouhrn"); //alert(SouhrnPodani.value); var podpis = document.getElementById("id_signedText"); podpis.value = ""; var timestamp = document.getElementById("id_timestamp"); // timestamp.value = new Date().getTime(); //put timestamp // provedu podepsani appletem podpis.value = _singString(souhrnPodani.value, timestamp.value); if (podpis.value != "") { //alert("Data byly podepsany."); } } catch(e) { if (getLastError().indexOf("INFO") != 0) window.alert("Exception function podepsatSouhrn: " + getLastError()); } } /** * Otevre dialogove okno, pres applet (swing) */ function vyberSoubor() { try { var filename = _getAppletObject().applet_showFileOpenDialog(null, null, 'Vyberte soubor'); var filenameInput = document.getElementById("id_filename"); filenameInput.value = filename; } catch(e) { if (getLastError().indexOf("INFO") != 0) window.alert("Exception function vyberSoubor: " + getLastError()); } } /** * Podepisu soubor, z HTML stranky si vezmu jmeno souboru a cas a podpis ulozem do jineho text pole jako base64 */ function podepsatSoubor() { // podepsani souboru try { var filename = document.getElementById("id_filename").value; var podpis = document.getElementById("id_signedText_filename"); podpis.value = ""; var timestamp = document.getElementById("id_timestamp"); // timestamp.value = new Date().getTime(); //put timestamp // provedu podepsani appletem podpis.value = _getAppletObject().applet_signFile(filename, timestamp.value); if (podpis.value != "") { // alert("Soubor " + filename + " byl podepsan."); } } catch(e) { if (getLastError().indexOf("INFO") != 0) window.alert("Exception function podepsatSoubor: " + getLastError()); } } /** * Podepisu url, z HTML stranky si vezmu url a cas a podpis ulozem do jineho text pole jako base64 */ function podepsatUrl() { // podepsani souboru try { var filename = document.getElementById("id_url").value; var podpis = document.getElementById("id_signedText_url"); podpis.value = ""; var timestamp = document.getElementById("id_timestamp"); //timestamp.value = new Date().getTime(); //put timestamp // provedu podepsani appletem podpis.value = _getAppletObject().applet_signUrl(filename, timestamp.value); if (podpis.value != "") { // alert("Soubor " + filename + " byl podepsan."); } } catch(e) { if (getLastError().indexOf("INFO") != 0) window.alert("Exception function podepsatUrl: " + getLastError()); } } /** * Funkce vrati cas podepsani ve formatu long 1.1.1970 je nula */ function getSignTime(base64_sign) { try { return timestamp = _getAppletObject().applet_getSignTime(base64_sign); } catch(e) { if (getLastError().indexOf("INFO") != 0) window.alert("Exception function getSignTime: " + getLastError()); } } /** * Funkce vrati cas podepsani ve formatu dle zadani, priklad "dd.MM.yyyy HH:mm:ss SSS" */ function getSignTime_format(base64_sign, format) { try { return timestamp = _getAppletObject().applet_getSignTime_format(base64_sign, format); } catch(e) { if (getLastError().indexOf("INFO") != 0) window.alert("Exception function getSignTime: " + getLastError()); } } /** * Funkce vrati metadata certifikatu */ function getCertificateStructure(base64_sign) { try { return certificateStructure = _getAppletObject().applet_getCertificateStructure(base64_sign); } catch(e) { if (getLastError().indexOf("INFO") != 0) window.alert("Exception function getCertificateStructure: " + getLastError()); } } /** * Funkce vrati metadata o vydavateli certifikatu */ function getIssuerCertificateStructure(base64_sign) { try { return certificateStructure = _getAppletObject().applet_getIssuerCertificateStructure(base64_sign); } catch(e) { if (getLastError().indexOf("INFO") != 0) window.alert("Exception function getIssuerCertificateStructure: " + getLastError()); } } /** * Funkce vrati metadata platnost od do z certifikatu */ function getCertificateDateFromTo(base64_sign) { try { return certificateStructure = _getAppletObject().applet_getCertificateDateFromTo(base64_sign); } catch(e) { if (getLastError().indexOf("INFO") != 0) window.alert("Exception function getCertificateDateFromTo: " + getLastError()); } }