Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions builds/gnu/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ src_libbitcoin_network_la_SOURCES = \
${srcdir}/../../src/tls/schedule.cpp \
${srcdir}/../../src/tls/server.cpp \
${srcdir}/../../src/tls/stream.cpp \
${srcdir}/../../src/tor/cell.cpp \
${srcdir}/../../src/tor/certificate.cpp \
${srcdir}/../../src/tor/link.cpp \
${srcdir}/../../src/ws/frame.cpp \
${srcdir}/../../src/ws/handshake.cpp \
${srcdir}/../../src/ws/reader.cpp \
Expand Down Expand Up @@ -601,6 +604,16 @@ include_bitcoin_network_tls_HEADERS = \
${srcdir}/../../include/bitcoin/network/tls/stream.hpp \
${srcdir}/../../include/bitcoin/network/tls/tls.hpp

include_bitcoin_network_tordir = \
${includedir}/bitcoin/network/tor

include_bitcoin_network_tor_HEADERS = \
${srcdir}/../../include/bitcoin/network/tor/cell.hpp \
${srcdir}/../../include/bitcoin/network/tor/certificate.hpp \
${srcdir}/../../include/bitcoin/network/tor/constants.hpp \
${srcdir}/../../include/bitcoin/network/tor/link.hpp \
${srcdir}/../../include/bitcoin/network/tor/tor.hpp

include_bitcoin_network_wsdir = \
${includedir}/bitcoin/network/ws

