mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:47:44 +00:00
Everywhere: Turn #if *_DEBUG into dbgln_if/if constexpr
This commit is contained in:
parent
4e6f03a860
commit
6cf59b6ae9
58 changed files with 315 additions and 469 deletions
|
@ -71,10 +71,10 @@ ssize_t TLSv12::handle_hello(ReadonlyBytes buffer, WritePacketStage& write_packe
|
|||
if (session_length && session_length <= 32) {
|
||||
memcpy(m_context.session_id, buffer.offset_pointer(res), session_length);
|
||||
m_context.session_id_size = session_length;
|
||||
#if TLS_DEBUG
|
||||
dbgln("Remote session ID:");
|
||||
print_buffer(ReadonlyBytes { m_context.session_id, session_length });
|
||||
#endif
|
||||
if constexpr (TLS_DEBUG) {
|
||||
dbgln("Remote session ID:");
|
||||
print_buffer(ReadonlyBytes { m_context.session_id, session_length });
|
||||
}
|
||||
} else {
|
||||
m_context.session_id_size = 0;
|
||||
}
|
||||
|
@ -268,10 +268,10 @@ void TLSv12::build_random(PacketBuilder& builder)
|
|||
}
|
||||
|
||||
auto& certificate = m_context.certificates[certificate_option.value()];
|
||||
#if TLS_DEBUG
|
||||
dbgln("PreMaster secret");
|
||||
print_buffer(m_context.premaster_key);
|
||||
#endif
|
||||
if constexpr (TLS_DEBUG) {
|
||||
dbgln("PreMaster secret");
|
||||
print_buffer(m_context.premaster_key);
|
||||
}
|
||||
|
||||
Crypto::PK::RSA_PKCS1_EME rsa(certificate.public_key.modulus(), 0, certificate.public_key.public_exponent());
|
||||
|
||||
|
@ -279,10 +279,10 @@ void TLSv12::build_random(PacketBuilder& builder)
|
|||
auto outbuf = Bytes { out, rsa.output_size() };
|
||||
rsa.encrypt(m_context.premaster_key, outbuf);
|
||||
|
||||
#if TLS_DEBUG
|
||||
dbgln("Encrypted: ");
|
||||
print_buffer(outbuf);
|
||||
#endif
|
||||
if constexpr (TLS_DEBUG) {
|
||||
dbgln("Encrypted: ");
|
||||
print_buffer(outbuf);
|
||||
}
|
||||
|
||||
if (!compute_master_secret(bytes)) {
|
||||
dbgln("oh noes we could not derive a master key :(");
|
||||
|
|
|
@ -53,22 +53,22 @@ bool TLSv12::expand_key()
|
|||
auto server_iv = key + offset;
|
||||
offset += iv_size;
|
||||
|
||||
#if TLS_DEBUG
|
||||
dbgln("client key");
|
||||
print_buffer(client_key, key_size);
|
||||
dbgln("server key");
|
||||
print_buffer(server_key, key_size);
|
||||
dbgln("client iv");
|
||||
print_buffer(client_iv, iv_size);
|
||||
dbgln("server iv");
|
||||
print_buffer(server_iv, iv_size);
|
||||
if (!is_aead) {
|
||||
dbgln("client mac key");
|
||||
print_buffer(m_context.crypto.local_mac, mac_size);
|
||||
dbgln("server mac key");
|
||||
print_buffer(m_context.crypto.remote_mac, mac_size);
|
||||
if constexpr (TLS_DEBUG) {
|
||||
dbgln("client key");
|
||||
print_buffer(client_key, key_size);
|
||||
dbgln("server key");
|
||||
print_buffer(server_key, key_size);
|
||||
dbgln("client iv");
|
||||
print_buffer(client_iv, iv_size);
|
||||
dbgln("server iv");
|
||||
print_buffer(server_iv, iv_size);
|
||||
if (!is_aead) {
|
||||
dbgln("client mac key");
|
||||
print_buffer(m_context.crypto.local_mac, mac_size);
|
||||
dbgln("server mac key");
|
||||
print_buffer(m_context.crypto.remote_mac, mac_size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (is_aead) {
|
||||
memcpy(m_context.crypto.local_aead_iv, client_iv, iv_size);
|
||||
|
@ -153,10 +153,10 @@ bool TLSv12::compute_master_secret(size_t length)
|
|||
ReadonlyBytes { m_context.remote_random, sizeof(m_context.remote_random) });
|
||||
|
||||
m_context.premaster_key.clear();
|
||||
#if TLS_DEBUG
|
||||
dbgln("master key:");
|
||||
print_buffer(m_context.master_key);
|
||||
#endif
|
||||
if constexpr (TLS_DEBUG) {
|
||||
dbgln("master key:");
|
||||
print_buffer(m_context.master_key);
|
||||
}
|
||||
expand_key();
|
||||
return true;
|
||||
}
|
||||
|
@ -195,9 +195,7 @@ ByteBuffer TLSv12::build_certificate()
|
|||
builder.append((u8)HandshakeType::CertificateMessage);
|
||||
|
||||
if (!total_certificate_size) {
|
||||
#if TLS_DEBUG
|
||||
dbgln("No certificates, sending empty certificate message");
|
||||
#endif
|
||||
dbgln_if(TLS_DEBUG, "No certificates, sending empty certificate message");
|
||||
builder.append_u24(certificate_vector_header_size);
|
||||
builder.append_u24(total_certificate_size);
|
||||
} else {
|
||||
|
|
|
@ -57,9 +57,7 @@ String TLSv12::read_line(size_t max_size)
|
|||
bool TLSv12::write(ReadonlyBytes buffer)
|
||||
{
|
||||
if (m_context.connection_status != ConnectionStatus::Established) {
|
||||
#if TLS_DEBUG
|
||||
dbgln("write request while not connected");
|
||||
#endif
|
||||
dbgln_if(TLS_DEBUG, "write request while not connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -186,9 +184,7 @@ bool TLSv12::check_connection_state(bool read)
|
|||
{
|
||||
if (!Core::Socket::is_open() || !Core::Socket::is_connected() || Core::Socket::eof()) {
|
||||
// an abrupt closure (the server is a jerk)
|
||||
#if TLS_DEBUG
|
||||
dbgln("Socket not open, assuming abrupt closure");
|
||||
#endif
|
||||
dbgln_if(TLS_DEBUG, "Socket not open, assuming abrupt closure");
|
||||
m_context.connection_finished = true;
|
||||
}
|
||||
if (m_context.critical_error) {
|
||||
|
@ -209,9 +205,7 @@ bool TLSv12::check_connection_state(bool read)
|
|||
m_context.application_buffer.size());
|
||||
} else {
|
||||
m_context.connection_finished = false;
|
||||
#if TLS_DEBUG
|
||||
dbgln("FINISHED");
|
||||
#endif
|
||||
dbgln_if(TLS_DEBUG, "FINISHED");
|
||||
}
|
||||
if (!m_context.application_buffer.size()) {
|
||||
m_context.connection_status = ConnectionStatus::Disconnected;
|
||||
|
@ -230,10 +224,10 @@ bool TLSv12::flush()
|
|||
if (out_buffer_length == 0)
|
||||
return true;
|
||||
|
||||
#if TLS_DEBUG
|
||||
dbgln("SENDING...");
|
||||
print_buffer(out_buffer, out_buffer_length);
|
||||
#endif
|
||||
if constexpr (TLS_DEBUG) {
|
||||
dbgln("SENDING...");
|
||||
print_buffer(out_buffer, out_buffer_length);
|
||||
}
|
||||
if (Core::Socket::write(&out_buffer[out_buffer_index], out_buffer_length)) {
|
||||
write_buffer().clear();
|
||||
return true;
|
||||
|
|
|
@ -493,9 +493,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
|
|||
ssize_t res = 0;
|
||||
|
||||
if (buffer.size() < 3) {
|
||||
#if TLS_DEBUG
|
||||
dbgln("not enough certificate header data");
|
||||
#endif
|
||||
dbgln_if(TLS_DEBUG, "not enough certificate header data");
|
||||
return (i8)Error::NeedMoreData;
|
||||
}
|
||||
|
||||
|
@ -509,9 +507,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
|
|||
res += 3;
|
||||
|
||||
if (certificate_total_length > buffer.size() - res) {
|
||||
#if TLS_DEBUG
|
||||
dbgln("not enough data for claimed total cert length");
|
||||
#endif
|
||||
dbgln_if(TLS_DEBUG, "not enough data for claimed total cert length");
|
||||
return (i8)Error::NeedMoreData;
|
||||
}
|
||||
size_t size = certificate_total_length;
|
||||
|
@ -522,18 +518,14 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
|
|||
while (size > 0) {
|
||||
++index;
|
||||
if (buffer.size() - res < 3) {
|
||||
#if TLS_DEBUG
|
||||
dbgln("not enough data for certificate length");
|
||||
#endif
|
||||
dbgln_if(TLS_DEBUG, "not enough data for certificate length");
|
||||
return (i8)Error::NeedMoreData;
|
||||
}
|
||||
size_t certificate_size = buffer[res] * 0x10000 + buffer[res + 1] * 0x100 + buffer[res + 2];
|
||||
res += 3;
|
||||
|
||||
if (buffer.size() - res < certificate_size) {
|
||||
#if TLS_DEBUG
|
||||
dbgln("not enough data for certificate body");
|
||||
#endif
|
||||
dbgln_if(TLS_DEBUG, "not enough data for certificate body");
|
||||
return (i8)Error::NeedMoreData;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue