From 01fd896e3c4d6bcdcf35f890e06396cb85cd5ca8 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Mon, 17 Jun 2013 15:04:37 +0200 Subject: Re-issue CAPA command once TLS has been started (POP3, IMAP). --- src/net/pop3/POP3Connection.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/net/pop3') diff --git a/src/net/pop3/POP3Connection.cpp b/src/net/pop3/POP3Connection.cpp index 96717620..846d31e9 100644 --- a/src/net/pop3/POP3Connection.cpp +++ b/src/net/pop3/POP3Connection.cpp @@ -65,7 +65,7 @@ namespace pop3 { POP3Connection::POP3Connection(ref store, ref auth) : m_store(store), m_auth(auth), m_socket(NULL), m_timeoutHandler(NULL), - m_authenticated(false), m_secured(false) + m_authenticated(false), m_secured(false), m_capabilitiesFetched(false) { } @@ -550,6 +550,13 @@ void POP3Connection::startTLS() m_secured = true; m_cntInfos = vmime::create (m_cntInfos->getHost(), m_cntInfos->getPort(), tlsSession, tlsSocket); + + // " Once TLS has been started, the client MUST discard cached + // information about server capabilities and SHOULD re-issue + // the CAPA command. This is necessary to protect against + // man-in-the-middle attacks which alter the capabilities list + // prior to STLS. " (RFC-2595) + invalidateCapabilities(); } catch (exceptions::command_error&) { @@ -568,6 +575,22 @@ void POP3Connection::startTLS() const std::vector POP3Connection::getCapabilities() +{ + if (!m_capabilitiesFetched) + fetchCapabilities(); + + return m_capabilities; +} + + +void POP3Connection::invalidateCapabilities() +{ + m_capabilities.clear(); + m_capabilitiesFetched = false; +} + + +void POP3Connection::fetchCapabilities() { POP3Command::CAPA()->send(thisRef().dynamicCast ()); @@ -582,7 +605,8 @@ const std::vector POP3Connection::getCapabilities() res.push_back(response->getLineAt(i)); } - return res; + m_capabilities = res; + m_capabilitiesFetched = true; } -- cgit