PolarSSL v1.3.7
x509.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_X509_H
28 #define POLARSSL_X509_H
29 
30 #if !defined(POLARSSL_CONFIG_FILE)
31 #include "config.h"
32 #else
33 #include POLARSSL_CONFIG_FILE
34 #endif
35 
36 #include "asn1.h"
37 #include "pk.h"
38 
39 #if defined(POLARSSL_RSA_C)
40 #include "rsa.h"
41 #endif
42 
52 #define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE -0x2080
53 #define POLARSSL_ERR_X509_UNKNOWN_OID -0x2100
54 #define POLARSSL_ERR_X509_INVALID_FORMAT -0x2180
55 #define POLARSSL_ERR_X509_INVALID_VERSION -0x2200
56 #define POLARSSL_ERR_X509_INVALID_SERIAL -0x2280
57 #define POLARSSL_ERR_X509_INVALID_ALG -0x2300
58 #define POLARSSL_ERR_X509_INVALID_NAME -0x2380
59 #define POLARSSL_ERR_X509_INVALID_DATE -0x2400
60 #define POLARSSL_ERR_X509_INVALID_SIGNATURE -0x2480
61 #define POLARSSL_ERR_X509_INVALID_EXTENSIONS -0x2500
62 #define POLARSSL_ERR_X509_UNKNOWN_VERSION -0x2580
63 #define POLARSSL_ERR_X509_UNKNOWN_SIG_ALG -0x2600
64 #define POLARSSL_ERR_X509_SIG_MISMATCH -0x2680
65 #define POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x2700
66 #define POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780
67 #define POLARSSL_ERR_X509_BAD_INPUT_DATA -0x2800
68 #define POLARSSL_ERR_X509_MALLOC_FAILED -0x2880
69 #define POLARSSL_ERR_X509_FILE_IO_ERROR -0x2900
70 /* \} name */
71 
76 #define BADCERT_EXPIRED 0x01
77 #define BADCERT_REVOKED 0x02
78 #define BADCERT_CN_MISMATCH 0x04
79 #define BADCERT_NOT_TRUSTED 0x08
80 #define BADCRL_NOT_TRUSTED 0x10
81 #define BADCRL_EXPIRED 0x20
82 #define BADCERT_MISSING 0x40
83 #define BADCERT_SKIP_VERIFY 0x80
84 #define BADCERT_OTHER 0x0100
85 #define BADCERT_FUTURE 0x0200
86 #define BADCRL_FUTURE 0x0400
87 /* \} name */
88 /* \} addtogroup x509_module */
89 
90 /*
91  * X.509 v3 Key Usage Extension flags
92  */
93 #define KU_DIGITAL_SIGNATURE (0x80) /* bit 0 */
94 #define KU_NON_REPUDIATION (0x40) /* bit 1 */
95 #define KU_KEY_ENCIPHERMENT (0x20) /* bit 2 */
96 #define KU_DATA_ENCIPHERMENT (0x10) /* bit 3 */
97 #define KU_KEY_AGREEMENT (0x08) /* bit 4 */
98 #define KU_KEY_CERT_SIGN (0x04) /* bit 5 */
99 #define KU_CRL_SIGN (0x02) /* bit 6 */
100 
101 /*
102  * Netscape certificate types
103  * (http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn3.html)
104  */
105 
106 #define NS_CERT_TYPE_SSL_CLIENT (0x80) /* bit 0 */
107 #define NS_CERT_TYPE_SSL_SERVER (0x40) /* bit 1 */
108 #define NS_CERT_TYPE_EMAIL (0x20) /* bit 2 */
109 #define NS_CERT_TYPE_OBJECT_SIGNING (0x10) /* bit 3 */
110 #define NS_CERT_TYPE_RESERVED (0x08) /* bit 4 */
111 #define NS_CERT_TYPE_SSL_CA (0x04) /* bit 5 */
112 #define NS_CERT_TYPE_EMAIL_CA (0x02) /* bit 6 */
113 #define NS_CERT_TYPE_OBJECT_SIGNING_CA (0x01) /* bit 7 */
114 
115 /*
116  * X.509 extension types
117  *
118  * Comments refer to the status for using certificates. Status can be
119  * different for writing certificates or reading CRLs or CSRs.
120  */
121 #define EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0)
122 #define EXT_SUBJECT_KEY_IDENTIFIER (1 << 1)
123 #define EXT_KEY_USAGE (1 << 2) /* Parsed but not used */
124 #define EXT_CERTIFICATE_POLICIES (1 << 3)
125 #define EXT_POLICY_MAPPINGS (1 << 4)
126 #define EXT_SUBJECT_ALT_NAME (1 << 5) /* Supported (DNS) */
127 #define EXT_ISSUER_ALT_NAME (1 << 6)
128 #define EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7)
129 #define EXT_BASIC_CONSTRAINTS (1 << 8) /* Supported */
130 #define EXT_NAME_CONSTRAINTS (1 << 9)
131 #define EXT_POLICY_CONSTRAINTS (1 << 10)
132 #define EXT_EXTENDED_KEY_USAGE (1 << 11) /* Parsed but not used */
133 #define EXT_CRL_DISTRIBUTION_POINTS (1 << 12)
134 #define EXT_INIHIBIT_ANYPOLICY (1 << 13)
135 #define EXT_FRESHEST_CRL (1 << 14)
136 
137 #define EXT_NS_CERT_TYPE (1 << 16) /* Parsed (and then ?) */
138 
139 /*
140  * Storage format identifiers
141  * Recognized formats: PEM and DER
142  */
143 #define X509_FORMAT_DER 1
144 #define X509_FORMAT_PEM 2
145 
146 #ifdef __cplusplus
147 extern "C" {
148 #endif
149 
163 
168 
174 
179 
181 typedef struct _x509_time
182 {
183  int year, mon, day;
184  int hour, min, sec;
185 }
186 x509_time;
187 
202 int x509_dn_gets( char *buf, size_t size, const x509_name *dn );
203 
215 int x509_serial_gets( char *buf, size_t size, const x509_buf *serial );
216 
227 const char *x509_oid_get_description( x509_buf *oid );
228 
240 int x509_oid_get_numeric_string( char *buf, size_t size, x509_buf *oid );
241 
251 int x509_time_expired( const x509_time *time );
252 
262 int x509_time_future( const x509_time *time );
263 
269 int x509_self_test( int verbose );
270 
271 /*
272  * Internal module functions. You probably do not want to use these unless you
273  * know you do.
274  */
275 int x509_get_name( unsigned char **p, const unsigned char *end,
276  x509_name *cur );
277 int x509_get_alg_null( unsigned char **p, const unsigned char *end,
278  x509_buf *alg );
279 int x509_get_sig( unsigned char **p, const unsigned char *end, x509_buf *sig );
280 int x509_get_sig_alg( const x509_buf *sig_oid, md_type_t *md_alg,
281  pk_type_t *pk_alg );
282 int x509_get_time( unsigned char **p, const unsigned char *end,
283  x509_time *time );
284 int x509_get_serial( unsigned char **p, const unsigned char *end,
285  x509_buf *serial );
286 int x509_get_ext( unsigned char **p, const unsigned char *end,
287  x509_buf *ext, int tag );
288 int x509_load_file( const char *path, unsigned char **buf, size_t *n );
289 int x509_key_size_helper( char *buf, size_t size, const char *name );
290 int x509_string_to_names( asn1_named_data **head, const char *name );
291 int x509_set_extension( asn1_named_data **head, const char *oid, size_t oid_len,
292  int critical, const unsigned char *val,
293  size_t val_len );
294 int x509_write_extensions( unsigned char **p, unsigned char *start,
295  asn1_named_data *first );
296 int x509_write_names( unsigned char **p, unsigned char *start,
297  asn1_named_data *first );
298 int x509_write_sig( unsigned char **p, unsigned char *start,
299  const char *oid, size_t oid_len,
300  unsigned char *sig, size_t size );
301 
302 #ifdef __cplusplus
303 }
304 #endif
305 
306 #endif /* x509.h */
int x509_time_expired(const x509_time *time)
Check a given x509_time against the system time and check if it is not expired.
int x509_set_extension(asn1_named_data **head, const char *oid, size_t oid_len, int critical, const unsigned char *val, size_t val_len)
int x509_string_to_names(asn1_named_data **head, const char *name)
struct _x509_time x509_time
Container for date and time (precision in seconds).
int sec
Time.
Definition: x509.h:184
int x509_get_name(unsigned char **p, const unsigned char *end, x509_name *cur)
int x509_get_serial(unsigned char **p, const unsigned char *end, x509_buf *serial)
int x509_key_size_helper(char *buf, size_t size, const char *name)
const char * x509_oid_get_description(x509_buf *oid)
Give an known OID, return its descriptive string.
int x509_get_alg_null(unsigned char **p, const unsigned char *end, x509_buf *alg)
Container for date and time (precision in seconds).
Definition: x509.h:181
Configuration options (set of defines)
int x509_get_sig(unsigned char **p, const unsigned char *end, x509_buf *sig)
Container for ASN1 bit strings.
Definition: asn1.h:131
Public Key abstraction layer.
asn1_named_data x509_name
Container for ASN1 named information objects.
Definition: x509.h:173
md_type_t
Definition: md.h:51
int hour
Definition: x509.h:184
int mon
Definition: x509.h:183
Container for a sequence of ASN.1 items.
Definition: asn1.h:142
int x509_write_names(unsigned char **p, unsigned char *start, asn1_named_data *first)
int x509_get_time(unsigned char **p, const unsigned char *end, x509_time *time)
Generic ASN.1 parsing.
int x509_dn_gets(char *buf, size_t size, const x509_name *dn)
Store the certificate DN in printable form into buf; no more than size characters will be written...
int x509_write_extensions(unsigned char **p, unsigned char *start, asn1_named_data *first)
int x509_oid_get_numeric_string(char *buf, size_t size, x509_buf *oid)
Give an OID, return a string version of its OID number.
int day
Date.
Definition: x509.h:183
int x509_get_sig_alg(const x509_buf *sig_oid, md_type_t *md_alg, pk_type_t *pk_alg)
pk_type_t
Public key types.
Definition: pk.h:95
int x509_load_file(const char *path, unsigned char **buf, size_t *n)
Container for a sequence or list of &#39;named&#39; ASN.1 data items.
Definition: asn1.h:152
Type-length-value structure that allows for ASN1 using DER.
Definition: asn1.h:120
The RSA public-key cryptosystem.
int year
Definition: x509.h:183
int x509_get_ext(unsigned char **p, const unsigned char *end, x509_buf *ext, int tag)
int min
Definition: x509.h:184
int x509_write_sig(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len, unsigned char *sig, size_t size)
int x509_time_future(const x509_time *time)
Check a given x509_time against the system time and check if it is not from the future.
asn1_buf x509_buf
Type-length-value structure that allows for ASN1 using DER.
Definition: x509.h:162
int x509_self_test(int verbose)
Checkup routine.
asn1_sequence x509_sequence
Container for a sequence of ASN.1 items.
Definition: x509.h:178
asn1_bitstring x509_bitstring
Container for ASN1 bit strings.
Definition: x509.h:167
int x509_serial_gets(char *buf, size_t size, const x509_buf *serial)
Store the certificate serial in printable form into buf; no more than size characters will be written...