4 * @brief Interface of x509_t.
9 * Copyright (C) 2006 Martin Willi, Andreas Steffen
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 typedef struct x509_t x509_t
;
29 #include <crypto/rsa/rsa_public_key.h>
30 #include <crypto/certinfo.h>
31 #include <utils/identification.h>
32 #include <utils/iterator.h>
35 * @brief X.509 certificate.
38 * - x509_create_from_chunk()
39 * - x509_create_from_file()
41 * @todo more code cleanup needed!
42 * @todo fix unimplemented functions...
43 * @todo handle memory management
50 * @brief Set trusted public key life.
52 * @param this calling object
53 * @param until time until public key is trusted
55 void (*set_until
) (x509_t
*this, time_t until
);
58 * @brief Get trusted public key life.
60 * @param this calling object
61 * @return time until public key is trusted
63 time_t (*get_until
) (const x509_t
*this);
66 * @brief Set the certificate status
68 * @param this calling object
69 * @param status certificate status
71 void (*set_status
) (x509_t
*this, cert_status_t status
);
74 * @brief Get the certificate status
76 * @param this calling object
77 * @return certificate status
79 cert_status_t (*get_status
) (const x509_t
*this);
82 * @brief Get the DER-encoded X.509 certificate body
84 * @param this calling object
85 * @return DER-encoded X.509 certificate
87 chunk_t (*get_certificate
) (const x509_t
*this);
90 * @brief Get the RSA public key from the certificate.
92 * @param this calling object
95 rsa_public_key_t
*(*get_public_key
) (const x509_t
*this);
98 * @brief Get serial number from the certificate.
100 * @param this calling object
101 * @return serialNumber
103 chunk_t (*get_serialNumber
) (const x509_t
*this);
106 * @brief Get subjectKeyID from the certificate.
108 * @param this calling object
109 * @return subjectKeyID
111 chunk_t (*get_subjectKeyID
) (const x509_t
*this);
114 * @brief Get keyid from the certificate's public key.
116 * @param this calling object
119 chunk_t (*get_keyid
) (const x509_t
*this);
122 * @brief Get the certificate issuer's ID.
124 * The resulting ID is always a identification_t
125 * of type ID_DER_ASN1_DN.
127 * @param this calling object
130 identification_t
*(*get_issuer
) (const x509_t
*this);
133 * @brief Get the subjectDistinguisheName.
135 * The resulting ID is always a identification_t
136 * of type ID_DER_ASN1_DN.
138 * @param this calling object
139 * @return subjects ID
141 identification_t
*(*get_subject
) (const x509_t
*this);
144 * @brief Create an iterator for the crlDistributionPoints.
146 * @param this calling object
147 * @return iterator for crlDistributionPoints
149 iterator_t
*(*create_crluri_iterator
) (const x509_t
*this);
152 * @brief Create an iterator for the ocspAccessLocations.
154 * @param this calling object
155 * @return iterator for ocspAccessLocations
157 iterator_t
*(*create_ocspuri_iterator
) (const x509_t
*this);
160 * @brief Check if a certificate is trustworthy
162 * @param this calling object
163 * @param signer signer's RSA public key
165 bool (*verify
) (const x509_t
*this, const rsa_public_key_t
*signer
);
168 * @brief Compare two certificates.
170 * Comparison is done via the certificates signature.
172 * @param this first cert for compare
173 * @param other second cert for compare
174 * @return TRUE if signature is equal
176 bool (*equals
) (const x509_t
*this, const x509_t
*that
);
179 * @brief Checks if the certificate contains a subjectAltName equal to id.
181 * @param this certificate being examined
182 * @param id id which is being compared to the subjectAltNames
183 * @return TRUE if a match is found
185 bool (*equals_subjectAltName
) (const x509_t
*this, identification_t
*id
);
188 * @brief Checks if the subject of the other cert is the issuer of this cert.
190 * @param this certificate
191 * @param issuer potential issuer certificate
192 * @return TRUE if issuer is found
194 bool (*is_issuer
) (const x509_t
*this, const x509_t
*issuer
);
197 * @brief Checks the validity interval of the certificate
199 * @param this certificate being examined
200 * @param until until = min(until, notAfter)
201 * @return NULL if the certificate is valid
203 err_t (*is_valid
) (const x509_t
*this, time_t *until
);
206 * @brief Returns the CA basic constraints flag
208 * @param this certificate being examined
209 * @return TRUE if the CA flag is set
211 bool (*is_ca
) (const x509_t
*this);
214 * @brief Checks if the certificate is self-signed (subject equals issuer)
216 * @param this certificate being examined
217 * @return TRUE if self-signed
219 bool (*is_self_signed
) (const x509_t
*this);
222 * @brief Destroys the certificate.
224 * @param this certificate to destroy
226 void (*destroy
) (x509_t
*this);
230 * @brief Read a x509 certificate from a DER encoded blob.
232 * @param chunk chunk containing DER encoded data
233 * @return created x509_t certificate, or NULL if inv\ 1lid.
235 * @ingroup transforms
237 x509_t
*x509_create_from_chunk(chunk_t chunk
);
240 * @brief Read a x509 certificate from a DER encoded file.
242 * @param filename file containing DER encoded data
243 * @param label label describing kind of certificate
244 * @return created x509_t certificate, or NULL if invalid.
246 * @ingroup transforms
248 x509_t
*x509_create_from_file(const char *filename
, const char *label
);