Skip to content

Commit 7652756

Browse files
committed
Migrate to MbedTLS v4.0.0
Signed-off-by: Dominik <[email protected]>
1 parent 1635019 commit 7652756

8 files changed

Lines changed: 138 additions & 352 deletions

File tree

.github/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ghcr.io/pi-hole/ftl-build:v2.13
1+
FROM ghcr.io/pi-hole/ftl-build:v2.15
22

33
WORKDIR /app
44

src/config/password.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,8 @@ bool get_secure_randomness(uint8_t *buffer, const size_t length)
124124
result = getrandom_fallback(buffer, length, 0);
125125
if(result < 0 || result < (ssize_t)length)
126126
{
127-
log_debug(DEBUG_API, "Fallback failed, trying internal DRBG generator");
128-
generator = "internal DRBG";
129-
result = drbg_random(buffer, length);
130-
if(result < 0)
131-
{
132-
// Warning will be printed by drbg_random()
133-
return false;
134-
}
135-
136-
log_debug(DEBUG_API, "Internal DRBG generator successfully used");
127+
log_err("Unable to get secure randomness from fallback generator");
128+
return false;
137129
}
138130
else
139131
log_debug(DEBUG_API, "Fallback to /dev/urandom successful");

src/daemon.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,6 @@ void cleanup(const int ret)
437437
log_debug(DEBUG_ANY, "Terminating: Closing memory database");
438438
close_memory_database();
439439

440-
// De-initialize the random number generator and entropy collector
441-
log_debug(DEBUG_ANY, "Terminating: Freeing entropy collector");
442-
destroy_entropy();
443-
444440
// Free environment variables
445441
log_debug(DEBUG_ANY, "Terminating: Freeing environment variables");
446442
freeEnvVars();

src/main.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ int main (int argc, char *argv[])
6464
log_info("########## FTL started on %s! ##########", hostname());
6565
log_FTL_version(false);
6666

67-
// Initialize entropy and random number generator
68-
init_entropy();
69-
7067
// Catch signals not handled by dnsmasq
7168
// We configure real-time signals later (after dnsmasq has forked)
7269
handle_signals();

src/webserver/civetweb/mod_mbedtls.inl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#if defined(USE_MBEDTLS) // USE_MBEDTLS used with NO_SSL
22

3-
#include "mbedtls/ctr_drbg.h"
43
#include "mbedtls/debug.h"
4+
#if MBEDTLS_VERSION_NUMBER < 0x04000000
55
#include "mbedtls/entropy.h"
6+
#include "mbedtls/ctr_drbg.h"
7+
#endif
68
#include "mbedtls/error.h"
79

810
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
@@ -26,8 +28,10 @@ typedef mbedtls_ssl_context SSL;
2628
typedef struct {
2729
mbedtls_ssl_config conf; /* SSL configuration */
2830
mbedtls_x509_crt cert; /* Certificate */
31+
#if MBEDTLS_VERSION_NUMBER < 0x04000000
2932
mbedtls_ctr_drbg_context ctr; /* Counter random generator state */
3033
mbedtls_entropy_context entropy; /* Entropy context */
34+
#endif
3135
mbedtls_pk_context pkey; /* Private key */
3236
} SSL_CTX;
3337

@@ -125,7 +129,9 @@ mbed_sslctx_init(SSL_CTX *ctx, const char *crt, const char *cipherlist)
125129
}
126130

127131
DEBUG_TRACE("%s", "Initializing MbedTLS SSL");
132+
#if MBEDTLS_VERSION_NUMBER < 0x04000000
128133
mbedtls_entropy_init(&ctx->entropy);
134+
#endif
129135

130136
conf = &ctx->conf;
131137
mbedtls_ssl_config_init(conf);
@@ -152,7 +158,9 @@ mbed_sslctx_init(SSL_CTX *ctx, const char *crt, const char *cipherlist)
152158

153159
/* Initialize TLS key and cert */
154160
mbedtls_pk_init(&ctx->pkey);
161+
#if MBEDTLS_VERSION_NUMBER < 0x04000000
155162
mbedtls_ctr_drbg_init(&ctx->ctr);
163+
#endif
156164
mbedtls_x509_crt_init(&ctx->cert);
157165

158166
#ifdef MBEDTLS_PSA_CRYPTO_C
@@ -168,6 +176,7 @@ mbed_sslctx_init(SSL_CTX *ctx, const char *crt, const char *cipherlist)
168176
}
169177
#endif
170178

179+
#if MBEDTLS_VERSION_NUMBER < 0x04000000
171180
rc = mbedtls_ctr_drbg_seed(&ctx->ctr,
172181
mbedtls_entropy_func,
173182
&ctx->entropy,
@@ -177,8 +186,9 @@ mbed_sslctx_init(SSL_CTX *ctx, const char *crt, const char *cipherlist)
177186
DEBUG_TRACE("TLS random seed failed (%i)", rc);
178187
return -1;
179188
}
189+
#endif
180190

181-
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
191+
#if MBEDTLS_VERSION_NUMBER >= 0x03000000 && MBEDTLS_VERSION_NUMBER < 0x04000000
182192
// mbedtls_pk_parse_keyfile() has changed in mbedTLS 3.0. You now need
183193
// to pass a properly seeded, cryptographically secure RNG when calling
184194
// these functions. It is used for blinding, a countermeasure against
@@ -209,7 +219,9 @@ mbed_sslctx_init(SSL_CTX *ctx, const char *crt, const char *cipherlist)
209219
return -1;
210220
}
211221

222+
#if MBEDTLS_VERSION_NUMBER >= 0x03000000 && MBEDTLS_VERSION_NUMBER < 0x04000000
212223
mbedtls_ssl_conf_rng(conf, mbedtls_ctr_drbg_random, &ctx->ctr);
224+
#endif
213225

214226
/* Set auth mode if peer cert should be verified */
215227
mbedtls_ssl_conf_authmode(conf, MBEDTLS_SSL_VERIFY_NONE);
@@ -237,10 +249,12 @@ mbed_sslctx_init(SSL_CTX *ctx, const char *crt, const char *cipherlist)
237249
void
238250
mbed_sslctx_uninit(SSL_CTX *ctx)
239251
{
252+
#if MBEDTLS_VERSION_NUMBER < 0x04000000
240253
mbedtls_ctr_drbg_free(&ctx->ctr);
254+
mbedtls_entropy_free(&ctx->entropy);
255+
#endif
241256
mbedtls_pk_free(&ctx->pkey);
242257
mbedtls_x509_crt_free(&ctx->cert);
243-
mbedtls_entropy_free(&ctx->entropy);
244258
mbedtls_ssl_config_free(&ctx->conf);
245259
}
246260

0 commit comments

Comments
 (0)