Merge pull request #9492 from eleuzi01/remove-legacy-symbol-definitions
Remove definitions of legacy symbols
diff --git a/ChangeLog.d/split-numeric-string-conversions-out-of-the-oid-module.txt b/ChangeLog.d/split-numeric-string-conversions-out-of-the-oid-module.txt
new file mode 100644
index 0000000..938e9ec
--- /dev/null
+++ b/ChangeLog.d/split-numeric-string-conversions-out-of-the-oid-module.txt
@@ -0,0 +1,4 @@
+Changes
+ * Functions regarding numeric string conversions for OIDs have been moved
+ from the OID module and now reside in X.509 module. This helps to reduce
+ the code size as these functions are not commonly used outside of X.509.
diff --git a/include/mbedtls/x509.h b/include/mbedtls/x509.h
index 453f598..18df19c 100644
--- a/include/mbedtls/x509.h
+++ b/include/mbedtls/x509.h
@@ -492,6 +492,38 @@
p += (size_t) ret; \
} while (0)
+/**
+ * \brief Translate an ASN.1 OID into its numeric representation
+ * (e.g. "\x2A\x86\x48\x86\xF7\x0D" into "1.2.840.113549")
+ *
+ * \param buf buffer to put representation in
+ * \param size size of the buffer
+ * \param oid OID to translate
+ *
+ * \return Length of the string written (excluding final NULL) or
+ * MBEDTLS_ERR_OID_BUF_TOO_SMALL in case of error
+ */
+int mbedtls_oid_get_numeric_string(char *buf, size_t size, const mbedtls_asn1_buf *oid);
+
+/**
+ * \brief Translate a string containing a dotted-decimal
+ * representation of an ASN.1 OID into its encoded form
+ * (e.g. "1.2.840.113549" into "\x2A\x86\x48\x86\xF7\x0D").
+ * On success, this function allocates oid->buf from the
+ * heap. It must be freed by the caller using mbedtls_free().
+ *
+ * \param oid #mbedtls_asn1_buf to populate with the DER-encoded OID
+ * \param oid_str string representation of the OID to parse
+ * \param size length of the OID string, not including any null terminator
+ *
+ * \return 0 if successful
+ * \return #MBEDTLS_ERR_ASN1_INVALID_DATA if \p oid_str does not
+ * represent a valid OID
+ * \return #MBEDTLS_ERR_ASN1_ALLOC_FAILED if the function fails to
+ * allocate oid->buf
+ */
+int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid, const char *oid_str, size_t size);
+
#ifdef __cplusplus
}
#endif
diff --git a/library/x509.c b/library/x509.c
index a80ab53..be7b277 100644
--- a/library/x509.c
+++ b/library/x509.c
@@ -805,6 +805,75 @@
return (i < 10) ? (i + '0') : (i - 10 + 'A');
}
+/* Return the x.y.z.... style numeric string for the given OID */
+int mbedtls_oid_get_numeric_string(char *buf, size_t size,
+ const mbedtls_asn1_buf *oid)
+{
+ int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+ char *p = buf;
+ size_t n = size;
+ unsigned int value = 0;
+
+ if (size > INT_MAX) {
+ /* Avoid overflow computing return value */
+ return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
+ }
+
+ if (oid->len <= 0) {
+ /* OID must not be empty */
+ return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
+ }
+
+ for (size_t i = 0; i < oid->len; i++) {
+ /* Prevent overflow in value. */
+ if (value > (UINT_MAX >> 7)) {
+ return MBEDTLS_ERR_ASN1_INVALID_DATA;
+ }
+ if ((value == 0) && ((oid->p[i]) == 0x80)) {
+ /* Overlong encoding is not allowed */
+ return MBEDTLS_ERR_ASN1_INVALID_DATA;
+ }
+
+ value <<= 7;
+ value |= oid->p[i] & 0x7F;
+
+ if (!(oid->p[i] & 0x80)) {
+ /* Last byte */
+ if (n == size) {
+ int component1;
+ unsigned int component2;
+ /* First subidentifier contains first two OID components */
+ if (value >= 80) {
+ component1 = '2';
+ component2 = value - 80;
+ } else if (value >= 40) {
+ component1 = '1';
+ component2 = value - 40;
+ } else {
+ component1 = '0';
+ component2 = value;
+ }
+ ret = mbedtls_snprintf(p, n, "%c.%u", component1, component2);
+ } else {
+ ret = mbedtls_snprintf(p, n, ".%u", value);
+ }
+ if (ret < 2 || (size_t) ret >= n) {
+ return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
+ }
+ n -= (size_t) ret;
+ p += ret;
+ value = 0;
+ }
+ }
+
+ if (value != 0) {
+ /* Unterminated subidentifier */
+ return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
+ }
+
+ return (int) (size - n);
+}
+
/*
* Store the name in printable form into buf; no more
* than size characters will be written
diff --git a/library/x509_create.c b/library/x509_create.c
index 839b5df..1309831 100644
--- a/library/x509_create.c
+++ b/library/x509_create.c
@@ -278,6 +278,182 @@
return MBEDTLS_ERR_X509_INVALID_NAME;
}
+static int oid_parse_number(unsigned int *num, const char **p, const char *bound)
+{
+ int ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+
+ *num = 0;
+
+ while (*p < bound && **p >= '0' && **p <= '9') {
+ ret = 0;
+ if (*num > (UINT_MAX / 10)) {
+ return MBEDTLS_ERR_ASN1_INVALID_DATA;
+ }
+ *num *= 10;
+ *num += **p - '0';
+ (*p)++;
+ }
+ return ret;
+}
+
+static size_t oid_subidentifier_num_bytes(unsigned int value)
+{
+ size_t num_bytes = 0;
+
+ do {
+ value >>= 7;
+ num_bytes++;
+ } while (value != 0);
+
+ return num_bytes;
+}
+
+static int oid_subidentifier_encode_into(unsigned char **p,
+ unsigned char *bound,
+ unsigned int value)
+{
+ size_t num_bytes = oid_subidentifier_num_bytes(value);
+
+ if ((size_t) (bound - *p) < num_bytes) {
+ return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
+ }
+ (*p)[num_bytes - 1] = (unsigned char) (value & 0x7f);
+ value >>= 7;
+
+ for (size_t i = 2; i <= num_bytes; i++) {
+ (*p)[num_bytes - i] = 0x80 | (unsigned char) (value & 0x7f);
+ value >>= 7;
+ }
+ *p += num_bytes;
+
+ return 0;
+}
+
+/* Return the OID for the given x.y.z.... style numeric string */
+int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid,
+ const char *oid_str, size_t size)
+{
+ int ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+ const char *str_ptr = oid_str;
+ const char *str_bound = oid_str + size;
+ unsigned int val = 0;
+ unsigned int component1, component2;
+ size_t encoded_len;
+ unsigned char *resized_mem;
+
+ /* Count the number of dots to get a worst-case allocation size. */
+ size_t num_dots = 0;
+ for (size_t i = 0; i < size; i++) {
+ if (oid_str[i] == '.') {
+ num_dots++;
+ }
+ }
+ /* Allocate maximum possible required memory:
+ * There are (num_dots + 1) integer components, but the first 2 share the
+ * same subidentifier, so we only need num_dots subidentifiers maximum. */
+ if (num_dots == 0 || (num_dots > MBEDTLS_OID_MAX_COMPONENTS - 1)) {
+ return MBEDTLS_ERR_ASN1_INVALID_DATA;
+ }
+ /* Each byte can store 7 bits, calculate number of bytes for a
+ * subidentifier:
+ *
+ * bytes = ceil(subidentifer_size * 8 / 7)
+ */
+ size_t bytes_per_subidentifier = (((sizeof(unsigned int) * 8) - 1) / 7)
+ + 1;
+ size_t max_possible_bytes = num_dots * bytes_per_subidentifier;
+ oid->p = mbedtls_calloc(max_possible_bytes, 1);
+ if (oid->p == NULL) {
+ return MBEDTLS_ERR_ASN1_ALLOC_FAILED;
+ }
+ unsigned char *out_ptr = oid->p;
+ unsigned char *out_bound = oid->p + max_possible_bytes;
+
+ ret = oid_parse_number(&component1, &str_ptr, str_bound);
+ if (ret != 0) {
+ goto error;
+ }
+ if (component1 > 2) {
+ /* First component can't be > 2 */
+ ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+ goto error;
+ }
+ if (str_ptr >= str_bound || *str_ptr != '.') {
+ ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+ goto error;
+ }
+ str_ptr++;
+
+ ret = oid_parse_number(&component2, &str_ptr, str_bound);
+ if (ret != 0) {
+ goto error;
+ }
+ if ((component1 < 2) && (component2 > 39)) {
+ /* Root nodes 0 and 1 may have up to 40 children, numbered 0-39 */
+ ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+ goto error;
+ }
+ if (str_ptr < str_bound) {
+ if (*str_ptr == '.') {
+ str_ptr++;
+ } else {
+ ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+ goto error;
+ }
+ }
+
+ if (component2 > (UINT_MAX - (component1 * 40))) {
+ ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+ goto error;
+ }
+ ret = oid_subidentifier_encode_into(&out_ptr, out_bound,
+ (component1 * 40) + component2);
+ if (ret != 0) {
+ goto error;
+ }
+
+ while (str_ptr < str_bound) {
+ ret = oid_parse_number(&val, &str_ptr, str_bound);
+ if (ret != 0) {
+ goto error;
+ }
+ if (str_ptr < str_bound) {
+ if (*str_ptr == '.') {
+ str_ptr++;
+ } else {
+ ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
+ goto error;
+ }
+ }
+
+ ret = oid_subidentifier_encode_into(&out_ptr, out_bound, val);
+ if (ret != 0) {
+ goto error;
+ }
+ }
+
+ encoded_len = (size_t) (out_ptr - oid->p);
+ resized_mem = mbedtls_calloc(encoded_len, 1);
+ if (resized_mem == NULL) {
+ ret = MBEDTLS_ERR_ASN1_ALLOC_FAILED;
+ goto error;
+ }
+ memcpy(resized_mem, oid->p, encoded_len);
+ mbedtls_free(oid->p);
+ oid->p = resized_mem;
+ oid->len = encoded_len;
+
+ oid->tag = MBEDTLS_ASN1_OID;
+
+ return 0;
+
+error:
+ mbedtls_free(oid->p);
+ oid->p = NULL;
+ oid->len = 0;
+ return ret;
+}
+
int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *name)
{
int ret = MBEDTLS_ERR_X509_INVALID_NAME;
diff --git a/programs/ssl/dtls_client.c b/programs/ssl/dtls_client.c
index ddb3c34..f7f417f 100644
--- a/programs/ssl/dtls_client.c
+++ b/programs/ssl/dtls_client.c
@@ -9,18 +9,17 @@
#include "mbedtls/platform.h"
-#if !defined(MBEDTLS_SSL_CLI_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) || \
- !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_TIMING_C) || \
- !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
- !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_RSA_C) || \
- !defined(MBEDTLS_PEM_PARSE_C)
+#if !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
+ !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_SSL_CLI_C) || \
+ !defined(MBEDTLS_TIMING_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) || \
+ !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
int main(void)
{
- mbedtls_printf("MBEDTLS_SSL_CLI_C and/or MBEDTLS_SSL_PROTO_DTLS and/or "
- "MBEDTLS_NET_C and/or MBEDTLS_TIMING_C and/or "
- "MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
- "MBEDTLS_X509_CRT_PARSE_C and/or MBEDTLS_RSA_C and/or "
- "MBEDTLS_PEM_PARSE_C not defined.\n");
+ mbedtls_printf("MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
+ "MBEDTLS_NET_C and/or MBEDTLS_SSL_CLI_C and/or "
+ "MBEDTLS_TIMING_C and/or MBEDTLS_SSL_PROTO_DTLS and/or "
+ "MBEDTLS_PEM_PARSE_C and/or MBEDTLS_X509_CRT_PARSE_C "
+ "not defined.\n");
mbedtls_exit(0);
}
#else
@@ -45,7 +44,7 @@
#ifdef FORCE_IPV4
#define SERVER_ADDR "127.0.0.1" /* Forces IPv4 */
#else
-#define SERVER_ADDR "::1"
+#define SERVER_ADDR SERVER_NAME
#endif
#define MESSAGE "Echo this"
@@ -99,7 +98,6 @@
mbedtls_ctr_drbg_init(&ctr_drbg);
mbedtls_entropy_init(&entropy);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
@@ -107,7 +105,6 @@
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
goto exit;
}
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_printf("\n . Seeding the random number generator...");
fflush(stdout);
@@ -326,9 +323,7 @@
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free();
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
/* Shell can not handle large exit numbers -> 1 for errors */
if (ret < 0) {
@@ -337,6 +332,5 @@
mbedtls_exit(ret);
}
-#endif /* MBEDTLS_SSL_CLI_C && MBEDTLS_SSL_PROTO_DTLS && MBEDTLS_NET_C &&
- MBEDTLS_TIMING_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C &&
- MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_RSA_C && MBEDTLS_PEM_PARSE_C */
+
+#endif /* configuration allows running this program */
diff --git a/programs/ssl/dtls_server.c b/programs/ssl/dtls_server.c
index 732625e..20e53d3 100644
--- a/programs/ssl/dtls_server.c
+++ b/programs/ssl/dtls_server.c
@@ -18,19 +18,19 @@
#define BIND_IP "::"
#endif
-#if !defined(MBEDTLS_SSL_SRV_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) || \
- !defined(MBEDTLS_SSL_COOKIE_C) || !defined(MBEDTLS_NET_C) || \
- !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
- !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_RSA_C) || \
- !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_TIMING_C)
-
+#if !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
+ !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_SSL_SRV_C) || \
+ !defined(MBEDTLS_TIMING_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) || \
+ !defined(MBEDTLS_SSL_COOKIE_C) || \
+ !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
int main(void)
{
- printf("MBEDTLS_SSL_SRV_C and/or MBEDTLS_SSL_PROTO_DTLS and/or "
- "MBEDTLS_SSL_COOKIE_C and/or MBEDTLS_NET_C and/or "
- "MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
- "MBEDTLS_X509_CRT_PARSE_C and/or MBEDTLS_RSA_C and/or "
- "MBEDTLS_PEM_PARSE_C and/or MBEDTLS_TIMING_C not defined.\n");
+ mbedtls_printf("MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
+ "MBEDTLS_NET_C and/or MBEDTLS_SSL_SRV_C and/or "
+ "MBEDTLS_TIMING_C and/or MBEDTLS_SSL_PROTO_DTLS and/or "
+ "MBEDTLS_SSL_COOKIE_C and/or "
+ "MBEDTLS_PEM_PARSE_C and/or MBEDTLS_X509_CRT_PARSE_C "
+ "not defined.\n");
mbedtls_exit(0);
}
#else
@@ -107,7 +107,6 @@
mbedtls_entropy_init(&entropy);
mbedtls_ctr_drbg_init(&ctr_drbg);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
@@ -115,7 +114,6 @@
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
goto exit;
}
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
#if defined(MBEDTLS_DEBUG_C)
mbedtls_debug_set_threshold(DEBUG_LEVEL);
@@ -391,9 +389,7 @@
#endif
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free();
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
/* Shell can not handle large exit numbers -> 1 for errors */
if (ret < 0) {
@@ -402,7 +398,5 @@
mbedtls_exit(ret);
}
-#endif /* MBEDTLS_SSL_SRV_C && MBEDTLS_SSL_PROTO_DTLS &&
- MBEDTLS_SSL_COOKIE_C && MBEDTLS_NET_C && MBEDTLS_ENTROPY_C &&
- MBEDTLS_CTR_DRBG_C && MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_RSA_C
- && MBEDTLS_PEM_PARSE_C && MBEDTLS_TIMING_C */
+
+#endif /* configuration allows running this program */
diff --git a/programs/ssl/mini_client.c b/programs/ssl/mini_client.c
index ba0195c..cac630e 100644
--- a/programs/ssl/mini_client.c
+++ b/programs/ssl/mini_client.c
@@ -165,13 +165,11 @@
#endif
mbedtls_entropy_init(&entropy);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
goto exit;
}
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
if (mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
(const unsigned char *) pers, strlen(pers)) != 0) {
@@ -265,9 +263,7 @@
#if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_free(&ca);
#endif
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free();
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(ret);
}
diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c
index ee734b1..a6ab858 100644
--- a/programs/ssl/ssl_client1.c
+++ b/programs/ssl/ssl_client1.c
@@ -9,17 +9,14 @@
#include "mbedtls/platform.h"
-#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
- !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \
- !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_RSA_C) || \
- !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
- !defined(MBEDTLS_X509_CRT_PARSE_C)
+#if !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
+ !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_SSL_CLI_C) || \
+ !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
int main(void)
{
- mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C and/or "
- "MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_CLI_C and/or "
- "MBEDTLS_NET_C and/or MBEDTLS_RSA_C and/or "
- "MBEDTLS_CTR_DRBG_C and/or MBEDTLS_X509_CRT_PARSE_C "
+ mbedtls_printf("MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
+ "MBEDTLS_NET_C and/or MBEDTLS_SSL_CLI_C and/or "
+ "MBEDTLS_PEM_PARSE_C and/or MBEDTLS_X509_CRT_PARSE_C "
"not defined.\n");
mbedtls_exit(0);
}
@@ -81,14 +78,12 @@
mbedtls_ctr_drbg_init(&ctr_drbg);
mbedtls_entropy_init(&entropy);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
(int) status);
goto exit;
}
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_printf("\n . Seeding the random number generator...");
fflush(stdout);
@@ -240,6 +235,9 @@
}
if (ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) {
+ mbedtls_printf("The return value %d from mbedtls_ssl_read() means that the server\n"
+ "closed the connection first. We're ok with that.\n",
+ MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY);
break;
}
@@ -259,7 +257,9 @@
mbedtls_ssl_close_notify(&ssl);
- exit_code = MBEDTLS_EXIT_SUCCESS;
+ if (ret == 0 || ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) {
+ exit_code = MBEDTLS_EXIT_SUCCESS;
+ }
exit:
@@ -277,12 +277,9 @@
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free();
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code);
}
-#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C &&
- MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C &&
- MBEDTLS_PEM_PARSE_C && MBEDTLS_CTR_DRBG_C && MBEDTLS_X509_CRT_PARSE_C */
+
+#endif /* configuration allows running this program */
diff --git a/programs/ssl/ssl_context_info.c b/programs/ssl/ssl_context_info.c
index 51e8781..cbe9c6d 100644
--- a/programs/ssl/ssl_context_info.c
+++ b/programs/ssl/ssl_context_info.c
@@ -925,14 +925,12 @@
size_t ssl_max_len = SSL_INIT_LEN;
size_t ssl_len = 0;
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
(int) status);
return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
}
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
/* The 'b64_file' is opened when parsing arguments to check that the
* file name is correct */
@@ -1002,9 +1000,7 @@
printf("Finished. No valid base64 code found\n");
}
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free();
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
return 0;
}
diff --git a/programs/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c
index f4822b7..9b36507 100644
--- a/programs/ssl/ssl_fork_server.c
+++ b/programs/ssl/ssl_fork_server.c
@@ -9,22 +9,15 @@
#include "mbedtls/platform.h"
-#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
- !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_SRV_C) || \
- !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_RSA_C) || \
- !defined(MBEDTLS_CTR_DRBG_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
- !defined(MBEDTLS_TIMING_C) || !defined(MBEDTLS_FS_IO) || \
- !defined(MBEDTLS_PEM_PARSE_C)
-int main(int argc, char *argv[])
+#if !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
+ !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_SSL_SRV_C) || \
+ !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
+int main(void)
{
- ((void) argc);
- ((void) argv);
-
- mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C "
- "and/or MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_SRV_C and/or "
- "MBEDTLS_NET_C and/or MBEDTLS_RSA_C and/or "
- "MBEDTLS_CTR_DRBG_C and/or MBEDTLS_X509_CRT_PARSE_C and/or "
- "MBEDTLS_TIMING_C and/or MBEDTLS_PEM_PARSE_C not defined.\n");
+ mbedtls_printf("MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
+ "MBEDTLS_NET_C and/or MBEDTLS_SSL_SRV_C and/or "
+ "MBEDTLS_PEM_PARSE_C and/or MBEDTLS_X509_CRT_PARSE_C "
+ "not defined.\n");
mbedtls_exit(0);
}
#elif defined(_WIN32)
@@ -93,14 +86,12 @@
mbedtls_x509_crt_init(&srvcert);
mbedtls_ctr_drbg_init(&ctr_drbg);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
(int) status);
goto exit;
}
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
signal(SIGCHLD, SIG_IGN);
@@ -225,6 +216,7 @@
if (pid != 0) {
mbedtls_printf(" ok\n");
mbedtls_net_close(&client_fd);
+ fflush(stdout);
if ((ret = mbedtls_ctr_drbg_reseed(&ctr_drbg,
(const unsigned char *) "parent",
@@ -282,6 +274,7 @@
}
mbedtls_printf("pid %d: SSL handshake ok\n", pid);
+ fflush(stdout);
/*
* 6. Read the HTTP Request
@@ -312,12 +305,14 @@
mbedtls_printf("pid %d: mbedtls_ssl_read returned %d\n", pid, ret);
break;
}
+ fflush(stdout);
break;
}
len = ret;
mbedtls_printf("pid %d: %d bytes read\n\n%s", pid, len, (char *) buf);
+ fflush(stdout);
if (ret > 0) {
break;
@@ -333,7 +328,7 @@
len = sprintf((char *) buf, HTTP_RESPONSE,
mbedtls_ssl_get_ciphersuite(&ssl));
- while (cnt++ < 100) {
+ while (cnt++ < 10) {
while ((ret = mbedtls_ssl_write(&ssl, buf, len)) <= 0) {
if (ret == MBEDTLS_ERR_NET_CONN_RESET) {
mbedtls_printf(
@@ -349,12 +344,16 @@
}
}
len = ret;
- mbedtls_printf("pid %d: %d bytes written\n\n%s\n", pid, len, (char *) buf);
+ mbedtls_printf("pid %d: %d bytes written (cnt=%d)\n\n%s\n",
+ pid, len, cnt, (char *) buf);
+ fflush(stdout);
mbedtls_net_usleep(1000000);
}
mbedtls_ssl_close_notify(&ssl);
+ mbedtls_printf("pid %d: shutting down\n", pid);
+ fflush(stdout);
goto exit;
}
@@ -369,9 +368,7 @@
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free();
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code);
}
diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c
index e3ed697..bdeef9b 100644
--- a/programs/ssl/ssl_mail_client.c
+++ b/programs/ssl/ssl_mail_client.c
@@ -359,14 +359,12 @@
mbedtls_ctr_drbg_init(&ctr_drbg);
mbedtls_entropy_init(&entropy);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
(int) status);
goto exit;
}
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
if (argc < 2) {
usage:
@@ -806,9 +804,7 @@
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free();
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code);
}
diff --git a/programs/ssl/ssl_pthread_server.c b/programs/ssl/ssl_pthread_server.c
index fcb8f2f..d8213cb 100644
--- a/programs/ssl/ssl_pthread_server.c
+++ b/programs/ssl/ssl_pthread_server.c
@@ -10,20 +10,21 @@
#include "mbedtls/platform.h"
-#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
- !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_SRV_C) || \
- !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_RSA_C) || \
- !defined(MBEDTLS_CTR_DRBG_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
- !defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_THREADING_C) || \
- !defined(MBEDTLS_THREADING_PTHREAD) || !defined(MBEDTLS_PEM_PARSE_C)
+#if !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
+ !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_SSL_SRV_C) || \
+ !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
int main(void)
{
- mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C "
- "and/or MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_SRV_C and/or "
- "MBEDTLS_NET_C and/or MBEDTLS_RSA_C and/or "
- "MBEDTLS_CTR_DRBG_C and/or MBEDTLS_X509_CRT_PARSE_C and/or "
- "MBEDTLS_THREADING_C and/or MBEDTLS_THREADING_PTHREAD "
- "and/or MBEDTLS_PEM_PARSE_C not defined.\n");
+ mbedtls_printf("MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
+ "MBEDTLS_NET_C and/or MBEDTLS_SSL_SRV_C and/or "
+ "MBEDTLS_PEM_PARSE_C and/or MBEDTLS_X509_CRT_PARSE_C "
+ "not defined.\n");
+ mbedtls_exit(0);
+}
+#elif !defined(MBEDTLS_THREADING_C) || !defined(MBEDTLS_THREADING_PTHREAD)
+int main(void)
+{
+ mbedtls_printf("MBEDTLS_THREADING_PTHREAD not defined.\n");
mbedtls_exit(0);
}
#else
@@ -123,6 +124,7 @@
* 5. Handshake
*/
mbedtls_printf(" [ #%ld ] Performing the SSL/TLS handshake\n", thread_id);
+ fflush(stdout);
while ((ret = mbedtls_ssl_handshake(&ssl)) != 0) {
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
@@ -138,6 +140,7 @@
* 6. Read the HTTP Request
*/
mbedtls_printf(" [ #%ld ] < Read from client\n", thread_id);
+ fflush(stdout);
do {
len = sizeof(buf) - 1;
@@ -170,6 +173,7 @@
len = ret;
mbedtls_printf(" [ #%ld ] %d bytes read\n=====\n%s\n=====\n",
thread_id, len, (char *) buf);
+ fflush(stdout);
if (ret > 0) {
break;
@@ -180,6 +184,7 @@
* 7. Write the 200 Response
*/
mbedtls_printf(" [ #%ld ] > Write to client:\n", thread_id);
+ fflush(stdout);
len = sprintf((char *) buf, HTTP_RESPONSE,
mbedtls_ssl_get_ciphersuite(&ssl));
@@ -201,6 +206,7 @@
len = ret;
mbedtls_printf(" [ #%ld ] %d bytes written\n=====\n%s\n=====\n",
thread_id, len, (char *) buf);
+ fflush(stdout);
mbedtls_printf(" [ #%ld ] . Closing the connection...", thread_id);
@@ -214,6 +220,7 @@
}
mbedtls_printf(" ok\n");
+ fflush(stdout);
ret = 0;
@@ -320,7 +327,6 @@
*/
mbedtls_entropy_init(&entropy);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
@@ -328,7 +334,6 @@
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
goto exit;
}
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
/*
* 1a. Seed the random number generator
@@ -442,6 +447,7 @@
* 3. Wait until a client connects
*/
mbedtls_printf(" [ main ] Waiting for a remote connection\n");
+ fflush(stdout);
if ((ret = mbedtls_net_accept(&listen_fd, &client_fd,
NULL, 0, NULL)) != 0) {
@@ -476,14 +482,9 @@
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
mbedtls_memory_buffer_alloc_free();
#endif
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free();
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(ret);
}
-#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C &&
- MBEDTLS_SSL_TLS_C && MBEDTLS_SSL_SRV_C && MBEDTLS_NET_C &&
- MBEDTLS_RSA_C && MBEDTLS_CTR_DRBG_C && MBEDTLS_THREADING_C &&
- MBEDTLS_THREADING_PTHREAD && MBEDTLS_PEM_PARSE_C */
+#endif /* configuration allows running this program */
diff --git a/programs/ssl/ssl_server.c b/programs/ssl/ssl_server.c
index 6becf8d..9a90d1d 100644
--- a/programs/ssl/ssl_server.c
+++ b/programs/ssl/ssl_server.c
@@ -9,18 +9,15 @@
#include "mbedtls/platform.h"
-#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_PEM_PARSE_C) || \
- !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_SSL_TLS_C) || \
- !defined(MBEDTLS_SSL_SRV_C) || !defined(MBEDTLS_NET_C) || \
- !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
- !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_FS_IO)
+#if !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
+ !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_SSL_SRV_C) || \
+ !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
int main(void)
{
- mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C "
- "and/or MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_SRV_C and/or "
- "MBEDTLS_NET_C and/or MBEDTLS_RSA_C and/or "
- "MBEDTLS_CTR_DRBG_C and/or MBEDTLS_X509_CRT_PARSE_C "
- "and/or MBEDTLS_PEM_PARSE_C not defined.\n");
+ mbedtls_printf("MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
+ "MBEDTLS_NET_C and/or MBEDTLS_SSL_SRV_C and/or "
+ "MBEDTLS_PEM_PARSE_C and/or MBEDTLS_X509_CRT_PARSE_C "
+ "not defined.\n");
mbedtls_exit(0);
}
#else
@@ -92,7 +89,6 @@
mbedtls_entropy_init(&entropy);
mbedtls_ctr_drbg_init(&ctr_drbg);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
@@ -100,7 +96,6 @@
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
goto exit;
}
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
#if defined(MBEDTLS_DEBUG_C)
mbedtls_debug_set_threshold(DEBUG_LEVEL);
@@ -315,16 +310,19 @@
mbedtls_printf(" %d bytes written\n\n%s\n", len, (char *) buf);
mbedtls_printf(" . Closing the connection...");
+ fflush(stdout);
while ((ret = mbedtls_ssl_close_notify(&ssl)) < 0) {
if (ret != MBEDTLS_ERR_SSL_WANT_READ &&
- ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
+ ret != MBEDTLS_ERR_SSL_WANT_WRITE &&
+ ret != MBEDTLS_ERR_NET_CONN_RESET) {
mbedtls_printf(" failed\n ! mbedtls_ssl_close_notify returned %d\n\n", ret);
goto reset;
}
}
mbedtls_printf(" ok\n");
+ fflush(stdout);
ret = 0;
goto reset;
@@ -350,13 +348,9 @@
#endif
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free();
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(ret);
}
-#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C &&
- MBEDTLS_SSL_TLS_C && MBEDTLS_SSL_SRV_C && MBEDTLS_NET_C &&
- MBEDTLS_RSA_C && MBEDTLS_CTR_DRBG_C && MBEDTLS_X509_CRT_PARSE_C
- && MBEDTLS_FS_IO && MBEDTLS_PEM_PARSE_C */
+
+#endif /* configuration allows running this program */
diff --git a/tests/Makefile b/tests/Makefile
index 63df02c..66bb1cd 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -281,7 +281,6 @@
# Test suites caught by SKIP_TEST_SUITES are built but not executed.
check: $(BINARIES) $(CRYPTO_BINARIES)
perl scripts/run-test-suites.pl $(TEST_FLAGS) --skip=$(SKIP_TEST_SUITES)
- cd ../tf-psa-crypto/tests && perl ../../tests/scripts/run-test-suites.pl $(TEST_FLAGS) --skip=$(SKIP_TEST_SUITES)
test: check
diff --git a/tests/opt-testcases/sample.sh b/tests/opt-testcases/sample.sh
new file mode 100644
index 0000000..e2eaf24
--- /dev/null
+++ b/tests/opt-testcases/sample.sh
@@ -0,0 +1,391 @@
+# Test that SSL sample programs can interoperate with each other
+# and with OpenSSL and GnuTLS.
+
+# Copyright The Mbed TLS Contributors
+# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+
+: ${PROGRAMS_DIR:=../programs/ssl}
+
+# Disable session tickets for ssl_client1 when potentially using TLS 1.3
+# until https://github.com/Mbed-TLS/mbedtls/issues/6640 is resolved
+# and (if relevant) implemented in ssl_client1.
+run_test "Sample: ssl_client1, ssl_server2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_server2 tickets=0" \
+ "$PROGRAMS_DIR/ssl_client1" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -c "[1-9][0-9]* bytes written" \
+ -S "error" \
+ -C "error"
+
+requires_protocol_version tls12
+run_test "Sample: ssl_client1, openssl server, TLS 1.2" \
+ -P 4433 \
+ "$O_SRV -tls1_2" \
+ "$PROGRAMS_DIR/ssl_client1" \
+ 0 \
+ -c "Protocol.*TLSv1.2" \
+ -S "ERROR" \
+ -C "error"
+
+requires_protocol_version tls12
+run_test "Sample: ssl_client1, gnutls server, TLS 1.2" \
+ -P 4433 \
+ "$G_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2" \
+ "$PROGRAMS_DIR/ssl_client1" \
+ 0 \
+ -s "Version: TLS1.2" \
+ -c "<TD>Protocol version:</TD><TD>TLS1.2</TD>" \
+ -S "Error" \
+ -C "error"
+
+# Disable session tickets for ssl_client1 when using TLS 1.3
+# until https://github.com/Mbed-TLS/mbedtls/issues/6640 is resolved
+# and (if relevant) implemented in ssl_client1.
+requires_protocol_version tls13
+requires_openssl_tls1_3
+run_test "Sample: ssl_client1, openssl server, TLS 1.3" \
+ -P 4433 \
+ "$O_NEXT_SRV -tls1_3 -num_tickets 0" \
+ "$PROGRAMS_DIR/ssl_client1" \
+ 0 \
+ -c "New, TLSv1.3, Cipher is" \
+ -S "ERROR" \
+ -C "error"
+
+# Disable session tickets for ssl_client1 when using TLS 1.3
+# until https://github.com/Mbed-TLS/mbedtls/issues/6640 is resolved
+# and (if relevant) implemented in ssl_client1.
+requires_protocol_version tls13
+requires_gnutls_tls1_3
+run_test "Sample: ssl_client1, gnutls server, TLS 1.3" \
+ -P 4433 \
+ "$G_NEXT_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.3 --noticket" \
+ "$PROGRAMS_DIR/ssl_client1" \
+ 0 \
+ -s "Version: TLS1.3" \
+ -c "<TD>Protocol version:</TD><TD>TLS1.3</TD>" \
+ -S "Error" \
+ -C "error"
+
+# The server complains of extra data after it closes the connection
+# because the client keeps sending data, so the server receives
+# more application data when it expects a new handshake. We consider
+# the test a success if both sides have sent and received application
+# data, no matter what happens afterwards.
+run_test "Sample: dtls_client, ssl_server2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_server2 dtls=1 server_addr=localhost" \
+ "$PROGRAMS_DIR/dtls_client" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -c "[1-9][0-9]* bytes written" \
+ -C "error"
+
+# The dtls_client program connects to localhost. This test case fails on
+# systems where the name "localhost" resolves to an IPv6 address, but
+# the IPv6 connection is not possible. Possible reasons include:
+# * OpenSSL is too old (IPv6 support was added in 1.1.0).
+# * OpenSSL was built without IPv6 support.
+# * A firewall blocks IPv6.
+#
+# To facilitate working with this test case, have it run with $OPENSSL_NEXT
+# which is at least 1.1.1a. At the time it was introduced, this test case
+# passed with OpenSSL 1.0.2g on an environment where IPv6 is disabled.
+requires_protocol_version dtls12
+run_test "Sample: dtls_client, openssl server, DTLS 1.2" \
+ -P 4433 \
+ "$O_NEXT_SRV -dtls1_2" \
+ "$PROGRAMS_DIR/dtls_client" \
+ 0 \
+ -s "Echo this" \
+ -c "Echo this" \
+ -c "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -S "ERROR" \
+ -C "error"
+
+requires_protocol_version dtls12
+run_test "Sample: dtls_client, gnutls server, DTLS 1.2" \
+ -P 4433 \
+ "$G_SRV -u --echo --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2" \
+ "$PROGRAMS_DIR/dtls_client" \
+ 0 \
+ -s "Server listening" \
+ -s "[1-9][0-9]* bytes command:" \
+ -c "Echo this" \
+ -c "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -S "Error" \
+ -C "error"
+
+run_test "Sample: ssl_server, ssl_client2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_server" \
+ "$PROGRAMS_DIR/ssl_client2" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -c "[1-9][0-9]* bytes written" \
+ -S "error" \
+ -C "error"
+
+run_test "Sample: ssl_client1 with ssl_server" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_server" \
+ "$PROGRAMS_DIR/ssl_client1" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -c "[1-9][0-9]* bytes written" \
+ -S "error" \
+ -C "error"
+
+requires_protocol_version tls12
+run_test "Sample: ssl_server, openssl client, TLS 1.2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_server" \
+ "$O_CLI -tls1_2" \
+ 0 \
+ -s "Successful connection using: TLS-" \
+ -c "Protocol.*TLSv1.2" \
+ -S "error" \
+ -C "ERROR"
+
+requires_protocol_version tls12
+run_test "Sample: ssl_server, gnutls client, TLS 1.2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_server" \
+ "$G_CLI --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2 localhost" \
+ 0 \
+ -s "Successful connection using: TLS-" \
+ -c "Description:.*TLS1.2" \
+ -S "error" \
+ -C "ERROR"
+
+requires_protocol_version tls13
+requires_openssl_tls1_3
+run_test "Sample: ssl_server, openssl client, TLS 1.3" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_server" \
+ "$O_NEXT_CLI -tls1_3" \
+ 0 \
+ -s "Successful connection using: TLS1-3-" \
+ -c "New, TLSv1.3, Cipher is" \
+ -S "error" \
+ -C "ERROR"
+
+requires_protocol_version tls13
+requires_gnutls_tls1_3
+run_test "Sample: ssl_server, gnutls client, TLS 1.3" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_server" \
+ "$G_NEXT_CLI --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.3 localhost" \
+ 0 \
+ -s "Successful connection using: TLS1-3-" \
+ -c "Description:.*TLS1.3" \
+ -S "error" \
+ -C "ERROR"
+
+run_test "Sample: ssl_fork_server, ssl_client2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_fork_server" \
+ "$PROGRAMS_DIR/ssl_client2" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -c "[1-9][0-9]* bytes written" \
+ -S "error" \
+ -C "error"
+
+run_test "Sample: ssl_client1 with ssl_fork_server" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_fork_server" \
+ "$PROGRAMS_DIR/ssl_client1" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -c "[1-9][0-9]* bytes written" \
+ -S "error" \
+ -C "error"
+
+requires_protocol_version tls12
+run_test "Sample: ssl_fork_server, openssl client, TLS 1.2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_fork_server" \
+ "$O_CLI -tls1_2" \
+ 0 \
+ -s "Successful connection using: TLS-" \
+ -c "Protocol.*TLSv1.2" \
+ -S "error" \
+ -C "ERROR"
+
+requires_protocol_version tls12
+run_test "Sample: ssl_fork_server, gnutls client, TLS 1.2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_fork_server" \
+ "$G_CLI --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2 localhost" \
+ 0 \
+ -s "Successful connection using: TLS-" \
+ -c "Description:.*TLS1.2" \
+ -S "error" \
+ -C "ERROR"
+
+requires_protocol_version tls13
+requires_openssl_tls1_3
+run_test "Sample: ssl_fork_server, openssl client, TLS 1.3" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_fork_server" \
+ "$O_NEXT_CLI -tls1_3" \
+ 0 \
+ -s "Successful connection using: TLS1-3-" \
+ -c "New, TLSv1.3, Cipher is" \
+ -S "error" \
+ -C "ERROR"
+
+requires_protocol_version tls13
+requires_gnutls_tls1_3
+run_test "Sample: ssl_fork_server, gnutls client, TLS 1.3" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_fork_server" \
+ "$G_NEXT_CLI --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.3 localhost" \
+ 0 \
+ -s "Successful connection using: TLS1-3-" \
+ -c "Description:.*TLS1.3" \
+ -S "error" \
+ -C "ERROR"
+
+run_test "Sample: ssl_pthread_server, ssl_client2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_pthread_server" \
+ "$PROGRAMS_DIR/ssl_client2" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -c "[1-9][0-9]* bytes written" \
+ -S "error" \
+ -C "error"
+
+run_test "Sample: ssl_client1 with ssl_pthread_server" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_pthread_server" \
+ "$PROGRAMS_DIR/ssl_client1" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -c "[1-9][0-9]* bytes written" \
+ -S "error" \
+ -C "error"
+
+requires_protocol_version tls12
+run_test "Sample: ssl_pthread_server, openssl client, TLS 1.2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_pthread_server" \
+ "$O_CLI -tls1_2" \
+ 0 \
+ -s "Successful connection using: TLS-" \
+ -c "Protocol.*TLSv1.2" \
+ -S "error" \
+ -C "ERROR"
+
+requires_protocol_version tls12
+run_test "Sample: ssl_pthread_server, gnutls client, TLS 1.2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_pthread_server" \
+ "$G_CLI --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2 localhost" \
+ 0 \
+ -s "Successful connection using: TLS-" \
+ -c "Description:.*TLS1.2" \
+ -S "error" \
+ -C "ERROR"
+
+requires_protocol_version tls13
+requires_openssl_tls1_3
+run_test "Sample: ssl_pthread_server, openssl client, TLS 1.3" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_pthread_server" \
+ "$O_NEXT_CLI -tls1_3" \
+ 0 \
+ -s "Successful connection using: TLS1-3-" \
+ -c "New, TLSv1.3, Cipher is" \
+ -S "error" \
+ -C "ERROR"
+
+requires_protocol_version tls13
+requires_gnutls_tls1_3
+run_test "Sample: ssl_pthread_server, gnutls client, TLS 1.3" \
+ -P 4433 \
+ "$PROGRAMS_DIR/ssl_pthread_server" \
+ "$G_NEXT_CLI --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.3 localhost" \
+ 0 \
+ -s "Successful connection using: TLS1-3-" \
+ -c "Description:.*TLS1.3" \
+ -S "error" \
+ -C "ERROR"
+
+# The server complains of extra data after it closes the connection
+# because the client keeps sending data, so the server receives
+# more application data when it expects a new handshake. We consider
+# the test a success if both sides have sent and received application
+# data, no matter what happens afterwards.
+run_test "Sample: dtls_client with dtls_server" \
+ -P 4433 \
+ "$PROGRAMS_DIR/dtls_server" \
+ "$PROGRAMS_DIR/dtls_client" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -c "[1-9][0-9]* bytes written" \
+ -C "error"
+
+# The server complains of extra data after it closes the connection
+# because the client keeps sending data, so the server receives
+# more application data when it expects a new handshake. We consider
+# the test a success if both sides have sent and received application
+# data, no matter what happens afterwards.
+run_test "Sample: ssl_client2, dtls_server" \
+ -P 4433 \
+ "$PROGRAMS_DIR/dtls_server" \
+ "$PROGRAMS_DIR/ssl_client2 dtls=1" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "[1-9][0-9]* bytes read" \
+ -c "[1-9][0-9]* bytes written" \
+ -C "error"
+
+requires_protocol_version dtls12
+run_test "Sample: dtls_server, openssl client, DTLS 1.2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/dtls_server" \
+ "$O_CLI -dtls1_2" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "Protocol.*TLSv1.2" \
+ -S "error" \
+ -C "ERROR"
+
+requires_protocol_version dtls12
+run_test "Sample: dtls_server, gnutls client, DTLS 1.2" \
+ -P 4433 \
+ "$PROGRAMS_DIR/dtls_server" \
+ "$G_CLI -u --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2 localhost" \
+ 0 \
+ -s "[1-9][0-9]* bytes read" \
+ -s "[1-9][0-9]* bytes written" \
+ -c "Description:.*DTLS1.2" \
+ -S "error" \
+ -C "ERROR"
diff --git a/tests/scripts/basic-build-test.sh b/tests/scripts/basic-build-test.sh
index b850147..4adae9a 100755
--- a/tests/scripts/basic-build-test.sh
+++ b/tests/scripts/basic-build-test.sh
@@ -35,8 +35,6 @@
exit 1
fi
-MBEDTLS_ROOT_DIR="$PWD"
-
: ${OPENSSL:="openssl"}
: ${GNUTLS_CLI:="gnutls-cli"}
: ${GNUTLS_SERV:="gnutls-serv"}
@@ -81,26 +79,21 @@
# Step 2 - Execute the tests
TEST_OUTPUT=out_${PPID}
-cd $MBEDTLS_ROOT_DIR/tests
+cd tests
if [ ! -f "seedfile" ]; then
dd if=/dev/urandom of="seedfile" bs=64 count=1
fi
-cd $MBEDTLS_ROOT_DIR/tf-psa-crypto/tests
-if [ ! -f "seedfile" ]; then
- dd if=/dev/urandom of="seedfile" bs=64 count=1
+if [ ! -f "../tf-psa-crypto/tests/seedfile" ]; then
+ cp "seedfile" "../tf-psa-crypto/tests/seedfile"
fi
echo
# Step 2a - Unit Tests (keep going even if some tests fail)
echo '################ Unit tests ################'
-cd $MBEDTLS_ROOT_DIR/tests
-perl scripts/run-test-suites.pl -v 2 |tee tls-x509-unit-test-$TEST_OUTPUT
-cd $MBEDTLS_ROOT_DIR/tf-psa-crypto/tests
-perl $MBEDTLS_ROOT_DIR/tests/scripts/run-test-suites.pl -v 2 |tee ../../tests/crypto-unit-test-$TEST_OUTPUT
+perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT
echo '^^^^^^^^^^^^^^^^ Unit tests ^^^^^^^^^^^^^^^^'
echo
-cd $MBEDTLS_ROOT_DIR/tests
# Step 2b - System Tests (keep going even if some tests fail)
echo
echo '################ ssl-opt.sh ################'
@@ -151,13 +144,13 @@
cd tests
- # Step 4a - TLS and x509 unit tests
- echo "TLS and x509 unit tests - tests/scripts/run-test-suites.pl"
+ # Step 4a - Unit tests
+ echo "Unit tests - tests/scripts/run-test-suites.pl"
- PASSED_TESTS=$(tail -n6 tls-x509-unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
- SKIPPED_TESTS=$(tail -n6 tls-x509-unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
- TOTAL_SUITES=$(tail -n6 tls-x509-unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
- FAILED_TESTS=$(tail -n6 tls-x509-unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
+ PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
+ SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
+ TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
+ FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
echo "No test suites : $TOTAL_SUITES"
echo "Passed : $PASSED_TESTS"
@@ -173,29 +166,7 @@
TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS))
- # Step 4b - Crypto unit tests
- echo "Crypto unit tests - tests/scripts/run-test-suites.pl"
-
- PASSED_TESTS=$(tail -n6 crypto-unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
- SKIPPED_TESTS=$(tail -n6 crypto-unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
- TOTAL_SUITES=$(tail -n6 crypto-unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
- FAILED_TESTS=$(tail -n6 crypto-unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
-
- echo "No test suites : $TOTAL_SUITES"
- echo "Passed : $PASSED_TESTS"
- echo "Failed : $FAILED_TESTS"
- echo "Skipped : $SKIPPED_TESTS"
- echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))"
- echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))"
- echo
-
- TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
- TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
- TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
- TOTAL_AVAIL=$(($TOTAL_AVAIL + $PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
- TOTAL_EXED=$(($TOTAL_EXED + $PASSED_TESTS + $FAILED_TESTS))
-
- # Step 4c - TLS Options tests
+ # Step 4b - TLS Options tests
echo "TLS Options tests - tests/ssl-opt.sh"
PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p')
@@ -217,7 +188,7 @@
TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS))
- # Step 4d - System Compatibility tests
+ # Step 4c - System Compatibility tests
echo "System/Compatibility tests - tests/compat.sh"
PASSED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }')
@@ -239,7 +210,7 @@
TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS))
- # Step 4e - Grand totals
+ # Step 4d - Grand totals
echo "-------------------------------------------------------------------------"
echo "Total tests"
@@ -251,13 +222,12 @@
echo
- # Step 4f - Coverage report
+ # Step 4e - Coverage report
echo "Coverage statistics:"
sed -n '1,/^Overall coverage/d; /%/p' cov-$TEST_OUTPUT
echo
- rm tls-x509-unit-test-$TEST_OUTPUT
- rm crypto-unit-test-$TEST_OUTPUT
+ rm unit-test-$TEST_OUTPUT
rm sys-test-$TEST_OUTPUT
rm compat-test-$TEST_OUTPUT
rm cov-$TEST_OUTPUT
diff --git a/tests/scripts/components-configuration.sh b/tests/scripts/components-configuration.sh
index 9f563a9..683ac84 100644
--- a/tests/scripts/components-configuration.sh
+++ b/tests/scripts/components-configuration.sh
@@ -229,40 +229,6 @@
! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
}
-component_test_no_psa_crypto_full_cmake_asan () {
- # full minus MBEDTLS_PSA_CRYPTO_C: run the same set of tests as basic-build-test.sh
- msg "build: cmake, full config minus PSA crypto, ASan"
- scripts/config.py full
- scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
- scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
- scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
- scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
- scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
- scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
- scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
- scripts/config.py unset MBEDTLS_LMS_C
- scripts/config.py unset MBEDTLS_LMS_PRIVATE
- CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
- make
-
- msg "test: main suites (full minus PSA crypto)"
- make test
-
- # Note: ssl-opt.sh has some test cases that depend on
- # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
- # This is the only component where those tests are not skipped.
- msg "test: ssl-opt.sh (full minus PSA crypto)"
- tests/ssl-opt.sh
-
- # Note: the next two invocations cover all compat.sh test cases.
- # We should use the same here and in basic-build-test.sh.
- msg "test: compat.sh: default version (full minus PSA crypto)"
- tests/compat.sh -e 'ARIA\|CHACHA'
-
- msg "test: compat.sh: next: ARIA, Chacha (full minus PSA crypto)"
- env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
-}
-
component_build_tfm () {
# Check that the TF-M configuration can build cleanly with various
# warning flags enabled. We don't build or run tests, since the
diff --git a/tests/scripts/run-test-suites.pl b/tests/scripts/run-test-suites.pl
index 408deaf..e01d44f 100755
--- a/tests/scripts/run-test-suites.pl
+++ b/tests/scripts/run-test-suites.pl
@@ -28,6 +28,7 @@
use utf8;
use open qw(:std utf8);
+use Cwd qw(getcwd);
use Getopt::Long qw(:config auto_help gnu_compat);
use Pod::Usage;
@@ -40,7 +41,8 @@
# All test suites = executable files with a .datax file.
my @suites = ();
-for my $data_file (glob 'test_suite_*.datax') {
+my @test_dirs = qw(../tf-psa-crypto/tests .);
+for my $data_file (map {glob "$_/test_suite_*.datax"} @test_dirs) {
(my $base = $data_file) =~ s/\.datax$//;
push @suites, $base if -x $base;
push @suites, "$base.exe" if -e "$base.exe";
@@ -59,15 +61,8 @@
')(\z|\.)' );
# in case test suites are linked dynamically
-if (-d '../../tf-psa-crypto') {
- $ENV{'LD_LIBRARY_PATH'} = '../../library';
- $ENV{'DYLD_LIBRARY_PATH'} = '../../library';
-}
-else
-{
- $ENV{'LD_LIBRARY_PATH'} = '../library';
- $ENV{'DYLD_LIBRARY_PATH'} = '../library';
-}
+$ENV{'LD_LIBRARY_PATH'} = getcwd() . "/../library";
+$ENV{'DYLD_LIBRARY_PATH'} = $ENV{'LD_LIBRARY_PATH'}; # For macOS
my $prefix = $^O eq "MSWin32" ? '' : './';
@@ -82,8 +77,13 @@
print $padchar x( $padlen ), " $string ", $padchar x( $padlen ), "\n";
}
-for my $suite (@suites)
+for my $suite_path (@suites)
{
+ my ($dir, $suite) = ('.', $suite_path);
+ if ($suite =~ m!(.*)/([^/]*)!) {
+ $dir = $1;
+ $suite = $2;
+ }
print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " ";
if( $suite =~ /$skip_re/o ) {
print "SKIP\n";
@@ -91,7 +91,7 @@
next;
}
- my $command = "$prefix$suite";
+ my $command = "cd $dir && $prefix$suite";
if( $verbose ) {
$command .= ' -v';
}
diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh
index 6f59963..e7eef1a 100755
--- a/tests/ssl-opt.sh
+++ b/tests/ssl-opt.sh
@@ -491,6 +491,37 @@
requires_certificate_authentication;;
esac
+ case " $CMD_LINE " in
+ *"programs/ssl/dtls_client "*|\
+ *"programs/ssl/ssl_client1 "*)
+ requires_config_enabled MBEDTLS_CTR_DRBG_C
+ requires_config_enabled MBEDTLS_ENTROPY_C
+ requires_config_enabled MBEDTLS_PEM_PARSE_C
+ requires_config_enabled MBEDTLS_SSL_CLI_C
+ requires_certificate_authentication
+ ;;
+ *"programs/ssl/dtls_server "*|\
+ *"programs/ssl/ssl_fork_server "*|\
+ *"programs/ssl/ssl_pthread_server "*|\
+ *"programs/ssl/ssl_server "*)
+ requires_config_enabled MBEDTLS_CTR_DRBG_C
+ requires_config_enabled MBEDTLS_ENTROPY_C
+ requires_config_enabled MBEDTLS_PEM_PARSE_C
+ requires_config_enabled MBEDTLS_SSL_SRV_C
+ requires_certificate_authentication
+ # The actual minimum depends on the configuration since it's
+ # mostly about the certificate size.
+ # In config-suite-b.h, for the test certificates (server5.crt),
+ # 1024 is not enough.
+ requires_config_value_at_least MBEDTLS_SSL_OUT_CONTENT_LEN 2000
+ ;;
+ esac
+
+ case " $CMD_LINE " in
+ *"programs/ssl/ssl_pthread_server "*)
+ requires_config_enabled MBEDTLS_THREADING_PTHREAD;;
+ esac
+
case "$CMD_LINE" in
*[-_\ =]psk*|*[-_\ =]PSK*) :;; # No certificate requirement with PSK
*/server5*|\
@@ -1252,7 +1283,7 @@
# check if the given command uses dtls and sets global variable DTLS
detect_dtls() {
case "$1" in
- *dtls=1*|*-dtls*|*-u*) DTLS=1;;
+ *dtls=1*|*-dtls*|*-u*|*/dtls_*) DTLS=1;;
*) DTLS=0;;
esac
}
@@ -1372,9 +1403,13 @@
# Outputs:
# * $CLI_CMD, $PXY_CMD, $SRV_CMD: may be tweaked.
analyze_test_commands() {
- # if the test uses DTLS but no custom proxy, add a simple proxy
- # as it provides timing info that's useful to debug failures
- if [ -z "$PXY_CMD" ] && [ "$DTLS" -eq 1 ]; then
+ # If the test uses DTLS, does not force a specific port, and does not
+ # specify a custom proxy, add a simple proxy.
+ # It provides timing info that's useful to debug failures.
+ if [ "$DTLS" -eq 1 ] &&
+ [ "$THIS_SRV_PORT" = "$SRV_PORT" ] &&
+ [ -z "$PXY_CMD" ]
+ then
PXY_CMD="$P_PXY"
case " $SRV_CMD " in
*' server_addr=::1 '*)
@@ -1410,7 +1445,20 @@
if [ -n "$PXY_CMD" ]; then
CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g )
else
- CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g )
+ CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$THIS_SRV_PORT/g )
+ fi
+
+ # If the test forces a specific port and the server is OpenSSL or
+ # GnuTLS, override its port specification.
+ if [ "$THIS_SRV_PORT" != "$SRV_PORT" ]; then
+ case "$SRV_CMD" in
+ "$G_SRV"*|"$G_NEXT_SRV"*)
+ SRV_CMD=$(
+ printf %s "$SRV_CMD " |
+ sed -e "s/ -p $SRV_PORT / -p $THIS_SRV_PORT /"
+ );;
+ "$O_SRV"*|"$O_NEXT_SRV"*) SRV_CMD="$SRV_CMD -accept $THIS_SRV_PORT";;
+ esac
fi
# prepend valgrind to our commands if active
@@ -1609,7 +1657,7 @@
printf '# %s\n%s\n' "$NAME" "$SRV_CMD" > $SRV_OUT
provide_input | $SRV_CMD >> $SRV_OUT 2>&1 &
SRV_PID=$!
- wait_server_start "$SRV_PORT" "$SRV_PID"
+ wait_server_start "$THIS_SRV_PORT" "$SRV_PID"
printf '# %s\n%s\n' "$NAME" "$CLI_CMD" > $CLI_OUT
# The client must be a subprocess of the script in order for killing it to
@@ -1732,7 +1780,7 @@
esac
fi
- # does this test use a proxy?
+ # Does this test specify a proxy?
if [ "X$1" = "X-p" ]; then
PXY_CMD="$2"
shift 2
@@ -1740,6 +1788,14 @@
PXY_CMD=""
fi
+ # Does this test force a specific port?
+ if [ "$1" = "-P" ]; then
+ THIS_SRV_PORT="$2"
+ shift 2
+ else
+ THIS_SRV_PORT="$SRV_PORT"
+ fi
+
# get commands and client output
SRV_CMD="$1"
CLI_CMD="$2"
@@ -1761,7 +1817,10 @@
# Check if we are trying to use an external tool which does not support ECDH
EXT_WO_ECDH=$(use_ext_tool_without_ecdh_support "$SRV_CMD" "$CLI_CMD")
- # Guess the TLS version which is going to be used
+ # Guess the TLS version which is going to be used.
+ # Note that this detection is wrong in some cases, which causes unduly
+ # skipped test cases in builds with TLS 1.3 but not TLS 1.2.
+ # https://github.com/Mbed-TLS/mbedtls/issues/9560
if [ "$EXT_WO_ECDH" = "no" ]; then
TLS_VERSION=$(get_tls_version "$SRV_CMD" "$CLI_CMD")
else
diff --git a/tests/suites/test_suite_x509parse.data b/tests/suites/test_suite_x509parse.data
index 510b0a3..143d676 100644
--- a/tests/suites/test_suite_x509parse.data
+++ b/tests/suites/test_suite_x509parse.data
@@ -3439,3 +3439,52 @@
X509 CRT parse Authority Key Id - Wrong Issuer sequence
depends_on:PSA_WANT_ALG_MD5:MBEDTLS_RSA_C
x509_crt_parse_authoritykeyid:"../framework/data_files/clusterfuzz-testcase-minimized-fuzz_x509crt-6666050834661376.crt.der":"":"":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS+MBEDTLS_ERR_ASN1_OUT_OF_DATA
+
+OID get numeric string - hardware module name
+oid_get_numeric_string:"2B06010505070804":0:"1.3.6.1.5.5.7.8.4"
+
+OID get numeric string - multi-byte subidentifier
+oid_get_numeric_string:"29903C":0:"1.1.2108"
+
+OID get numeric string - second component greater than 39
+oid_get_numeric_string:"81010000863A00":0:"2.49.0.0.826.0"
+
+OID get numeric string - multi-byte first subidentifier
+oid_get_numeric_string:"8837":0:"2.999"
+
+OID get numeric string - second subidentifier not terminated
+oid_get_numeric_string:"0081":MBEDTLS_ERR_ASN1_OUT_OF_DATA:""
+
+OID get numeric string - empty oid buffer
+oid_get_numeric_string:"":MBEDTLS_ERR_ASN1_OUT_OF_DATA:""
+
+OID get numeric string - no final / all bytes have top bit set
+oid_get_numeric_string:"818181":MBEDTLS_ERR_ASN1_OUT_OF_DATA:""
+
+OID get numeric string - 0.39
+oid_get_numeric_string:"27":0:"0.39"
+
+OID get numeric string - 1.0
+oid_get_numeric_string:"28":0:"1.0"
+
+OID get numeric string - 1.39
+oid_get_numeric_string:"4f":0:"1.39"
+
+OID get numeric string - 2.0
+oid_get_numeric_string:"50":0:"2.0"
+
+OID get numeric string - 1 byte first subidentifier beyond 2.39
+oid_get_numeric_string:"7f":0:"2.47"
+
+# Encodes the number 0x0400000000 as a subidentifier which overflows 32-bits
+OID get numeric string - 32-bit overflow
+oid_get_numeric_string:"C080808000":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID get numeric string - 32-bit overflow, second subidentifier
+oid_get_numeric_string:"2BC080808000":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID get numeric string - overlong encoding
+oid_get_numeric_string:"8001":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID get numeric string - overlong encoding, second subidentifier
+oid_get_numeric_string:"2B8001":MBEDTLS_ERR_ASN1_INVALID_DATA:""
diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function
index 9fc0e55..fae3657 100644
--- a/tests/suites/test_suite_x509parse.function
+++ b/tests/suites/test_suite_x509parse.function
@@ -10,6 +10,8 @@
#include "mbedtls/base64.h"
#include "mbedtls/error.h"
#include "mbedtls/pk.h"
+#include "mbedtls/asn1.h"
+#include "mbedtls/asn1write.h"
#include "string.h"
#if MBEDTLS_X509_MAX_INTERMEDIATE_CA > 19
@@ -1747,3 +1749,27 @@
mbedtls_x509_crt_free(&crt);
}
/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
+void oid_get_numeric_string(data_t *oid, int error_ret, char *result_str)
+{
+ char buf[256];
+ mbedtls_asn1_buf input_oid = { 0, 0, NULL };
+ int ret;
+
+ input_oid.tag = MBEDTLS_ASN1_OID;
+ /* Test that an empty OID is not dereferenced */
+ input_oid.p = oid->len ? oid->x : (void *) 1;
+ input_oid.len = oid->len;
+
+ ret = mbedtls_oid_get_numeric_string(buf, sizeof(buf), &input_oid);
+
+ if (error_ret == 0) {
+ TEST_EQUAL(ret, strlen(result_str));
+ TEST_ASSERT(ret >= 3);
+ TEST_EQUAL(strcmp(buf, result_str), 0);
+ } else {
+ TEST_EQUAL(ret, error_ret);
+ }
+}
+/* END_CASE */
diff --git a/tests/suites/test_suite_x509write.data b/tests/suites/test_suite_x509write.data
index 3fbb721..e4e08da 100644
--- a/tests/suites/test_suite_x509write.data
+++ b/tests/suites/test_suite_x509write.data
@@ -268,3 +268,52 @@
Check max extension length
x509_set_extension_length_check:
+
+OID from numeric string - hardware module name
+oid_from_numeric_string:"1.3.6.1.5.5.7.8.4":0:"2B06010505070804"
+
+OID from numeric string - multi-byte subidentifier
+oid_from_numeric_string:"1.1.2108":0:"29903C"
+
+OID from numeric string - second component greater than 39
+oid_from_numeric_string:"2.49.0.0.826.0":0:"81010000863A00"
+
+OID from numeric string - multi-byte first subidentifier
+oid_from_numeric_string:"2.999":0:"8837"
+
+OID from numeric string - empty string input
+oid_from_numeric_string:"":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID from numeric string - first component not a number
+oid_from_numeric_string:"abc.1.2":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID from numeric string - second component not a number
+oid_from_numeric_string:"1.abc.2":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID from numeric string - first component too large
+oid_from_numeric_string:"3.1":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID from numeric string - first component < 2, second > 39
+oid_from_numeric_string:"1.40":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID from numeric string - third component not a number
+oid_from_numeric_string:"1.2.abc":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID from numeric string - non-'.' separator between first and second
+oid_from_numeric_string:"1/2.3.4":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID from numeric string - non-'.' separator between second and third
+oid_from_numeric_string:"1.2/3.4":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID from numeric string - non-'.' separator between third and fourth
+oid_from_numeric_string:"1.2.3/4":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID from numeric string - OID greater than max length (129 components)
+oid_from_numeric_string:"1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
+OID from numeric string - OID with maximum subidentifier
+oid_from_numeric_string:"2.4294967215":0:"8FFFFFFF7F"
+
+OID from numeric string - OID with overflowing subidentifier
+oid_from_numeric_string:"2.4294967216":MBEDTLS_ERR_ASN1_INVALID_DATA:""
+
diff --git a/tests/suites/test_suite_x509write.function b/tests/suites/test_suite_x509write.function
index eb3c2f7..64b4e9e 100644
--- a/tests/suites/test_suite_x509write.function
+++ b/tests/suites/test_suite_x509write.function
@@ -6,6 +6,7 @@
#include "mbedtls/pem.h"
#include "mbedtls/oid.h"
#include "mbedtls/rsa.h"
+#include "mbedtls/asn1.h"
#include "mbedtls/asn1write.h"
#include "mbedtls/pk.h"
#include "mbedtls/psa_util.h"
@@ -761,3 +762,29 @@
TEST_ASSERT(MBEDTLS_ERR_X509_BAD_INPUT_DATA == ret);
}
/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
+void oid_from_numeric_string(char *oid_str, int error_ret,
+ data_t *exp_oid_buf)
+{
+ mbedtls_asn1_buf oid = { 0, 0, NULL };
+ mbedtls_asn1_buf exp_oid = { 0, 0, NULL };
+ int ret;
+
+ exp_oid.tag = MBEDTLS_ASN1_OID;
+ exp_oid.p = exp_oid_buf->x;
+ exp_oid.len = exp_oid_buf->len;
+
+ ret = mbedtls_oid_from_numeric_string(&oid, oid_str, strlen(oid_str));
+
+ if (error_ret == 0) {
+ TEST_EQUAL(oid.len, exp_oid.len);
+ TEST_ASSERT(memcmp(oid.p, exp_oid.p, oid.len) == 0);
+ mbedtls_free(oid.p);
+ oid.p = NULL;
+ oid.len = 0;
+ } else {
+ TEST_EQUAL(ret, error_ret);
+ }
+}
+/* END_CASE */
diff --git a/tf-psa-crypto/drivers/builtin/include/mbedtls/oid.h b/tf-psa-crypto/drivers/builtin/include/mbedtls/oid.h
index 0366944..e0ad35e 100644
--- a/tf-psa-crypto/drivers/builtin/include/mbedtls/oid.h
+++ b/tf-psa-crypto/drivers/builtin/include/mbedtls/oid.h
@@ -483,38 +483,6 @@
} mbedtls_oid_descriptor_t;
/**
- * \brief Translate an ASN.1 OID into its numeric representation
- * (e.g. "\x2A\x86\x48\x86\xF7\x0D" into "1.2.840.113549")
- *
- * \param buf buffer to put representation in
- * \param size size of the buffer
- * \param oid OID to translate
- *
- * \return Length of the string written (excluding final NULL) or
- * MBEDTLS_ERR_OID_BUF_TOO_SMALL in case of error
- */
-int mbedtls_oid_get_numeric_string(char *buf, size_t size, const mbedtls_asn1_buf *oid);
-
-/**
- * \brief Translate a string containing a dotted-decimal
- * representation of an ASN.1 OID into its encoded form
- * (e.g. "1.2.840.113549" into "\x2A\x86\x48\x86\xF7\x0D").
- * On success, this function allocates oid->buf from the
- * heap. It must be freed by the caller using mbedtls_free().
- *
- * \param oid #mbedtls_asn1_buf to populate with the DER-encoded OID
- * \param oid_str string representation of the OID to parse
- * \param size length of the OID string, not including any null terminator
- *
- * \return 0 if successful
- * \return #MBEDTLS_ERR_ASN1_INVALID_DATA if \p oid_str does not
- * represent a valid OID
- * \return #MBEDTLS_ERR_ASN1_ALLOC_FAILED if the function fails to
- * allocate oid->buf
- */
-int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid, const char *oid_str, size_t size);
-
-/**
* \brief Translate an X.509 extension OID into local values
*
* \param oid OID to use
diff --git a/tf-psa-crypto/drivers/builtin/src/oid.c b/tf-psa-crypto/drivers/builtin/src/oid.c
index 862f09d..ae30dfe 100644
--- a/tf-psa-crypto/drivers/builtin/src/oid.c
+++ b/tf-psa-crypto/drivers/builtin/src/oid.c
@@ -918,249 +918,4 @@
cipher_alg)
#endif /* MBEDTLS_PKCS12_C && MBEDTLS_CIPHER_C */
-/* Return the x.y.z.... style numeric string for the given OID */
-int mbedtls_oid_get_numeric_string(char *buf, size_t size,
- const mbedtls_asn1_buf *oid)
-{
- int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
- char *p = buf;
- size_t n = size;
- unsigned int value = 0;
-
- if (size > INT_MAX) {
- /* Avoid overflow computing return value */
- return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
- }
-
- if (oid->len <= 0) {
- /* OID must not be empty */
- return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
- }
-
- for (size_t i = 0; i < oid->len; i++) {
- /* Prevent overflow in value. */
- if (value > (UINT_MAX >> 7)) {
- return MBEDTLS_ERR_ASN1_INVALID_DATA;
- }
- if ((value == 0) && ((oid->p[i]) == 0x80)) {
- /* Overlong encoding is not allowed */
- return MBEDTLS_ERR_ASN1_INVALID_DATA;
- }
-
- value <<= 7;
- value |= oid->p[i] & 0x7F;
-
- if (!(oid->p[i] & 0x80)) {
- /* Last byte */
- if (n == size) {
- int component1;
- unsigned int component2;
- /* First subidentifier contains first two OID components */
- if (value >= 80) {
- component1 = '2';
- component2 = value - 80;
- } else if (value >= 40) {
- component1 = '1';
- component2 = value - 40;
- } else {
- component1 = '0';
- component2 = value;
- }
- ret = mbedtls_snprintf(p, n, "%c.%u", component1, component2);
- } else {
- ret = mbedtls_snprintf(p, n, ".%u", value);
- }
- if (ret < 2 || (size_t) ret >= n) {
- return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
- }
- n -= (size_t) ret;
- p += ret;
- value = 0;
- }
- }
-
- if (value != 0) {
- /* Unterminated subidentifier */
- return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
- }
-
- return (int) (size - n);
-}
-
-static int oid_parse_number(unsigned int *num, const char **p, const char *bound)
-{
- int ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
-
- *num = 0;
-
- while (*p < bound && **p >= '0' && **p <= '9') {
- ret = 0;
- if (*num > (UINT_MAX / 10)) {
- return MBEDTLS_ERR_ASN1_INVALID_DATA;
- }
- *num *= 10;
- *num += **p - '0';
- (*p)++;
- }
- return ret;
-}
-
-static size_t oid_subidentifier_num_bytes(unsigned int value)
-{
- size_t num_bytes = 0;
-
- do {
- value >>= 7;
- num_bytes++;
- } while (value != 0);
-
- return num_bytes;
-}
-
-static int oid_subidentifier_encode_into(unsigned char **p,
- unsigned char *bound,
- unsigned int value)
-{
- size_t num_bytes = oid_subidentifier_num_bytes(value);
-
- if ((size_t) (bound - *p) < num_bytes) {
- return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
- }
- (*p)[num_bytes - 1] = (unsigned char) (value & 0x7f);
- value >>= 7;
-
- for (size_t i = 2; i <= num_bytes; i++) {
- (*p)[num_bytes - i] = 0x80 | (unsigned char) (value & 0x7f);
- value >>= 7;
- }
- *p += num_bytes;
-
- return 0;
-}
-
-/* Return the OID for the given x.y.z.... style numeric string */
-int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid,
- const char *oid_str, size_t size)
-{
- int ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
- const char *str_ptr = oid_str;
- const char *str_bound = oid_str + size;
- unsigned int val = 0;
- unsigned int component1, component2;
- size_t encoded_len;
- unsigned char *resized_mem;
-
- /* Count the number of dots to get a worst-case allocation size. */
- size_t num_dots = 0;
- for (size_t i = 0; i < size; i++) {
- if (oid_str[i] == '.') {
- num_dots++;
- }
- }
- /* Allocate maximum possible required memory:
- * There are (num_dots + 1) integer components, but the first 2 share the
- * same subidentifier, so we only need num_dots subidentifiers maximum. */
- if (num_dots == 0 || (num_dots > MBEDTLS_OID_MAX_COMPONENTS - 1)) {
- return MBEDTLS_ERR_ASN1_INVALID_DATA;
- }
- /* Each byte can store 7 bits, calculate number of bytes for a
- * subidentifier:
- *
- * bytes = ceil(subidentifer_size * 8 / 7)
- */
- size_t bytes_per_subidentifier = (((sizeof(unsigned int) * 8) - 1) / 7)
- + 1;
- size_t max_possible_bytes = num_dots * bytes_per_subidentifier;
- oid->p = mbedtls_calloc(max_possible_bytes, 1);
- if (oid->p == NULL) {
- return MBEDTLS_ERR_ASN1_ALLOC_FAILED;
- }
- unsigned char *out_ptr = oid->p;
- unsigned char *out_bound = oid->p + max_possible_bytes;
-
- ret = oid_parse_number(&component1, &str_ptr, str_bound);
- if (ret != 0) {
- goto error;
- }
- if (component1 > 2) {
- /* First component can't be > 2 */
- ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
- goto error;
- }
- if (str_ptr >= str_bound || *str_ptr != '.') {
- ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
- goto error;
- }
- str_ptr++;
-
- ret = oid_parse_number(&component2, &str_ptr, str_bound);
- if (ret != 0) {
- goto error;
- }
- if ((component1 < 2) && (component2 > 39)) {
- /* Root nodes 0 and 1 may have up to 40 children, numbered 0-39 */
- ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
- goto error;
- }
- if (str_ptr < str_bound) {
- if (*str_ptr == '.') {
- str_ptr++;
- } else {
- ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
- goto error;
- }
- }
-
- if (component2 > (UINT_MAX - (component1 * 40))) {
- ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
- goto error;
- }
- ret = oid_subidentifier_encode_into(&out_ptr, out_bound,
- (component1 * 40) + component2);
- if (ret != 0) {
- goto error;
- }
-
- while (str_ptr < str_bound) {
- ret = oid_parse_number(&val, &str_ptr, str_bound);
- if (ret != 0) {
- goto error;
- }
- if (str_ptr < str_bound) {
- if (*str_ptr == '.') {
- str_ptr++;
- } else {
- ret = MBEDTLS_ERR_ASN1_INVALID_DATA;
- goto error;
- }
- }
-
- ret = oid_subidentifier_encode_into(&out_ptr, out_bound, val);
- if (ret != 0) {
- goto error;
- }
- }
-
- encoded_len = (size_t) (out_ptr - oid->p);
- resized_mem = mbedtls_calloc(encoded_len, 1);
- if (resized_mem == NULL) {
- ret = MBEDTLS_ERR_ASN1_ALLOC_FAILED;
- goto error;
- }
- memcpy(resized_mem, oid->p, encoded_len);
- mbedtls_free(oid->p);
- oid->p = resized_mem;
- oid->len = encoded_len;
-
- oid->tag = MBEDTLS_ASN1_OID;
-
- return 0;
-
-error:
- mbedtls_free(oid->p);
- oid->p = NULL;
- oid->len = 0;
- return ret;
-}
-
#endif /* MBEDTLS_OID_C */
diff --git a/tf-psa-crypto/tests/suites/test_suite_oid.data b/tf-psa-crypto/tests/suites/test_suite_oid.data
index 8919d42..42b0505 100644
--- a/tf-psa-crypto/tests/suites/test_suite_oid.data
+++ b/tf-psa-crypto/tests/suites/test_suite_oid.data
@@ -105,103 +105,6 @@
OID hash id - invalid oid
oid_get_md_alg_id:"2B864886f70d0204":-1
-OID get numeric string - hardware module name
-oid_get_numeric_string:"2B06010505070804":0:"1.3.6.1.5.5.7.8.4"
-
-OID get numeric string - multi-byte subidentifier
-oid_get_numeric_string:"29903C":0:"1.1.2108"
-
-OID get numeric string - second component greater than 39
-oid_get_numeric_string:"81010000863A00":0:"2.49.0.0.826.0"
-
-OID get numeric string - multi-byte first subidentifier
-oid_get_numeric_string:"8837":0:"2.999"
-
-OID get numeric string - second subidentifier not terminated
-oid_get_numeric_string:"0081":MBEDTLS_ERR_ASN1_OUT_OF_DATA:""
-
-OID get numeric string - empty oid buffer
-oid_get_numeric_string:"":MBEDTLS_ERR_ASN1_OUT_OF_DATA:""
-
-OID get numeric string - no final / all bytes have top bit set
-oid_get_numeric_string:"818181":MBEDTLS_ERR_ASN1_OUT_OF_DATA:""
-
-OID get numeric string - 0.39
-oid_get_numeric_string:"27":0:"0.39"
-
-OID get numeric string - 1.0
-oid_get_numeric_string:"28":0:"1.0"
-
-OID get numeric string - 1.39
-oid_get_numeric_string:"4f":0:"1.39"
-
-OID get numeric string - 2.0
-oid_get_numeric_string:"50":0:"2.0"
-
-OID get numeric string - 1 byte first subidentifier beyond 2.39
-oid_get_numeric_string:"7f":0:"2.47"
-
-# Encodes the number 0x0400000000 as a subidentifier which overflows 32-bits
-OID get numeric string - 32-bit overflow
-oid_get_numeric_string:"C080808000":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID get numeric string - 32-bit overflow, second subidentifier
-oid_get_numeric_string:"2BC080808000":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID get numeric string - overlong encoding
-oid_get_numeric_string:"8001":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID get numeric string - overlong encoding, second subidentifier
-oid_get_numeric_string:"2B8001":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID from numeric string - hardware module name
-oid_from_numeric_string:"1.3.6.1.5.5.7.8.4":0:"2B06010505070804"
-
-OID from numeric string - multi-byte subidentifier
-oid_from_numeric_string:"1.1.2108":0:"29903C"
-
-OID from numeric string - second component greater than 39
-oid_from_numeric_string:"2.49.0.0.826.0":0:"81010000863A00"
-
-OID from numeric string - multi-byte first subidentifier
-oid_from_numeric_string:"2.999":0:"8837"
-
-OID from numeric string - empty string input
-oid_from_numeric_string:"":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID from numeric string - first component not a number
-oid_from_numeric_string:"abc.1.2":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID from numeric string - second component not a number
-oid_from_numeric_string:"1.abc.2":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID from numeric string - first component too large
-oid_from_numeric_string:"3.1":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID from numeric string - first component < 2, second > 39
-oid_from_numeric_string:"1.40":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID from numeric string - third component not a number
-oid_from_numeric_string:"1.2.abc":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID from numeric string - non-'.' separator between first and second
-oid_from_numeric_string:"1/2.3.4":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID from numeric string - non-'.' separator between second and third
-oid_from_numeric_string:"1.2/3.4":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID from numeric string - non-'.' separator between third and fourth
-oid_from_numeric_string:"1.2.3/4":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID from numeric string - OID greater than max length (129 components)
-oid_from_numeric_string:"1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1.2.3.4.5.6.7.8.1":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
-OID from numeric string - OID with maximum subidentifier
-oid_from_numeric_string:"2.4294967215":0:"8FFFFFFF7F"
-
-OID from numeric string - OID with overflowing subidentifier
-oid_from_numeric_string:"2.4294967216":MBEDTLS_ERR_ASN1_INVALID_DATA:""
-
mbedtls_oid_get_md_hmac - RIPEMD160
depends_on:PSA_WANT_ALG_RIPEMD160
mbedtls_oid_get_md_hmac:"2B06010505080104":MBEDTLS_MD_RIPEMD160
diff --git a/tf-psa-crypto/tests/suites/test_suite_oid.function b/tf-psa-crypto/tests/suites/test_suite_oid.function
index 337f843..e96425e 100644
--- a/tf-psa-crypto/tests/suites/test_suite_oid.function
+++ b/tf-psa-crypto/tests/suites/test_suite_oid.function
@@ -118,53 +118,3 @@
}
}
/* END_CASE */
-
-/* BEGIN_CASE */
-void oid_get_numeric_string(data_t *oid, int error_ret, char *result_str)
-{
- char buf[256];
- mbedtls_asn1_buf input_oid = { 0, 0, NULL };
- int ret;
-
- input_oid.tag = MBEDTLS_ASN1_OID;
- /* Test that an empty OID is not dereferenced */
- input_oid.p = oid->len ? oid->x : (void *) 1;
- input_oid.len = oid->len;
-
- ret = mbedtls_oid_get_numeric_string(buf, sizeof(buf), &input_oid);
-
- if (error_ret == 0) {
- TEST_EQUAL(ret, strlen(result_str));
- TEST_ASSERT(ret >= 3);
- TEST_EQUAL(strcmp(buf, result_str), 0);
- } else {
- TEST_EQUAL(ret, error_ret);
- }
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void oid_from_numeric_string(char *oid_str, int error_ret,
- data_t *exp_oid_buf)
-{
- mbedtls_asn1_buf oid = { 0, 0, NULL };
- mbedtls_asn1_buf exp_oid = { 0, 0, NULL };
- int ret;
-
- exp_oid.tag = MBEDTLS_ASN1_OID;
- exp_oid.p = exp_oid_buf->x;
- exp_oid.len = exp_oid_buf->len;
-
- ret = mbedtls_oid_from_numeric_string(&oid, oid_str, strlen(oid_str));
-
- if (error_ret == 0) {
- TEST_EQUAL(oid.len, exp_oid.len);
- TEST_ASSERT(memcmp(oid.p, exp_oid.p, oid.len) == 0);
- mbedtls_free(oid.p);
- oid.p = NULL;
- oid.len = 0;
- } else {
- TEST_EQUAL(ret, error_ret);
- }
-}
-/* END_CASE */