working on openssl module

This commit is contained in:
Aaron Blakely 2024-03-14 00:44:56 -05:00
parent 05d0d11e05
commit fa4fdbb663
3 changed files with 81 additions and 2 deletions

View File

@ -52,6 +52,13 @@ struct irc_conn
#else #else
bool use_ssl; bool use_ssl;
bool verify_ssl; bool verify_ssl;
bool sslmod_loaded;
void (*sslmod_connect)();
int (*sslmod_read)();
int (*sslmod_write)();
void (*sslmod_cleanup)();
#endif #endif
char db_file[256]; char db_file[256];
@ -67,6 +74,9 @@ typedef struct handler event_handler;
void irc_connect(struct irc_conn *bot); void irc_connect(struct irc_conn *bot);
void irc_auth(struct irc_conn *bot); void irc_auth(struct irc_conn *bot);
void set_ssl_connect(struct irc_conn *bot, void *func);
void set_ssl_read(struct irc_conn *bot, void *func);
void set_ssl_write(struct irc_conn *bot, void *func);
MY_API void irc_notice(struct irc_conn *bot, char *to, char *fmt, ...); MY_API void irc_notice(struct irc_conn *bot, char *to, char *fmt, ...);
MY_API void irc_privmsg(struct irc_conn *bot, char *to, char *fmt, ...); MY_API void irc_privmsg(struct irc_conn *bot, char *to, char *fmt, ...);

71
mods/openssl/openssl.c Normal file
View File

@ -0,0 +1,71 @@
#define MY_DLL_EXPORTS 1
#include "util.h"
#include "irc.h"
#include "events.h"
#include "module.h"
#include "timers.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
int ssl_fd;
SSL *ssl;
SSL_CTX *ctx;
MY_API void sslmod_init(struct irc_conn *bot)
{
SSL_library_init();
SSL_load_error_strings();
ctx = SSL_CTX_new(SSLv23_client_method());
if (ctx == NULL)
{
eprint("Error: Cannot create SSL context\n");
}
if (bot->verify_ssl)
{
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
}
else
{
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
}
if ((ssl = SSL_new(ctx)) == NULL)
{
eprint("Error: Cannot create SSL object\n");
}
}
MY_API void sslmod_connect(struct irc_conn *bot)
{
if (SSL_set_fd(ssl, fileno(bot->srv_fd)) == 0)
{
eprint("Error: Cannot set SSL file descriptor\n");
}
if (SSL_connect(ssl) != 1)
{
eprint("Error: Cannot connect to SSL server\n");
}
ssl_fd = fileno(bot->srv_fd);
}
MY_API void mod_init()
{
register_module("openssl", "Aaron Blakely", "1.0", "SSL/TLS support using OpenSSL");
}
MY_API void mod_unlaod()
{
unregister_module("openssl");
}

View File

@ -28,8 +28,6 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define FDOPEN fdopen #define FDOPEN fdopen
#define SETBUF setbuf #define SETBUF setbuf
#endif #endif