summaryrefslogtreecommitdiff
path: root/src/LibgnutlsTLSSession.cc
diff options
context:
space:
mode:
authorNils Maier <maierman@web.de>2014-12-13 08:08:47 +0100
committerNils Maier <maierman@web.de>2014-12-14 10:34:09 +0100
commit3c8704178a94a9ae3abde238aa4c369efd5f01a1 (patch)
tree46ae75e7731a4bc58b9ff2c0bff9b2101c9d17cd /src/LibgnutlsTLSSession.cc
parentc5c38bf3a4f6193ecba814d47a305872b6ea5454 (diff)
Move warn logic into SocketCore
Also fiddle a bit with the WinTLS implementation, forcing "strong" crypto only for > SSLv3.
Diffstat (limited to 'src/LibgnutlsTLSSession.cc')
-rw-r--r--src/LibgnutlsTLSSession.cc59
1 files changed, 38 insertions, 21 deletions
diff --git a/src/LibgnutlsTLSSession.cc b/src/LibgnutlsTLSSession.cc
index 88c13fc7..273d82b2 100644
--- a/src/LibgnutlsTLSSession.cc
+++ b/src/LibgnutlsTLSSession.cc
@@ -39,9 +39,39 @@
#include "TLSContext.h"
#include "util.h"
#include "SocketCore.h"
-#include "LogFactory.h"
-#include "fmt.h"
-#include "message.h"
+
+namespace {
+using namespace aria2;
+
+TLSVersion getProtocolFromSession(gnutls_session_t& session) {
+ auto proto = gnutls_protocol_get_version(session);
+ switch(proto) {
+ case GNUTLS_SSL3:
+ return TLS_PROTO_SSL3;
+
+#ifdef GNUTLS_TLS1_0
+ case GNUTLS_TLS1_0:
+ return TLS_PROTO_TLS10;
+#endif // GNUTLS_TLS1_0
+
+#ifdef GNUTLS_TLS1_1
+ case GNUTLS_TLS1_1:
+ return TLS_PROTO_TLS11;
+ break;
+#endif // GNUTLS_TLS1_1
+
+#ifdef GNUTLS_TLS1_2
+ case GNUTLS_TLS1_2:
+ return TLS_PROTO_TLS12;
+ break;
+#endif // GNUTLS_TLS1_2
+
+ default:
+ return TLS_PROTO_NONE;
+ break;
+ }
+}
+} // namespace
namespace aria2 {
@@ -200,7 +230,8 @@ ssize_t GnuTLSSession::readData(void* data, size_t len)
}
int GnuTLSSession::tlsConnect(const std::string& hostname,
- std::string& handshakeErr)
+ TLSVersion& version,
+ std::string& handshakeErr)
{
handshakeErr = "";
for(;;) {
@@ -300,32 +331,18 @@ int GnuTLSSession::tlsConnect(const std::string& hostname,
return TLS_ERR_ERROR;
}
}
- auto proto = gnutls_protocol_get_version(sslSession_);
- switch(proto) {
- case GNUTLS_SSL3: {
- std::string protoAndSuite = gnutls_protocol_get_name(proto);
- protoAndSuite += " ";
- protoAndSuite += gnutls_cipher_suite_get_name(
- gnutls_kx_get(sslSession_),
- gnutls_cipher_get(sslSession_),
- gnutls_mac_get(sslSession_)
- );
- A2_LOG_WARN(fmt(MSG_WARN_OLD_TLS_CONNECTION, protoAndSuite.c_str()));
- break;
- }
- default:
- break;
- }
+ version = getProtocolFromSession(sslSession_);
return TLS_ERR_OK;
}
-int GnuTLSSession::tlsAccept()
+int GnuTLSSession::tlsAccept(TLSVersion& version)
{
for(;;) {
rv_ = gnutls_handshake(sslSession_);
if(rv_ == GNUTLS_E_SUCCESS) {
+ version = getProtocolFromSession(sslSession_);
return TLS_ERR_OK;
}
if(rv_ == GNUTLS_E_AGAIN || rv_ == GNUTLS_E_INTERRUPTED) {