-
Notifications
You must be signed in to change notification settings - Fork 0
feat!: the Mbed TLS stream asks a credentials source for its material #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
85cd195
aa34926
d35d64a
bf9b4ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |||||||||||
| #include "BddTargetTlsConfig.h" | ||||||||||||
| #include "SolidSyslogLwipRawAddress.h" | ||||||||||||
| #include "SolidSyslogLwipRawTcpStream.h" | ||||||||||||
| #include "SolidSyslogMbedTlsHandleCredentials.h" | ||||||||||||
| #include "SolidSyslogMbedTlsStream.h" | ||||||||||||
| #include "SolidSyslogNullSender.h" | ||||||||||||
| #include "SolidSyslogStream.h" | ||||||||||||
|
|
@@ -56,6 +57,7 @@ | |||||||||||
| struct SolidSyslogResolver; | ||||||||||||
|
|
||||||||||||
| static struct SolidSyslogStream* underlyingStream; | ||||||||||||
| static struct SolidSyslogMbedTlsCredentials* credentials; | ||||||||||||
| static struct SolidSyslogStream* tlsStream; | ||||||||||||
| static struct SolidSyslogAddress* address; | ||||||||||||
| static struct SolidSyslogSender* sender; | ||||||||||||
|
|
@@ -378,13 +380,18 @@ struct SolidSyslogSender* BddTargetTlsSender_Create(struct SolidSyslogResolver* | |||||||||||
| tlsStreamConfig.Transport = underlyingStream; | ||||||||||||
| tlsStreamConfig.Sleep = RtosSleep; | ||||||||||||
| tlsStreamConfig.Rng = &drbg; | ||||||||||||
| tlsStreamConfig.CaChain = &caChain; | ||||||||||||
| /* Plain-TLS and mTLS share one SNI on this oracle (CN/SAN = "syslog-ng"), | ||||||||||||
| * so BddTargetTlsConfig_GetServerName and BddTargetMtlsConfig_GetServerName | ||||||||||||
| * return the same string. Use the TLS one to make the equivalence explicit. */ | ||||||||||||
| tlsStreamConfig.ServerName = BddTargetTlsConfig_GetServerName(); | ||||||||||||
| tlsStreamConfig.ClientCertChain = &clientCertChain; | ||||||||||||
| tlsStreamConfig.ClientKey = &clientKey; | ||||||||||||
| static struct SolidSyslogMbedTlsHandleCredentialsConfig credentialsConfig; | ||||||||||||
| credentialsConfig = (struct SolidSyslogMbedTlsHandleCredentialsConfig) {0}; | ||||||||||||
| credentialsConfig.Rng = &drbg; | ||||||||||||
| credentialsConfig.CaChain = &caChain; | ||||||||||||
| credentialsConfig.ClientCertChain = &clientCertChain; | ||||||||||||
| credentialsConfig.ClientKey = &clientKey; | ||||||||||||
| credentials = SolidSyslogMbedTlsHandleCredentials_Create(&credentialsConfig); | ||||||||||||
| tlsStreamConfig.Credentials = credentials; | ||||||||||||
| tlsStream = SolidSyslogMbedTlsStream_Create(&tlsStreamConfig); | ||||||||||||
|
|
||||||||||||
| address = SolidSyslogLwipRawAddress_Create(); | ||||||||||||
|
|
@@ -414,6 +421,7 @@ void BddTargetTlsSender_Destroy(void) | |||||||||||
| SolidSyslogStreamSender_Destroy(sender); | ||||||||||||
| SolidSyslogLwipRawAddress_Destroy(address); | ||||||||||||
| SolidSyslogMbedTlsStream_Destroy(tlsStream); | ||||||||||||
| SolidSyslogMbedTlsHandleCredentials_Destroy(credentials); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Do not destroy the Null credentials fallback.
Only destroy a pool-owned handle. Proposed fix+#include "SolidSyslogMbedTlsNullCredentials.h"
...
- SolidSyslogMbedTlsHandleCredentials_Destroy(credentials);
+ if (credentials != SolidSyslogMbedTlsNullCredentials_Get())
+ {
+ SolidSyslogMbedTlsHandleCredentials_Destroy(credentials);
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declining, though the mechanism is real: a pool-exhausted Create returns the shared Null credentials, and Destroy then reports an unknown destroy. That exposure is not new or specific to this handle. If the idiom is worth changing it is worth changing across every BDD target at once, which is not this PR.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I will not pursue this change in this PR. If you want a repository-wide teardown-policy follow-up, please request an issue. 🐇 ✏️ Learnings added
You are interacting with an AI system. |
||||||||||||
| SolidSyslogLwipRawTcpStream_Destroy(underlyingStream); | ||||||||||||
|
|
||||||||||||
| /* Entropy / DRBG / parsed certs survive across Destroy -> Create cycles to | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited | ||
| * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial | ||
| */ | ||
|
|
||
| /** @file | ||
| * An Mbed TLS credentials backend that carries caller-built, caller-owned | ||
| * mbedTLS handles. The integrator parses its own PEM, unwraps its own key, or | ||
| * fetches material from wherever it lives, and hands the resulting handles | ||
| * here; this library parses nothing and owns nothing. | ||
| * | ||
| * The handles must outlive the credentials, because every connection installs | ||
| * the same ones. A backend that acquires material per connection - one parsing | ||
| * a PEM buffer on demand, or reaching a secure element - is a different | ||
| * implementation of the same role. */ | ||
| #ifndef SOLIDSYSLOGMBEDTLSHANDLECREDENTIALS_H | ||
| #define SOLIDSYSLOGMBEDTLSHANDLECREDENTIALS_H | ||
|
|
||
| #include "SolidSyslogExternC.h" | ||
|
|
||
| /* Forward declarations keep the header free of any mbedTLS include, as the | ||
| * stream header does. Integrators include the relevant mbedTLS headers | ||
| * themselves before this one to bring the types into scope. */ | ||
| struct mbedtls_ctr_drbg_context; | ||
| struct mbedtls_pk_context; | ||
| struct mbedtls_x509_crt; | ||
|
|
||
| SOLIDSYSLOG_EXTERN_C_BEGIN | ||
|
|
||
| struct SolidSyslogMbedTlsCredentials; | ||
|
|
||
| /** Where this backend's material lives. Every handle is caller-built and | ||
| * caller-owned, and must stay valid for the lifetime of the credentials. */ | ||
| struct SolidSyslogMbedTlsHandleCredentialsConfig | ||
| { | ||
| /** Trust anchors the peer certificate must chain to; NULL installs | ||
| * none, which leaves the peer authorised only if the stream has | ||
| * another means to do it. */ | ||
| struct mbedtls_x509_crt* CaChain; | ||
| /** Leaf certificate (plus intermediates) for mutual TLS; NULL means no | ||
| * client credential. Certificate and key are all-or-nothing - | ||
| * supplying one without the other is reported. */ | ||
| struct mbedtls_x509_crt* ClientCertChain; | ||
| /** Private key matching ClientCertChain; NULL means no client | ||
| * credential. */ | ||
| struct mbedtls_pk_context* ClientKey; | ||
| /** Seeded CTR-DRBG, used to check the client key against its | ||
| * certificate; required - a NULL is reported at | ||
| * SolidSyslogMbedTlsHandleCredentials_Create. The stream takes its own | ||
| * handshake RNG separately, and the same one serves both. */ | ||
| struct mbedtls_ctr_drbg_context* Rng; | ||
| }; | ||
|
|
||
| /** Draw a credentials instance from the pool. A NULL config or a NULL Rng is | ||
| * reported and falls back to the shared Null credentials, as does an | ||
| * exhausted pool. */ | ||
| struct SolidSyslogMbedTlsCredentials* SolidSyslogMbedTlsHandleCredentials_Create( | ||
| const struct SolidSyslogMbedTlsHandleCredentialsConfig* config | ||
| ); | ||
| /** Release the pool slot. */ | ||
| void SolidSyslogMbedTlsHandleCredentials_Destroy(struct SolidSyslogMbedTlsCredentials * base); | ||
|
|
||
| SOLIDSYSLOG_EXTERN_C_END | ||
|
|
||
| #endif /* SOLIDSYSLOGMBEDTLSHANDLECREDENTIALS_H */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited | ||
| * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial | ||
| */ | ||
|
|
||
| /** @file | ||
| * Error codes and Source identity for the MbedTlsHandleCredentials backend. */ | ||
| #ifndef SOLIDSYSLOGMBEDTLSHANDLECREDENTIALSERRORS_H | ||
| #define SOLIDSYSLOGMBEDTLSHANDLECREDENTIALSERRORS_H | ||
|
|
||
| #include "SolidSyslogExternC.h" | ||
|
|
||
| SOLIDSYSLOG_EXTERN_C_BEGIN | ||
|
|
||
| struct SolidSyslogErrorSource; | ||
|
|
||
| /** Detail codes for events whose Source is SolidSyslogMbedTlsHandleCredentialsErrorSource. | ||
| * A handler reads these off event->Detail after matching event->Source; the | ||
| * members name their own fault. */ | ||
| enum SolidSyslogMbedTlsHandleCredentialsErrors | ||
| { | ||
| SOLIDSYSLOG_MBEDTLS_HANDLE_CREDENTIALS_ERROR_POOL_EXHAUSTED, | ||
| SOLIDSYSLOG_MBEDTLS_HANDLE_CREDENTIALS_ERROR_UNKNOWN_DESTROY, | ||
| SOLIDSYSLOG_MBEDTLS_HANDLE_CREDENTIALS_ERROR_NULL_CONFIG, | ||
| SOLIDSYSLOG_MBEDTLS_HANDLE_CREDENTIALS_ERROR_NULL_RNG, | ||
| SOLIDSYSLOG_MBEDTLS_HANDLE_CREDENTIALS_ERROR_CLIENT_CREDENTIAL_INCOMPLETE, | ||
| SOLIDSYSLOG_MBEDTLS_HANDLE_CREDENTIALS_ERROR_CLIENT_CREDENTIAL_MISMATCHED, | ||
| SOLIDSYSLOG_MBEDTLS_HANDLE_CREDENTIALS_ERROR_CLIENT_CREDENTIAL_NOT_INSTALLED, | ||
| SOLIDSYSLOG_MBEDTLS_HANDLE_CREDENTIALS_ERROR_MAX /**< One past the last code; never emitted. Bounds the range for iteration. */ | ||
| }; | ||
|
|
||
| /** Identity for events raised by an MbedTlsHandleCredentials. A handler | ||
| * matches by address (event->Source == &SolidSyslogMbedTlsHandleCredentialsErrorSource), | ||
| * then reads event->Detail as an enum | ||
| * SolidSyslogMbedTlsHandleCredentialsErrors. */ | ||
| extern const struct SolidSyslogErrorSource SolidSyslogMbedTlsHandleCredentialsErrorSource; | ||
|
|
||
| SOLIDSYSLOG_EXTERN_C_END | ||
|
|
||
| #endif /* SOLIDSYSLOGMBEDTLSHANDLECREDENTIALSERRORS_H */ |
Uh oh!
There was an error while loading. Please reload this page.