Commit Graph

73 Commits

Author SHA1 Message Date
Ben Wiederhake
7967a8bd8c LibTLS: Avoid implicitly copying ByteBuffer 2021-12-08 09:46:13 -08:00
Andreas Kling
80d4e830a0 Everywhere: Pass AK::ReadonlyBytes by value 2021-11-11 01:27:46 +01:00
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling
a15ed8743d AK: Make ByteBuffer::try_* functions return ErrorOr<void>
Same as Vector, ByteBuffer now also signals allocation failure by
returning an ENOMEM Error instead of a bool, allowing us to use the
TRY() and MUST() patterns.
2021-11-10 21:58:58 +01:00
Ali Mohammad Pur
e8891e6d56 LibTLS: Remove useless ByteBuffer allocation in TLSv12::read_line() 2021-10-10 00:27:44 +02:00
Ben Wiederhake
5e4739e371 LibTLS: Add missing headers to CipherSuite.h 2021-10-06 23:52:40 +01:00
Ali Mohammad Pur
ab46864674 LibTLS: Split large application data packets into chunks
Each TLS record has a limited max size, we should respect that and split
the packets.
Fixes RecordOverflow errors when a packet larger than 18432 bytes is
sent over.
2021-10-03 14:42:00 +03:30
Nico Weber
de72332920 Libraries: Fix typos 2021-10-01 01:06:40 +01:00
Ali Mohammad Pur
3d24850db5 LibTLS: Mark the connection as finished and disconnected on TLS error 2021-09-28 22:32:31 +02:00
Ben Wiederhake
32e98d0924 Libraries: Use AK::Variant default initialization where appropriate 2021-09-21 04:22:52 +04:30
Ali Mohammad Pur
436693c0c9 LibTLS: Use a setter for on_tls_ready_to_write with some more smarts
The callback should be called as soon as the connection is established,
and if we actually set the callback when it already is, we expect it to
be called immediately.
2021-09-19 21:10:23 +04:30
Ali Mohammad Pur
d3ea0818f3 LibTLS: Don't close the underlying socket on EOF 2021-09-19 21:10:23 +04:30
Ali Mohammad Pur
f4d3c54c12 LibTLS: Close the underlying socket on EOF
This is 23febbed41 but without the bug
that makes the CI hang :^)
2021-09-16 16:42:51 +02:00
Brian Gianforcaro
b61eff8730 Revert "LibTLS: Close the underlying socket on EOF"
This reverts commit 23febbed41.

It breaks the TestTLSHandshake test used in CI, it causes it
to hang, and all CI jobs have been hanging.
2021-09-16 09:11:32 +00:00
Ali Mohammad Pur
e5fde795e0 LibTLS: Increase the maximum socket read size to 4MiB
There's no reason to limit ourselves to 4KiB, this socket is not
blocking anyway.
2021-09-15 22:29:47 +02:00
Ali Mohammad Pur
23febbed41 LibTLS: Close the underlying socket on EOF
There's no reason to keep waiting when there's nothing else to come.
This makes RequestServer not spin on Core::Socket::read() (in some
scenarios).
2021-09-15 22:29:47 +02:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
Ali Mohammad Pur
3a9f00c59b Everywhere: Use OOM-safe ByteBuffer APIs where possible
If we can easily communicate failure, let's avoid asserting and report
failure instead.
2021-09-06 01:53:26 +02:00
sin-ack
8ea22121ac Userland: Migrate to argument-less deferred_invoke
Only one place used this argument and it was to hold on to a strong ref
for the object. Since we already do that now, there's no need to keep
this argument around since this can be easily captured.

This commit contains no changes.
2021-09-02 03:47:47 +04:30
networkException
acde7d12b0 Everywhere: Rename get in ConfigFile::get_for_{lib,app,system} to open
This patch brings the ConfigFile helpers for opening lib, app and system
configs more inline with the regular ConfigFile::open functions.
2021-08-22 01:32:25 +02:00
Samuel Bowman
7089135a07 LibTLS: Add DHE_RSA AES GCM cipher suites
This adds the following cipher suites:
  * DHE_RSA_WITH_AES_128_GCM_SHA256
  * DHE_RSA_WITH_AES_256_GCM_SHA384
2021-08-16 03:50:53 +04:30
Samuel Bowman
b288016bbc LibTLS: Implement the DHE_RSA key exchange algorithm
This adds two methods, handle_dhe_rsa_server_key_exchange and
build_dhe_rsa_pre_master_secret, to TLSv12 and a struct,
server_diffie_hellman_params, to Context, which are used to implement
the DHE_RSA key exchange algorithm. This grants us the benefits of
forward secrecy and access to sites which support DHE_RSA.

It is worth noting that the signature of the server provided
Diffie-Hellman parameters is not currently validated. This will need to
be addressed to prevent man-in-the-middle attacks.
2021-08-16 03:50:53 +04:30
Andreas Kling
c94c15d45c Everywhere: Replace AK::Singleton => Singleton 2021-08-08 00:03:45 +02:00
Brian Gianforcaro
18d6f9ed5c Libraries: Remove unused header includes 2021-08-01 08:10:16 +02:00
Idan Horowitz
005d75656e LibCrypto: Replace from_base{2,8,10,16}() & to_base10 with from_base(N)
This allows us to support parsing and serializing BigIntegers to and
from any base N (such that 2 <= N <= 36).
2021-06-29 16:55:54 +01:00
Ali Mohammad Pur
2a7cb4fe42 LibTLS: Ensure that on_tls_finished is called only once
Connection state changes when the logical transport is closed should
not trigger tls_finished.
2021-06-28 16:35:04 +02:00
Ali Mohammad Pur
2fe9c81b30 Everywhere: Replace the multiple impls of print_buffer() with :hex-dump 2021-06-17 18:44:00 +04:30
Ali Mohammad Pur
7ac196974d Everywhere: Replace Vector<T*> with nonnull entries with Vector<T&> 2021-06-08 19:14:24 +02:00
Gunnar Beutner
5f18cf75c5 AK: Replace ByteBuffer::grow with resize()/ensure_capacity()
Previously ByteBuffer::grow() behaved like Vector<T>::resize().
However the function name was somewhat ambiguous - and so this patch
updates ByteBuffer to behave more like Vector<T> by replacing grow()
with resize() and adding an ensure_capacity() method.

