Skip to content

Commit 9f0aa38

Browse files
authored
Merge pull request #7223 from gojimmypi/PR-debug-messages
Add wolfSSL debug messages
2 parents 2e970f5 + bf29066 commit 9f0aa38

10 files changed

Lines changed: 168 additions & 34 deletions

File tree

src/internal.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7405,6 +7405,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
74057405

74067406
/* all done with init, now can return errors, call other stuff */
74077407
if ((ret = ReinitSSL(ssl, ctx, writeDup)) != 0) {
7408+
WOLFSSL_MSG_EX("ReinitSSL failed. err = %d", ret);
74087409
return ret;
74097410
}
74107411

@@ -7438,6 +7439,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
74387439
&& ret != NO_PRIVATE_KEY
74397440
#endif
74407441
) {
7442+
WOLFSSL_MSG_EX("SetSSL_CTX failed. err = %d", ret);
74417443
return ret;
74427444
}
74437445
ssl->options.dtls = ssl->version.major == DTLS_MAJOR;
@@ -7451,8 +7453,10 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
74517453

74527454
/* hsHashes */
74537455
ret = InitHandshakeHashes(ssl);
7454-
if (ret != 0)
7456+
if (ret != 0) {
7457+
WOLFSSL_MSG_EX("InitHandshakeHashes failed. err = %d", ret);
74557458
return ret;
7459+
}
74567460

74577461
#if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_SERVER)
74587462
if (ssl->options.dtls && ssl->options.side == WOLFSSL_SERVER_END) {
@@ -7493,10 +7497,10 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
74937497

74947498
ssl->session = wolfSSL_NewSession(ssl->heap);
74957499
if (ssl->session == NULL) {
7496-
WOLFSSL_MSG("SSL Session Memory error");
7500+
WOLFSSL_MSG_EX("SSL Session Memory error. wolfSSL_NewSession "
7501+
"err = %d", ret);
74977502
return MEMORY_E;
74987503
}
7499-
75007504
#ifdef HAVE_SESSION_TICKET
75017505
ssl->options.noTicketTls12 = ctx->noTicketTls12;
75027506
#endif
@@ -7573,6 +7577,8 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
75737577
ssl->sigSpec = ctx->sigSpec;
75747578
ssl->sigSpecSz = ctx->sigSpecSz;
75757579
#endif /* WOLFSSL_DUAL_ALG_CERTS */
7580+
/* Returns 0 on success, not WOLFSSL_SUCCESS (1) */
7581+
WOLFSSL_MSG_EX("InitSSL done. return 0 (success)");
75767582
return 0;
75777583
}
75787584

@@ -20736,8 +20742,10 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2073620742
#endif
2073720743

2073820744
ret = RetrySendAlert(ssl);
20739-
if (ret != 0)
20745+
if (ret != 0) {
20746+
WOLFSSL_MSG_EX("RetrySendAlert failed, giving up. err = %d", ret);
2074020747
return ret;
20748+
}
2074120749

