Skip to content

Commit

Permalink
Apply consistent format to SSL debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Jun 5, 2024
1 parent 2d306b7 commit 77cffbf
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
20 changes: 10 additions & 10 deletions Sming/Components/ssl/BearSsl/BrConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -200,15 +200,15 @@ 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;
}

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;
}

Expand All @@ -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
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Sming/Components/ssl/BearSsl/BrContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Sming/Components/ssl/BearSsl/BrPrivateKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sming/Components/ssl/BearSsl/BrPublicKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sming/Components/ssl/BearSsl/BrServerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ int BrServerConnection::init()
cert.data = const_cast<uint8_t*>(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();
}

Expand Down
14 changes: 7 additions & 7 deletions Sming/Components/ssl/BearSsl/X509Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -98,15 +98,15 @@ 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();
}

unsigned endChain()
{
if(certificateCount == 0) {
debug_w("No certificate processed");
debug_w("[SSL] No certificate processed");
return BR_ERR_X509_EMPTY_CHAIN;
}

Expand Down

0 comments on commit 77cffbf

Please sign in to comment.