From 77cffbf2847f520611fbe28f02e2e0e69d32350f Mon Sep 17 00:00:00 2001 From: mikee47 Date: Wed, 5 Jun 2024 12:11:01 +0100 Subject: [PATCH] Apply consistent format to SSL debug messages --- Sming/Components/ssl/BearSsl/BrConnection.cpp | 20 +++++++++---------- Sming/Components/ssl/BearSsl/BrContext.cpp | 4 ++-- Sming/Components/ssl/BearSsl/BrPrivateKey.cpp | 2 +- Sming/Components/ssl/BearSsl/BrPublicKey.cpp | 2 +- .../ssl/BearSsl/BrServerConnection.cpp | 4 ++-- Sming/Components/ssl/BearSsl/X509Context.h | 14 ++++++------- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Sming/Components/ssl/BearSsl/BrConnection.cpp b/Sming/Components/ssl/BearSsl/BrConnection.cpp index fc37057eef..2dea34644a 100644 --- a/Sming/Components/ssl/BearSsl/BrConnection.cpp +++ b/Sming/Components/ssl/BearSsl/BrConnection.cpp @@ -119,12 +119,12 @@ int BrConnection::init(size_t bufferSize, bool bidi) void BrConnection::setCipherSuites(const CipherSuites::Array* cipherSuites) { if(cipherSuites == nullptr) { - debug_w("Cipher suites not configured, defaulting to basic"); + debug_w("[SSL] Cipher suites not configured, defaulting to basic"); cipherSuites = &CipherSuites::basic; } auto count = cipherSuites->length(); if(count > BR_MAX_CIPHER_SUITES) { - debug_w("Too many cipher suites, truncating %u -> %u entries", count, BR_MAX_CIPHER_SUITES); + debug_w("[SSL] Too many cipher suites, truncating %u -> %u entries", count, BR_MAX_CIPHER_SUITES); count = BR_MAX_CIPHER_SUITES; } LOAD_FSTR_ARRAY(suites, *cipherSuites); @@ -146,7 +146,7 @@ int BrConnection::read(InputBuffer& input, uint8_t*& output) size_t len = 0; output = br_ssl_engine_recvapp_buf(engine, &len); - debug_hex(DBG, "READ", output, len, 0); + debug_hex(DBG, "[SSL] READ", output, len, 0); br_ssl_engine_recvapp_ack(engine, len); return len; } @@ -168,12 +168,12 @@ int BrConnection::write(const uint8_t* data, size_t length) size_t available; auto buf = br_ssl_engine_sendapp_buf(engine, &available); if(available == 0) { - debug_w("SSL: Send buffer full"); + debug_w("[SSL] Send buffer full"); return 0; } if(available < length) { - debug_i("SSL: Required: %d, Available: %u", length, available); + debug_i("[SSL] Required: %d, Available: %u", length, available); length = available; } @@ -200,7 +200,7 @@ int BrConnection::runUntil(InputBuffer& input, unsigned target) if(state & BR_SSL_CLOSED) { int err = getLastError(); - debug_w("SSL CLOSED, last error = %d (%s), heap free = %u", err, getErrorString(err).c_str(), + debug_w("[SSL] CLOSED, last error = %d (%s), heap free = %u", err, getErrorString(err).c_str(), system_get_free_heap_size()); return err; } @@ -208,7 +208,7 @@ int BrConnection::runUntil(InputBuffer& input, unsigned target) if(!handshakeDone && (state & BR_SSL_SENDAPP)) { handshakeDone = true; context.session.handshakeComplete(true); - debug_i("Negotiated MFLN: %u", br_ssl_engine_get_mfln_negotiated(engine)); + debug_i("[SSL] Negotiated MFLN: %u", br_ssl_engine_get_mfln_negotiated(engine)); continue; } @@ -224,7 +224,7 @@ int BrConnection::runUntil(InputBuffer& input, unsigned target) return 0; } if(wlen < 0) { - debug_w("SSL SHUTDOWN"); + debug_w("[SSL] SHUTDOWN"); /* * If we received a close_notify and we * still send something, then we have our @@ -251,7 +251,7 @@ int BrConnection::runUntil(InputBuffer& input, unsigned target) // Conflict: Application data hasn't been read if(state & BR_SSL_RECVAPP) { - debug_e("SSL: Protocol Error"); + debug_e("[SSL] Protocol Error"); return BR_ERR_BAD_STATE; } @@ -263,7 +263,7 @@ int BrConnection::runUntil(InputBuffer& input, unsigned target) return state; } - debug_hex(DBG, "READ", buf, len, 0); + debug_hex(DBG, "[SSL] READ", buf, len, 0); br_ssl_engine_recvrec_ack(engine, len); continue; diff --git a/Sming/Components/ssl/BearSsl/BrContext.cpp b/Sming/Components/ssl/BearSsl/BrContext.cpp index a51ad21869..e79e1c8800 100644 --- a/Sming/Components/ssl/BearSsl/BrContext.cpp +++ b/Sming/Components/ssl/BearSsl/BrContext.cpp @@ -23,7 +23,7 @@ Connection* BrContext::createClient(tcp_pcb* tcp) if(connection != nullptr) { int res = connection->init(); if(res < 0) { - debug_e("Connection init failed: %s", connection->getErrorString(res).c_str()); + debug_e("[SSL] Connection init failed: %s", connection->getErrorString(res).c_str()); delete connection; connection = nullptr; } @@ -37,7 +37,7 @@ Connection* BrContext::createServer(tcp_pcb* tcp) if(connection != nullptr) { int res = connection->init(); if(res < 0) { - debug_e("Connection init failed: %s", connection->getErrorString(res).c_str()); + debug_e("[SSL] Connection init failed: %s", connection->getErrorString(res).c_str()); delete connection; connection = nullptr; } diff --git a/Sming/Components/ssl/BearSsl/BrPrivateKey.cpp b/Sming/Components/ssl/BearSsl/BrPrivateKey.cpp index 31ff6997f9..5d88084824 100644 --- a/Sming/Components/ssl/BearSsl/BrPrivateKey.cpp +++ b/Sming/Components/ssl/BearSsl/BrPrivateKey.cpp @@ -37,7 +37,7 @@ bool BrPrivateKey::decode(const uint8_t* buf, size_t len) return copy(*br_skey_decoder_get_ec(&dc)); default: - debug_e("Unknown key type: %d", type); + debug_e("[SSL] Unknown key type: %d", type); return false; } } diff --git a/Sming/Components/ssl/BearSsl/BrPublicKey.cpp b/Sming/Components/ssl/BearSsl/BrPublicKey.cpp index ea7ff33636..a2c89fddda 100644 --- a/Sming/Components/ssl/BearSsl/BrPublicKey.cpp +++ b/Sming/Components/ssl/BearSsl/BrPublicKey.cpp @@ -37,7 +37,7 @@ bool BrPublicKey::decode(const uint8_t* buf, size_t len) return copy(*br_pkey_decoder_get_ec(&dc)); default: - debug_e("Unknown key type: %d", type); + debug_e("[SSL] Unknown key type: %d", type); return false; } } diff --git a/Sming/Components/ssl/BearSsl/BrServerConnection.cpp b/Sming/Components/ssl/BearSsl/BrServerConnection.cpp index f109cf0289..3dbda3f157 100644 --- a/Sming/Components/ssl/BearSsl/BrServerConnection.cpp +++ b/Sming/Components/ssl/BearSsl/BrServerConnection.cpp @@ -43,14 +43,14 @@ int BrServerConnection::init() cert.data = const_cast(keyCert.getCertificate()); cert.data_len = keyCert.getCertificateLength(); if(!key.decode(keyCert.getKey(), keyCert.getKeyLength())) { - debug_e("Failed to decode keyCert"); + debug_e("[SSL] Failed to decode keyCert"); return -BR_ERR_BAD_PARAM; } br_ssl_server_set_single_rsa(&serverContext, &cert, 1, key, BR_KEYTYPE_RSA | BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, br_rsa_private_get_default(), br_rsa_pkcs1_sign_get_default()); // Warning: Inconsistent return type: not an error code if(!br_ssl_server_reset(&serverContext)) { - debug_e("br_ssl_client_reset failed"); + debug_e("[SSL] br_ssl_client_reset failed"); return getLastError(); } diff --git a/Sming/Components/ssl/BearSsl/X509Context.h b/Sming/Components/ssl/BearSsl/X509Context.h index 0118336bb1..1f176856f9 100644 --- a/Sming/Components/ssl/BearSsl/X509Context.h +++ b/Sming/Components/ssl/BearSsl/X509Context.h @@ -59,7 +59,7 @@ class X509Context // Callback on the first byte of any certificate static void start_chain(const br_x509_class** ctx, const char* server_name) { - debug_i("start_chain: %s", server_name); + debug_i("[SSL] start_chain: %s", server_name); GET_SELF(); self->certificateCount = 0; self->handler.startChain(server_name); @@ -68,7 +68,7 @@ class X509Context // Callback for each certificate present in the chain static void start_cert(const br_x509_class** ctx, uint32_t length) { - debug_i("start_cert: %u", length); + debug_i("[SSL] start_cert: %u", length); GET_SELF(); self->startCert(length); } @@ -81,15 +81,15 @@ class X509Context // Callback for each byte stream in the chain static void append(const br_x509_class** ctx, const unsigned char* buf, size_t len) { - debug_i("append: %u", len); + debug_i("[SSL] X509 append: %u", len); GET_SELF(); self->handler.appendCertData(buf, len); - debug_hex(DBG, "CERT", buf, len, 0); + debug_hex(DBG, "[SSL] CERT", buf, len, 0); } static void end_cert(const br_x509_class** ctx) { - debug_i("end_cert"); + debug_i("[SSL] end_cert"); GET_SELF(); self->handler.endCert(); ++self->certificateCount; @@ -98,7 +98,7 @@ class X509Context // Complete chain has been parsed, return 0 on validation success static unsigned end_chain(const br_x509_class** ctx) { - debug_i("end_chain"); + debug_i("[SSL] end_chain"); GET_SELF(); return self->endChain(); } @@ -106,7 +106,7 @@ class X509Context unsigned endChain() { if(certificateCount == 0) { - debug_w("No certificate processed"); + debug_w("[SSL] No certificate processed"); return BR_ERR_X509_EMPTY_CHAIN; }