2074220750
for (;;) {
2074320751
switch (ssl->options.processReply) {
@@ -24634,8 +24642,16 @@ static int SendAlert_ex(WOLFSSL* ssl, int severity, int type)
2463424642

2463524643
int RetrySendAlert(WOLFSSL* ssl)
2463624644
{
24637-
int type = ssl->pendingAlert.code;
24638-
int severity = ssl->pendingAlert.level;
24645+
int type;
24646+
int severity;
24647+
WOLFSSL_ENTER("RetrySendAlert");
24648+
24649+
if (ssl == NULL) {
24650+
return BAD_FUNC_ARG;
24651+
}
24652+
24653+
type = ssl->pendingAlert.code;
24654+
severity = ssl->pendingAlert.level;
2463924655

2464024656
if (severity == alert_none)
2464124657
return 0;
@@ -24649,6 +24665,12 @@ int RetrySendAlert(WOLFSSL* ssl)
2464924665
/* send alert message */
2465024666
int SendAlert(WOLFSSL* ssl, int severity, int type)
2465124667
{
24668+
WOLFSSL_ENTER("SendAlert");
24669+
24670+
if (ssl == NULL) {
24671+
return BAD_FUNC_ARG;
24672+
}
24673+
2465224674
if (ssl->pendingAlert.level != alert_none) {
2465324675
int ret = RetrySendAlert(ssl);
2465424676
if (ret != 0) {

src/ssl.c

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,18 +1474,35 @@ WOLFSSL* wolfSSL_new(WOLFSSL_CTX* ctx)
14741474

14751475
WOLFSSL_ENTER("wolfSSL_new");
14761476

1477-
if (ctx == NULL)
1478-
return ssl;
1477+
if (ctx == NULL) {
1478+
WOLFSSL_MSG("wolfSSL_new ctx is null");
1479+
return NULL;
1480+
}
14791481

14801482
ssl = (WOLFSSL*) XMALLOC(sizeof(WOLFSSL), ctx->heap, DYNAMIC_TYPE_SSL);
1481-
if (ssl) {
1482-
if ( (ret = InitSSL(ssl, ctx, 0)) < 0) {
1483+
1484+
if (ssl == NULL) {
1485+
WOLFSSL_MSG_EX("ssl xmalloc failed to allocate %d bytes",
1486+
(int)sizeof(WOLFSSL));
1487+
}
1488+
else {
1489+
ret = InitSSL(ssl, ctx, 0);
1490+
if (ret < 0) {
1491+
WOLFSSL_MSG_EX("wolfSSL_new failed during InitSSL. err = %d", ret);
14831492
FreeSSL(ssl, ctx->heap);
1484-
ssl = 0;
1493+
ssl = NULL;
14851494
}
1486-
}
1495+
else if (ret == 0) {
1496+
WOLFSSL_MSG("wolfSSL_new InitSSL success");
1497+
}
1498+
else {
1499+
/* Only success (0) or negative values should ever be seen. */
1500+
WOLFSSL_MSG_EX("WARNING: wolfSSL_new unexpected InitSSL return"
1501+
" value = %d", ret);
1502+
} /* InitSSL check */
1503+
} /* ssl XMALLOC success */
14871504

1488-
WOLFSSL_LEAVE("wolfSSL_new", ret);
1505+
WOLFSSL_LEAVE("wolfSSL_new InitSSL =", ret);
14891506
(void)ret;
14901507

14911508
return ssl;
@@ -1496,8 +1513,14 @@ WOLFSSL_ABI
14961513
void wolfSSL_free(WOLFSSL* ssl)
14971514
{
14981515
WOLFSSL_ENTER("wolfSSL_free");
1499-
if (ssl)
1516+
1517+
if (ssl) {
1518+
WOLFSSL_MSG_EX("Free SSL: %p", (uintptr_t)ssl);
15001519
FreeSSL(ssl, ssl->ctx->heap);
1520+
}
1521+
else {
1522+
WOLFSSL_MSG("Free SSL: wolfSSL_free already null");
1523+
}
15011524
WOLFSSL_LEAVE("wolfSSL_free", 0);
15021525
}
15031526

@@ -11906,7 +11929,10 @@ static int wolfSSL_parse_cipher_list(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
1190611929
}
1190711930

1190811931
/* list contains ciphers either only for TLS 1.3 or <= TLS 1.2 */
11909-
11932+
if (suites->suiteSz == 0) {
11933+
WOLFSSL_MSG("Warning suites->suiteSz = 0 set to WOLFSSL_MAX_SUITE_SZ");
11934+
suites->suiteSz = WOLFSSL_MAX_SUITE_SZ;
11935+
}
1191011936
#ifdef WOLFSSL_SMALL_STACK
1191111937
if (suites->suiteSz > 0) {
1191211938
suitesCpy = (byte*)XMALLOC(suites->suiteSz, NULL,
@@ -12598,10 +12624,13 @@ int wolfSSL_DTLS_SetCookieSecret(WOLFSSL* ssl,
1259812624
return wolfSSL_connect_TLSv13(ssl);
1259912625
#else
1260012626
#ifdef WOLFSSL_TLS13
12601-
if (ssl->options.tls1_3)
12627+
if (ssl->options.tls1_3) {
12628+
WOLFSSL_MSG("TLS 1.3");
1260212629
return wolfSSL_connect_TLSv13(ssl);
12630+
}
1260312631
#endif
1260412632

12633+
WOLFSSL_MSG("TLS 1.2 or lower");
1260512634
WOLFSSL_ENTER("wolfSSL_connect");
1260612635

1260712636
/* make sure this wolfSSL object has arrays and rng setup. Protects
@@ -12719,11 +12748,14 @@ int wolfSSL_DTLS_SetCookieSecret(WOLFSSL* ssl,
1271912748
neededState = SERVER_HELLOVERIFYREQUEST_COMPLETE;
1272012749
#endif
1272112750
/* get response */
12751+
WOLFSSL_MSG("Server state up to needed state.");
1272212752
while (ssl->options.serverState < neededState) {
12753+
WOLFSSL_MSG("Progressing server state...");
1272312754
#ifdef WOLFSSL_TLS13
1272412755
if (ssl->options.tls1_3)
1272512756
return wolfSSL_connect_TLSv13(ssl);
1272612757
#endif
12758+
WOLFSSL_MSG("ProcessReply...");
1272712759
if ( (ssl->error = ProcessReply(ssl)) < 0) {
1272812760
WOLFSSL_ERROR(ssl->error);
1272912761
return WOLFSSL_FATAL_ERROR;
@@ -12739,6 +12771,7 @@ int wolfSSL_DTLS_SetCookieSecret(WOLFSSL* ssl,
1273912771
neededState = SERVER_HELLODONE_COMPLETE;
1274012772
}
1274112773
}
12774+
WOLFSSL_MSG("ProcessReply done.");
1274212775

1274312776
#ifdef WOLFSSL_DTLS13
1274412777
if (ssl->options.dtls && IsAtLeastTLSv1_3(ssl->version)
@@ -16903,6 +16936,11 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1690316936
}
1690416937
#endif
1690516938

16939+
#ifdef NO_FILESYSTEM
16940+
WOLFSSL_MSG("wolfSSL_CTX_set_default_verify_paths not supported"
16941+
" with NO_FILESYSTEM enabled");
16942+
ret = WOLFSSL_FATAL_ERROR;
16943+
#else
1690616944
ret = wolfSSL_CTX_load_system_CA_certs(ctx);
1690716945
if (ret == WOLFSSL_BAD_PATH) {
1690816946
/*
@@ -16911,6 +16949,7 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1691116949
*/
1691216950
ret = WOLFSSL_SUCCESS;
1691316951
}
16952+
#endif
1691416953

1691516954
WOLFSSL_LEAVE("wolfSSL_CTX_set_default_verify_paths", ret);
1691616955

src/ssl_certman.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include <wolfssl/wolfcrypt/settings.h>
2727

28-
#include <wolfssl/internal.h>
28+
#include <wolfssl/internal.h>
2929

3030
#if !defined(WOLFSSL_SSL_CERTMAN_INCLUDED)
3131
#ifndef WOLFSSL_IGNORE_FILE_WARN
@@ -89,11 +89,22 @@ WOLFSSL_CERT_MANAGER* wolfSSL_CertManagerNew_ex(void* heap)
8989
WOLFSSL_CERT_MANAGER* cm;
9090

9191
WOLFSSL_ENTER("wolfSSL_CertManagerNew");
92+
if (heap == NULL) {
93+
WOLFSSL_MSG("heap param is null");
94+
}
95+
else {
96+
/* Some systems may have heap in unexpected segments. (IRAM vs DRAM) */
97+
WOLFSSL_MSG_EX("heap param = %p", heap);
98+
}
99+
WOLFSSL_MSG_EX("DYNAMIC_TYPE_CERT_MANAGER Allocating = %d bytes",
100+
(word32)sizeof(WOLFSSL_CERT_MANAGER));
92101

93102
/* Allocate memory for certificate manager. */
94103
cm = (WOLFSSL_CERT_MANAGER*)XMALLOC(sizeof(WOLFSSL_CERT_MANAGER), heap,
95104
DYNAMIC_TYPE_CERT_MANAGER);
96105
if (cm == NULL) {
106+
WOLFSSL_MSG_EX("XMALLOC failed to allocate WOLFSSL_CERT_MANAGER %d "
107+
"bytes.", (int)sizeof(WOLFSSL_CERT_MANAGER));
97108
err = 1;
98109
}
99110
if (!err) {

src/tls.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7459,7 +7459,9 @@ static int TLSX_KeyShare_GenEccKey(WOLFSSL *ssl, KeyShareEntry* kse)
74597459
/* Allocate an ECC key to hold private key. */
74607460
kse->key = (byte*)XMALLOC(sizeof(ecc_key), ssl->heap, DYNAMIC_TYPE_ECC);
74617461
if (kse->key == NULL) {
7462-
WOLFSSL_MSG("EccTempKey Memory error");
7462+
WOLFSSL_MSG_EX("Failed to allocate %d bytes, ssl->heap: %p",
7463+
(int)sizeof(ecc_key), (uintptr_t)ssl->heap);
7464+
WOLFSSL_MSG("EccTempKey Memory error!");
74637465
return MEMORY_E;
74647466
}
74657467

src/tls13.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12633,7 +12633,7 @@ int wolfSSL_connect_TLSv13(WOLFSSL* ssl)
1263312633
}
1263412634

1263512635
ssl->options.connectState = CLIENT_HELLO_SENT;
12636-
WOLFSSL_MSG("connect state: CLIENT_HELLO_SENT");
12636+
WOLFSSL_MSG("TLSv13 connect state: CLIENT_HELLO_SENT");
1263712637
#ifdef WOLFSSL_EARLY_DATA
1263812638
if (ssl->earlyData != no_early_data) {
1263912639
#if defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)

wolfcrypt/src/aes.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,10 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
527527
#endif /* HAVE_AES_DECRYPT */
528528

529529
#elif defined(WOLFSSL_ESP32_CRYPT) && \
530-
!defined(NO_WOLFSSL_ESP32_CRYPT_AES)
530+
!defined(NO_WOLFSSL_ESP32_CRYPT_AES)
531531
#include <esp_log.h>
532532
#include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
533-
const char* TAG = "aes";
533+
#define TAG "aes"
534534

535535
/* We'll use SW for fallback:
536536
* unsupported key lengths. (e.g. ESP32-S3)
@@ -968,6 +968,10 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
968968

969969

970970

971+
#if defined(WC_AES_BITSLICED) && !defined(HAVE_AES_ECB)
972+
#error "When WC_AES_BITSLICED is defined, HAVE_AES_ECB is needed."
973+
#endif
974+
971975
#ifdef NEED_AES_TABLES
972976

973977
#ifndef WC_AES_BITSLICED

wolfcrypt/src/ecc.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,6 +3828,7 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point* G, ecc_point* R, mp_int* a,
38283828
#endif
38293829
/* k can't have more bits than order */
38303830
if (mp_count_bits(k) > mp_count_bits(order)) {
3831+
WOLFSSL_MSG("Private key length is greater than order in bits.");
38313832
return ECC_OUT_OF_RANGE_E;
38323833
}
38333834

@@ -5801,19 +5802,32 @@ static int _ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key,
58015802
/* load curve info */
58025803
if (err == MP_OKAY) {
58035804
ALLOC_CURVE_SPECS(ECC_CURVE_FIELD_COUNT, err);
5805+
if (err != MP_OKAY) {
5806+
WOLFSSL_MSG("ALLOC_CURVE_SPECS failed");
5807+
}
58045808
}
5809+
58055810
if (err == MP_OKAY) {
58065811
err = wc_ecc_curve_load(key->dp, &curve, ECC_CURVE_FIELD_ALL);
5812+
if (err != MP_OKAY) {
5813+
WOLFSSL_MSG("wc_ecc_curve_load failed");
5814+
}
58075815
}
58085816

58095817
/* generate k */
58105818
if (err == MP_OKAY) {
58115819
err = wc_ecc_gen_k(rng, key->dp->size, key->k, curve->order);
5820+
if (err != MP_OKAY) {
5821+
WOLFSSL_MSG("wc_ecc_gen_k failed");
5822+
}
58125823
}
58135824

58145825
/* generate public key from k */
58155826
if (err == MP_OKAY) {
58165827
err = ecc_make_pub_ex(key, curve, NULL, rng);
5828+
if (err != MP_OKAY) {
5829+
WOLFSSL_MSG("ecc_make_pub_ex failed");
5830+
}
58175831
}
58185832

58195833
if (err == MP_OKAY

wolfcrypt/src/md5.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ int wc_Md5Final(wc_Md5* md5, byte* hash)
454454

455455
/* ensure we have a valid buffer length; (-1 to append a byte to length) */
456456
if (md5->buffLen > WC_MD5_BLOCK_SIZE - 1) {
457+
/* some places consider this BAD_STATE_E */
457458
return BUFFER_E;
458459
}
459460

0 commit comments

Comments
 (0)