1 | <!doctype html> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <meta charset="utf-8"> |
---|
5 | <title>hwcrypto.js</title> |
---|
6 | <script src="gitversion.js"></script> |
---|
7 | <script src="hwcrypto-legacy.js"></script> |
---|
8 | <script src="hwcrypto.js"></script> |
---|
9 | <script src="jquery.js"></script> |
---|
10 | <script src="hex2base.js"></script> |
---|
11 | <style type="text/css"> |
---|
12 | body {font-family: Georgia, serif;} |
---|
13 | </style> |
---|
14 | |
---|
15 | <script> |
---|
16 | var hashes = {}; |
---|
17 | hashes['SHA-1'] = 'c33df55b8aee82b5018130f61a9199f6a9d5d385'; |
---|
18 | hashes['SHA-224'] = '614eadb55ecd6c4938fe23a450edd51292519f7ffb51e91dc8aa5fbe'; |
---|
19 | hashes['SHA-256'] = '413140d54372f9baf481d4c54e2d5c7bcf28fd6087000280e07976121dd54af2'; |
---|
20 | hashes['SHA-384'] = '71839e04e1f8c6e3a6697e27e9a7b8aff24c95358ea7dc7f98476c1e4d88c67d65803d175209689af02aa3cbf69f2fd3'; |
---|
21 | hashes['SHA-512'] = 'c793dc32d969cd4982a1d6e630de5aa0ebcd37e3b8bd0095f383a839582b080b9fe2d00098844bd303b8736ca1000344c5128ea38584bbed2d77a3968c7cdd71'; |
---|
22 | hashes['SHA-192'] = 'ad41e82bcff23839dc0d9683d46fbae0be3dfcbbb1b49c70'; |
---|
23 | |
---|
24 | function log_text(s) { |
---|
25 | var d = document.createElement("div"); |
---|
26 | d.innerHTML = s; |
---|
27 | document.getElementById('log').appendChild(d); |
---|
28 | } |
---|
29 | |
---|
30 | function debug() { |
---|
31 | window.hwcrypto.debug().then(function(response) {log_text("Debug: " + response);}); |
---|
32 | } |
---|
33 | function sign() { |
---|
34 | // Clear log |
---|
35 | document.getElementById('log').innerHTML = ''; |
---|
36 | // Timestamp |
---|
37 | log_text("sign() clicked on " + new Date().toUTCString()); |
---|
38 | // Select hash |
---|
39 | var hashtype = $("input[name=hash]:checked").val(); |
---|
40 | // Set backend if asked |
---|
41 | var backend = $("input[name=backend]:checked").val() |
---|
42 | // get language |
---|
43 | var lang = $("input[name=lang]:checked").val(); |
---|
44 | if (!window.hwcrypto.use(backend)) { |
---|
45 | log_text("Selecting backend failed."); |
---|
46 | } |
---|
47 | |
---|
48 | var hash = $("#hashvalue").val(); |
---|
49 | log_text("Signing " + hashtype + ": " + hash); |
---|
50 | // debug |
---|
51 | window.hwcrypto.debug().then(function(response) { |
---|
52 | log_text("Debug: " + response); |
---|
53 | }, function(err) { |
---|
54 | log_text("debug() failed: " + err); |
---|
55 | return; |
---|
56 | }); |
---|
57 | // Sign |
---|
58 | window.hwcrypto.getCertificate({lang: lang}).then(function(response) { |
---|
59 | var cert = response; |
---|
60 | log_text("Using certificate:\n" + hexToPem(response.hex)); |
---|
61 | window.hwcrypto.sign(cert, {type: hashtype, hex: hash}, {lang: lang}).then(function(response) { |
---|
62 | log_text("Generated signature:\n" + response.hex.match(/.{1,64}/g).join("\n")); |
---|
63 | }, function(err) { |
---|
64 | log_text("sign() failed: " + err); |
---|
65 | }); |
---|
66 | }, function(err) { |
---|
67 | log_text("getCertificate() failed: " + err); |
---|
68 | }); |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | </script> |
---|
73 | </head> |
---|
74 | <body> |
---|
75 | <noscript><h1>Plase enable JavaScript!</h1></noscript> |
---|
76 | <script> |
---|
77 | $(document).ready(function() { |
---|
78 | $("#scripton").show(); |
---|
79 | $("input[type=radio][name=hash]").change(function() { |
---|
80 | $("#hashvalue").val(hashes[$("input[name=hash]:checked").val()]); |
---|
81 | }); |
---|
82 | $("#hashvalue").val(hashes[$("input[name=hash]:checked").val()]); |
---|
83 | }); |
---|
84 | </script> |
---|
85 | <div id="scripton" style="display: none"> |
---|
86 | <p>This is a |
---|
87 | <b><script>document.write(window.location.protocol.substring(0, window.location.protocol.length-1).toUpperCase());</script></b> test page for |
---|
88 | <a href="hwcrypto.js">hwcrypto.js</a> (<a href="https://github.com/open-eid/hwcrypto.js/wiki">more information</a>) |
---|
89 | implementing <a href="https://github.com/open-eid/hwcrypto.js/wiki/ModernAPI">API v0.1</a> |
---|
90 | </p> |
---|
91 | <p> |
---|
92 | Switch to: |
---|
93 | <a href="http://open-eid.github.io/hwcrypto.js/sign.html">HTTP</a> | <a href="https://open-eid.github.io/hwcrypto.js/sign.html">HTTPS</a> |
---|
94 | | <a href="okbrowser.html">browser with module</a> | <a href="nokbrowser.html">browser without module</a> | <a href="success.html">success</a> |
---|
95 | </p> |
---|
96 | <hr> |
---|
97 | |
---|
98 | <h1>sign()</h1> |
---|
99 | <p>You can get old NPAPI plugins from: <a href="https://installer.id.ee">installer.id.ee</a></p> |
---|
100 | <p><a href="https://chrome.google.com/webstore/detail/ckjefchnfjhjfedoccjbhjpbncimppeg">Install extension from chrome web store</a></p> |
---|
101 | |
---|
102 | Choose parameters: |
---|
103 | <ul> |
---|
104 | <li><b>HASH</b>: |
---|
105 | |
---|
106 | <input type="radio" name="hash" value="SHA-1">SHA-1 |
---|
107 | <input type="radio" name="hash" value="SHA-224">SHA-224 |
---|
108 | <input type="radio" name="hash" value="SHA-256" checked>SHA-256 |
---|
109 | <input type="radio" name="hash" value="SHA-384">SHA-384 |
---|
110 | <input type="radio" name="hash" value="SHA-512">SHA-512 |
---|
111 | <input type="radio" name="hash" value="SHA-192">"SHA-192" (erronoeus) |
---|
112 | <br/> |
---|
113 | <input id="hashvalue" type="text" size="200"> |
---|
114 | </li> |
---|
115 | |
---|
116 | <li><b>LANGUAGE</b>: |
---|
117 | <input type="radio" name="lang" value="en" checked>English |
---|
118 | <input type="radio" name="lang" value="et">eesti |
---|
119 | <input type="radio" name="lang" value="ru">русский |
---|
120 | <input type="radio" name="lang" value="sw">Swahili |
---|
121 | </li> |
---|
122 | <li><b>BACKEND</b>: |
---|
123 | <input type="radio" name="backend" value="auto" checked>autodetect |
---|
124 | <input type="radio" name="backend" value="npapi">legacy NPAPI |
---|
125 | <input type="radio" name="backend" value="chrome">chrome-token-signing |
---|
126 | </li> |
---|
127 | </ul> |
---|
128 | <p><button id="click1" onclick='sign();'>Click here to invoke <b>sign()</b></button></p> |
---|
129 | <p><button id="click2" onclick='debug();'>Brief debug()</button></p> |
---|
130 | |
---|
131 | |
---|
132 | <hr> |
---|
133 | <script>document.write("<pre>This is sign.html " + publishedGitVersion + " running on\n" + navigator.userAgent + "</pre>");</script> |
---|
134 | <div id="log" style="white-space: pre; font-family: monospace;"></div> |
---|
135 | </div> |
---|
136 | </body> |
---|
137 | </html> |
---|