wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
x509v3.h
Go to the documentation of this file.
1 
5 #ifndef X509V3_H
6 #define X509V3_H
7 
8 #include "asn1.h"
9 
11  struct asn1_oid oid;
12 };
13 
15  enum x509_name_attr_type {
16  X509_NAME_ATTR_NOT_USED,
17  X509_NAME_ATTR_DC,
18  X509_NAME_ATTR_CN,
19  X509_NAME_ATTR_C,
20  X509_NAME_ATTR_L,
21  X509_NAME_ATTR_ST,
22  X509_NAME_ATTR_O,
23  X509_NAME_ATTR_OU
24  } type;
25  char *value;
26 };
27 
28 #define X509_MAX_NAME_ATTRIBUTES 20
29 
30 struct x509_name {
31  struct x509_name_attr attr[X509_MAX_NAME_ATTRIBUTES];
32  size_t num_attr;
33  char *email; /* emailAddress */
34 
35  /* from alternative name extension */
36  char *alt_email; /* rfc822Name */
37  char *dns; /* dNSName */
38  char *uri; /* uniformResourceIdentifier */
39  u8 *ip; /* iPAddress */
40  size_t ip_len; /* IPv4: 4, IPv6: 16 */
41  struct asn1_oid rid; /* registeredID */
42 };
43 
45  struct x509_certificate *next;
46  enum { X509_CERT_V1 = 0, X509_CERT_V2 = 1, X509_CERT_V3 = 2 } version;
47  unsigned long serial_number;
48  struct x509_algorithm_identifier signature;
49  struct x509_name issuer;
50  struct x509_name subject;
51  os_time_t not_before;
52  os_time_t not_after;
53  struct x509_algorithm_identifier public_key_alg;
54  u8 *public_key;
55  size_t public_key_len;
56  struct x509_algorithm_identifier signature_alg;
57  u8 *sign_value;
58  size_t sign_value_len;
59 
60  /* Extensions */
61  unsigned int extensions_present;
62 #define X509_EXT_BASIC_CONSTRAINTS (1 << 0)
63 #define X509_EXT_PATH_LEN_CONSTRAINT (1 << 1)
64 #define X509_EXT_KEY_USAGE (1 << 2)
65 #define X509_EXT_SUBJECT_ALT_NAME (1 << 3)
66 #define X509_EXT_ISSUER_ALT_NAME (1 << 4)
67 
68  /* BasicConstraints */
69  int ca; /* cA */
70  unsigned long path_len_constraint; /* pathLenConstraint */
71 
72  /* KeyUsage */
73  unsigned long key_usage;
74 #define X509_KEY_USAGE_DIGITAL_SIGNATURE (1 << 0)
75 #define X509_KEY_USAGE_NON_REPUDIATION (1 << 1)
76 #define X509_KEY_USAGE_KEY_ENCIPHERMENT (1 << 2)
77 #define X509_KEY_USAGE_DATA_ENCIPHERMENT (1 << 3)
78 #define X509_KEY_USAGE_KEY_AGREEMENT (1 << 4)
79 #define X509_KEY_USAGE_KEY_CERT_SIGN (1 << 5)
80 #define X509_KEY_USAGE_CRL_SIGN (1 << 6)
81 #define X509_KEY_USAGE_ENCIPHER_ONLY (1 << 7)
82 #define X509_KEY_USAGE_DECIPHER_ONLY (1 << 8)
83 
84  /*
85  * The DER format certificate follows struct x509_certificate. These
86  * pointers point to that buffer.
87  */
88  const u8 *cert_start;
89  size_t cert_len;
90  const u8 *tbs_cert_start;
91  size_t tbs_cert_len;
92 };
93 
94 enum {
95  X509_VALIDATE_OK,
96  X509_VALIDATE_BAD_CERTIFICATE,
97  X509_VALIDATE_UNSUPPORTED_CERTIFICATE,
98  X509_VALIDATE_CERTIFICATE_REVOKED,
99  X509_VALIDATE_CERTIFICATE_EXPIRED,
100  X509_VALIDATE_CERTIFICATE_UNKNOWN,
101  X509_VALIDATE_UNKNOWN_CA
102 };
103 
104 void x509_certificate_free(struct x509_certificate *cert);
105 struct x509_certificate * x509_certificate_parse(const u8 *buf, size_t len);
106 void x509_name_string(struct x509_name *name, char *buf, size_t len);
107 int x509_name_compare(struct x509_name *a, struct x509_name *b);
110  struct x509_certificate *cert);
112  struct x509_certificate *chain,
113  int *reason, int disable_time_checks);
114 struct x509_certificate *
116  struct x509_name *name);
118 
119 #endif /* X509V3_H */
struct x509_certificate * x509_certificate_parse(const u8 *buf, size_t len)
Parse a X.509 certificate in DER format.
Definition: x509v3.c:1472
Definition: x509v3.h:30
void x509_name_string(struct x509_name *name, char *buf, size_t len)
Convert an X.509 certificate name into a string.
Definition: x509v3.c:495
int x509_certificate_check_signature(struct x509_certificate *issuer, struct x509_certificate *cert)
Verify certificate signature.
Definition: x509v3.c:1578
Definition: asn1.h:49
ASN.1 DER parsing.
Definition: x509v3.h:44
Definition: x509v3.h:10
void x509_certificate_chain_free(struct x509_certificate *cert)
Free an X.509 certificate chain.
Definition: x509v3.c:62
void x509_certificate_free(struct x509_certificate *cert)
Free an X.509 certificate.
Definition: x509v3.c:41
Definition: x509v3.h:14
int x509_certificate_self_signed(struct x509_certificate *cert)
Is the certificate self-signed?
Definition: x509v3.c:1983
int x509_name_compare(struct x509_name *a, struct x509_name *b)
Compare X.509 certificate names.
Definition: x509v3.c:143
int x509_certificate_chain_validate(struct x509_certificate *trusted, struct x509_certificate *chain, int *reason, int disable_time_checks)
Validate X.509 certificate chain.
Definition: x509v3.c:1835
struct x509_certificate * x509_certificate_get_subject(struct x509_certificate *chain, struct x509_name *name)
Get a certificate based on Subject name.
Definition: x509v3.c:1965