From 203a2ce0031046f454d4120f53ad437d33763eaa Mon Sep 17 00:00:00 2001 From: Michael Schuster Date: Thu, 25 Jun 2020 00:30:41 +0200 Subject: [PATCH] Move QKeychain::NoBackendAvailable error handling to KeychainChunk class Originally this was in the WebFlowCredentials class. Since we've abstracted everything from there already, let's also move this in case some other code may use KeychainChunk::ReadJob prior to WebFlowCredentials. Signed-off-by: Michael Schuster --- src/gui/creds/keychainchunk.cpp | 21 +++++++++++++++++++-- src/gui/creds/keychainchunk.h | 5 +++++ src/gui/creds/webflowcredentials.cpp | 15 --------------- src/gui/creds/webflowcredentials.h | 1 - 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/gui/creds/keychainchunk.cpp b/src/gui/creds/keychainchunk.cpp index cd6d3257f..836be0b01 100644 --- a/src/gui/creds/keychainchunk.cpp +++ b/src/gui/creds/keychainchunk.cpp @@ -202,8 +202,25 @@ void ReadJob::slotReadJobDone(QKeychain::Job *incomingJob) } #endif } else { - if (readJob->error() != QKeychain::Error::EntryNotFound || - ((readJob->error() == QKeychain::Error::EntryNotFound) && _chunkCount == 0)) { +#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) + if (!readJob->insecureFallback()) { // If insecureFallback is set, the next test would be pointless + if (_retryOnKeyChainError && (readJob->error() == QKeychain::NoBackendAvailable + || readJob->error() == QKeychain::OtherError)) { + // Could be that the backend was not yet available. Wait some extra seconds. + // (Issues #4274 and #6522) + // (For kwallet, the error is OtherError instead of NoBackendAvailable, maybe a bug in QtKeychain) + qCInfo(lcKeychainChunk) << "Backend unavailable (yet?) Retrying in a few seconds." << readJob->errorString(); + QTimer::singleShot(10000, this, &ReadJob::start); + _retryOnKeyChainError = false; + readJob->deleteLater(); + return; + } + _retryOnKeyChainError = false; + } +#endif + + if (readJob->error() != QKeychain::EntryNotFound || + ((readJob->error() == QKeychain::EntryNotFound) && _chunkCount == 0)) { _error = readJob->error(); _errorString = readJob->errorString(); qCWarning(lcKeychainChunk) << "Unable to read" << readJob->key() << "chunk" << QString::number(_chunkCount) << readJob->errorString(); diff --git a/src/gui/creds/keychainchunk.h b/src/gui/creds/keychainchunk.h index 875ab5037..d1ae1e9dd 100644 --- a/src/gui/creds/keychainchunk.h +++ b/src/gui/creds/keychainchunk.h @@ -111,6 +111,11 @@ signals: private slots: void slotReadJobDone(QKeychain::Job *incomingJob); + +#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) +private: + bool _retryOnKeyChainError = true; // true if we haven't done yet any reading from keychain +#endif }; // class ReadJob } // namespace KeychainChunk diff --git a/src/gui/creds/webflowcredentials.cpp b/src/gui/creds/webflowcredentials.cpp index ba762ee0c..ff5c2eb2a 100644 --- a/src/gui/creds/webflowcredentials.cpp +++ b/src/gui/creds/webflowcredentials.cpp @@ -450,21 +450,6 @@ void WebFlowCredentials::fetchFromKeychainHelper() { void WebFlowCredentials::slotReadClientCertPEMJobDone(KeychainChunk::ReadJob *readJob) { -#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) - Q_ASSERT(!readJob->insecureFallback()); // If insecureFallback is set, the next test would be pointless - if (_retryOnKeyChainError && (readJob->error() == QKeychain::NoBackendAvailable - || readJob->error() == QKeychain::OtherError)) { - // Could be that the backend was not yet available. Wait some extra seconds. - // (Issues #4274 and #6522) - // (For kwallet, the error is OtherError instead of NoBackendAvailable, maybe a bug in QtKeychain) - qCInfo(lcWebFlowCredentials) << "Backend unavailable (yet?) Retrying in a few seconds." << readJob->errorString(); - QTimer::singleShot(10000, this, &WebFlowCredentials::fetchFromKeychainHelper); - _retryOnKeyChainError = false; - return; - } - _retryOnKeyChainError = false; -#endif - // Store PEM in memory if (readJob->error() == NoError && readJob->binaryData().length() > 0) { QList sslCertificateList = QSslCertificate::fromData(readJob->binaryData(), QSsl::Pem); diff --git a/src/gui/creds/webflowcredentials.h b/src/gui/creds/webflowcredentials.h index 511ab542e..3f9cee38d 100644 --- a/src/gui/creds/webflowcredentials.h +++ b/src/gui/creds/webflowcredentials.h @@ -122,7 +122,6 @@ protected: bool _ready = false; bool _credentialsValid = false; bool _keychainMigration = false; - bool _retryOnKeyChainError = true; // true if we haven't done yet any reading from keychain WebFlowCredentialsDialog *_askDialog = nullptr; };