Expand Down Expand Up @@ -795,6 +808,9 @@ test_libbitcoin_network_test_SOURCES = \
${srcdir}/../../test/tls/server.cpp \
${srcdir}/../../test/tls/server_hello.cpp \
${srcdir}/../../test/tls/socket.cpp \
${srcdir}/../../test/tor/cell.cpp \
${srcdir}/../../test/tor/certificate.cpp \
${srcdir}/../../test/tor/link.cpp \
${srcdir}/../../test/ws/frame.cpp \
${srcdir}/../../test/ws/handshake.cpp \
${srcdir}/../../test/ws/reader.cpp \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@
<ClCompile Include="..\..\..\..\test\tls\socket.cpp">
<ObjectFileName>$(IntDir)test_tls_socket.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\..\..\test\tor\cell.cpp" />
<ClCompile Include="..\..\..\..\test\tor\certificate.cpp" />
<ClCompile Include="..\..\..\..\test\tor\link.cpp" />
<ClCompile Include="..\..\..\..\test\ws\frame.cpp" />
<ClCompile Include="..\..\..\..\test\ws\handshake.cpp" />
<ClCompile Include="..\..\..\..\test\ws\reader.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@
<Filter Include="src\tls">
<UniqueIdentifier>{D28FC18A-8B81-4247-0000-000000000006}</UniqueIdentifier>
</Filter>
<Filter Include="src\ws">
<Filter Include="src\tor">
<UniqueIdentifier>{D28FC18A-8B81-4247-0000-000000000007}</UniqueIdentifier>
</Filter>
<Filter Include="src\zmtp">
<Filter Include="src\ws">
<UniqueIdentifier>{D28FC18A-8B81-4247-0000-000000000008}</UniqueIdentifier>
</Filter>
<Filter Include="src\zmtp">
<UniqueIdentifier>{D28FC18A-8B81-4247-0000-000000000009}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\test\async\desubscriber.cpp">
Expand Down Expand Up @@ -537,6 +540,15 @@
<ClCompile Include="..\..\..\..\test\tls\socket.cpp">
<Filter>src\tls</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\tor\cell.cpp">
<Filter>src\tor</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\tor\certificate.cpp">
<Filter>src\tor</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\tor\link.cpp">
<Filter>src\tor</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\ws\frame.cpp">
<Filter>src\ws</Filter>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@
<ClCompile Include="..\..\..\..\src\tls\stream.cpp">
<ObjectFileName>$(IntDir)src_tls_stream.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\..\..\src\tor\cell.cpp" />
<ClCompile Include="..\..\..\..\src\tor\certificate.cpp" />
<ClCompile Include="..\..\..\..\src\tor\link.cpp" />
<ClCompile Include="..\..\..\..\src\ws\frame.cpp" />
<ClCompile Include="..\..\..\..\src\ws\handshake.cpp" />
<ClCompile Include="..\..\..\..\src\ws\reader.cpp" />
Expand Down Expand Up @@ -489,6 +492,11 @@
<ClInclude Include="..\..\..\..\include\bitcoin\network\tls\server.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\tls\stream.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\tls\tls.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\tor\cell.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\tor\certificate.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\tor\constants.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\tor\link.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\tor\tor.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\ws\client.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\ws\frame.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\ws\handshake.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,72 +112,78 @@
<Filter Include="include\bitcoin\network\tls">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000004}</UniqueIdentifier>
</Filter>
<Filter Include="include\bitcoin\network\ws">
<Filter Include="include\bitcoin\network\tor">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000005}</UniqueIdentifier>
</Filter>
<Filter Include="include\bitcoin\network\zmtp">
<Filter Include="include\bitcoin\network\ws">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000006}</UniqueIdentifier>
</Filter>
<Filter Include="src">
<Filter Include="include\bitcoin\network\zmtp">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000007}</UniqueIdentifier>
</Filter>
<Filter Include="src\async">
<Filter Include="src">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000008}</UniqueIdentifier>
</Filter>
<Filter Include="src\broadcast">
<Filter Include="src\async">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000009}</UniqueIdentifier>
</Filter>
<Filter Include="src\channels">
<Filter Include="src\broadcast">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000010}</UniqueIdentifier>
</Filter>
<Filter Include="src\config">
<Filter Include="src\channels">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000011}</UniqueIdentifier>
</Filter>
<Filter Include="src\io">
<Filter Include="src\config">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-0000000000A2}</UniqueIdentifier>
</Filter>
<Filter Include="src\log">
<Filter Include="src\io">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-0000000000B2}</UniqueIdentifier>
</Filter>
<Filter Include="src\messages">
<Filter Include="src\log">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-0000000000C2}</UniqueIdentifier>
</Filter>
<Filter Include="src\messages\http">
<Filter Include="src\messages">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-0000000000D2}</UniqueIdentifier>
</Filter>
<Filter Include="src\messages\http\enums">
<Filter Include="src\messages\http">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-0000000000E2}</UniqueIdentifier>
</Filter>
<Filter Include="src\messages\peer">
<Filter Include="src\messages\http\enums">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-0000000000F2}</UniqueIdentifier>
</Filter>
<Filter Include="src\messages\peer\detail">
<Filter Include="src\messages\peer">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000003}</UniqueIdentifier>
</Filter>
<Filter Include="src\messages\rpc">
<Filter Include="src\messages\peer\detail">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000004}</UniqueIdentifier>
</Filter>
<Filter Include="src\net">
<Filter Include="src\messages\rpc">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000005}</UniqueIdentifier>
</Filter>
<Filter Include="src\p2ps">
<Filter Include="src\net">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000006}</UniqueIdentifier>
</Filter>
<Filter Include="src\protocols">
<Filter Include="src\p2ps">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000007}</UniqueIdentifier>
</Filter>
<Filter Include="src\sessions">
<Filter Include="src\protocols">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000008}</UniqueIdentifier>
</Filter>
<Filter Include="src\tls">
<Filter Include="src\sessions">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000009}</UniqueIdentifier>
</Filter>
<Filter Include="src\ws">
<Filter Include="src\tls">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000010}</UniqueIdentifier>
</Filter>
<Filter Include="src\zmtp">
<Filter Include="src\tor">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000011}</UniqueIdentifier>
</Filter>
<Filter Include="src\ws">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-000000000012}</UniqueIdentifier>
</Filter>
<Filter Include="src\zmtp">
<UniqueIdentifier>{564EB540-D6B6-425C-0000-0000000000A3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\src\async\thread.cpp">
Expand Down Expand Up @@ -612,6 +618,15 @@
<ClCompile Include="..\..\..\..\src\tls\stream.cpp">
<Filter>src\tls</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\tor\cell.cpp">
<Filter>src\tor</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\tor\certificate.cpp">
<Filter>src\tor</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\tor\link.cpp">
<Filter>src\tor</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\ws\frame.cpp">
<Filter>src\ws</Filter>
</ClCompile>
Expand Down Expand Up @@ -1220,6 +1235,21 @@
<ClInclude Include="..\..\..\..\include\bitcoin\network\tls\tls.hpp">
<Filter>include\bitcoin\network\tls</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\tor\cell.hpp">
<Filter>include\bitcoin\network\tor</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\tor\certificate.hpp">
<Filter>include\bitcoin\network\tor</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\tor\constants.hpp">
<Filter>include\bitcoin\network\tor</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\tor\link.hpp">
<Filter>include\bitcoin\network\tor</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\tor\tor.hpp">
<Filter>include\bitcoin\network\tor</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\ws\client.hpp">
<Filter>include\bitcoin\network\ws</Filter>
</ClInclude>
Expand Down
5 changes: 5 additions & 0 deletions include/bitcoin/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@
#include <bitcoin/network/tls/server.hpp>
#include <bitcoin/network/tls/stream.hpp>
#include <bitcoin/network/tls/tls.hpp>
#include <bitcoin/network/tor/cell.hpp>
#include <bitcoin/network/tor/certificate.hpp>
#include <bitcoin/network/tor/constants.hpp>
#include <bitcoin/network/tor/link.hpp>
#include <bitcoin/network/tor/tor.hpp>
#include <bitcoin/network/ws/client.hpp>
#include <bitcoin/network/ws/frame.hpp>
#include <bitcoin/network/ws/handshake.hpp>
Expand Down
15 changes: 7 additions & 8 deletions include/bitcoin/network/tls/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ namespace libbitcoin {
namespace network {
namespace tls {

/// The client side of one TLS 1.3 connection (rfc8446): the suites, groups
/// and signature schemes of the context offer, server authentication by
/// ECDSA P-256 or P-384 or RSA-PSS (to anchors, or unanchored), optional
/// client authentication (P-256 or P-384), without pre-shared keys or early
/// data. The client hello is output on construction. Not thread safe.
/// TLS 1.3 client connection (rfc8446), offer of context, no psk or early data.
/// Server authentication ECDSA P-256/P-384 or RSA-PSS (anchored or not),
/// optional client authentication (P-256/P-384). Sends client hello on
/// construction. Not thread safe.
class BCT_API client final
: public connection
{
Expand All @@ -41,18 +40,18 @@ class BCT_API client final
typedef system::x25519::key key;
typedef system::data_array<32> random;

/// The context must outlive the client.
/// Context must outlive client.
client(const context& context) NOEXCEPT;

/// Fixed client random and x25519 ephemeral secret (test vectors).
client(const context& context, const random& random,
const key& ephemeral) NOEXCEPT;
~client() NOEXCEPT override;

/// The server sent a HelloRetryRequest.
/// Server sent HelloRetryRequest.
bool is_retried() const NOEXCEPT;

/// The server requested a client certificate.
/// Server requested client certificate.
bool is_requested() const NOEXCEPT;

protected:
Expand Down
32 changes: 15 additions & 17 deletions include/bitcoin/network/tls/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@ namespace libbitcoin {
namespace network {
namespace tls {

/// One TLS 1.3 connection (rfc8446): the record layer, alerts, handshake
/// framing, application data and key updates, under the handshake of the
/// client or server. Transport bytes are consumed by receive and produced into
/// output. Not thread safe.
/// TLS 1.3 connection (rfc8446) records, alerts, framing, data, key updates.
/// Handshake by client or server, transport bytes consumed by receive and
/// produced into output. Not thread safe.
class BCT_API connection
{
public:
DELETE_COPY_MOVE(connection);

/// Consume received transport bytes. False once failed, when output holds
/// any alert to be sent, or once the peer has sent close_notify.
/// Consume transport bytes, false once failed (alert in output) or closed.
bool receive(const const_byte_span& data) NOEXCEPT;

/// Transport bytes to be sent (the caller consumes them).
/// Transport bytes to send (caller consumes them).
system::data_chunk& output() NOEXCEPT;

/// Protect application data into output (once established).
Expand All @@ -53,22 +51,22 @@ class BCT_API connection
/// Received application bytes not yet read.
size_t readable() const NOEXCEPT;

/// Queue a key update into output, optionally requesting the peer's.
/// Queue key update into output, optionally requesting peer's.
bool update(bool request) NOEXCEPT;

/// Queue close_notify into output (once).
void close() NOEXCEPT;

/// The handshake is complete (peer finished verified).
/// Handshake complete (peer finished verified).
bool is_established() const NOEXCEPT;

/// The peer sent close_notify.
/// Peer sent close_notify.
bool is_closed() const NOEXCEPT;

/// This side sent close_notify.
bool is_close_sent() const NOEXCEPT;

/// The connection failed, with the alert sent or received.
/// Connection failed, alert sent or received.
bool is_failed() const NOEXCEPT;
uint8_t failure() const NOEXCEPT;
bool is_failure_received() const NOEXCEPT;
Expand All @@ -83,7 +81,7 @@ class BCT_API connection
protected:
typedef const_byte_span span;

/// The context must outlive the connection.
/// Context must outlive connection.
connection(const context& context, bool server) NOEXCEPT;
virtual ~connection() NOEXCEPT;

Expand All @@ -98,18 +96,18 @@ class BCT_API connection
uint8_t& alert, const span& body) NOEXCEPT;
static uint8_t to_alert(const code& ec) NOEXCEPT;

/// CertificateVerify by the context key, of the transcript (4.4.3).
/// CertificateVerify of transcript by context key (4.4.3).
system::data_chunk make_verify(std::string_view label) const NOEXCEPT;

/// True if the leaf signed the transcript by the scheme (4.4.3).
/// True if leaf signed transcript by scheme (4.4.3).
bool is_verified(const system::x509::certificate& leaf, uint16_t scheme,
const span& signature, std::string_view label) const NOEXCEPT;

/// Handshake of the role, from the received handshake message.
/// Role handshake of received handshake message.
virtual bool handle_message(uint8_t type, const span& message,
const span& body) NOEXCEPT = 0;

/// True if a compatibility change_cipher_spec may be received (5).
/// True if compatibility change_cipher_spec may be received (5).
virtual bool is_handshaking() const NOEXCEPT = 0;

/// Records and keys.
Expand All @@ -125,7 +123,7 @@ class BCT_API connection
void add_transcript(const span& message) NOEXCEPT;
schedule::secret transcript() const NOEXCEPT;

/// Application traffic secrets (7.1), from the handshake secret.
/// Application traffic secrets (7.1) from handshake secret.
void derive_traffic() NOEXCEPT;

// Configuration.
Expand Down
Loading
Loading