[Add] Added the SSL plugin. Can't be certain if it even works yet
though.
This commit is contained in:
parent
d3a1a6ba83
commit
f1600194c1
3
Makefile
3
Makefile
@ -1,7 +1,8 @@
|
|||||||
default:
|
default:
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
mkdir -p bin/base
|
mkdir -p bin/base
|
||||||
cd base && make clean
|
cd base && make
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -Rf bin/
|
rm -Rf bin/
|
||||||
cd base && make clean
|
cd base && make clean
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
default:
|
default:
|
||||||
cd network_plain && make
|
cd network_plain && make
|
||||||
cd network_ssl && make
|
cd network_ssl && make
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
cd network_plain && make clean
|
cd network_plain && make clean
|
||||||
cd network_ssl && make clean
|
cd network_ssl && make clean
|
||||||
|
@ -1,5 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define PLUGIN_TYPE_NETWOR 0x1
|
#define PLUGIN_TYPE_NETWORK 0x1
|
||||||
|
|
||||||
void configErrorPush(const char* err);
|
void configErrorPush(const char* err);
|
||||||
|
|
||||||
|
/* This is the common API for plugins. */
|
||||||
|
unsigned int pluginType();
|
||||||
|
const char* pluginName();
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#ifndef __NETWORK_H__
|
||||||
|
/* This one's for network plugins. */
|
||||||
|
void* pluginConnect(const char* host, int port);
|
||||||
|
int pluginSocketGet(void* connection);
|
||||||
|
int pluginReadData(void* connection, char* buffer, int buffer_len);
|
||||||
|
int pluginSendData(void* connection, const char* buffer, int buffer_len);
|
||||||
|
void* pluginSocketDone(void* connection);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
8
base/network_plain/Makefile
Normal file
8
base/network_plain/Makefile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
SRC = network.c
|
||||||
|
OUTPUT = network_plain.so
|
||||||
|
CFLAGS += -fPIC -shared -Wl,-soname,network_plain.so -O3 -Wall -I../
|
||||||
|
|
||||||
|
default:
|
||||||
|
$(CC) $(CFLAGS) $(SRC) -o ../../bin/base/$(OUTPUT) $(LDFLAGS)
|
||||||
|
|
||||||
|
clean:
|
@ -6,7 +6,7 @@ unsigned int pluginType() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char* pluginName() {
|
const char* pluginName() {
|
||||||
return* "plain";
|
return "plain";
|
||||||
}
|
}
|
||||||
|
|
||||||
void* pluginConnect(const char* host, int port) {
|
void* pluginConnect(const char* host, int port) {
|
||||||
@ -53,7 +53,7 @@ int pluginReadData(NETWORK_PLAIN* connection, char* buffer, int buffer_len) {
|
|||||||
return recv(connection->socket, buffer, buffer_len, 0);
|
return recv(connection->socket, buffer, buffer_len, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pluginSendData(NETWORK_PLAI* connection, char* buffer, int buffer_len) {
|
int pluginSendData(NETWORK_PLAIN* connection, char* buffer, int buffer_len) {
|
||||||
return send(connection->socket, buffer, buffer_len, 0);
|
return send(connection->socket, buffer, buffer_len, 0);
|
||||||
}
|
}
|
||||||
|
|
@ -1,3 +1,9 @@
|
|||||||
|
SRC = network.c
|
||||||
|
OUTPUT = ../../bin/base/network_ssl.so
|
||||||
|
CFLAGS += -fPIC -shared -Wl,-soname,network_ssl.so -O3 -Wall -I../
|
||||||
|
LDFlags += -lssl
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
$(CC) $(SRC) -o $(OUTPUT) $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
73
base/network_ssl/network.c
Normal file
73
base/network_ssl/network.c
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#include <config/api.h>
|
||||||
|
#include "network.h"
|
||||||
|
|
||||||
|
unsigned int pluginType() {
|
||||||
|
return PLUGIN_TYPE_NETWORK;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* pluginName() {
|
||||||
|
return "ssl";
|
||||||
|
}
|
||||||
|
|
||||||
|
void* pluginConnect(const char* host, int port) {
|
||||||
|
NETWORK_SSL* connection;
|
||||||
|
|
||||||
|
if((connection = malloc(sizeof(BIO))) == NULL) {
|
||||||
|
configErrorPush("Unable to malloc");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
connection->ctx == SSL_CTX_new(SSLv23_client_method());
|
||||||
|
|
||||||
|
if((connection->bio = BIO_new_ssl_connect(connection->ctx)) == NULL) {
|
||||||
|
configErrorPush("Unable to allocate a BIO");
|
||||||
|
free(connection);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
BIO_get_SSL(connection->bio, &connection->ssl);
|
||||||
|
SSL_set_mode(connection->ssl, SSL_MODE_AUTO_RETRY);
|
||||||
|
BIO_set_conn_hostname(connection->bio, host);
|
||||||
|
BIO_set_conn_int_port(connection->bio, &port);
|
||||||
|
|
||||||
|
if(BIO_do_connect(connection->bio) <= 0) {
|
||||||
|
configErrorPush("Unable to connect");
|
||||||
|
free(connection);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pluginSocketGet(NETWORK_SSL* connection) {
|
||||||
|
return BIO_get_fd(connection->bio, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int pluginReadData(NETWORK_SSL* connection, char* buffer, int buffer_len) {
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if((ret == BIO_read(connection->bio, buffer, buffer_len)) == 0)
|
||||||
|
return ECONNRESET;
|
||||||
|
else if(ret == -1)
|
||||||
|
return (!BIO_should_retry(connection->bio)) ? ECONNRESET : EWOULDBLOCK;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pluginSendData(NETWORK_SSL* connection, const char* buffer, int buffer_len) {
|
||||||
|
int ret;
|
||||||
|
if((ret = BIO_write(connection->bio, buffer, buffer_len)) <= 0) {
|
||||||
|
if(!BIO_should_retry(connection->bio))
|
||||||
|
return ECONNRESET;
|
||||||
|
return EWOULDBLOCK;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* pluginSocketDone(NETWORK_SSL* connection) {
|
||||||
|
BIO_free_all(connection->bio);
|
||||||
|
SSL_CTX_free(connection->ctx);
|
||||||
|
|
||||||
|
free(connection);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
16
base/network_ssl/network.h
Normal file
16
base/network_ssl/network.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <openssl/bio.h>
|
||||||
|
#include <openssl/ssl.h>
|
||||||
|
#include <openssl/err.h>
|
||||||
|
|
||||||
|
#include <config/api.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
BIO* bio;
|
||||||
|
SSL_CTX* ctx;
|
||||||
|
SSL* ssl;
|
||||||
|
} NETWORK_SSL;
|
BIN
bin/base/network_plain.so
Executable file
BIN
bin/base/network_plain.so
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user