Go to the documentation of this file.
32 #define TRACE_LEVEL TLS_TRACE_LEVEL
49 #if (TLS_SUPPORT == ENABLED)
76 if(context->cert != NULL)
79 certChain = context->cert->certChain;
81 certChainLen = context->cert->certChainLen;
92 while(certChainLen > 0)
106 if((*written +
n + 3) > context->txBufferMaxLen)
130 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
171 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
173 if(context->cert != NULL)
189 context->cert->certChainLen, NULL, &derCertLen, NULL);
205 context->cert->certChainLen, derCert, &derCertLen, NULL);
228 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
288 const uint8_t *
p,
size_t length)
294 const char_t *subjectName;
300 issuerCertInfo = NULL;
318 if(issuerCertInfo == NULL)
365 context->keyExchMethod);
377 #if (TLS_CLIENT_SUPPORT == ENABLED)
406 subjectName = context->serverName;
438 error = certValidResult;
446 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
464 for(i = 0;
length > 0; i++)
543 error = certValidResult;
549 *certInfo = *issuerCertInfo;
555 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
607 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
609 if(context->rpkVerifyCallback != NULL)
612 size_t rawPublicKeyLen;
613 const uint8_t *rawPublicKey;
616 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
632 if(
length < rawPublicKeyLen)
648 &subjectPublicKeyInfo);
654 p += rawPublicKeyLen;
656 length -= rawPublicKeyLen;
658 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
690 error = context->rpkVerifyCallback(context, rawPublicKey,
721 const TlsCertDesc *cert,
const uint8_t *certTypes,
size_t numCertTypes,
738 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1)
770 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
775 if(acceptable && certTypes != NULL)
778 for(i = 0, acceptable =
FALSE; i < numCertTypes && !acceptable; i++)
820 if(acceptable && curveList != NULL)
823 n =
ntohs(curveList->length) /
sizeof(uint16_t);
826 for(i = 0, acceptable =
FALSE; i <
n && !acceptable; i++)
839 #if (TLS_SM2_SIGN_SUPPORT == ENABLED)
853 if(acceptable && certSignAlgoList != NULL)
856 n =
ntohs(certSignAlgoList->length) /
sizeof(uint16_t);
859 for(i = 0, acceptable =
FALSE; i <
n && !acceptable; i++)
870 if(acceptable && certAuthorities != NULL)
903 while(certChainLen > 0 && !acceptable)
908 &derCertLen, &pemCertLen);
921 derCert, &derCertLen, NULL);
935 for(i = 0; i <
length; i +=
n + 2)
943 n =
LOAD16BE(certAuthorities->value + i);
965 certChain += pemCertLen;
966 certChainLen -= pemCertLen;
1000 const char_t *trustedCaList;
1001 size_t trustedCaListLen;
1010 if(context->certVerifyCallback != NULL)
1013 error = context->certVerifyCallback(context, certInfo, pathLen,
1014 context->certVerifyParam);
1025 if(context->trustedCaListLen > 0)
1028 trustedCaList = context->trustedCaList;
1030 trustedCaListLen = context->trustedCaListLen;
1036 if(caCertInfo != NULL)
1044 NULL, &derCertLen, &pemCertLen);
1057 trustedCaListLen, derCert, &derCertLen, NULL);
1104 trustedCaList += pemCertLen;
1105 trustedCaListLen -= pemCertLen;
1110 trustedCaListLen = 0;
1165 if(certInfo == NULL || certType == NULL || namedCurve == NULL)
1172 #if (TLS_RSA_SIGN_SUPPORT == ENABLED || TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
1183 #if (TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
1194 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
1205 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED || TLS_SM2_SIGN_SUPPORT == ENABLED)
1238 #if (TLS_ED25519_SIGN_SUPPORT == ENABLED)
1249 #if (TLS_ED448_SIGN_SUPPORT == ENABLED)
1285 if(certInfo == NULL || signScheme == NULL)
1292 #if (RSA_SUPPORT == ENABLED)
1326 #if (RSA_SUPPORT == ENABLED && X509_RSA_PSS_SUPPORT == ENABLED)
1334 #if (SHA256_SUPPORT == ENABLED)
1343 #if (SHA384_SUPPORT == ENABLED)
1352 #if (SHA512_SUPPORT == ENABLED)
1369 #if (DSA_SUPPORT == ENABLED)
1391 #if (ECDSA_SUPPORT == ENABLED)
1425 #if (SM2_SUPPORT == ENABLED)
1434 #if (ED25519_SUPPORT == ENABLED)
1443 #if (ED448_SUPPORT == ENABLED)
1481 #if (TLS_RSA_SIGN_SUPPORT == ENABLED || TLS_RSA_PSS_SIGN_SUPPORT == ENABLED)
1490 &context->peerRsaPublicKey);
1530 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
1538 &context->peerDsaPublicKey);
1563 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED || TLS_SM2_SIGN_SUPPORT == ENABLED)
1574 if(curveInfo != NULL)
1583 error =
ecImport(&context->peerEcParams, &context->peerEcPublicKey.q,
1614 #if (TLS_ED25519_SIGN_SUPPORT == ENABLED || TLS_ED448_SIGN_SUPPORT == ENABLED)
1625 if(curveInfo != NULL)
1634 error =
ecImport(&context->peerEcParams, &context->peerEcPublicKey.q,
1674 #if (TLS_CLIENT_SUPPORT == ENABLED)
1755 #if (TLS_CERT_KEY_USAGE_SUPPORT == ENABLED)
1767 if(keyUsage->
bitmap != 0)
1820 if(extKeyUsage->
bitmap != 0)
#define tlsAllocMem(size)
X.509 certificate parsing.
X509SignAlgoId signatureAlgo
error_t x509ValidateCertificate(const X509CertInfo *certInfo, const X509CertInfo *issuerCertInfo, uint_t pathLen)
X.509 certificate validation.
const uint8_t DSA_WITH_SHA224_OID[9]
X509TbsCertificate tbsCert
const EcCurveInfo * x509GetCurveInfo(const uint8_t *oid, size_t length)
Get the elliptic curve that matches the specified OID.
const uint8_t MD5_WITH_RSA_ENCRYPTION_OID[9]
const uint8_t SHA512_WITH_RSA_ENCRYPTION_OID[9]
error_t x509ImportRsaPublicKey(const X509SubjectPublicKeyInfo *publicKeyInfo, RsaPublicKey *publicKey)
Import an RSA public key.
#define TLS_MAX_DSA_MODULUS_SIZE
__weak_func error_t tlsParseCertificateList(TlsContext *context, const uint8_t *p, size_t length)
Parse certificate chain.
@ ERROR_UNKNOWN_CERTIFICATE
error_t ecImport(const EcDomainParameters *params, EcPoint *r, const uint8_t *data, size_t length)
Convert an octet string to an EC point.
X509Extensions extensions
error_t x509ParseSubjectPublicKeyInfo(const uint8_t *data, size_t length, size_t *totalLength, X509SubjectPublicKeyInfo *publicKeyInfo)
Parse SubjectPublicKeyInfo structure.
TlsConnectionEnd
TLS connection end.
error_t x509ParseCertificate(const uint8_t *data, size_t length, X509CertInfo *certInfo)
Parse a X.509 certificate.
bool_t tlsIsCertificateAcceptable(TlsContext *context, const TlsCertDesc *cert, const uint8_t *certTypes, size_t numCertTypes, const TlsSupportedGroupList *curveList, const TlsSignSchemeList *certSignAlgoList, const TlsCertAuthorities *certAuthorities)
Check whether a certificate is acceptable.
const uint8_t EC_PUBLIC_KEY_OID[7]
TlsCertificateType type
End entity certificate type.
X509EcParameters ecParams
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA512
X509ExtendedKeyUsage extKeyUsage
error_t asn1DumpObject(const uint8_t *data, size_t length, uint_t level)
Display an ASN.1 data object.
@ X509_EXT_KEY_USAGE_CLIENT_AUTH
@ ERROR_UNSUPPORTED_CERTIFICATE
@ TLS_SIGN_SCHEME_ED25519
error_t tlsReadSubjectPublicKey(TlsContext *context, const X509SubjectPublicKeyInfo *subjectPublicKeyInfo)
Extract the subject public key from the received certificate.
const uint8_t RSASSA_PSS_OID[9]
const uint8_t ECDSA_WITH_SHA256_OID[8]
@ ERROR_CERTIFICATE_REVOKED
int_t oidComp(const uint8_t *oid1, size_t oidLen1, const uint8_t *oid2, size_t oidLen2)
Compare object identifiers.
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA384
error_t tls13ParseCertExtensions(const uint8_t *p, size_t length, size_t *consumed)
Parse certificate extensions.
bool_t x509CompareName(const uint8_t *name1, size_t nameLen1, const uint8_t *name2, size_t nameLen2)
Compare distinguished names.
const uint8_t SHA384_WITH_RSA_ENCRYPTION_OID[9]
error_t tlsValidateCertificate(TlsContext *context, const X509CertInfo *certInfo, uint_t pathLen, const char_t *subjectName)
Verify certificate against root CAs.
@ TLS_KEY_EXCH_ECDHE_ECDSA
error_t ecLoadDomainParameters(EcDomainParameters *params, const EcCurveInfo *curveInfo)
Load EC domain parameters.
size_t certChainLen
Length of the certificate chain.
error_t pemImportCertificate(const char_t *input, size_t inputLen, uint8_t *output, size_t *outputLen, size_t *consumed)
Decode a PEM file containing a certificate.
Elliptic curve parameters.
PEM file import functions.
@ ERROR_INVALID_PARAMETER
Invalid parameter.
#define osMemcpy(dest, src, length)
error_t x509ImportDsaPublicKey(const X509SubjectPublicKeyInfo *publicKeyInfo, DsaPublicKey *publicKey)
Import a DSA public key.
@ TLS_SIGN_SCHEME_RSA_PSS_PSS_SHA256
@ TLS_CONNECTION_END_SERVER
TlsKeyExchMethod
Key exchange methods.
Extended Key Usage extension.
const uint8_t SHA256_OID[9]
TlsSignatureScheme signScheme
Signature scheme used to sign the end entity certificate.
const uint8_t ECDSA_WITH_SHA384_OID[8]
error_t tlsFormatRawPublicKey(TlsContext *context, uint8_t *p, size_t *written)
Format raw public key.
@ X509_EXT_KEY_USAGE_SERVER_AUTH
@ X509_KEY_USAGE_DIGITAL_SIGNATURE
TlsNamedGroup tlsGetNamedCurve(const uint8_t *oid, size_t length)
Get the named curve that matches the specified OID.
const uint8_t SM2_WITH_SM3_OID[8]
error_t tls13FormatCertExtensions(uint8_t *p, size_t *written)
Format certificate extensions.
const uint8_t ECDSA_WITH_SHA1_OID[7]
const uint8_t ECDSA_WITH_SHA224_OID[8]
error_t tlsCheckKeyUsage(const X509CertInfo *certInfo, TlsConnectionEnd entity, TlsKeyExchMethod keyExchMethod)
Check certificate key usage.
const uint8_t SHA256_WITH_RSA_ENCRYPTION_OID[9]
X509OctetString namedCurve
TlsCertificateType
Certificate types.
const uint8_t ED448_OID[3]
error_t tlsFormatCertificateList(TlsContext *context, uint8_t *p, size_t *written)
Format certificate chain.
error_t x509CheckNameConstraints(const char_t *subjectName, const X509CertInfo *certInfo)
Check name constraints.
uint_t mpiGetBitLength(const Mpi *a)
Get the actual length in bits.
const uint8_t ECDSA_WITH_SHA512_OID[8]
const uint8_t ED25519_OID[3]
const uint8_t RSA_ENCRYPTION_OID[9]
#define TRACE_WARNING(...)
error_t tlsParseRawPublicKey(TlsContext *context, const uint8_t *p, size_t length)
Parse raw public key.
Subject Public Key Information extension.
@ TLS_SIGN_SCHEME_SM2SIG_SM3
#define TLS_MAX_RSA_MODULUS_SIZE
error_t tlsGetCertificateSignAlgo(const X509CertInfo *certInfo, TlsSignatureScheme *signScheme)
Retrieve the signature algorithm used to sign the certificate.
@ ERROR_CERTIFICATE_EXPIRED
const uint8_t DSA_WITH_SHA1_OID[7]
@ TLS_CONNECTION_END_CLIENT
const uint8_t DSA_WITH_SHA256_OID[9]
X.509 certificate handling.
Helper functions for signature generation and verification.
const EcCurveInfo * tlsGetCurveInfo(TlsContext *context, uint16_t namedCurve)
Get the EC domain parameters that match the specified named curve.
TLS (Transport Layer Security)
const uint8_t SHA512_OID[9]
X.509 certificate validation.
error_t x509CheckSubjectName(const X509CertInfo *certInfo, const char_t *fqdn)
Check whether the certificate matches the specified FQDN.
const char_t * certChain
End entity certificate chain (PEM format)
#define TLS_SIGN_ALGO(signScheme)
error_t tlsGetCertificateType(const X509CertInfo *certInfo, TlsCertificateType *certType, TlsNamedGroup *namedCurve)
Retrieve the certificate type.
Parsing of ASN.1 encoded keys.
TlsNamedGroup
Named groups.
TlsSignatureScheme
Signature schemes.
@ X509_KEY_USAGE_KEY_ENCIPHERMENT
X509EcPublicKey ecPublicKey
X509SubjectPublicKeyInfo subjectPublicKeyInfo
const uint8_t SHA384_OID[9]
X509RsaPssParameters rsaPssParams
#define TLS_SIGN_SCHEME(signAlgo, hashAlgo)
const uint8_t SHA1_WITH_RSA_ENCRYPTION_OID[9]
TlsNamedGroup namedCurve
Named curve used to generate the EC public key.
ASN.1 (Abstract Syntax Notation One)