[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 | |
---|
[288126d] | 21 | package ve.gob.cenditel.tibisaymovil; |
---|
| 22 | |
---|
| 23 | import org.spongycastle.cert.ocsp.CertificateStatus; |
---|
| 24 | import org.spongycastle.cert.ocsp.RevokedStatus; |
---|
| 25 | import org.spongycastle.cert.ocsp.UnknownStatus; |
---|
| 26 | |
---|
| 27 | public class ValidationResult { |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | * Construction status |
---|
| 31 | */ |
---|
| 32 | static public final int ERROR_CHAIN = 0; |
---|
| 33 | static public final int ERROR_CONNECTION = 1; |
---|
| 34 | // OCSP responses |
---|
| 35 | static public final int GOOD = 2; |
---|
| 36 | static public final int UNKNOWN = 3; |
---|
| 37 | static public final int REVOKED = 4; |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * Result status |
---|
| 41 | */ |
---|
| 42 | static public final int ERROR_CHAIN_RESULT = 16; |
---|
| 43 | static public final int ERROR_CONNECTION_RESULT = 17; |
---|
| 44 | static public final int GOOD_RESULT = 18; |
---|
| 45 | static public final int GOOD_UNTRUSTED_RESULT = 19; |
---|
| 46 | static public final int UNKNOWN_RESULT = 20; |
---|
| 47 | static public final int REVOKED_RESULT = 21; |
---|
| 48 | |
---|
| 49 | private final boolean validSignature; |
---|
| 50 | private final boolean validSigner; |
---|
| 51 | private int status; |
---|
| 52 | |
---|
| 53 | public ValidationResult(int errorState) { |
---|
| 54 | setErrorState(errorState); |
---|
| 55 | validSignature = false; |
---|
| 56 | validSigner = false; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | public ValidationResult(CertificateStatus certStatus, |
---|
| 60 | boolean validSignature, boolean validSigner) { |
---|
| 61 | setStatus(certStatus); |
---|
| 62 | this.validSignature = validSignature; |
---|
| 63 | this.validSigner = validSigner; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | private void setStatus(CertificateStatus certStatus) { |
---|
| 67 | if (certStatus == null) { // null is GOOD in CertificateStatus |
---|
| 68 | // specification |
---|
| 69 | status = GOOD; |
---|
| 70 | } else if (certStatus instanceof UnknownStatus) { |
---|
| 71 | status = UNKNOWN; |
---|
| 72 | } else if (certStatus instanceof RevokedStatus) { |
---|
| 73 | status = REVOKED; |
---|
| 74 | } else { |
---|
| 75 | throw new IllegalArgumentException(); |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | public void setErrorState(int errorState) { |
---|
| 80 | if (errorState == ERROR_CHAIN) { |
---|
| 81 | status = errorState; |
---|
| 82 | } else if (errorState == ERROR_CONNECTION) { |
---|
| 83 | status = errorState; |
---|
| 84 | } else { |
---|
| 85 | throw new IllegalArgumentException(); |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | public int getStatus() { |
---|
| 90 | return status; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | public boolean isValidSignature() { |
---|
| 94 | return validSignature; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | public boolean isValidSigner() { |
---|
| 98 | return validSigner; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | public int getResultValue() { |
---|
| 102 | if (getStatus() == ValidationResult.GOOD && isValidSignature() |
---|
| 103 | && isValidSigner()) { |
---|
| 104 | return GOOD_RESULT; |
---|
| 105 | } else if (getStatus() == ValidationResult.GOOD && // Untrust authority |
---|
| 106 | (!isValidSignature() || !isValidSigner())) { |
---|
| 107 | return GOOD_UNTRUSTED_RESULT; |
---|
| 108 | } else if (getStatus() == ValidationResult.REVOKED) { |
---|
| 109 | return REVOKED_RESULT; |
---|
| 110 | } else if (getStatus() == ValidationResult.UNKNOWN) { |
---|
| 111 | return UNKNOWN_RESULT; |
---|
| 112 | } else if (getStatus() == ValidationResult.ERROR_CHAIN) { |
---|
| 113 | return ERROR_CHAIN_RESULT; |
---|
| 114 | } else if (getStatus() == ValidationResult.ERROR_CONNECTION) { |
---|
| 115 | return ERROR_CONNECTION_RESULT; |
---|
| 116 | } else { |
---|
| 117 | throw new IllegalStateException(); |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | } |
---|