2021-01-05 23:34:27 +01:00
|
|
|
/*
|
|
|
|
* Common source code for SSL test programs. This file is included by
|
|
|
|
* both ssl_client2.c and ssl_server2.c and is intended for source
|
|
|
|
* code that is textually identical in both programs, but that cannot be
|
|
|
|
* compiled separately because it refers to types or macros that are
|
|
|
|
* different in the two programs, or because it would have an incomplete
|
|
|
|
* type.
|
|
|
|
*
|
|
|
|
* This file is meant to be #include'd and cannot be compiled separately.
|
|
|
|
*
|
|
|
|
* Copyright The Mbed TLS Contributors
|
2023-11-02 20:47:20 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
2021-01-05 23:34:27 +01:00
|
|
|
*/
|
2021-01-05 23:40:14 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void eap_tls_key_derivation(void *p_expkey,
|
|
|
|
mbedtls_ssl_key_export_type secret_type,
|
|
|
|
const unsigned char *secret,
|
|
|
|
size_t secret_len,
|
|
|
|
const unsigned char client_random[32],
|
|
|
|
const unsigned char server_random[32],
|
|
|
|
mbedtls_tls_prf_types tls_prf_type)
|
2021-01-05 23:40:14 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
eap_tls_keys *keys = (eap_tls_keys *) p_expkey;
|
2021-01-05 23:40:14 +01:00
|
|
|
|
2021-05-24 11:57:07 +02:00
|
|
|
/* We're only interested in the TLS 1.2 master secret */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (secret_type != MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET) {
|
2021-06-21 10:32:27 +02:00
|
|
|
return;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
|
|
|
if (secret_len != sizeof(keys->master_secret)) {
|
2021-06-21 10:32:27 +02:00
|
|
|
return;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-05-24 11:57:07 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memcpy(keys->master_secret, secret, sizeof(keys->master_secret));
|
|
|
|
memcpy(keys->randbytes, client_random, 32);
|
|
|
|
memcpy(keys->randbytes + 32, server_random, 32);
|
2021-01-05 23:40:14 +01:00
|
|
|
keys->tls_prf_type = tls_prf_type;
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void nss_keylog_export(void *p_expkey,
|
|
|
|
mbedtls_ssl_key_export_type secret_type,
|
|
|
|
const unsigned char *secret,
|
|
|
|
size_t secret_len,
|
|
|
|
const unsigned char client_random[32],
|
|
|
|
const unsigned char server_random[32],
|
|
|
|
mbedtls_tls_prf_types tls_prf_type)
|
2021-01-05 23:40:14 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
char nss_keylog_line[200];
|
2021-01-05 23:40:14 +01:00
|
|
|
size_t const client_random_len = 32;
|
|
|
|
size_t len = 0;
|
|
|
|
size_t j;
|
|
|
|
|
2021-05-24 11:57:07 +02:00
|
|
|
/* We're only interested in the TLS 1.2 master secret */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (secret_type != MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET) {
|
2021-06-21 10:32:27 +02:00
|
|
|
return;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-05-24 11:57:07 +02:00
|
|
|
|
2021-01-05 23:40:14 +01:00
|
|
|
((void) p_expkey);
|
|
|
|
((void) server_random);
|
|
|
|
((void) tls_prf_type);
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
len += sprintf(nss_keylog_line + len,
|
|
|
|
"%s", "CLIENT_RANDOM ");
|
2021-01-05 23:40:14 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
for (j = 0; j < client_random_len; j++) {
|
|
|
|
len += sprintf(nss_keylog_line + len,
|
|
|
|
"%02x", client_random[j]);
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
len += sprintf(nss_keylog_line + len, " ");
|
2021-01-05 23:40:14 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
for (j = 0; j < secret_len; j++) {
|
|
|
|
len += sprintf(nss_keylog_line + len,
|
|
|
|
"%02x", secret[j]);
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
len += sprintf(nss_keylog_line + len, "\n");
|
|
|
|
nss_keylog_line[len] = '\0';
|
2021-01-05 23:40:14 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_printf("\n");
|
|
|
|
mbedtls_printf("---------------- NSS KEYLOG -----------------\n");
|
|
|
|
mbedtls_printf("%s", nss_keylog_line);
|
|
|
|
mbedtls_printf("---------------------------------------------\n");
|
2021-01-05 23:40:14 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (opt.nss_keylog_file != NULL) {
|
2021-01-05 23:40:14 +01:00
|
|
|
FILE *f;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if ((f = fopen(opt.nss_keylog_file, "a")) == NULL) {
|
2021-01-05 23:40:14 +01:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2022-06-30 17:06:11 +02:00
|
|
|
/* Ensure no stdio buffering of secrets, as such buffers cannot be
|
|
|
|
* wiped. */
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_setbuf(f, NULL);
|
2022-06-30 17:06:11 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (fwrite(nss_keylog_line, 1, len, f) != len) {
|
|
|
|
fclose(f);
|
2021-01-05 23:40:14 +01:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
fclose(f);
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_platform_zeroize(nss_keylog_line,
|
|
|
|
sizeof(nss_keylog_line));
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#if defined(MBEDTLS_SSL_DTLS_SRTP)
|
|
|
|
void dtls_srtp_key_derivation(void *p_expkey,
|
|
|
|
mbedtls_ssl_key_export_type secret_type,
|
|
|
|
const unsigned char *secret,
|
|
|
|
size_t secret_len,
|
|
|
|
const unsigned char client_random[32],
|
|
|
|
const unsigned char server_random[32],
|
|
|
|
mbedtls_tls_prf_types tls_prf_type)
|
2021-01-05 23:40:14 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
dtls_srtp_keys *keys = (dtls_srtp_keys *) p_expkey;
|
2021-01-05 23:40:14 +01:00
|
|
|
|
2021-05-24 11:57:07 +02:00
|
|
|
/* We're only interested in the TLS 1.2 master secret */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (secret_type != MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET) {
|
2021-06-21 10:32:27 +02:00
|
|
|
return;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
|
|
|
if (secret_len != sizeof(keys->master_secret)) {
|
2021-06-21 10:32:27 +02:00
|
|
|
return;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-05-24 11:57:07 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memcpy(keys->master_secret, secret, sizeof(keys->master_secret));
|
|
|
|
memcpy(keys->randbytes, client_random, 32);
|
|
|
|
memcpy(keys->randbytes + 32, server_random, 32);
|
2021-01-05 23:40:14 +01:00
|
|
|
keys->tls_prf_type = tls_prf_type;
|
|
|
|
}
|
|
|
|
#endif /* MBEDTLS_SSL_DTLS_SRTP */
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
int ssl_check_record(mbedtls_ssl_context const *ssl,
|
|
|
|
unsigned char const *buf, size_t len)
|
2021-01-05 23:40:14 +01:00
|
|
|
{
|
2021-07-07 10:48:26 +02:00
|
|
|
int my_ret = 0, ret_cr1, ret_cr2;
|
2021-01-05 23:40:14 +01:00
|
|
|
unsigned char *tmp_buf;
|
|
|
|
|
|
|
|
/* Record checking may modify the input buffer,
|
|
|
|
* so make a copy. */
|
2023-01-11 14:50:10 +01:00
|
|
|
tmp_buf = mbedtls_calloc(1, len);
|
|
|
|
if (tmp_buf == NULL) {
|
|
|
|
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
|
|
|
|
}
|
|
|
|
memcpy(tmp_buf, buf, len);
|
|
|
|
|
|
|
|
ret_cr1 = mbedtls_ssl_check_record(ssl, tmp_buf, len);
|
|
|
|
if (ret_cr1 != MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) {
|
2021-01-05 23:40:14 +01:00
|
|
|
/* Test-only: Make sure that mbedtls_ssl_check_record()
|
|
|
|
* doesn't alter state. */
|
2023-01-11 14:50:10 +01:00
|
|
|
memcpy(tmp_buf, buf, len); /* Restore buffer */
|
|
|
|
ret_cr2 = mbedtls_ssl_check_record(ssl, tmp_buf, len);
|
|
|
|
if (ret_cr2 != ret_cr1) {
|
|
|
|
mbedtls_printf("mbedtls_ssl_check_record() returned inconsistent results.\n");
|
2021-07-07 10:48:26 +02:00
|
|
|
my_ret = -1;
|
2021-07-06 12:05:23 +02:00
|
|
|
goto cleanup;
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (ret_cr1) {
|
2021-01-05 23:40:14 +01:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MBEDTLS_ERR_SSL_INVALID_RECORD:
|
2023-01-11 14:50:10 +01:00
|
|
|
if (opt.debug_level > 1) {
|
|
|
|
mbedtls_printf("mbedtls_ssl_check_record() detected invalid record.\n");
|
|
|
|
}
|
2021-01-05 23:40:14 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MBEDTLS_ERR_SSL_INVALID_MAC:
|
2023-01-11 14:50:10 +01:00
|
|
|
if (opt.debug_level > 1) {
|
|
|
|
mbedtls_printf("mbedtls_ssl_check_record() detected unauthentic record.\n");
|
|
|
|
}
|
2021-01-05 23:40:14 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MBEDTLS_ERR_SSL_UNEXPECTED_RECORD:
|
2023-01-11 14:50:10 +01:00
|
|
|
if (opt.debug_level > 1) {
|
|
|
|
mbedtls_printf("mbedtls_ssl_check_record() detected unexpected record.\n");
|
|
|
|
}
|
2021-01-05 23:40:14 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_printf("mbedtls_ssl_check_record() failed fatally with -%#04x.\n",
|
|
|
|
(unsigned int) -ret_cr1);
|
2021-07-07 10:48:26 +02:00
|
|
|
my_ret = -1;
|
2021-07-06 12:05:23 +02:00
|
|
|
goto cleanup;
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Regardless of the outcome, forward the record to the stack. */
|
|
|
|
}
|
|
|
|
|
2021-07-06 12:05:23 +02:00
|
|
|
cleanup:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(tmp_buf);
|
2021-01-05 23:40:14 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return my_ret;
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
int recv_cb(void *ctx, unsigned char *buf, size_t len)
|
2021-01-05 23:40:14 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
io_ctx_t *io_ctx = (io_ctx_t *) ctx;
|
2021-01-05 23:40:14 +01:00
|
|
|
size_t recv_len;
|
|
|
|
int ret;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (opt.nbio == 2) {
|
|
|
|
ret = delayed_recv(io_ctx->net, buf, len);
|
|
|
|
} else {
|
|
|
|
ret = mbedtls_net_recv(io_ctx->net, buf, len);
|
|
|
|
}
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
2021-01-05 23:40:14 +01:00
|
|
|
recv_len = (size_t) ret;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
|
2021-01-05 23:40:14 +01:00
|
|
|
/* Here's the place to do any datagram/record checking
|
|
|
|
* in between receiving the packet from the underlying
|
|
|
|
* transport and passing it on to the TLS stack. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ssl_check_record(io_ctx->ssl, buf, recv_len) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return (int) recv_len;
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
int recv_timeout_cb(void *ctx, unsigned char *buf, size_t len,
|
|
|
|
uint32_t timeout)
|
2021-01-05 23:40:14 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
io_ctx_t *io_ctx = (io_ctx_t *) ctx;
|
2021-01-05 23:40:14 +01:00
|
|
|
int ret;
|
|
|
|
size_t recv_len;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
ret = mbedtls_net_recv_timeout(io_ctx->net, buf, len, timeout);
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
2021-01-05 23:40:14 +01:00
|
|
|
recv_len = (size_t) ret;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
|
2021-01-05 23:40:14 +01:00
|
|
|
/* Here's the place to do any datagram/record checking
|
|
|
|
* in between receiving the packet from the underlying
|
|
|
|
* transport and passing it on to the TLS stack. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ssl_check_record(io_ctx->ssl, buf, recv_len) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return (int) recv_len;
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
int send_cb(void *ctx, unsigned char const *buf, size_t len)
|
2021-01-05 23:40:14 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
io_ctx_t *io_ctx = (io_ctx_t *) ctx;
|
2021-01-05 23:40:14 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (opt.nbio == 2) {
|
|
|
|
return delayed_send(io_ctx->net, buf, len);
|
|
|
|
}
|
2021-01-05 23:40:14 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_net_send(io_ctx->net, buf, len);
|
2021-01-05 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
2023-02-22 12:38:54 +01:00
|
|
|
#if defined(MBEDTLS_PK_CAN_ECDSA_SOME) && defined(MBEDTLS_RSA_C)
|
2022-06-16 05:40:44 +02:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2022-06-23 04:16:33 +02:00
|
|
|
/*
|
2022-06-24 04:10:47 +02:00
|
|
|
* When GnuTLS/Openssl server is configured in TLS 1.2 mode with a certificate
|
|
|
|
* declaring an RSA public key and Mbed TLS is configured in hybrid mode, if
|
|
|
|
* `rsa_pss_rsae_*` algorithms are before `rsa_pkcs1_*` ones in this list then
|
2022-06-27 10:27:35 +02:00
|
|
|
* the GnuTLS/Openssl server chooses an `rsa_pss_rsae_*` signature algorithm
|
|
|
|
* for its signature in the key exchange message. As Mbed TLS 1.2 does not
|
2022-06-24 04:10:47 +02:00
|
|
|
* support them, the handshake fails.
|
2022-06-19 11:16:38 +02:00
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_SIG_ALG(hash) ((hash << 8) | MBEDTLS_SSL_SIG_ECDSA), \
|
|
|
|
((hash << 8) | MBEDTLS_SSL_SIG_RSA), \
|
|
|
|
(0x800 | hash),
|
2022-06-16 05:40:44 +02:00
|
|
|
#else
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_SIG_ALG(hash) ((hash << 8) | MBEDTLS_SSL_SIG_ECDSA), \
|
|
|
|
((hash << 8) | MBEDTLS_SSL_SIG_RSA),
|
2022-06-16 05:40:44 +02:00
|
|
|
#endif
|
2023-02-22 12:38:54 +01:00
|
|
|
#elif defined(MBEDTLS_PK_CAN_ECDSA_SOME)
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_SIG_ALG(hash) ((hash << 8) | MBEDTLS_SSL_SIG_ECDSA),
|
2022-01-12 11:43:08 +01:00
|
|
|
#elif defined(MBEDTLS_RSA_C)
|
2022-06-16 05:40:44 +02:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2022-06-19 11:16:38 +02:00
|
|
|
/* See above */
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_SIG_ALG(hash) ((hash << 8) | MBEDTLS_SSL_SIG_RSA), \
|
|
|
|
(0x800 | hash),
|
2022-06-16 05:40:44 +02:00
|
|
|
#else
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_SIG_ALG(hash) ((hash << 8) | MBEDTLS_SSL_SIG_RSA),
|
2022-06-16 05:40:44 +02:00
|
|
|
#endif
|
2022-01-12 11:43:08 +01:00
|
|
|
#else
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_SIG_ALG(hash)
|
2022-01-12 11:43:08 +01:00
|
|
|
#endif
|
2022-09-06 23:30:43 +02:00
|
|
|
|
2022-01-12 11:43:08 +01:00
|
|
|
uint16_t ssl_sig_algs_for_test[] = {
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA512)
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_SSL_SIG_ALG(MBEDTLS_SSL_HASH_SHA512)
|
2021-04-06 14:28:22 +02:00
|
|
|
#endif
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA384)
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_SSL_SIG_ALG(MBEDTLS_SSL_HASH_SHA384)
|
2021-01-05 23:40:14 +01:00
|
|
|
#endif
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA256)
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_SSL_SIG_ALG(MBEDTLS_SSL_HASH_SHA256)
|
2021-04-19 16:46:28 +02:00
|
|
|
#endif
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA224)
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_SSL_SIG_ALG(MBEDTLS_SSL_HASH_SHA224)
|
2021-01-05 23:40:14 +01:00
|
|
|
#endif
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_MD_CAN_SHA256)
|
2022-06-16 16:55:31 +02:00
|
|
|
MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256,
|
2023-03-17 12:50:01 +01:00
|
|
|
#endif /* MBEDTLS_RSA_C && MBEDTLS_MD_CAN_SHA256 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA1)
|
2021-01-05 23:40:14 +01:00
|
|
|
/* Allow SHA-1 as we use it extensively in tests. */
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_SSL_SIG_ALG(MBEDTLS_SSL_HASH_SHA1)
|
2021-01-05 23:40:14 +01:00
|
|
|
#endif
|
2022-01-12 11:43:08 +01:00
|
|
|
MBEDTLS_TLS1_3_SIG_NONE
|
2021-01-05 23:40:14 +01:00
|
|
|
};
|
|
|
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
2021-04-27 15:50:43 +02:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
|
|
|
/** Functionally equivalent to mbedtls_x509_crt_verify_info, see that function
|
|
|
|
* for more info.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
int x509_crt_verify_info(char *buf, size_t size, const char *prefix,
|
|
|
|
uint32_t flags)
|
2021-04-27 15:50:43 +02:00
|
|
|
{
|
2021-04-28 11:04:05 +02:00
|
|
|
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_x509_crt_verify_info(buf, size, prefix, flags);
|
2021-04-27 15:50:43 +02:00
|
|
|
|
|
|
|
#else /* !MBEDTLS_X509_REMOVE_INFO */
|
|
|
|
int ret;
|
|
|
|
char *p = buf;
|
|
|
|
size_t n = size;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define X509_CRT_ERROR_INFO(err, err_str, info) \
|
|
|
|
if ((flags & err) != 0) \
|
2021-04-27 15:50:43 +02:00
|
|
|
{ \
|
2023-01-11 14:50:10 +01:00
|
|
|
ret = mbedtls_snprintf(p, n, "%s%s\n", prefix, info); \
|
2021-04-27 15:50:43 +02:00
|
|
|
MBEDTLS_X509_SAFE_SNPRINTF; \
|
|
|
|
flags ^= err; \
|
|
|
|
}
|
|
|
|
|
|
|
|
MBEDTLS_X509_CRT_ERROR_INFO_LIST
|
|
|
|
#undef X509_CRT_ERROR_INFO
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (flags != 0) {
|
|
|
|
ret = mbedtls_snprintf(p, n, "%sUnknown reason "
|
|
|
|
"(this should not happen)\n", prefix);
|
2021-04-27 15:50:43 +02:00
|
|
|
MBEDTLS_X509_SAFE_SNPRINTF;
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return (int) (size - n);
|
2021-04-27 15:50:43 +02:00
|
|
|
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
|
|
|
}
|
|
|
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
2022-06-27 10:21:00 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_print_supported_sig_algs(void)
|
2022-06-27 10:21:00 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_printf("supported signature algorithms:\n");
|
2022-06-27 10:21:00 +02:00
|
|
|
mbedtls_printf("\trsa_pkcs1_sha256 ");
|
|
|
|
mbedtls_printf("rsa_pkcs1_sha384 ");
|
|
|
|
mbedtls_printf("rsa_pkcs1_sha512\n");
|
|
|
|
mbedtls_printf("\tecdsa_secp256r1_sha256 ");
|
|
|
|
mbedtls_printf("ecdsa_secp384r1_sha384 ");
|
|
|
|
mbedtls_printf("ecdsa_secp521r1_sha512\n");
|
|
|
|
mbedtls_printf("\trsa_pss_rsae_sha256 ");
|
|
|
|
mbedtls_printf("rsa_pss_rsae_sha384 ");
|
|
|
|
mbedtls_printf("rsa_pss_rsae_sha512\n");
|
|
|
|
mbedtls_printf("\trsa_pss_pss_sha256 ");
|
|
|
|
mbedtls_printf("rsa_pss_pss_sha384 ");
|
|
|
|
mbedtls_printf("rsa_pss_pss_sha512\n");
|
|
|
|
mbedtls_printf("\ted25519 ");
|
|
|
|
mbedtls_printf("ed448 ");
|
|
|
|
mbedtls_printf("rsa_pkcs1_sha1 ");
|
|
|
|
mbedtls_printf("ecdsa_sha1\n");
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_printf("\n");
|
2022-06-27 10:27:35 +02:00
|
|
|
}
|