working on openssl module
This commit is contained in:
parent
05d0d11e05
commit
fa4fdbb663
10
lib/irc.h
10
lib/irc.h
@ -52,6 +52,13 @@ struct irc_conn
|
||||
#else
|
||||
bool use_ssl;
|
||||
bool verify_ssl;
|
||||
bool sslmod_loaded;
|
||||
|
||||
void (*sslmod_connect)();
|
||||
int (*sslmod_read)();
|
||||
int (*sslmod_write)();
|
||||
void (*sslmod_cleanup)();
|
||||
|
||||
#endif
|
||||
|
||||
char db_file[256];
|
||||
@ -67,6 +74,9 @@ typedef struct handler event_handler;
|
||||
|
||||
void irc_connect(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_privmsg(struct irc_conn *bot, char *to, char *fmt, ...);
|
||||
|
71
mods/openssl/openssl.c
Normal file
71
mods/openssl/openssl.c
Normal 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");
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user