Changeset 2c5fcda in murachi
- Timestamp:
- Jun 15, 2015, 6:11:27 PM (9 years ago)
- Branches:
- master
- Children:
- 6bb4976
- Parents:
- 11d82e1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
murachi/src/main/java/ve/gob/cenditel/murachi/MurachiRESTWS.java
r11d82e1 r2c5fcda 178 178 * un json con el id del archivo en el servidor para futuras consultas 179 179 * de estado de firmas 180 * 180 181 * @param uploadedInputStream stream para obtener el archivo 181 182 * @param fileDetails datos del archivo 182 183 * @return 183 184 * @throws MurachiException 185 * 186 * @api {post} /Murachi/0.1/archivos/ Carga un archivo 187 * @apiName Archivos 188 * @apiGroup Archivos 189 * @apiVersion 0.1.0 190 * @apiDescription Carga un archivo a través de un formulario y retorna un json con el id del archivo en el servidor 191 * 192 * 193 * @apiExample Example usage: 194 * 195 * var formData = new FormData(); 196 * formData.append("upload", $("#file-sign")[0].files[0]); 197 * $.ajax({ 198 * url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos", 199 * type: "post", 200 * dataType: "json", 201 * data: formData, 202 * cache: false, 203 * contentType: false, 204 * processData: false, 205 * success: function(response) { 206 * //identificador del archivo en el servidor 207 * var fileId = response.fileId.toString(); 208 * alert("fileId: "+ fileId); 209 * }, 210 * error: function(response){ 211 * alert("error: " + response.error.toString()); 212 * } 213 * }); 214 * 215 * @apiErrorExample {json} Error-Response: 216 * HTTP/1.1 400 Bad Request 217 * { 218 * "error": "datos recibidos del formulario son nulos" 219 * } 220 * 221 * HTTP/1.1 500 222 * { 223 * "error": "IOException" 224 * } 225 * 226 * @apiSuccess {String} fileId Identificador único del archivo cargado en el servidor. 227 * 184 228 */ 185 229 @POST … … 196 240 System.out.println("uploadedInputStream == null"); 197 241 logger.error("uploadedInputStream != null. datos recibidos del formulario son nulos."); 198 throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos."); 242 //throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos."); 243 244 return Response.status(400).entity("{\"error\": \"datos recibidos del formulario son nulos\"}").type(MediaType.APPLICATION_JSON).build(); 199 245 } 200 246 … … 202 248 System.out.println("fileDetails == null"); 203 249 logger.error("fileDetails == null. datos recibidos del formulario son nulos."); 204 throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos."); 250 //throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos."); 251 return Response.status(400).entity("{\"error\": \"datos recibidos del formulario son nulos\"}").type(MediaType.APPLICATION_JSON).build(); 205 252 } 206 253 … … 215 262 logger.error("Ocurrio una excepcion: ", e); 216 263 e.printStackTrace(); 217 throw new MurachiException(e.getMessage()); 264 //throw new MurachiException(e.getMessage()); 265 return Response.status(500).entity("{\"error\":" + e.getMessage()).build(); 266 218 267 } 219 268 … … 245 294 * 246 295 * @apiErrorExample {json} Error-Response: 247 * HTTP/1.1 40 1 Not Authenticated296 * HTTP/1.1 404 Not Found 248 297 * { 249 298 * "fileExist": false … … 299 348 * en caso de que este firmado 300 349 * 301 * @param uploadedInputStream stream para obtener el archivo 350 * @param uploadedInputStream stream para obtener el archivo 302 351 * @param fileDetails datos del archivo 303 352 * @return 304 353 * @throws MurachiException 354 * 355 * @api {post} /Murachi/0.1/archivos/firmados Carga un archivo y verifica 356 * @apiName Firmados 357 * @apiGroup Archivos 358 * @apiVersion 0.1.0 359 * @apiDescription Carga un archivo a través de un formulario y retorna un json con la información de la firma. 360 * 361 * @apiSuccess {Boolean} fileExist El archivo se cargó exitosamente en el servidor. 362 * @apiSuccess {String} error Extension not supported. En caso de que el archivo sea diferente de PDF y BDOC. 363 * 364 * @apiSuccess {Number} numberOfSignatures Número de firmas existentes en el archivo. 365 * @apiSuccess {Object[]} signatures Lista de firmas. 366 * @apiSuccess {String} signatures.signatureType Tipo de firma de archivo PDF: approval 367 * @apiSuccess {String} signatures.signedOn Fecha en que se realiza la firma. 368 * @apiSuccess {Boolean} signatures.integrityCheck Chequea la integridad de la firma. 369 * @apiSuccess {String} signatures.timeStamp Estampilla de tiempo 370 * @apiSuccess {String} signatures.reason Razón de la firma. 371 * @apiSuccess {String} signatures.location Ubicación donde se realiza la firma. 372 * @apiSuccess {String} signatures.alternativeNameOfTheSigner Nombre alternativo del firmante. 373 * @apiSuccess {String} signatures.signerCertificateValidFrom Fecha de inicio de validez del certificado. 374 * @apiSuccess {Boolean} signatures.signerCertificateStillValid El certificado todavía está válido. 375 * @apiSuccess {Boolean} signatures.signerCertificateHasExpired El certificado expiró. 376 * @apiSuccess {Boolean} signatures.signatureCoversWholeDocument La firma abarca todo el documento PDF. 377 * @apiSuccess {String} signatures.filterSubtype Tipo de subfiltro: /adbe.pkcs7.sha1, /adbe.pkcs7.detached. 378 * @apiSuccess {String} signatures.signerCertificateSubject Sujeto firmante. 379 * @apiSuccess {Boolean} signatures.signerCertificateValidAtTimeOfSigning El certificado es válido en el momento de la firma. 380 * @apiSuccess {String} signatures.encryptionAlgorithm Algoritmo de cifrado. 381 * @apiSuccess {String} signatures.timeStampService Servicio de estampillado de tiempo. 382 * @apiSuccess {String} signatures.digestAlgorithm Algoritmo hash (reseña). 383 * @apiSuccess {Boolean} signatures.certificatesVerifiedAgainstTheKeyStore Certificado verificado contra el repositorio de certificados confiables. 384 * @apiSuccess {Number} signatures.documentRevision Número de revisión del documento PDF. 385 * @apiSuccess {String} signatures.nameOfTheSigner Nombre del firmante. 386 * @apiSuccess {Number} signatures.totalDocumentRevisions Número total de revisiones del documento PDF. 387 * @apiSuccess {String} signatures.contactInfo Información de contacto del firmante. 388 * @apiSuccess {Boolean} signatures.timeStampVerified Estampilla de tiempo verificada. 389 * @apiSuccess {String} signatures.signerCertificateIssuer Emisor del certificado firmante. 390 * @apiSuccess {String} signatures.signerCertificateValidTo Fecha de fin de validez del certificado. 391 * 392 * @apiExample Example usage: 393 * 394 * var formData = new FormData(); 395 * formData.append("upload", $("#file-sign")[0].files[0]); 396 * $.ajax({ 397 * url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/firmados", 398 * type: "post", 399 * dataType: "json", 400 * data: formData, 401 * cache: false, 402 * contentType: false, 403 * processData: false, 404 * success: function(response) { 405 * var json = JSON.stringify(response); 406 * alert(json); 407 * }, 408 * error: function(response){ 409 * alert("error: " + response.error.toString()); 410 * } 411 * }); 412 * 413 * 414 * 415 * @apiErrorExample {json} Error-Response: 416 * HTTP/1.1 400 Bad Request 417 * { 418 * "error": "datos recibidos del formulario son nulos" 419 * } 420 * 421 * 422 * HTTP/1.1 500 423 * { 424 * "error": "IOException" 425 * } 426 * 305 427 */ 306 428 @POST … … 317 439 System.out.println("uploadedInputStream == null"); 318 440 logger.error("uploadedInputStream != null. datos recibidos del formulario son nulos."); 319 throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos."); 441 //throw new MurachiException("uploadedInputStream != null. datos recibidos del formulario son nulos."); 442 return Response.status(400).entity("{\"error\": \"datos recibidos del formulario son nulos\"}").type(MediaType.APPLICATION_JSON).build(); 320 443 } 321 444 … … 323 446 System.out.println("fileDetails == null"); 324 447 logger.error("fileDetails == null. datos recibidos del formulario son nulos."); 325 throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos."); 448 //throw new MurachiException("fileDetails == null. datos recibidos del formulario son nulos."); 449 return Response.status(400).entity("{\"error\": \"datos recibidos del formulario son nulos\"}").type(MediaType.APPLICATION_JSON).build(); 450 326 451 } 327 452 … … 336 461 logger.error("Ocurrio una excepcion: ", e); 337 462 e.printStackTrace(); 338 throw new MurachiException(e.getMessage()); 463 //throw new MurachiException(e.getMessage()); 464 return Response.status(500).entity("{\"error\":" + e.getMessage()).build(); 339 465 } 340 466 … … 834 960 * @throws MurachiException 835 961 * 962 * @api {post} /Murachi/0.1/archivos/firmados/pdfs Prepara la firma del documento PDF. 963 * @apiName Pdfs 964 * @apiGroup PDFS 965 * @apiVersion 0.1.0 966 * @apiDescription Prepara la firma de un documento PDF. Se debe pasar un JSON con la siguiente estructura: 967 * {"fileId":"file_id", 968 * "certificate":"hex_cert_value", 969 * "reason":"reason", 970 * "location":"location", 971 * "contact":"contact" 972 * } 973 * 974 * @apiSuccess {String} hash Reseña o hash del archivo que se debe cifrar con la clave privada protegida por el 975 * dispositivo criptográfico. 976 * 977 * @apiExample Example usage: 978 * 979 * var parameters = JSON.stringify({ 980 * "fileId":fileId, 981 * "certificate":cert.hex, 982 * "reason":"prueba firma web", 983 * "location":"Oficina", 984 * "contact":"582746574336" 985 * }); 986 * 987 * $.ajax({ 988 * url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs", 989 * type: "post", 990 * dataType: "json", 991 * data: parameters, 992 * contentType: "application/json", 993 * success: function(data, textStatus, jqXHR){ 994 * var json_x = data; 995 * var hash = json_x['hash']; 996 * alert("hash recibido del servidor "+hash); 997 * }, 998 * error: function(jqXHR, textStatus, errorThrown){ 999 * //alert('error: ' + textStatus); 1000 * //var responseText = jQuery.parseJSON(jqXHR.responseText); 1001 * alert('ajax error function: ' + jqXHR.responseText); 1002 * 1003 * } 1004 * }); 1005 * 1006 * 1007 * 1008 * @apiErrorExample {json} Error-Response: 1009 * HTTP/1.1 400 Bad Request 1010 * { 1011 * "hash": "", 1012 * "error": "El archivo que desea firmar no es un PDF." 1013 * } 1014 * 1015 * HTTP/1.1 500 Internal Server Error 1016 * { 1017 * "hash": "", 1018 * "error": "error en carga de certificado de firmante" 1019 * } 1020 * 1021 * 836 1022 */ 837 1023 @POST … … 888 1074 System.out.println("error chain[0] == null"); 889 1075 logger.error("presignPdf: error en carga de certificado de firmante"); 890 throw new MurachiException("presignPdf: error en carga de certificado de firmante"); 1076 //throw new MurachiException("presignPdf: error en carga de certificado de firmante"); 1077 1078 presignHash.setError("error en carga de certificado de firmante"); 1079 presignHash.setHash(""); 1080 return Response.status(500).entity(presignHash).build(); 1081 891 1082 }else { 892 1083 … … 1003 1194 logger.error("presignPdf ocurrio una excepcion ", e1); 1004 1195 e1.printStackTrace(); 1005 throw new MurachiException(e1.getMessage()); 1196 //throw new MurachiException(e1.getMessage()); 1197 presignHash.setError(e1.getMessage()); 1198 presignHash.setHash(""); 1199 return Response.status(500).entity(presignHash).build(); 1200 1006 1201 } catch (InvalidPdfException e) { 1007 1202 logger.error("presignPdf ocurrio una excepcion ", e); 1008 1203 e.printStackTrace(); 1204 //presignHash.setError("No se pudo leer el archivo PDF en el servidor"); 1205 //throw new MurachiException(e.getMessage()); 1009 1206 presignHash.setError("No se pudo leer el archivo PDF en el servidor"); 1010 throw new MurachiException(e.getMessage()); 1207 presignHash.setHash(""); 1208 return Response.status(500).entity(presignHash).build(); 1209 1011 1210 } catch (IOException e) { 1012 1211 logger.error("presignPdf ocurrio una excepcion ", e); 1013 1212 e.printStackTrace(); 1014 throw new MurachiException(e.getMessage()); 1213 //throw new MurachiException(e.getMessage()); 1214 1215 presignHash.setError(e.getMessage()); 1216 presignHash.setHash(""); 1217 return Response.status(500).entity(presignHash).build(); 1218 1015 1219 } catch (DocumentException e) { 1016 1220 logger.error("presignPdf ocurrio una excepcion ", e); 1017 1221 e.printStackTrace(); 1018 throw new MurachiException(e.getMessage()); 1222 //throw new MurachiException(e.getMessage()); 1223 1224 presignHash.setError(e.getMessage()); 1225 presignHash.setHash(""); 1226 return Response.status(500).entity(presignHash).build(); 1227 1019 1228 } catch (InvalidKeyException e) { 1020 1229 logger.error("presignPdf ocurrio una excepcion ", e); 1021 1230 e.printStackTrace(); 1022 throw new MurachiException(e.getMessage()); 1231 //throw new MurachiException(e.getMessage()); 1232 1233 presignHash.setError(e.getMessage()); 1234 presignHash.setHash(""); 1235 return Response.status(500).entity(presignHash).build(); 1236 1023 1237 } catch (NoSuchProviderException e) { 1024 1238 logger.error("presignPdf ocurrio una excepcion ", e); 1025 1239 e.printStackTrace(); 1026 throw new MurachiException(e.getMessage()); 1240 //throw new MurachiException(e.getMessage()); 1241 1242 presignHash.setError(e.getMessage()); 1243 presignHash.setHash(""); 1244 return Response.status(500).entity(presignHash).build(); 1245 1027 1246 } catch (NoSuchAlgorithmException e) { 1028 1247 logger.error("presignPdf ocurrio una excepcion ", e); 1029 1248 e.printStackTrace(); 1030 throw new MurachiException(e.getMessage()); 1249 //throw new MurachiException(e.getMessage()); 1250 1251 presignHash.setError(e.getMessage()); 1252 presignHash.setHash(""); 1253 return Response.status(500).entity(presignHash).build(); 1254 1031 1255 } catch (GeneralSecurityException e) { 1032 1256 logger.error("presignPdf ocurrio una excepcion ", e); 1033 1257 e.printStackTrace(); 1034 throw new MurachiException(e.getMessage()); 1258 //throw new MurachiException(e.getMessage()); 1259 1260 presignHash.setError(e.getMessage()); 1261 presignHash.setHash(""); 1262 return Response.status(500).entity(presignHash).build(); 1263 1035 1264 } 1036 1265 … … 1085 1314 * @throws IOException 1086 1315 * @throws MurachiException 1316 * 1317 * 1318 * @api {post} /Murachi/0.1/archivos/firmados/pdfs/resenas Completa la firma del documento PDF. 1319 * @apiName PdfsResenas 1320 * @apiGroup PDFS 1321 * @apiVersion 0.1.0 1322 * @apiDescription Completa la firma del documento PDF. Recibe el hash cifrado del cliente y termina de completar la firma del 1323 * archivo PDF. 1324 * 1325 * @apiSuccess {String} signedFileId Identificador único del archivo firmado en el servidor. 1326 * 1327 * @apiExample Example usage: 1328 * 1329 * $.ajax({ 1330 * url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs/resenas", 1331 * type: "post", 1332 * dataType: "json", 1333 * data: JSON.stringify({"signature":signature.hex}), 1334 * contentType: "application/json", 1335 * success: function(data, textStatus, jqXHR){ 1336 * alert('Archivo firmado correctamente: ' + data['signedFileId']); 1337 * }, 1338 * error: function(jqXHR, textStatus, errorThrown){ 1339 * alert('error en pdfs/resenas: ' + textStatus); 1340 * } 1341 * }); 1342 * 1343 * 1344 * 1345 * @apiErrorExample {json} Error-Response: 1346 * HTTP/1.1 500 Internal Server Error 1347 * { 1348 * "error": "El archivo que desea firmar no es un PDF." 1349 * } 1350 * 1087 1351 */ 1088 1352 @POST … … 1115 1379 ByteArrayOutputStream os = (ByteArrayOutputStream) session.getAttribute("baos"); 1116 1380 1381 JSONObject jsonError = new JSONObject(); 1382 1117 1383 if (sgn == null) { 1118 1384 System.out.println("sgn == null"); 1119 1385 logger.error("Error en completacion de firma: estructura PdfPKCS7 nula"); 1120 throw new MurachiException("Error en completacion de firma: estructura PdfPKCS7 nula"); 1386 //throw new MurachiException("Error en completacion de firma: estructura PdfPKCS7 nula"); 1387 1388 jsonError.put("error", "estructura PdfPKCS7 nula"); 1389 return Response.status(500).entity(jsonError).build(); 1121 1390 } 1122 1391 if (hash == null) { 1123 1392 System.out.println("hash == null"); 1124 1393 logger.error("Error en completacion de firma: hash nulo"); 1125 throw new MurachiException("Error en completacion de firma: hash nulo"); 1394 //throw new MurachiException("Error en completacion de firma: hash nulo"); 1395 jsonError.put("error", "hash nulo"); 1396 return Response.status(500).entity(jsonError).build(); 1126 1397 } 1127 1398 if (cal == null) { 1128 1399 System.out.println("cal == null"); 1129 1400 logger.error("Error en completacion de firma: estructura de fecha nula"); 1130 throw new MurachiException("Error en completacion de firma: estructura de fecha nula"); 1401 //throw new MurachiException("Error en completacion de firma: estructura de fecha nula"); 1402 1403 jsonError.put("error", "estructura de fecha nula"); 1404 return Response.status(500).entity(jsonError).build(); 1131 1405 } 1132 1406 if (sap == null) { 1133 1407 System.out.println("sap == null"); 1134 1408 logger.error("Error en completacion de firma: estructura de apariencia de firma pdf nula"); 1135 throw new MurachiException("Error en completacion de firma: estructura de apariencia de firma pdf nula"); 1409 //throw new MurachiException("Error en completacion de firma: estructura de apariencia de firma pdf nula"); 1410 1411 jsonError.put("error", "estructura de apariencia de firma pdf nula"); 1412 return Response.status(500).entity(jsonError).build(); 1136 1413 } 1137 1414 if (os == null) { 1138 1415 System.out.println("os == null"); 1139 1416 logger.error("Error en completacion de firma: bytes de archivo nulos"); 1140 throw new MurachiException("Error en completacion de firma: bytes de archivo nulos"); 1417 //throw new MurachiException("Error en completacion de firma: bytes de archivo nulos"); 1418 1419 jsonError.put("error", "bytes de archivo nulos"); 1420 return Response.status(500).entity(jsonError).build(); 1141 1421 } 1142 1422 … … 1161 1441 System.out.println("throw new IOException"); 1162 1442 logger.error("postsignPdf: ocurrio una excepcion", e); 1163 throw new MurachiException(e.getMessage()); 1443 //throw new MurachiException(e.getMessage()); 1444 jsonError.put("error", e.getMessage()); 1445 return Response.status(500).entity(jsonError).build(); 1164 1446 1165 1447 } catch (IOException e) { … … 1167 1449 logger.error("postsignPdf: ocurrio una excepcion", e); 1168 1450 e.printStackTrace(); 1169 throw new MurachiException(e.getMessage()); 1451 //throw new MurachiException(e.getMessage()); 1452 1453 jsonError.put("error", e.getMessage()); 1454 return Response.status(500).entity(jsonError).build(); 1170 1455 1171 1456 }
Note: See TracChangeset
for help on using the changeset viewer.