Commit Graph

51 Commits

Author SHA1 Message Date
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
Ali Mohammad Pur
38418fdfdf AK+Userland: Use mpfard@serenityos.org for my copyright headers 2021-04-22 22:19:09 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
AnotherTest
38f4441103 LibTLS: Parse X.509 certificates with the new ASN.1 parser
As a nice side effect, also correctly test for certificate validity :^)
2021-04-18 14:18:16 +02:00
Jelle Raaijmakers
f733b85957 LibTLS: Remove excessive CloseNotify logging 2021-04-10 21:05:00 +02:00
Jelle Raaijmakers
55d9f36dae LibTLS: Convert some #ifs to dbgln_if() 2021-04-10 14:45:14 +02:00
Jelle Raaijmakers
7d5995f08c LibTLS: Support empty SNI data in ServerHello
According to RFC6066, empty extension_data for an SNI extension is
absolutely one of the possibilities - so let's support this instead of
spamming the debug log.
2021-04-10 14:45:14 +02:00
Linus Groh
57c6264877 LibTLS: Hide some debug spam, use more dbgln_if and if constexpr
The debug console was full of 'Update hash with message of size x'.
2021-04-07 19:21:26 +02:00
AnotherTest
2020176f0f LibTLS: Make the TLS connection options user-configurable
The user may now request specific cipher suites, the use of SNI, and
whether we should validate certificates (not that we're doing a good job
of that).
2021-04-03 11:22:01 +02:00
AnotherTest
b5f24c84e4 LibTLS: Remove long-outdated comment that no longer makes sense 2021-04-03 11:22:01 +02:00
AnotherTest
d6d6750dd8 LibTLS: Move TLS extensions to a separate 'extensions' struct
This has no behavioural effect.
2021-04-03 11:22:01 +02:00
Andreas Kling
ef1e5db1d0 Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)
Good-bye LogStream. Long live AK::Format!
2021-03-12 17:29:37 +01:00
Linus Groh
e265054c12 Everywhere: Remove a bunch of redundant 'AK::' namespace prefixes
This is basically just for consistency, it's quite strange to see
multiple AK container types next to each other, some with and some
without the namespace prefix - we're 'using AK::Foo;' a lot and should
leverage that. :^)
2021-02-26 16:59:56 +01:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
b1a705d7d8 LibTLS: Replace dbgprintf() with dbgln() 2021-02-20 17:06:39 +01:00
AnotherTest
3fe7ac0924 LibCrypto: Make a better ASN.1 parser
And use it to parse RSA keys.
As a bonus, this one shouldn't be reading out of bounds or messing with
the stack (as much) anymore.
2021-02-14 13:30:10 +01:00
AnotherTest
09a43969ba Everywhere: Replace dbgln<flag>(...) with dbgln_if(flag, ...)
Replacement made by `find Kernel Userland -name '*.h' -o -name '*.cpp' | sed -i -Ee 's/dbgln\b<(\w+)>\(/dbgln_if(\1, /g'`
2021-02-08 18:08:55 +01:00
asynts
8465683dcf Everywhere: Debug macros instead of constexpr.
This was done with the following script:

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/dbgln<debug_([a-z_]+)>/dbgln<\U\1_DEBUG>/' {} \;

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/if constexpr \(debug_([a-z0-9_]+)/if constexpr \(\U\1_DEBUG/' {} \;
2021-01-25 09:47:36 +01:00
asynts
1a3a0836c0 Everywhere: Use CMake to generate AK/Debug.h.
This was done with the help of several scripts, I dump them here to
easily find them later:

    awk '/#ifdef/ { print "#cmakedefine01 "$2 }' AK/Debug.h.in

    for debug_macro in $(awk '/#ifdef/ { print $2 }' AK/Debug.h.in)
    do
        find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/#ifdef '$debug_macro'/#if '$debug_macro'/' {} \;
    done

    # Remember to remove WRAPPER_GERNERATOR_DEBUG from the list.
    awk '/#cmake/ { print "set("$2" ON)" }' AK/Debug.h.in
2021-01-25 09:47:36 +01:00
asynts
7d783d8b84 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.
2021-01-22 22:14:30 +01:00
asynts
5c5665c1e7 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.
2021-01-22 22:14:30 +01:00
asynts
6b7602d33b 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.
2021-01-16 11:54:35 +01:00
asynts
01879d27c2 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.
2021-01-16 11:54:35 +01:00