2 * Copyright (C) 2007-2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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>.
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
17 * @defgroup certificate certificate
18 * @{ @ingroup certificates
21 #ifndef CERTIFICATE_H_
22 #define CERTIFICATE_H_
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
;
29 #include <utils/identification.h>
30 #include <credentials/keys/public_key.h>
33 * Kind of a certificate_t
35 enum certificate_type_t
{
36 /** just any certificate */
38 /** X.509 certificate */
40 /** X.509 certificate revocation list */
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 */
48 /** PKCS#10 certificate request */
50 /** trusted, preinstalled public key */
52 /** PGP certificate */
54 /** Pluto cert_t (not a certificate_t), either x509 or PGP */
56 /** Pluto x509acert_t (not a certificate_t), attribute certificate */
58 /** Pluto x509crl_t (not a certificate_t), certificate revocation list */
63 * Enum names for certificate_type_t
65 extern enum_name_t
*certificate_type_names
;
68 * Result of a certificate validation.
70 * Order of values is relevant, sorted from good to bad.
72 enum cert_validation_t
{
73 /** certificate has been validated successfully */
75 /** validation has been skipped due to missing validation information */
77 /** certificate has been validated, but check based on stale information */
79 /** validation failed due to a processing error */
81 /** certificate has been revoked */
86 * Enum names for cert_validation_t
88 extern enum_name_t
*cert_validation_names
;
91 * An abstract certificate.
93 * A certificate designs a subject-issuer relationship. It may have an
94 * associated public key.
96 struct certificate_t
{
99 * Get the type of the certificate.
101 * @return certificate type
103 certificate_type_t (*get_type
)(certificate_t
*this);
106 * Get the primary subject to which this certificate belongs.
108 * @return subject identity
110 identification_t
* (*get_subject
)(certificate_t
*this);
113 * Check if certificate contains a subject ID.
115 * A certificate may contain additional subject identifiers, which are
116 * not returned by get_subject (e.g. subjectAltNames)
118 * @param subject subject identity
119 * @return matching value of best match
121 id_match_t (*has_subject
)(certificate_t
*this, identification_t
*subject
);
124 * Get the issuer which signed this certificate.
126 * @return issuer identity
128 identification_t
* (*get_issuer
)(certificate_t
*this);
131 * Check if certificate contains an issuer ID.
133 * A certificate may contain additional issuer identifiers, which are
134 * not returned by get_issuer (e.g. issuerAltNames)
136 * @param subject isser identity
137 * @return matching value of best match
139 id_match_t (*has_issuer
)(certificate_t
*this, identification_t
*issuer
);
142 * Check if this certificate is issued and signed by a specific issuer.
144 * @param issuer issuer's certificate
145 * @return TRUE if certificate issued by issuer and trusted
147 bool (*issued_by
)(certificate_t
*this, certificate_t
*issuer
);
150 * Get the public key associated to this certificate.
152 * @return newly referenced public_key, NULL if none available
154 public_key_t
* (*get_public_key
)(certificate_t
*this);
157 * Check the lifetime of the certificate.
159 * @param when check validity at a certain time (NULL for now)
160 * @param not_before receives certificates start of lifetime
161 * @param not_after receives certificates end of lifetime
162 * @return TRUE if when between not_after and not_before
164 bool (*get_validity
)(certificate_t
*this, time_t *when
,
165 time_t *not_before
, time_t *not_after
);
168 * Is this newer than that?
170 * @return TRUE if newer, FALSE otherwise
172 bool (*is_newer
)(certificate_t
*this, certificate_t
*that
);
175 * Get the certificate in an encoded form.
177 * @return allocated chunk of encoded cert
179 chunk_t (*get_encoding
)(certificate_t
*this);
182 * Check if two certificates are equal.
184 * @param other certificate to compair against this
185 * @return TRUE if certificates are equal
187 bool (*equals
)(certificate_t
*this, certificate_t
*other
);
190 * Get a new reference to the certificate.
192 * @return this, with an increased refcount
194 certificate_t
* (*get_ref
)(certificate_t
*this);
197 * Destroy a certificate.
199 void (*destroy
)(certificate_t
*this);
202 #endif /** CERTIFICATE_H_ @}*/