SNode.C
Loading...
Searching...
No Matches
apps::tlslegacy::TlsLegacySocketContext Class Reference

#include <TlsLegacySocketContext.h>

Inheritance diagram for apps::tlslegacy::TlsLegacySocketContext:
Collaboration diagram for apps::tlslegacy::TlsLegacySocketContext:

Public Types

enum class  Role { SERVER , CLIENT }

Public Member Functions

 TlsLegacySocketContext (core::socket::stream::SocketConnection *socketConnection, Role role)
Public Member Functions inherited from core::socket::stream::SocketContext
 SocketContext (core::socket::stream::SocketConnection *socketConnection)
void sendToPeer (const char *chunk, std::size_t chunkLen) const final
bool streamToPeer (core::pipe::Source *source) const
void streamEof ()
std::size_t readFromPeer (char *chunk, std::size_t chunklen) const final
void setTimeout (const utils::Timeval &timeout) final
void shutdownRead ()
void shutdownWrite ()
void close () override
std::size_t getTotalSent () const override
std::size_t getTotalQueued () const override
std::size_t getTotalRead () const override
std::size_t getTotalProcessed () const override
std::string getOnlineSince () const override
std::string getOnlineDuration () const override
SocketConnectiongetSocketConnection () const
void sendToPeer (const std::string &data) const
Public Member Functions inherited from core::socket::SocketContext
 SocketContext (const SocketContext &)=delete
 SocketContext (SocketContext &&)=delete
SocketContextoperator= (const SocketContext &)=delete
SocketContextoperator= (SocketContext &&)=delete
void sendToPeer (const std::string &data) const

Private Member Functions

void onConnected () override
void onDisconnected () override
bool onSignal (int signum) override
std::size_t onReceivedFromPeer () override
void onClientLine (const std::string &line)
void onServerLine (const std::string &line)
void startLegacyRetryTimer (const std::string &payload)

Private Attributes

Role role
std::string inboundBuffer
bool tlsReplySeen = false
bool legacyReplySeen = false
bool legacyPayloadSeen = false
core::timer::Timer legacyRetryTimer

Additional Inherited Members

Protected Member Functions inherited from core::socket::stream::SocketContext
void onWriteError (int errnum) override
void onReadError (int errnum) override
std::size_t readFromPeer ()
Protected Member Functions inherited from core::socket::SocketContext
 SocketContext ()=default
virtual ~SocketContext ()

Detailed Description

Definition at line 23 of file TlsLegacySocketContext.h.

Member Enumeration Documentation

◆ Role

Enumerator
SERVER 
CLIENT 

Definition at line 25 of file TlsLegacySocketContext.h.

25{ SERVER, CLIENT };

Constructor & Destructor Documentation

◆ TlsLegacySocketContext()

apps::tlslegacy::TlsLegacySocketContext::TlsLegacySocketContext ( core::socket::stream::SocketConnection * socketConnection,
Role role )
explicit

Definition at line 23 of file TlsLegacySocketContext.cpp.

24 : core::socket::stream::SocketContext(socketConnection)
25 , role(role) {
26 }
core::socket::stream::SocketConnection * socketConnection

References role, and core::socket::stream::SocketContext::SocketContext().

Referenced by apps::tlslegacy::TlsLegacyClientSocketContextFactory::create(), and apps::tlslegacy::TlsLegacyServerSocketContextFactory::create().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ onClientLine()

void apps::tlslegacy::TlsLegacySocketContext::onClientLine ( const std::string & line)
private

Definition at line 62 of file TlsLegacySocketContext.cpp.

62 {
63 if (line == TLS_ACK && !tlsReplySeen) {
64 tlsReplySeen = true;
65 VLOG(1) << getSocketConnection()->getConnectionName() << ": got TLS ack, initiating TLS shutdown handshake (close_notify) "
66 << line;
68 startLegacyRetryTimer(LEGACY_HELLO);
69 } else if (line == LEGACY_ACK && !legacyReplySeen) {
70 legacyReplySeen = true;
71 legacyRetryTimer.cancel();
72 VLOG(1) << getSocketConnection()->getConnectionName() << ": got LEGACY ack -> post-TLS plaintext path works " << line;
74 }
75 }
#define VLOG(level)
Definition Logger.h:164
void startLegacyRetryTimer(const std::string &payload)
const std::string & getConnectionName() const
SocketConnection * getSocketConnection() const

