/*
* ngIRCd -- The Next Generation IRC Daemon
- *
- * SSL wrapper functions.
* Copyright (c) 2005-2008 Florian Westphal <fw@strlen.de>
*/
#include "portab.h"
+
+/**
+ * @file
+ * SSL wrapper functions
+ */
+
#include "imp.h"
#include "conf-ssl.h"
#include <unistd.h>
#include <gnutls/x509.h>
-#define DH_BITS 1024
+#define DH_BITS 2048
+#define DH_BITS_MIN 1024
+
static gnutls_certificate_credentials_t x509_cred;
static gnutls_dh_params_t dh_params;
-
static bool ConnSSL_LoadServerKey_gnutls PARAMS(( void ));
#endif
bool ret = true;
if (!Conf_SSLOptions.DHFile) {
- Log(LOG_NOTICE, "Configuration option \"SSLDHFile\" not set!");
+ Log(LOG_NOTICE, "Configuration option \"DHFile\" not set!");
return false;
}
fp = fopen(Conf_SSLOptions.DHFile, "r");
}
if (need_dhgenerate) {
Log(LOG_WARNING,
- "SSLDHFile not set, generating %u bit DH parameters. This may take a while ...",
+ "DHFile not set, generating %u bit DH parameters. This may take a while ...",
DH_BITS);
err = gnutls_dh_params_generate2(tmp_dh_params, DH_BITS);
if (err < 0) {
bool
ConnSSL_InitLibrary( void )
{
+ if (!Conf_SSLInUse()) {
+ LogDebug("SSL not in use, skipping initialization.");
+ return true;
+ }
+
#ifdef HAVE_LIBSSL
SSL_CTX *newctx;
* According to OpenSSL RAND_egd(3): "The automatic query of /var/run/egd-pool et al was added in OpenSSL 0.9.7";
* so it makes little sense to deal with PRNGD seeding ourselves.
*/
+ array_free(&Conf_SSLOptions.ListenPorts);
return false;
}
newctx = SSL_CTX_new(SSLv23_method());
if (!newctx) {
LogOpenSSLError("SSL_CTX_new()", NULL);
+ array_free(&Conf_SSLOptions.ListenPorts);
return false;
}
return true;
out:
SSL_CTX_free(newctx);
+ array_free(&Conf_SSLOptions.ListenPorts);
return false;
#endif
#ifdef HAVE_LIBGNUTLS
err = gnutls_global_init();
if (err) {
Log(LOG_ERR, "gnutls_global_init(): %s", gnutls_strerror(err));
+ array_free(&Conf_SSLOptions.ListenPorts);
return false;
}
- if (!ConnSSL_LoadServerKey_gnutls())
+ if (!ConnSSL_LoadServerKey_gnutls()) {
+ array_free(&Conf_SSLOptions.ListenPorts);
return false;
+ }
Log(LOG_INFO, "gnutls %s initialized.", gnutls_check_version(NULL));
initialized = true;
return true;
cert_file = Conf_SSLOptions.CertFile ? Conf_SSLOptions.CertFile:Conf_SSLOptions.KeyFile;
if (!cert_file) {
- Log(LOG_NOTICE, "No SSL server key configured, SSL disabled.");
+ Log(LOG_ERR, "No SSL server key configured!");
return false;
}
assert(ctx);
if (!Conf_SSLOptions.KeyFile) {
- Log(LOG_NOTICE, "No SSL server key configured, SSL disabled.");
+ Log(LOG_ERR, "No SSL server key configured!");
return false;
}
int ret;
assert(c != NULL);
#ifdef HAVE_LIBSSL
- if (!ssl_ctx) /* NULL when library initialization failed */
+ if (!ssl_ctx) {
+ Log(LOG_ERR, "Cannot init ssl_ctx: OpenSSL initialization failed at startup");
return false;
-
+ }
assert(c->ssl_state.ssl == NULL);
c->ssl_state.ssl = SSL_new(ssl_ctx);
ConnSSL_Free(c);
return false;
}
- gnutls_dh_set_prime_bits(c->ssl_state.gnutls_session, DH_BITS);
+ gnutls_dh_set_prime_bits(c->ssl_state.gnutls_session, DH_BITS_MIN);
#endif
Conn_OPTION_ADD(c, CONN_SSL);
return true;
assert(ssl);
- Log(LOG_INFO, "New %s connection using cipher %s on socket %d.",
- SSL_get_version(ssl), SSL_get_cipher(ssl), c->sock);
+ Log(LOG_INFO, "Connection %d: initialized %s using cipher %s.",
+ c->sock, SSL_get_version(ssl), SSL_get_cipher(ssl));
#endif
#ifdef HAVE_LIBGNUTLS
gnutls_session_t sess = c->ssl_state.gnutls_session;
gnutls_cipher_algorithm_t cipher = gnutls_cipher_get(sess);
- Log(LOG_INFO, "New %s connection using cipher %s-%s on socket %d.",
+ Log(LOG_INFO, "Connection %d: initialized %s using cipher %s-%s.",
+ c->sock,
gnutls_protocol_get_name(gnutls_protocol_get_version(sess)),
gnutls_cipher_get_name(cipher),
- gnutls_mac_get_name(gnutls_mac_get(sess)), c->sock);
+ gnutls_mac_get_name(gnutls_mac_get(sess)));
#endif
}
#endif /* _GNUTLS */
Conn_OPTION_DEL(c, (CONN_SSL_WANT_WRITE|CONN_SSL_WANT_READ|CONN_SSL_CONNECT));
ConnSSL_LogCertInfo(c);
+
+ Conn_StartLogin(CONNECTION2ID(c));
return 1;
}
#endif
}
+#else
+
+bool
+ConnSSL_InitLibrary(void)
+{
+ return true;
+}
#endif /* SSL_SUPPORT */
/* -eof- */