PolarSSL v1.3.2
x509.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_X509_H
28 #define POLARSSL_X509_H
29 
30 #include "config.h"
31 
32 #include "asn1.h"
33 #include "pk.h"
34 
35 #if defined(POLARSSL_RSA_C)
36 #include "rsa.h"
37 #endif
38 
48 #define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE -0x2080
49 #define POLARSSL_ERR_X509_UNKNOWN_OID -0x2100
50 #define POLARSSL_ERR_X509_INVALID_FORMAT -0x2180
51 #define POLARSSL_ERR_X509_INVALID_VERSION -0x2200
52 #define POLARSSL_ERR_X509_INVALID_SERIAL -0x2280
53 #define POLARSSL_ERR_X509_INVALID_ALG -0x2300
54 #define POLARSSL_ERR_X509_INVALID_NAME -0x2380
55 #define POLARSSL_ERR_X509_INVALID_DATE -0x2400
56 #define POLARSSL_ERR_X509_INVALID_SIGNATURE -0x2480
57 #define POLARSSL_ERR_X509_INVALID_EXTENSIONS -0x2500
58 #define POLARSSL_ERR_X509_UNKNOWN_VERSION -0x2580
59 #define POLARSSL_ERR_X509_UNKNOWN_SIG_ALG -0x2600
60 #define POLARSSL_ERR_X509_SIG_MISMATCH -0x2680
61 #define POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x2700
62 #define POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780
63 #define POLARSSL_ERR_X509_BAD_INPUT_DATA -0x2800
64 #define POLARSSL_ERR_X509_MALLOC_FAILED -0x2880
65 #define POLARSSL_ERR_X509_FILE_IO_ERROR -0x2900
66 /* \} name */
67 
72 #define BADCERT_EXPIRED 0x01
73 #define BADCERT_REVOKED 0x02
74 #define BADCERT_CN_MISMATCH 0x04
75 #define BADCERT_NOT_TRUSTED 0x08
76 #define BADCRL_NOT_TRUSTED 0x10
77 #define BADCRL_EXPIRED 0x20
78 #define BADCERT_MISSING 0x40
79 #define BADCERT_SKIP_VERIFY 0x80
80 #define BADCERT_OTHER 0x0100
81 /* \} name */
82 /* \} addtogroup x509_module */
83 
84 /*
85  * X.509 v3 Key Usage Extension flags
86  */
87 #define KU_DIGITAL_SIGNATURE (0x80) /* bit 0 */
88 #define KU_NON_REPUDIATION (0x40) /* bit 1 */
89 #define KU_KEY_ENCIPHERMENT (0x20) /* bit 2 */
90 #define KU_DATA_ENCIPHERMENT (0x10) /* bit 3 */
91 #define KU_KEY_AGREEMENT (0x08) /* bit 4 */
92 #define KU_KEY_CERT_SIGN (0x04) /* bit 5 */
93 #define KU_CRL_SIGN (0x02) /* bit 6 */
94 
95 /*
96  * Netscape certificate types
97  * (http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn3.html)
98  */
99 
100 #define NS_CERT_TYPE_SSL_CLIENT (0x80) /* bit 0 */
101 #define NS_CERT_TYPE_SSL_SERVER (0x40) /* bit 1 */
102 #define NS_CERT_TYPE_EMAIL (0x20) /* bit 2 */
103 #define NS_CERT_TYPE_OBJECT_SIGNING (0x10) /* bit 3 */
104 #define NS_CERT_TYPE_RESERVED (0x08) /* bit 4 */
105 #define NS_CERT_TYPE_SSL_CA (0x04) /* bit 5 */
106 #define NS_CERT_TYPE_EMAIL_CA (0x02) /* bit 6 */
107 #define NS_CERT_TYPE_OBJECT_SIGNING_CA (0x01) /* bit 7 */
108 
109 /*
110  * X.509 extension types
111  */
112 #define EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0)
113 #define EXT_SUBJECT_KEY_IDENTIFIER (1 << 1)
114 #define EXT_KEY_USAGE (1 << 2)
115 #define EXT_CERTIFICATE_POLICIES (1 << 3)
116 #define EXT_POLICY_MAPPINGS (1 << 4)
117 #define EXT_SUBJECT_ALT_NAME (1 << 5)
118 #define EXT_ISSUER_ALT_NAME (1 << 6)
119 #define EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7)
120 #define EXT_BASIC_CONSTRAINTS (1 << 8)
121 #define EXT_NAME_CONSTRAINTS (1 << 9)
122 #define EXT_POLICY_CONSTRAINTS (1 << 10)
123 #define EXT_EXTENDED_KEY_USAGE (1 << 11)
124 #define EXT_CRL_DISTRIBUTION_POINTS (1 << 12)
125 #define EXT_INIHIBIT_ANYPOLICY (1 << 13)
126 #define EXT_FRESHEST_CRL (1 << 14)
127 
128 #define EXT_NS_CERT_TYPE (1 << 16)
129 
130 /*
131  * Storage format identifiers
132  * Recognized formats: PEM and DER
133  */
134 #define X509_FORMAT_DER 1
135 #define X509_FORMAT_PEM 2
136 
137 #ifdef __cplusplus
138 extern "C" {
139 #endif
140 
154 
159 
165 
170 
172 typedef struct _x509_time
173 {
174  int year, mon, day;
175  int hour, min, sec;
176 }
177 x509_time;
178 
193 int x509_dn_gets( char *buf, size_t size, const x509_name *dn );
194 
206 int x509_serial_gets( char *buf, size_t size, const x509_buf *serial );
207 
216 const char *x509_oid_get_description( x509_buf *oid );
217 
229 int x509_oid_get_numeric_string( char *buf, size_t size, x509_buf *oid );
230 
240 int x509_time_expired( const x509_time *time );
241 
247 int x509_self_test( int verbose );
248 
249 /*
250  * Internal module functions. You probably do not want to use these unless you
251  * know you do.
252  */
253 int x509_get_name( unsigned char **p, const unsigned char *end,
254  x509_name *cur );
255 int x509_get_alg_null( unsigned char **p, const unsigned char *end,
256  x509_buf *alg );
257 int x509_get_sig( unsigned char **p, const unsigned char *end, x509_buf *sig );
258 int x509_get_sig_alg( const x509_buf *sig_oid, md_type_t *md_alg,
259  pk_type_t *pk_alg );
260 int x509_get_time( unsigned char **p, const unsigned char *end,
261  x509_time *time );
262 int x509_get_serial( unsigned char **p, const unsigned char *end,
263  x509_buf *serial );
264 int x509_get_ext( unsigned char **p, const unsigned char *end,
265  x509_buf *ext, int tag );
266 int x509_load_file( const char *path, unsigned char **buf, size_t *n );
267 int x509_key_size_helper( char *buf, size_t size, const char *name );
268 int x509_string_to_names( asn1_named_data **head, const char *name );
269 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 );
270 int x509_write_extensions( unsigned char **p, unsigned char *start,
271  asn1_named_data *first );
272 int x509_write_names( unsigned char **p, unsigned char *start,
273  asn1_named_data *first );
274 int x509_write_sig( unsigned char **p, unsigned char *start,
275  const char *oid, size_t oid_len,
276  unsigned char *sig, size_t size );
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 
282 #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 valid.
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:175
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:172
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:127
Public Key abstraction layer.
asn1_named_data x509_name
Container for ASN1 named information objects.
Definition: x509.h:164
md_type_t
Definition: md.h:51
int hour
Definition: x509.h:175
int mon
Definition: x509.h:174
Container for a sequence of ASN.1 items.
Definition: asn1.h:138
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:174
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:90
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:148
Type-length-value structure that allows for ASN1 using DER.
Definition: asn1.h:116
The RSA public-key cryptosystem.
int year
Definition: x509.h:174
int x509_get_ext(unsigned char **p, const unsigned char *end, x509_buf *ext, int tag)
int min
Definition: x509.h:175
int x509_write_sig(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len, unsigned char *sig, size_t size)
asn1_buf x509_buf
Type-length-value structure that allows for ASN1 using DER.
Definition: x509.h:153
int x509_self_test(int verbose)
Checkup routine.
asn1_sequence x509_sequence
Container for a sequence of ASN.1 items.
Definition: x509.h:169
asn1_bitstring x509_bitstring
Container for ASN1 bit strings.
Definition: x509.h:158
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...