summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibTLS/Extensions.h83
-rw-r--r--Userland/Libraries/LibTLS/Handshake.cpp2
-rw-r--r--Userland/Libraries/LibTLS/HandshakeServer.cpp12
-rw-r--r--Userland/Libraries/LibTLS/Record.cpp6
4 files changed, 93 insertions, 10 deletions
diff --git a/Userland/Libraries/LibTLS/Extensions.h b/Userland/Libraries/LibTLS/Extensions.h
index 6a418bf712..4f206811e6 100644
--- a/Userland/Libraries/LibTLS/Extensions.h
+++ b/Userland/Libraries/LibTLS/Extensions.h
@@ -704,6 +704,89 @@ enum class AlertDescription : u8 {
#undef _ENUM_KEY
#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)
{
#define _ENUM_KEY_VALUE(name, value) \
diff --git a/Userland/Libraries/LibTLS/Handshake.cpp b/Userland/Libraries/LibTLS/Handshake.cpp
index c654eeb9fd..d2a3933aab 100644
--- a/Userland/Libraries/LibTLS/Handshake.cpp
+++ b/Userland/Libraries/LibTLS/Handshake.cpp
@@ -412,7 +412,7 @@ ssize_t TLSv12::handle_handshake_payload(ReadonlyBytes vbuffer)
}
break;
default:
- dbgln("message type not understood: {}", to_underlying(type));
+ dbgln("message type not understood: {}", enum_to_string(type));
return (i8)Error::NotUnderstood;
}
diff --git a/Userland/Libraries/LibTLS/HandshakeServer.cpp b/Userland/Libraries/LibTLS/HandshakeServer.cpp
index 27e4158b15..239f1882bb 100644
--- a/Userland/Libraries/LibTLS/HandshakeServer.cpp
+++ b/Userland/Libraries/LibTLS/HandshakeServer.cpp
@@ -85,7 +85,7 @@ ssize_t TLSv12::handle_server_hello(ReadonlyBytes buffer, WritePacketStage& writ
return (i8)Error::NoCommonCipher;
}
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
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)));
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)
return (i8)Error::NeedMoreData;
@@ -188,7 +188,7 @@ ssize_t TLSv12::handle_server_hello(ReadonlyBytes buffer, WritePacketStage& writ
// that the server supports uncompressed points.
res += extension_length;
} 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;
}
}
@@ -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)
{
auto signature_hash = signature_buffer[0];
- auto signature_algorithm = signature_buffer[1];
- if (signature_algorithm != (u8)SignatureAlgorithm::RSA) {
- dbgln("verify_rsa_server_key_exchange failed: Signature algorithm is not RSA, instead {}", signature_algorithm);
+ auto signature_algorithm = static_cast<SignatureAlgorithm>(signature_buffer[1]);
+ if (signature_algorithm != SignatureAlgorithm::RSA) {
+ dbgln("verify_rsa_server_key_exchange failed: Signature algorithm is not RSA, instead {}", enum_to_string(signature_algorithm));
return (i8)Error::NotUnderstood;
}
diff --git a/Userland/Libraries/LibTLS/Record.cpp b/Userland/Libraries/LibTLS/Record.cpp
index 729d936f4b..0426787b4e 100644
--- a/Userland/Libraries/LibTLS/Record.cpp
+++ b/Userland/Libraries/LibTLS/Record.cpp
@@ -325,8 +325,8 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
// FIXME: Read the version and verify it
if constexpr (TLS_DEBUG) {
- auto version = ByteReader::load16(buffer.offset_pointer(buffer_position));
- dbgln("type={}, version={}", (u8)type, (u16)version);
+ auto version = static_cast<ProtocolVersion>(ByteReader::load16(buffer.offset_pointer(buffer_position)));
+ dbgln("type={}, version={}", enum_to_string(type), enum_to_string(version));
}
buffer_position += 2;
@@ -341,7 +341,7 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
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);
ByteBuffer decrypted;