summaryrefslogtreecommitdiff
path: root/src/modules/extra
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2013-04-28 00:32:14 +0200
committerattilamolnar <attilamolnar@hush.com>2013-04-28 00:32:14 +0200
commit8790551dc182cd8804ee7d8ef89ccb31067cc2a4 (patch)
treefa411b244ae8541e49eb126a9d15a7b5a13504db /src/modules/extra
parent021c09faff4be2e37fa86b0fe3e61707ffddab27 (diff)
parent9b96fee72a3720e6d12812243edb4192d0790b34 (diff)
Merge insp20
Diffstat (limited to 'src/modules/extra')
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index 1caacaa0f..00dff68e6 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -86,6 +86,12 @@ static ssize_t gnutls_pull_wrapper(gnutls_transport_ptr_t user_wrap, void* buffe
return -1;
}
int rv = ServerInstance->SE->Recv(user, reinterpret_cast<char *>(buffer), size, 0);
+ if (rv < 0)
+ {
+ /* On Windows we need to set errno for gnutls */
+ if (SocketEngine::IgnoreError())
+ errno = EAGAIN;
+ }
if (rv < (int)size)
ServerInstance->SE->ChangeEventMask(user, FD_READ_WILL_BLOCK);
return rv;
@@ -100,6 +106,12 @@ static ssize_t gnutls_push_wrapper(gnutls_transport_ptr_t user_wrap, const void*
return -1;
}
int rv = ServerInstance->SE->Send(user, reinterpret_cast<const char *>(buffer), size, 0);
+ if (rv < 0)
+ {
+ /* On Windows we need to set errno for gnutls */
+ if (SocketEngine::IgnoreError())
+ errno = EAGAIN;
+ }
if (rv < (int)size)
ServerInstance->SE->ChangeEventMask(user, FD_WRITE_WILL_BLOCK);
return rv;
@@ -322,6 +334,7 @@ class ModuleSSLGnuTLS : public Module
{
gnutls_dh_params_deinit(dh_params);
dh_alloc = false;
+ dh_params = NULL;
}
if (cred_alloc)
@@ -409,10 +422,30 @@ class ModuleSSLGnuTLS : public Module
ret = gnutls_dh_params_init(&dh_params);
dh_alloc = (ret >= 0);
if (!dh_alloc)
- ServerInstance->Logs->Log("m_ssl_gnutls",LOG_DEFAULT, "m_ssl_gnutls.so: Failed to initialise DH parameters: %s", gnutls_strerror(ret));
+ {
+ ServerInstance->Logs->Log("m_ssl_gnutls", LOG_DEFAULT, "m_ssl_gnutls.so: Failed to initialise DH parameters: %s", gnutls_strerror(ret));
+ return;
+ }
- // This may be on a large (once a day or week) timer eventually.
- GenerateDHParams();
+ std::string dhfile = Conf->getString("dhfile");
+ if (!dhfile.empty())
+ {
+ // Try to load DH params from file
+ reader.LoadFile(dhfile);
+ std::string dhstring = reader.Contents();
+ gnutls_datum_t dh_datum = { (unsigned char*)dhstring.data(), static_cast<unsigned int>(dhstring.length()) };
+
+ if ((ret = gnutls_dh_params_import_pkcs3(dh_params, &dh_datum, GNUTLS_X509_FMT_PEM)) < 0)
+ {
+ // File unreadable or GnuTLS was unhappy with the contents, generate the DH primes now
+ ServerInstance->Logs->Log("m_ssl_gnutls", LOG_DEFAULT, "m_ssl_gnutls.so: Generating DH parameters because I failed to load them from file '%s': %s", dhfile.c_str(), gnutls_strerror(ret));
+ GenerateDHParams();
+ }
+ }
+ else
+ {
+ GenerateDHParams();
+ }
}
void GenerateDHParams()