mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-10-28 18:07:34 +08:00
Compare commits
7 Commits
446c10b8a8
...
bc66dc9c5d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc66dc9c5d | ||
|
|
d8d5ea7cbc | ||
|
|
433c88651a | ||
|
|
7de85af87f | ||
|
|
14b15fcabf | ||
|
|
49fe7fc873 | ||
|
|
fe0c44827a |
5
ChangeLog.d/fix-x509-profile-pk-sigalg.txt
Normal file
5
ChangeLog.d/fix-x509-profile-pk-sigalg.txt
Normal file
@ -0,0 +1,5 @@
|
||||
Bugfix
|
||||
* Fix X.509 certificate profile checks to correctly map internal PK types
|
||||
to public signature algorithm identifiers. Previously, ECKEY certificates
|
||||
were incorrectly rejected when MBEDTLS_PK_SIGALG_ECDSA was allowed in a
|
||||
custom profile. Fixes #10849 and #10747.
|
||||
4
ChangeLog.d/tls13-transform-resource-leak.txt
Normal file
4
ChangeLog.d/tls13-transform-resource-leak.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Bugfix
|
||||
* Fix a resource leak in TLS 1.3 transform setup when importing the
|
||||
decryption traffic key fails after the encryption traffic key has already
|
||||
been imported. Fixes #10917.
|
||||
@ -1034,6 +1034,8 @@ int mbedtls_ssl_tls13_populate_transform(
|
||||
&transform->psa_key_dec)) != PSA_SUCCESS) {
|
||||
MBEDTLS_SSL_DEBUG_RET(
|
||||
1, "psa_import_key", PSA_TO_MBEDTLS_ERR(status));
|
||||
psa_destroy_key(transform->psa_key_enc);
|
||||
transform->psa_key_enc = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
return PSA_TO_MBEDTLS_ERR(status);
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,6 +181,24 @@ int mbedtls_x509_profile_check_md_alg(const mbedtls_x509_crt_profile *profile,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Map an internal pk_type to the public pk_sigalg_t used in profiles.
|
||||
*
|
||||
* This is needed because mbedtls_pk_type_t and mbedtls_pk_sigalg_t have
|
||||
* different numerical values for the same logical algorithms.
|
||||
*/
|
||||
static mbedtls_pk_sigalg_t x509_pk_type_to_sigalg(mbedtls_pk_type_t pk_type)
|
||||
{
|
||||
switch (pk_type) {
|
||||
case MBEDTLS_PK_RSA: return MBEDTLS_PK_SIGALG_RSA_PKCS1V15;
|
||||
case MBEDTLS_PK_RSASSA_PSS: return MBEDTLS_PK_SIGALG_RSA_PSS;
|
||||
case MBEDTLS_PK_ECKEY:
|
||||
case MBEDTLS_PK_ECKEY_DH:
|
||||
case MBEDTLS_PK_ECDSA: return MBEDTLS_PK_SIGALG_ECDSA;
|
||||
default: return MBEDTLS_PK_SIGALG_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
int mbedtls_x509_profile_check_pk_alg(const mbedtls_x509_crt_profile *profile,
|
||||
mbedtls_pk_sigalg_t pk_alg)
|
||||
{
|
||||
@ -3074,7 +3092,7 @@ static int x509_crt_verify_restartable_ca_cb(mbedtls_x509_crt *crt,
|
||||
/* Check the type and size of the key */
|
||||
pk_type = mbedtls_pk_get_type(&crt->pk);
|
||||
|
||||
if (mbedtls_x509_profile_check_pk_alg(profile, (mbedtls_pk_sigalg_t) pk_type) != 0) {
|
||||
if (mbedtls_x509_profile_check_pk_alg(profile, x509_pk_type_to_sigalg(pk_type)) != 0) {
|
||||
ee_flags |= MBEDTLS_X509_BADCERT_BAD_PK;
|
||||
}
|
||||
|
||||
|
||||
@ -2856,6 +2856,9 @@ SSL TLS 1.3 Record Encryption RFC 8448 Example #2
|
||||
depends_on:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_GCM:PSA_WANT_ALG_SHA_256
|
||||
ssl_tls13_record_protection:MBEDTLS_TLS1_3_AES_128_GCM_SHA256:MBEDTLS_SSL_IS_SERVER:1:1:"9f02283b6c9c07efc26bb9f2ac92e356":"cf782b88dd83549aadf1e984":"17422dda596ed5d9acd890e3c63f5051":"5b78923dee08579033e523d9":"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031":"2e937e11ef4ac740e538ad36005fc4a46932fc3225d05f82aa1b36e30efaf97d90e6dffc602dcb501a59a8fcc49c4bf2e5f0a21c0047c2abf332540dd032e167c2955d"
|
||||
|
||||
TLS 1.3 transform frees encryption key if decryption key import fails
|
||||
ssl_tls13_populate_transform_second_key_import_failure
|
||||
|
||||
SSL TLS 1.3 Key schedule: Application secrets derivation helper
|
||||
# Vector from RFC 8448
|
||||
depends_on:PSA_WANT_ALG_SHA_256
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#endif /* MBEDTLS_PK_HAVE_PRIVATE_HEADER */
|
||||
#include <ssl_tls13_keys.h>
|
||||
#include <ssl_tls13_invasive.h>
|
||||
#include <psa_crypto_slot_management.h>
|
||||
#include <test/ssl_helpers.h>
|
||||
#include <test/ssl_helpers_internal.h>
|
||||
|
||||
@ -114,6 +115,36 @@ static void tls_abort_transcript(void *ctx, int level,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PSA_KEY_STORE_DYNAMIC)
|
||||
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_SSL_CLI_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C)
|
||||
#define SSL_TEST_KEY_SLICE_1_LENGTH 4
|
||||
#define SSL_TEST_KEY_SLICE_2_LENGTH 10
|
||||
static size_t ssl_test_tiny_key_slice_length(size_t slice_idx)
|
||||
{
|
||||
switch (slice_idx) {
|
||||
case 1: return SSL_TEST_KEY_SLICE_1_LENGTH;
|
||||
case 2: return SSL_TEST_KEY_SLICE_2_LENGTH;
|
||||
default: return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* In the below definition SSL_TEST_KEY_SLICE_1_LENGTH has 4 slots and
|
||||
* SSL_TEST_KEY_SLICE_2_LENGTH has 10 all other slices have 1.
|
||||
* psa_key_slot_volatile_slice_count() returns the total number of slices.
|
||||
* However we have already countes slices 1 and 2, so we mustr subtract 2 from
|
||||
* this number to avoid double counting.
|
||||
*/
|
||||
|
||||
#define SSL_TEST_MAX_VOLATILE_KEYS \
|
||||
(SSL_TEST_KEY_SLICE_1_LENGTH + \
|
||||
SSL_TEST_KEY_SLICE_2_LENGTH + \
|
||||
psa_key_slot_volatile_slice_count() - 2)
|
||||
#endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_SSL_CLI_C */
|
||||
#else /* MBEDTLS_PSA_KEY_STORE_DYNAMIC */
|
||||
#define SSL_TEST_MAX_VOLATILE_KEYS MBEDTLS_PSA_KEY_SLOT_COUNT
|
||||
#endif /* MBEDTLS_PSA_KEY_STORE_DYNAMIC */
|
||||
|
||||
#if (!defined(MBEDTLS_SSL_PROTO_TLS1_2)) && \
|
||||
defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_CLI_C) && \
|
||||
defined(MBEDTLS_SSL_SRV_C) && defined(MBEDTLS_DEBUG_C) && \
|
||||
@ -2489,6 +2520,85 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3:MBEDTLS_SSL_CLI_C:SSL_TEST_MAX_VOLATILE_KEYS:MBEDTLS_PSA_CRYPTO_C */
|
||||
void ssl_tls13_populate_transform_second_key_import_failure(void)
|
||||
{
|
||||
mbedtls_ssl_key_set traffic_keys;
|
||||
mbedtls_ssl_transform transform;
|
||||
mbedtls_svc_key_id_t *keys = NULL;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
mbedtls_psa_stats_t stats_before, stats_after;
|
||||
psa_status_t status = PSA_SUCCESS;
|
||||
size_t i = 0;
|
||||
|
||||
memset(&traffic_keys, 0, sizeof(traffic_keys));
|
||||
mbedtls_ssl_transform_init(&transform);
|
||||
|
||||
#if defined(MBEDTLS_PSA_KEY_STORE_DYNAMIC) && defined(MBEDTLS_TEST_HOOKS)
|
||||
mbedtls_test_hook_psa_volatile_key_slice_length =
|
||||
ssl_test_tiny_key_slice_length;
|
||||
#endif
|
||||
|
||||
PSA_INIT();
|
||||
TEST_CALLOC(keys, SSL_TEST_MAX_VOLATILE_KEYS + 1);
|
||||
|
||||
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
|
||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_RAW_DATA);
|
||||
|
||||
/* Allow one more attempt than the maximum number of volatile keys so
|
||||
* that the loop ends because the key store is full. */
|
||||
while (i <= SSL_TEST_MAX_VOLATILE_KEYS) {
|
||||
status = psa_import_key(&attributes,
|
||||
(const uint8_t *) &i, sizeof(i),
|
||||
&keys[i]);
|
||||
if (status == PSA_ERROR_INSUFFICIENT_MEMORY) {
|
||||
break;
|
||||
}
|
||||
PSA_ASSERT(status);
|
||||
i++;
|
||||
}
|
||||
TEST_EQUAL(status, PSA_ERROR_INSUFFICIENT_MEMORY);
|
||||
TEST_ASSERT(i > 0);
|
||||
|
||||
/* Leave exactly one slot free: the encryption key import consumes it,
|
||||
* then the decryption key import fails. */
|
||||
PSA_ASSERT(psa_destroy_key(keys[--i]));
|
||||
keys[i] = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
mbedtls_psa_get_stats(&stats_before);
|
||||
|
||||
traffic_keys.key_len = 16;
|
||||
traffic_keys.iv_len = 12;
|
||||
TEST_ASSERT(mbedtls_ssl_tls13_populate_transform(
|
||||
&transform, MBEDTLS_SSL_IS_CLIENT,
|
||||
MBEDTLS_TLS1_3_AES_128_GCM_SHA256,
|
||||
&traffic_keys, NULL) != 0);
|
||||
|
||||
/* The first import must be rolled back when the second one fails. */
|
||||
TEST_ASSERT(mbedtls_svc_key_id_is_null(transform.psa_key_enc));
|
||||
|
||||
/* Also check the key store itself: the failed operation must neither
|
||||
* consume a slot nor leave the only free slot unusable. */
|
||||
mbedtls_psa_get_stats(&stats_after);
|
||||
TEST_EQUAL(stats_after.volatile_slots, stats_before.volatile_slots);
|
||||
TEST_EQUAL(stats_after.empty_slots, stats_before.empty_slots);
|
||||
PSA_ASSERT(psa_import_key(&attributes,
|
||||
(const uint8_t *) &i, sizeof(i),
|
||||
&keys[i]));
|
||||
i++;
|
||||
|
||||
exit:
|
||||
mbedtls_ssl_transform_free(&transform);
|
||||
while (i > 0) {
|
||||
psa_destroy_key(keys[--i]);
|
||||
}
|
||||
mbedtls_free(keys);
|
||||
PSA_DONE();
|
||||
#if defined(MBEDTLS_PSA_KEY_STORE_DYNAMIC) && defined(MBEDTLS_TEST_HOOKS)
|
||||
mbedtls_test_hook_psa_volatile_key_slice_length = NULL;
|
||||
#endif
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3 */
|
||||
void ssl_tls13_key_evolution(int hash_alg,
|
||||
data_t *secret,
|
||||
|
||||
@ -2768,6 +2768,10 @@ X509 CRT verify chain #25 (len=3, vrfy fatal on depth 3, untrusted)
|
||||
depends_on:PSA_WANT_ALG_SHA_256:PSA_HAVE_ALG_ECDSA_VERIFY:PSA_WANT_ECC_SECP_R1_256:PSA_HAVE_ALG_SOME_RSA_VERIFY:PSA_WANT_ALG_SHA_1:PSA_WANT_ECC_SECP_R1_384
|
||||
mbedtls_x509_crt_verify_chain:"../framework/data_files/server10_int3_int-ca2_ca.crt":"../framework/data_files/test-ca2.crt":-1:-4:"":8
|
||||
|
||||
X509 CRT verify chain #26 (ECDSA-only profile, EC self-signed cert)
|
||||
depends_on:PSA_WANT_ALG_SHA_256:PSA_HAVE_ALG_ECDSA_VERIFY:PSA_WANT_ECC_SECP_R1_256
|
||||
mbedtls_x509_crt_verify_chain:"../framework/data_files/server5-selfsigned.crt":"../framework/data_files/server5-selfsigned.crt":0:0:"ecdsa_only":0
|
||||
|
||||
X509 OID description #1
|
||||
x509_oid_desc:"2b06010505070301":"TLS Web Server Authentication"
|
||||
|
||||
|
||||
@ -58,6 +58,14 @@ const mbedtls_x509_crt_profile profile_rsa3072 =
|
||||
3072,
|
||||
};
|
||||
|
||||
const mbedtls_x509_crt_profile profile_ecdsa_only =
|
||||
{
|
||||
0xFFFFFFFF, /* Any MD */
|
||||
MBEDTLS_X509_ID_FLAG(MBEDTLS_PK_SIGALG_ECDSA),
|
||||
0xFFFFFFFF, /* Any curve */
|
||||
1024,
|
||||
};
|
||||
|
||||
const mbedtls_x509_crt_profile profile_sha512 =
|
||||
{
|
||||
MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512),
|
||||
@ -1530,6 +1538,8 @@ void mbedtls_x509_crt_verify_chain(char *chain_paths, char *trusted_ca,
|
||||
profile = &profile_rsa3072;
|
||||
} else if (strcmp(profile_name, "sha512") == 0) {
|
||||
profile = &profile_sha512;
|
||||
} else if (strcmp(profile_name, "ecdsa_only") == 0) {
|
||||
profile = &profile_ecdsa_only;
|
||||
}
|
||||
|
||||
res = mbedtls_x509_crt_verify_with_profile(&chain, &trusted, NULL, profile,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user