Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file x509.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2009, Paul Bakker <polarssl_maintainer at polarssl.org> |
| 5 | * All rights reserved. |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 6 | * |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame] | 7 | * Joined copyright on original XySSL code with: Christophe Devine |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 22 | */ |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 23 | #ifndef POLARSSL_X509_H |
| 24 | #define POLARSSL_X509_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 25 | |
Paul Bakker | 8e831ed | 2009-01-03 21:24:11 +0000 | [diff] [blame] | 26 | #include "polarssl/rsa.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 27 | |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 28 | /* |
| 29 | * ASN1 Error codes |
| 30 | * |
| 31 | * These error codes will be OR'ed to X509 error codes for |
| 32 | * higher error granularity. |
| 33 | */ |
Paul Bakker | b5bf176 | 2009-07-19 20:28:35 +0000 | [diff] [blame] | 34 | #define POLARSSL_ERR_ASN1_OUT_OF_DATA 0x0014 |
| 35 | #define POLARSSL_ERR_ASN1_UNEXPECTED_TAG 0x0016 |
| 36 | #define POLARSSL_ERR_ASN1_INVALID_LENGTH 0x0018 |
| 37 | #define POLARSSL_ERR_ASN1_LENGTH_MISMATCH 0x001A |
| 38 | #define POLARSSL_ERR_ASN1_INVALID_DATA 0x001C |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 39 | |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 40 | /* |
| 41 | * X509 Error codes |
| 42 | */ |
Paul Bakker | 3391b12 | 2009-07-28 20:11:54 +0000 | [diff] [blame] | 43 | #define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE -0x0020 |
| 44 | #define POLARSSL_ERR_X509_CERT_INVALID_PEM -0x0040 |
| 45 | #define POLARSSL_ERR_X509_CERT_INVALID_FORMAT -0x0060 |
| 46 | #define POLARSSL_ERR_X509_CERT_INVALID_VERSION -0x0080 |
| 47 | #define POLARSSL_ERR_X509_CERT_INVALID_SERIAL -0x00A0 |
| 48 | #define POLARSSL_ERR_X509_CERT_INVALID_ALG -0x00C0 |
| 49 | #define POLARSSL_ERR_X509_CERT_INVALID_NAME -0x00E0 |
| 50 | #define POLARSSL_ERR_X509_CERT_INVALID_DATE -0x0100 |
| 51 | #define POLARSSL_ERR_X509_CERT_INVALID_PUBKEY -0x0120 |
| 52 | #define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE -0x0140 |
| 53 | #define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS -0x0160 |
| 54 | #define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION -0x0180 |
| 55 | #define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG -0x01A0 |
| 56 | #define POLARSSL_ERR_X509_CERT_UNKNOWN_PK_ALG -0x01C0 |
| 57 | #define POLARSSL_ERR_X509_CERT_SIG_MISMATCH -0x01E0 |
| 58 | #define POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x0200 |
| 59 | #define POLARSSL_ERR_X509_KEY_INVALID_PEM -0x0220 |
| 60 | #define POLARSSL_ERR_X509_KEY_INVALID_VERSION -0x0240 |
| 61 | #define POLARSSL_ERR_X509_KEY_INVALID_FORMAT -0x0260 |
| 62 | #define POLARSSL_ERR_X509_KEY_INVALID_ENC_IV -0x0280 |
| 63 | #define POLARSSL_ERR_X509_KEY_UNKNOWN_ENC_ALG -0x02A0 |
| 64 | #define POLARSSL_ERR_X509_KEY_PASSWORD_REQUIRED -0x02C0 |
| 65 | #define POLARSSL_ERR_X509_KEY_PASSWORD_MISMATCH -0x02E0 |
| 66 | #define POLARSSL_ERR_X509_POINT_ERROR -0x0300 |
| 67 | #define POLARSSL_ERR_X509_VALUE_TO_LENGTH -0x0320 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 68 | |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 69 | /* |
| 70 | * X509 Verify codes |
| 71 | */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 72 | #define BADCERT_EXPIRED 1 |
| 73 | #define BADCERT_REVOKED 2 |
| 74 | #define BADCERT_CN_MISMATCH 4 |
| 75 | #define BADCERT_NOT_TRUSTED 8 |
Paul Bakker | 40ea7de | 2009-05-03 10:18:48 +0000 | [diff] [blame] | 76 | #define BADCRL_NOT_TRUSTED 16 |
| 77 | #define BADCRL_EXPIRED 32 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * DER constants |
| 81 | */ |
| 82 | #define ASN1_BOOLEAN 0x01 |
| 83 | #define ASN1_INTEGER 0x02 |
| 84 | #define ASN1_BIT_STRING 0x03 |
| 85 | #define ASN1_OCTET_STRING 0x04 |
| 86 | #define ASN1_NULL 0x05 |
| 87 | #define ASN1_OID 0x06 |
| 88 | #define ASN1_UTF8_STRING 0x0C |
| 89 | #define ASN1_SEQUENCE 0x10 |
| 90 | #define ASN1_SET 0x11 |
| 91 | #define ASN1_PRINTABLE_STRING 0x13 |
| 92 | #define ASN1_T61_STRING 0x14 |
| 93 | #define ASN1_IA5_STRING 0x16 |
| 94 | #define ASN1_UTC_TIME 0x17 |
Paul Bakker | 9120018 | 2010-02-18 21:26:15 +0000 | [diff] [blame] | 95 | #define ASN1_GENERALIZED_TIME 0x18 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 96 | #define ASN1_UNIVERSAL_STRING 0x1C |
| 97 | #define ASN1_BMP_STRING 0x1E |
| 98 | #define ASN1_PRIMITIVE 0x00 |
| 99 | #define ASN1_CONSTRUCTED 0x20 |
| 100 | #define ASN1_CONTEXT_SPECIFIC 0x80 |
| 101 | |
| 102 | /* |
| 103 | * various object identifiers |
| 104 | */ |
| 105 | #define X520_COMMON_NAME 3 |
| 106 | #define X520_COUNTRY 6 |
| 107 | #define X520_LOCALITY 7 |
| 108 | #define X520_STATE 8 |
| 109 | #define X520_ORGANIZATION 10 |
| 110 | #define X520_ORG_UNIT 11 |
| 111 | #define PKCS9_EMAIL 1 |
| 112 | |
| 113 | #define X509_OUTPUT_DER 0x01 |
| 114 | #define X509_OUTPUT_PEM 0x02 |
| 115 | #define PEM_LINE_LENGTH 72 |
| 116 | #define X509_ISSUER 0x01 |
| 117 | #define X509_SUBJECT 0x02 |
| 118 | |
| 119 | #define OID_X520 "\x55\x04" |
| 120 | #define OID_CN "\x55\x04\x03" |
| 121 | #define OID_PKCS1 "\x2A\x86\x48\x86\xF7\x0D\x01\x01" |
| 122 | #define OID_PKCS1_RSA "\x2A\x86\x48\x86\xF7\x0D\x01\x01\x01" |
| 123 | #define OID_PKCS1_RSA_SHA "\x2A\x86\x48\x86\xF7\x0D\x01\x01\x05" |
| 124 | #define OID_PKCS9 "\x2A\x86\x48\x86\xF7\x0D\x01\x09" |
| 125 | #define OID_PKCS9_EMAIL "\x2A\x86\x48\x86\xF7\x0D\x01\x09\x01" |
| 126 | |
| 127 | /* |
| 128 | * Structures for parsing X.509 certificates |
| 129 | */ |
| 130 | typedef struct _x509_buf |
| 131 | { |
| 132 | int tag; |
| 133 | int len; |
| 134 | unsigned char *p; |
| 135 | } |
| 136 | x509_buf; |
| 137 | |
| 138 | typedef struct _x509_name |
| 139 | { |
| 140 | x509_buf oid; |
| 141 | x509_buf val; |
| 142 | struct _x509_name *next; |
| 143 | } |
| 144 | x509_name; |
| 145 | |
| 146 | typedef struct _x509_time |
| 147 | { |
| 148 | int year, mon, day; |
| 149 | int hour, min, sec; |
| 150 | } |
| 151 | x509_time; |
| 152 | |
| 153 | typedef struct _x509_cert |
| 154 | { |
| 155 | x509_buf raw; |
| 156 | x509_buf tbs; |
| 157 | |
| 158 | int version; |
| 159 | x509_buf serial; |
| 160 | x509_buf sig_oid1; |
| 161 | |
| 162 | x509_buf issuer_raw; |
| 163 | x509_buf subject_raw; |
| 164 | |
| 165 | x509_name issuer; |
| 166 | x509_name subject; |
| 167 | |
| 168 | x509_time valid_from; |
| 169 | x509_time valid_to; |
| 170 | |
| 171 | x509_buf pk_oid; |
| 172 | rsa_context rsa; |
| 173 | |
| 174 | x509_buf issuer_id; |
| 175 | x509_buf subject_id; |
| 176 | x509_buf v3_ext; |
| 177 | |
| 178 | int ca_istrue; |
| 179 | int max_pathlen; |
| 180 | |
| 181 | x509_buf sig_oid2; |
| 182 | x509_buf sig; |
Paul Bakker | 27d6616 | 2010-03-17 06:56:01 +0000 | [diff] [blame^] | 183 | int sig_alg; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 184 | |
| 185 | struct _x509_cert *next; |
| 186 | } |
| 187 | x509_cert; |
| 188 | |
Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 189 | typedef struct _x509_crl_entry |
| 190 | { |
| 191 | x509_buf raw; |
| 192 | |
| 193 | x509_buf serial; |
| 194 | |
| 195 | x509_time revocation_date; |
| 196 | |
| 197 | x509_buf entry_ext; |
| 198 | |
| 199 | struct _x509_crl_entry *next; |
| 200 | } |
| 201 | x509_crl_entry; |
| 202 | |
| 203 | typedef struct _x509_crl |
| 204 | { |
| 205 | x509_buf raw; |
| 206 | x509_buf tbs; |
| 207 | |
| 208 | int version; |
| 209 | x509_buf sig_oid1; |
| 210 | |
| 211 | x509_buf issuer_raw; |
| 212 | |
| 213 | x509_name issuer; |
| 214 | |
| 215 | x509_time this_update; |
| 216 | x509_time next_update; |
| 217 | |
| 218 | x509_crl_entry entry; |
| 219 | |
| 220 | x509_buf crl_ext; |
| 221 | |
| 222 | x509_buf sig_oid2; |
| 223 | x509_buf sig; |
Paul Bakker | 27d6616 | 2010-03-17 06:56:01 +0000 | [diff] [blame^] | 224 | int sig_alg; |
Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 225 | |
| 226 | struct _x509_crl *next; |
| 227 | } |
| 228 | x509_crl; |
| 229 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 230 | /* |
| 231 | * Structures for writing X.509 certificates |
| 232 | */ |
| 233 | typedef struct _x509_node |
| 234 | { |
| 235 | unsigned char *data; |
| 236 | unsigned char *p; |
| 237 | unsigned char *end; |
| 238 | |
| 239 | size_t len; |
| 240 | } |
| 241 | x509_node; |
| 242 | |
| 243 | typedef struct _x509_raw |
| 244 | { |
| 245 | x509_node raw; |
| 246 | x509_node tbs; |
| 247 | |
| 248 | x509_node version; |
| 249 | x509_node serial; |
| 250 | x509_node tbs_signalg; |
| 251 | x509_node issuer; |
| 252 | x509_node validity; |
| 253 | x509_node subject; |
| 254 | x509_node subpubkey; |
| 255 | |
| 256 | x509_node signalg; |
| 257 | x509_node sign; |
| 258 | } |
| 259 | x509_raw; |
| 260 | |
| 261 | #ifdef __cplusplus |
| 262 | extern "C" { |
| 263 | #endif |
| 264 | |
| 265 | /** |
| 266 | * \brief Parse one or more certificates and add them |
| 267 | * to the chained list |
| 268 | * |
| 269 | * \param chain points to the start of the chain |
| 270 | * \param buf buffer holding the certificate data |
| 271 | * \param buflen size of the buffer |
| 272 | * |
| 273 | * \return 0 if successful, or a specific X509 error code |
| 274 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 275 | int x509parse_crt( x509_cert *chain, const unsigned char *buf, int buflen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * \brief Load one or more certificates and add them |
| 279 | * to the chained list |
| 280 | * |
| 281 | * \param chain points to the start of the chain |
| 282 | * \param path filename to read the certificates from |
| 283 | * |
| 284 | * \return 0 if successful, or a specific X509 error code |
| 285 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 286 | int x509parse_crtfile( x509_cert *chain, const char *path ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 287 | |
| 288 | /** |
Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 289 | * \brief Parse one or more CRLs and add them |
| 290 | * to the chained list |
| 291 | * |
| 292 | * \param chain points to the start of the chain |
| 293 | * \param buf buffer holding the CRL data |
| 294 | * \param buflen size of the buffer |
| 295 | * |
| 296 | * \return 0 if successful, or a specific X509 error code |
| 297 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 298 | int x509parse_crl( x509_crl *chain, const unsigned char *buf, int buflen ); |
Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 299 | |
| 300 | /** |
| 301 | * \brief Load one or more CRLs and add them |
| 302 | * to the chained list |
| 303 | * |
| 304 | * \param chain points to the start of the chain |
| 305 | * \param path filename to read the CRLs from |
| 306 | * |
| 307 | * \return 0 if successful, or a specific X509 error code |
| 308 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 309 | int x509parse_crlfile( x509_crl *chain, const char *path ); |
Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 310 | |
| 311 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 312 | * \brief Parse a private RSA key |
| 313 | * |
| 314 | * \param rsa RSA context to be initialized |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 315 | * \param key input buffer |
| 316 | * \param keylen size of the buffer |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 317 | * \param pwd password for decryption (optional) |
| 318 | * \param pwdlen size of the password |
| 319 | * |
| 320 | * \return 0 if successful, or a specific X509 error code |
| 321 | */ |
| 322 | int x509parse_key( rsa_context *rsa, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 323 | const unsigned char *key, int keylen, |
| 324 | const unsigned char *pwd, int pwdlen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 325 | |
| 326 | /** |
| 327 | * \brief Load and parse a private RSA key |
| 328 | * |
| 329 | * \param rsa RSA context to be initialized |
| 330 | * \param path filename to read the private key from |
| 331 | * \param pwd password to decrypt the file (can be NULL) |
| 332 | * |
| 333 | * \return 0 if successful, or a specific X509 error code |
| 334 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 335 | int x509parse_keyfile( rsa_context *rsa, const char *path, |
| 336 | const char *password ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 337 | |
| 338 | /** |
| 339 | * \brief Store the certificate DN in printable form into buf; |
Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 340 | * no more than size characters will be written. |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 341 | * |
| 342 | * \param buf Buffer to write to |
| 343 | * \param size Maximum size of buffer |
| 344 | * \param dn The X509 name to represent |
| 345 | * |
| 346 | * \return The amount of data written to the buffer, or -1 in |
| 347 | * case of an error. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 348 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 349 | int x509parse_dn_gets( char *buf, size_t size, const x509_name *dn ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 350 | |
| 351 | /** |
| 352 | * \brief Returns an informational string about the |
| 353 | * certificate. |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 354 | * |
| 355 | * \param buf Buffer to write to |
| 356 | * \param size Maximum size of buffer |
| 357 | * \param prefix A line prefix |
| 358 | * \param crt The X509 certificate to represent |
| 359 | * |
| 360 | * \return The amount of data written to the buffer, or -1 in |
| 361 | * case of an error. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 362 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 363 | int x509parse_cert_info( char *buf, size_t size, const char *prefix, |
| 364 | const x509_cert *crt ); |
Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 365 | |
| 366 | /** |
| 367 | * \brief Returns an informational string about the |
| 368 | * CRL. |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 369 | * |
| 370 | * \param buf Buffer to write to |
| 371 | * \param size Maximum size of buffer |
| 372 | * \param prefix A line prefix |
| 373 | * \param crt The X509 CRL to represent |
| 374 | * |
| 375 | * \return The amount of data written to the buffer, or -1 in |
| 376 | * case of an error. |
Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 377 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 378 | int x509parse_crl_info( char *buf, size_t size, const char *prefix, |
| 379 | const x509_crl *crl ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 380 | |
| 381 | /** |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 382 | * \brief Check a given x509_time against the system time and check |
| 383 | * if it is valid. |
| 384 | * |
| 385 | * \param time x509_time to check |
| 386 | * |
| 387 | * \return Return 0 if the x509_time is still valid, |
Paul Bakker | 40ea7de | 2009-05-03 10:18:48 +0000 | [diff] [blame] | 388 | * or 1 otherwise. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 389 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 390 | int x509parse_time_expired( const x509_time *time ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 391 | |
| 392 | /** |
| 393 | * \brief Verify the certificate signature |
| 394 | * |
| 395 | * \param crt a certificate to be verified |
| 396 | * \param trust_ca the trusted CA chain |
Paul Bakker | 40ea7de | 2009-05-03 10:18:48 +0000 | [diff] [blame] | 397 | * \param ca_crl the CRL chain for trusted CA's |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 398 | * \param cn expected Common Name (can be set to |
| 399 | * NULL if the CN must not be verified) |
| 400 | * \param flags result of the verification |
| 401 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 402 | * \return 0 if successful or POLARSSL_ERR_X509_SIG_VERIFY_FAILED, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 403 | * in which case *flags will have one or more of |
| 404 | * the following values set: |
| 405 | * BADCERT_EXPIRED -- |
| 406 | * BADCERT_REVOKED -- |
| 407 | * BADCERT_CN_MISMATCH -- |
| 408 | * BADCERT_NOT_TRUSTED |
| 409 | * |
| 410 | * \note TODO: add two arguments, depth and crl |
| 411 | */ |
| 412 | int x509parse_verify( x509_cert *crt, |
| 413 | x509_cert *trust_ca, |
Paul Bakker | 40ea7de | 2009-05-03 10:18:48 +0000 | [diff] [blame] | 414 | x509_crl *ca_crl, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 415 | const char *cn, int *flags ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 416 | |
| 417 | /** |
| 418 | * \brief Unallocate all certificate data |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 419 | * |
| 420 | * \param crt Certificate chain to free |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 421 | */ |
| 422 | void x509_free( x509_cert *crt ); |
| 423 | |
| 424 | /** |
Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 425 | * \brief Unallocate all CRL data |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 426 | * |
| 427 | * \param crt CRL chain to free |
Paul Bakker | d98030e | 2009-05-02 15:13:40 +0000 | [diff] [blame] | 428 | */ |
| 429 | void x509_crl_free( x509_crl *crl ); |
| 430 | |
| 431 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 432 | * \brief Checkup routine |
| 433 | * |
| 434 | * \return 0 if successful, or 1 if the test failed |
| 435 | */ |
| 436 | int x509_self_test( int verbose ); |
| 437 | |
| 438 | #ifdef __cplusplus |
| 439 | } |
| 440 | #endif |
| 441 | |
| 442 | #endif /* x509.h */ |