2022-08-28 19:02:06 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: TLSCipherSuites.cpp
|
|
|
|
Date: 2022-8-27
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include "TLS.hpp"
|
2022-08-29 18:57:24 +00:00
|
|
|
#include <mbedtls/ssl.h>
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
namespace Aurora::IO::TLS
|
|
|
|
{
|
2022-08-29 18:57:24 +00:00
|
|
|
AUKN_SYM const AuList<AuUInt16> &GetDefaultCipherSuites()
|
2022-08-28 19:02:06 +00:00
|
|
|
{
|
2022-08-29 18:57:24 +00:00
|
|
|
static AuList<AuUInt16> gDefaultSuites {
|
|
|
|
MBEDTLS_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
|
|
|
|
MBEDTLS_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
|
|
|
|
MBEDTLS_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
|
|
|
|
MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384,
|
|
|
|
MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256,
|
|
|
|
MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
|
|
|
|
};
|
|
|
|
|
|
|
|
return gDefaultSuites;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM const AuList<AuUInt16> &GetSupportedCipherSuites()
|
|
|
|
{
|
|
|
|
static AuList<AuUInt16> gSupportedSuites;
|
|
|
|
|
|
|
|
if (gSupportedSuites.empty())
|
|
|
|
{
|
2022-08-31 15:09:45 +00:00
|
|
|
auto iItr = ::mbedtls_ssl_list_ciphersuites();
|
2022-08-29 18:57:24 +00:00
|
|
|
|
|
|
|
while (auto cipher = *(iItr++))
|
|
|
|
{
|
|
|
|
gSupportedSuites.push_back(cipher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return gSupportedSuites;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM AuUInt16 CipherSuiteFromString(const AuString &string)
|
|
|
|
{
|
2022-08-31 15:09:45 +00:00
|
|
|
auto pSuite = ::mbedtls_ssl_ciphersuite_from_string(string.c_str());
|
2022-08-29 18:57:24 +00:00
|
|
|
if (!pSuite)
|
|
|
|
{
|
|
|
|
SysPushErrorCrypt("Unknown ciphersuite: {}", string);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pSuite->private_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM AuString CipherSuiteToString(AuUInt16 uCipherSuite)
|
|
|
|
{
|
2022-08-31 15:09:45 +00:00
|
|
|
auto pSuite = ::mbedtls_ssl_ciphersuite_from_id(uCipherSuite);
|
2022-08-29 18:57:24 +00:00
|
|
|
if (!pSuite)
|
|
|
|
{
|
|
|
|
SysPushErrorCrypt("Unknown ciphersuite: {} ({:02x})", uCipherSuite, uCipherSuite);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return pSuite->private_name;
|
2022-08-28 19:02:06 +00:00
|
|
|
}
|
|
|
|
}
|