[8379cd8] | 1 | /* |
---|
| 2 | Tibisay Movil |
---|
| 3 | |
---|
| 4 | Copyright (C) 2013 Antonio Araujo (aaraujo@cenditel.gob.ve), Jose Ruiz |
---|
| 5 | (jruiz@cenditel.gob.ve), Fundacion Centro Nacional de Desarrollo e |
---|
| 6 | Investigacion en Tecnologias Libres - CENDITEL. |
---|
| 7 | |
---|
| 8 | La Fundación CENDITEL concede permiso para usar, copiar, distribuir y/o |
---|
| 9 | modificar este programa, reconociendo el derecho que la humanidad posee al |
---|
| 10 | libre acceso al conocimiento, bajo los términos de la licencia de software |
---|
| 11 | GPL versión 2.0 de la Free Software Foundation. |
---|
| 12 | |
---|
| 13 | Este programa se distribuye con la esperanza de que sea util, pero SIN |
---|
| 14 | NINGUNA GARANTIA; tampoco las implicitas garantias de MERCANTILIDAD o |
---|
| 15 | ADECUACION A UN PROPOSITO PARTICULAR. |
---|
| 16 | |
---|
| 17 | Para mayor información sobre los términos de la licencia ver el archivo |
---|
| 18 | llamado "gpl-2.0.txt" en ingles. |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | |
---|
[88eadd6] | 22 | package ve.gob.cenditel.tibisaymovil; |
---|
| 23 | |
---|
| 24 | import java.io.File; |
---|
| 25 | import java.io.FileInputStream; |
---|
| 26 | import java.io.FileNotFoundException; |
---|
| 27 | import java.io.FileOutputStream; |
---|
| 28 | import java.io.IOException; |
---|
| 29 | import java.io.InputStream; |
---|
| 30 | import java.io.OutputStream; |
---|
| 31 | import java.nio.channels.FileChannel; |
---|
| 32 | import java.util.ArrayList; |
---|
| 33 | import java.util.Collection; |
---|
| 34 | |
---|
| 35 | import ee.sk.digidoc.DigiDocException; |
---|
| 36 | |
---|
| 37 | import android.content.Context; |
---|
| 38 | import android.net.Uri; |
---|
| 39 | import android.os.Environment; |
---|
| 40 | import android.os.StatFs; |
---|
| 41 | import android.text.format.DateFormat; |
---|
| 42 | import android.util.Log; |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | * Clase para utilidades sobre contenedores BDOC |
---|
| 46 | * |
---|
| 47 | * |
---|
| 48 | */ |
---|
| 49 | |
---|
| 50 | public class BDOCUtils { |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | public BDOCUtils() {} |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | public static String translateErrors(ArrayList list) { |
---|
| 57 | |
---|
| 58 | String errorList = ""; |
---|
| 59 | |
---|
| 60 | for (int i = 0; i < list.size(); i++) { |
---|
| 61 | if ( ((DigiDocException) list.get(i)).getCode() == 82) { |
---|
| 62 | errorList = errorList.concat("El certificado firmante expiró"); |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | return errorList; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | // funcion para traducir el codigo de error al verificar una firma electronica |
---|
| 69 | public static String translateError(int codeError) { |
---|
| 70 | |
---|
| 71 | String stringError = ""; |
---|
| 72 | |
---|
| 73 | if ( codeError == 38) |
---|
| 74 | stringError = stringError.concat("Error interno: No se encontró el valor de la firma."); |
---|
| 75 | if ( codeError == 39) |
---|
| 76 | stringError = stringError.concat("El certificado del firmante no existe."); |
---|
| 77 | if ( codeError == 53) |
---|
| 78 | stringError = stringError.concat("No se encontró el certificado del servidor OCSP."); |
---|
| 79 | if ( codeError == 70) |
---|
| 80 | stringError = stringError.concat("Error interno: sólo se soporta un servidor OCSP. Servidor OCSP inválido."); |
---|
| 81 | if ( codeError == 78) |
---|
| 82 | stringError = stringError.concat("Error interno: no hay elemento de referencia para uno de los archivos firmados."); |
---|
| 83 | if ( codeError == 79) |
---|
| 84 | stringError = stringError.concat("Error interno: el valor de la reseña (hash) es incorrecto."); |
---|
| 85 | if ( codeError == 80) |
---|
| 86 | stringError = stringError.concat("Error interno: no hay elemento de referencia para bloque SignedProperties de la firma."); |
---|
| 87 | if ( codeError == 81) |
---|
| 88 | stringError = stringError.concat("El certificado del firmante es inválido o no existe."); |
---|
| 89 | if ( codeError == 82) |
---|
| 90 | stringError = stringError.concat("El certificado del firmante expiró."); |
---|
| 91 | if ( codeError == 83) |
---|
| 92 | stringError = stringError.concat("Error interno: el valor del OCSP está vacío"); |
---|
| 93 | if ( codeError == 90) |
---|
| 94 | stringError = stringError.concat("La firma no tiene confirmación OCSP."); |
---|
| 95 | if ( codeError == 94) |
---|
| 96 | stringError = stringError.concat("El certificado firmante no ha sido firmado por una AC raíz conocida."); |
---|
| 97 | if ( codeError == 129) |
---|
| 98 | stringError = stringError.concat("Se está usando un algoritmo de reseña (hash) considerado débil."); |
---|
| 99 | if ( codeError ==162) |
---|
| 100 | stringError = stringError.concat("El certificado del firmante no posee el bit de no repudio."); |
---|
| 101 | |
---|
| 102 | return stringError; |
---|
| 103 | } |
---|
| 104 | |
---|
[8860b8f] | 105 | public static String translateError(String e) { |
---|
| 106 | String translatedError = null; |
---|
| 107 | |
---|
| 108 | if (e.contains("Missing signature value!")) { |
---|
| 109 | translatedError = "Error interno: El valor de la firma no se encontró en el archivo."; |
---|
| 110 | } |
---|
| 111 | if (e.contains("Signers cert missing!")) { |
---|
| 112 | translatedError = "El certificado del firmante no se encuentó."; |
---|
| 113 | } |
---|
| 114 | if (e.contains("Signers cert not trusted, missing CA cert!")) { |
---|
| 115 | translatedError = "El certificado del firmante no es confiable; No se encuentra el certificado de la AC que lo emitió."; |
---|
| 116 | } |
---|
| 117 | if (e.contains("Signers cert does not have non-repudiation bit set!")) { |
---|
| 118 | translatedError = "El certificado del firmante no posee el uso de clave no repudio o Sin-rechazo."; |
---|
| 119 | } |
---|
| 120 | if (e.contains("No notarys certificate!")) { |
---|
| 121 | translatedError = "No se encontró el certificado para el servidor OCSP."; |
---|
| 122 | } |
---|
| 123 | if (e.contains("Wrong notarys certificate:")) { |
---|
| 124 | translatedError = "El certificado del servidor OCSP es incorrecto."; |
---|
| 125 | } |
---|
| 126 | if (e.contains("Notary certificates digest doesn't match!")) { |
---|
| 127 | translatedError = "Error interno: La reseña o hash del certificado del servidor OCSP no coincide."; |
---|
| 128 | } |
---|
| 129 | if (e.contains("Error calculating notary certificate digest!")) { |
---|
| 130 | translatedError = "Error interno: la reseña o hash del certificado del servidor OCSP no es correcta."; |
---|
| 131 | } |
---|
| 132 | if (e.contains("does not match OcpsRef-s producedAt:")) { |
---|
| 133 | translatedError = "La hora de la notarización de la firma del servidor OCSP no es correcta"; |
---|
| 134 | } |
---|
| 135 | if (e.contains("Currently supports only one OCSP. Invalid ocsp")) { |
---|
| 136 | translatedError = "Servidor OCSP inválido. Sólo está soportado un servidor OCSP."; |
---|
| 137 | } |
---|
| 138 | if (e.contains("No Reference element for DataFile:")) { |
---|
| 139 | translatedError = "Error interno: no hay elemento de referencia para uno de los archivos firmados."; |
---|
| 140 | } |
---|
| 141 | if (e.contains("Invalid or missing signers cert!")) { |
---|
| 142 | translatedError = "El certificado del firmante es inválido o no se encuentra en el archivo."; |
---|
| 143 | } |
---|
| 144 | if (e.contains("Invalid signature method!")) { |
---|
| 145 | translatedError = "Algoritmo de firma no soportado."; |
---|
| 146 | } |
---|
| 147 | if (e.contains("Signature method:")) { |
---|
| 148 | translatedError = "El algoritmo de firma no está disponible en la aplicación."; |
---|
| 149 | } |
---|
| 150 | if (e.contains("Invalid signature value! Signers cert and signature value don't match!")) { |
---|
| 151 | translatedError = "Error interno: el valor de la firma no es correcto. El certificado firmante y el valor de la firma no coinciden."; |
---|
| 152 | } |
---|
| 153 | if (e.contains("Signature asn.1 prefix:")) { |
---|
| 154 | translatedError = "Error interno: prefijo ASN.1 de la firma no es correcto."; |
---|
| 155 | } |
---|
| 156 | if (e.contains("Invalid signature value! Signature value decrypted len:")) { |
---|
| 157 | translatedError = "Error interno: valor de firma inválido. No existe prefijo de estructura ASN.1."; |
---|
| 158 | } |
---|
| 159 | if (e.contains("Invalid signature value!")) { |
---|
| 160 | translatedError = "Valor de firma inválido."; |
---|
| 161 | } |
---|
| 162 | if (e.contains("Missing Reference for file")) { |
---|
| 163 | translatedError = "Error interno: no existe una referencia al archivo"; |
---|
| 164 | } |
---|
| 165 | if (e.contains("Signers certificate has expired!")) { |
---|
| 166 | translatedError = "El certificado del firmante expiró."; |
---|
| 167 | } |
---|
| 168 | if (e.contains("Failed to verify OCSP for:")) { |
---|
| 169 | translatedError = "No se pudo verificar el certificado del servidor OCSP."; |
---|
| 170 | } |
---|
| 171 | if (e.contains("OCSP value is empty!")) { |
---|
| 172 | translatedError = "Error interno: el valor del certificado del OCSP es vacío."; |
---|
| 173 | } |
---|
| 174 | if (e.contains("No OCSP ref for uri:")) { |
---|
| 175 | translatedError = "Error interno: no existe una referencia para el certificado del servidor OCSP."; |
---|
| 176 | } |
---|
| 177 | if (e.contains("Notarys digest doesn't match!")) { |
---|
| 178 | translatedError = "Error interno: la reseña o hash del certificado OCSP no coincide."; |
---|
| 179 | } |
---|
| 180 | if (e.contains("Signature has no OCSP confirmation!")) { |
---|
| 181 | translatedError = "La firma no tiene confirmación de un servidor OCSP."; |
---|
| 182 | } |
---|
| 183 | //if (e.contains("")) { |
---|
| 184 | // translatedError = "El certificado firmante no ha sido firmado por una AC raíz conocida."; |
---|
| 185 | //} |
---|
| 186 | if (e.contains("The current BDoc container uses weaker encryption method than officialy accepted in Estonia")) { |
---|
| 187 | translatedError = "El archivo firmado utiliza un algoritmo de reseña (hash) considerado débil."; |
---|
| 188 | } |
---|
| 189 | if (e.contains("81 -")) { |
---|
| 190 | translatedError = "Error interno: tipo de bloque desconocido."; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | else{ |
---|
| 194 | //translatedError = e; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | return translatedError; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | |
---|
[88eadd6] | 202 | } |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | |
---|