Commit graph

77 commits

Author SHA1 Message Date
Timothy Flynn
27478ec7d4 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-19 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")
2024-12-28 05:39:32 -08:00
rmg-x
e222ccf028 LibTLS: Use Crypto::fill_with_secure_random instead of PRNG 2024-12-24 17:54:52 +01:00
devgianlu
89061dd3c4 LibCrypto: Replace all hashes implementation with OpenSSL
This required multiple changes:
- Make hashes non-copiable because they contain a heap allocated pointer
- Reference classes via `NonnullOwnPtr` only (they are non-copiable)
- Drop all existing hashes implementations
- Use the `OpenSSLHashFunction` base class to implement the same hashes

I was not able to come up with a way to divide this commit into multiple
without increasing the amount of changes.

Nothing breaks with this commit!
2024-12-22 18:53:45 +01:00
Pavel Shliak
fa02d94d30 LibTLS: Remove unreachable buffer length check
Refer to the while condition
2024-12-22 12:33:41 +01:00
stasoid
15a96e841b Meta: Make pthread and mman available for all libraries on Windows
by default
2024-12-18 05:55:58 +01:00
devgianlu
1ae28324bd LibCrypto: Accept correct IV sizes for AES-GCM
AES-GCM should accept 96-bits keys as is. Any other key should be
preprocessed with GHASH.
2024-12-16 13:27:53 +01:00
devgianlu
ec990d620f LibCrypto: Cleanup Crypto::PK::RSA constructors to avoid pitfalls
- Removed the constructor taking a (n, d, e) tuple and moved
  it to `RSAPrivateKey`
- Removed default constructor with key generation because it was always
  misused and the default key size is quite small
- Added utility constructors to accept a key pair, public key, private
  key or both
- Made constructor parameters const
- Updated test to use generated random keys where possible
2024-12-15 23:31:49 +01:00
stasoid
8ac5424f3a LibTLS: Port to Windows 2024-12-15 08:20:16 +01:00
devgianlu
9240d38273 LibCrypto+LibTLS+LibWeb: Store EC key size + refactor serialization
In order for public/private key serialization to work correctly we must
store the size of the key because P-521 cannot be stored as full words
inside `UnsignedBigInteger` and therefore is exported as the wrong
length (68 instead of 66).

This makes it also possible to refactor some methods and cleanup
constants scattered around.

Gets almost all import/export tests, expect the JWK ones that calculate
the public key on export. The `SECPxxxr1` implementation currently fails
to do calculations for P-521.
2024-12-14 01:52:16 +01:00
devgianlu
27fbcf70bf LibTLS: Parse SECP256r1 parameters separately 2024-12-07 19:08:40 +01:00
devgianlu
57ecd72256 LibCrypto: Return PEM type when decoding and sanity check footer
Improve PEM decoding by parsing the header and returning it along the
data. Also verify if the header is equal to the footer.
2024-11-30 11:17:44 +01:00
devgianlu
51f69be51f LibCrypto: Move ASN1 constants to Crypto::ASN1
Makes more sense to have them in `Crypto::ASN1` rather than in
`Crypto::Certificate`.
2024-11-30 11:17:44 +01:00
devgianlu
ab2960e49f LibCrypto+LibWeb: Reorganize OID ASN1 constants
I have divided ANS1 constants by length so that they don't have
trailing zeros that need to be removed.

Also moved OIDs lists to the only place they are used for clarity.

Fixed a couple of WPT tests by adding SECP521r1 to the list of known
curves.
2024-11-30 11:17:44 +01:00
devgianlu
49c388b891 LibTLS+LibWeb+LibCrypto: Move Certificate to LibCrypto
By moving `Certificate` to `LibCrypto` it is possible to reuse a bunch
of code from in `LibCrypto` itself. It also moves some constants
and pieces of code to a more appropriate place than `LibTLS`.

This also makes future work on WebCryptoAPI easier.
2024-11-25 13:38:38 +01:00
devgianlu
fcdcba51f5 LibTLS+LibWeb: Decouple EC parameters from TLS::SupportedGroup
This is in preparation of the next commits to split the changes.
2024-11-25 13:38:38 +01:00
devgianlu
32a90a7fd1 LibTLS: Move some Certificate methods to the correct file
The implementation of `Certificate::is_valid` and
`Certificate::is_self_signed` were in `TLSv12.cpp` and they have been
moved to `Certificate.cpp`.

