acdd3a954a858d45b00e1f28185a660eaeae13de
4 * @brief Interface of x509_t.
9 * Copyright (C) 2000 Andreas Hess, Patric Lichtsteiner, Roger Wegmann
10 * Copyright (C) 2001 Marco Bertossa, Andreas Schleiss
11 * Copyright (C) 2002 Mario Strasser
12 * Copyright (C) 2000-2004 Andreas Steffen, Zuercher Hochschule Winterthur
13 * Copyright (C) 2006 Martin Willi, Andreas Steffen
15 * Hochschule fuer Technik Rapperswil
17 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the
19 * Free Software Foundation; either version 2 of the License, or (at your
20 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
31 typedef struct x509_t x509_t
;
34 #include <crypto/rsa/rsa_public_key.h>
35 #include <crypto/certinfo.h>
36 #include <utils/identification.h>
37 #include <utils/iterator.h>
38 #include <utils/linked_list.h>
42 #define AUTH_NONE 0x00 /* no authorities */
43 #define AUTH_CA 0x01 /* certification authority */
44 #define AUTH_AA 0x02 /* authorization authority */
45 #define AUTH_OCSP 0x04 /* ocsp signing authority */
48 * @brief X.509 certificate.
51 * - x509_create_from_chunk()
52 * - x509_create_from_file()
59 * @brief Set trusted public key life.
61 * @param this calling object
62 * @param until time until public key is trusted
64 void (*set_until
) (x509_t
*this, time_t until
);
67 * @brief Get trusted public key life.
69 * @param this calling object
70 * @return time until public key is trusted
72 time_t (*get_until
) (const x509_t
*this);
75 * @brief Set the certificate status
77 * @param this calling object
78 * @param status certificate status
80 void (*set_status
) (x509_t
*this, cert_status_t status
);
83 * @brief Get the certificate status
85 * @param this calling object
86 * @return certificate status
88 cert_status_t (*get_status
) (const x509_t
*this);
91 * @brief Add authority flags
93 * @param this calling object
94 * @param flag flags to be added
96 void (*add_authority_flags
) (x509_t
*this, u_int flags
);
99 * @brief Get authority flags
101 * @param this calling object
102 * @return authority flags
104 u_int (*get_authority_flags
) (x509_t
*this);
107 * @brief Check a specific authority flag
109 * @param this calling object
110 * @param flag flag to be checked
111 * @return TRUE if flag is present
113 bool (*has_authority_flag
) (x509_t
*this, u_int flag
);
116 * @brief Get the DER-encoded X.509 certificate body
118 * @param this calling object
119 * @return DER-encoded X.509 certificate
121 chunk_t (*get_certificate
) (const x509_t
*this);
124 * @brief Get the RSA public key from the certificate.
126 * @param this calling object
129 rsa_public_key_t
*(*get_public_key
) (const x509_t
*this);
132 * @brief Get serial number from the certificate.
134 * @param this calling object
135 * @return serialNumber
137 chunk_t (*get_serialNumber
) (const x509_t
*this);
140 * @brief Get subjectKeyID from the certificate.
142 * @param this calling object
143 * @return subjectKeyID
145 chunk_t (*get_subjectKeyID
) (const x509_t
*this);
148 * @brief Get keyid from the certificate's public key.
150 * @param this calling object
153 chunk_t (*get_keyid
) (const x509_t
*this);
156 * @brief Get the certificate issuer's ID.
158 * The resulting ID is always a identification_t
159 * of type ID_DER_ASN1_DN.
161 * @param this calling object
164 identification_t
*(*get_issuer
) (const x509_t
*this);
167 * @brief Get the subjectDistinguisheName.
169 * The resulting ID is always a identification_t
170 * of type ID_DER_ASN1_DN.
172 * @param this calling object
173 * @return subjects ID
175 identification_t
*(*get_subject
) (const x509_t
*this);
178 * @brief Create an iterator for the crlDistributionPoints.
180 * @param this calling object
181 * @return iterator for crlDistributionPoints
183 iterator_t
*(*create_crluri_iterator
) (const x509_t
*this);
186 * @brief Create an iterator for the ocspAccessLocations.
188 * @param this calling object
189 * @return iterator for ocspAccessLocations
191 iterator_t
*(*create_ocspuri_iterator
) (const x509_t
*this);
194 * @brief Check if a certificate is trustworthy
196 * @param this calling object
197 * @param signer signer's RSA public key
199 bool (*verify
) (const x509_t
*this, const rsa_public_key_t
*signer
);
202 * @brief Compare two certificates.
204 * Comparison is done via the certificates signature.
206 * @param this first cert for compare
207 * @param other second cert for compare
208 * @return TRUE if signature is equal
210 bool (*equals
) (const x509_t
*this, const x509_t
*that
);
213 * @brief Checks if the certificate contains a subjectAltName equal to id.
215 * @param this certificate being examined
216 * @param id id which is being compared to the subjectAltNames
217 * @return TRUE if a match is found
219 bool (*equals_subjectAltName
) (const x509_t
*this, identification_t
*id
);
222 * @brief Checks if the subject of the other cert is the issuer of this cert.
224 * @param this certificate
225 * @param issuer potential issuer certificate
226 * @return TRUE if issuer is found
228 bool (*is_issuer
) (const x509_t
*this, const x509_t
*issuer
);
231 * @brief Checks the validity interval of the certificate
233 * @param this certificate being examined
234 * @param until until = min(until, notAfter)
235 * @return NULL if the certificate is valid
237 err_t (*is_valid
) (const x509_t
*this, time_t *until
);
240 * @brief Returns the CA basic constraints flag
242 * @param this certificate being examined
243 * @return TRUE if the CA flag is set
245 bool (*is_ca
) (const x509_t
*this);
248 * @brief Returns the OCSPSigner extended key usage flag
250 * @param this certificate being examined
251 * @return TRUE if the OCSPSigner flag is set
253 bool (*is_ocsp_signer
) (const x509_t
*this);
256 * @brief Checks if the certificate is self-signed (subject equals issuer)
258 * @param this certificate being examined
259 * @return TRUE if self-signed
261 bool (*is_self_signed
) (const x509_t
*this);
264 * @brief Log the certificate info to out.
266 * @param this calling object
267 * @param out stream to write to
268 * @param utc TRUE for UTC times, FALSE for local time
270 void (*list
)(x509_t
*this, FILE *out
, bool utc
);
273 * @brief Destroys the certificate.
275 * @param this certificate to destroy
277 void (*destroy
) (x509_t
*this);
281 * @brief Read a x509 certificate from a DER encoded blob.
283 * @param chunk chunk containing DER encoded data
284 * @return created x509_t certificate, or NULL if inv\ 1lid.
288 x509_t
*x509_create_from_chunk(chunk_t chunk
, u_int level
);
291 * @brief Read a x509 certificate from a DER encoded file.
293 * @param filename file containing DER encoded data
294 * @param label label describing kind of certificate
295 * @return created x509_t certificate, or NULL if invalid.
299 x509_t
*x509_create_from_file(const char *filename
, const char *label
);
302 * @brief Parses a DER encoded authorityKeyIdentifier
304 * @param blob blob containing DER encoded data
305 * @param level0 indicates the current parsing level
306 * @param authKeyID assigns the authorityKeyIdentifier
307 * @param authKeySerialNumber assigns the authKeySerialNumber
311 void parse_authorityKeyIdentifier(chunk_t blob
, int level0
, chunk_t
*authKeyID
, chunk_t
*authKeySerialNumber
);
314 * @brief Parses DER encoded generalNames
316 * @param blob blob containing DER encoded data
317 * @param level0 indicates the current parsing level
318 * @param implicit implicit coding is used
319 * @param list linked list of decoded generalNames
323 void parse_generalNames(chunk_t blob
, int level0
, bool implicit
, linked_list_t
*list
);