// Copyright (c) 2019-2020 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include #include #include #include "utiltls.h" #include "tlsenums.h" #include #include #include "../util.h" #include "../protocol.h" #include "../net.h" #include "sync.h" #include #include #include #ifdef WIN32 #include #else #include #endif using namespace std; namespace hush { typedef struct _NODE_ADDR { std::string ipAddr; int64_t time; // time in msec, of an attempt to connect via TLS _NODE_ADDR(std::string _ipAddr, int64_t _time = 0) : ipAddr(_ipAddr), time(_time) {} bool operator==(const _NODE_ADDR b) const { return (ipAddr == b.ipAddr); } } NODE_ADDR, *PNODE_ADDR; /** * @brief A class to wrap some of hush specific TLS functionalities used in the net.cpp * */ class TLSManager { public: int waitFor(SSLConnectionRoutine eRoutine, SOCKET hSocket, SSL* ssl, int timeoutSec); SSL* connect(SOCKET hSocket, const CAddress& addrConnect); SSL_CTX* initCtx( TLSContextType ctxType, const boost::filesystem::path& privateKeyFile, const boost::filesystem::path& certificateFile, const std::vector& trustedDirs); bool prepareCredentials(); SSL* accept(SOCKET hSocket, const CAddress& addr); bool isNonTLSAddr(const string& strAddr, const vector& vPool, CCriticalSection& cs); void cleanNonTLSPool(std::vector& vPool, CCriticalSection& cs); int threadSocketHandler(CNode* pnode, fd_set& fdsetRecv, fd_set& fdsetSend, fd_set& fdsetError); bool initialize(); }; }