TLS almost connects. Needs read and write logic finished.
This commit is contained in:
parent
e0c0e2c07e
commit
5feabd0fde
@ -5,7 +5,7 @@
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
# include "Command.h"
|
||||
# include "EPoll.h"
|
||||
# include "LogListener.h"
|
||||
# include "TLSInfo.h"
|
||||
|
||||
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) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process beginning for socket " << getDescriptor();
|
||||
if(inHandler)
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "inHandler was already true.";
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ coreutils::Log(coreutils::LOG_DEBUG_2) << "inHandler was already true.";
|
||||
inHandler = true;
|
||||
if(event.events & EPOLLRDHUP) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLRDHUP";
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
namespace core {
|
||||
|
||||
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, int depth, std::string text)
|
||||
: TCPSocket(ePoll, text), commands(delimiter, depth) {
|
||||
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, TLSInfo *tlsInfo, std::string delimiter, int depth, std::string text)
|
||||
: TCPSocket(ePoll, tlsInfo, text), commands(delimiter, depth) {
|
||||
|
||||
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
||||
int yes = 1;
|
||||
@ -31,6 +31,10 @@ namespace core {
|
||||
TCPSession *session = accept();
|
||||
if (session)
|
||||
sessions.push_back(session);
|
||||
if(true) {
|
||||
registerSocket(session->getDescriptor());
|
||||
acceptSocket();
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
# include "SubscriptionManager.h"
|
||||
# include "TCPSession.h"
|
||||
# include "TCPSocket.h"
|
||||
# include "TLSInfo.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
@ -36,7 +37,7 @@ namespace core {
|
||||
/// @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.
|
||||
|
@ -10,7 +10,7 @@ namespace core {
|
||||
|
||||
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) {}
|
||||
|
||||
@ -28,6 +28,11 @@ namespace core {
|
||||
}
|
||||
|
||||
void TCPSocket::onDataReceived(coreutils::ZString &data) {
|
||||
|
||||
if(tlsInfo) {
|
||||
|
||||
}
|
||||
|
||||
if (data.getLength() > 0) {
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength());
|
||||
memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength());
|
||||
|
@ -106,6 +106,7 @@ namespace core {
|
||||
|
||||
protected:
|
||||
bool term = false;
|
||||
TLSInfo *tlsInfo;
|
||||
|
||||
private:
|
||||
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))
|
||||
throw coreutils::Exception("Cannot verify locations.");
|
||||
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 "Log.h"
|
||||
#include "IPAddress.h"
|
||||
#include "TLSInfo.h"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@ -17,7 +18,12 @@ int main(int argc, char **argv) {
|
||||
|
||||
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(console, "consoles");
|
||||
|
Loading…
x
Reference in New Issue
Block a user