merged multi-auth branch back into trunk
[strongswan.git] / src / libstrongswan / credentials / certificates / certificate.h
1 /*
2 * Copyright (C) 2007-2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup certificate certificate
18 * @{ @ingroup certificates
19 */
20
21 #ifndef CERTIFICATE_H_
22 #define CERTIFICATE_H_
23
24 typedef struct certificate_t certificate_t;
25 typedef enum certificate_type_t certificate_type_t;
26 typedef enum cert_validation_t cert_validation_t;
27
28 #include <library.h>
29 #include <utils/identification.h>
30 #include <credentials/keys/public_key.h>
31
32 /**
33 * Kind of a certificate_t
34 */
35 enum certificate_type_t {
36 /** just any certificate */
37 CERT_ANY,
38 /** X.509 certificate */
39 CERT_X509,
40 /** X.509 certificate revocation list */
41 CERT_X509_CRL,
42 /** X.509 online certificate status protocol request */
43 CERT_X509_OCSP_REQUEST,
44 /** X.509 online certificate status protocol response */
45 CERT_X509_OCSP_RESPONSE,
46 /** X.509 attribute certificate */
47 CERT_X509_AC,
48 /** trusted, preinstalled public key */
49 CERT_TRUSTED_PUBKEY,
50 /** PGP certificate */
51 CERT_PGP,
52 };
53
54 /**
55 * Enum names for certificate_type_t
56 */
57 extern enum_name_t *certificate_type_names;
58
59 /**
60 * Result of a certificate validation.
61 *
62 * Order of values is relevant, sorted from good to bad.
63 */
64 enum cert_validation_t {
65 /** certificate has been validated successfully */
66 VALIDATION_GOOD = 0,
67 /** validation has been skipped due to missing validation information */
68 VALIDATION_SKIPPED,
69 /** certificate has been validated, but check based on stale information */
70 VALIDATION_STALE,
71 /** validation failed due to a processing error */
72 VALIDATION_FAILED,
73 /** certificate has been revoked */
74 VALIDATION_REVOKED,
75 };
76
77 /**
78 * Enum names for cert_validation_t
79 */
80 extern enum_name_t *cert_validation_names;
81
82 /**
83 * An abstract certificate.
84 *
85 * A certificate designs a subject-issuer relationship. It may have an
86 * associated public key.
87 */
88 struct certificate_t {
89
90 /**
91 * Get the type of the certificate.
92 *
93 * @return certifcate type
94 */
95 certificate_type_t (*get_type)(certificate_t *this);
96
97 /**
98 * Get the primary subject to which this certificate belongs.
99 *
100 * @return subject identity
101 */
102 identification_t* (*get_subject)(certificate_t *this);
103
104 /**
105 * Check if certificate contains a subject ID.
106 *
107 * A certificate may contain additional subject identifiers, which are
108 * not returned by get_subject (e.g. subjectAltNames)
109 *
110 * @param subject subject identity
111 * @return matching value of best match
112 */
113 id_match_t (*has_subject)(certificate_t *this, identification_t *subject);
114
115 /**
116 * Get the issuer which signed this certificate.
117 *
118 * @return issuer identity
119 */
120 identification_t* (*get_issuer)(certificate_t *this);
121
122 /**
123 * Check if certificate contains an issuer ID.
124 *
125 * A certificate may contain additional issuer identifiers, which are
126 * not returned by get_issuer (e.g. issuerAltNames)
127 *
128 * @param subject isser identity
129 * @return matching value of best match
130 */
131 id_match_t (*has_issuer)(certificate_t *this, identification_t *issuer);
132
133 /**
134 * Check if this certificate is issued and signed by a specific issuer.
135 *
136 * @param issuer issuer's certificate
137 * @return TRUE if certificate issued by issuer and trusted
138 */
139 bool (*issued_by)(certificate_t *this, certificate_t *issuer);
140
141 /**
142 * Get the public key associated to this certificate.
143 *
144 * @return newly referenced public_key, NULL if none available
145 */
146 public_key_t* (*get_public_key)(certificate_t *this);
147
148 /**
149 * Check the lifetime of the certificate.
150 *
151 * @param when check validity at a certain time (NULL for now)
152 * @param not_before receives certificates start of lifetime
153 * @param not_after receives certificates end of lifetime
154 * @return TRUE if when between not_after and not_before
155 */
156 bool (*get_validity)(certificate_t *this, time_t *when,
157 time_t *not_before, time_t *not_after);
158
159 /**
160 * Is this newer than that?
161 *
162 * @return TRUE if newer, FALSE otherwise
163 */
164 bool (*is_newer)(certificate_t *this, certificate_t *that);
165
166 /**
167 * Get the certificate in an encoded form.
168 *
169 * @return allocated chunk of encoded cert
170 */
171 chunk_t (*get_encoding)(certificate_t *this);
172
173 /**
174 * Check if two certificates are equal.
175 *
176 * @param other certificate to compair against this
177 * @return TRUE if certificates are equal
178 */
179 bool (*equals)(certificate_t *this, certificate_t *other);
180
181 /**
182 * Get a new reference to the certificate.
183 *
184 * @return this, with an increased refcount
185 */
186 certificate_t* (*get_ref)(certificate_t *this);
187
188 /**
189 * Destroy a certificate.
190 */
191 void (*destroy)(certificate_t *this);
192 };
193
194 #endif /** CERTIFICATE_H_ @}*/