diff --git a/lib/irc.h b/lib/irc.h index e60bb2c..d5ee148 100755 --- a/lib/irc.h +++ b/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, ...); diff --git a/mods/openssl/openssl.c b/mods/openssl/openssl.c new file mode 100644 index 0000000..e873dc2 --- /dev/null +++ b/mods/openssl/openssl.c @@ -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 +#include +#include + +#include +#include + +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"); + +} diff --git a/src/irc.c b/src/irc.c index 84f3c53..d158df7 100755 --- a/src/irc.c +++ b/src/irc.c @@ -28,8 +28,6 @@ #include #include #include -#include -#include #define FDOPEN fdopen #define SETBUF setbuf #endif