mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibTLS: Even more ByteBuffer -> Span conversion
This commit is contained in:
parent
f82b0a78ef
commit
e517505e35
Notes:
sideshowbarker
2024-07-19 00:44:31 +09:00
Author: https://github.com/awesomekling
Commit: e517505e35
8 changed files with 18 additions and 23 deletions
|
@ -96,9 +96,7 @@ void GeminiJob::read_while_data_available(Function<IterationDecision()> read)
|
||||||
|
|
||||||
void GeminiJob::set_certificate(String certificate, String private_key)
|
void GeminiJob::set_certificate(String certificate, String private_key)
|
||||||
{
|
{
|
||||||
if (!m_socket->add_client_key(
|
if (!m_socket->add_client_key(certificate.bytes(), private_key.bytes())) {
|
||||||
ByteBuffer::wrap(const_cast<char*>(certificate.characters()), certificate.length()),
|
|
||||||
ByteBuffer::wrap(const_cast<char*>(private_key.characters()), private_key.length()))) {
|
|
||||||
dbg() << "LibGemini: Failed to set a client certificate";
|
dbg() << "LibGemini: Failed to set a client certificate";
|
||||||
// FIXME: Do something about this failure
|
// FIXME: Do something about this failure
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
|
|
|
@ -89,10 +89,7 @@ void HttpsJob::shutdown()
|
||||||
|
|
||||||
void HttpsJob::set_certificate(String certificate, String private_key)
|
void HttpsJob::set_certificate(String certificate, String private_key)
|
||||||
{
|
{
|
||||||
if (!m_socket->add_client_key(
|
if (!m_socket->add_client_key(certificate.bytes(), private_key.bytes())) {
|
||||||
ByteBuffer::wrap(const_cast<char*>(certificate.characters()), certificate.length()),
|
|
||||||
ByteBuffer::wrap(const_cast<char*>(private_key.characters()), private_key.length()))) {
|
|
||||||
|
|
||||||
dbg() << "LibHTTP: Failed to set a client certificate";
|
dbg() << "LibHTTP: Failed to set a client certificate";
|
||||||
// FIXME: Do something about this failure
|
// FIXME: Do something about this failure
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
|
|
|
@ -92,7 +92,7 @@ ssize_t TLSv12::handle_hello(ReadonlyBytes buffer, WritePacketStage& write_packe
|
||||||
m_context.session_id_size = session_length;
|
m_context.session_id_size = session_length;
|
||||||
#ifdef TLS_DEBUG
|
#ifdef TLS_DEBUG
|
||||||
dbg() << "Remote session ID:";
|
dbg() << "Remote session ID:";
|
||||||
print_buffer(ByteBuffer::wrap(m_context.session_id, session_length));
|
print_buffer(ReadonlyBytes { m_context.session_id, session_length });
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
m_context.session_id_size = 0;
|
m_context.session_id_size = 0;
|
||||||
|
|
|
@ -50,8 +50,8 @@ bool TLSv12::expand_key()
|
||||||
key_buffer,
|
key_buffer,
|
||||||
m_context.master_key,
|
m_context.master_key,
|
||||||
(const u8*)"key expansion", 13,
|
(const u8*)"key expansion", 13,
|
||||||
ByteBuffer::wrap(m_context.remote_random, 32),
|
ReadonlyBytes { m_context.remote_random, sizeof(m_context.remote_random) },
|
||||||
ByteBuffer::wrap(m_context.local_random, 32));
|
ReadonlyBytes { m_context.local_random, sizeof(m_context.local_random) });
|
||||||
|
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
if (is_aead) {
|
if (is_aead) {
|
||||||
|
@ -93,14 +93,14 @@ bool TLSv12::expand_key()
|
||||||
memcpy(m_context.crypto.local_aead_iv, client_iv, iv_size);
|
memcpy(m_context.crypto.local_aead_iv, client_iv, iv_size);
|
||||||
memcpy(m_context.crypto.remote_aead_iv, server_iv, iv_size);
|
memcpy(m_context.crypto.remote_aead_iv, server_iv, iv_size);
|
||||||
|
|
||||||
m_aes_local.gcm = make<Crypto::Cipher::AESCipher::GCMMode>(ByteBuffer::wrap(client_key, key_size), key_size * 8, Crypto::Cipher::Intent::Encryption, Crypto::Cipher::PaddingMode::RFC5246);
|
m_aes_local.gcm = make<Crypto::Cipher::AESCipher::GCMMode>(ReadonlyBytes { client_key, key_size }, key_size * 8, Crypto::Cipher::Intent::Encryption, Crypto::Cipher::PaddingMode::RFC5246);
|
||||||
m_aes_remote.gcm = make<Crypto::Cipher::AESCipher::GCMMode>(ByteBuffer::wrap(server_key, key_size), key_size * 8, Crypto::Cipher::Intent::Decryption, Crypto::Cipher::PaddingMode::RFC5246);
|
m_aes_remote.gcm = make<Crypto::Cipher::AESCipher::GCMMode>(ReadonlyBytes { server_key, key_size }, key_size * 8, Crypto::Cipher::Intent::Decryption, Crypto::Cipher::PaddingMode::RFC5246);
|
||||||
} else {
|
} else {
|
||||||
memcpy(m_context.crypto.local_iv, client_iv, iv_size);
|
memcpy(m_context.crypto.local_iv, client_iv, iv_size);
|
||||||
memcpy(m_context.crypto.remote_iv, server_iv, iv_size);
|
memcpy(m_context.crypto.remote_iv, server_iv, iv_size);
|
||||||
|
|
||||||
m_aes_local.cbc = make<Crypto::Cipher::AESCipher::CBCMode>(ByteBuffer::wrap(client_key, key_size), key_size * 8, Crypto::Cipher::Intent::Encryption, Crypto::Cipher::PaddingMode::RFC5246);
|
m_aes_local.cbc = make<Crypto::Cipher::AESCipher::CBCMode>(ReadonlyBytes { client_key, key_size }, key_size * 8, Crypto::Cipher::Intent::Encryption, Crypto::Cipher::PaddingMode::RFC5246);
|
||||||
m_aes_remote.cbc = make<Crypto::Cipher::AESCipher::CBCMode>(ByteBuffer::wrap(server_key, key_size), key_size * 8, Crypto::Cipher::Intent::Decryption, Crypto::Cipher::PaddingMode::RFC5246);
|
m_aes_remote.cbc = make<Crypto::Cipher::AESCipher::CBCMode>(ReadonlyBytes { server_key, key_size }, key_size * 8, Crypto::Cipher::Intent::Decryption, Crypto::Cipher::PaddingMode::RFC5246);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_context.crypto.created = 1;
|
m_context.crypto.created = 1;
|
||||||
|
@ -167,8 +167,8 @@ bool TLSv12::compute_master_secret(size_t length)
|
||||||
m_context.master_key,
|
m_context.master_key,
|
||||||
m_context.premaster_key,
|
m_context.premaster_key,
|
||||||
(const u8*)"master secret", 13,
|
(const u8*)"master secret", 13,
|
||||||
ByteBuffer::wrap(m_context.local_random, 32),
|
ReadonlyBytes { m_context.local_random, sizeof(m_context.local_random) },
|
||||||
ByteBuffer::wrap(m_context.remote_random, 32));
|
ReadonlyBytes { m_context.remote_random, sizeof(m_context.remote_random) });
|
||||||
|
|
||||||
m_context.premaster_key.clear();
|
m_context.premaster_key.clear();
|
||||||
#ifdef TLS_DEBUG
|
#ifdef TLS_DEBUG
|
||||||
|
|
|
@ -157,7 +157,7 @@ ByteBuffer TLSv12::build_finished()
|
||||||
auto dummy = ByteBuffer::create_zeroed(0);
|
auto dummy = ByteBuffer::create_zeroed(0);
|
||||||
|
|
||||||
auto digest = m_context.handshake_hash.digest();
|
auto digest = m_context.handshake_hash.digest();
|
||||||
auto hashbuf = ByteBuffer::wrap(const_cast<u8*>(digest.immutable_data()), m_context.handshake_hash.digest_size());
|
auto hashbuf = ReadonlyBytes { digest.immutable_data(), m_context.handshake_hash.digest_size() };
|
||||||
pseudorandom_function(outbuffer, m_context.master_key, (const u8*)"client finished", 15, hashbuf, dummy);
|
pseudorandom_function(outbuffer, m_context.master_key, (const u8*)"client finished", 15, hashbuf, dummy);
|
||||||
|
|
||||||
builder.append(outbuffer.bytes());
|
builder.append(outbuffer.bytes());
|
||||||
|
|
|
@ -371,7 +371,7 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
|
||||||
memcpy(temp_buf, buffer.offset_pointer(0), 3);
|
memcpy(temp_buf, buffer.offset_pointer(0), 3);
|
||||||
*(u16*)(temp_buf + 3) = AK::convert_between_host_and_network_endian(length);
|
*(u16*)(temp_buf + 3) = AK::convert_between_host_and_network_endian(length);
|
||||||
auto hmac = hmac_message({ temp_buf, 5 }, decrypted_span.slice(0, length), mac_size);
|
auto hmac = hmac_message({ temp_buf, 5 }, decrypted_span.slice(0, length), mac_size);
|
||||||
auto message_mac = ByteBuffer::wrap(const_cast<u8*>(message_hmac), mac_size);
|
auto message_mac = ReadonlyBytes { message_hmac, mac_size };
|
||||||
if (hmac != message_mac) {
|
if (hmac != message_mac) {
|
||||||
dbg() << "integrity check failed (mac length " << mac_size << ")";
|
dbg() << "integrity check failed (mac length " << mac_size << ")";
|
||||||
dbg() << "mac received:";
|
dbg() << "mac received:";
|
||||||
|
|
|
@ -292,7 +292,7 @@ static ssize_t _parse_asn1(const Context& context, Certificate& cert, const u8*
|
||||||
cert.SAN.append(alt_name);
|
cert.SAN.append(alt_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// print_buffer(ByteBuffer::wrap(const_cast<u8*>(buffer) + position, length));
|
// print_buffer(ReadonlyBytes { buffer + position, length });
|
||||||
break;
|
break;
|
||||||
case 0x03:
|
case 0x03:
|
||||||
if (_asn1_is_field_present(fields, Constants::pk_id)) {
|
if (_asn1_is_field_present(fields, Constants::pk_id)) {
|
||||||
|
|
|
@ -204,7 +204,7 @@ static void aes_cbc(const char* message, size_t len)
|
||||||
|
|
||||||
if (encrypting) {
|
if (encrypting) {
|
||||||
Crypto::Cipher::AESCipher::CBCMode cipher(
|
Crypto::Cipher::AESCipher::CBCMode cipher(
|
||||||
ByteBuffer::wrap(const_cast<char*>(secret_key), strlen(secret_key)),
|
StringView(secret_key).bytes(),
|
||||||
key_bits,
|
key_bits,
|
||||||
Crypto::Cipher::Intent::Encryption);
|
Crypto::Cipher::Intent::Encryption);
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ static void aes_cbc(const char* message, size_t len)
|
||||||
print_buffer(enc_span, Crypto::Cipher::AESCipher::block_size());
|
print_buffer(enc_span, Crypto::Cipher::AESCipher::block_size());
|
||||||
} else {
|
} else {
|
||||||
Crypto::Cipher::AESCipher::CBCMode cipher(
|
Crypto::Cipher::AESCipher::CBCMode cipher(
|
||||||
ByteBuffer::wrap(const_cast<char*>(secret_key), strlen(secret_key)),
|
StringView(secret_key).bytes(),
|
||||||
key_bits,
|
key_bits,
|
||||||
Crypto::Cipher::Intent::Decryption);
|
Crypto::Cipher::Intent::Decryption);
|
||||||
auto dec = cipher.create_aligned_buffer(buffer.size());
|
auto dec = cipher.create_aligned_buffer(buffer.size());
|
||||||
|
@ -2038,8 +2038,8 @@ static void tls_test_client_hello()
|
||||||
FAIL(write(0) failed);
|
FAIL(write(0) failed);
|
||||||
loop.quit(0);
|
loop.quit(0);
|
||||||
}
|
}
|
||||||
auto* the_server = (const u8*)(server ?: DEFAULT_SERVER);
|
auto* the_server = server ?: DEFAULT_SERVER;
|
||||||
if (!tls.write(ByteBuffer::wrap(const_cast<u8*>(the_server), strlen((const char*)the_server)))) {
|
if (!tls.write(StringView(the_server).bytes())) {
|
||||||
FAIL(write(1) failed);
|
FAIL(write(1) failed);
|
||||||
loop.quit(0);
|
loop.quit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue