Skip to content

Commit c22f813

Browse files
committed
Migrate KDE wallet entries
1 parent 9f227d0 commit c22f813

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
1515

16+
import javax.crypto.BadPaddingException;
17+
import javax.crypto.IllegalBlockSizeException;
18+
import javax.crypto.NoSuchPaddingException;
19+
import java.security.InvalidAlgorithmParameterException;
20+
import java.security.InvalidKeyException;
21+
import java.security.NoSuchAlgorithmException;
1622
import java.util.ArrayList;
1723
import java.util.List;
1824
import java.util.Map;
@@ -38,6 +44,8 @@ public SecretServiceKeychainAccess() {
3844
collection.addItemChangedHandler(item -> LOG.debug("Item {} changed", item.getPath()));
3945
collection.addItemCreatedHandler(item -> LOG.debug("Item {} created", item.getPath()));
4046
collection.addItemDeletedHandler(item -> LOG.debug("Item {} deleted", item.getPath()));
47+
48+
migrateKDEWalletEntries();
4149
}
4250

4351
@Override
@@ -152,4 +160,33 @@ public boolean isLocked() {
152160
private Map<String, String> createAttributes(String key) {
153161
return Map.of("Vault", key);
154162
}
163+
164+
private void migrateKDEWalletEntries() {
165+
session.setupEncryptedSession();
166+
var getItems = collection.getItems();
167+
if (getItems.isSuccess() && !getItems.value().isEmpty()) {
168+
for (DBusPath i : getItems.value()) {
169+
session.getService().ensureUnlocked(i);
170+
var attribs = new Item(i).getAttributes();
171+
if (attribs.isSuccess() &&
172+
attribs.value().containsKey("server") &&
173+
attribs.value().containsKey("user") &&
174+
attribs.value().get("server").equals("Cryptomator")) {
175+
176+
session.getService().ensureUnlocked(i);
177+
var item = new Item(i);
178+
var secret = item.getSecret(session.getSession());
179+
try {
180+
storePassphrase(attribs.value().get("user"), "Cryptomator", new String(session.decrypt(secret)));
181+
} catch (KeychainAccessException | NoSuchPaddingException | NoSuchAlgorithmException |
182+
InvalidAlgorithmParameterException | InvalidKeyException | BadPaddingException |
183+
IllegalBlockSizeException e) {
184+
LOG.error("Migrating entry {} for vault {} failed", i.getPath(), attribs.value().get("user"));
185+
}
186+
item.delete();
187+
LOG.info("Successfully migrated password for vault {}", attribs.value().get("user"));
188+
}
189+
}
190+
}
191+
}
155192
}

0 commit comments

Comments
 (0)