Commit graph

203 commits

Author SHA1 Message Date
circl
9f7f6aa80c LibTLS: Remove key-logging debug feature
This attempted to save data into /home/anon even on Linux
2024-06-24 09:45:41 -06:00
circl
c169e43e13 Userland: Remove some SerenityOS checks 2024-06-10 13:53:01 +02:00
Andreas Kling
fce4739d3e LibTLS: Put debug spam about loaded certificates behind TLS_DEBUG 2024-06-05 07:11:34 +02:00
Ali Mohammad Pur
57714fbb38 RequestServer: Handle IPC requests on multiple threads concurrently
Previously RS handled all the requests in an event loop, leading to
issues with connections being started in the middle of other connections
being started (and potentially blowing up the stack), ultimately causing
requests to be delayed because of other requests.
This commit reworks the way we handle these (specifically starting
connections) by first serialising the requests, and then performing them
in multiple threads concurrently; which yields a significant loading
performance and reliability increase.
2024-05-20 08:03:35 +02:00
Ali Mohammad Pur
06d522f017 LibTLS: Clear connected/error callbacks before leaving connect()
Otherwise error events will call into our setup code, eventually leading
to a UAF.
2024-05-20 08:03:35 +02:00
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
Dan Klishch
5ed7cd6e32 Everywhere: Use east const in more places
These changes are compatible with clang-format 16 and will be mandatory
when we eventually bump clang-format version. So, since there are no
real downsides, let's commit them now.
2024-04-19 06:31:19 -04:00
Ali Mohammad Pur
06386ab2b5 LibTLS+LibHTTP: Tolerate improperly closed TLS sockets
Some really cursed servers simply drop the TCP socket on the floor when
they're trying to close an HTTP connection going through a TLS socket.
This commit makes LibTLS tolerate these silly servers, and LibHTTP
accept their idea of "EOF == connection closed".

Fixes loading wpt.live/acid/acid3/test.html.

Note that this means TLSv12::on_ready_to_read can fire with an empty
buffer signifying EOF; one test refused this behaviour, and has been
changed in this commit.
2024-04-17 07:19:03 +02:00
Andreas Kling
1cb5385a29 LibCore: Stop obsessing about tiny OOMs in Core::Timer
Work towards #20405
2024-04-17 07:16:52 +02:00
Timothy Flynn
c23060e21b Userland: Avoid some now-unneeded explicit conversions to Bytes 2024-04-04 11:23:21 +02:00
Andrew Kaster
562068e001 LibTLS: Implement ASN.1 parser function for PrivateKeyInfo
LibWeb wants to parse these for Web Crypto. In theory Certificate
parsing in LibTLS should use it as well.
2024-03-25 17:01:23 -06:00
Andrew Kaster
7b27c1ce6c LibTLS: Export parse_subject_public_key_info
LibWeb wants to call this for Web Crypto.
2024-03-25 17:01:23 -06:00
Ali Mohammad Pur
e2bab93fdd LibTLS: Avoid using new event loops when setting up connections
This was causing some racey behaviour in LibHTTP, and just generally
lead to really bad stack traces; avoid that by switching to
Core::Promise and using the existing event loop.

Possibly resolves #23524 and #23642.
2024-03-22 18:27:53 +01:00
Ali Mohammad Pur
0994aa91dc LibCrypto: Remove unused Crypto::PK::EMSA_PSS class
This is not used, and its implementation is not actually correct
regardless.
2024-03-16 01:17:02 -06:00
Timothy Flynn
928287b782 LibCrypto: Store ASN1 certificate timestamps as UnixDateTime
We are currently using Core::DateTime, which is meant to represent local
time. However, we are doing no conversion between the parsed time in UTC
and local time, so we end up comparing time stamps from different time
zones.

Instead, store the parsed times as UnixDateTime, which is UTC. Then we
can always compare the parsed times against the current UTC time.

This also lets us store parsed milliseconds.
2024-03-08 00:41:23 +01:00
Hendiadyoin1
e1c663ba27 LibTLS: Move Strings when creating RelativeDistinguishedNames
Also cleans up the organizational_unit() helper to use `value_or({})`
instead of doing the same thing manually.
2024-03-01 14:05:53 -07:00
Hendiadyoin1
f7329f89aa LibTLS: Prefer structured bindings when iterating over HashMaps 2024-03-01 14:05:53 -07:00
Andrew Kaster
080aa567a5 RequestServer+LibTLS: Allow applications to specify multiple root certs 2024-02-08 08:49:32 -07:00
Ali Mohammad Pur
c3167afa3a LibTLS: Notify the client for app data as soon as some data is available
Previously we were waiting until the socket was no longer immediately
readable to notify the client, resulting in large buffers and longer
latency.
2024-01-03 14:59:59 +01: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
495b0f2bcc LibTLS: Improve message when root certificate is invalid
Currently there is one root certificate which has expired, but it does
not have a common name, so we are simply printing "Certificate for  by
is invalid, ...", which is less than useful. Instead we just print the
complete subject now, and remove printing the issuer, as root
certificates are always self-signed.
2023-11-29 18:17:14 +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
bc9cdd4394 LibCrypto+LibTLS: Switch to the generic SECPxxxr1 implementation 2023-11-27 09:43:07 +03:30
Michiel Visser
e785172290 LibTLS: Implement the extended_master_secret TLS extension 2023-11-27 09:37:25 +03:30
Michiel Visser
5ab64320b2 LibTLS: Compute the master secret in a single place
Before we were computing the master secret in the different
`build_*_pre_master_secret` methods, but this can be simplified to a
single call.
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
Andrew Kaster
baa26d10a8 LibTLS: Retry sending in TLSv12::flush() on EAGAIN or EINTR
Crashing here is not very helpful.
2023-10-31 00:36:51 +03:30
Andrew Kaster
f9386737a6 LibTLS: Add certificate verification for ECDSA with SECP256r1 curves 2023-10-30 10:17:39 -06:00
Michiel Visser
c548dca174 LibTLS: Add ECDSA support with the secp256r1 curve 2023-10-30 10:17:39 -06:00
Ali Mohammad Pur
aeee98b3a1 AK+Everywhere: Remove the null state of DeprecatedString
This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
2023-10-13 18:33:21 +03:30
Tim Ledbetter
e6d9bb0774 LibTLS: Don't attempt to read past EOF when parsing TBSCertificate
This allows the decoder to fail gracefully when reading a partial or
malformed TBSCertificate. We also now ensure that the certificate data
is valid before making a copy of it.
2023-10-11 07:08:22 +02:00
stelar7
42d80aab06 LibTLS: Reorder supported ciphers 2023-10-06 22:32:07 +02:00
Andrew Kaster
28d3d3c9fc LibTLS: Allow applications to provide a custom default CA Cert path
On Lagom, we also need to allow the initial load of /etc/cacert.pem to
fail.
2023-08-02 05:44:43 +02:00
Andrew Kaster
6266976e7a LibTLS: Move singleton for DefaultRootCACertificates out of line
This follows the pattern of every other singleton in the system.

Also, remove use of AK::Singleton in place of a function-scope static.
There are only three uses of that class outside of the Kernel, and all
the remaining uses are suspect. We need it in the Kernel because we
want to avoid global destructors to prevent nasty surprises about
expected lifetimes of objects. In Userland, we have normal thread-safe
statics available. 7d11edbe1 attempted to standardize the pattern, but
it seems like more uses of awkward singleton creation have crept in or
were missed back then.

As a bonus, this fixes a linker error on macOS with -g -O0 for Lagom
WebContent.
2023-07-26 05:34:38 +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
0fc73679f1 LibTLS: Fix typo in ecdsa_sha512 OID 2023-07-02 16:13:37 +02:00
stelar7
77080fbade LibTLS: Rename parse_version to parse_certificate_version
This is not a generic version, but specifically for certificates.
2023-07-02 16:13:37 +02:00
Ben Wiederhake
2bb2a7097d LibTLS: Avoid unnecessary HashMap copies, improve const-correctness 2023-05-19 22:33:57 +02:00
Ben Wiederhake
ac5cef1b66 LibCrypto+LibTLS: Avoid crashing on invalid input
Fixes #18307.
2023-05-08 06:43:28 +02:00
stelar7
2d2d2539b4 LibTLS: Use the TBS ASN.1 data when verifying certificates 2023-05-05 09:36:43 +03:30
stelar7
0b70314379 LibCrypto: Store the TBS ASN.1 data on the certificate
This way we dont need to guess the offsets in LibTLS when using it.
2023-05-05 09:36:43 +03:30
Ali Mohammad Pur
7e6341587b AK+Everywhere: Disallow Error::from_string_view(FooString)
That pattern seems to show up a lot in code written by people that
aren't intimately familiar with the lifetime model of Error and Strings.
This commit makes the compiler detect it and present a more helpful
diagnostic than "garbage string at runtime".
2023-04-28 05:55:20 +02:00
stelar7
4043c89310 LibTLS: Change CertificateKeyAlgorithm from enum to struct 2023-04-15 09:03:47 +03:30
stelar7
e59137d4f6 LibTLS: Add RFC explanation of AlertDescription values 2023-04-14 12:32:04 +01:00
stelar7
9059694216 LibTLS: Show enum value instead of underlying value where possible 2023-04-14 12:32:04 +01: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