1 | // Cuarto paso (Se envia la información del token para terminar la firma) |
---|
2 | function FinalizarFirmaMultiples(signature){ |
---|
3 | |
---|
4 | $.ajax({ |
---|
5 | type: 'POST', |
---|
6 | contentType: 'application/json', |
---|
7 | //url:"https://192.168.12.154:8443/Murachi/0.1/archivos/pdfs/resenas", |
---|
8 | url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs/resenas", |
---|
9 | dataType: 'json', |
---|
10 | data: JSON.stringify({"signature":signature}), |
---|
11 | xhrFields: {withCredentials: true}, |
---|
12 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
13 | success: function(data, textStatus, jqXHR){ |
---|
14 | |
---|
15 | //var linkToDownload = "<a href=\"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/descargas/" + data['signedFileId'] +"\"><h4>Descargar archivo firmado</h4></a>"; |
---|
16 | var linkToDownload = "<a href=\"https://192.168.12.154:8443/Murachi/0.1/archivos/descargas/" + data['signedFileId'] +"\"><h4>Descargar archivo firmado</h4></a>"; |
---|
17 | document.getElementById("log").innerHTML = ''; |
---|
18 | document.getElementById("respuesta").innerHTML = '<center><h2>Archivo firmado correctamente:</h2> <br>'+linkToDownload+'</center>'; |
---|
19 | |
---|
20 | InfoDocumentDataTablePDFMultiples(data['signedFileId']); |
---|
21 | |
---|
22 | }, |
---|
23 | error: function(jqXHR, textStatus, errorThrown){ |
---|
24 | alert('error en pdfs/resenas: ' + textStatus); |
---|
25 | $("#respuesta").html("error en pdfs/resenas: " + textStatus); |
---|
26 | } |
---|
27 | }); |
---|
28 | |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | //Tercer paso (Obtenemos el hash de pdf enviado por el servidor y luego procesa la información en el token) |
---|
33 | function ObtenerHashPDFServerMultiples(parameters,cert){ |
---|
34 | |
---|
35 | $.ajax({ |
---|
36 | type: 'POST', |
---|
37 | contentType: 'application/json', |
---|
38 | //url:"https://192.168.12.154:8443/Murachi/0.1/archivos/pdfs2", |
---|
39 | url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs", |
---|
40 | dataType: "json", |
---|
41 | data: parameters, |
---|
42 | xhrFields: {withCredentials: true}, |
---|
43 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
44 | success: function(data, textStatus, jqXHR){ |
---|
45 | var json_x = data; |
---|
46 | var hash = json_x['hash']; |
---|
47 | //alert("hash recibido del servidor "+hash); |
---|
48 | var hashtype = "SHA-256"; |
---|
49 | var lang = "eng"; |
---|
50 | |
---|
51 | //Procesa la información |
---|
52 | window.hwcrypto.sign(cert, {type: hashtype, hex: hash}, {lang: lang}).then( |
---|
53 | function(signature) { |
---|
54 | FinalizarFirmaMultiples(signature.hex); |
---|
55 | }, |
---|
56 | function(err) { |
---|
57 | var error; |
---|
58 | if(err == "Error: user_cancel") { |
---|
59 | error = "El usuario cancelo la operación"; |
---|
60 | } |
---|
61 | else if(err == "Error: no_certificates") { |
---|
62 | error = "No hay certificado disponible"; |
---|
63 | } |
---|
64 | else if(err == "Error: no_implementation") { |
---|
65 | error = "No hay soporte para el manejo del certificado"; |
---|
66 | } |
---|
67 | simple_modal(error); |
---|
68 | }); |
---|
69 | |
---|
70 | }, |
---|
71 | error: function(jqXHR, textStatus, errorThrown){ |
---|
72 | //alert('error: ' + textStatus); |
---|
73 | //var responseText = jQuery.parseJSON(jqXHR.responseText); |
---|
74 | alert('ajax error function: ' + jqXHR.responseText); |
---|
75 | $("#respuesta").html("error function: " + jqXHR.responseText); |
---|
76 | } |
---|
77 | |
---|
78 | }); |
---|
79 | |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | //Segundo paso (Seleccionamos el Certificado Firmante) |
---|
84 | function ObtenerCertificadoFirmanteMultiples(fileId){ |
---|
85 | |
---|
86 | // identificador del archivo en el servidor |
---|
87 | window.hwcrypto.getCertificate({lang: "en"}).then( |
---|
88 | function(response) { |
---|
89 | var cert = response; |
---|
90 | console.log(response); |
---|
91 | console.log("ssss"); |
---|
92 | var parameters = ""; |
---|
93 | parameters = JSON.stringify({ |
---|
94 | "fileId":fileId, |
---|
95 | "certificate":cert.hex, |
---|
96 | "reason":"Certificado", |
---|
97 | "location":"CENDITEL", |
---|
98 | "contact":"RedGealc", |
---|
99 | "signatureVisible":"false", |
---|
100 | "signaturePage": "", |
---|
101 | "xPos": "", |
---|
102 | "yPos": "" |
---|
103 | }); |
---|
104 | |
---|
105 | // ahora llamar al ajax de obtener la resena del pdf |
---|
106 | ObtenerHashPDFServerMultiples(parameters, cert); |
---|
107 | |
---|
108 | }, |
---|
109 | function(err) { |
---|
110 | var error; |
---|
111 | if(err == "Error: user_cancel") { |
---|
112 | error = "El usuario cancelo la operación"; |
---|
113 | } |
---|
114 | else if(err == "Error: no_certificates") { |
---|
115 | error = "No hay certificado disponible"; |
---|
116 | } |
---|
117 | else if(err == "Error: no_implementation") { |
---|
118 | error = "No hay soporte para el manejo del certificado"; |
---|
119 | } |
---|
120 | simple_modal(error); |
---|
121 | } |
---|
122 | |
---|
123 | ); |
---|
124 | } |
---|
125 | |
---|