diff --git a/Libraries/LibGemini/GeminiJob.cpp b/Libraries/LibGemini/GeminiJob.cpp index fdcc9a3d3ea..fcd19000cfc 100644 --- a/Libraries/LibGemini/GeminiJob.cpp +++ b/Libraries/LibGemini/GeminiJob.cpp @@ -96,9 +96,7 @@ void GeminiJob::read_while_data_available(Function read) void GeminiJob::set_certificate(String certificate, String private_key) { - if (!m_socket->add_client_key( - ByteBuffer::wrap(const_cast(certificate.characters()), certificate.length()), - ByteBuffer::wrap(const_cast(private_key.characters()), private_key.length()))) { + if (!m_socket->add_client_key(certificate.bytes(), private_key.bytes())) { dbg() << "LibGemini: Failed to set a client certificate"; // FIXME: Do something about this failure ASSERT_NOT_REACHED(); diff --git a/Libraries/LibHTTP/HttpsJob.cpp b/Libraries/LibHTTP/HttpsJob.cpp index b424764d220..0b1b5855da6 100644 --- a/Libraries/LibHTTP/HttpsJob.cpp +++ b/Libraries/LibHTTP/HttpsJob.cpp @@ -89,10 +89,7 @@ void HttpsJob::shutdown() void HttpsJob::set_certificate(String certificate, String private_key) { - if (!m_socket->add_client_key( - ByteBuffer::wrap(const_cast(certificate.characters()), certificate.length()), - ByteBuffer::wrap(const_cast(private_key.characters()), private_key.length()))) { - + if (!m_socket->add_client_key(certificate.bytes(), private_key.bytes())) { dbg() << "LibHTTP: Failed to set a client certificate"; // FIXME: Do something about this failure ASSERT_NOT_REACHED(); diff --git a/Libraries/LibTLS/ClientHandshake.cpp b/Libraries/LibTLS/ClientHandshake.cpp index a9cf86783da..633e01f9187 100644 --- a/Libraries/LibTLS/ClientHandshake.cpp +++ b/Libraries/LibTLS/ClientHandshake.cpp @@ -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; diff --git a/Libraries/LibTLS/Exchange.cpp b/Libraries/LibTLS/Exchange.cpp index f13484976cc..391f2d0abd7 100644 --- a/Libraries/LibTLS/Exchange.cpp +++ b/Libraries/LibTLS/Exchange.cpp @@ -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(ByteBuffer::wrap(client_key, key_size), key_size * 8, Crypto::Cipher::Intent::Encryption, Crypto::Cipher::PaddingMode::RFC5246); - m_aes_remote.gcm = make(ByteBuffer::wrap(server_key, key_size), key_size * 8, Crypto::Cipher::Intent::Decryption, Crypto::Cipher::PaddingMode::RFC5246); + m_aes_local.gcm = make(ReadonlyBytes { client_key, key_size }, key_size * 8, Crypto::Cipher::Intent::Encryption, Crypto::Cipher::PaddingMode::RFC5246); + m_aes_remote.gcm = make(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(ByteBuffer::wrap(client_key, key_size), key_size * 8, Crypto::Cipher::Intent::Encryption, Crypto::Cipher::PaddingMode::RFC5246); - m_aes_remote.cbc = make(ByteBuffer::wrap(server_key, key_size), key_size * 8, Crypto::Cipher::Intent::Decryption, Crypto::Cipher::PaddingMode::RFC5246); + m_aes_local.cbc = make(ReadonlyBytes { client_key, key_size }, key_size * 8, Crypto::Cipher::Intent::Encryption, Crypto::Cipher::PaddingMode::RFC5246); + m_aes_remote.cbc = make(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 diff --git a/Libraries/LibTLS/Handshake.cpp b/Libraries/LibTLS/Handshake.cpp index e4e4d9ff0ed..88cca0a8ad6 100644 --- a/Libraries/LibTLS/Handshake.cpp +++ b/Libraries/LibTLS/Handshake.cpp @@ -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(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()); diff --git a/Libraries/LibTLS/Record.cpp b/Libraries/LibTLS/Record.cpp index 627ac69e435..8f8b71c575a 100644 --- a/Libraries/LibTLS/Record.cpp +++ b/Libraries/LibTLS/Record.cpp @@ -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(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:"; diff --git a/Libraries/LibTLS/TLSv12.cpp b/Libraries/LibTLS/TLSv12.cpp index 41a4c7156ff..0101148af83 100644 --- a/Libraries/LibTLS/TLSv12.cpp +++ b/Libraries/LibTLS/TLSv12.cpp @@ -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(buffer) + position, length)); + // print_buffer(ReadonlyBytes { buffer + position, length }); break; case 0x03: if (_asn1_is_field_present(fields, Constants::pk_id)) { diff --git a/Userland/test-crypto.cpp b/Userland/test-crypto.cpp index 633ffe122ad..b650f1773d6 100644 --- a/Userland/test-crypto.cpp +++ b/Userland/test-crypto.cpp @@ -204,7 +204,7 @@ static void aes_cbc(const char* message, size_t len) if (encrypting) { Crypto::Cipher::AESCipher::CBCMode cipher( - ByteBuffer::wrap(const_cast(secret_key), strlen(secret_key)), + StringView(secret_key).bytes(), key_bits, 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()); } else { Crypto::Cipher::AESCipher::CBCMode cipher( - ByteBuffer::wrap(const_cast(secret_key), strlen(secret_key)), + StringView(secret_key).bytes(), key_bits, Crypto::Cipher::Intent::Decryption); auto dec = cipher.create_aligned_buffer(buffer.size()); @@ -2038,8 +2038,8 @@ static void tls_test_client_hello() FAIL(write(0) failed); loop.quit(0); } - auto* the_server = (const u8*)(server ?: DEFAULT_SERVER); - if (!tls.write(ByteBuffer::wrap(const_cast(the_server), strlen((const char*)the_server)))) { + auto* the_server = server ?: DEFAULT_SERVER; + if (!tls.write(StringView(the_server).bytes())) { FAIL(write(1) failed); loop.quit(0); }