Skip to content

purejava/kdewallet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kdewallet

KWallet

Publish to Maven Central Codacy Badge Maven Central License

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.

Usage

The library provides an API, which sends secrets over D-Bus and has D-Bus signaling enabled.

Dependency

Add kdewallet as a dependency to your project.

<dependency>
    <groupId>org.purejava</groupId>
    <artifactId>kdewallet</artifactId>
    <version>1.5.0</version>
</dependency>

Accessing the kwallet daemon

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();
        }
    }
}

Signal handling

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.

Thank you

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

Copyright (C) 2020-2024 Ralph Plawetzki