Skip to content

Commit aa7e387

Browse files
committed
Add legacy support for KWallet maps
In the ongoing migration from KWallet to QtKeychain in Plasma, in order to migrate without too strong rewrites and most important have the existing stored data still working, (some secrets actually have the structure of multiple key value maps) make reading from map still work. return it as a json serialized string, which is also how the kwallet compatibility layer stores maps on secretservice. This is only supported while reading, so when writing again it will be written directly as a serialized json string. this makes an implicit data migration which will make easier to go completely away from kwallet.
1 parent 6e90eda commit aa7e387

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

qtkeychain/keychain_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class JobPrivate : public QObject
3636
{
3737
Q_OBJECT
3838
public:
39-
enum Mode { Text, Binary };
39+
enum Mode { Text, Binary, Map };
4040

4141
virtual void scheduledStart() = 0;
4242

qtkeychain/keychain_unix.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,16 +420,19 @@ void ReadPasswordJobPrivate::kwalletEntryTypeFinished(QDBusPendingCallWatcher *w
420420
case Stream:
421421
mode = Binary;
422422
break;
423-
case Map:
424-
q->emitFinishedWithError(EntryNotFound, tr("Unsupported entry type 'Map'"));
425-
return;
423+
case KWalletEntryType::Map: {
424+
mode = JobPrivate::Map;
425+
break;
426+
}
426427
default:
427428
q->emitFinishedWithError(OtherError, tr("Unknown kwallet entry type '%1'").arg(value));
428429
return;
429430
}
430431

431432
const auto nextReply = (mode == Text)
432433
? QDBusPendingCall(iface->readPassword(walletHandle, q->service(), key, q->service()))
434+
: (mode == JobPrivate::Map)
435+
? QDBusPendingCall(iface->readMap(walletHandle, q->service(), key, q->service()))
433436
: QDBusPendingCall(iface->readEntry(walletHandle, q->service(), key, q->service()));
434437
auto nextWatcher = new QDBusPendingCallWatcher(nextReply, this);
435438
connect(nextWatcher, &QDBusPendingCallWatcher::finished, this,
@@ -444,6 +447,20 @@ void ReadPasswordJobPrivate::kwalletFinished(QDBusPendingCallWatcher *watcher)
444447
if (reply.isValid()) {
445448
data = reply.value();
446449
}
450+
} else if (mode == Map) {
451+
QDBusPendingReply<QByteArray> reply = *watcher;
452+
if (reply.isValid()) {
453+
QByteArray v = reply.value();
454+
QMap<QString, QString> map;
455+
QDataStream ds(&v, QIODevice::ReadOnly);
456+
ds >> map;
457+
QJsonObject json;
458+
for (auto it = map.constBegin(); it != map.constEnd(); ++it) {
459+
json.insert(it.key(), it.value());
460+
}
461+
QJsonDocument doc(json);
462+
data = doc.toJson(QJsonDocument::Compact);
463+
}
447464
} else {
448465
QDBusPendingReply<QString> reply = *watcher;
449466
if (reply.isValid()) {

0 commit comments

Comments
 (0)