x509_crt.h
mbedtls/config.h
mbedtls/x509.h
mbedtls/x509_crl.h
mbedtls/bignum.h
ssl.h
mbedtls/asn1.h
mbedtls/bignum.h
mbedtls/check_config.h
mbedtls/config.h
mbedtls/ecdsa.h
mbedtls/ecp.h
mbedtls/md.h
mbedtls/pk.h
mbedtls/platform_time.h
mbedtls/platform_util.h
mbedtls/rsa.h
mbedtls/threading.h
mbedtls/x509.h
mbedtls/x509_crl.h
x509_crt.h
limits.h
pthread.h
stddef.h
stdint.h
stdio.h
stdlib.h
time.h
debug.h
net.h
net_sockets.h
ssl.h
ssl_cache.h
ssl_cookie.h
ssl_ticket.h
x509_crt.h
mbedtls_x509_crt
mbedtls_x509_san_other_name
mbedtls_x509_subject_alternative_name
mbedtls_x509_crt_profile
mbedtls_x509write_cert
mbedtls_x509_crt_verify_chain_item
mbedtls_x509_crt_verify_chain
Structures and functions for parsing and writing X.509 certificates
- MBEDTLS_X509_ID_FLAG
- MBEDTLS_X509_CRT_VERSION_1
- MBEDTLS_X509_CRT_VERSION_2
- MBEDTLS_X509_CRT_VERSION_3
- MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN
- MBEDTLS_X509_RFC5280_UTC_TIME_LEN
- MBEDTLS_X509_MAX_FILE_PATH_LEN
- MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE
- mbedtls_x509_crt
- mbedtls_x509_san_other_name
- mbedtls_x509_subject_alternative_name
- mbedtls_x509_crt_profile
- mbedtls_x509write_cert
- mbedtls_x509_crt_restart_ctx
- mbedtls_x509_crt_ext_cb_t
- mbedtls_x509_crt_ca_cb_t
- mbedtls_x509_crt_profile_default
- mbedtls_x509_crt_profile_next
- mbedtls_x509_crt_profile_suiteb
- mbedtls_x509_crt_parse_der
- mbedtls_x509_crt_parse_der_with_ext_cb
- mbedtls_x509_crt_parse_der_nocopy
- mbedtls_x509_crt_parse
- mbedtls_x509_crt_parse_file
- mbedtls_x509_crt_parse_path
- mbedtls_x509_parse_subject_alt_name
- mbedtls_x509_crt_info
- mbedtls_x509_crt_verify_info
- mbedtls_x509_crt_verify
- mbedtls_x509_crt_verify_with_profile
- mbedtls_x509_crt_verify_restartable
- mbedtls_x509_crt_check_key_usage
- mbedtls_x509_crt_check_extended_key_usage
- mbedtls_x509_crt_is_revoked
- mbedtls_x509_crt_init
- mbedtls_x509_crt_free
- mbedtls_x509write_crt_init
- mbedtls_x509write_crt_set_version
- mbedtls_x509write_crt_set_serial
- mbedtls_x509write_crt_set_validity
- mbedtls_x509write_crt_set_issuer_name
- mbedtls_x509write_crt_set_subject_name
- mbedtls_x509write_crt_set_subject_key
- mbedtls_x509write_crt_set_issuer_key
- mbedtls_x509write_crt_set_md_alg
- mbedtls_x509write_crt_set_extension
- mbedtls_x509write_crt_set_basic_constraints
- mbedtls_x509write_crt_set_subject_key_identifier
- mbedtls_x509write_crt_set_authority_key_identifier
- mbedtls_x509write_crt_set_key_usage
- mbedtls_x509write_crt_set_ns_cert_type
- mbedtls_x509write_crt_free
- mbedtls_x509write_crt_der
- mbedtls_x509write_crt_pem

