A Java library for storing secrets on linux in a KDE wallet over D-Bus.
The KDE wallet functionality itself is provided by the kwallet daemon kwalletd.
The library provides an API, which sends secrets over D-Bus and has D-Bus signaling enabled.
Add kdewallet
as a dependency to your project.
<dependency>
<groupId>org.purejava</groupId>
<artifactId>kdewallet</artifactId>
<version>1.5.1</version>
</dependency>
Creating a folder in a wallet can be done like this:
package org.example;
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder;
import org.freedesktop.dbus.exceptions.DBusException;
import org.kde.KWallet;
import java.io.IOException;
public class App {
public static void main(String[] args) {
DBusConnection connection = null;
try {
connection = DBusConnectionBuilder.forSessionBus().withShared(false).build();
var service = connection.getRemoteObject("org.kde.kwalletd6",
"/modules/kwalletd6", KWallet.class);
var wallet = "kdewallet";
var wId = 0;
var appid = "Tester";
var handle = service.open(wallet, wId, appid);
var folder = "Test-Folder";
var created = service.createFolder(handle, folder, appid);
service.close(handle, false, appid);
} catch (DBusException e) {
System.out.println(e.toString() + e.getCause());
}
try {
connection.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
D-Bus signals are emitted on every change to a wallet, e.g. when it's opened asynchronously, closed etc. Listening to these signals can be done asynchronously with few effort.
For the complete API and examples see the Wiki.
Thanks to David M., who wrote an improved version of Java DBus library provided by freedesktop.org. Thanks to Sebastian Wiesendahl, who implemented the original core messaging interface to DBus in his secret-service library.
Copyright (C) 2020-2024 Ralph Plawetzki