This is in preparation of the next commits to split the changes.
2024-11-25 13:38:38 +01:00
devgianlu
e42410a7a7 LibTLS: Move DefaultRootCACertificates to correct header file
The declaration of `DefaultRootCACertificates` was in `Certificate.h`
and its implementation in `TLSv12.cpp`. It has been moved over
to `TLSv12.h` for consistency.

This is in preparation of the next commits to split the changes.
2024-11-25 13:38:38 +01:00
Andreas Kling
4d25369f29 LibWeb: Implement the importKey algorithm for Ed25519 2024-11-24 23:28:23 +01:00
Ali Mohammad Pur
e5ff572d73 LibTLS: Change connection state to disconnected after server CloseNotify
Prior to this commit LibTLS closed the connection but did not consider
it terminated after receiving and acknowledging a CloseNotify from the
server, which led to hangs in DoT (and possibly other users).
2024-11-24 22:33:58 +01:00
Pavel Shliak
8d13115d9a LibCrypto: Clean up #include directives
This change aims to improve the speed of incremental builds.
2024-11-21 14:08:33 +01:00
Ali Mohammad Pur
d704b61066 LibCore+LibTLS: Add an API for connect()'ing 'with hostname
This just unifies the API for all three sockets (UDP, TCP and TLS)
2024-11-20 21:37:58 +01:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
asynts
6fa42af567 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.

The modifications in this commit were automatically made using the
following command:

    find . -name '*.h' -exec sed -i -E 's/dbg\(\) << ("[^"{]*");/dbgln\(\1\);/' {} \;
2021-01-11 21:49:29 +01:00
Lenny Maiorani
f99d1d3bd7 Vector: Implement find, find_if, find_first_matching in terms of AK::find*
Problem:
- The implementation of `find` is coupled to the implementation of `Vector`.
- `Vector::find` takes the predicate by value which might be expensive.

Solution:
- Decouple the implementation of `find` from `Vector` by using a
  generic `find` algorithm.
- Change the name of `find` with a predicate to `find_if` so that a
  binding reference can be used and the predicate can be forwarded to
  avoid copies.
- Change all the `find(pred)` call sites to use `find_if`.
2021-01-11 19:45:05 +01:00
asynts
938e5c7719 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.Everything:

The modifications in this commit were automatically made using the
following command:

    find . -name '*.cpp' -exec sed -i -E 's/dbg\(\) << ("[^"{]*");/dbgln\(\1\);/' {} \;
2021-01-09 21:11:09 +01:00
Andreas Kling
3be9a9ac76 LibTLS: Fix TLS breakage after ByteBuffer => Span conversion
Oops, I accidentally shadowed the outer scope's "decrypted" ByteBuffer
which caused us to throw away the buffer too early.

Fixes #4533.
2020-12-26 16:09:02 +01:00
Andreas Kling
b30acdb4b7 LibTLS+Userland: Remove all uses of ByteBuffer::slice_view()
This was another way to get a non-owning ByteBuffer wrapper.
2020-12-19 18:29:13 +01:00
Andreas Kling
d5600e966a LibTLS+LibCrypto: Remove all remaining uses of ByteBuffer::wrap() 2020-12-19 18:29:13 +01:00
Andreas Kling
e517505e35 LibTLS: Even more ByteBuffer -> Span conversion 2020-12-19 18:29:13 +01:00
Andreas Kling
f82b0a78ef LibTLS+LibCrypto: More ByteBuffer -> Span conversion 2020-12-19 18:29:13 +01:00
Andreas Kling
8e20208dd6 LibTLS+LibCrypto: Replace a whole bunch of ByteBuffers with Spans 2020-12-19 18:29:13 +01:00
AnotherTest
dbfce38c90 LibTLS: Read subjectAltName from certificates and use it
As quite a few certificates use this extension, reading and using it to
find matching certificates is fairly useful :^)
2020-12-13 20:24:58 +01:00
Andreas Kling
986ce57be9 LibTLS: TLSv12::read_line() should chomp result string
Match the Core::IODevice::read_line() API change and return a chomped
string from here as well.
2020-12-13 18:19:32 +01:00
Andreas Kling
b9b7b2b28a LibCore: Make IODevice::read_line() return a String
Almost everyone using this API actually wanted String instead of a
ByteBuffer anyway, and there were a bunch of slightly different ways
clients would convert to String.