X.509 certificate parsing and writing.

    /*
    *CopyrightTheMbedTLSContributors
    *SPDX-License-Identifier:Apache-2.0ORGPL-2.0-or-later
    */
    #ifndefMBEDTLS_X509_CRT_H
    #defineMBEDTLS_X509_CRT_H

    #if!defined(MBEDTLS_CONFIG_FILE)
    #include"mbedtls/config.h"
    #else
    #includeMBEDTLS_CONFIG_FILE
    #endif

    #include"mbedtls/x509.h"
    #include"mbedtls/x509_crl.h"
    #include"mbedtls/bignum.h"

    #ifdef__cplusplus
    extern"C"{
    #endif

    typedefstructmbedtls_x509_crt{
    intown_buffer;
    mbedtls_x509_bufraw;
    mbedtls_x509_buftbs;
    intversion;
    mbedtls_x509_bufserial;
    mbedtls_x509_bufsig_oid;
    mbedtls_x509_bufissuer_raw;
    mbedtls_x509_bufsubject_raw;
    mbedtls_x509_nameissuer;
    mbedtls_x509_namesubject;
    mbedtls_x509_timevalid_from;
    mbedtls_x509_timevalid_to;
    mbedtls_x509_bufpk_raw;
    mbedtls_pk_contextpk;
    mbedtls_x509_bufissuer_id;
    mbedtls_x509_bufsubject_id;
    mbedtls_x509_bufv3_ext;
    mbedtls_x509_sequencesubject_alt_names;
    mbedtls_x509_sequencecertificate_policies;
    intext_types;
    intca_istrue;
    intmax_pathlen;
    unsignedintkey_usage;
    mbedtls_x509_sequenceext_key_usage;
    unsignedcharns_cert_type;
    mbedtls_x509_bufsig;
    mbedtls_md_type_tsig_md;
    mbedtls_pk_type_tsig_pk;
    void*sig_opts;
    structmbedtls_x509_crt*next;
    }
    mbedtls_x509_crt;

    typedefstructmbedtls_x509_san_other_name{
    mbedtls_x509_buftype_id;
    union{
    struct{
    mbedtls_x509_bufoid;
    mbedtls_x509_bufval;
    }
    hardware_module_name;
    }
    value;
    }
    mbedtls_x509_san_other_name;

    typedefstructmbedtls_x509_subject_alternative_name{
    inttype;
    union{
    mbedtls_x509_san_other_nameother_name;
    mbedtls_x509_bufunstructured_name;
    }
    san;
    }
    mbedtls_x509_subject_alternative_name;

    #defineMBEDTLS_X509_ID_FLAG(id)(1<<((id)-1))

    typedefstructmbedtls_x509_crt_profile{
    uint32_tallowed_mds;
    uint32_tallowed_pks;
    uint32_tallowed_curves;
    uint32_trsa_min_bitlen;
    }
    mbedtls_x509_crt_profile;

    #defineMBEDTLS_X509_CRT_VERSION_10
    #defineMBEDTLS_X509_CRT_VERSION_21
    #defineMBEDTLS_X509_CRT_VERSION_32

    #defineMBEDTLS_X509_RFC5280_MAX_SERIAL_LEN32
    #defineMBEDTLS_X509_RFC5280_UTC_TIME_LEN15

    #if!defined(MBEDTLS_X509_MAX_FILE_PATH_LEN)
    #defineMBEDTLS_X509_MAX_FILE_PATH_LEN512
    #endif

    typedefstructmbedtls_x509write_cert{
    intversion;
    mbedtls_mpiserial;
    mbedtls_pk_context*subject_key;
    mbedtls_pk_context*issuer_key;
    mbedtls_asn1_named_data*subject;
    mbedtls_asn1_named_data*issuer;
    mbedtls_md_type_tmd_alg;
    charnot_before[MBEDTLS_X509_RFC5280_UTC_TIME_LEN+1];
    charnot_after[MBEDTLS_X509_RFC5280_UTC_TIME_LEN+1];
    mbedtls_asn1_named_data*extensions;
    }
    mbedtls_x509write_cert;

    typedefstruct{
    mbedtls_x509_crt*crt;
    uint32_tflags;
    }mbedtls_x509_crt_verify_chain_item;

    #defineMBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE(MBEDTLS_X509_MAX_INTERMEDIATE_CA+2)

    typedefstruct{
    mbedtls_x509_crt_verify_chain_itemitems[MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE];
    unsignedlen;

    #ifdefined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
    /*Thisstoresthelistofpotentialtrustedsignersobtainedfrom
    *theCAcallbackusedfortheCRTverification,ifconfigured.
    *Wemusttrackitsomewherebecausethecallbackpassesits
    *ownershiptothecaller.*/
    mbedtls_x509_crt*trust_ca_cb_result;
    #endif/*MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK*/
    }mbedtls_x509_crt_verify_chain;

    #ifdefined(MBEDTLS_ECDSA_C)&&defined(MBEDTLS_ECP_RESTARTABLE)

    typedefstruct{
    /*forcheck_signature()*/
    mbedtls_pk_restart_ctxpk;

    /*forfind_parent_in()*/
    mbedtls_x509_crt*parent;/*non-nulliffparent_ininprogress*/
    mbedtls_x509_crt*fallback_parent;
    intfallback_signature_is_good;

    /*forfind_parent()*/
    intparent_is_trusted;/*-1iffind_parentisnotinprogress*/

    /*forverify_chain()*/
    enum{
    x509_crt_rs_none,
    x509_crt_rs_find_parent,
    }in_progress;/*noneifnooperationisinprogress*/
    intself_cnt;
    mbedtls_x509_crt_verify_chainver_chain;

    }mbedtls_x509_crt_restart_ctx;

    #else/*MBEDTLS_ECDSA_C&&MBEDTLS_ECP_RESTARTABLE*/

    /*Nowwecandeclarefunctionsthattakeapointertothat*/
    typedefvoidmbedtls_x509_crt_restart_ctx;

    #endif/*MBEDTLS_ECDSA_C&&MBEDTLS_ECP_RESTARTABLE*/

    #ifdefined(MBEDTLS_X509_CRT_PARSE_C)
    externconstmbedtls_x509_crt_profilembedtls_x509_crt_profile_default;

    externconstmbedtls_x509_crt_profilembedtls_x509_crt_profile_next;

    externconstmbedtls_x509_crt_profilembedtls_x509_crt_profile_suiteb;

    intmbedtls_x509_crt_parse_der(mbedtls_x509_crt*chain,
    constunsignedchar*buf,
    size_tbuflen);

    typedefint(*mbedtls_x509_crt_ext_cb_t)(void*p_ctx,
    mbedtls_x509_crtconst*crt,
    mbedtls_x509_bufconst*oid,
    intcritical,
    constunsignedchar*p,
    constunsignedchar*end);

    intmbedtls_x509_crt_parse_der_with_ext_cb(mbedtls_x509_crt*chain,
    constunsignedchar*buf,
    size_tbuflen,
    intmake_copy,
    mbedtls_x509_crt_ext_cb_tcb,
    void*p_ctx);

    intmbedtls_x509_crt_parse_der_nocopy(mbedtls_x509_crt*chain,
    constunsignedchar*buf,
    size_tbuflen);

    intmbedtls_x509_crt_parse(mbedtls_x509_crt*chain,constunsignedchar*buf,size_tbuflen);

    #ifdefined(MBEDTLS_FS_IO)
    intmbedtls_x509_crt_parse_file(mbedtls_x509_crt*chain,constchar*path);

    intmbedtls_x509_crt_parse_path(mbedtls_x509_crt*chain,constchar*path);

    #endif/*MBEDTLS_FS_IO*/
    intmbedtls_x509_parse_subject_alt_name(constmbedtls_x509_buf*san_buf,
    mbedtls_x509_subject_alternative_name*san);
    intmbedtls_x509_crt_info(char*buf,size_tsize,constchar*prefix,
    constmbedtls_x509_crt*crt);

    intmbedtls_x509_crt_verify_info(char*buf,size_tsize,constchar*prefix,
    uint32_tflags);

    intmbedtls_x509_crt_verify(mbedtls_x509_crt*crt,
    mbedtls_x509_crt*trust_ca,
    mbedtls_x509_crl*ca_crl,
    constchar*cn,uint32_t*flags,
    int(*f_vrfy)(void*,mbedtls_x509_crt*,int,uint32_t*),
    void*p_vrfy);

    intmbedtls_x509_crt_verify_with_profile(mbedtls_x509_crt*crt,
    mbedtls_x509_crt*trust_ca,
    mbedtls_x509_crl*ca_crl,
    constmbedtls_x509_crt_profile*profile,
    constchar*cn,uint32_t*flags,
    int(*f_vrfy)(void*,mbedtls_x509_crt*,int,uint32_t*),
    void*p_vrfy);

    intmbedtls_x509_crt_verify_restartable(mbedtls_x509_crt*crt,
    mbedtls_x509_crt*trust_ca,
    mbedtls_x509_crl*ca_crl,
    constmbedtls_x509_crt_profile*profile,
    constchar*cn,uint32_t*flags,
    int(*f_vrfy)(void*,mbedtls_x509_crt*,int,uint32_t*),
    void*p_vrfy,
    mbedtls_x509_crt_restart_ctx*rs_ctx);

    typedefint(*mbedtls_x509_crt_ca_cb_t)(void*p_ctx,
    mbedtls_x509_crtconst*child,
    mbedtls_x509_crt**candidate_cas);

    #ifdefined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
    intmbedtls_x509_crt_verify_with_ca_cb(mbedtls_x509_crt*crt,
    mbedtls_x509_crt_ca_cb_tf_ca_cb,
    void*p_ca_cb,
    constmbedtls_x509_crt_profile*profile,
    constchar*cn,uint32_t*flags,
    int(*f_vrfy)(void*,mbedtls_x509_crt*,int,uint32_t*),
    void*p_vrfy);

    #endif/*MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK*/

    #ifdefined(MBEDTLS_X509_CHECK_KEY_USAGE)
    intmbedtls_x509_crt_check_key_usage(constmbedtls_x509_crt*crt,
    unsignedintusage);
    #endif/*MBEDTLS_X509_CHECK_KEY_USAGE)*/

    #ifdefined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
    intmbedtls_x509_crt_check_extended_key_usage(constmbedtls_x509_crt*crt,
    constchar*usage_oid,
    size_tusage_len);
    #endif/*MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE*/

    #ifdefined(MBEDTLS_X509_CRL_PARSE_C)
    intmbedtls_x509_crt_is_revoked(constmbedtls_x509_crt*crt,constmbedtls_x509_crl*crl);
    #endif/*MBEDTLS_X509_CRL_PARSE_C*/

    voidmbedtls_x509_crt_init(mbedtls_x509_crt*crt);

    voidmbedtls_x509_crt_free(mbedtls_x509_crt*crt);

    #ifdefined(MBEDTLS_ECDSA_C)&&defined(MBEDTLS_ECP_RESTARTABLE)
    voidmbedtls_x509_crt_restart_init(mbedtls_x509_crt_restart_ctx*ctx);

    voidmbedtls_x509_crt_restart_free(mbedtls_x509_crt_restart_ctx*ctx);
    #endif/*MBEDTLS_ECDSA_C&&MBEDTLS_ECP_RESTARTABLE*/
    #endif/*MBEDTLS_X509_CRT_PARSE_C*/

    #ifdefined(MBEDTLS_X509_CRT_WRITE_C)
    voidmbedtls_x509write_crt_init(mbedtls_x509write_cert*ctx);

    voidmbedtls_x509write_crt_set_version(mbedtls_x509write_cert*ctx,intversion);

    intmbedtls_x509write_crt_set_serial(mbedtls_x509write_cert*ctx,constmbedtls_mpi*serial);

    intmbedtls_x509write_crt_set_validity(mbedtls_x509write_cert*ctx,constchar*not_before,
    constchar*not_after);

    intmbedtls_x509write_crt_set_issuer_name(mbedtls_x509write_cert*ctx,
    constchar*issuer_name);

    intmbedtls_x509write_crt_set_subject_name(mbedtls_x509write_cert*ctx,
    constchar*subject_name);

    voidmbedtls_x509write_crt_set_subject_key(mbedtls_x509write_cert*ctx,mbedtls_pk_context*key);

    voidmbedtls_x509write_crt_set_issuer_key(mbedtls_x509write_cert*ctx,mbedtls_pk_context*key);

    voidmbedtls_x509write_crt_set_md_alg(mbedtls_x509write_cert*ctx,mbedtls_md_type_tmd_alg);

    intmbedtls_x509write_crt_set_extension(mbedtls_x509write_cert*ctx,
    constchar*oid,size_toid_len,
    intcritical,
    constunsignedchar*val,size_tval_len);

    intmbedtls_x509write_crt_set_basic_constraints(mbedtls_x509write_cert*ctx,
    intis_ca,intmax_pathlen);

    #ifdefined(MBEDTLS_SHA1_C)
    intmbedtls_x509write_crt_set_subject_key_identifier(mbedtls_x509write_cert*ctx);

    intmbedtls_x509write_crt_set_authority_key_identifier(mbedtls_x509write_cert*ctx);
    #endif/*MBEDTLS_SHA1_C*/

    intmbedtls_x509write_crt_set_key_usage(mbedtls_x509write_cert*ctx,
    unsignedintkey_usage);

    intmbedtls_x509write_crt_set_ns_cert_type(mbedtls_x509write_cert*ctx,
    unsignedcharns_cert_type);

    voidmbedtls_x509write_crt_free(mbedtls_x509write_cert*ctx);

    intmbedtls_x509write_crt_der(mbedtls_x509write_cert*ctx,unsignedchar*buf,size_tsize,
    int(*f_rng)(void*,unsignedchar*,size_t),
    void*p_rng);

    #ifdefined(MBEDTLS_PEM_WRITE_C)
    intmbedtls_x509write_crt_pem(mbedtls_x509write_cert*ctx,unsignedchar*buf,size_tsize,
    int(*f_rng)(void*,unsignedchar*,size_t),
    void*p_rng);
    #endif/*MBEDTLS_PEM_WRITE_C*/
    #endif/*MBEDTLS_X509_CRT_WRITE_C*/

    #ifdef__cplusplus
    }
    #endif

    #endif/*mbedtls_x509_crt.h*/