From 9f41ed8c728a9ec6454df314dc523d54fd2f9f49 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Fri, 31 Mar 2023 16:11:58 +0200 Subject: [PATCH 1/6] Add missing guards --- src/ssl_asn1.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ssl_asn1.c b/src/ssl_asn1.c index 27ccd13c8d..9d8cb554dc 100644 --- a/src/ssl_asn1.c +++ b/src/ssl_asn1.c @@ -40,6 +40,8 @@ * ASN1_item APIs ******************************************************************************/ +#ifndef NO_ASN + #ifdef OPENSSL_EXTRA #ifdef OPENSSL_ALL @@ -4022,5 +4024,7 @@ void wolfSSL_ASN1_TYPE_set(WOLFSSL_ASN1_TYPE *a, int type, void *value) #endif /* OPENSSL_ALL || WOLFSSL_WPAS */ +#endif /* !NO_ASN */ + #endif /* !WOLFSSL_SSL_ASN1_INCLUDED */ From 7138b66b5e033f85391ac92a0971067ecd5acb25 Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Fri, 31 Mar 2023 11:22:58 -0400 Subject: [PATCH 2/6] Compiler error --- src/ssl_asn1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ssl_asn1.c b/src/ssl_asn1.c index 9d8cb554dc..213ccebe08 100644 --- a/src/ssl_asn1.c +++ b/src/ssl_asn1.c @@ -2364,7 +2364,7 @@ char* wolfSSL_i2s_ASN1_STRING(WOLFSSL_v3_ext_method *method, } /* Handle 0 length data separately. */ else if (s->length == 0) { - ret = XMALLOC(1, NULL, DYNAMIC_TYPE_TMP_BUFFER); + ret = (char *)XMALLOC(1, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (ret != NULL) { ret[0] = '\0'; } From c8e1731cb7e0d5381c8dfd9817ae05382d8565c8 Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Fri, 31 Mar 2023 13:21:13 -0400 Subject: [PATCH 3/6] Fix dependency issues --- src/ssl.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index cbd79414e0..5077a21f8f 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -150,9 +150,6 @@ int wolfssl_bn_get_value(WOLFSSL_BIGNUM* bn, mp_int* mpi); int wolfssl_bn_set_value(WOLFSSL_BIGNUM** bn, mp_int* mpi); #endif -#if defined(OPENSSL_EXTRA) && !defined(NO_ASN) - static int wolfssl_bn_set_neg(WOLFSSL_BIGNUM* bn, int n); -#endif #if defined(WOLFSSL_QT) #include @@ -211,11 +208,6 @@ #define WOLFSSL_EVP_INCLUDED #include "wolfcrypt/src/evp.c" -#ifndef OPENSSL_EXTRA_NO_ASN1 -#define WOLFSSL_SSL_ASN1_INCLUDED -#include "src/ssl_asn1.c" -#endif /* OPENSSL_EXTRA_NO_ASN1 */ - #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \ !defined(WOLFCRYPT_ONLY) /* Convert shortname to NID. @@ -416,6 +408,11 @@ WC_RNG* wolfssl_make_rng(WC_RNG* rng, int* local) #define WOLFSSL_SSL_BN_INCLUDED #include "src/ssl_bn.c" +#ifndef OPENSSL_EXTRA_NO_ASN1 +#define WOLFSSL_SSL_ASN1_INCLUDED +#include "src/ssl_asn1.c" +#endif /* OPENSSL_EXTRA_NO_ASN1 */ + #define WOLFSSL_PK_INCLUDED #include "src/pk.c" From 80a0fb548a0908eda503f42168ed495f6ca7abe5 Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Fri, 31 Mar 2023 15:29:36 -0400 Subject: [PATCH 4/6] Zero buffer size test should be implemented another way --- tests/api.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/api.c b/tests/api.c index 2fddc90ded..185ff56e77 100644 --- a/tests/api.c +++ b/tests/api.c @@ -31228,8 +31228,10 @@ static int test_wolfSSL_a2i_ASN1_INTEGER(void) BIO_free(out); AssertNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem())); + /* TODO: can't create zero length buffer AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); AssertIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0); + */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0); BIO_free(fixed); @@ -32016,8 +32018,10 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void) AssertIntEQ(p_len, 15); BIO_read(bio, (void*)rbuf, 15); AssertStrEQ((char*)rbuf, "Hello wolfSSL!"); + /* TODO: can't create zero length buffers AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); + */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 14), 1); @@ -32030,8 +32034,10 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void) AssertIntEQ(p_len, 9); BIO_read(bio, (void*)rbuf, 9); AssertStrEQ((char*)rbuf, "a\\+\\;\\<\\>"); + /* TODO: can't create zero length buffers AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0); + */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 8), 1); @@ -32044,8 +32050,10 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void) AssertIntEQ(p_len, 28); BIO_read(bio, (void*)rbuf, 28); AssertStrEQ((char*)rbuf, "OCTET STRING:Hello wolfSSL!"); + /* TODO: can't create zero length buffers AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); + */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 12), 1); @@ -32060,8 +32068,10 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void) AssertIntEQ(p_len, 31); BIO_read(bio, (void*)rbuf, 31); AssertStrEQ((char*)rbuf, "#48656C6C6F20776F6C6653534C2100"); + /* TODO: can't create zero length buffers AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); + */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 30), 1); @@ -32074,8 +32084,10 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void) AssertIntEQ(p_len, 35); BIO_read(bio, (void*)rbuf, 35); AssertStrEQ((char*)rbuf, "#040F48656C6C6F20776F6C6653534C2100"); + /* TODO: can't create zero length buffers AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); + */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 2), 1); @@ -32235,7 +32247,7 @@ static int test_wolfSSL_ASN1_GENERALIZEDTIME_print(void) BIO_free(bio); AssertNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem())); - for (i = 0; i < 20; i++) { + for (i = 1; i < 20; i++) { /* TODO: can't create zero length buffers */ AssertIntEQ(BIO_set_write_buf_size(bio, i), 1); AssertIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, >ime), 0); } @@ -32677,8 +32689,10 @@ static int test_wolfSSL_ASN1_TIME_print(void) AssertIntEQ(XMEMCMP(buf, "Dec 16 21:17:49 2022 GMT", sizeof(buf) - 1), 0); /* Test BIO_write fails. */ + /* TODO: can't create zero length buffers AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); AssertIntEQ(ASN1_TIME_print(fixed, notBefore), 0); + */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(ASN1_TIME_print(fixed, notBefore), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 23), 1); From 18f4b451297e0d3bdbb79ae01fc5ec33416b9d6e Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Fri, 31 Mar 2023 15:44:25 -0400 Subject: [PATCH 5/6] Fix object size --- tests/api.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/api.c b/tests/api.c index 185ff56e77..60fd9eedaf 100644 --- a/tests/api.c +++ b/tests/api.c @@ -31442,6 +31442,7 @@ static int test_wolfSSL_ASN1_OBJECT(void) AssertNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s)); ASN1_OBJECT_free(a); s.obj = der; + s.objSz = sizeof(der); AssertNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s)); ASN1_OBJECT_free(a); ASN1_OBJECT_free(&s); From c56e58db5bb37bda2351777e7881908de7b5c3ec Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Fri, 31 Mar 2023 15:51:28 -0400 Subject: [PATCH 6/6] Remove TODO+bad tests --- tests/api.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/tests/api.c b/tests/api.c index 60fd9eedaf..70c61b06ee 100644 --- a/tests/api.c +++ b/tests/api.c @@ -31228,10 +31228,6 @@ static int test_wolfSSL_a2i_ASN1_INTEGER(void) BIO_free(out); AssertNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem())); - /* TODO: can't create zero length buffer - AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); - AssertIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0); - */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0); BIO_free(fixed); @@ -32019,10 +32015,6 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void) AssertIntEQ(p_len, 15); BIO_read(bio, (void*)rbuf, 15); AssertStrEQ((char*)rbuf, "Hello wolfSSL!"); - /* TODO: can't create zero length buffers - AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); - AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); - */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 14), 1); @@ -32035,10 +32027,6 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void) AssertIntEQ(p_len, 9); BIO_read(bio, (void*)rbuf, 9); AssertStrEQ((char*)rbuf, "a\\+\\;\\<\\>"); - /* TODO: can't create zero length buffers - AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); - AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0); - */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 8), 1); @@ -32051,10 +32039,6 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void) AssertIntEQ(p_len, 28); BIO_read(bio, (void*)rbuf, 28); AssertStrEQ((char*)rbuf, "OCTET STRING:Hello wolfSSL!"); - /* TODO: can't create zero length buffers - AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); - AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); - */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 12), 1); @@ -32069,10 +32053,6 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void) AssertIntEQ(p_len, 31); BIO_read(bio, (void*)rbuf, 31); AssertStrEQ((char*)rbuf, "#48656C6C6F20776F6C6653534C2100"); - /* TODO: can't create zero length buffers - AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); - AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); - */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 30), 1); @@ -32085,10 +32065,6 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void) AssertIntEQ(p_len, 35); BIO_read(bio, (void*)rbuf, 35); AssertStrEQ((char*)rbuf, "#040F48656C6C6F20776F6C6653534C2100"); - /* TODO: can't create zero length buffers - AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); - AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); - */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 2), 1); @@ -32248,7 +32224,7 @@ static int test_wolfSSL_ASN1_GENERALIZEDTIME_print(void) BIO_free(bio); AssertNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem())); - for (i = 1; i < 20; i++) { /* TODO: can't create zero length buffers */ + for (i = 1; i < 20; i++) { AssertIntEQ(BIO_set_write_buf_size(bio, i), 1); AssertIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, >ime), 0); } @@ -32690,10 +32666,6 @@ static int test_wolfSSL_ASN1_TIME_print(void) AssertIntEQ(XMEMCMP(buf, "Dec 16 21:17:49 2022 GMT", sizeof(buf) - 1), 0); /* Test BIO_write fails. */ - /* TODO: can't create zero length buffers - AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1); - AssertIntEQ(ASN1_TIME_print(fixed, notBefore), 0); - */ AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1); AssertIntEQ(ASN1_TIME_print(fixed, notBefore), 0); AssertIntEQ(BIO_set_write_buf_size(fixed, 23), 1);