123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- #ifndef _IPXE_X509_H
- #define _IPXE_X509_H
-
-
-
- FILE_LICENCE ( GPL2_OR_LATER );
-
- #include <stdint.h>
- #include <stddef.h>
- #include <time.h>
- #include <ipxe/asn1.h>
- #include <ipxe/refcnt.h>
- #include <ipxe/list.h>
-
-
- struct x509_serial {
-
- struct asn1_cursor raw;
- };
-
-
- struct x509_issuer {
-
- struct asn1_cursor raw;
- };
-
-
- struct x509_time {
-
- time_t time;
- };
-
-
- struct x509_validity {
-
- struct x509_time not_before;
-
- struct x509_time not_after;
- };
-
-
- struct x509_public_key {
-
- struct asn1_cursor raw;
-
- struct asn1_algorithm *algorithm;
-
- struct asn1_bit_string raw_bits;
- };
-
-
- struct x509_subject {
-
- struct asn1_cursor raw;
-
- char *name;
-
- struct x509_public_key public_key;
- };
-
-
- struct x509_signature {
-
- struct asn1_algorithm *algorithm;
-
- struct asn1_bit_string value;
- };
-
-
- struct x509_basic_constraints {
-
- int ca;
-
- unsigned int path_len;
- };
-
-
- #define X509_PATH_LEN_UNLIMITED -2U
-
-
- struct x509_key_usage {
-
- int present;
-
- unsigned int bits;
- };
-
-
- enum x509_key_usage_bits {
- X509_DIGITAL_SIGNATURE = 0x0080,
- X509_NON_REPUDIATION = 0x0040,
- X509_KEY_ENCIPHERMENT = 0x0020,
- X509_DATA_ENCIPHERMENT = 0x0010,
- X509_KEY_AGREEMENT = 0x0008,
- X509_KEY_CERT_SIGN = 0x0004,
- X509_CRL_SIGN = 0x0002,
- X509_ENCIPHER_ONLY = 0x0001,
- X509_DECIPHER_ONLY = 0x8000,
- };
-
-
- struct x509_extended_key_usage {
-
- unsigned int bits;
- };
-
-
- enum x509_extended_key_usage_bits {
- X509_CODE_SIGNING = 0x0001,
- X509_OCSP_SIGNING = 0x0002,
- };
-
-
- struct x509_ocsp_responder {
-
- char *uri;
- };
-
-
- struct x509_authority_info_access {
-
- struct x509_ocsp_responder ocsp;
- };
-
-
- struct x509_extensions {
-
- struct x509_basic_constraints basic;
-
- struct x509_key_usage usage;
-
- struct x509_extended_key_usage ext_usage;
-
- struct x509_authority_info_access auth_info;
- };
-
-
- struct x509_certificate {
-
- struct refcnt refcnt;
-
- struct list_head list;
-
-
- int valid;
-
- unsigned int path_remaining;
-
-
- struct asn1_cursor raw;
-
- unsigned int version;
-
- struct x509_serial serial;
-
- struct asn1_cursor tbs;
-
- struct asn1_algorithm *signature_algorithm;
-
- struct x509_issuer issuer;
-
- struct x509_validity validity;
-
- struct x509_subject subject;
-
- struct x509_signature signature;
-
- struct x509_extensions extensions;
- };
-
-
- static inline __attribute__ (( always_inline )) struct x509_certificate *
- x509_get ( struct x509_certificate *cert ) {
- ref_get ( &cert->refcnt );
- return cert;
- }
-
-
- static inline __attribute__ (( always_inline )) void
- x509_put ( struct x509_certificate *cert ) {
- ref_put ( &cert->refcnt );
- }
-
-
- struct x509_link {
-
- struct list_head list;
-
- struct x509_certificate *cert;
- };
-
-
- struct x509_chain {
-
- struct refcnt refcnt;
-
- struct list_head links;
- };
-
-
- static inline __attribute__ (( always_inline )) struct x509_chain *
- x509_chain_get ( struct x509_chain *chain ) {
- ref_get ( &chain->refcnt );
- return chain;
- }
-
-
- static inline __attribute__ (( always_inline )) void
- x509_chain_put ( struct x509_chain *chain ) {
- ref_put ( &chain->refcnt );
- }
-
-
- static inline __attribute__ (( always_inline )) struct x509_certificate *
- x509_first ( struct x509_chain *chain ) {
- struct x509_link *link;
-
- link = list_first_entry ( &chain->links, struct x509_link, list );
- return ( link ? link->cert : NULL );
- }
-
-
- static inline __attribute__ (( always_inline )) struct x509_certificate *
- x509_last ( struct x509_chain *chain ) {
- struct x509_link *link;
-
- link = list_last_entry ( &chain->links, struct x509_link, list );
- return ( link ? link->cert : NULL );
- }
-
-
- struct x509_extension {
-
- const char *name;
-
- struct asn1_cursor oid;
-
-
- int ( * parse ) ( struct x509_certificate *cert,
- const struct asn1_cursor *raw );
- };
-
-
- struct x509_key_purpose {
-
- const char *name;
-
- struct asn1_cursor oid;
-
- unsigned int bits;
- };
-
-
- struct x509_access_method {
-
- const char *name;
-
- struct asn1_cursor oid;
-
-
- int ( * parse ) ( struct x509_certificate *cert,
- const struct asn1_cursor *raw );
- };
-
-
- struct x509_root {
-
- struct digest_algorithm *digest;
-
- unsigned int count;
-
- const void *fingerprints;
- };
-
- extern int x509_certificate ( const void *data, size_t len,
- struct x509_certificate **cert );
-
- extern struct x509_chain * x509_alloc_chain ( void );
- extern int x509_append ( struct x509_chain *chain,
- struct x509_certificate *cert );
- extern int x509_append_raw ( struct x509_chain *chain, const void *data,
- size_t len );
- extern int x509_auto_append ( struct x509_chain *chain,
- struct x509_chain *certs );
- extern int x509_validate_chain ( struct x509_chain *chain, time_t time,
- struct x509_root *root );
-
-
- extern int x509_check_issuer ( struct x509_certificate *cert,
- struct x509_certificate *issuer );
- extern void x509_fingerprint ( struct x509_certificate *cert,
- struct digest_algorithm *digest,
- void *fingerprint );
- extern int x509_check_root ( struct x509_certificate *cert,
- struct x509_root *root );
- extern int x509_check_time ( struct x509_certificate *cert, time_t time );
-
-
- static inline void x509_invalidate ( struct x509_certificate *cert ) {
- cert->valid = 0;
- cert->path_remaining = 0;
- }
-
-
- static inline void x509_invalidate_chain ( struct x509_chain *chain ) {
- struct x509_link *link;
-
- list_for_each_entry ( link, &chain->links, list )
- x509_invalidate ( link->cert );
- }
-
- #endif
|