summaryrefslogtreecommitdiff
path: root/kde-apps/ksmtp/files/ksmtp-17.12.0-ehlo-auth-fix.patch
blob: 903bfe0d1144138d3bdfedb5c2a9be96de0a2d3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
From 4564d77d3c644a7d1f99749c4e934969b4e21952 Mon Sep 17 00:00:00 2001
From: Fabian Vogt <fabian@ritter-vogt.de>
Date: Fri, 22 Dec 2017 14:22:49 +0100
Subject: [PATCH] Fix duplicate authentication

Summary:
The response to EHLO triggers an authentication command, but with TLS
two EHLOs are sent: For the 220 from the server and after TLS negotiation.
However, sending it twice results in an unexpected "503 already authenticated"
response which ends up getting parsed by the SendJob, causing confusion.

BUG: 387926
BUG: 388068

Reviewers: mlaurent, dvratil

Subscribers: rdieter, heikobecker, asn, #kde_pim, lbeltrame, cgiboudeaux

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D9476
---
 src/session.cpp       | 29 +++++++++++++++++++----------
 src/session_p.h       |  1 +
 src/sessionthread.cpp |  1 -
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/session.cpp b/src/session.cpp
index 861419d..4320adc 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -80,6 +80,19 @@ void SessionPrivate::setAuthenticationMethods(const QList<QByteArray> &authMetho
     }
 }
 
+void SessionPrivate::startHandshake()
+{
+    QByteArray cmd;
+    if (!m_ehloRejected) {
+         cmd = "EHLO ";
+    } else {
+         cmd = "HELO ";
+    }
+    setState(Session::Handshake);
+    const auto hostname = m_customHostname.isEmpty() ? m_thread->hostName() : m_customHostname;
+    sendData(cmd + QUrl::toAce(hostname));
+}
+
 
 
 Session::Session(const QString &hostName, quint16 port, QObject *parent)
@@ -277,15 +290,7 @@ void SessionPrivate::responseReceived(const ServerResponse &r)
 
     if (m_state == Session::Ready) {
         if (r.isCode(22) || m_ehloRejected) {
-            QByteArray cmd;
-            if (!m_ehloRejected) {
-                cmd = "EHLO ";
-            } else {
-                cmd = "HELO ";
-            }
-            setState(Session::Handshake);
-            const auto hostname = m_customHostname.isEmpty() ? m_thread->hostName() : m_customHostname;
-            sendData(cmd + QUrl::toAce(hostname));
+            startHandshake();
             return;
         }
     }
@@ -346,7 +351,11 @@ KTcpSocket::SslVersion SessionPrivate::negotiatedEncryption() const
 
 void SessionPrivate::encryptionNegotiationResult(bool encrypted, KTcpSocket::SslVersion version)
 {
-    Q_UNUSED(encrypted);
+    if (encrypted) {
+        // Get the updated auth methods
+        startHandshake();
+    }
+
     m_sslVersion = version;
 }
 
diff --git a/src/session_p.h b/src/session_p.h
index 875f7be..90151f6 100644
--- a/src/session_p.h
+++ b/src/session_p.h
@@ -73,6 +73,7 @@ private Q_SLOTS:
 
 private:
 
+    void startHandshake();
     void startNext();
     void startSocketTimer();
     void stopSocketTimer();
diff --git a/src/sessionthread.cpp b/src/sessionthread.cpp
index 1e4db8b..c195826 100644
--- a/src/sessionthread.cpp
+++ b/src/sessionthread.cpp
@@ -223,7 +223,6 @@ void SessionThread::sslConnected()
     } else {
         qCDebug(KSMTP_LOG) << "TLS negotiation done.";
 
-        QMetaObject::invokeMethod(this, "sendData", Qt::QueuedConnection, Q_ARG(QByteArray, "EHLO " + QUrl::toAce(hostName())));
         Q_EMIT encryptionNegotiationResult(true, m_socket->negotiatedSslVersion());
     }
 }
-- 
2.13.6