mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibTLS: Show enum value instead of underlying value where possible
This commit is contained in:
parent
5853d9642a
commit
9059694216
4 changed files with 93 additions and 10 deletions
|
@ -704,6 +704,89 @@ enum class AlertDescription : u8 {
|
||||||
#undef _ENUM_KEY
|
#undef _ENUM_KEY
|
||||||
#undef _ENUM_KEY_VALUE
|
#undef _ENUM_KEY_VALUE
|
||||||
|
|
||||||
|
constexpr static StringView enum_to_string(CipherSuite descriptor)
|
||||||
|
{
|
||||||
|
#define _ENUM_KEY_VALUE(name, value) \
|
||||||
|
case CipherSuite::name: \
|
||||||
|
return #name##sv;
|
||||||
|
|
||||||
|
switch (descriptor) {
|
||||||
|
__ENUM_CIPHER_SUITES
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown"sv;
|
||||||
|
#undef _ENUM_KEY_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr static StringView enum_to_string(ExtensionType descriptor)
|
||||||
|
{
|
||||||
|
#define _ENUM_KEY_VALUE(name, value) \
|
||||||
|
case ExtensionType::name: \
|
||||||
|
return #name##sv;
|
||||||
|
|
||||||
|
switch (descriptor) {
|
||||||
|
__ENUM_EXTENSION_TYPES
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown"sv;
|
||||||
|
#undef _ENUM_KEY_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr static StringView enum_to_string(ContentType descriptor)
|
||||||
|
{
|
||||||
|
#define _ENUM_KEY_VALUE(name, value) \
|
||||||
|
case ContentType::name: \
|
||||||
|
return #name##sv;
|
||||||
|
|
||||||
|
switch (descriptor) {
|
||||||
|
__ENUM_CONTENT_TYPES
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown"sv;
|
||||||
|
#undef _ENUM_KEY_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr static StringView enum_to_string(ProtocolVersion descriptor)
|
||||||
|
{
|
||||||
|
#define _ENUM_KEY_VALUE(name, value) \
|
||||||
|
case ProtocolVersion::name: \
|
||||||
|
return #name##sv;
|
||||||
|
|
||||||
|
switch (descriptor) {
|
||||||
|
__ENUM_PROTOCOL_VERSIONS
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown"sv;
|
||||||
|
#undef _ENUM_KEY_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr static StringView enum_to_string(HandshakeType descriptor)
|
||||||
|
{
|
||||||
|
#define _ENUM_KEY_VALUE(name, value) \
|
||||||
|
case HandshakeType::name: \
|
||||||
|
return #name##sv;
|
||||||
|
|
||||||
|
switch (descriptor) {
|
||||||
|
__ENUM_HANDSHAKE_TYPES
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown"sv;
|
||||||
|
#undef _ENUM_KEY_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr static StringView enum_to_string(SignatureAlgorithm descriptor)
|
||||||
|
{
|
||||||
|
#define _ENUM_KEY_VALUE(name, value) \
|
||||||
|
case SignatureAlgorithm::name: \
|
||||||
|
return #name##sv;
|
||||||
|
|
||||||
|
switch (descriptor) {
|
||||||
|
__ENUM_SIGNATURE_ALGORITHM
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown"sv;
|
||||||
|
#undef _ENUM_KEY_VALUE
|
||||||
|
}
|
||||||
constexpr static StringView enum_to_string(AlertDescription descriptor)
|
constexpr static StringView enum_to_string(AlertDescription descriptor)
|
||||||
{
|
{
|
||||||
#define _ENUM_KEY_VALUE(name, value) \
|
#define _ENUM_KEY_VALUE(name, value) \
|
||||||
|
|
|
@ -412,7 +412,7 @@ ssize_t TLSv12::handle_handshake_payload(ReadonlyBytes vbuffer)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dbgln("message type not understood: {}", to_underlying(type));
|
dbgln("message type not understood: {}", enum_to_string(type));
|
||||||
return (i8)Error::NotUnderstood;
|
return (i8)Error::NotUnderstood;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ ssize_t TLSv12::handle_server_hello(ReadonlyBytes buffer, WritePacketStage& writ
|
||||||
return (i8)Error::NoCommonCipher;
|
return (i8)Error::NoCommonCipher;
|
||||||
}
|
}
|
||||||
m_context.cipher = cipher;
|
m_context.cipher = cipher;
|
||||||
dbgln_if(TLS_DEBUG, "Cipher: {}", (u16)cipher);
|
dbgln_if(TLS_DEBUG, "Cipher: {}", enum_to_string(cipher));
|
||||||
|
|
||||||
// Simplification: We only support handshake hash functions via HMAC
|
// Simplification: We only support handshake hash functions via HMAC
|
||||||
m_context.handshake_hash.initialize(hmac_hash());
|
m_context.handshake_hash.initialize(hmac_hash());
|
||||||
|
@ -116,7 +116,7 @@ ssize_t TLSv12::handle_server_hello(ReadonlyBytes buffer, WritePacketStage& writ
|
||||||
u16 extension_length = AK::convert_between_host_and_network_endian(ByteReader::load16(buffer.offset_pointer(res)));
|
u16 extension_length = AK::convert_between_host_and_network_endian(ByteReader::load16(buffer.offset_pointer(res)));
|
||||||
res += 2;
|
res += 2;
|
||||||
|
|
||||||
dbgln_if(TLS_DEBUG, "Extension {} with length {}", (u16)extension_type, extension_length);
|
dbgln_if(TLS_DEBUG, "Extension {} with length {}", enum_to_string(extension_type), extension_length);
|
||||||
|
|
||||||
if (buffer.size() - res < extension_length)
|
if (buffer.size() - res < extension_length)
|
||||||
return (i8)Error::NeedMoreData;
|
return (i8)Error::NeedMoreData;
|
||||||
|
@ -188,7 +188,7 @@ ssize_t TLSv12::handle_server_hello(ReadonlyBytes buffer, WritePacketStage& writ
|
||||||
// that the server supports uncompressed points.
|
// that the server supports uncompressed points.
|
||||||
res += extension_length;
|
res += extension_length;
|
||||||
} else {
|
} else {
|
||||||
dbgln("Encountered unknown extension {} with length {}", (u16)extension_type, extension_length);
|
dbgln("Encountered unknown extension {} with length {}", enum_to_string(extension_type), extension_length);
|
||||||
res += extension_length;
|
res += extension_length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -346,9 +346,9 @@ ssize_t TLSv12::handle_ecdhe_rsa_server_key_exchange(ReadonlyBytes buffer)
|
||||||
ssize_t TLSv12::verify_rsa_server_key_exchange(ReadonlyBytes server_key_info_buffer, ReadonlyBytes signature_buffer)
|
ssize_t TLSv12::verify_rsa_server_key_exchange(ReadonlyBytes server_key_info_buffer, ReadonlyBytes signature_buffer)
|
||||||
{
|
{
|
||||||
auto signature_hash = signature_buffer[0];
|
auto signature_hash = signature_buffer[0];
|
||||||
auto signature_algorithm = signature_buffer[1];
|
auto signature_algorithm = static_cast<SignatureAlgorithm>(signature_buffer[1]);
|
||||||
if (signature_algorithm != (u8)SignatureAlgorithm::RSA) {
|
if (signature_algorithm != SignatureAlgorithm::RSA) {
|
||||||
dbgln("verify_rsa_server_key_exchange failed: Signature algorithm is not RSA, instead {}", signature_algorithm);
|
dbgln("verify_rsa_server_key_exchange failed: Signature algorithm is not RSA, instead {}", enum_to_string(signature_algorithm));
|
||||||
return (i8)Error::NotUnderstood;
|
return (i8)Error::NotUnderstood;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -325,8 +325,8 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
|
||||||
// FIXME: Read the version and verify it
|
// FIXME: Read the version and verify it
|
||||||
|
|
||||||
if constexpr (TLS_DEBUG) {
|
if constexpr (TLS_DEBUG) {
|
||||||
auto version = ByteReader::load16(buffer.offset_pointer(buffer_position));
|
auto version = static_cast<ProtocolVersion>(ByteReader::load16(buffer.offset_pointer(buffer_position)));
|
||||||
dbgln("type={}, version={}", (u8)type, (u16)version);
|
dbgln("type={}, version={}", enum_to_string(type), enum_to_string(version));
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_position += 2;
|
buffer_position += 2;
|
||||||
|
@ -341,7 +341,7 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
|
||||||
return (i8)Error::NeedMoreData;
|
return (i8)Error::NeedMoreData;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgln_if(TLS_DEBUG, "message type: {}, length: {}", (u8)type, length);
|
dbgln_if(TLS_DEBUG, "message type: {}, length: {}", enum_to_string(type), length);
|
||||||
auto plain = buffer.slice(buffer_position, buffer.size() - buffer_position);
|
auto plain = buffer.slice(buffer_position, buffer.size() - buffer_position);
|
||||||
|
|
||||||
ByteBuffer decrypted;
|
ByteBuffer decrypted;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue