TLS almost connects. Needs read and write logic finished.

This commit is contained in:
Brad Arant 2025-02-20 15:33:28 -08:00
parent e0c0e2c07e
commit 5feabd0fde
10 changed files with 45 additions and 27 deletions

View File

@ -5,7 +5,7 @@
namespace core { namespace core {
ConsoleServer::ConsoleServer(EPoll &ePoll, IPAddress address) : TCPServer(ePoll, address, " ", 10, "Console Server") { ConsoleServer::ConsoleServer(EPoll &ePoll, IPAddress address, TLSInfo *tlsInfo) : TCPServer(ePoll, address, tlsInfo, " ", 10, "Console Server") {
coreutils::Log(this); coreutils::Log(this);
} }

View File

@ -5,6 +5,7 @@
# include "Command.h" # include "Command.h"
# include "EPoll.h" # include "EPoll.h"
# include "LogListener.h" # include "LogListener.h"
# include "TLSInfo.h"
namespace core { namespace core {
@ -23,7 +24,7 @@ namespace core {
// //
// //
ConsoleServer(EPoll &ePoll, IPAddress address); ConsoleServer(EPoll &ePoll, IPAddress address, TLSInfo *tlsInfo);
// //
// //

View File

@ -70,7 +70,7 @@ namespace core
bool Socket::eventReceived(struct epoll_event event, long long eventId) { bool Socket::eventReceived(struct epoll_event event, long long eventId) {
coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process beginning for socket " << getDescriptor(); coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process beginning for socket " << getDescriptor();
if(inHandler) if(inHandler)
coreutils::Log(coreutils::LOG_DEBUG_2) << "inHandler was already true."; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ coreutils::Log(coreutils::LOG_DEBUG_2) << "inHandler was already true.";
inHandler = true; inHandler = true;
if(event.events & EPOLLRDHUP) { if(event.events & EPOLLRDHUP) {
coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLRDHUP"; coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLRDHUP";

View File

@ -6,8 +6,8 @@
namespace core { namespace core {
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, int depth, std::string text) TCPServer::TCPServer(EPoll &ePoll, IPAddress address, TLSInfo *tlsInfo, std::string delimiter, int depth, std::string text)
: TCPSocket(ePoll, text), commands(delimiter, depth) { : TCPSocket(ePoll, tlsInfo, text), commands(delimiter, depth) {
setDescriptor(socket(AF_INET, SOCK_STREAM, 0)); setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
int yes = 1; int yes = 1;
@ -31,6 +31,10 @@ namespace core {
TCPSession *session = accept(); TCPSession *session = accept();
if (session) if (session)
sessions.push_back(session); sessions.push_back(session);
if(true) {
registerSocket(session->getDescriptor());
acceptSocket();
}
lock.unlock(); lock.unlock();
} }

View File

@ -8,6 +8,7 @@
# include "SubscriptionManager.h" # include "SubscriptionManager.h"
# include "TCPSession.h" # include "TCPSession.h"
# include "TCPSocket.h" # include "TCPSocket.h"
# include "TLSInfo.h"
namespace core { namespace core {
@ -36,7 +37,7 @@ namespace core {
/// @param commandName the name of the command used to invoke the status display for this object. /// @param commandName the name of the command used to invoke the status display for this object.
/// ///
TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter = " ", int depth = 10, std::string text = ""); TCPServer(EPoll &ePoll, IPAddress address, TLSInfo *tlsInfo, std::string delimiter = " ", int depth = 10, std::string text = "");
/// ///
/// The destructor for this object. /// The destructor for this object.

View File

@ -10,7 +10,7 @@ namespace core {
TCPSocket::TCPSocket(EPoll &ePoll, std::string text) : Socket(ePoll, text) {} TCPSocket::TCPSocket(EPoll &ePoll, std::string text) : Socket(ePoll, text) {}
TCPSocket::TCPSocket(EPoll &ePoll, TLSInfo *tlsInfo, std::string text) : Socket(ePoll, text), TLS(tlsInfo) {} TCPSocket::TCPSocket(EPoll &ePoll, TLSInfo *tlsInfo, std::string text) : Socket(ePoll, text), TLS(tlsInfo), tlsInfo(tlsInfo) {}
TCPSocket::TCPSocket(EPoll &ePoll, SSL_CTX *ctx, std::string text) : Socket(ePoll, text), TLS(ctx) {} TCPSocket::TCPSocket(EPoll &ePoll, SSL_CTX *ctx, std::string text) : Socket(ePoll, text), TLS(ctx) {}
@ -28,6 +28,11 @@ namespace core {
} }
void TCPSocket::onDataReceived(coreutils::ZString &data) { void TCPSocket::onDataReceived(coreutils::ZString &data) {
if(tlsInfo) {
}
if (data.getLength() > 0) { if (data.getLength() > 0) {
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength()); lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength());
memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength()); memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength());

View File

@ -106,6 +106,7 @@ namespace core {
protected: protected:
bool term = false; bool term = false;
TLSInfo *tlsInfo;
private: private:
char *lineBuffer = NULL; char *lineBuffer = NULL;

View File

@ -85,7 +85,7 @@ namespace core {
if(!SSL_CTX_load_verify_locations(ctx, tlsInfo->cACertificate.c_str(), NULL)) if(!SSL_CTX_load_verify_locations(ctx, tlsInfo->cACertificate.c_str(), NULL))
throw coreutils::Exception("Cannot verify locations."); throw coreutils::Exception("Cannot verify locations.");
SSL_CTX_set_client_CA_list(ctx, SSL_load_client_CA_file(tlsInfo->cACertificate.c_str())); SSL_CTX_set_client_CA_list(ctx, SSL_load_client_CA_file(tlsInfo->cACertificate.c_str()));
coreutils::Log(coreutils::LOG_DEBUG_1) << "Server key authenticated."; coreutils::Log(coreutils::LOG_INFO) << "Server key authenticated.";
} }
} }

Binary file not shown.

View File

@ -4,6 +4,7 @@
#include "File.h" #include "File.h"
#include "Log.h" #include "Log.h"
#include "IPAddress.h" #include "IPAddress.h"
#include "TLSInfo.h"
#include <iostream> #include <iostream>
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -17,7 +18,12 @@ int main(int argc, char **argv) {
core::EPoll ePoll; core::EPoll ePoll;
core::TCPServer console(ePoll, core::IPAddress(ipAddress, 1027)); core::TLSInfo tlsInfo;
tlsInfo.cACertificate = "certs/cert.pem";
tlsInfo.certificate = "certs/cert.pem";
tlsInfo.key = "certs/key.pem";
core::TCPServer console(ePoll, core::IPAddress(ipAddress, 1027), &tlsInfo);
console.commands.add(ePoll, "threads"); console.commands.add(ePoll, "threads");
console.commands.add(console, "consoles"); console.commands.add(console, "consoles");