TLS prototype test

This commit is contained in:
Ugo Cirmignani
2018-11-26 22:27:01 +01:00
parent 9f055ca084
commit ed0b033fba
39 changed files with 113 additions and 214 deletions

View File

@ -11,6 +11,7 @@ OPTIMIZATION=-O3
HEADERS=-I
LIBPATH=./build/modules/
BUILDFILES=start uFTP end
LIBS=-lpthread -lssl -lcrypto
#DEFINITIONS=
@ -29,14 +30,17 @@ start:
end:
@echo Build process end
uFTP: uFTP.c fileManagement.o configRead.o logFunctions.o ftpCommandElaborate.o ftpData.o ftpServer.o daemon.o signals.o connection.o
@$(CC) $(DEFINITIONS) uFTP.c $(LIBPATH)dynamicVectors.o $(LIBPATH)fileManagement.o $(LIBPATH)configRead.o $(LIBPATH)logFunctions.o $(LIBPATH)ftpCommandElaborate.o $(LIBPATH)ftpData.o $(LIBPATH)ftpServer.o $(LIBPATH)daemon.o $(LIBPATH)signals.o $(LIBPATH)connection.o -o $(OUTPATH)uFTP -lpthread
uFTP: uFTP.c fileManagement.o configRead.o logFunctions.o ftpCommandElaborate.o ftpData.o ftpServer.o daemon.o signals.o connection.o openSsl.o
@$(CC) $(DEFINITIONS) uFTP.c $(LIBPATH)dynamicVectors.o $(LIBPATH)fileManagement.o $(LIBPATH)configRead.o $(LIBPATH)logFunctions.o $(LIBPATH)ftpCommandElaborate.o $(LIBPATH)ftpData.o $(LIBPATH)ftpServer.o $(LIBPATH)daemon.o $(LIBPATH)signals.o $(LIBPATH)connection.o $(LIBPATH)openSsl.o -o $(OUTPATH)uFTP $(LIBS)
daemon.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)daemon.c -o $(LIBPATH)daemon.o
dynamicVectors.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)dynamicVectors.c -o $(LIBPATH)dynamicVectors.o
openSsl.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)openSsl.c -o $(LIBPATH)openSsl.o
configRead.o: dynamicVectors.o fileManagement.o
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)configRead.c -o $(LIBPATH)configRead.o
@ -59,7 +63,7 @@ ftpCommandElaborate.o:
ftpData.o:
@$(CC) $(CFLAGS) ftpData.c -o $(LIBPATH)ftpData.o
ftpServer.o:
ftpServer.o: openSsl.o
@$(CC) $(CFLAGS) ftpServer.c -o $(LIBPATH)ftpServer.o
clean:

View File

@ -1,29 +0,0 @@
build/Debug/GNU-Linux/ftpCommandElaborate.o: ftpCommandElaborate.c \
library/dynamicVectors.h library/fileManagement.h \
library/dynamicVectors.h ftpData.h library/dynamicVectors.h ftpServer.h \
library/logFunctions.h library/fileManagement.h library/configRead.h \
library/dynamicVectors.h library/../ftpData.h ftpCommandsElaborate.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
ftpData.h:
library/dynamicVectors.h:
ftpServer.h:
library/logFunctions.h:
library/fileManagement.h:
library/configRead.h:
library/dynamicVectors.h:
library/../ftpData.h:
ftpCommandsElaborate.h:

Binary file not shown.

View File

@ -1,27 +0,0 @@
build/Debug/GNU-Linux/ftpData.o: ftpData.c library/dynamicVectors.h \
library/fileManagement.h library/dynamicVectors.h ftpServer.h \
ftpCommandsElaborate.h ftpData.h library/dynamicVectors.h \
library/configRead.h library/dynamicVectors.h library/../ftpData.h \
library/fileManagement.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
ftpServer.h:
ftpCommandsElaborate.h:
ftpData.h:
library/dynamicVectors.h:
library/configRead.h:
library/dynamicVectors.h:
library/../ftpData.h:
library/fileManagement.h:

Binary file not shown.

View File

@ -1,33 +0,0 @@
build/Debug/GNU-Linux/ftpServer.o: ftpServer.c library/dynamicVectors.h \
library/fileManagement.h library/dynamicVectors.h ftpServer.h ftpData.h \
library/dynamicVectors.h ftpCommandsElaborate.h library/fileManagement.h \
library/logFunctions.h library/configRead.h library/dynamicVectors.h \
library/../ftpData.h library/signals.h library/connection.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
ftpServer.h:
ftpData.h:
library/dynamicVectors.h:
ftpCommandsElaborate.h:
library/fileManagement.h:
library/logFunctions.h:
library/configRead.h:
library/dynamicVectors.h:
library/../ftpData.h:
library/signals.h:
library/connection.h:

