]> jfr.im git - solanum.git/blobdiff - libratbox/src/gnutls.c
Merge branch 'master' of github.com:charybdis-ircd/charybdis
[solanum.git] / libratbox / src / gnutls.c
index 2cf6657ec9b0a0bd084155169a4e3d432e6131fb..b50960848a567bb95cd5ba1e1d156a6aba2dfc14 100644 (file)
 
 #include <gnutls/gnutls.h>
 #include <gnutls/x509.h>
-#include <gnutls/crypto.h>
 
-#if GNUTLS_VERSION_MAJOR < 3
+#if (GNUTLS_VERSION_MAJOR < 3)
 # include <gcrypt.h>
+#else
+# include <gnutls/crypto.h>
 #endif
 
-static gnutls_certificate_credentials x509;
-static gnutls_dh_params dh_params;
+static gnutls_certificate_credentials_t x509;
+static gnutls_dh_params_t dh_params;
 static gnutls_priority_t default_priority;
 
 /* These are all used for getting GnuTLS to supply a client cert. */
@@ -46,9 +47,13 @@ static gnutls_priority_t default_priority;
 static unsigned int x509_cert_count;
 static gnutls_x509_crt_t x509_cert[MAX_CERTS];
 static gnutls_x509_privkey_t x509_key;
+#if GNUTLS_VERSION_MAJOR < 3
 static int cert_callback(gnutls_session_t session, const gnutls_datum_t *req_ca_rdn, int nreqs,
        const gnutls_pk_algorithm_t *sign_algos, int sign_algos_len, gnutls_retr_st *st);
-
+#else
+static int cert_callback(gnutls_session_t session, const gnutls_datum_t *req_ca_rdn, int nreqs,
+       const gnutls_pk_algorithm_t *sign_algos, int sign_algos_len, gnutls_retr2_st *st);
+#endif
 
 #define SSL_P(x) *((gnutls_session_t *)F->ssl)
 
@@ -158,7 +163,7 @@ rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout)
        gnutls_dh_set_prime_bits(*ssl, 1024);
        gnutls_transport_set_ptr(*ssl, (gnutls_transport_ptr_t) (long int)new_F->fd);
        gnutls_certificate_server_set_request(*ssl, GNUTLS_CERT_REQUEST);
-       gnutls_priority_set(SSL_P(F), default_priority);
+       gnutls_priority_set(*ssl, default_priority);
 
        if(do_ssl_handshake(new_F, rb_ssl_tryaccept, NULL))
        {
@@ -252,13 +257,13 @@ rb_ssl_write(rb_fde_t *F, const void *buf, size_t count)
        return rb_ssl_read_or_write(1, F, NULL, buf, count);
 }
 
+#if (GNUTLS_VERSION_MAJOR < 3)
 static void
 rb_gcry_random_seed(void *unused)
 {
-#if GNUTLS_VERSION_MAJOR < 3
        gcry_fast_random_poll();
-#endif
 }
+#endif
 
 int
 rb_init_ssl(void)
@@ -271,12 +276,16 @@ rb_init_ssl(void)
                return 0;
        }
 
-       /* This should be changed to gnutls_certificate_set_retrieve_function2 once
-        * everyone in the world has upgraded to GnuTLS 3.
-        */
+#if GNUTLS_VERSION_MAJOR < 3
        gnutls_certificate_client_set_retrieve_function(x509, cert_callback);
+#else
+       gnutls_certificate_set_retrieve_function(x509, cert_callback);
+#endif
 
+#if (GNUTLS_VERSION_MAJOR < 3)
        rb_event_addish("rb_gcry_random_seed", rb_gcry_random_seed, NULL, 300);
+#endif
+
        return 1;
 }
 
@@ -287,15 +296,27 @@ rb_init_ssl(void)
  * as it breaks fingerprint auth.  Thus, we use this callback to force GnuTLS to always
  * authenticate with our certificate at all times.
  */
+#if GNUTLS_VERSION_MAJOR < 3
 static int
 cert_callback(gnutls_session_t session, const gnutls_datum_t *req_ca_rdn, int nreqs,
        const gnutls_pk_algorithm_t *sign_algos, int sign_algos_len, gnutls_retr_st *st)
+#else
+static int
+cert_callback(gnutls_session_t session, const gnutls_datum_t *req_ca_rdn, int nreqs,
+       const gnutls_pk_algorithm_t *sign_algos, int sign_algos_len, gnutls_retr2_st *st)
+#endif
 {
        /* XXX - ugly hack. Tell GnuTLS to use the first (only) certificate we have for auth. */
+#if (GNUTLS_VERSION_MAJOR < 3)
        st->type = GNUTLS_CRT_X509;
+#else
+       st->cert_type = GNUTLS_CRT_X509;
+       st->key_type = GNUTLS_PRIVKEY_X509;
+#endif
        st->ncerts = x509_cert_count;
        st->cert.x509 = x509_cert;
        st->key.x509 = x509_key;
+       st->deinit_all = 0;
 
        return 0;
 }
@@ -409,7 +430,7 @@ rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile, c
                        rb_lib_log("rb_setup_ssl_server: Unable to setup DH parameters");
        }
 
-       ret = gnutls_priority_init(&default_priority, ssl_cipher_list, &err);
+       ret = gnutls_priority_init(&default_priority, cipher_list, &err);
        if (ret < 0)
        {
                rb_lib_log("rb_setup_ssl_server: syntax error (using defaults instead) in ssl cipher list at: %s", err);
@@ -552,8 +573,6 @@ rb_init_prng(const char *path, prng_seed_t seed_type)
 {
 #if GNUTLS_VERSION_MAJOR < 3
        gcry_fast_random_poll();
-#else
-       gnutls_rnd_refresh();
 #endif
        return 1;
 }
@@ -645,7 +664,7 @@ rb_supports_ssl(void)
 void
 rb_get_ssl_info(char *buf, size_t len)
 {
-       rb_snprintf(buf, len, "GNUTLS: compiled (%s), library(%s)",
+       snprintf(buf, len, "GNUTLS: compiled (%s), library(%s)",
                    LIBGNUTLS_VERSION, gnutls_check_version(NULL));
 }
 
@@ -654,7 +673,7 @@ rb_ssl_get_cipher(rb_fde_t *F)
 {
        static char buf[1024];
 
-       rb_snprintf(buf, sizeof(buf), "%s-%s-%s-%s",
+       snprintf(buf, sizeof(buf), "%s-%s-%s-%s",
                gnutls_protocol_get_name(gnutls_protocol_get_version(SSL_P(F))),
                gnutls_kx_get_name(gnutls_kx_get(SSL_P(F))),
                gnutls_cipher_get_name(gnutls_cipher_get(SSL_P(F))),