- if((ret = gnutls_certificate_set_x509_key_file (x509_cred, certfile.c_str(), keyfile.c_str(), GNUTLS_X509_FMT_PEM)) < 0)
- {
- // If this fails, no SSL port will work. At all. So, do the smart thing - throw a ModuleException
- throw ModuleException("Unable to load GnuTLS server certificate: " + std::string(gnutls_strerror(ret)));
- }
+ FileReader reader;
+
+ reader.LoadFile(certfile);
+ std::string cert_string = reader.Contents();
+ gnutls_datum_t cert_datum = { (unsigned char*)cert_string.data(), cert_string.length() };
+
+ reader.LoadFile(keyfile);
+ std::string key_string = reader.Contents();
+ gnutls_datum_t key_datum = { (unsigned char*)key_string.data(), key_string.length() };
+
+ // If this fails, no SSL port will work. At all. So, do the smart thing - throw a ModuleException
+ if((ret = gnutls_x509_crt_import(x509_cert, &cert_datum, GNUTLS_X509_FMT_PEM)) < 0)
+ throw ModuleException("Unable to load GnuTLS server certificate (" + certfile + "): " + std::string(gnutls_strerror(ret)));
+
+ if((ret = gnutls_x509_privkey_import(x509_key, &key_datum, GNUTLS_X509_FMT_PEM)) < 0)
+ throw ModuleException("Unable to load GnuTLS server private key (" + keyfile + "): " + std::string(gnutls_strerror(ret)));
+
+ if((ret = gnutls_certificate_set_x509_key(x509_cred, &x509_cert, 1, x509_key)) < 0)
+ throw ModuleException("Unable to set GnuTLS cert/key pair: " + std::string(gnutls_strerror(ret)));
+
+ gnutls_certificate_client_set_retrieve_function (x509_cred, cert_callback);
+
+ if((ret = gnutls_dh_params_init(&dh_params)) < 0)
+ ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Failed to initialise DH parameters: %s", gnutls_strerror(ret));