References core::Timer::cancel(), core::socket::stream::SocketConnection::getConnectionName(), core::socket::stream::SocketContext::getSocketConnection(), anonymous_namespace{TlsLegacySocketContext.cpp}::LEGACY_ACK, anonymous_namespace{TlsLegacySocketContext.cpp}::LEGACY_HELLO, legacyReplySeen, legacyRetryTimer, logger::LogMessage::LogMessage(), core::socket::stream::SocketContext::shutdownWrite(), startLegacyRetryTimer(), anonymous_namespace{TlsLegacySocketContext.cpp}::TLS_ACK, and tlsReplySeen.

Referenced by onReceivedFromPeer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onConnected()

void apps::tlslegacy::TlsLegacySocketContext::onConnected ( )
overrideprivatevirtual

Implements core::socket::stream::SocketContext.

Definition at line 28 of file TlsLegacySocketContext.cpp.

28 {
29 VLOG(1) << getSocketConnection()->getConnectionName() << ": connected";
30
31 if (role == Role::CLIENT) {
32 sendToPeer(TLS_HELLO);
33 VLOG(1) << getSocketConnection()->getConnectionName() << ": sent TLS greeting";
34 }
35 }
void sendToPeer(const char *chunk, std::size_t chunkLen) const final

References CLIENT, core::socket::stream::SocketConnection::getConnectionName(), core::socket::stream::SocketContext::getSocketConnection(), logger::LogMessage::LogMessage(), role, core::socket::SocketContext::sendToPeer(), and anonymous_namespace{TlsLegacySocketContext.cpp}::TLS_HELLO.

Here is the call graph for this function:

◆ onDisconnected()

void apps::tlslegacy::TlsLegacySocketContext::onDisconnected ( )
overrideprivatevirtual

Implements core::socket::stream::SocketContext.

Definition at line 37 of file TlsLegacySocketContext.cpp.

37 {
38 legacyRetryTimer.cancel();
39 VLOG(1) << getSocketConnection()->getConnectionName() << ": disconnected";
40 }

References core::Timer::cancel(), core::socket::stream::SocketConnection::getConnectionName(), core::socket::stream::SocketContext::getSocketConnection(), legacyRetryTimer, and logger::LogMessage::LogMessage().

Here is the call graph for this function:

◆ onReceivedFromPeer()

std::size_t apps::tlslegacy::TlsLegacySocketContext::onReceivedFromPeer ( )
overrideprivatevirtual

Implements core::socket::SocketContext.

Definition at line 91 of file TlsLegacySocketContext.cpp.

91 {
92 char chunk[4096];
93 const std::size_t chunkLen = readFromPeer(chunk, sizeof(chunk));
94
95 if (chunkLen == 0) {
96 return 0;
97 }
98
99 inboundBuffer.append(chunk, chunkLen);
100
101 std::size_t pos = std::string::npos;
102 while ((pos = inboundBuffer.find('\n')) != std::string::npos) {
103 const std::string line = inboundBuffer.substr(0, pos + 1);
104 inboundBuffer.erase(0, pos + 1);
105
106 if (role == Role::CLIENT) {
107 onClientLine(line);
108 } else {
109 onServerLine(line);
110 }
111 }
112
113 return chunkLen;
114 }

References CLIENT, inboundBuffer, onClientLine(), onServerLine(), core::socket::stream::SocketContext::readFromPeer(), and role.

Here is the call graph for this function:

◆ onServerLine()

void apps::tlslegacy::TlsLegacySocketContext::onServerLine ( const std::string & line)
private

Definition at line 77 of file TlsLegacySocketContext.cpp.