This also lets the user change the buffer's capacity without affecting
the size which was not previously possible.

Additionally this patch makes the capacity() method public (again).
2021-05-31 14:49:00 +04:30
DexesTTP
4bbf954ad0 LibTLS: Allow using other hash algorithms for HMAC
The standard allows for ciphers to define which hash to use.
Fixes #7348
2021-05-29 13:29:46 +04:30
DexesTTP
cb4a0dec8a LibTLS: Use a more precise KeyExchangeAlgorithm enum
The old enumeration didn't allow discriminating the key exchange
algorithms used, but only allowed the handshake with the server. With
this new enumeration, we can know which key exchange algorithm we are
actually supposed to use :^)
2021-05-29 13:29:46 +04:30
DexesTTP
dd35aa7725 LibTLS: Add IANA Hex codes for all recommended cipher suites
Also sort the existing cipher suites, and remove the unsupported ones.
We don't support any of these recommended ciphers, but at least we now
know which ones we should focus on :^)
2021-05-29 13:29:46 +04:30
DexesTTP
ed1800547e LibTLS: Enable the RSA_WITH_AES_256_GCM_SHA384 cipher
This is more of an example commit of how to add new ciphers to TLS.
2021-05-19 09:18:45 +02:00
DexesTTP
68f6796e72 LibTLS: Use RSA key exchange based on the cipher
After this, we aren't hardcoding RSA in everything we do anymore!
2021-05-19 09:18:45 +02:00
DexesTTP
9bb823a6ab LibTLS: Generate cipher variants based on the cipher
This is better than using the AEAD flag :^)
2021-05-19 09:18:45 +02:00
DexesTTP
2e9a4bb95c LibTLS: Replace cipher selection with a variant 2021-05-19 09:18:45 +02:00
DexesTTP
851e254e8f LibTLS: Rework method names and arrangement in cpp files
This commit only moves and renames methods. The code hasn't changed.
2021-05-19 09:18:45 +02:00
DexesTTP
6d190b299e LibTLS: Define cipher suite parameters and components in a macro
Instead of sprinkling the definition of the ciper suites all over the
TLS implementation, let's regroup it all once and for all in a single
place, and then add our new implementations there.
2021-05-19 09:18:45 +02:00
DexesTTP
17a1f51579 LibTLS: Move the asn certificate parser to Certificate.cpp 2021-05-19 09:18:45 +02:00
DexesTTP
45d55ecacc LibTLS: Move the cipher list to the CipherSuite.h header 2021-05-19 09:18:45 +02:00
Gunnar Beutner
53d0150827 AK+Userland: Remove nullability feature for the ByteBuffer type
Nobody seems to use this particular feature, in fact there were some
bugs which were uncovered by removing operator bool.
2021-05-16 17:49:42 +02:00
Gunnar Beutner
f0fa51773a AK+Userland: Fix some compiler warnings and make variables const-ref
This fixes a few compiler warnings and makes some variables const-ref
in preparation for the next commit which changes how ByteBuffer works.
2021-05-16 17:49:42 +02:00
Ali Mohammad Pur
5a7db74c52 LibTLS: Actually verify the certificats
This was likely commented out at some point to debug something.
2021-05-14 08:39:29 +01:00
Ali Mohammad Pur
df515e1d85 LibCrypto+LibTLS: Avoid unaligned reads and writes
This adds an `AK::ByteReader` to help with that so we don't duplicate
the logic all over the place.
No more `*(const u16*)` and `*(const u32*)` for anyone.
This should help a little with #7060.
2021-05-14 08:39:29 +01:00
Ali Mohammad Pur
d922bb0903 LibTLS: Enable -Wvla for LibTLS
Fixes #7071.
2021-05-13 17:53:32 +02:00
Ali Mohammad Pur
98ecb95709 LibTLS: Remove all uses of VLAs 2021-05-13 17:53:32 +02:00
Ali Mohammad Pur
a91a49337c LibCore+Everywhere: Move OpenMode out of IODevice
...and make it an enum class so people don't omit "OpenMode".
2021-05-12 11:00:45 +01:00
Ali Mohammad Pur
afa98fcb55 LibTLS: Always send the signature_algorithms extension
At some point since Sep 2018, OpenSSL added a ~~bug~~ feature that makes
the default set of signature algorithms defined in TLSv1.2 unusable
without reducing what they call the "security level", which caused
communication with servers using more recent versions of openssl to
fail with "internal error".
This commit makes LibTLS always send its supported sigalgs, making the
server not default to the insecure defaults, and thus enabling us to
talk to such servers.
2021-05-12 08:35:02 +01:00
Gunnar Beutner
6cf59b6ae9 Everywhere: Turn #if *_DEBUG into dbgln_if/if constexpr 2021-05-01 21:25:06 +02:00
Ali Mohammad Pur
cb134cd702 LibTLS: Call the read hooks after processing messages too
Otherwise the notification would be deferred until the next read event,
which means the client will not get any events if the server initiates
the appdata transfers.
2021-04-23 13:14:35 +02:00