added cipher cache to cleanup
[umurmur.git] / src / ssli_gnutls.c
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c081a9c0ea948487cafa7e3bb0125b3964e1c26b 100644 (file)
@@ -0,0 +1,59 @@
+#include "ssl.h"
+#include "conf.h"
+#include "log.h"
+
+static gnutls_dh_params_t dhParameters;
+static gnutls_certificate_credentials_t certificate;
+
+static const char * ciphers = "SECURE128:-VERS-DTLS-ALL:-VERS-SSL3.0:-VERS-TLS1.0:+COMP_ALL";
+static gnutls_priority_t cipherCache;
+
+void initializeCertificate()
+  {
+  char* certificatePath = (char*) getStrConf(CERTIFICATE);
+
+  if(!certificatePath) {
+    Log_fatal("No certificate file specified.");
+  }
+
+  char* keyPath = (char*) getStrConf(KEY);
+
+  if(!keyPath) {
+    Log_fatal("No key file specified");
+  }
+
+  gnutls_certificate_allocate_credentials(&certificate);
+
+  int error = gnutls_certificate_set_x509_key_file(certificate, certificatePath, keyPath, GNUTLS_X509_FMT_PEM);
+
+  if( error != GNUTLS_E_SUCCESS ) {
+    Log_fatal("Could not open key (%s) or certificate (%s).", keyPath, certificatePath);
+  }
+
+  }
+
+void SSLi_init()
+  {
+  unsigned const bitCount = gnutls_sec_param_to_pk_bits(GNUTLS_PK_DH, GNUTLS_SEC_PARAM_MEDIUM);
+
+  gnutls_dh_params_init(&dhParameters);
+  gnutls_dh_params_generate2(dhParameters, bitCount);
+
+#if GNUTLS_VERSION_NUMBER < 0x030300
+  gnutls_global_init();
+#endif
+
+  gnutls_priority_init(&cipherCache, ciphers, NULL);
+
+  initializeCertificate();
+
+  Log_info("Sucessfully initialized GNUTLS version %s", gnutls_check_version(NULL));
+
+  }
+
+void SSLi_deinit()
+  {
+  gnutls_certificate_free_credentials(certificate);
+  gnutls_priority_deinit(cipherCache);
+  gnutls_global_deinit();
+  }