From fe36fe7a604df9fafb2fe2bdd64454a46cd660b7 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 13 Jul 2024 09:12:13 +0200 Subject: [PATCH] Fix certificate reading when using GnuTLS --- src/core/system_parameters/gnss_crypto.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/system_parameters/gnss_crypto.cc b/src/core/system_parameters/gnss_crypto.cc index b7595fa59..231c33004 100644 --- a/src/core/system_parameters/gnss_crypto.cc +++ b/src/core/system_parameters/gnss_crypto.cc @@ -650,11 +650,12 @@ bool Gnss_Crypto::readPublicKeyFromCRT(const std::string& crtFilePath) return false; } - std::vector buffer((std::istreambuf_iterator(crtFile)), std::istreambuf_iterator()); + const std::vector buffer((std::istreambuf_iterator(crtFile)), std::istreambuf_iterator()); + const gnutls_datum_t buffer_datum = {const_cast(buffer.data()), static_cast(buffer.size())}; gnutls_x509_crt_t cert; gnutls_x509_crt_init(&cert); - int ret = gnutls_x509_crt_import(cert, (const gnutls_datum_t*)&buffer, GNUTLS_X509_FMT_PEM); + int ret = gnutls_x509_crt_import(cert, &buffer_datum, GNUTLS_X509_FMT_PEM); if (ret < 0) { LOG(INFO) << "GnuTLS: Failed to import certificate: " << gnutls_strerror(ret);