1 Commits
v2.1.0 ... ssl2

Author SHA1 Message Date
471b5b56f8 remove this commit
All checks were successful
Linux arm64 / Build (push) Successful in 58s
2025-03-15 09:33:59 +01:00
2 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
#include <cstring>
#include <iostream>
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/entropy.h>
#include <mbedtls/x509_crt.h>
#include <sp/common/DataBuffer.h>
#include <sp/common/NonCopyable.h>
namespace sp {
class SslContext : private NonCopyable {
public:
SslContext(unsigned int a_KeySizeBits) {
mbedtls_rsa_context rsaContext;
mbedtls_rsa_init(&rsaContext);
mbedtls_rsa_gen_key(&rsaContext, mbedtls_ctr_drbg_random, &m_CtrCrbg, a_KeySizeBits, 65537);
mbedtls_rsa_free(&rsaContext);
}
SslContext(const DataBuffer& a_Data) {
mbedtls_x509_crt_parse(&m_CaCert, (const unsigned char*)a_Data.data(), a_Data.GetSize()) == 0;
}
SslContext(const std::string& a_CertFilePath) {
mbedtls_x509_crt_parse_file(&m_CaCert, a_CertFilePath.c_str());
}
~SslContext() {
mbedtls_ctr_drbg_free(&m_CtrCrbg);
mbedtls_entropy_free(&m_Entropy);
mbedtls_x509_crt_free(&m_CaCert);
}
private:
void InitContext() {
int error = 0;
mbedtls_x509_crt_init(&m_CaCert);
mbedtls_ctr_drbg_init(&m_CtrCrbg);
mbedtls_entropy_init(&m_Entropy);
if ((error = mbedtls_ctr_drbg_seed(&m_CtrCrbg, mbedtls_entropy_func, &m_Entropy, nullptr, 0)) != 0) {
throw std::runtime_error("Failed to initialise random number generator. Returned error: " + std::to_string(error));
}
}
mbedtls_entropy_context m_Entropy;
mbedtls_ctr_drbg_context m_CtrCrbg;
mbedtls_x509_crt m_CaCert;
};
} // namespace sp

View File

@@ -14,6 +14,12 @@ local modules = {
Deps = {},
Includes = {"include/(sp/extensions/Tcp.h)", "include/(sp/extensions/tcp/*.h)"},
Sources = {"src/sp/extensions/Tcp*.cpp"}
},
MbedTls = {
Option = "tls",
Deps = {"mbedtls"},
Includes = {"include/(sp/extensions/Ssl.h)", "include/(sp/extensions/Ssl/*.h)"},
Sources = {"src/sp/extensions/Ssl*.cpp"}
}
}