Migrate http auth to webflow

This moves all the basic http auth over to the webflow mechanism.
This thus also makes sure that if the password changes a webflow page
pops up. And thus will directly move them over to apptokens then.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-11-02 09:49:43 +01:00
parent 28fe702e8e
commit 045bba0161
No known key found for this signature in database
GPG key ID: F941078878347C0C
3 changed files with 43 additions and 11 deletions

View file

@ -253,6 +253,20 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
acc->setUrl(urlConfig.toUrl());
}
// Migrate to webflow
if (authType == QLatin1String("http")) {
authType = "webflow";
settings.setValue(QLatin1String(authTypeC), authType);
foreach(QString key, settings.childKeys()) {
if (!key.startsWith("http_"))
continue;
auto newkey = QString::fromLatin1("webflow_").append(key.mid(5));
settings.setValue(newkey, settings.value((key)));
settings.remove(key);
}
}
qCInfo(lcAccountManager) << "Account for" << acc->url() << "using auth type" << authType;
acc->_serverVersion = settings.value(QLatin1String(serverVersionC)).toString();

View file

@ -54,8 +54,9 @@ private:
};
WebFlowCredentials::WebFlowCredentials()
: _ready(false),
_credentialsValid(false)
: _ready(false)
, _credentialsValid(false)
, _keychainMigration(false)
{
}
@ -67,6 +68,7 @@ WebFlowCredentials::WebFlowCredentials(const QString &user, const QString &passw
, _clientSslCertificate(certificate)
, _ready(true)
, _credentialsValid(true)
, _keychainMigration(false)
{
}
@ -260,7 +262,7 @@ void WebFlowCredentials::fetchFromKeychainHelper() {
const QString kck = keychainKey(
_account->url().toString(),
_user,
_account->id());
_keychainMigration ? QString() : _account->id());
ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
job->setInsecureFallback(false);
@ -273,6 +275,13 @@ void WebFlowCredentials::slotReadPasswordJobDone(Job *incomingJob) {
QKeychain::ReadPasswordJob *job = static_cast<ReadPasswordJob *>(incomingJob);
QKeychain::Error error = job->error();
// If we could not find the entry try the old entries
if (!_keychainMigration && error == QKeychain::EntryNotFound) {
_keychainMigration = true;
fetchFromKeychainHelper();
return;
}
if (error == QKeychain::NoError) {
_password = job->textData();
_ready = true;
@ -280,8 +289,22 @@ void WebFlowCredentials::slotReadPasswordJobDone(Job *incomingJob) {
} else {
_ready = false;
}
emit fetched();
// If keychain data was read from legacy location, wipe these entries and store new ones
if (_keychainMigration && _ready) {
_keychainMigration = false;
persist();
deleteOldKeychainEntries();
qCWarning(lcWebFlowCredentials) << "Migrated old keychain entries";
}
}
void WebFlowCredentials::deleteOldKeychainEntries() {
DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
job->setInsecureFallback(false);
job->setKey(keychainKey(_account->url().toString(), _user, QString()));
job->start();
}
}

View file

@ -52,14 +52,8 @@ private slots:
void slotAskFromUserCredentialsProvided(const QString &user, const QString &pass, const QString &host);
private:
/** Reads data from keychain locations
*
* Goes through
* slotReadClientCertPEMJobDone to
* slotReadClientCertPEMJobDone to
* slotReadJobDone
*/
void fetchFromKeychainHelper();
void deleteOldKeychainEntries();
QString fetchUser();
@ -70,6 +64,7 @@ private:
bool _ready;
bool _credentialsValid;
bool _keychainMigration;
WebFlowCredentialsDialog *_askDialog;
};