You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-13 13:31:48 +00:00
mbedTLS: Update to new LTS v3.6.0
Keep module compatibility with mbedtls 2.x (old LTS branch). A patch has been added to allow compiling after removing all the `psa_*` files from the library folder (will look into upstreaming it). Note: mbedTLS 3.6 finally enabled TLSv1.3 by default, but it requires some module changes, and to enable PSA crypto (new "standard" API specification), so it might be best done in a separate commit/PR.
This commit is contained in:
committed by
Fabio Alessandrelli
parent
6c57928063
commit
40fa684c18
386
thirdparty/mbedtls/include/mbedtls/x509_crt.h
vendored
386
thirdparty/mbedtls/include/mbedtls/x509_crt.h
vendored
@@ -9,12 +9,9 @@
|
||||
*/
|
||||
#ifndef MBEDTLS_X509_CRT_H
|
||||
#define MBEDTLS_X509_CRT_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
#include "mbedtls/x509.h"
|
||||
#include "mbedtls/x509_crl.h"
|
||||
@@ -36,10 +33,14 @@ extern "C" {
|
||||
|
||||
/**
|
||||
* Container for an X.509 certificate. The certificate may be chained.
|
||||
*
|
||||
* Some fields of this structure are publicly readable. Do not modify
|
||||
* them except via Mbed TLS library functions: the effect of modifying
|
||||
* those fields or the data that those fields points to is unspecified.
|
||||
*/
|
||||
typedef struct mbedtls_x509_crt {
|
||||
int own_buffer; /**< Indicates if \c raw is owned
|
||||
* by the structure or not. */
|
||||
int MBEDTLS_PRIVATE(own_buffer); /**< Indicates if \c raw is owned
|
||||
* by the structure or not. */
|
||||
mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
|
||||
mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
|
||||
|
||||
@@ -62,72 +63,34 @@ typedef struct mbedtls_x509_crt {
|
||||
mbedtls_x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
|
||||
mbedtls_x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */
|
||||
mbedtls_x509_buf v3_ext; /**< Optional X.509 v3 extensions. */
|
||||
mbedtls_x509_sequence subject_alt_names; /**< Optional list of raw entries of Subject Alternative Names extension (currently only dNSName and OtherName are listed). */
|
||||
mbedtls_x509_sequence subject_alt_names; /**< Optional list of raw entries of Subject Alternative Names extension. These can be later parsed by mbedtls_x509_parse_subject_alt_name. */
|
||||
mbedtls_x509_buf subject_key_id; /**< Optional X.509 v3 extension subject key identifier. */
|
||||
mbedtls_x509_authority authority_key_id; /**< Optional X.509 v3 extension authority key identifier. */
|
||||
|
||||
mbedtls_x509_sequence certificate_policies; /**< Optional list of certificate policies (Only anyPolicy is printed and enforced, however the rest of the policies are still listed). */
|
||||
|
||||
int ext_types; /**< Bit string containing detected and parsed extensions */
|
||||
int ca_istrue; /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */
|
||||
int max_pathlen; /**< Optional Basic Constraint extension value: The maximum path length to the root certificate. Path length is 1 higher than RFC 5280 'meaning', so 1+ */
|
||||
int MBEDTLS_PRIVATE(ext_types); /**< Bit string containing detected and parsed extensions */
|
||||
int MBEDTLS_PRIVATE(ca_istrue); /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */
|
||||
int MBEDTLS_PRIVATE(max_pathlen); /**< Optional Basic Constraint extension value: The maximum path length to the root certificate. Path length is 1 higher than RFC 5280 'meaning', so 1+ */
|
||||
|
||||
unsigned int key_usage; /**< Optional key usage extension value: See the values in x509.h */
|
||||
unsigned int MBEDTLS_PRIVATE(key_usage); /**< Optional key usage extension value: See the values in x509.h */
|
||||
|
||||
mbedtls_x509_sequence ext_key_usage; /**< Optional list of extended key usage OIDs. */
|
||||
|
||||
unsigned char ns_cert_type; /**< Optional Netscape certificate type extension value: See the values in x509.h */
|
||||
unsigned char MBEDTLS_PRIVATE(ns_cert_type); /**< Optional Netscape certificate type extension value: See the values in x509.h */
|
||||
|
||||
mbedtls_x509_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
|
||||
mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
|
||||
mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
|
||||
void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
|
||||
mbedtls_x509_buf MBEDTLS_PRIVATE(sig); /**< Signature: hash of the tbs part signed with the private key. */
|
||||
mbedtls_md_type_t MBEDTLS_PRIVATE(sig_md); /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
|
||||
mbedtls_pk_type_t MBEDTLS_PRIVATE(sig_pk); /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
|
||||
void *MBEDTLS_PRIVATE(sig_opts); /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
|
||||
|
||||
struct mbedtls_x509_crt *next; /**< Next certificate in the CA-chain. */
|
||||
/** Next certificate in the linked list that constitutes the CA chain.
|
||||
* \p NULL indicates the end of the list.
|
||||
* Do not modify this field directly. */
|
||||
struct mbedtls_x509_crt *next;
|
||||
}
|
||||
mbedtls_x509_crt;
|
||||
|
||||
/**
|
||||
* From RFC 5280 section 4.2.1.6:
|
||||
* OtherName ::= SEQUENCE {
|
||||
* type-id OBJECT IDENTIFIER,
|
||||
* value [0] EXPLICIT ANY DEFINED BY type-id }
|
||||
*/
|
||||
typedef struct mbedtls_x509_san_other_name {
|
||||
/**
|
||||
* The type_id is an OID as defined in RFC 5280.
|
||||
* To check the value of the type id, you should use
|
||||
* \p MBEDTLS_OID_CMP with a known OID mbedtls_x509_buf.
|
||||
*/
|
||||
mbedtls_x509_buf type_id; /**< The type id. */
|
||||
union {
|
||||
/**
|
||||
* From RFC 4108 section 5:
|
||||
* HardwareModuleName ::= SEQUENCE {
|
||||
* hwType OBJECT IDENTIFIER,
|
||||
* hwSerialNum OCTET STRING }
|
||||
*/
|
||||
struct {
|
||||
mbedtls_x509_buf oid; /**< The object identifier. */
|
||||
mbedtls_x509_buf val; /**< The named value. */
|
||||
}
|
||||
hardware_module_name;
|
||||
}
|
||||
value;
|
||||
}
|
||||
mbedtls_x509_san_other_name;
|
||||
|
||||
/**
|
||||
* A structure for holding the parsed Subject Alternative Name, according to type
|
||||
*/
|
||||
typedef struct mbedtls_x509_subject_alternative_name {
|
||||
int type; /**< The SAN type, value of MBEDTLS_X509_SAN_XXX. */
|
||||
union {
|
||||
mbedtls_x509_san_other_name other_name; /**< The otherName supported type. */
|
||||
mbedtls_x509_buf unstructured_name; /**< The buffer for the un constructed types. Only dnsName currently supported */
|
||||
}
|
||||
san; /**< A union of the supported SAN types */
|
||||
}
|
||||
mbedtls_x509_subject_alternative_name;
|
||||
|
||||
/**
|
||||
* Build flag from an algorithm/curve identifier (pk, md, ecp)
|
||||
* Since 0 is always XXX_NONE, ignore it.
|
||||
@@ -138,6 +101,26 @@ mbedtls_x509_subject_alternative_name;
|
||||
* Security profile for certificate verification.
|
||||
*
|
||||
* All lists are bitfields, built by ORing flags from MBEDTLS_X509_ID_FLAG().
|
||||
*
|
||||
* The fields of this structure are part of the public API and can be
|
||||
* manipulated directly by applications. Future versions of the library may
|
||||
* add extra fields or reorder existing fields.
|
||||
*
|
||||
* You can create custom profiles by starting from a copy of
|
||||
* an existing profile, such as mbedtls_x509_crt_profile_default or
|
||||
* mbedtls_x509_ctr_profile_none and then tune it to your needs.
|
||||
*
|
||||
* For example to allow SHA-224 in addition to the default:
|
||||
*
|
||||
* mbedtls_x509_crt_profile my_profile = mbedtls_x509_crt_profile_default;
|
||||
* my_profile.allowed_mds |= MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA224 );
|
||||
*
|
||||
* Or to allow only RSA-3072+ with SHA-256:
|
||||
*
|
||||
* mbedtls_x509_crt_profile my_profile = mbedtls_x509_crt_profile_none;
|
||||
* my_profile.allowed_mds = MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA256 );
|
||||
* my_profile.allowed_pks = MBEDTLS_X509_ID_FLAG( MBEDTLS_PK_RSA );
|
||||
* my_profile.rsa_min_bitlen = 3072;
|
||||
*/
|
||||
typedef struct mbedtls_x509_crt_profile {
|
||||
uint32_t allowed_mds; /**< MDs for signatures */
|
||||
@@ -153,36 +136,120 @@ mbedtls_x509_crt_profile;
|
||||
#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_MAX_SERIAL_LEN 20
|
||||
#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
|
||||
|
||||
/* This macro unfolds to the concatenation of macro invocations
|
||||
* X509_CRT_ERROR_INFO( error code,
|
||||
* error code as string,
|
||||
* human readable description )
|
||||
* where X509_CRT_ERROR_INFO is defined by the user.
|
||||
* See x509_crt.c for an example of how to use this. */
|
||||
#define MBEDTLS_X509_CRT_ERROR_INFO_LIST \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXPIRED, \
|
||||
"MBEDTLS_X509_BADCERT_EXPIRED", \
|
||||
"The certificate validity has expired") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_REVOKED, \
|
||||
"MBEDTLS_X509_BADCERT_REVOKED", \
|
||||
"The certificate has been revoked (is on a CRL)") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_CN_MISMATCH, \
|
||||
"MBEDTLS_X509_BADCERT_CN_MISMATCH", \
|
||||
"The certificate Common Name (CN) does not match with the expected CN") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NOT_TRUSTED, \
|
||||
"MBEDTLS_X509_BADCERT_NOT_TRUSTED", \
|
||||
"The certificate is not correctly signed by the trusted CA") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_NOT_TRUSTED, \
|
||||
"MBEDTLS_X509_BADCRL_NOT_TRUSTED", \
|
||||
"The CRL is not correctly signed by the trusted CA") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_EXPIRED, \
|
||||
"MBEDTLS_X509_BADCRL_EXPIRED", \
|
||||
"The CRL is expired") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_MISSING, \
|
||||
"MBEDTLS_X509_BADCERT_MISSING", \
|
||||
"Certificate was missing") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_SKIP_VERIFY, \
|
||||
"MBEDTLS_X509_BADCERT_SKIP_VERIFY", \
|
||||
"Certificate verification was skipped") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_OTHER, \
|
||||
"MBEDTLS_X509_BADCERT_OTHER", \
|
||||
"Other reason (can be used by verify callback)") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_FUTURE, \
|
||||
"MBEDTLS_X509_BADCERT_FUTURE", \
|
||||
"The certificate validity starts in the future") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_FUTURE, \
|
||||
"MBEDTLS_X509_BADCRL_FUTURE", \
|
||||
"The CRL is from the future") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_KEY_USAGE, \
|
||||
"MBEDTLS_X509_BADCERT_KEY_USAGE", \
|
||||
"Usage does not match the keyUsage extension") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXT_KEY_USAGE, \
|
||||
"MBEDTLS_X509_BADCERT_EXT_KEY_USAGE", \
|
||||
"Usage does not match the extendedKeyUsage extension") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NS_CERT_TYPE, \
|
||||
"MBEDTLS_X509_BADCERT_NS_CERT_TYPE", \
|
||||
"Usage does not match the nsCertType extension") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_MD, \
|
||||
"MBEDTLS_X509_BADCERT_BAD_MD", \
|
||||
"The certificate is signed with an unacceptable hash.") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_PK, \
|
||||
"MBEDTLS_X509_BADCERT_BAD_PK", \
|
||||
"The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA).") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_KEY, \
|
||||
"MBEDTLS_X509_BADCERT_BAD_KEY", \
|
||||
"The certificate is signed with an unacceptable key (eg bad curve, RSA too short).") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_MD, \
|
||||
"MBEDTLS_X509_BADCRL_BAD_MD", \
|
||||
"The CRL is signed with an unacceptable hash.") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_PK, \
|
||||
"MBEDTLS_X509_BADCRL_BAD_PK", \
|
||||
"The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA).") \
|
||||
X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_KEY, \
|
||||
"MBEDTLS_X509_BADCRL_BAD_KEY", \
|
||||
"The CRL is signed with an unacceptable key (eg bad curve, RSA too short).")
|
||||
|
||||
/**
|
||||
* Container for writing a certificate (CRT)
|
||||
*/
|
||||
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;
|
||||
int MBEDTLS_PRIVATE(version);
|
||||
unsigned char MBEDTLS_PRIVATE(serial)[MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN];
|
||||
size_t MBEDTLS_PRIVATE(serial_len);
|
||||
mbedtls_pk_context *MBEDTLS_PRIVATE(subject_key);
|
||||
mbedtls_pk_context *MBEDTLS_PRIVATE(issuer_key);
|
||||
mbedtls_asn1_named_data *MBEDTLS_PRIVATE(subject);
|
||||
mbedtls_asn1_named_data *MBEDTLS_PRIVATE(issuer);
|
||||
mbedtls_md_type_t MBEDTLS_PRIVATE(md_alg);
|
||||
char MBEDTLS_PRIVATE(not_before)[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
|
||||
char MBEDTLS_PRIVATE(not_after)[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
|
||||
mbedtls_asn1_named_data *MBEDTLS_PRIVATE(extensions);
|
||||
}
|
||||
mbedtls_x509write_cert;
|
||||
|
||||
/**
|
||||
* \brief Set Subject Alternative Name
|
||||
*
|
||||
* \param ctx Certificate context to use
|
||||
* \param san_list List of SAN values
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
*
|
||||
* \note "dnsName", "uniformResourceIdentifier", "IP address",
|
||||
* "otherName", and "DirectoryName", as defined in RFC 5280,
|
||||
* are supported.
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_subject_alternative_name(mbedtls_x509write_cert *ctx,
|
||||
const mbedtls_x509_san_list *san_list);
|
||||
|
||||
/**
|
||||
* Item in a verification chain: cert and flags for it
|
||||
*/
|
||||
typedef struct {
|
||||
mbedtls_x509_crt *crt;
|
||||
uint32_t flags;
|
||||
mbedtls_x509_crt *MBEDTLS_PRIVATE(crt);
|
||||
uint32_t MBEDTLS_PRIVATE(flags);
|
||||
} mbedtls_x509_crt_verify_chain_item;
|
||||
|
||||
/**
|
||||
@@ -194,15 +261,15 @@ typedef struct {
|
||||
* Verification chain as built by \c mbedtls_crt_verify_chain()
|
||||
*/
|
||||
typedef struct {
|
||||
mbedtls_x509_crt_verify_chain_item items[MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE];
|
||||
unsigned len;
|
||||
mbedtls_x509_crt_verify_chain_item MBEDTLS_PRIVATE(items)[MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE];
|
||||
unsigned MBEDTLS_PRIVATE(len);
|
||||
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
/* This stores the list of potential trusted signers obtained from
|
||||
* the CA callback used for the CRT verification, if configured.
|
||||
* We must track it somewhere because the callback passes its
|
||||
* ownership to the caller. */
|
||||
mbedtls_x509_crt *trust_ca_cb_result;
|
||||
mbedtls_x509_crt *MBEDTLS_PRIVATE(trust_ca_cb_result);
|
||||
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
|
||||
} mbedtls_x509_crt_verify_chain;
|
||||
|
||||
@@ -213,23 +280,23 @@ typedef struct {
|
||||
*/
|
||||
typedef struct {
|
||||
/* for check_signature() */
|
||||
mbedtls_pk_restart_ctx pk;
|
||||
mbedtls_pk_restart_ctx MBEDTLS_PRIVATE(pk);
|
||||
|
||||
/* for find_parent_in() */
|
||||
mbedtls_x509_crt *parent; /* non-null iff parent_in in progress */
|
||||
mbedtls_x509_crt *fallback_parent;
|
||||
int fallback_signature_is_good;
|
||||
mbedtls_x509_crt *MBEDTLS_PRIVATE(parent); /* non-null iff parent_in in progress */
|
||||
mbedtls_x509_crt *MBEDTLS_PRIVATE(fallback_parent);
|
||||
int MBEDTLS_PRIVATE(fallback_signature_is_good);
|
||||
|
||||
/* for find_parent() */
|
||||
int parent_is_trusted; /* -1 if find_parent is not in progress */
|
||||
int MBEDTLS_PRIVATE(parent_is_trusted); /* -1 if find_parent is not in progress */
|
||||
|
||||
/* for verify_chain() */
|
||||
enum {
|
||||
x509_crt_rs_none,
|
||||
x509_crt_rs_find_parent,
|
||||
} in_progress; /* none if no operation is in progress */
|
||||
int self_cnt;
|
||||
mbedtls_x509_crt_verify_chain ver_chain;
|
||||
} MBEDTLS_PRIVATE(in_progress); /* none if no operation is in progress */
|
||||
int MBEDTLS_PRIVATE(self_cnt);
|
||||
mbedtls_x509_crt_verify_chain MBEDTLS_PRIVATE(ver_chain);
|
||||
|
||||
} mbedtls_x509_crt_restart_ctx;
|
||||
|
||||
@@ -246,12 +313,12 @@ typedef void mbedtls_x509_crt_restart_ctx;
|
||||
* and compatibility with current deployments.
|
||||
*
|
||||
* This profile permits:
|
||||
* - SHA2 hashes.
|
||||
* - All supported elliptic curves.
|
||||
* - SHA2 hashes with at least 256 bits: SHA-256, SHA-384, SHA-512.
|
||||
* - Elliptic curves with 255 bits and above except secp256k1.
|
||||
* - RSA with 2048 bits and above.
|
||||
*
|
||||
* New minor versions of Mbed TLS may extend this profile, for example if
|
||||
* new curves are added to the library. New minor versions of Mbed TLS will
|
||||
* new algorithms are added to the library. New minor versions of Mbed TLS will
|
||||
* not reduce this profile unless serious security concerns require it.
|
||||
*/
|
||||
extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;
|
||||
@@ -259,6 +326,7 @@ extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;
|
||||
/**
|
||||
* Expected next default profile. Recommended for new deployments.
|
||||
* Currently targets a 128-bit security level, except for allowing RSA-2048.
|
||||
* This profile may change at any time.
|
||||
*/
|
||||
extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next;
|
||||
|
||||
@@ -267,6 +335,12 @@ extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next;
|
||||
*/
|
||||
extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;
|
||||
|
||||
/**
|
||||
* Empty profile that allows nothing. Useful as a basis for constructing
|
||||
* custom profiles.
|
||||
*/
|
||||
extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_none;
|
||||
|
||||
/**
|
||||
* \brief Parse a single DER formatted certificate and add it
|
||||
* to the end of the provided chained list.
|
||||
@@ -400,7 +474,7 @@ int mbedtls_x509_crt_parse_der_with_ext_cb(mbedtls_x509_crt *chain,
|
||||
* mbedtls_x509_crt_init().
|
||||
* \param buf The address of the readable buffer holding the DER encoded
|
||||
* certificate to use. On success, this buffer must be
|
||||
* retained and not be changed for the liftetime of the
|
||||
* retained and not be changed for the lifetime of the
|
||||
* CRT chain \p chain, that is, until \p chain is destroyed
|
||||
* through a call to mbedtls_x509_crt_free().
|
||||
* \param buflen The size in Bytes of \p buf.
|
||||
@@ -490,35 +564,8 @@ 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 /* MBEDTLS_FS_IO */
|
||||
/**
|
||||
* \brief This function parses an item in the SubjectAlternativeNames
|
||||
* extension.
|
||||
*
|
||||
* \param san_buf The buffer holding the raw data item of the subject
|
||||
* alternative name.
|
||||
* \param san The target structure to populate with the parsed presentation
|
||||
* of the subject alternative name encoded in \p san_buf.
|
||||
*
|
||||
* \note Only "dnsName" and "otherName" of type hardware_module_name
|
||||
* as defined in RFC 4180 is supported.
|
||||
*
|
||||
* \note This function should be called on a single raw data of
|
||||
* subject alternative name. For example, after successful
|
||||
* certificate parsing, one must iterate on every item in the
|
||||
* \c crt->subject_alt_names sequence, and pass it to
|
||||
* this function.
|
||||
*
|
||||
* \warning The target structure contains pointers to the raw data of the
|
||||
* parsed certificate, and its lifetime is restricted by the
|
||||
* lifetime of the certificate.
|
||||
*
|
||||
* \return \c 0 on success
|
||||
* \return #MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE for an unsupported
|
||||
* SAN type.
|
||||
* \return Another negative value for any other failure.
|
||||
*/
|
||||
int mbedtls_x509_parse_subject_alt_name(const mbedtls_x509_buf *san_buf,
|
||||
mbedtls_x509_subject_alternative_name *san);
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
/**
|
||||
* \brief Returns an informational string about the
|
||||
* certificate.
|
||||
@@ -548,6 +595,7 @@ int mbedtls_x509_crt_info(char *buf, size_t size, const char *prefix,
|
||||
*/
|
||||
int mbedtls_x509_crt_verify_info(char *buf, size_t size, const char *prefix,
|
||||
uint32_t flags);
|
||||
#endif /* !MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
/**
|
||||
* \brief Verify a chain of certificates.
|
||||
@@ -596,8 +644,12 @@ int mbedtls_x509_crt_verify_info(char *buf, size_t size, const char *prefix,
|
||||
* \param cn The expected Common Name. This will be checked to be
|
||||
* present in the certificate's subjectAltNames extension or,
|
||||
* if this extension is absent, as a CN component in its
|
||||
* Subject name. Currently only DNS names are supported. This
|
||||
* may be \c NULL if the CN need not be verified.
|
||||
* Subject name. DNS names and IP addresses are fully
|
||||
* supported, while the URI subtype is partially supported:
|
||||
* only exact matching, without any normalization procedures
|
||||
* described in 7.4 of RFC5280, will result in a positive
|
||||
* URI verification.
|
||||
* This may be \c NULL if the CN need not be verified.
|
||||
* \param flags The address at which to store the result of the verification.
|
||||
* If the verification couldn't be completed, the flag value is
|
||||
* set to (uint32_t) -1.
|
||||
@@ -766,7 +818,6 @@ int mbedtls_x509_crt_verify_with_ca_cb(mbedtls_x509_crt *crt,
|
||||
|
||||
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
|
||||
|
||||
#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
|
||||
/**
|
||||
* \brief Check usage of certificate against keyUsage extension.
|
||||
*
|
||||
@@ -790,9 +841,7 @@ int mbedtls_x509_crt_verify_with_ca_cb(mbedtls_x509_crt *crt,
|
||||
*/
|
||||
int mbedtls_x509_crt_check_key_usage(const mbedtls_x509_crt *crt,
|
||||
unsigned int usage);
|
||||
#endif /* MBEDTLS_X509_CHECK_KEY_USAGE) */
|
||||
|
||||
#if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
|
||||
/**
|
||||
* \brief Check usage of certificate against extendedKeyUsage.
|
||||
*
|
||||
@@ -809,7 +858,6 @@ int mbedtls_x509_crt_check_key_usage(const mbedtls_x509_crt *crt,
|
||||
int mbedtls_x509_crt_check_extended_key_usage(const mbedtls_x509_crt *crt,
|
||||
const char *usage_oid,
|
||||
size_t usage_len);
|
||||
#endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
|
||||
|
||||
#if defined(MBEDTLS_X509_CRL_PARSE_C)
|
||||
/**
|
||||
@@ -851,6 +899,35 @@ void mbedtls_x509_crt_restart_free(mbedtls_x509_crt_restart_ctx *ctx);
|
||||
#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
/**
|
||||
* \brief Query certificate for given extension type
|
||||
*
|
||||
* \param[in] ctx Certificate context to be queried, must not be \c NULL
|
||||
* \param ext_type Extension type being queried for, must be a valid
|
||||
* extension type. Must be one of the MBEDTLS_X509_EXT_XXX
|
||||
* values
|
||||
*
|
||||
* \return 0 if the given extension type is not present,
|
||||
* non-zero otherwise
|
||||
*/
|
||||
static inline int mbedtls_x509_crt_has_ext_type(const mbedtls_x509_crt *ctx,
|
||||
int ext_type)
|
||||
{
|
||||
return ctx->MBEDTLS_PRIVATE(ext_types) & ext_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Access the ca_istrue field
|
||||
*
|
||||
* \param[in] crt Certificate to be queried, must not be \c NULL
|
||||
*
|
||||
* \return \c 1 if this a CA certificate \c 0 otherwise.
|
||||
* \return MBEDTLS_ERR_X509_INVALID_EXTENSIONS if the certificate does not contain
|
||||
* the Optional Basic Constraint extension.
|
||||
*
|
||||
*/
|
||||
int mbedtls_x509_crt_get_ca_istrue(const mbedtls_x509_crt *crt);
|
||||
|
||||
/** \} name Structures and functions for parsing and writing X.509 certificates */
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_WRITE_C)
|
||||
@@ -871,15 +948,43 @@ void mbedtls_x509write_crt_init(mbedtls_x509write_cert *ctx);
|
||||
*/
|
||||
void mbedtls_x509write_crt_set_version(mbedtls_x509write_cert *ctx, int version);
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C) && !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
/**
|
||||
* \brief Set the serial number for a Certificate.
|
||||
*
|
||||
* \deprecated This function is deprecated and will be removed in a
|
||||
* future version of the library. Please use
|
||||
* mbedtls_x509write_crt_set_serial_raw() instead.
|
||||
*
|
||||
* \note Even though the MBEDTLS_BIGNUM_C guard looks redundant since
|
||||
* X509 depends on PK and PK depends on BIGNUM, this emphasizes
|
||||
* a direct dependency between X509 and BIGNUM which is going
|
||||
* to be deprecated in the future.
|
||||
*
|
||||
* \param ctx CRT context to use
|
||||
* \param serial serial number to set
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_serial(mbedtls_x509write_cert *ctx, const mbedtls_mpi *serial);
|
||||
int MBEDTLS_DEPRECATED mbedtls_x509write_crt_set_serial(
|
||||
mbedtls_x509write_cert *ctx, const mbedtls_mpi *serial);
|
||||
#endif // MBEDTLS_BIGNUM_C && !MBEDTLS_DEPRECATED_REMOVED
|
||||
|
||||
/**
|
||||
* \brief Set the serial number for a Certificate.
|
||||
*
|
||||
* \param ctx CRT context to use
|
||||
* \param serial A raw array of bytes containing the serial number in big
|
||||
* endian format
|
||||
* \param serial_len Length of valid bytes (expressed in bytes) in \p serial
|
||||
* input buffer
|
||||
*
|
||||
* \return 0 if successful, or
|
||||
* MBEDTLS_ERR_X509_BAD_INPUT_DATA if the provided input buffer
|
||||
* is too big (longer than MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN)
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_serial_raw(mbedtls_x509write_cert *ctx,
|
||||
unsigned char *serial, size_t serial_len);
|
||||
|
||||
/**
|
||||
* \brief Set the validity period for a Certificate
|
||||
@@ -985,7 +1090,7 @@ int mbedtls_x509write_crt_set_extension(mbedtls_x509write_cert *ctx,
|
||||
int mbedtls_x509write_crt_set_basic_constraints(mbedtls_x509write_cert *ctx,
|
||||
int is_ca, int max_pathlen);
|
||||
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
#if defined(MBEDTLS_MD_CAN_SHA1)
|
||||
/**
|
||||
* \brief Set the subjectKeyIdentifier extension for a CRT
|
||||
* Requires that mbedtls_x509write_crt_set_subject_key() has been
|
||||
@@ -1007,7 +1112,7 @@ int mbedtls_x509write_crt_set_subject_key_identifier(mbedtls_x509write_cert *ctx
|
||||
* \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_authority_key_identifier(mbedtls_x509write_cert *ctx);
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#endif /* MBEDTLS_MD_CAN_SHA1 */
|
||||
|
||||
/**
|
||||
* \brief Set the Key Usage Extension flags
|
||||
@@ -1021,6 +1126,19 @@ int mbedtls_x509write_crt_set_authority_key_identifier(mbedtls_x509write_cert *c
|
||||
int mbedtls_x509write_crt_set_key_usage(mbedtls_x509write_cert *ctx,
|
||||
unsigned int key_usage);
|
||||
|
||||
/**
|
||||
* \brief Set the Extended Key Usage Extension
|
||||
* (e.g. MBEDTLS_OID_SERVER_AUTH)
|
||||
*
|
||||
* \param ctx CRT context to use
|
||||
* \param exts extended key usage extensions to set, a sequence of
|
||||
* MBEDTLS_ASN1_OID objects
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_ext_key_usage(mbedtls_x509write_cert *ctx,
|
||||
const mbedtls_asn1_sequence *exts);
|
||||
|
||||
/**
|
||||
* \brief Set the Netscape Cert Type flags
|
||||
* (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
|
||||
@@ -1049,16 +1167,13 @@ void mbedtls_x509write_crt_free(mbedtls_x509write_cert *ctx);
|
||||
* \param ctx certificate to write away
|
||||
* \param buf buffer to write to
|
||||
* \param size size of the buffer
|
||||
* \param f_rng RNG function (for signature, see note)
|
||||
* \param f_rng RNG function. This must not be \c NULL.
|
||||
* \param p_rng RNG parameter
|
||||
*
|
||||
* \return length of data written if successful, or a specific
|
||||
* error code
|
||||
*
|
||||
* \note f_rng may be NULL if RSA is used for signature and the
|
||||
* signature is made offline (otherwise f_rng is desirable
|
||||
* for countermeasures against timing attacks).
|
||||
* ECDSA signatures always require a non-NULL f_rng.
|
||||
* \note \p f_rng is used for the signature operation.
|
||||
*/
|
||||
int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
@@ -1071,15 +1186,12 @@ int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx, unsigned char *buf, s
|
||||
* \param ctx certificate to write away
|
||||
* \param buf buffer to write to
|
||||
* \param size size of the buffer
|
||||
* \param f_rng RNG function (for signature, see note)
|
||||
* \param f_rng RNG function. This must not be \c NULL.
|
||||
* \param p_rng RNG parameter
|
||||
*
|
||||
* \return 0 if successful, or a specific error code
|
||||
*
|
||||
* \note f_rng may be NULL if RSA is used for signature and the
|
||||
* signature is made offline (otherwise f_rng is desirable
|
||||
* for countermeasures against timing attacks).
|
||||
* ECDSA signatures always require a non-NULL f_rng.
|
||||
* \note \p f_rng is used for the signature operation.
|
||||
*/
|
||||
int mbedtls_x509write_crt_pem(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
|
||||
Reference in New Issue
Block a user