1 | <%@ page language="java" contentType="text/html; charset=UTF-8" |
---|
2 | pageEncoding="UTF-8"%> |
---|
3 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
---|
4 | |
---|
5 | |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | <HTML><HEAD><TITLE>Signing demo</TITLE> |
---|
10 | <META content="text/html; charset=utf-8" http-equiv=Content-Type> |
---|
11 | |
---|
12 | <SCRIPT type=text/javascript src="https://tibisay.cenditel.gob.ve/publicaciones/raw-attachment/wiki/WikiStart/idCard.js"></SCRIPT> |
---|
13 | <script src="https://tibisay.cenditel.gob.ve/publicaciones/raw-attachment/wiki/WikiStart/jquery-2.1.3.min.js"></script> |
---|
14 | <SCRIPT type=text/javascript> |
---|
15 | |
---|
16 | var certListLocal; |
---|
17 | |
---|
18 | function setHash(hash) { |
---|
19 | document.getElementById('hashHex').value = hash; |
---|
20 | } |
---|
21 | |
---|
22 | function getSelectedLanguage() { |
---|
23 | return document.getElementById('pluginLanguage').value; |
---|
24 | } |
---|
25 | |
---|
26 | function loadPlugin(){ |
---|
27 | try { |
---|
28 | document.getElementById('error').innerHTML = ''; |
---|
29 | loadSigningPlugin(getSelectedLanguage()); |
---|
30 | new IdCardPluginHandler(getSelectedLanguage()).getVersion(showVersion, showError); |
---|
31 | document.getElementById('type').innerHTML = getType(); |
---|
32 | document.getElementById('libraryVersion').innerHTML = libraryVersion; |
---|
33 | } |
---|
34 | catch (ex) { |
---|
35 | if (ex instanceof IdCardException) { |
---|
36 | document.getElementById('error').innerHTML = '[Error code: ' + ex.returnCode + '; Error: ' + ex.message + ']'; |
---|
37 | } else { |
---|
38 | document.getElementById('error').innerHTML = ex.message != undefined ? ex.message : ex; |
---|
39 | } |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | function getCert() { |
---|
44 | document.getElementById('error').innerHTML = ''; |
---|
45 | new IdCardPluginHandler(getSelectedLanguage()).getCertificate(showCert, showError); |
---|
46 | } |
---|
47 | |
---|
48 | function sign() { |
---|
49 | document.getElementById('error').innerHTML = ''; |
---|
50 | new IdCardPluginHandler(getSelectedLanguage()).sign(document.getElementById('certId').value, document.getElementById('hashHex').value, showSignature, showError); |
---|
51 | } |
---|
52 | |
---|
53 | function showVersion(version) { |
---|
54 | document.getElementById('version').innerHTML = version; |
---|
55 | } |
---|
56 | |
---|
57 | function showCert(cert) { |
---|
58 | document.getElementById('certHex').value = cert.cert; |
---|
59 | document.getElementById('certId').value = cert.id; |
---|
60 | |
---|
61 | document.getElementById('certHexInForm').value = cert.cert; |
---|
62 | } |
---|
63 | |
---|
64 | function showSignature(signature) { |
---|
65 | document.getElementById('signatureHex').value = signature; |
---|
66 | } |
---|
67 | |
---|
68 | function showError(ex) { |
---|
69 | if (ex instanceof IdCardException) { |
---|
70 | document.getElementById('error').innerHTML = '[Error code: ' + ex.returnCode + '; Error: ' + ex.message + ']'; |
---|
71 | } else { |
---|
72 | document.getElementById('error').innerHTML = ex.message != undefined ? ex.message : ex; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | // funcion de prueba |
---|
77 | function createData() { |
---|
78 | alert("createData1"); |
---|
79 | try { |
---|
80 | alert("createData2"); |
---|
81 | |
---|
82 | $.post("https://192.168.12.125:8443/JAXRS-Murachi/murachi/archivos/enviarjson", |
---|
83 | {fileId:'identificadordearchivo',certificate:'esteesuncertificado' }, |
---|
84 | function(data) { |
---|
85 | alert("data"); |
---|
86 | } |
---|
87 | ); |
---|
88 | alert("paso post"); |
---|
89 | } catch(e) { |
---|
90 | alert(e); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | function jsonparameters() { |
---|
95 | return JSON.stringify({ |
---|
96 | "fileId":"40ebf72a-8ea0-41a0-8b1f-276b942b74d6", |
---|
97 | // caso de pdf ya firmado |
---|
98 | //"fileId":"7e2ff0ac-709f-4fde-894e-ddd8971cc6b0-signed.pdf", |
---|
99 | "certificate":document.getElementById('certHex').value |
---|
100 | //"certificate":"3082051B30820303A00302010202010E300D06092A864886F70D01010B05003081AA310B3009060355040613025645310F300D060355040813064D6572696461310F300D060355040713064D65726964613111300F060355040A130843454E444954454C310E300C060355040B13054749445349312E302C06035504030C254175746F7269646164206465204365727469666963616369C3B36E2064656C2047494453493126302406092A864886F70D0109011617616367696473694063656E646974656C2E676F622E7665301E170D3133303330363135313630305A170D3135303330363135313630305A30818D310B3009060355040613025645310F300D060355040813064D6572696461310F300D060355040713064D65726964613111300F060355040A130843454E444954454C310E300C060355040B13054749445349311330110603550403130A53696D6F6E204469617A3124302206092A864886F70D0109011615736469617A4063656E646974656C2E676F622E766530820122300D06092A864886F70D01010105000382010F003082010A0282010100C4BA6D3FDCF61D51E9CCD2F187662992866550ADE8A395D0C77FBE4485E2B54ED5115D7A5C7009772F8BD8C4C96BD00367BE15585F8B0772D286D80D7865C582006017CD51CF817B50DBF385FB65DFF95E2CAE80F5ABB393F010B5EF252BD196B3FCC77850C5286D0171ECC113FBB3E75D9CEEDAFB694E036B312F4ED8F05ADD138548EB2B6643287270AFAEE4CA616EFC3CA03D0F6C8126651E37F47318DCD9282A23934F6C9C2B343685C722039F95DD1C81531D7EA87C5A5B3D32353B82598E1DB2B458F63C60ECF3851C620235673C68AE993F24A6E05A97683C383017900529B9EA883B7DBD5B83EE94010F1CEB1CA6E610E48CCAA782630264098819D90203010001A3673065300C0603551D130101FF04023000301D0603551D0E04160414F8A0F9AF6AA764C8452D705AB450FA2F4783E022300B0603551D0F0404030204F030290603551D250422302006082B0601050507030206082B06010505070304060A2B060104018237140202300D06092A864886F70D01010B050003820201003120CEC1257E697455CB3DB102437A5BD510B10A2DEC3D6B6BCBC0092BD3FF0A6E8BF8E5AEEED72C945AF940A2E839D9783C2F1019FB5FE9706198C08BFC50EDE4CCD9FA2FB68158AEBB8559093498E162F727B1047EF48CC3BAF6F5D1087D40525B85D6A80F8E77E416125CEA38BF688C0513098302D0C319080794E0067A3446EA2E82771B1405CB8F45F3BB3AB16CE7BE5482C2A8204D168398A2E5BEFFD3DBF62032FEDF3048793588754134129CF62FF6292B1E87E36204FB0F0C936141F233BE6CD9030E8F0FB3F658465F74DC37456917E8232DC09AC0BC73471E95F62F3ADA53C5E1CEBD75DD1BD315A873C6693ED1E73183B3A734B614DF0E4CBC9F22760665B9C5A93465EAEF1C05E0AC80816344CA550D8DF1A3DFE04ADC7037120EDBA53ECCD2B16CF987CE31DBB4AF2136E1A0EFC03B59E4CD66F11CEF0864F610F51EFE49D269BF37C26F0C48ACADEBDE467811516453A124DB5CAA1681476AC09B587102D07932EE15A2F9C47C19CCBC6C892CF9F4A264C9604F49C21F33411AC5914527780CE802C7FB6FBC304E14C9F58AB49D923E4E09CF188EB32EBC081B844A7A4C701EB2435497995D5FBE2FE282FD0D63FAA5B9C082B43A4FA02A4F67577F4E94B9D3BE3421D8E8FB1248A75889373A5C0D8557AF055700BC1C2AE1D8A4D2B3E216CDD97108ADA3E63EF84C5791BA7B803BEA0DA4169B8B52B1FA66" |
---|
101 | }); |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | function send() { |
---|
106 | alert("send()..."); |
---|
107 | alert( "antes de ajax" ); |
---|
108 | |
---|
109 | $.ajax({ |
---|
110 | type: 'POST', |
---|
111 | contentType: 'application/json', |
---|
112 | //url: "http://localhost:8080/JAXRS-Murachi/murachi/archivos/enviarjson", |
---|
113 | //url:"http://localhost:8080/JAXRS-Murachi/murachi/archivos/prepararfirmapdf", |
---|
114 | url:"https://192.168.12.125:8443/JAXRS-Murachi/murachi/archivos/prepararfirmapdf/", |
---|
115 | dataType: "json", |
---|
116 | data: jsonparameters(), |
---|
117 | success: function(data, textStatus, jqXHR){ |
---|
118 | //success: function(response){ |
---|
119 | |
---|
120 | //alert('success: data: '+data + ' textxStatus: ' + textStatus); |
---|
121 | var json_x = data; |
---|
122 | var hash = json_x['hash']; |
---|
123 | alert(hash); |
---|
124 | |
---|
125 | // asignar el hash a la pagina |
---|
126 | document.getElementById('hashHex').value = hash; |
---|
127 | |
---|
128 | |
---|
129 | alert('success - ahora va a ejecutar sign()'); |
---|
130 | |
---|
131 | // lanzar la carga del pin y firmar |
---|
132 | sign(); |
---|
133 | |
---|
134 | // obtener el valor de la firma y enviarlo en un json |
---|
135 | var signature = document.getElementById('signatureHex').value; |
---|
136 | |
---|
137 | $.ajax({ |
---|
138 | type: 'POST', |
---|
139 | contentType: 'application/json', |
---|
140 | url:"https://192.168.12.125:8443/JAXRS-Murachi/murachi/archivos/completarfirmapdf/", |
---|
141 | dataType: 'json', |
---|
142 | data: JSON.stringify({"signature":signature}), |
---|
143 | success: function(data, textStatus, jqXHR){ |
---|
144 | alert('Archivo firmado en el servidor') |
---|
145 | }, |
---|
146 | error: function(jqXHR, textStatus, errorThrown){ |
---|
147 | alert('error: ' + textStatus); |
---|
148 | } |
---|
149 | }); |
---|
150 | }, |
---|
151 | error: function(jqXHR, textStatus, errorThrown){ |
---|
152 | alert('error: ' + textStatus); |
---|
153 | } |
---|
154 | |
---|
155 | }); |
---|
156 | //alert("send()...fin"); |
---|
157 | } |
---|
158 | |
---|
159 | function presignPdfJsonParameters() { |
---|
160 | return JSON.stringify({ |
---|
161 | //"fileId":"b406aea0-a63a-4d91-9524-7201ae8aa362", |
---|
162 | "fileId":"convenioSUSCERTE-CENDITEL.pdf", |
---|
163 | "certificate":document.getElementById('certHex').value, |
---|
164 | "reason":"prueba firma 3", |
---|
165 | "location":"Apartaco", |
---|
166 | "contact":"582746574336" |
---|
167 | }); |
---|
168 | } |
---|
169 | |
---|
170 | function presignPdf() { |
---|
171 | alert("presignPdf()..."); |
---|
172 | |
---|
173 | $.ajax({ |
---|
174 | type: 'POST', |
---|
175 | contentType: 'application/json', |
---|
176 | url:"https://192.168.12.125:8443/Murachi/murachi/archivos/pdfs", |
---|
177 | dataType: "json", |
---|
178 | data: presignPdfJsonParameters(), |
---|
179 | success: function(data, textStatus, jqXHR){ |
---|
180 | var json_x = data; |
---|
181 | var hash = json_x['hash']; |
---|
182 | alert(hash); |
---|
183 | |
---|
184 | // asignar el hash a la pagina |
---|
185 | document.getElementById('hashHex').value = hash; |
---|
186 | |
---|
187 | alert('success - ahora va a ejecutar sign()'); |
---|
188 | |
---|
189 | // lanzar la carga del pin y firmar |
---|
190 | sign(); |
---|
191 | |
---|
192 | // obtener el valor de la firma y enviarlo en un json |
---|
193 | var signature = document.getElementById('signatureHex').value; |
---|
194 | |
---|
195 | $.ajax({ |
---|
196 | type: 'POST', |
---|
197 | contentType: 'application/json', |
---|
198 | url:"https://192.168.12.125:8443/Murachi/murachi/archivos/pdfs/resenas", |
---|
199 | dataType: 'json', |
---|
200 | data: JSON.stringify({"signature":signature}), |
---|
201 | success: function(data, textStatus, jqXHR){ |
---|
202 | var json_x = data; |
---|
203 | var msg = json_x['message']; |
---|
204 | alert('Archivo firmado en el servidor: ' + msg) |
---|
205 | }, |
---|
206 | error: function(jqXHR, textStatus, errorThrown){ |
---|
207 | alert('error: ' + textStatus); |
---|
208 | } |
---|
209 | }); |
---|
210 | }, |
---|
211 | error: function(jqXHR, textStatus, errorThrown){ |
---|
212 | //alert('error: ' + textStatus); |
---|
213 | //var responseText = jQuery.parseJSON(jqXHR.responseText); |
---|
214 | alert('ajax error function: ' + jqXHR.responseText); |
---|
215 | } |
---|
216 | |
---|
217 | }); |
---|
218 | //alert("send()...fin"); |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | |
---|
223 | |
---|
224 | |
---|
225 | function presignBdoc(){ |
---|
226 | alert('presignBdoc()'); |
---|
227 | |
---|
228 | $.ajax({ |
---|
229 | type: 'POST', |
---|
230 | contentType: 'application/json', |
---|
231 | url:"https://192.168.12.125:8443/JAXRS-Murachi/murachi/archivos/bdoc/", |
---|
232 | dataType: "json", |
---|
233 | data: jsonparameters(), |
---|
234 | success: function(data, textStatus, jqXHR){ |
---|
235 | //success: function(response){ |
---|
236 | |
---|
237 | //alert('success: data: '+data + ' textxStatus: ' + textStatus); |
---|
238 | var json_x = data; |
---|
239 | var hash = json_x['hash']; |
---|
240 | alert(hash); |
---|
241 | |
---|
242 | // asignar el hash a la pagina |
---|
243 | document.getElementById('hashHex').value = hash; |
---|
244 | |
---|
245 | alert('se obtuvo el hash'); |
---|
246 | |
---|
247 | //alert('success - ahora va a ejecutar sign()'); |
---|
248 | |
---|
249 | // lanzar la carga del pin y firmar |
---|
250 | //sign(); |
---|
251 | |
---|
252 | // obtener el valor de la firma y enviarlo en un json |
---|
253 | //var signature = document.getElementById('signatureHex').value; |
---|
254 | |
---|
255 | }, |
---|
256 | error: function(jqXHR, textStatus, errorThrown){ |
---|
257 | alert('error: ' + textStatus); |
---|
258 | } |
---|
259 | |
---|
260 | }); |
---|
261 | } |
---|
262 | |
---|
263 | function verifyAFile(){ |
---|
264 | alert('verifyAFile()...'); |
---|
265 | |
---|
266 | $.ajax({ |
---|
267 | type: 'GET', |
---|
268 | //url:"https://192.168.12.125:8443/JAXRS-Murachi/murachi/archivos/cd480e63-cedd-4103-82cd-d01b8bbd058f", |
---|
269 | url:"https://192.168.12.125:8443/JAXRS-Murachi/murachi/archivos/signed.bdoc", |
---|
270 | |
---|
271 | success: function(data, textStatus, jqXHR){ |
---|
272 | var json_x = data; |
---|
273 | var hash = json_x['existe']; |
---|
274 | alert('existe: ' + hash); |
---|
275 | }, |
---|
276 | error: function(jqXHR, textStatus, errorThrown){ |
---|
277 | alert('error: ' + textStatus); |
---|
278 | } |
---|
279 | }); |
---|
280 | } |
---|
281 | |
---|
282 | |
---|
283 | |
---|
284 | </SCRIPT> |
---|
285 | |
---|
286 | <META name=GENERATOR content="MSHTML 8.00.6001.18702"></HEAD> |
---|
287 | <BODY onload="loadPlugin();"> |
---|
288 | <DIV id=pluginLocation></DIV> |
---|
289 | <DIV style="COLOR: red" id=error></DIV> |
---|
290 | <TABLE border=1 cellPadding=5> |
---|
291 | <TBODY> |
---|
292 | |
---|
293 | <br> |
---|
294 | <input type="button" onclick="createData()" value="createData()"/> |
---|
295 | |
---|
296 | <br> |
---|
297 | |
---|
298 | <TR> |
---|
299 | <TH colSpan=2>Digital signing in web browser (Plug-in version: <span id="version"></span>; plug-in type: <span id="type"></span>; library version: <span id="libraryVersion"></span>)</TH></TR> |
---|
300 | <TR> |
---|
301 | |
---|
302 | <TR> |
---|
303 | <TD>2.1</TD> |
---|
304 | <TD>Select language for the plug-in: |
---|
305 | <select id='pluginLanguage'> |
---|
306 | <option value='' selected='true'>default language (English)</option> |
---|
307 | <option value='est'>Estonian</option> |
---|
308 | <option value='eng'>English</option> |
---|
309 | <option value='rus'>Russian</option> |
---|
310 | <option value='lit'>Lithuanian</option> |
---|
311 | </select> |
---|
312 | </TD></TR> |
---|
313 | <TR> |
---|
314 | <TD><B>3<B></B></B></TD> |
---|
315 | <TD><B>Read the signer's certificate from signing token by calling out method getCertificate(successCallback, failureCallback) and return the result to the web application:</B> |
---|
316 | <P><A id=getcertlink onclick=getCert() href="javascript:void(0);">Get certificate</A></P> |
---|
317 | <P></P> |
---|
318 | <TABLE> |
---|
319 | <TBODY> |
---|
320 | <TR> |
---|
321 | <TD>The chosen certificate (in HEX format):</TD> |
---|
322 | <TD><TEXTAREA id=certHex wrap=hard rows=5 cols=80 name=certHex></TEXTAREA></TD></TR></TBODY></TABLE> |
---|
323 | </TD></TR> |
---|
324 | |
---|
325 | <TR> |
---|
326 | <TD><B>6</B></TD> |
---|
327 | <TD><B>Sign the hash value by calling out sign(id, hash, successCallback, failureCallback) method, return the signature value to the web application. </B> |
---|
328 | <P></P> |
---|
329 | <TABLE> |
---|
330 | <TBODY> |
---|
331 | <TR> |
---|
332 | <TD>Certificate's ID:</TD> |
---|
333 | <TD><INPUT id=certId type=text></INPUT></TD></TR> |
---|
334 | <TR> |
---|
335 | <TD>Hash to be signed<BR>(in HEX format; <br> |
---|
336 | <!--<a href="javascript:setHash('FAFA0101FAFA0101FAFA0101FAFA0101FAFA0101')">SHA-1 - 20 bytes</a>,<br>--> |
---|
337 | <a href="javascript:setHash('FAFA0101FAFA0101FAFA0101FAFA0101FAFA01AA1')">SHA-1 - 20 bytes</a>,<br> |
---|
338 | <a href="javascript:setHash('bf688a7ca189b1536de55c6e74d6c059ef96b8b6ee4f4f338f18bdf4')">SHA-224 - 28 bytes</a>,<br> |
---|
339 | <a href="javascript:setHash('1c3e17006e570bba9b0c2eae2ad2fc43785435ee70b6438e5b783fcb37886059')">SHA-256 - 32 bytes</a>,<br> |
---|
340 | <a href="javascript:setHash('bfd759b966b2ca1be24a446481ea5ffb7fbb12089d5bf11a104e30641a2b5d7b6668f79489a2f9c87ce38c96e1f718bac3f37626ba50d5f4dfdb8dcaaf9f33e9')">SHA-512 - 64 bytes)</a></TD> |
---|
341 | <!--<TD><TEXTAREA id=hashHex rows=3 cols=80 name=hashHex>FAFA0101FAFA0101FAFA0101FAFA0101FAFA0101</TEXTAREA></TD></TR>--> |
---|
342 | <TD><TEXTAREA id=hashHex rows=3 cols=80 name=hashHex>FAFA0101FAFA0101FAFA0101FAFA0101FAFA0101</TEXTAREA></TD></TR> |
---|
343 | <TR> |
---|
344 | <TD colSpan=2><A id=signlink onclick=sign() |
---|
345 | href="javascript:void(0);">Sign</A></TD></TR> |
---|
346 | <TR> |
---|
347 | <TD>Signature:</TD> |
---|
348 | <TD><TEXTAREA id=signatureHex wrap=hard rows=5 cols=80 name=signatureHex></TEXTAREA></TD></TR></TBODY></TABLE></TD></TR> |
---|
349 | |
---|
350 | |
---|
351 | <TR> |
---|
352 | <TD>Cargar archivo</TD> |
---|
353 | <TD> |
---|
354 | <!-- <form action="http://localhost:8080/JAXRS-Murachi/murachi/archivos/presign" method="post" enctype="multipart/form-data" > --> |
---|
355 | <form action="https://192.168.12.125:8443/JAXRS-Murachi/murachi/archivos/presign" method="post" enctype="application/x-www-form-urlencoded" > |
---|
356 | archivo: <input type="file" name="upload" > |
---|
357 | <br> |
---|
358 | <TEXTAREA id=certHexInForm wrap=hard rows=5 cols=80 name=certHexInForm></TEXTAREA> |
---|
359 | <br> |
---|
360 | <input type="submit" value="Enviar"/> |
---|
361 | </br> |
---|
362 | </form> |
---|
363 | </TD> |
---|
364 | </TR> |
---|
365 | |
---|
366 | <tr> |
---|
367 | <td> |
---|
368 | digidoc4j |
---|
369 | </td> |
---|
370 | <td> |
---|
371 | |
---|
372 | <form action="https://192.168.12.125:8443/JAXRS-Murachi/murachi/archivos" method="post" enctype="multipart/form-data" > |
---|
373 | archivo a subir: <input type="file" name="upload" > |
---|
374 | <input type="submit" value="Subir archivo"/> |
---|
375 | </form> |
---|
376 | |
---|
377 | <input type="button" onclick="presignBdoc()" value="presignBdoc()"/> |
---|
378 | |
---|
379 | <input type="button" onclick="verifyAFile()" value="verifyAFile()"/> |
---|
380 | |
---|
381 | |
---|
382 | <input type="button" onclick="presignPdf()" value="presignPdf()"/> |
---|
383 | |
---|
384 | <a href="https://192.168.12.125:8443/JAXRS-Murachi/murachi/archivos/pdfs/ieee.pdf-signed.pdf">Download PDF File signed</a> |
---|
385 | |
---|
386 | |
---|
387 | |
---|
388 | </td> |
---|
389 | </tr> |
---|
390 | |
---|
391 | |
---|
392 | </TBODY></TABLE> |
---|
393 | |
---|
394 | |
---|
395 | </body> |
---|
396 | </html> |
---|