Commit Graph

77 Commits

Author SHA1 Message Date
Ali Mohammad Pur
2f10243fa2 LibTLS: Ignore empty reads from underlying socket while connecting
We should not expect the server to respond immediately after connecting,
this can manifest as random requests failing (e.g. on https://null.com).
2024-04-26 15:53:00 +02:00
Andreas Kling
27a294547d LibTLS: Add segmentation to the application buffer to avoid memcpy churn
We were previously doing a *lot* of unnecessary memcpy work when
transferring large files.

This patch addresses the issue by introducing a simple segmented buffer
with no additional work when appending new data, or when transfering out
of the buffer.
2024-01-03 14:59:59 +01:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Michiel Visser
4ab75bd138 LibTLS: Add comment to cipher suite list about Mozilla recommended order 2023-11-27 15:02:04 +01:00
Michiel Visser
dde1e8ccf5 LibTLS: Modernize the TLS cipher suite list 2023-11-27 15:02:04 +01:00
Michiel Visser
e785172290 LibTLS: Implement the extended_master_secret TLS extension 2023-11-27 09:37:25 +03:30
Michiel Visser
927dc1f02a LibTLS: Add support for SECP384r1 2023-11-11 14:40:10 +03:30
Ali Mohammad Pur
32e6fd9715 LibTLS: Do not defer flushing alert packets
There's a good chance the TLS socket instance will be deleted before the
deferred invocation fires, and there's no real reason to defer flushes
of alerts anyway as they are usually sent on errors.
Fixes #21800.
2023-11-10 09:02:58 +01:00
stelar7
a559dca816 LibTLS: Fix supported signature algorithms typo
The ED curve is INTRINSIC/ED25519, not INTRINSIC/ECDSA
2023-10-31 07:07:53 +01:00
Michiel Visser
c548dca174 LibTLS: Add ECDSA support with the secp256r1 curve 2023-10-30 10:17:39 -06:00
stelar7
42d80aab06 LibTLS: Reorder supported ciphers 2023-10-06 22:32:07 +02:00
Lucas CHOLLET
9581fe1d7d LibTLS: Remove unused methods
Affected methods are:
 - can_read_line
 - can_read
 - read_line
2023-07-03 23:29:28 +02:00
stelar7
5853d9642a LibTLS: Move AlertDescription to Extensions.h
Also add missing values from the IANA registry
2023-04-14 12:32:04 +01:00
stelar7
e8945f15f4 LibTLS: Move CipherSuite to Extensions.h
Also add missing values from the IANA registry
2023-04-14 12:32:04 +01:00
stelar7
e5f81475e5 LibTLS: Move ECPointFormat to Extensions.h
Also add missing values from the IANA registry
2023-04-14 12:32:04 +01:00
stelar7
a4855aef17 LibTLS: Rename NamedCurve to SupportedGroup
This matches the wording used in the IANA registry and TLS 1.3
Also add missing values from the IANA registry
2023-04-14 12:32:04 +01:00
stelar7
6df3ffaf45 LibTLS: Move ECCurveType to Extensions.h
Also add missing values from the IANA registry
2023-04-14 12:32:04 +01:00
stelar7
0fea6e7f13 LibTLS: Move NameType to Extensions.h 2023-04-14 12:32:04 +01:00
stelar7
9110f26c79 LibTLS: Rename HandshakeExtension to ExtensionType
This matches the wording used in the TLS RFC
2023-04-14 12:32:04 +01:00
stelar7
c30ee1b89b LibTLS: Update HandshakeType value names to match IANA registry values 2023-04-14 12:32:04 +01:00
stelar7
611a235a52 LibTLS: Rename AlertLevel Critial to FATAL
This matches the wording used in the TLS RFC
2023-04-14 12:32:04 +01:00
stelar7
ca6b8bfe7f LibTLS: Rename Version to ProtocolVersion
This matches the wording used in the TLS RFC
Also define GREASE values as specified in RFC8701
2023-04-14 12:32:04 +01:00
Tim Schumacher
d5871f5717 AK: Rename Stream::{read,write} to Stream::{read_some,write_some}
Similar to POSIX read, the basic read and write functions of AK::Stream
do not have a lower limit of how much data they read or write (apart
from "none at all").

Rename the functions to "read some [data]" and "write some [data]" (with
"data" being omitted, since everything here is reading and writing data)
to make them sufficiently distinct from the functions that ensure to
use the entire buffer (which should be the go-to function for most
usages).

No functional changes, just a lot of new FIXMEs.
2023-03-13 15:16:20 +00:00
Tim Schumacher
874c7bba28 LibCore: Remove Stream.h 2023-02-13 00:50:07 +00:00
Tim Schumacher
a96339b72b LibCore: Move Stream-based sockets into the Core namespace 2023-02-13 00:50:07 +00:00
Sam Atkins
1568063cc8 LibTLS: Remove declarations for non-existent methods 2023-01-27 20:33:18 +00:00
Tim Schumacher
5061a905ff LibCore: Remove Stream::is_{readable,writable}
Next to functions like `is_eof` these were really confusing to use, and
the `read`/`write` functions should fail anyways if a stream is not
readable/writable.
2022-12-12 14:16:42 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Linus Groh
d26aabff04 Everywhere: Run clang-format 2022-12-03 23:52:23 +00:00
sin-ack
e5f09ea170 Everywhere: Split Error::from_string_literal and Error::from_string_view
Error::from_string_literal now takes direct char const*s, while
Error::from_string_view does what Error::from_string_literal used to do:
taking StringViews. This change will remove the need to insert `sv`
after error strings when returning string literal errors once
StringView(char const*) is removed.

No functional changes.
2022-07-12 23:11:35 +02:00
Michiel Visser
fa18c283dc LibTLS: Cleanup of verify_chain and verify_certificate_pair 2022-04-17 10:10:19 +04:30
Michiel Visser
7bc3b193c0 LibTLS: Add option to allow self-signed certificates
With this option enabled self-signed certificates will be accepted,
eventhough they cannot be verified.
2022-04-17 10:10:19 +04:30
Michiel Visser
d78813d902 LibTLS: Simplify the way verify_chain is called
The `build_rsa_pre_master_secret` function originally called
`verify_chain_and_get_matching_certificate`, which verified the chain
and returned a certificate matching the specified hostname.

Since the first certificate in the chain should always be the one
matching with the hostname, we can simply use that one instead. This
means we can completely remove this method and just use `verify_chain`.

To make sure the hostname is still verified, `verify_chain` now also
checks that the first certificate in the chain matches the specified
hostname. If the hostname is empty, we currently fail the verification,
however this basically never happen, as the server name indication
extension is always used.
2022-04-17 10:10:19 +04:30
Michiel Visser
fea5aeda0b LibTLS: Verify the certificate chain sent by the server
With this change the certificate chain sent by the server will actually
be verified, instead of just checking the names of the certificates.

To determine if a certificate is signed by a root certificate, the list
of root certificates is now a HashMap mapping from the unique identifier
string to the certificate. This allows us to take the issuer of a
certificate and easily check if it is a root certificate. If a
certificate is not signed by a root certificate, we will check that it
is signed by the next certificate in the chain.

This also removes the ad-hoc checking of certificate validity from
multiple places, and moves all checking to the verify_chain.
2022-04-17 10:10:19 +04:30
Sam Atkins
3b1e063d30 LibCore+Everywhere: Make Core::Stream::read() return Bytes
A mistake I've repeatedly made is along these lines:
```c++
auto nread = TRY(source_file->read(buffer));
TRY(destination_file->write(buffer));
```

It's a little clunky to have to create a Bytes or StringView from the
buffer's data pointer and the nread, and easy to forget and just use
the buffer. So, this patch changes the read() function to return a
Bytes of the data that were just read.

The other read_foo() methods will be modified in the same way in
subsequent commits.

Fixes #13687
2022-04-16 13:27:51 -04:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Florent Castelli
e165ae5b60 LibHTTP+LibTLS: Better HTTPS Socket EOF detection
When the server doesn't signal the Content-Length or use a chunked mode,
it may just terminate the connection after sending the data.
The TLS sockets would then get stuck in a state with no data to read and
not reach the disconnected state, making some requests hang.

We know double check the EOF status of HTTP jobs after reading the
payload to resolve requests properly and also mark the TLS sockets as
EOF after processing all the data and the underlying TCP socket reaches
EOF.

Fixes #12866.
2022-03-20 01:01:40 +01:00
Michiel Visser
66d99c83d9 LibCrypto+LibTLS: Add SECP256r1 support to LibTLS
Add the required methods to SECP256r1 to conform to the EllipticCurve
virtual base class. Using this updated version of SECP256r1, support in
LibTLS is implemented.
2022-03-20 00:51:50 +03:30
Michiel Visser
c1b041e761 LibCrypto+LibTLS: Generalize the elliptic curve interface
These changes generalize the interface with an elliptic curve
implementation. This allows LibTLS to support elliptic curves generally
without needing the specifics of elliptic curve implementations.

This should allow for easier addition of other elliptic curves.
2022-03-20 00:51:50 +03:30
stelar7
125a43e203 LibTLS: Add support for curve x448 2022-03-09 13:04:48 +03:30
Michiel Visser
898be38517 LibTLS: Add signature verification for DHE and ECDHE key exchange
This will verify that the signature of the ephemeral key used in the
DHE and ECDHE key exchanges is actually generated by the server.

This verification is done using the first certificate provided by the
server, however the validity of this certificate is not checked here.
Instead this code expects the validity to be checked earlier by
`TLSv12::handle_certificate`.
2022-02-23 13:20:28 +03:30
Michiel Visser
ab84aa6fb2 LibTLS: Add OutOfMemory error that will send an InternalError alert 2022-02-23 13:20:28 +03:30
Michiel Visser
7ab4337721 LibTLS: Add Elliptic Curve Diffie-Hellman Ephemeral (ECDHE) support
This adds support for the Elliptic Curve Diffie-Hellman Ephemeral key
exchange, using the X25519 elliptic curve. This means that the
ECDHE_RSA_WITH_AES_128_GCM_SHA256 and ECDHE_RSA_WITH_AES_256_GCM_SHA384
cipher suites are now supported.

Currently, only the X25519 elliptic curve is supported in combination
with the uncompressed elliptic curve point format. However, since the
X25519 is the recommended curve, basically every server supports this.
Furthermore, the uncompressed point format is required by the TLS
specification, which means any server with EC support will support the
uncompressed format.

Like the implementation of the normal Diffie-Hellman Ephemeral key
exchange, this implementation does not currently validate the signature
of the public key sent by the server.
2022-02-18 15:41:41 +03:30
Ali Mohammad Pur
6f5ab30253 LibTLS: Remove some unused/unimplemented declarations 2022-02-06 13:10:10 +01:00
Ali Mohammad Pur
aafc451016 Userland: Convert TLS::TLSv12 to a Core::Stream::Socket
This commit converts TLS::TLSv12 to a Core::Stream object, and in the
process allows TLS to now wrap other Core::Stream::Socket objects.
As a large part of LibHTTP and LibGemini depend on LibTLS's interface,
this also converts those to support Core::Stream, which leads to a
simplification of LibHTTP (as there's no need to care about the
underlying socket type anymore).
Note that RequestServer now controls the TLS socket options, which is a
better place anyway, as RS is the first receiver of the user-requested
options (though this is currently not particularly useful).
2022-02-06 13:10:10 +01:00
mjz19910
3102d8e160 Everywhere: Fix many spelling errors 2022-01-07 10:56:59 +01: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
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