]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/conn-ssl.c
Initialize SSL when needed only, and disable SSL on errors
[ngircd-alex.git] / src / ngircd / conn-ssl.c
index 7630420dad36bfa46e2dbb0590e382055f3d7979..914d01651235ad16af2e81ebb3d9a045e1d39a37 100644 (file)
@@ -52,9 +52,10 @@ static bool ConnSSL_LoadServerKey_openssl PARAMS(( SSL_CTX *c ));
 #include <gnutls/x509.h>
 
 #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
 
@@ -240,6 +241,9 @@ void ConnSSL_Free(CONNECTION *c)
 bool
 ConnSSL_InitLibrary( void )
 {
+       if (!array_bytes(&Conf_SSLOptions.ListenPorts))
+               return true;
+
 #ifdef HAVE_LIBSSL
        SSL_CTX *newctx;
 
@@ -255,12 +259,14 @@ ConnSSL_InitLibrary( void )
                 * 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;
        }
 
@@ -275,6 +281,7 @@ ConnSSL_InitLibrary( void )
        return true;
 out:
        SSL_CTX_free(newctx);
+       array_free(&Conf_SSLOptions.ListenPorts);
        return false;
 #endif
 #ifdef HAVE_LIBGNUTLS
@@ -286,10 +293,13 @@ out:
        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;
@@ -312,7 +322,7 @@ ConnSSL_LoadServerKey_gnutls(void)
 
        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;
        }
 
@@ -343,7 +353,7 @@ ConnSSL_LoadServerKey_openssl(SSL_CTX *ctx)
 
        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;
        }
 
@@ -426,7 +436,7 @@ ConnSSL_Init_SSL(CONNECTION *c)
                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;
@@ -548,17 +558,18 @@ ConnSSL_LogCertInfo( CONNECTION *c )
 
        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
 }
 
@@ -623,6 +634,8 @@ ConnectAccept( CONNECTION *c, bool connect)
 #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;
 }