Line data Source code
1 : /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited
2 : * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial
3 : */
4 :
5 : #ifndef SOLIDSYSLOGMBEDTLSPEMBUFFERCREDENTIALSPRIVATE_H
6 : #define SOLIDSYSLOGMBEDTLSPEMBUFFERCREDENTIALSPRIVATE_H
7 :
8 : #include <mbedtls/pk.h>
9 : #include <mbedtls/x509_crt.h>
10 : #include <stdint.h>
11 :
12 : #include "SolidSyslogError.h"
13 : #include "SolidSyslogMbedTlsCredentialsDefinition.h"
14 : #include "SolidSyslogMbedTlsPemBufferCredentials.h"
15 : #include "SolidSyslogMbedTlsPemBufferCredentialsErrors.h"
16 : #include "SolidSyslogPrival.h"
17 : #include "SolidSyslogStreamOpenHealth.h"
18 :
19 : struct SolidSyslogMbedTlsPemBufferCredentials
20 : {
21 : struct SolidSyslogMbedTlsCredentials Base;
22 : struct SolidSyslogMbedTlsPemBufferCredentialsConfig Config;
23 : /* Holds the parsed material for the length of one connection only. Init'd
24 : * at Create so the frees in Release are safe whether or not Install ever
25 : * ran, and left in Mbed TLS's freed-equivalent state afterwards so the next
26 : * Install parses into them again. */
27 : mbedtls_x509_crt CaChain;
28 : mbedtls_x509_crt ClientCertChain;
29 : mbedtls_pk_context ClientKey;
30 : /* Install/Release calls outstanding. One slot parses for one connection,
31 : * so a second overlapping Install is refused - but the contract answers
32 : * every Install with a Release whatever it returned, so counting is what
33 : * keeps a refused one from freeing the live connection's material. */
34 : size_t OutstandingInstalls;
35 : /* A refusal that fails Install is reported once per run of the same
36 : * detail, as a stream's failed Open is: the stream asks on every attempt.
37 : * An Install that succeeds re-arms it. */
38 : struct SolidSyslogStreamOpenHealth InstallHealth;
39 : };
40 :
41 : void SolidSyslogMbedTlsPemBufferCredentials_Initialise(
42 : struct SolidSyslogMbedTlsCredentials* base,
43 : const struct SolidSyslogMbedTlsPemBufferCredentialsConfig* config
44 : );
45 : void SolidSyslogMbedTlsPemBufferCredentials_Cleanup(struct SolidSyslogMbedTlsCredentials* base);
46 :
47 15 : static inline void MbedTlsPemBufferCredentials_Report(
48 : enum SolidSyslogSeverity severity,
49 : uint16_t category,
50 : enum SolidSyslogTlsCredentialsErrors code
51 : )
52 : {
53 15 : SolidSyslog_Error(severity, &SolidSyslogMbedTlsPemBufferCredentialsErrorSource, category, (int32_t) code);
54 15 : }
55 :
56 15 : static inline void MbedTlsPemBufferCredentials_ReportInstallFailure(
57 : struct SolidSyslogMbedTlsPemBufferCredentials* self,
58 : enum SolidSyslogSeverity severity,
59 : uint16_t category,
60 : enum SolidSyslogTlsCredentialsErrors code
61 : )
62 : {
63 15 : SolidSyslogStreamOpenHealth_ReportFailure(
64 : &self->InstallHealth,
65 : &SolidSyslogMbedTlsPemBufferCredentialsErrorSource,
66 : severity,
67 : category,
68 : (int32_t) code
69 : );
70 15 : }
71 :
72 : #endif /* SOLIDSYSLOGMBEDTLSPEMBUFFERCREDENTIALSPRIVATE_H */
|