source: dispositivos_moviles/TibisayMovil/src/ve/gob/cenditel/tibisaymovil/BDOCUtils.java @ 42e7061

Last change on this file since 42e7061 was 8860b8f, checked in by Antonio Araujo Brett <aaraujo@…>, 11 years ago

*- Implementación inicial de traducción de errores en firmas electrónicas.
*- Corrección de error de duplicación de mensajes de error en detalles de firma.

  • Property mode set to 100644
File size: 7.1 KB
Line 
1package ve.gob.cenditel.tibisaymovil;
2
3import java.io.File;
4import java.io.FileInputStream;
5import java.io.FileNotFoundException;
6import java.io.FileOutputStream;
7import java.io.IOException;
8import java.io.InputStream;
9import java.io.OutputStream;
10import java.nio.channels.FileChannel;
11import java.util.ArrayList;
12import java.util.Collection;
13
14import ee.sk.digidoc.DigiDocException;
15
16import android.content.Context;
17import android.net.Uri;
18import android.os.Environment;
19import android.os.StatFs;
20import android.text.format.DateFormat;
21import android.util.Log;
22
23/**
24 * Clase para utilidades sobre contenedores BDOC
25 *
26 *
27 */
28
29public class BDOCUtils {
30       
31       
32        public BDOCUtils() {}
33       
34       
35        public static String translateErrors(ArrayList list) {
36               
37                String errorList = "";
38               
39                for (int i = 0; i < list.size(); i++) {
40                        if ( ((DigiDocException) list.get(i)).getCode() == 82) {
41                                errorList = errorList.concat("El certificado firmante expiró");
42                        }
43                }       
44                return errorList;
45        }
46       
47        // funcion para traducir el codigo de error al verificar una firma electronica
48        public static String translateError(int codeError) {
49               
50                String stringError = "";
51               
52                if ( codeError == 38)
53                        stringError = stringError.concat("Error interno: No se encontró el valor de la firma.");       
54                if ( codeError == 39)
55                        stringError = stringError.concat("El certificado del firmante no existe.");
56                if ( codeError == 53)
57                        stringError = stringError.concat("No se encontró el certificado del servidor OCSP.");
58                if ( codeError == 70)
59                        stringError = stringError.concat("Error interno: sólo se soporta un servidor OCSP. Servidor OCSP inválido.");
60                if ( codeError == 78)
61                        stringError = stringError.concat("Error interno: no hay elemento de referencia para uno de los archivos firmados.");
62                if ( codeError == 79)
63                        stringError = stringError.concat("Error interno: el valor de la reseña (hash) es incorrecto.");
64                if ( codeError == 80)
65                        stringError = stringError.concat("Error interno: no hay elemento de referencia para bloque SignedProperties de la firma.");
66                if ( codeError == 81)
67                        stringError = stringError.concat("El certificado del firmante es inválido o no existe.");
68                if ( codeError == 82)
69                        stringError = stringError.concat("El certificado del firmante expiró.");
70                if ( codeError == 83)
71                        stringError = stringError.concat("Error interno: el valor del OCSP está vacío");
72                if ( codeError == 90)
73                        stringError = stringError.concat("La firma no tiene confirmación OCSP.");
74                if ( codeError == 94)
75                        stringError = stringError.concat("El certificado firmante no ha sido firmado por una AC raíz conocida.");
76                if ( codeError == 129)
77                        stringError = stringError.concat("Se está usando un algoritmo de reseña (hash) considerado débil.");
78                if ( codeError ==162)
79                        stringError = stringError.concat("El certificado del firmante no posee el bit de no repudio."); 
80               
81                return stringError;
82        }
83       
84        public static String translateError(String e) {
85                String translatedError = null;
86               
87                if (e.contains("Missing signature value!")) {
88                        translatedError = "Error interno: El valor de la firma no se encontró en el archivo.";
89                }
90                if (e.contains("Signers cert missing!")) {
91                        translatedError = "El certificado del firmante no se encuentó.";
92                }
93                if (e.contains("Signers cert not trusted, missing CA cert!")) {
94                        translatedError = "El certificado del firmante no es confiable; No se encuentra el certificado de la AC que lo emitió.";
95                }
96                if (e.contains("Signers cert does not have non-repudiation bit set!")) {
97                        translatedError = "El certificado del firmante no posee el uso de clave no repudio o Sin-rechazo.";
98                }
99                if (e.contains("No notarys certificate!")) {
100                        translatedError = "No se encontró el certificado para el servidor OCSP.";
101                }
102                if (e.contains("Wrong notarys certificate:")) {
103                        translatedError = "El certificado del servidor OCSP es incorrecto.";
104                }
105                if (e.contains("Notary certificates digest doesn't match!")) {
106                        translatedError = "Error interno: La reseña o hash del certificado del servidor OCSP no coincide.";
107                }
108                if (e.contains("Error calculating notary certificate digest!")) {
109                        translatedError = "Error interno: la reseña o hash del certificado del servidor OCSP no es correcta.";
110                }
111                if (e.contains("does not match OcpsRef-s producedAt:")) {
112                        translatedError = "La hora de la notarización de la firma del servidor OCSP no es correcta";
113                }
114                if (e.contains("Currently supports only one OCSP. Invalid ocsp")) {
115                        translatedError = "Servidor OCSP inválido. Sólo está soportado un servidor OCSP.";
116                }
117                if (e.contains("No Reference element for DataFile:")) {
118                        translatedError = "Error interno: no hay elemento de referencia para uno de los archivos firmados.";
119                }
120                if (e.contains("Invalid or missing signers cert!")) {
121                        translatedError = "El certificado del firmante es inválido o no se encuentra en el archivo.";
122                }
123                if (e.contains("Invalid signature method!")) {
124                        translatedError = "Algoritmo de firma no soportado.";
125                }
126                if (e.contains("Signature method:")) {
127                        translatedError = "El algoritmo de firma no está disponible en la aplicación.";
128                }
129                if (e.contains("Invalid signature value! Signers cert and signature value don't match!")) {
130                        translatedError = "Error interno: el valor de la firma no es correcto. El certificado firmante y el valor de la firma no coinciden.";
131                }
132                if (e.contains("Signature asn.1 prefix:")) {
133                        translatedError = "Error interno: prefijo ASN.1 de la firma no es correcto.";
134                }
135                if (e.contains("Invalid signature value! Signature value decrypted len:")) {
136                        translatedError = "Error interno: valor de firma inválido. No existe prefijo de estructura ASN.1.";
137                }
138                if (e.contains("Invalid signature value!")) {
139                        translatedError = "Valor de firma inválido.";
140                }
141                if (e.contains("Missing Reference for file")) {
142                        translatedError = "Error interno: no existe una referencia al archivo";
143                }
144                if (e.contains("Signers certificate has expired!")) {
145                        translatedError = "El certificado del firmante expiró.";
146                }
147                if (e.contains("Failed to verify OCSP for:")) {
148                        translatedError = "No se pudo verificar el certificado del servidor OCSP.";
149                }
150                if (e.contains("OCSP value is empty!")) {
151                        translatedError = "Error interno: el valor del certificado del OCSP es vacío.";
152                }
153                if (e.contains("No OCSP ref for uri:")) {
154                        translatedError = "Error interno: no existe una referencia para el certificado del servidor OCSP.";
155                }
156                if (e.contains("Notarys digest doesn't match!")) {
157                        translatedError = "Error interno: la reseña o hash del certificado OCSP no coincide.";
158                }
159                if (e.contains("Signature has no OCSP confirmation!")) {
160                        translatedError = "La firma no tiene confirmación de un servidor OCSP.";
161                }
162                //if (e.contains("")) {
163                //      translatedError = "El certificado firmante no ha sido firmado por una AC raíz conocida.";
164                //}
165                if (e.contains("The current BDoc container uses weaker encryption method than officialy accepted in Estonia")) {
166                        translatedError = "El archivo firmado utiliza un algoritmo de reseña (hash) considerado débil.";
167                }
168                if (e.contains("81 -")) {
169                        translatedError = "Error interno: tipo de bloque desconocido.";
170                }
171               
172                else{
173                        //translatedError = e;
174                }
175               
176                       
177                return translatedError;
178        }
179       
180       
181}
182
183
184
Note: See TracBrowser for help on using the repository browser.