source: dispositivos_moviles/TibisayMovil/src/ve/gob/cenditel/tibisaymovil/ValidationResult.java

Last change on this file was 8379cd8, checked in by Antonio Araujo Brett <aaraujo@…>, 11 years ago

Agregado encabezado de licencia a archivos fuentes.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2Tibisay Movil
3
4Copyright (C) 2013 Antonio Araujo (aaraujo@cenditel.gob.ve), Jose Ruiz
5(jruiz@cenditel.gob.ve), Fundacion Centro Nacional de Desarrollo e
6Investigacion en Tecnologias Libres - CENDITEL.
7
8La Fundación CENDITEL concede permiso para usar, copiar, distribuir y/o
9modificar este programa, reconociendo el derecho que la humanidad posee al
10libre acceso al conocimiento, bajo los términos de la licencia de software
11GPL versión 2.0 de la Free Software Foundation.
12
13Este programa se distribuye con la esperanza de que sea util, pero SIN
14NINGUNA GARANTIA; tampoco las implicitas garantias de MERCANTILIDAD o
15ADECUACION A UN PROPOSITO PARTICULAR.
16
17Para mayor información sobre los términos de la licencia ver el archivo
18llamado "gpl-2.0.txt" en ingles.
19*/
20
21package ve.gob.cenditel.tibisaymovil;
22
23import org.spongycastle.cert.ocsp.CertificateStatus;
24import org.spongycastle.cert.ocsp.RevokedStatus;
25import org.spongycastle.cert.ocsp.UnknownStatus;
26
27public 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}
Note: See TracBrowser for help on using the repository browser.