View File

@ -1,23 +0,0 @@
build/Debug/GNU-Linux/library/configRead.o: library/configRead.c \
library/dynamicVectors.h library/fileManagement.h \
library/dynamicVectors.h library/configRead.h library/dynamicVectors.h \
library/../ftpData.h library/../library/dynamicVectors.h \
library/fileManagement.h library/daemon.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
library/configRead.h:
library/dynamicVectors.h:
library/../ftpData.h:
library/../library/dynamicVectors.h:
library/fileManagement.h:
library/daemon.h:

View File

@ -1,16 +0,0 @@
build/Debug/GNU-Linux/library/connection.o: library/connection.c \
library/dynamicVectors.h library/fileManagement.h \
library/dynamicVectors.h library/../ftpData.h \
library/../library/dynamicVectors.h library/connection.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
library/../ftpData.h:
library/../library/dynamicVectors.h:
library/connection.h:

View File

@ -1,11 +0,0 @@
build/Debug/GNU-Linux/library/daemon.o: library/daemon.c \
library/dynamicVectors.h library/fileManagement.h \
library/dynamicVectors.h library/fileManagement.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
library/fileManagement.h:

View File

@ -1,11 +0,0 @@
build/Debug/GNU-Linux/library/dynamicVectors.o: library/dynamicVectors.c \
library/dynamicVectors.h library/fileManagement.h \
library/dynamicVectors.h library/dynamicVectors.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
library/dynamicVectors.h:

View File

@ -1,14 +0,0 @@
build/Debug/GNU-Linux/library/fileManagement.o: library/fileManagement.c \
library/dynamicVectors.h library/fileManagement.h \
library/dynamicVectors.h library/fileManagement.h \
library/dynamicVectors.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:

View File

@ -1,11 +0,0 @@
build/Debug/GNU-Linux/library/logFunctions.o: library/logFunctions.c \
library/dynamicVectors.h library/fileManagement.h \
library/dynamicVectors.h library/logFunctions.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
library/logFunctions.h:

View File

@ -1,11 +0,0 @@
build/Debug/GNU-Linux/library/signals.o: library/signals.c \
library/dynamicVectors.h library/fileManagement.h \
library/dynamicVectors.h library/../ftpServer.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
library/../ftpServer.h:

Binary file not shown.

View File

