1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

LibTLS: Even more ByteBuffer -> Span conversion

This commit is contained in:
Andreas Kling 2020-12-19 16:23:52 +01:00
parent f82b0a78ef
commit e517505e35
Notes: sideshowbarker 2024-07-19 00:44:31 +09:00
8 changed files with 18 additions and 23 deletions

View file

@ -92,7 +92,7 @@ ssize_t TLSv12::handle_hello(ReadonlyBytes buffer, WritePacketStage& write_packe
m_context.session_id_size = session_length;
#ifdef TLS_DEBUG
dbg() << "Remote session ID:";
print_buffer(ByteBuffer::wrap(m_context.session_id, session_length));
print_buffer(ReadonlyBytes { m_context.session_id, session_length });
#endif
} else {
m_context.session_id_size = 0;

View file

@ -50,8 +50,8 @@ bool TLSv12::expand_key()
key_buffer,
m_context.master_key,
(const u8*)"key expansion", 13,
ByteBuffer::wrap(m_context.remote_random, 32),
ByteBuffer::wrap(m_context.local_random, 32));
ReadonlyBytes { m_context.remote_random, sizeof(m_context.remote_random) },
ReadonlyBytes { m_context.local_random, sizeof(m_context.local_random) });
size_t offset = 0;
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.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_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_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>(ReadonlyBytes { server_key, key_size }, key_size * 8, Crypto::Cipher::Intent::Decryption, Crypto::Cipher::PaddingMode::RFC5246);
} else {
memcpy(m_context.crypto.local_iv, client_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_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_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>(ReadonlyBytes { server_key, key_size }, key_size * 8, Crypto::Cipher::Intent::Decryption, Crypto::Cipher::PaddingMode::RFC5246);
}
m_context.crypto.created = 1;
@ -167,8 +167,8 @@ bool TLSv12::compute_master_secret(size_t length)
m_context.master_key,
m_context.premaster_key,
(const u8*)"master secret", 13,
ByteBuffer::wrap(m_context.local_random, 32),
ByteBuffer::wrap(m_context.remote_random, 32));
ReadonlyBytes { m_context.local_random, sizeof(m_context.local_random) },
ReadonlyBytes { m_context.remote_random, sizeof(m_context.remote_random) });
m_context.premaster_key.clear();
#ifdef TLS_DEBUG

View file

@ -157,7 +157,7 @@ ByteBuffer TLSv12::build_finished()
auto dummy = ByteBuffer::create_zeroed(0);
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);
builder.append(outbuffer.bytes());

View file

@ -371,7 +371,7 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
memcpy(temp_buf, buffer.offset_pointer(0), 3);
*(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 message_mac = ByteBuffer::wrap(const_cast<u8*>(message_hmac), mac_size);
auto message_mac = ReadonlyBytes { message_hmac, mac_size };
if (hmac != message_mac) {
dbg() << "integrity check failed (mac length " << mac_size << ")";
dbg() << "mac received:";

View file

@ -292,7 +292,7 @@ static ssize_t _parse_asn1(const Context& context, Certificate& cert, const u8*
cert.SAN.append(alt_name);
}
}
// print_buffer(ByteBuffer::wrap(const_cast<u8*>(buffer) + position, length));
// print_buffer(ReadonlyBytes { buffer + position, length });
break;
case 0x03:
if (_asn1_is_field_present(fields, Constants::pk_id)) {