TLS almost connects. Needs read and write logic finished.
This commit is contained in:
parent
e0c0e2c07e
commit
5feabd0fde
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#ifndef __ConsoleServer_h__
|
#ifndef __ConsoleServer_h__
|
||||||
#define __ConsoleServer_h__
|
# define __ConsoleServer_h__
|
||||||
|
|
||||||
#include "TCPServer.h"
|
# include "TCPServer.h"
|
||||||
#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);
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -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";
|
||||||
|
@ -5,21 +5,21 @@
|
|||||||
#include "TCPSession.h"
|
#include "TCPSession.h"
|
||||||
|
|
||||||
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;
|
||||||
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
|
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
|
||||||
|
|
||||||
if (bind(getDescriptor(), address.getPointer(), address.addressLength) < 0)
|
if (bind(getDescriptor(), address.getPointer(), address.addressLength) < 0)
|
||||||
throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno));
|
throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno));
|
||||||
|
|
||||||
if (listen(getDescriptor(), 20) < 0)
|
if (listen(getDescriptor(), 20) < 0)
|
||||||
throw coreutils::Exception("Error on listen to socket");
|
throw coreutils::Exception("Error on listen to socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
TCPServer::~TCPServer() {
|
TCPServer::~TCPServer() {
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << ".";
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << ".";
|
||||||
close(getDescriptor());
|
close(getDescriptor());
|
||||||
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.
|
||||||
|
@ -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());
|
||||||
|
@ -106,6 +106,7 @@ namespace core {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool term = false;
|
bool term = false;
|
||||||
|
TLSInfo *tlsInfo;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *lineBuffer = NULL;
|
char *lineBuffer = NULL;
|
||||||
|
2
TLS.cpp
2
TLS.cpp
@ -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.
@ -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) {
|
||||||
@ -16,8 +17,13 @@ int main(int argc, char **argv) {
|
|||||||
std::string ipAddress = "0.0.0.0";
|
std::string ipAddress = "0.0.0.0";
|
||||||
|
|
||||||
core::EPoll ePoll;
|
core::EPoll ePoll;
|
||||||
|
|
||||||
|
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));
|
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");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user