123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661 |
- #ifndef MBEDTLS_X509_CRT_H
- #define MBEDTLS_X509_CRT_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #include "config.h"
- #else
- #include MBEDTLS_CONFIG_FILE
- #endif
- #include "x509.h"
- #include "x509_crl.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct mbedtls_x509_crt
- {
- mbedtls_x509_buf raw;
- mbedtls_x509_buf tbs;
- int version;
- mbedtls_x509_buf serial;
- mbedtls_x509_buf sig_oid;
- mbedtls_x509_buf issuer_raw;
- mbedtls_x509_buf subject_raw;
- mbedtls_x509_name issuer;
- mbedtls_x509_name subject;
- mbedtls_x509_time valid_from;
- mbedtls_x509_time valid_to;
- mbedtls_pk_context pk;
- mbedtls_x509_buf issuer_id;
- mbedtls_x509_buf subject_id;
- mbedtls_x509_buf v3_ext;
- mbedtls_x509_sequence subject_alt_names;
- int ext_types;
- int ca_istrue;
- int max_pathlen;
- unsigned int key_usage;
- mbedtls_x509_sequence ext_key_usage;
- unsigned char ns_cert_type;
- mbedtls_x509_buf sig;
- mbedtls_md_type_t sig_md;
- mbedtls_pk_type_t sig_pk;
- void *sig_opts;
- struct mbedtls_x509_crt *next;
- }
- mbedtls_x509_crt;
- #define MBEDTLS_X509_ID_FLAG( id ) ( 1 << ( id - 1 ) )
- typedef struct
- {
- uint32_t allowed_mds;
- uint32_t allowed_pks;
- uint32_t allowed_curves;
- uint32_t rsa_min_bitlen;
- }
- mbedtls_x509_crt_profile;
- #define MBEDTLS_X509_CRT_VERSION_1 0
- #define MBEDTLS_X509_CRT_VERSION_2 1
- #define MBEDTLS_X509_CRT_VERSION_3 2
- #define MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN 32
- #define MBEDTLS_X509_RFC5280_UTC_TIME_LEN 15
- #if !defined( MBEDTLS_X509_MAX_FILE_PATH_LEN )
- #define MBEDTLS_X509_MAX_FILE_PATH_LEN 512
- #endif
- typedef struct mbedtls_x509write_cert
- {
- int version;
- mbedtls_mpi serial;
- mbedtls_pk_context *subject_key;
- mbedtls_pk_context *issuer_key;
- mbedtls_asn1_named_data *subject;
- mbedtls_asn1_named_data *issuer;
- mbedtls_md_type_t md_alg;
- char not_before[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
- char not_after[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
- mbedtls_asn1_named_data *extensions;
- }
- mbedtls_x509write_cert;
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;
- extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next;
- extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;
- int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, const unsigned char *buf,
- size_t buflen );
- int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen );
- #if defined(MBEDTLS_FS_IO)
- int mbedtls_x509_crt_parse_file( mbedtls_x509_crt *chain, const char *path );
- int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path );
- #endif
- int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
- const mbedtls_x509_crt *crt );
- int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix,
- uint32_t flags );
- int mbedtls_x509_crt_verify( mbedtls_x509_crt *crt,
- mbedtls_x509_crt *trust_ca,
- mbedtls_x509_crl *ca_crl,
- const char *cn, uint32_t *flags,
- int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
- void *p_vrfy );
- int mbedtls_x509_crt_verify_with_profile( mbedtls_x509_crt *crt,
- mbedtls_x509_crt *trust_ca,
- mbedtls_x509_crl *ca_crl,
- const mbedtls_x509_crt_profile *profile,
- const char *cn, uint32_t *flags,
- int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
- void *p_vrfy );
- #if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
- int mbedtls_x509_crt_check_key_usage( const mbedtls_x509_crt *crt,
- unsigned int usage );
- #endif
- #if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
- int mbedtls_x509_crt_check_extended_key_usage( const mbedtls_x509_crt *crt,
- const char *usage_oid,
- size_t usage_len );
- #endif
- #if defined(MBEDTLS_X509_CRL_PARSE_C)
- int mbedtls_x509_crt_is_revoked( const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl );
- #endif
- void mbedtls_x509_crt_init( mbedtls_x509_crt *crt );
- void mbedtls_x509_crt_free( mbedtls_x509_crt *crt );
- #endif
- #if defined(MBEDTLS_X509_CRT_WRITE_C)
- void mbedtls_x509write_crt_init( mbedtls_x509write_cert *ctx );
- void mbedtls_x509write_crt_set_version( mbedtls_x509write_cert *ctx, int version );
- int mbedtls_x509write_crt_set_serial( mbedtls_x509write_cert *ctx, const mbedtls_mpi *serial );
- int mbedtls_x509write_crt_set_validity( mbedtls_x509write_cert *ctx, const char *not_before,
- const char *not_after );
- int mbedtls_x509write_crt_set_issuer_name( mbedtls_x509write_cert *ctx,
- const char *issuer_name );
- int mbedtls_x509write_crt_set_subject_name( mbedtls_x509write_cert *ctx,
- const char *subject_name );
- void mbedtls_x509write_crt_set_subject_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
- void mbedtls_x509write_crt_set_issuer_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
- void mbedtls_x509write_crt_set_md_alg( mbedtls_x509write_cert *ctx, mbedtls_md_type_t md_alg );
- int mbedtls_x509write_crt_set_extension( mbedtls_x509write_cert *ctx,
- const char *oid, size_t oid_len,
- int critical,
- const unsigned char *val, size_t val_len );
- int mbedtls_x509write_crt_set_basic_constraints( mbedtls_x509write_cert *ctx,
- int is_ca, int max_pathlen );
- #if defined(MBEDTLS_SHA1_C)
- int mbedtls_x509write_crt_set_subject_key_identifier( mbedtls_x509write_cert *ctx );
- int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert *ctx );
- #endif
- int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx,
- unsigned int key_usage );
- int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx,
- unsigned char ns_cert_type );
- void mbedtls_x509write_crt_free( mbedtls_x509write_cert *ctx );
- int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- #if defined(MBEDTLS_PEM_WRITE_C)
- int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- #endif
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|