Let's just cut out all the confusion and make it return String. :^)
2020-12-13 11:54:11 +01:00
AnotherTest
de4061ff94 LibTLS: Count the mac size towards the packet length in CBC mode
This is a regression introduced in 1172746, where the padding would be
done without accounting for the added MAC bytes.
Fixes #4098.
2020-11-16 13:21:18 +01:00
AnotherTest
1172746633 LibTLS: Add support for AEAD cipher suites
And integrate AES-GCM.
2020-11-14 10:18:54 +01:00
AnotherTest
37c089fb7b LibTLS: (Almost) verify certificate chain against root CA certificates
Also adds a very primitive systemwide ca_certs.ini file.
2020-10-30 23:42:03 +01:00
AnotherTest
1746e6f9ca LibTLS: Also read out the Organisational Unit from the certificate
This needs to be read out if we want to actually verify the cert chain.
2020-10-30 23:42:03 +01:00
AnotherTest
a2186fd64a LibTLS: Move out Certificate to its own header file 2020-10-30 23:42:03 +01:00
Luke
63a94deb43 LibTLS: Treat a close_notify before agreeing on a cipher suite as a handshake failure
Some TLS implementations (namely, AWS CloudFront) do this instead of
sending handshake_failure for some reason.
2020-10-26 08:59:57 +01:00
Nico Weber
ef1b21004f Everywhere: Fix typos
Mostly in comments, but sprintf() now prints "August" instead of
"Auguest" so that's something.
2020-10-02 16:03:17 +02:00
asynts
10c6f062b3 AK: Add Endian.h header to replace NetworkOrdered.h. 2020-08-25 16:22:14 +02:00
Nico Weber
8b166e57df
Misc: Remove some unneeded includes of Timer.h and ElapsedTimer.h (#3286) 2020-08-25 09:41:56 +02:00
AnotherTest
abb842ee5a LibTLS: Fix some debug logging 2020-08-24 09:29:39 +02:00
AnotherTest
0be3937be7 LibTLS: Do not process_message() the finished message twice
With two different sequence numbers to boot!
Fixes #3273
2020-08-24 09:29:39 +02:00
Ben Wiederhake
2a2630edc9 Meta: Fix wrong 'using namespace X' usages
Apart from causing All AK:: and Crypto:: symbols being suddenly visible even though
they might not be supposed to be, the style guide also says this is wrong:

https://github.com/SerenityOS/serenity/blob/master/Documentation/CodingStyle.md#using-statements
2020-08-23 00:53:16 +02:00
asynts
fff581cd72 AK: Rename span() to bytes() when appropriate.
I originally defined the bytes() method for the String class, because it
made it obvious that it's a span of bytes instead of span of characters.

This commit makes this more consistent by defining a bytes() method when
the type of the span is known to be u8.

Additionaly, the cast operator to Bytes is overloaded for ByteBuffer and
such.
2020-08-15 21:21:18 +02:00
Ali Mohammad Pur
d1571ce00a LibTLS: Re-silence a debug log
bc7a149039 (r41386045)
2020-08-12 10:59:06 +02:00
AnotherTest
880b0a7600 LibTLS: Avoid extra initialisation of buffers that are initialised
A trace for proof:
buffer:

    L91: 0:(packet.size() - header_size)
    L98: (packet.size() - header_size):(packet.size() - header_size + mac_size)
    L102: (packet.size() - header_size + mac_size):buffer.size()
    (asserted at L103)

ct:

    L88: 0:(header_size - 2)
    L123: (header_size - 2):(header_size)
    L111: (header_size):(header_size + iv_size)
    L117: (header_size + iv_size):(header_size + iv_size + length)
    (asserted at L113)
2020-08-11 21:37:10 +02:00