TLS work. Not done.
This commit is contained in:
parent
e6c1e9db0d
commit
43a24b900a
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
ConsoleServer::ConsoleServer(EPoll &ePoll, IPAddress address) : TCPServer(ePoll, address) {
|
ConsoleServer::ConsoleServer(EPoll &ePoll, IPAddress address) : TLSServer(ePoll, address) {
|
||||||
coreutils::Log(this);
|
coreutils::Log(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
#define __ConsoleServer_h__
|
#define __ConsoleServer_h__
|
||||||
|
|
||||||
#include "includes"
|
#include "includes"
|
||||||
#include "TCPServer.h"
|
#include "TLSServer.h"
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "EPoll.h"
|
#include "EPoll.h"
|
||||||
|
#include "LogListener.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ namespace core {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
class ConsoleServer : public TCPServer, coreutils::LogListener {
|
class ConsoleServer : public TLSServer, public coreutils::LogListener {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ namespace core {
|
|||||||
|
|
||||||
Socket::Socket(EPoll &ePoll) : ePoll(ePoll) {
|
Socket::Socket(EPoll &ePoll) : ePoll(ePoll) {
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "BMASocket object created.";
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "BMASocket object created.";
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "Buffer size set to default (4096).";
|
|
||||||
buffer = (char *)malloc(4096);
|
buffer = (char *)malloc(4096);
|
||||||
length = 4096;
|
length = 4096;
|
||||||
}
|
}
|
||||||
@ -23,15 +22,12 @@ namespace core {
|
|||||||
if(descriptor < 3)
|
if(descriptor < 3)
|
||||||
throw coreutils::Exception("Descriptor out of range", __FILE__, __LINE__);
|
throw coreutils::Exception("Descriptor out of range", __FILE__, __LINE__);
|
||||||
this->descriptor = descriptor;
|
this->descriptor = descriptor;
|
||||||
onTLSInit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket::getDescriptor() {
|
int Socket::getDescriptor() {
|
||||||
return descriptor;
|
return descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::onTLSInit() {}
|
|
||||||
|
|
||||||
void Socket::setBufferSize(int length) {
|
void Socket::setBufferSize(int length) {
|
||||||
buffer = (char *)realloc(buffer, length);
|
buffer = (char *)realloc(buffer, length);
|
||||||
this->length = length;
|
this->length = length;
|
||||||
@ -42,7 +38,7 @@ namespace core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Socket::onUnregistered() {
|
void Socket::onUnregistered() {
|
||||||
// onDisconnected();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::eventReceived(struct epoll_event event) {
|
void Socket::eventReceived(struct epoll_event event) {
|
||||||
|
2
Socket.h
2
Socket.h
@ -109,8 +109,6 @@ namespace core {
|
|||||||
|
|
||||||
virtual void onConnected(); ///< Called when socket is open and ready to communicate.
|
virtual void onConnected(); ///< Called when socket is open and ready to communicate.
|
||||||
|
|
||||||
virtual void onTLSInit();
|
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
@ -30,18 +30,18 @@ namespace core {
|
|||||||
TCPSession *session = getSocketAccept(ePoll);
|
TCPSession *session = getSocketAccept(ePoll);
|
||||||
session->setDescriptor(::accept(getDescriptor(), (struct sockaddr *)&session->ipAddress.addr, &session->ipAddress.addressLength));
|
session->setDescriptor(::accept(getDescriptor(), (struct sockaddr *)&session->ipAddress.addr, &session->ipAddress.addressLength));
|
||||||
|
|
||||||
// if(blackList && blackList->contains(session->ipAddress.getClientAddress())) {
|
// if(blackList && blackList->contains(session->ipAddress.getClientAddress())) {
|
||||||
// session->shutdown();
|
// session->shutdown();
|
||||||
// Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is blacklisted and was denied a connection.";
|
// Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is blacklisted and was denied a connection.";
|
||||||
// return NULL;
|
// return NULL;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// if(whiteList && !whiteList->contains(session->ipAddress.getClientAddress())) {
|
// if(whiteList && !whiteList->contains(session->ipAddress.getClientAddress())) {
|
||||||
// session->shutdown();
|
// session->shutdown();
|
||||||
// Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is not authorized and was denied a connection.";
|
// Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is not authorized and was denied a connection.";
|
||||||
// return NULL;
|
// return NULL;
|
||||||
// }
|
// }
|
||||||
|
//
|
||||||
ePoll.registerSocket(session);
|
ePoll.registerSocket(session);
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "Session started on socket " << session->getDescriptor() << ".";
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "Session started on socket " << session->getDescriptor() << ".";
|
||||||
return session;
|
return session;
|
||||||
|
@ -8,12 +8,16 @@ namespace core {
|
|||||||
|
|
||||||
static pthread_mutex_t *lockarray;
|
static pthread_mutex_t *lockarray;
|
||||||
|
|
||||||
//static void lock_callback(int mode, int type, const char *file, int line) {
|
static unsigned long thread_id(void) {
|
||||||
// if(mode & CRYPTO_LOCK)
|
return ((unsigned long) pthread_self());
|
||||||
// pthread_mutex_lock(&(lockarray[type]));
|
}
|
||||||
// else
|
|
||||||
// pthread_mutex_unlock(&(lockarray[type]));
|
static void lock_callback(int mode, int type, const char *file, int line) {
|
||||||
//}
|
if(mode & CRYPTO_LOCK)
|
||||||
|
pthread_mutex_lock(&(lockarray[type]));
|
||||||
|
else
|
||||||
|
pthread_mutex_unlock(&(lockarray[type]));
|
||||||
|
}
|
||||||
|
|
||||||
TLSServer::TLSServer(EPoll &ePoll, IPAddress address) : TCPServer(ePoll, address) {
|
TLSServer::TLSServer(EPoll &ePoll, IPAddress address) : TCPServer(ePoll, address) {
|
||||||
|
|
||||||
@ -24,8 +28,8 @@ namespace core {
|
|||||||
for(int i = 0; i < CRYPTO_num_locks(); ++i)
|
for(int i = 0; i < CRYPTO_num_locks(); ++i)
|
||||||
pthread_mutex_init(&(lockarray[i]), NULL);
|
pthread_mutex_init(&(lockarray[i]), NULL);
|
||||||
|
|
||||||
// CRYPTO_set_id_callback((unsigned long (*)())thread_id);
|
CRYPTO_set_id_callback((unsigned long (*)())thread_id);
|
||||||
// CRYPTO_set_locking_callback((void ()(int, int, const char *, int))lock_callback);
|
CRYPTO_set_locking_callback((void (*)(int, int, const char *, int))lock_callback);
|
||||||
|
|
||||||
SSLeay_add_ssl_algorithms();
|
SSLeay_add_ssl_algorithms();
|
||||||
RAND_load_file("/dev/hwrng", 1024);
|
RAND_load_file("/dev/hwrng", 1024);
|
||||||
|
@ -43,9 +43,9 @@ namespace core {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
char *sip_cacert = (char *)"/home/barant/testkeys/certs/pbxca.crt";
|
char *sip_cacert = (char *)"../testkeys/certs/pbxca.crt";
|
||||||
char *sip_cert = (char *)"/home/barant/testkeys/certs/pbxserver.crt";
|
char *sip_cert = (char *)"../testkeys/certs/pbxserver.crt";
|
||||||
char *sip_key = (char *)"/home/barant/testkeys/certs/pbxserver.key";
|
char *sip_key = (char *)"../testkeys/certs/pbxserver.key";
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,48 +31,48 @@ namespace core {
|
|||||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "No client certificate.";
|
coreutils::Log(coreutils::LOG_DEBUG_3) << "No client certificate.";
|
||||||
}
|
}
|
||||||
|
|
||||||
TLSSession::TLSSession(EPoll &ePoll, TCPServer &server) : TCPSession(ePoll, server) {}
|
TLSSession::TLSSession(EPoll &ePoll, TCPServer &server) : TCPSession(ePoll, server) {
|
||||||
|
|
||||||
// void TLSSession::init() {
|
initialized = true;
|
||||||
//
|
|
||||||
// initialized = true;
|
int ret;
|
||||||
//
|
|
||||||
// int ret;
|
coreutils::Log(coreutils::LOG_DEBUG_3) << "TLS socket initializing on socket " << getDescriptor() << "...";
|
||||||
//
|
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_3) << "TLS socket initializing...";
|
fcntl(getDescriptor(), F_SETFL, fcntl(getDescriptor(), F_GETFL, 0) | O_NONBLOCK);
|
||||||
//
|
|
||||||
// fcntl(getDescriptor(), F_SETFL, fcntl(getDescriptor(), F_GETFL, 0) | O_NONBLOCK);
|
ssl = SSL_new(static_cast<TLSServer &>(server).ctx);
|
||||||
//
|
if(ssl <= 0)
|
||||||
// if(!(ssl = SSL_new(((TLSService &)service).ctx)))
|
throw std::string("Error creating new TLS socket.");
|
||||||
// throw std::string("Error creating new TLS socket.");
|
|
||||||
//
|
SSL_set_info_callback(ssl, handshake_complete);
|
||||||
// SSL_set_info_callback(ssl, handshake_complete);
|
|
||||||
//
|
if((ret = SSL_set_fd(ssl, getDescriptor())) == 0)
|
||||||
// if((ret = SSL_set_fd(ssl, getDescriptor())) == 0)
|
throw std::string("Error setting TLS socket descriptor.");
|
||||||
// throw std::string("Error setting TLS socket descriptor.");
|
|
||||||
//
|
if(!SSL_set_generate_session_id(ssl, generate_session_id))
|
||||||
//// if(!SSL_set_generate_session_id(ssl, generate_session_id))
|
throw std::string("Error setting session identifier callback.");
|
||||||
//// throw std::string("Error setting session identifier callback.");
|
|
||||||
//
|
switch (SSL_get_error(ssl, SSL_accept(ssl))) {
|
||||||
// switch (SSL_get_error(ssl, SSL_accept(ssl))) {
|
case SSL_ERROR_SSL:
|
||||||
// case SSL_ERROR_SSL:
|
coreutils::Log(coreutils::LOG_DEBUG_3) << "ERROR_SSL on ssl_accept. errno=" << errno;
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_3) << "ERROR_SSL on ssl_accept. errno=" << errno;
|
break;
|
||||||
// break;
|
case SSL_ERROR_WANT_READ:
|
||||||
// case SSL_ERROR_WANT_READ:
|
coreutils::Log(coreutils::LOG_DEBUG_3) << "ERROR_WANT_READ on ssl_accept.";
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_3) << "ERROR_WANT_READ on ssl_accept.";
|
break;
|
||||||
// break;
|
case SSL_ERROR_WANT_WRITE:
|
||||||
// case SSL_ERROR_WANT_WRITE:
|
coreutils::Log(coreutils::LOG_DEBUG_3) << "ERROR_WANT_WRITE on ssl_accept.";
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_3) << "ERROR_WANT_WRITE on ssl_accept.";
|
break;
|
||||||
// break;
|
case SSL_ERROR_SYSCALL:
|
||||||
// case SSL_ERROR_SYSCALL:
|
coreutils::Log(coreutils::LOG_DEBUG_3) << "ERROR_SYSCALL on ssl_accept. errno=" << errno;
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_3) << "ERROR_SYSCALL on ssl_accept. errno=" << errno;
|
shutdown();
|
||||||
// shutdown();
|
break;
|
||||||
// break;
|
default:
|
||||||
// default:
|
coreutils::Log(coreutils::LOG_DEBUG_3) << "Unknown ERROR on ssl_accept.";
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_3) << "Unknown ERROR on ssl_accept.";
|
break;
|
||||||
// break;
|
}
|
||||||
// }
|
|
||||||
// }
|
}
|
||||||
|
|
||||||
TLSSession::~TLSSession() {
|
TLSSession::~TLSSession() {
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
TerminalSession::TerminalSession(EPoll &ePoll, TCPServer &server) : TCPSession(ePoll, server) {
|
TerminalSession::TerminalSession(EPoll &ePoll, TCPServer &server) : TLSSession(ePoll, server) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalSession::~TerminalSession() {
|
TerminalSession::~TerminalSession() {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define __Terminal_h__
|
#define __Terminal_h__
|
||||||
|
|
||||||
#include "includes"
|
#include "includes"
|
||||||
#include "TCPSession.h"
|
#include "TLSSession.h"
|
||||||
#include "TCPServer.h"
|
#include "TCPServer.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
@ -27,7 +27,7 @@ namespace core {
|
|||||||
|
|
||||||
static const char esc = 0x1b;
|
static const char esc = 0x1b;
|
||||||
|
|
||||||
class TerminalSession : public TCPSession {
|
class TerminalSession : public TLSSession {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TerminalSession(EPoll &ePoll, TCPServer &server);
|
TerminalSession(EPoll &ePoll, TCPServer &server);
|
||||||
|
2
compile
2
compile
@ -5,7 +5,7 @@ do
|
|||||||
filename="${file%.*}"
|
filename="${file%.*}"
|
||||||
list="$list $filename.o"
|
list="$list $filename.o"
|
||||||
echo -n "Compiling $filename..."
|
echo -n "Compiling $filename..."
|
||||||
g++ -c -I../CoreUtils $file &
|
g++ -g -c -I../CoreUtils $file
|
||||||
if [ $? = '0' ]
|
if [ $? = '0' ]
|
||||||
then
|
then
|
||||||
echo "OK"
|
echo "OK"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user