77 {
78 if (line == TLS_HELLO && !tlsReplySeen) {
79 tlsReplySeen = true;
80 sendToPeer(TLS_ACK);
81 VLOG(1) << getSocketConnection()->getConnectionName() << ": TLS phase complete, waiting for peer close_notify " << line;
82 } else if (line == LEGACY_HELLO && !legacyPayloadSeen) {
83 legacyPayloadSeen = true;
84 legacyRetryTimer.cancel();
85 sendToPeer(LEGACY_ACK);
86 VLOG(1) << getSocketConnection()->getConnectionName() << ": received LEGACY payload after TLS shutdown " << line;
88 }
89 }

References core::Timer::cancel(), core::socket::stream::SocketConnection::getConnectionName(), core::socket::stream::SocketContext::getSocketConnection(), anonymous_namespace{TlsLegacySocketContext.cpp}::LEGACY_ACK, anonymous_namespace{TlsLegacySocketContext.cpp}::LEGACY_HELLO, legacyPayloadSeen, legacyRetryTimer, logger::LogMessage::LogMessage(), core::socket::SocketContext::sendToPeer(), core::socket::stream::SocketContext::shutdownWrite(), anonymous_namespace{TlsLegacySocketContext.cpp}::TLS_ACK, anonymous_namespace{TlsLegacySocketContext.cpp}::TLS_HELLO, and tlsReplySeen.

Referenced by onReceivedFromPeer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onSignal()

bool apps::tlslegacy::TlsLegacySocketContext::onSignal ( int signum)
overrideprivatevirtual

Implements core::socket::SocketContext.

Definition at line 42 of file TlsLegacySocketContext.cpp.

42 {
43 return true;
44 }

◆ startLegacyRetryTimer()

void apps::tlslegacy::TlsLegacySocketContext::startLegacyRetryTimer ( const std::string & payload)
private

Definition at line 46 of file TlsLegacySocketContext.cpp.

46 {
47 legacyRetryTimer.cancel();
48
50 [this, payload](const std::function<void()>& stop) {
52 stop();
53 return;
54 }
55
56 sendToPeer(payload);
57 VLOG(1) << getSocketConnection()->getConnectionName() << ": trying post-TLS legacy payload: " << payload;
58 },
59 utils::Timeval(0.5));
60 }
static Timer intervalTimer(const std::function< void(const std::function< void()> &)> &dispatcher, const utils::Timeval &timeout)
Definition Timer.cpp:61

References core::Timer::cancel(), CLIENT, core::socket::stream::SocketConnection::getConnectionName(), core::socket::stream::SocketContext::getSocketConnection(), core::timer::Timer::intervalTimer(), legacyReplySeen, legacyRetryTimer, logger::LogMessage::LogMessage(), core::timer::Timer::operator=(), role, core::socket::SocketContext::sendToPeer(), and utils::Timeval::Timeval().

Referenced by onClientLine().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ inboundBuffer

std::string apps::tlslegacy::TlsLegacySocketContext::inboundBuffer
private

Definition at line 40 of file TlsLegacySocketContext.h.

Referenced by onReceivedFromPeer().

◆ legacyPayloadSeen

bool apps::tlslegacy::TlsLegacySocketContext::legacyPayloadSeen = false
private

Definition at line 44 of file TlsLegacySocketContext.h.

Referenced by onServerLine().

◆ legacyReplySeen

bool apps::tlslegacy::TlsLegacySocketContext::legacyReplySeen = false
private

Definition at line 43 of file TlsLegacySocketContext.h.

Referenced by onClientLine(), and startLegacyRetryTimer().

◆ legacyRetryTimer

core::timer::Timer apps::tlslegacy::TlsLegacySocketContext::legacyRetryTimer
private

◆ role

Role apps::tlslegacy::TlsLegacySocketContext::role
private

◆ tlsReplySeen

bool apps::tlslegacy::TlsLegacySocketContext::tlsReplySeen = false
private

Definition at line 42 of file TlsLegacySocketContext.h.

Referenced by onClientLine(), and onServerLine().


The documentation for this class was generated from the following files: