irssiproxy: Remove openssl ifdefs, and several style fixes

This commit is contained in:
dequis 2015-06-27 11:59:41 -03:00
parent 3c351ba018
commit 87542831fe
4 changed files with 36 additions and 67 deletions

View File

@ -33,17 +33,15 @@
void proxy_send(CLIENT_REC *client, char *d, int l) void proxy_send(CLIENT_REC *client, char *d, int l)
{ {
#ifdef HAVE_OPENSSL
if(client->listen->use_ssl) { if(client->listen->use_ssl) {
SSL_write(client->ssl, d, l); SSL_write(client->ssl, d, l);
} else return;
#endif }
net_sendbuffer_send(client->handle, d, l); net_sendbuffer_send(client->handle, d, l);
} }
int proxy_readline(CLIENT_REC *client, char **str) int proxy_readline(CLIENT_REC *client, char **str)
{ {
#ifdef HAVE_OPENSSL
if(client->listen->use_ssl) { if(client->listen->use_ssl) {
char tmpbuf[2048]; char tmpbuf[2048];
int recvlen = 0; int recvlen = 0;
@ -61,9 +59,8 @@ int proxy_readline(CLIENT_REC *client, char **str)
} }
return recvlen; /* if any other error occurs, this will quit the connection */ return recvlen; /* if any other error occurs, this will quit the connection */
} }
} else }
#endif return net_sendbuffer_receive_line(client->handle, str, 1);
return net_sendbuffer_receive_line(client->handle, str, 1);
} }
void proxy_outdata(CLIENT_REC *client, const char *data, ...) void proxy_outdata(CLIENT_REC *client, const char *data, ...)

View File

@ -50,11 +50,9 @@ static void remove_client(CLIENT_REC *rec)
printtext(rec->server, NULL, MSGLEVEL_CLIENTNOTICE, printtext(rec->server, NULL, MSGLEVEL_CLIENTNOTICE,
"Proxy: Client %s:%d disconnected", rec->host, rec->port); "Proxy: Client %s:%d disconnected", rec->host, rec->port);
#ifdef HAVE_OPENSSL
if(rec->listen->use_ssl) { if(rec->listen->use_ssl) {
SSL_free(rec->ssl); SSL_free(rec->ssl);
} }
#endif
g_free(rec->proxy_address); g_free(rec->proxy_address);
net_sendbuffer_destroy(rec->handle, TRUE); net_sendbuffer_destroy(rec->handle, TRUE);
g_source_remove(rec->recv_tag); g_source_remove(rec->recv_tag);
@ -138,12 +136,10 @@ static void handle_client_connect_cmd(CLIENT_REC *client,
"Proxy: Client %s:%d connected", "Proxy: Client %s:%d connected",
client->host, client->port); client->host, client->port);
client->connected = TRUE; client->connected = TRUE;
#ifdef HAVE_OPENSSL if(client->listen->use_ssl) {
if(client->listen->use_ssl) { printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, "Proxy: Client connected from %s using encryption %s and logged in!", client->host, SSL_get_cipher(client->ssl));
"Proxy: Client connected from %s using encryption %s and logged in!", client->host, SSL_get_cipher(client->ssl)); }
}
#endif
proxy_dump_data(client); proxy_dump_data(client);
} }
@ -363,7 +359,6 @@ static void sig_listen(LISTEN_REC *listen)
sendbuf = net_sendbuffer_create(handle, 0); sendbuf = net_sendbuffer_create(handle, 0);
rec = g_new0(CLIENT_REC, 1); rec = g_new0(CLIENT_REC, 1);
#ifdef HAVE_OPENSSL
if(listen->use_ssl) { if(listen->use_ssl) {
rec->ssl = SSL_new(listen->ssl_ctx); rec->ssl = SSL_new(listen->ssl_ctx);
SSL_set_fd(rec->ssl, g_io_channel_unix_get_fd(handle)); SSL_set_fd(rec->ssl, g_io_channel_unix_get_fd(handle));
@ -380,7 +375,6 @@ static void sig_listen(LISTEN_REC *listen)
} }
} }
} }
#endif
rec->listen = listen; rec->listen = listen;
rec->handle = sendbuf; rec->handle = sendbuf;
@ -653,7 +647,6 @@ static void add_listen(const char *ircnet, int port, char *sslcert)
} }
if(sslcert != NULL) { if(sslcert != NULL) {
#ifdef HAVE_OPENSSL
rec->use_ssl = TRUE; rec->use_ssl = TRUE;
rec->ssl_method = SSLv3_server_method(); /* let's start with 3 */ rec->ssl_method = SSLv3_server_method(); /* let's start with 3 */
rec->ssl_ctx = SSL_CTX_new(rec->ssl_method); rec->ssl_ctx = SSL_CTX_new(rec->ssl_method);
@ -662,39 +655,33 @@ static void add_listen(const char *ircnet, int port, char *sslcert)
"Proxy: Error setting up SSL Context for port %d failed.", "Proxy: Error setting up SSL Context for port %d failed.",
rec->port); rec->port);
g_free(rec->ircnet); g_free(rec->ircnet);
g_free(rec); g_free(rec);
return; return;
} }
if(SSL_CTX_use_certificate_file(rec->ssl_ctx, sslcert, SSL_FILETYPE_PEM) <= 0) { if(SSL_CTX_use_certificate_file(rec->ssl_ctx, sslcert, SSL_FILETYPE_PEM) <= 0) {
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Proxy: Error loading certificate."); printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Proxy: Error loading certificate.");
SSL_CTX_free(rec->ssl_ctx); SSL_CTX_free(rec->ssl_ctx);
g_free(rec->ircnet); g_free(rec->ircnet);
g_free(rec); g_free(rec);
return; return;
} }
if(SSL_CTX_use_PrivateKey_file(rec->ssl_ctx, sslcert, SSL_FILETYPE_PEM) <= 0) { if(SSL_CTX_use_PrivateKey_file(rec->ssl_ctx, sslcert, SSL_FILETYPE_PEM) <= 0) {
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Proxy: Error loading private key."); printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Proxy: Error loading private key.");
SSL_CTX_free(rec->ssl_ctx); SSL_CTX_free(rec->ssl_ctx);
g_free(rec->ircnet); g_free(rec->ircnet);
g_free(rec); g_free(rec);
return; return;
} }
if(!SSL_CTX_check_private_key(rec->ssl_ctx)) { if(!SSL_CTX_check_private_key(rec->ssl_ctx)) {
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Proxy: Error loading checking certificate agains private key."); printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Proxy: Error loading checking certificate agains private key.");
SSL_CTX_free(rec->ssl_ctx); SSL_CTX_free(rec->ssl_ctx);
g_free(rec->ircnet); g_free(rec->ircnet);
g_free(rec); g_free(rec);
return; return;
} }
#else
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
"Proxy: Specified SSL certificate/private key but irssi compiled WITHOUT OpenSSL!");
#endif
} }
rec->tag = g_input_add(rec->handle, G_INPUT_READ, rec->tag = g_input_add(rec->handle, G_INPUT_READ,
@ -711,11 +698,9 @@ static void remove_listen(LISTEN_REC *rec)
remove_client(rec->clients->data); remove_client(rec->clients->data);
net_disconnect(rec->handle); net_disconnect(rec->handle);
#ifdef HAVE_OPENSSL
if(rec->use_ssl) { if(rec->use_ssl) {
SSL_CTX_free(rec->ssl_ctx); SSL_CTX_free(rec->ssl_ctx);
} }
#endif
g_source_remove(rec->tag); g_source_remove(rec->tag);
g_free(rec->ircnet); g_free(rec->ircnet);
g_free(rec); g_free(rec);

View File

@ -78,10 +78,8 @@ void irc_proxy_init(void)
settings_add_str("irssiproxy", "irssiproxy_bind", ""); settings_add_str("irssiproxy", "irssiproxy_bind", "");
settings_add_bool("irssiproxy", "irssiproxy", TRUE); settings_add_bool("irssiproxy", "irssiproxy", TRUE);
#ifdef HAVE_OPENSSL
SSL_load_error_strings(); SSL_load_error_strings();
OpenSSL_add_ssl_algorithms(); OpenSSL_add_ssl_algorithms();
#endif
if (*settings_get_str("irssiproxy_password") == '\0') { if (*settings_get_str("irssiproxy_password") == '\0') {
/* no password - bad idea! */ /* no password - bad idea! */
@ -93,14 +91,9 @@ void irc_proxy_init(void)
if (*settings_get_str("irssiproxy_ports") == '\0') { if (*settings_get_str("irssiproxy_ports") == '\0') {
signal_emit("gui dialog", 2, "warning", signal_emit("gui dialog", 2, "warning",
"No proxy ports specified. Use /set " "No proxy ports specified. Use /set "
#ifdef HAVE_OPENSSL
"irssiproxy_ports <ircnet>=<port> <ircnet2>=<port2>:<sslcert> " "irssiproxy_ports <ircnet>=<port> <ircnet2>=<port2>:<sslcert> "
"... to set them. You can add :filename.pem to secure the proxy with SSL." "... to set them. You can add :filename.pem to secure the proxy with SSL."
" (Should contain a cert and key in PEM format)"); " (Should contain a cert and key in PEM format)");
#else
"irssiproxy_ports <ircnet>=<port> <ircnet2>=<port2> "
"... to set them.");
#endif
} }

View File

@ -7,14 +7,12 @@
#include "irc.h" #include "irc.h"
#include "irc-servers.h" #include "irc-servers.h"
#ifdef HAVE_OPENSSL
#include <openssl/rsa.h> #include <openssl/rsa.h>
#include <openssl/crypto.h> #include <openssl/crypto.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/err.h> #include <openssl/err.h>
#endif
typedef struct { typedef struct {
int port; int port;
@ -24,11 +22,9 @@ typedef struct {
GIOChannel *handle; GIOChannel *handle;
GSList *clients; GSList *clients;
#ifdef HAVE_OPENSSL
unsigned int use_ssl; unsigned int use_ssl;
SSL_CTX *ssl_ctx; SSL_CTX *ssl_ctx;
SSL_METHOD *ssl_method; SSL_METHOD *ssl_method;
#endif
} LISTEN_REC; } LISTEN_REC;
typedef struct { typedef struct {
@ -43,9 +39,7 @@ typedef struct {
unsigned int user_sent:1; unsigned int user_sent:1;
unsigned int connected:1; unsigned int connected:1;
unsigned int want_ctcp:1; unsigned int want_ctcp:1;
#ifdef HAVE_OPENSSL
SSL *ssl; SSL *ssl;
#endif
} CLIENT_REC; } CLIENT_REC;
#endif #endif