void WebFlowCredentials::askFromUser() {
// Determine if the old flow has to be used (GS for now)
// Do a DetermineAuthTypeJob to make sure that the server is still using Flow2
- auto *job = new DetermineAuthTypeJob(_account->sharedFromThis(), this);
+ auto job = new DetermineAuthTypeJob(_account->sharedFromThis(), this);
connect(job, &DetermineAuthTypeJob::authType, [this](DetermineAuthTypeJob::AuthType type) {
// LoginFlowV2 > WebViewFlow > OAuth > Shib > Basic
bool useFlow2 = (type != DetermineAuthTypeJob::WebViewFlow);
// write cert if there is one
if (!_clientSslCertificate.isNull()) {
- auto *job = new KeychainChunk::WriteJob(_account,
- _user + clientCertificatePEMC,
- _clientSslCertificate.toPem(),
- this);
+ auto job = new KeychainChunk::WriteJob(_account,
+ _user + clientCertificatePEMC,
+ _clientSslCertificate.toPem(),
+ this);
connect(job, &KeychainChunk::WriteJob::finished, this, &WebFlowCredentials::slotWriteClientCertPEMJobDone);
job->start();
} else {
{
// write ssl key if there is one
if (!_clientSslKey.isNull()) {
- auto *job = new KeychainChunk::WriteJob(_account,
- _user + clientKeyPEMC,
- _clientSslKey.toPem(),
- this);
+ auto job = new KeychainChunk::WriteJob(_account,
+ _user + clientKeyPEMC,
+ _clientSslKey.toPem(),
+ this);
connect(job, &KeychainChunk::WriteJob::finished, this, &WebFlowCredentials::slotWriteClientKeyPEMJobDone);
job->start();
} else {
return;
}
- auto *job = new KeychainChunk::WriteJob(_account,
- _user + clientCaCertificatePEMC + QString::number(index),
- cert.toPem(),
- this);
+ auto job = new KeychainChunk::WriteJob(_account,
+ _user + clientCaCertificatePEMC + QString::number(index),
+ cert.toPem(),
+ this);
connect(job, &KeychainChunk::WriteJob::finished, this, &WebFlowCredentials::slotWriteClientCaCertsPEMJobDone);
job->start();
} else {
}
// done storing ca certs, time for the password
- auto *job = new WritePasswordJob(Theme::instance()->appName(), this);
+ auto job = new WritePasswordJob(Theme::instance()->appName(), this);
#if defined(KEYCHAINCHUNK_ENABLE_INSECURE_FALLBACK)
addSettingsToJob(_account, job);
#endif
return;
}
- auto *job = new DeletePasswordJob(Theme::instance()->appName(), this);
+ auto job = new DeletePasswordJob(Theme::instance()->appName(), this);
job->setInsecureFallback(false);
job->setKey(kck);
job->start();
void WebFlowCredentials::fetchFromKeychainHelper() {
// Read client cert from keychain
- auto *job = new KeychainChunk::ReadJob(_account,
- _user + clientCertificatePEMC,
- _keychainMigration,
- this);
+ auto job = new KeychainChunk::ReadJob(_account,
+ _user + clientCertificatePEMC,
+ _keychainMigration,
+ this);
connect(job, &KeychainChunk::ReadJob::finished, this, &WebFlowCredentials::slotReadClientCertPEMJobDone);
job->start();
}
}
// Load key too
- auto *job = new KeychainChunk::ReadJob(_account,
- _user + clientKeyPEMC,
- _keychainMigration,
- this);
+ auto job = new KeychainChunk::ReadJob(_account,
+ _user + clientKeyPEMC,
+ _keychainMigration,
+ this);
connect(job, &KeychainChunk::ReadJob::finished, this, &WebFlowCredentials::slotReadClientKeyPEMJobDone);
job->start();
}
{
// try to fetch a client ca cert
if (_clientSslCaCertificates.count() < _clientSslCaCertificatesMaxCount) {
- auto *job = new KeychainChunk::ReadJob(_account,
- _user + clientCaCertificatePEMC + QString::number(_clientSslCaCertificates.count()),
- _keychainMigration,
- this);
+ auto job = new KeychainChunk::ReadJob(_account,
+ _user + clientCaCertificatePEMC + QString::number(_clientSslCaCertificates.count()),
+ _keychainMigration,
+ this);
connect(job, &KeychainChunk::ReadJob::finished, this, &WebFlowCredentials::slotReadClientCaCertsPEMJobDone);
job->start();
} else {
_user,
_keychainMigration ? QString() : _account->id());
- auto *job = new ReadPasswordJob(Theme::instance()->appName(), this);
+ auto job = new ReadPasswordJob(Theme::instance()->appName(), this);
#if defined(KEYCHAINCHUNK_ENABLE_INSECURE_FALLBACK)
addSettingsToJob(_account, job);
#endif
}
void WebFlowCredentials::slotReadPasswordJobDone(Job *incomingJob) {
- auto *job = qobject_cast<ReadPasswordJob *>(incomingJob);
+ auto job = qobject_cast<ReadPasswordJob *>(incomingJob);
QKeychain::Error error = job->error();
// If we could not find the entry try the old entries
void WebFlowCredentials::deleteKeychainEntries(bool oldKeychainEntries) {
auto startDeleteJob = [this, oldKeychainEntries](QString key) {
- auto *job = new KeychainChunk::DeleteJob(_account, key, oldKeychainEntries, this);
+ auto job = new KeychainChunk::DeleteJob(_account, key, oldKeychainEntries, this);
job->start();
};
_chunkBuffer.clear();
}
+QKeychain::Error Job::error() const
+{
+ return _error;
+}
+
+QString Job::errorString() const
+{
+ return _errorString;
+}
+
+QByteArray Job::binaryData() const
+{
+ return _chunkBuffer;
+}
+
+QString Job::textData() const
+{
+ return _chunkBuffer;
+}
+
+bool Job::insecureFallback() const
+{
+ return _insecureFallback;
+}
+
+#if defined(KEYCHAINCHUNK_ENABLE_INSECURE_FALLBACK)
+void Job::setInsecureFallback(bool insecureFallback)
+{
+ _insecureFallback = insecureFallback;
+}
+#endif
+
+bool Job::autoDelete() const
+{
+ return _autoDelete;
+}
+
+void Job::setAutoDelete(bool autoDelete)
+{
+ _autoDelete = autoDelete;
+}
+
/*
* WriteJob
*/
void WriteJob::slotWriteJobDone(QKeychain::Job *incomingJob)
{
- auto *writeJob = static_cast<QKeychain::WritePasswordJob *>(incomingJob);
+ auto writeJob = qobject_cast<QKeychain::WritePasswordJob *>(incomingJob);
- // errors?
+ // Errors? (writeJob can be nullptr here, see: WriteJob::start)
if (writeJob) {
_error = writeJob->error();
_errorString = writeJob->errorString();
emit finished(this);
- if (_autoDelete)
+ if (_autoDelete) {
deleteLater();
+ }
return;
}
_account->id()
) : keyWithIndex;
- auto *job = new QKeychain::WritePasswordJob(_serviceName, this);
+ auto job = new QKeychain::WritePasswordJob(_serviceName, this);
#if defined(KEYCHAINCHUNK_ENABLE_INSECURE_FALLBACK)
addSettingsToJob(_account, job);
#endif
} else {
emit finished(this);
- if (_autoDelete)
+ if (_autoDelete) {
deleteLater();
+ }
}
writeJob->deleteLater();
/*
* ReadJob
*/
-ReadJob::ReadJob(Account *account, const QString &key, const bool &keychainMigration, QObject *parent)
+ReadJob::ReadJob(Account *account, const QString &key, bool keychainMigration, QObject *parent)
: Job(parent)
{
_account = account;
_keychainMigration ? QString() : _account->id()
) : _key;
- auto *job = new QKeychain::ReadPasswordJob(_serviceName, this);
+ auto job = new QKeychain::ReadPasswordJob(_serviceName, this);
#if defined(KEYCHAINCHUNK_ENABLE_INSECURE_FALLBACK)
addSettingsToJob(_account, job);
#endif
void ReadJob::slotReadJobDone(QKeychain::Job *incomingJob)
{
// Errors or next chunk?
- auto *readJob = static_cast<QKeychain::ReadPasswordJob *>(incomingJob);
+ auto readJob = qobject_cast<QKeychain::ReadPasswordJob *>(incomingJob);
+ Q_ASSERT(readJob);
- if (readJob) {
- if (readJob->error() == NoError && readJob->binaryData().length() > 0) {
- _chunkBuffer.append(readJob->binaryData());
- _chunkCount++;
+ if (readJob->error() == NoError && !readJob->binaryData().isEmpty()) {
+ _chunkBuffer.append(readJob->binaryData());
+ _chunkCount++;
#if defined(Q_OS_WIN)
- // try to fetch next chunk
- if (_chunkCount < KeychainChunk::MaxChunks) {
- const QString keyWithIndex = _key + QString(".") + QString::number(_chunkCount);
- const QString kck = _account ? AbstractCredentials::keychainKey(
- _account->url().toString(),
- keyWithIndex,
- _keychainMigration ? QString() : _account->id()
- ) : keyWithIndex;
-
- QKeychain::ReadPasswordJob *job = new QKeychain::ReadPasswordJob(_serviceName, this);
+ // try to fetch next chunk
+ if (_chunkCount < KeychainChunk::MaxChunks) {
+ const QString keyWithIndex = _key + QString(".") + QString::number(_chunkCount);
+ const QString kck = _account ? AbstractCredentials::keychainKey(
+ _account->url().toString(),
+ keyWithIndex,
+ _keychainMigration ? QString() : _account->id()
+ ) : keyWithIndex;
+
+ auto job = new QKeychain::ReadPasswordJob(_serviceName, this);
#if defined(KEYCHAINCHUNK_ENABLE_INSECURE_FALLBACK)
- addSettingsToJob(_account, job);
+ addSettingsToJob(_account, job);
#endif
- job->setInsecureFallback(_insecureFallback);
- job->setKey(kck);
- connect(job, &QKeychain::Job::finished, this, &KeychainChunk::ReadJob::slotReadJobDone);
- job->start();
+ job->setInsecureFallback(_insecureFallback);
+ job->setKey(kck);
+ connect(job, &QKeychain::Job::finished, this, &KeychainChunk::ReadJob::slotReadJobDone);
+ job->start();
- readJob->deleteLater();
- return;
- } else {
- qCWarning(lcKeychainChunk) << "Maximum chunk count for" << readJob->key() << "reached, ignoring after" << KeychainChunk::MaxChunks;
- }
-#endif
+ readJob->deleteLater();
+ return;
} else {
+ qCWarning(lcKeychainChunk) << "Maximum chunk count for" << readJob->key() << "reached, ignoring after" << KeychainChunk::MaxChunks;
+ }
+#endif
+ } else {
#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;
- }
+ 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();
- }
+ 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();
}
-
- readJob->deleteLater();
}
+ readJob->deleteLater();
+
emit finished(this);
- if (_autoDelete)
+ if (_autoDelete) {
deleteLater();
+ }
}
/*
* DeleteJob
*/
-DeleteJob::DeleteJob(Account *account, const QString &key, const bool &keychainMigration, QObject *parent)
+DeleteJob::DeleteJob(Account *account, const QString &key, bool keychainMigration, QObject *parent)
: Job(parent)
{
_account = account;
_keychainMigration ? QString() : _account->id()
) : _key;
- auto *job = new QKeychain::DeletePasswordJob(_serviceName, this);
+ auto job = new QKeychain::DeletePasswordJob(_serviceName, this);
#if defined(KEYCHAINCHUNK_ENABLE_INSECURE_FALLBACK)
addSettingsToJob(_account, job);
#endif
void DeleteJob::slotDeleteJobDone(QKeychain::Job *incomingJob)
{
// Errors or next chunk?
- auto *deleteJob = static_cast<QKeychain::DeletePasswordJob *>(incomingJob);
+ auto deleteJob = qobject_cast<QKeychain::DeletePasswordJob *>(incomingJob);
+ Q_ASSERT(deleteJob);
- if (deleteJob) {
- if (deleteJob->error() == NoError) {
- _chunkCount++;
+ if (deleteJob->error() == NoError) {
+ _chunkCount++;
#if defined(Q_OS_WIN)
- // try to delete next chunk
- if (_chunkCount < KeychainChunk::MaxChunks) {
- const QString keyWithIndex = _key + QString(".") + QString::number(_chunkCount);
- const QString kck = _account ? AbstractCredentials::keychainKey(
- _account->url().toString(),
- keyWithIndex,
- _keychainMigration ? QString() : _account->id()
- ) : keyWithIndex;
-
- QKeychain::DeletePasswordJob *job = new QKeychain::DeletePasswordJob(_serviceName, this);
+ // try to delete next chunk
+ if (_chunkCount < KeychainChunk::MaxChunks) {
+ const QString keyWithIndex = _key + QString(".") + QString::number(_chunkCount);
+ const QString kck = _account ? AbstractCredentials::keychainKey(
+ _account->url().toString(),
+ keyWithIndex,
+ _keychainMigration ? QString() : _account->id()
+ ) : keyWithIndex;
+
+ auto job = new QKeychain::DeletePasswordJob(_serviceName, this);
#if defined(KEYCHAINCHUNK_ENABLE_INSECURE_FALLBACK)
- addSettingsToJob(_account, job);
+ addSettingsToJob(_account, job);
#endif
- job->setInsecureFallback(_insecureFallback);
- job->setKey(kck);
- connect(job, &QKeychain::Job::finished, this, &KeychainChunk::DeleteJob::slotDeleteJobDone);
- job->start();
+ job->setInsecureFallback(_insecureFallback);
+ job->setKey(kck);
+ connect(job, &QKeychain::Job::finished, this, &KeychainChunk::DeleteJob::slotDeleteJobDone);
+ job->start();
- deleteJob->deleteLater();
- return;
- } else {
- qCWarning(lcKeychainChunk) << "Maximum chunk count for" << deleteJob->key() << "reached, ignoring after" << KeychainChunk::MaxChunks;
- }
-#endif
+ deleteJob->deleteLater();
+ return;
} else {
- if (deleteJob->error() != QKeychain::EntryNotFound ||
- ((deleteJob->error() == QKeychain::EntryNotFound) && _chunkCount == 0)) {
- _error = deleteJob->error();
- _errorString = deleteJob->errorString();
- qCWarning(lcKeychainChunk) << "Unable to delete" << deleteJob->key() << "chunk" << QString::number(_chunkCount) << deleteJob->errorString();
- }
+ qCWarning(lcKeychainChunk) << "Maximum chunk count for" << deleteJob->key() << "reached, ignoring after" << KeychainChunk::MaxChunks;
+ }
+#endif
+ } else {
+ if (deleteJob->error() != QKeychain::EntryNotFound ||
+ ((deleteJob->error() == QKeychain::EntryNotFound) && _chunkCount == 0)) {
+ _error = deleteJob->error();
+ _errorString = deleteJob->errorString();
+ qCWarning(lcKeychainChunk) << "Unable to delete" << deleteJob->key() << "chunk" << QString::number(_chunkCount) << deleteJob->errorString();
}
-
- deleteJob->deleteLater();
}
+ deleteJob->deleteLater();
+
emit finished(this);
- if (_autoDelete)
+ if (_autoDelete) {
deleteLater();
+ }
}
} // namespace KeychainChunk
virtual ~Job();
- const QKeychain::Error error() const {
- return _error;
- }
- const QString errorString() const {
- return _errorString;
- }
-
- QByteArray binaryData() const {
- return _chunkBuffer;
- }
- QString textData() const {
- return _chunkBuffer;
- }
-
- const bool insecureFallback() const {
- return _insecureFallback;
- }
+ QKeychain::Error error() const;
+ QString errorString() const;
+
+ QByteArray binaryData() const;
+ QString textData() const;
+
+ bool insecureFallback() const;
// If we use it but don't support insecure fallback, give us nice compilation errors ;p
#if defined(KEYCHAINCHUNK_ENABLE_INSECURE_FALLBACK)
- void setInsecureFallback(const bool &insecureFallback)
- {
- _insecureFallback = insecureFallback;
- }
+ void setInsecureFallback(bool insecureFallback);
#endif
/**
* @return Whether this job autodeletes itself once finished() has been emitted. Default is true.
* @see setAutoDelete()
*/
- bool autoDelete() const {
- return _autoDelete;
- }
+ bool autoDelete() const;
/**
* Set whether this job should autodelete itself once finished() has been emitted.
* @see autoDelete()
*/
- void setAutoDelete(bool autoDelete) {
- _autoDelete = autoDelete;
- }
+ void setAutoDelete(bool autoDelete);
protected:
QString _serviceName;
{
Q_OBJECT
public:
- ReadJob(Account *account, const QString &key, const bool &keychainMigration, QObject *parent = nullptr);
+ ReadJob(Account *account, const QString &key, bool keychainMigration, QObject *parent = nullptr);
ReadJob(const QString &key, QObject *parent = nullptr);
/**
{
Q_OBJECT
public:
- DeleteJob(Account *account, const QString &key, const bool &keychainMigration, QObject *parent = nullptr);
+ DeleteJob(Account *account, const QString &key, bool keychainMigration, QObject *parent = nullptr);
DeleteJob(const QString &key, QObject *parent = nullptr);
/**