* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
-#include <gcrypt.h>
+#include <gnutls/crypto.h>
+
+#if GNUTLS_VERSION_MAJOR < 3
+# include <gcrypt.h>
+#endif
static gnutls_certificate_credentials x509;
static gnutls_dh_params dh_params;
+static gnutls_priority_t default_priority;
/* These are all used for getting GnuTLS to supply a client cert. */
#define MAX_CERTS 6
F->accept = NULL;
rb_settimeout(F, 0, NULL, NULL);
rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, NULL, NULL);
-
+
if(ret > 0)
ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data);
else
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);
+
if(do_ssl_handshake(new_F, rb_ssl_tryaccept, NULL))
{
struct acceptdata *ad = new_F->accept;
gnutls_dh_set_prime_bits(SSL_P(new_F), 1024);
gnutls_transport_set_ptr(SSL_P(new_F), (gnutls_transport_ptr_t) (long int)rb_get_fd(new_F));
gnutls_certificate_server_set_request(SSL_P(new_F), GNUTLS_CERT_REQUEST);
+ gnutls_priority_set(SSL_P(F), default_priority);
+
if(do_ssl_handshake(F, rb_ssl_tryaccept, NULL))
{
struct acceptdata *ad = F->accept;
static void
rb_gcry_random_seed(void *unused)
{
+#if GNUTLS_VERSION_MAJOR < 3
gcry_fast_random_poll();
+#endif
}
int
}
int
-rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile)
+rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile, const char *cipher_list)
{
int ret;
+ const char *err;
gnutls_datum_t *d_cert, *d_key;
if(cert == NULL)
{
else
rb_lib_log("rb_setup_ssl_server: Unable to setup DH parameters");
}
+
+ ret = gnutls_priority_init(&default_priority, ssl_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);
+ gnutls_priority_init(&default_priority, NULL, &err);
+ return 1;
+ }
+
return 1;
}
{
int result;
- result = rb_listen(F->fd, backlog, defer_accept);
+ result = rb_listen(F, backlog, defer_accept);
F->type = RB_FD_SOCKET | RB_FD_LISTEN | RB_FD_SSL;
return result;
gnutls_credentials_set(SSL_P(F), GNUTLS_CRD_CERTIFICATE, x509);
gnutls_dh_set_prime_bits(SSL_P(F), 1024);
gnutls_transport_set_ptr(SSL_P(F), (gnutls_transport_ptr_t) (long int)F->fd);
+ gnutls_priority_set(SSL_P(F), default_priority);
do_ssl_handshake(F, rb_ssl_tryconn_cb, (void *)sconn);
}
gnutls_credentials_set(SSL_P(F), GNUTLS_CRD_CERTIFICATE, x509);
gnutls_dh_set_prime_bits(SSL_P(F), 1024);
gnutls_transport_set_ptr(SSL_P(F), (gnutls_transport_ptr_t) (long int)F->fd);
+ gnutls_priority_set(SSL_P(F), default_priority);
rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn);
int
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;
}
int
rb_get_random(void *buf, size_t length)
{
+#if GNUTLS_VERSION_MAJOR < 3
gcry_randomize(buf, length, GCRY_STRONG_RANDOM);
- return 1;
-}
-
-int
-rb_get_pseudo_random(void *buf, size_t length)
-{
- gcry_randomize(buf, length, GCRY_WEAK_RANDOM);
+#else
+ gnutls_rnd(GNUTLS_RND_KEY, buf, length);
+#endif
return 1;
}
}
int
-rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN])
+rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN], int method)
{
gnutls_x509_crt_t cert;
+ gnutls_digest_algorithm_t algo;
unsigned int cert_list_size;
const gnutls_datum_t *cert_list;
uint8_t digest[RB_SSL_CERTFP_LEN * 2];
size_t digest_size;
+ int len;
if (gnutls_certificate_type_get(SSL_P(F)) != GNUTLS_CRT_X509)
return 0;
return 0;
}
- if (gnutls_x509_crt_get_fingerprint(cert, GNUTLS_DIG_SHA1, digest, &digest_size) < 0)
+ switch(method)
+ {
+ case RB_SSL_CERTFP_METH_SHA1:
+ algo = GNUTLS_DIG_SHA1;
+ len = RB_SSL_CERTFP_LEN_SHA1;
+ break;
+ case RB_SSL_CERTFP_METH_SHA256:
+ algo = GNUTLS_DIG_SHA256;
+ len = RB_SSL_CERTFP_LEN_SHA256;
+ break;
+ case RB_SSL_CERTFP_METH_SHA512:
+ algo = GNUTLS_DIG_SHA512;
+ len = RB_SSL_CERTFP_LEN_SHA512;
+ break;
+ default:
+ return 0;
+ }
+
+ if (gnutls_x509_crt_get_fingerprint(cert, algo, digest, &digest_size) < 0)
{
gnutls_x509_crt_deinit(cert);
return 0;
}
- memcpy(certfp, digest, RB_SSL_CERTFP_LEN);
+ memcpy(certfp, digest, len);
gnutls_x509_crt_deinit(cert);
- return 1;
+ return len;
}
int
void
rb_get_ssl_info(char *buf, size_t len)
{
- rb_snprintf(buf, len, "GNUTLS: compiled (%s), library(%s)",
+ rb_snprintf(buf, len, "GNUTLS: compiled (%s), library(%s)",
LIBGNUTLS_VERSION, gnutls_check_version(NULL));
}
-
-
+
+const char *
+rb_ssl_get_cipher(rb_fde_t *F)
+{
+ static char buf[1024];
+
+ rb_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))),
+ gnutls_mac_get_name(gnutls_mac_get(SSL_P(F))));
+
+ return buf;
+}
+
#endif /* HAVE_GNUTLS */