, _ready(false)
, _stillValid(false)
, _browser(0)
+ , _keychainMigration(false)
{
}
, _stillValid(true)
, _browser(0)
, _shibCookie(cookie)
+ , _keychainMigration(false)
{
}
Q_EMIT fetched();
} else {
_url = _account->url();
- ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
- job->setSettings(ConfigFile::settingsWithGroup(Theme::instance()->appName(), job).release());
- job->setInsecureFallback(false);
- job->setKey(keychainKey(_account->url().toString(), user()));
- connect(job, SIGNAL(finished(QKeychain::Job *)), SLOT(slotReadJobDone(QKeychain::Job *)));
- job->start();
+ _keychainMigration = false;
+ fetchFromKeychainHelper();
}
}
+void ShibbolethCredentials::fetchFromKeychainHelper()
+{
+ ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
+ job->setSettings(ConfigFile::settingsWithGroup(Theme::instance()->appName(), job).release());
+ job->setInsecureFallback(false);
+ job->setKey(keychainKey(_url.toString(), user(),
+ _keychainMigration ? QString() : _account->id()));
+ connect(job, SIGNAL(finished(QKeychain::Job *)), SLOT(slotReadJobDone(QKeychain::Job *)));
+ job->start();
+}
+
void ShibbolethCredentials::askFromUser()
{
showLoginWindow();
void ShibbolethCredentials::slotReadJobDone(QKeychain::Job *job)
{
+ // If we can't find the credentials at the keys that include the account id,
+ // try to read them from the legacy locations that don't have a account id.
+ if (!_keychainMigration && job->error() == QKeychain::EntryNotFound) {
+ qCWarning(lcShibboleth)
+ << "Could not find keychain entry, attempting to read from legacy location";
+ _keychainMigration = true;
+ fetchFromKeychainHelper();
+ return;
+ }
+
if (job->error() == QKeychain::NoError) {
ReadPasswordJob *readJob = static_cast<ReadPasswordJob *>(job);
delete readJob->settings();
_ready = false;
Q_EMIT fetched();
}
+
+
+ // If keychain data was read from legacy location, wipe these entries and store new ones
+ if (_keychainMigration && _ready) {
+ persist();
+
+ DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
+ job->setSettings(ConfigFile::settingsWithGroup(Theme::instance()->appName(), job).release());
+ job->setKey(keychainKey(_account->url().toString(), user(), QString()));
+ job->start();
+
+ qCWarning(lcShibboleth) << "Migrated old keychain entries";
+ }
}
void ShibbolethCredentials::showLoginWindow()
job->setSettings(ConfigFile::settingsWithGroup(Theme::instance()->appName(), job).release());
// we don't really care if it works...
//connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotWriteJobDone(QKeychain::Job*)));
- job->setKey(keychainKey(_account->url().toString(), user()));
+ job->setKey(keychainKey(_account->url().toString(), user(), _account->id()));
job->setTextData(QString::fromUtf8(cookie.toRawForm()));
job->start();
}
{
DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
job->setSettings(ConfigFile::settingsWithGroup(Theme::instance()->appName(), job).release());
- job->setKey(keychainKey(_account->url().toString(), user()));
+ job->setKey(keychainKey(_account->url().toString(), user(), _account->id()));
job->start();
}
jar->blockSignals(false);
}
-
} // namespace OCC
HttpCredentials::HttpCredentials()
: _ready(false)
+ , _keychainMigration(false)
{
}
, _ready(true)
, _clientSslKey(key)
, _clientSslCertificate(certificate)
+ , _keychainMigration(false)
{
}
return;
}
- const QString kck = keychainKey(_account->url().toString(), _user);
-
if (_ready) {
Q_EMIT fetched();
} else {
- // Read client cert from keychain
- const QString kck = keychainKey(_account->url().toString(), _user + clientCertificatePEMC);
- ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
- addSettingsToJob(_account, job);
- job->setInsecureFallback(false);
- job->setKey(kck);
+ _keychainMigration = false;
+ fetchFromKeychainHelper();
+ }
+}
- connect(job, SIGNAL(finished(QKeychain::Job *)), SLOT(slotReadClientCertPEMJobDone(QKeychain::Job *)));
+void HttpCredentials::fetchFromKeychainHelper()
+{
+ // Read client cert from keychain
+ const QString kck = keychainKey(
+ _account->url().toString(),
+ _user + clientCertificatePEMC,
+ _keychainMigration ? QString() : _account->id());
+
+ ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
+ addSettingsToJob(_account, job);
+ job->setInsecureFallback(false);
+ job->setKey(kck);
+ connect(job, SIGNAL(finished(QKeychain::Job *)), SLOT(slotReadClientCertPEMJobDone(QKeychain::Job *)));
+ job->start();
+}
+
+void HttpCredentials::deleteOldKeychainEntries()
+{
+ auto startDeleteJob = [this](QString user) {
+ DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
+ addSettingsToJob(_account, job);
+ job->setInsecureFallback(true);
+ job->setKey(keychainKey(_account->url().toString(), user, QString()));
job->start();
- }
+ };
+
+ startDeleteJob(_user);
+ startDeleteJob(_user + clientKeyPEMC);
+ startDeleteJob(_user + clientCertificatePEMC);
}
void HttpCredentials::slotReadClientCertPEMJobDone(QKeychain::Job *incoming)
}
// Load key too
- const QString kck = keychainKey(_account->url().toString(), _user + clientKeyPEMC);
+ const QString kck = keychainKey(
+ _account->url().toString(),
+ _user + clientKeyPEMC,
+ _keychainMigration ? QString() : _account->id());
+
ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
addSettingsToJob(_account, job);
job->setInsecureFallback(false);
job->setKey(kck);
-
connect(job, SIGNAL(finished(QKeychain::Job *)), SLOT(slotReadClientKeyPEMJobDone(QKeychain::Job *)));
job->start();
}
}
// Now fetch the actual server password
- const QString kck = keychainKey(_account->url().toString(), _user);
+ const QString kck = keychainKey(
+ _account->url().toString(),
+ _user,
+ _keychainMigration ? QString() : _account->id());
+
ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
addSettingsToJob(_account, job);
job->setInsecureFallback(false);
job->setKey(kck);
-
connect(job, SIGNAL(finished(QKeychain::Job *)), SLOT(slotReadJobDone(QKeychain::Job *)));
job->start();
}
void HttpCredentials::slotReadJobDone(QKeychain::Job *incomingJob)
{
QKeychain::ReadPasswordJob *job = static_cast<ReadPasswordJob *>(incomingJob);
+ QKeychain::Error error = job->error();
+
+ // If we can't find the credentials at the keys that include the account id,
+ // try to read them from the legacy locations that don't have a account id.
+ if (!_keychainMigration && error == QKeychain::EntryNotFound) {
+ qCWarning(lcHttpCredentials)
+ << "Could not find keychain entries, attempting to read from legacy locations";
+ _keychainMigration = true;
+ fetchFromKeychainHelper();
+ return;
+ }
bool isOauth = _account->credentialSetting(QLatin1String(isOAuthC)).toBool();
if (isOauth) {
qCWarning(lcHttpCredentials) << "Strange: User is empty!";
}
- QKeychain::Error error = job->error();
-
if (!_refreshToken.isEmpty() && error == NoError) {
refreshAccessToken();
} else if (!_password.isEmpty() && error == NoError) {
_ready = false;
emit fetched();
}
+
+ // If keychain data was read from legacy location, wipe these entries and store new ones
+ if (_keychainMigration && _ready) {
+ persist();
+ deleteOldKeychainEntries();
+ qCWarning(lcHttpCredentials) << "Migrated old keychain entries";
+ }
}
bool HttpCredentials::refreshAccessToken()
// User must be fetched from config file to generate a valid key
fetchUser();
- const QString kck = keychainKey(_account->url().toString(), _user);
+ const QString kck = keychainKey(_account->url().toString(), _user, _account->id());
if (kck.isEmpty()) {
qCWarning(lcHttpCredentials) << "InvalidateToken: User is empty, bailing out!";
return;
addSettingsToJob(_account, job);
job->setInsecureFallback(false);
connect(job, SIGNAL(finished(QKeychain::Job *)), SLOT(slotWriteClientCertPEMJobDone(QKeychain::Job *)));
- job->setKey(keychainKey(_account->url().toString(), _user + clientCertificatePEMC));
+ job->setKey(keychainKey(_account->url().toString(), _user + clientCertificatePEMC, _account->id()));
job->setBinaryData(_clientSslCertificate.toPem());
job->start();
}
addSettingsToJob(_account, job);
job->setInsecureFallback(false);
connect(job, SIGNAL(finished(QKeychain::Job *)), SLOT(slotWriteClientKeyPEMJobDone(QKeychain::Job *)));
- job->setKey(keychainKey(_account->url().toString(), _user + clientKeyPEMC));
+ job->setKey(keychainKey(_account->url().toString(), _user + clientKeyPEMC, _account->id()));
job->setBinaryData(_clientSslKey.toPem());
job->start();
}
addSettingsToJob(_account, job);
job->setInsecureFallback(false);
connect(job, SIGNAL(finished(QKeychain::Job *)), SLOT(slotWriteJobDone(QKeychain::Job *)));
- job->setKey(keychainKey(_account->url().toString(), _user));
+ job->setKey(keychainKey(_account->url().toString(), _user, _account->id()));
job->setTextData(isUsingOAuth() ? _refreshToken : _password);
job->start();
}