-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "LibTLS+Everywhere: Switch to using WolfSSL"
This reverts commit 8bb610b. Linking wolfSSL seems to cause more legal trouble than it's worth due to it being GPLv2, so let's undo this for now.
- Loading branch information
Showing
28 changed files
with
3,944 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
set(TEST_SOURCES | ||
TestTLSCertificateParser.cpp | ||
TestTLSHandshake.cpp | ||
) | ||
|
||
foreach(source IN LISTS TEST_SOURCES) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (c) 2021, Peter Bocan <me@pbocan.net> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include <AK/Base64.h> | ||
#include <LibCore/ConfigFile.h> | ||
#include <LibCore/EventLoop.h> | ||
#include <LibCrypto/ASN1/ASN1.h> | ||
#include <LibCrypto/ASN1/PEM.h> | ||
#include <LibFileSystem/FileSystem.h> | ||
#include <LibTLS/TLSv12.h> | ||
#include <LibTest/TestCase.h> | ||
|
||
static StringView ca_certs_file = "./cacert.pem"sv; | ||
static int port = 443; | ||
|
||
constexpr auto DEFAULT_SERVER = "www.google.com"sv; | ||
|
||
static ByteBuffer operator""_b(char const* string, size_t length) | ||
{ | ||
return ByteBuffer::copy(string, length).release_value(); | ||
} | ||
|
||
ErrorOr<Vector<Certificate>> load_certificates(); | ||
ByteString locate_ca_certs_file(); | ||
|
||
ByteString locate_ca_certs_file() | ||
{ | ||
if (FileSystem::exists(ca_certs_file)) { | ||
return ca_certs_file; | ||
} | ||
auto on_target_path = ByteString("/etc/cacert.pem"); | ||
if (FileSystem::exists(on_target_path)) { | ||
return on_target_path; | ||
} | ||
return ""; | ||
} | ||
|
||
ErrorOr<Vector<Certificate>> load_certificates() | ||
{ | ||
auto cacert_file = TRY(Core::File::open(locate_ca_certs_file(), Core::File::OpenMode::Read)); | ||
auto data = TRY(cacert_file->read_until_eof()); | ||
return TRY(DefaultRootCACertificates::parse_pem_root_certificate_authorities(data)); | ||
} | ||
|
||
TEST_CASE(test_TLS_hello_handshake) | ||
{ | ||
Core::EventLoop loop; | ||
TLS::Options options; | ||
options.set_root_certificates(TRY_OR_FAIL(load_certificates())); | ||
options.set_alert_handler([&](TLS::AlertDescription) { | ||
FAIL("Connection failure"); | ||
loop.quit(1); | ||
}); | ||
options.set_finish_callback([&] { | ||
loop.quit(0); | ||
}); | ||
|
||
auto tls = TRY_OR_FAIL(TLS::TLSv12::connect(DEFAULT_SERVER, port, move(options))); | ||
ByteBuffer contents; | ||
tls->on_ready_to_read = [&] { | ||
(void)TRY_OR_FAIL(tls->read_some(contents.must_get_bytes_for_writing(4 * KiB))); | ||
loop.quit(0); | ||
}; | ||
|
||
if (tls->write_until_depleted("GET / HTTP/1.1\r\nHost: "_b).is_error()) { | ||
FAIL("write(0) failed"); | ||
return; | ||
} | ||
|
||
auto the_server = DEFAULT_SERVER; | ||
if (tls->write_until_depleted(the_server.bytes()).is_error()) { | ||
FAIL("write(1) failed"); | ||
return; | ||
} | ||
if (tls->write_until_depleted("\r\nConnection : close\r\n\r\n"_b).is_error()) { | ||
FAIL("write(2) failed"); | ||
return; | ||
} | ||
|
||
loop.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2020, Ali Mohammad Pur <mpfard@serenityos.org> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <AK/Types.h> | ||
#include <LibTLS/Extensions.h> | ||
|
||
namespace TLS { | ||
|
||
// Defined in RFC 5246 section 7.4.1.4.1 | ||
struct SignatureAndHashAlgorithm { | ||
HashAlgorithm hash; | ||
SignatureAlgorithm signature; | ||
}; | ||
|
||
enum class KeyExchangeAlgorithm { | ||
Invalid, | ||
// Defined in RFC 5246 section 7.4.2 / RFC 4279 section 4 | ||
RSA_PSK, | ||
// Defined in RFC 5246 section 7.4.3 | ||
DHE_DSS, | ||
DHE_RSA, | ||
DH_anon, | ||
RSA, | ||
DH_DSS, | ||
DH_RSA, | ||
// Defined in RFC 4492 section 2 | ||
ECDHE_RSA, | ||
ECDH_ECDSA, | ||
ECDH_RSA, | ||
ECDHE_ECDSA, | ||
ECDH_anon, | ||
}; | ||
|
||
// Defined in RFC 5246 section 7.4.1.4.1 | ||
constexpr SignatureAlgorithm signature_for_key_exchange_algorithm(KeyExchangeAlgorithm algorithm) | ||
{ | ||
switch (algorithm) { | ||
case KeyExchangeAlgorithm::RSA: | ||
case KeyExchangeAlgorithm::DHE_RSA: | ||
case KeyExchangeAlgorithm::DH_RSA: | ||
case KeyExchangeAlgorithm::RSA_PSK: | ||
case KeyExchangeAlgorithm::ECDH_RSA: | ||
case KeyExchangeAlgorithm::ECDHE_RSA: | ||
return SignatureAlgorithm::RSA; | ||
case KeyExchangeAlgorithm::DHE_DSS: | ||
case KeyExchangeAlgorithm::DH_DSS: | ||
return SignatureAlgorithm::DSA; | ||
case KeyExchangeAlgorithm::ECDH_ECDSA: | ||
case KeyExchangeAlgorithm::ECDHE_ECDSA: | ||
return SignatureAlgorithm::ECDSA; | ||
case KeyExchangeAlgorithm::DH_anon: | ||
case KeyExchangeAlgorithm::ECDH_anon: | ||
default: | ||
return SignatureAlgorithm::ANONYMOUS; | ||
} | ||
} | ||
|
||
enum class CipherAlgorithm { | ||
Invalid, | ||
AES_128_CBC, | ||
AES_128_GCM, | ||
AES_128_CCM, | ||
AES_128_CCM_8, | ||
AES_256_CBC, | ||
AES_256_GCM, | ||
}; | ||
|
||
constexpr size_t cipher_key_size(CipherAlgorithm algorithm) | ||
{ | ||
switch (algorithm) { | ||
case CipherAlgorithm::AES_128_CBC: | ||
case CipherAlgorithm::AES_128_GCM: | ||
case CipherAlgorithm::AES_128_CCM: | ||
case CipherAlgorithm::AES_128_CCM_8: | ||
return 128; | ||
case CipherAlgorithm::AES_256_CBC: | ||
case CipherAlgorithm::AES_256_GCM: | ||
return 256; | ||
case CipherAlgorithm::Invalid: | ||
default: | ||
return 0; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.