@ -1,10 +0,0 @@
build/Debug/GNU-Linux/uFTP.o: uFTP.c library/dynamicVectors.h \
library/fileManagement.h library/dynamicVectors.h ftpServer.h
library/dynamicVectors.h:
library/fileManagement.h:
library/dynamicVectors.h:
ftpServer.h:

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -40,6 +40,7 @@
#include "library/logFunctions.h"
#include "library/fileManagement.h"
#include "library/configRead.h"
#include "library/openSsl.h"
#include "ftpCommandsElaborate.h"
@ -214,13 +215,29 @@ int parseCommandPass(ftpDataType * data, int socketId)
}
}
int parseCommandAuth(clientDataType *theClientData)
int parseCommandAuth(clientDataType *theClientData, SSL_CTX *ctx)
{
int returnCode;
returnCode = dprintf(theClientData->socketDescriptor, "502 Security extensions not implemented.\r\n");
//returnCode = dprintf(theClientData->socketDescriptor, "502 Security extensions not implemented.\r\n");
returnCode = dprintf(theClientData->socketDescriptor, "234 AUTH TLS OK..\r\n");
if (returnCode <= 0)
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
theClientData->tlsIsEnabled = 1;
SSL *ssl;
ssl = SSL_new(ctx);
SSL_set_fd(ssl, theClientData->socketDescriptor);
if (SSL_accept(ssl) <= 0) {
printf("\nSSL ERRORS");
ERR_print_errors_fp(stderr);
}
else {
printf("\nSSL ACCEPTED");
SSL_write(ssl, "ciao prova\r\n", strlen("ciao prova\r\n"));
}
//client -> AUTH TLS
//server -> 234 AUTH TLS OK.
@ -272,7 +289,7 @@ int parseCommandFeat(clientDataType *theClientData)
211 End.
*/
int returnCode;
returnCode = dprintf(theClientData->socketDescriptor, "211-Extensions supported:\r\n PASV\r\nUTF8\r\n211 End.\r\n");
returnCode = dprintf(theClientData->socketDescriptor, "211-Extensions supported:\r\n PASV\r\nUTF8\r\nAUTH TLS\r\n211 End.\r\n");
if (returnCode <= 0)
return FTP_COMMAND_PROCESSED_WRITE_ERROR;

View File

@ -37,7 +37,8 @@
#define FTP_CHMODE_COMMAND_RETURN_CODE_NO_FILE 2
#define FTP_CHMODE_COMMAND_RETURN_CODE_NO_PERMISSIONS 3
#define FTP_CHMODE_COMMAND_RETURN_NAME_TOO_LONG 4
#include <openssl/ssl.h>
#include <openssl/err.h>
#include "ftpData.h"
#ifdef __cplusplus
@ -49,7 +50,7 @@ extern "C" {
int parseCommandUser(clientDataType *theClientData);
int parseCommandSite(clientDataType *theClientData);
int parseCommandPass(ftpDataType * data, int socketId);
int parseCommandAuth(clientDataType *theClientData);
int parseCommandAuth(clientDataType *theClientData, SSL_CTX *);
int parseCommandPwd(clientDataType *theClientData);
int parseCommandSyst(clientDataType *theClientData);
int parseCommandFeat(clientDataType *theClientData);

View File

@ -27,6 +27,8 @@
#define FTPDATA_H
#include <netinet/in.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include "library/dynamicVectors.h"
@ -50,7 +52,6 @@ struct parameter
char* value;
} typedef parameter_DataType;
struct ownerShip
{
int ownerShipSet;
@ -116,6 +117,8 @@ struct ipData
struct workerData
{
int threadIsAlive;
int connectionPort;
int passiveModeOn;
@ -147,6 +150,9 @@ struct workerData
struct clientData
{
SSL *ssl;
int tlsIsEnabled;
int clientProgressiveNumber;
int socketDescriptor;
int socketIsConnected;
@ -202,6 +208,7 @@ struct ConnectionParameters
struct ftpData
{
int connectedClients;
char welcomeMessage[1024];
ConnectionData_DataType connectionData;

View File

@ -47,10 +47,11 @@
#include "library/logFunctions.h"
#include "library/configRead.h"
#include "library/signals.h"
#include "library/openSsl.h"
#include "library/connection.h"
ftpDataType ftpData;
SSL_CTX *ctx;
static int processCommand(int processingElement);
void workerCleanup(void *socketId)
@ -325,9 +326,11 @@ void *connectionWorkerHandle(void * socketId)
void runFtpServer(void)
{
printf("\nHello uFTP server v%s starting..\n", UFTP_SERVER_VERSION);
/* Needed for Select*/
static int processingSock = 0, returnCode = 0;
@ -352,6 +355,10 @@ void runFtpServer(void)
/* the maximum socket fd is now the main socket descriptor */
ftpData.connectionData.maxSocketFD = ftpData.connectionData.theMainSocket+1;
init_openssl();
ctx = create_context();
configure_context(ctx);
//Endless loop ftp process
while (1)
@ -359,9 +366,7 @@ void runFtpServer(void)
/* waits for socket activity, if no activity then checks for client socket timeouts */
if (selectWait(&ftpData) == 0)
{
checkClientConnectionTimeout(&ftpData);
flushLoginWrongTriesData(&ftpData);
}
@ -518,7 +523,38 @@ static int processCommand(int processingElement)
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "AUTH", strlen("AUTH")) == 1)
{
printf("\nAUTH COMMAND RECEIVED");
toReturn = parseCommandAuth(&ftpData.clients[processingElement]);
int returnCode;
//returnCode = dprintf(theClientData->socketDescriptor, "502 Security extensions not implemented.\r\n");
returnCode = dprintf(ftpData.clients[processingElement].socketDescriptor, "234 AUTH TLS OK..\r\n");
ftpData.clients[processingElement].tlsIsEnabled = 1;
SSL *ssl;
ssl = SSL_new(ctx);
SSL_set_fd(ssl, ftpData.clients[processingElement].socketDescriptor);
if (SSL_accept(ssl) <= 0) {
printf("\nSSL ERRORS");
ERR_print_errors_fp(stderr);
}
else {
printf("\nSSL ACCEPTED");
SSL_write(ssl, "ciao prova\r\n", strlen("ciao prova\r\n"));
}
char buffer[100];
int readenb = 0;
while(1)
{
readenb = SSL_read(ssl, buffer, 100);
if (readenb > 0)
printf("\nSslReaden: %s", buffer);
sleep(1);
}
// toReturn = parseCommandAuth(&ftpData.clients[processingElement], ctx);
}
else if(compareStringCaseInsensitive(ftpData.clients[processingElement].theCommandReceived, "PWD", strlen("PWD")) == 1)
{

View File

@ -44,6 +44,7 @@ OBJECTFILES= \
${OBJECTDIR}/library/dynamicVectors.o \
${OBJECTDIR}/library/fileManagement.o \
${OBJECTDIR}/library/logFunctions.o \
${OBJECTDIR}/library/openSsl.o \
${OBJECTDIR}/library/signals.o \
${OBJECTDIR}/uFTP.o
@ -117,6 +118,11 @@ ${OBJECTDIR}/library/logFunctions.o: library/logFunctions.c
${RM} "$@.d"
$(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/logFunctions.o library/logFunctions.c
${OBJECTDIR}/library/openSsl.o: library/openSsl.c
${MKDIR} -p ${OBJECTDIR}/library
${RM} "$@.d"
$(COMPILE.c) -g -D_LARGEFILE64_SOURCE -Ilibrary -include library/dynamicVectors.h -include library/fileManagement.h -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/openSsl.o library/openSsl.c
${OBJECTDIR}/library/signals.o: library/signals.c
${MKDIR} -p ${OBJECTDIR}/library
${RM} "$@.d"

View File

@ -44,6 +44,7 @@ OBJECTFILES= \
${OBJECTDIR}/library/dynamicVectors.o \
${OBJECTDIR}/library/fileManagement.o \
${OBJECTDIR}/library/logFunctions.o \
${OBJECTDIR}/library/openSsl.o \
${OBJECTDIR}/library/signals.o \
${OBJECTDIR}/uFTP.o
@ -117,6 +118,11 @@ ${OBJECTDIR}/library/logFunctions.o: library/logFunctions.c
${RM} "$@.d"
$(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/logFunctions.o library/logFunctions.c
${OBJECTDIR}/library/openSsl.o: library/openSsl.c
${MKDIR} -p ${OBJECTDIR}/library
${RM} "$@.d"
$(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/library/openSsl.o library/openSsl.c
${OBJECTDIR}/library/signals.o: library/signals.c
${MKDIR} -p ${OBJECTDIR}/library
${RM} "$@.d"

View File

@ -10,6 +10,7 @@
<itemPath>library/dynamicVectors.h</itemPath>
<itemPath>library/fileManagement.h</itemPath>
<itemPath>library/logFunctions.h</itemPath>
<itemPath>library/openSsl.h</itemPath>
<itemPath>library/signals.h</itemPath>
</logicalFolder>
<itemPath>library/daemon.h</itemPath>
@ -33,6 +34,7 @@
<itemPath>library/dynamicVectors.c</itemPath>
<itemPath>library/fileManagement.c</itemPath>
<itemPath>library/logFunctions.c</itemPath>
<itemPath>library/openSsl.c</itemPath>
<itemPath>library/signals.c</itemPath>
</logicalFolder>
<itemPath>MakeFileGeneric</itemPath>
@ -124,6 +126,10 @@
</item>
<item path="library/logFunctions.h" ex="false" tool="3" flavor2="0">
</item>
<item path="library/openSsl.c" ex="false" tool="0" flavor2="0">
</item>
<item path="library/openSsl.h" ex="false" tool="3" flavor2="0">
</item>
<item path="library/signals.c" ex="false" tool="0" flavor2="0">
</item>
<item path="library/signals.h" ex="false" tool="3" flavor2="0">
@ -197,6 +203,10 @@
</item>
<item path="library/logFunctions.h" ex="false" tool="3" flavor2="0">
</item>
<item path="library/openSsl.c" ex="false" tool="0" flavor2="0">
</item>
<item path="library/openSsl.h" ex="false" tool="3" flavor2="0">
</item>
<item path="library/signals.c" ex="false" tool="0" flavor2="0">
</item>
<item path="library/signals.h" ex="false" tool="3" flavor2="0">

View File

@ -13,8 +13,6 @@
<gdb_interceptlist>
<gdbinterceptoptions gdb_all="false" gdb_unhandled="true" gdb_unexpected="true"/>
</gdb_interceptlist>
<gdb_signals>
</gdb_signals>
<gdb_options>
<DebugOptions>
</DebugOptions>

View File

@ -6,6 +6,16 @@
</data>
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
<group>
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpData.c</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/library/openSsl.h</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpCommandElaborate.c</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpServer.c</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/MakeFileGeneric</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/library/openSsl.c</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpData.h</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/library/configRead.c</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpCommandsElaborate.h</file>
</group>
</open-files>
</project-private>

View File

@ -13,7 +13,7 @@ FTP_PORT = 21
SINGLE_INSTANCE = true
#Allow only one server instance (true or false)
DAEMON_MODE = true
DAEMON_MODE = false
#Run in background, daemon mode ok
IDLE_MAX_TIMEOUT = 3600