Commit 943d0ef8 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Merge remote-tracking branch 'origin/release/21.12'

parents 1c7cb773 f14fabce
Pipeline #108622 passed with stage
in 9 minutes and 58 seconds
......@@ -536,6 +536,39 @@ Result POP3Protocol::loginPASS()
return Result::pass();
}
Result POP3Protocol::startSsl()
{
mSocket->ignoreSslErrors(); // Don't worry, errors are handled manually below
mSocket->startClientEncryption();
const bool encryptionStarted = mSocket->waitForEncrypted(s_connectTimeout);
const QSslCipher cipher = mSocket->sessionCipher();
const QList<QSslError> errors = mSocket->sslHandshakeErrors();
if (!encryptionStarted || !errors.isEmpty() || !mSocket->isEncrypted() || cipher.isNull() || cipher.usedBits() == 0) {
QString errorString = std::accumulate(errors.begin(), errors.end(), QString(), [](QString cur, const QSslError &error) {
if (!cur.isEmpty())
cur += QLatin1Char('\n');
cur += error.errorString();
return cur;
});
qCDebug(POP3_LOG) << "Initial SSL handshake failed. cipher.isNull() is" << cipher.isNull() << ", cipher.usedBits() is" << cipher.usedBits()
<< ", the socket says:" << mSocket->errorString() << "and the SSL errors are:" << errorString;
mContinueAfterSslError = false;
Q_EMIT sslError(KSslErrorUiData(mSocket));
if (!mContinueAfterSslError) {
if (errorString.isEmpty())
errorString = mSocket->errorString();
qCDebug(POP3_LOG) << "TLS setup has failed. Aborting." << errorString;
closeConnection();
return Result::fail(ERR_SSL_FAILURE, i18n("SSL/TLS error: %1", errorString));
}
} else {
qCDebug(POP3_LOG) << "TLS has been enabled.";
}
return Result::pass();
}
Result POP3Protocol::openConnection()
{
Q_ASSERT(QThread::currentThread() != qApp->thread());
......@@ -563,6 +596,13 @@ Result POP3Protocol::openConnection()
return Result::fail(mSocket->error(), errorString);
}
if (mSettings.useSSL()) {
const Result res = startSsl();
if (!res.success) {
return res;
}
}
mConnected = true;
greeting_buf = new char[GREETING_BUF_LEN];
......@@ -611,35 +651,9 @@ Result POP3Protocol::openConnection()
"was unsuccessful.\nYou can "
"disable TLS in the POP account settings dialog."));
}
}
if (mSettings.useSSL() || mSettings.useTLS()) {
mSocket->ignoreSslErrors(); // Don't worry, errors are handled manually below
mSocket->startClientEncryption();
const bool encryptionStarted = mSocket->waitForEncrypted(s_connectTimeout);
const QSslCipher cipher = mSocket->sessionCipher();
const QList<QSslError> errors = mSocket->sslHandshakeErrors();
if (!encryptionStarted || !errors.isEmpty() || !mSocket->isEncrypted() || cipher.isNull() || cipher.usedBits() == 0) {
QString errorString = std::accumulate(errors.begin(), errors.end(), QString(), [](QString cur, const QSslError &error) {
if (!cur.isEmpty())
cur += QLatin1Char('\n');
cur += error.errorString();
return cur;
});
qCDebug(POP3_LOG) << "Initial SSL handshake failed. cipher.isNull() is" << cipher.isNull() << ", cipher.usedBits() is" << cipher.usedBits()
<< ", the socket says:" << mSocket->errorString() << "and the SSL errors are:" << errorString;
mContinueAfterSslError = false;
Q_EMIT sslError(KSslErrorUiData(mSocket));
if (!mContinueAfterSslError) {
if (errorString.isEmpty())
errorString = mSocket->errorString();
qCDebug(POP3_LOG) << "TLS setup has failed. Aborting." << errorString;
closeConnection();
return Result::fail(ERR_SSL_FAILURE, i18n("SSL/TLS error: %1", errorString));
}
} else {
qCDebug(POP3_LOG) << "TLS has been enabled.";
const Result res = startSsl();
if (!res.success) {
return res;
}
}
......
......@@ -127,6 +127,8 @@ private:
*/
Q_REQUIRED_RESULT Result loginPASS();
Q_REQUIRED_RESULT Result startSsl();
const Settings &mSettings;
QSslSocket *const mSocket;
unsigned short int m_iPort;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment