diff --git a/.setupkeystore.sh b/.setupkeystore.sh index 401f648..450a968 100755 --- a/.setupkeystore.sh +++ b/.setupkeystore.sh @@ -4,6 +4,7 @@ keyring="$1" set -x if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ] && [ "$keyring" == "gnome" ]; then + killall kwalletd || true export $(dbus-launch) # --config-file=${GITHUB_WORKSPACE}/.github/workflows/dbus.xml) eval "$(echo '\n' | gnome-keyring-daemon --unlock)" echo xxx@gmail.com | secret-tool store --label="main" email address @@ -21,6 +22,7 @@ if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ] && [ "$keyring" == "kde" ]; t # install pre-filled wallet (because there is no way to interactively create key store without password) # created with empty password # entry added with `kwalletcli -f . -e address -p xxx@gmail.com` + killall gnome-keyring-daemon || true mkdir -p ~/.local/share/kwalletd cp $GITHUB_WORKSPACE/.setupkeystore/* ~/.local/share/kwalletd chmod 600 ~/.local/share/kwalletd/* diff --git a/java-keyring/pom.xml b/java-keyring/pom.xml index 8d672d0..03a7193 100644 --- a/java-keyring/pom.xml +++ b/java-keyring/pom.xml @@ -21,6 +21,14 @@ + + com.github.hypfvieh + dbus-java-core + + + com.github.hypfvieh + dbus-java-transport-jnr-unixsocket + de.swiesend secret-service @@ -35,14 +43,6 @@ - - com.github.hypfvieh - dbus-java-transport-jnr-unixsocket - - - com.github.hypfvieh - dbus-java-core - net.java.dev.jna jna @@ -55,6 +55,10 @@ org.slf4j slf4j-api + + org.slf4j + slf4j-simple + pt.davidafsilva.apple jkeychain diff --git a/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/FreedesktopKeyringBackend.java b/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/FreedesktopKeyringBackend.java index d205391..2a6ff2d 100755 --- a/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/FreedesktopKeyringBackend.java +++ b/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/FreedesktopKeyringBackend.java @@ -52,7 +52,10 @@ public class FreedesktopKeyringBackend implements KeyringBackend { public FreedesktopKeyringBackend() throws BackendNotSupportedException { try { collection = new SimpleCollection(); - } catch (IOException ex) { + if (!collection.isConnected()) { + throw new BackendNotSupportedException("Error connecting to dbus"); + } + } catch (IOException | IllegalStateException ex) { throw new BackendNotSupportedException("Error connecting to dbus", ex); } } diff --git a/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/SimpleCollection.java b/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/SimpleCollection.java index 8efebb8..57f0c2b 100755 --- a/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/SimpleCollection.java +++ b/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/SimpleCollection.java @@ -82,6 +82,10 @@ public SimpleCollection() throws IOException { unlock(); } + public boolean isConnected() { + return this.session.getConnection().isConnected(); + } + /* * A user specified collection. * diff --git a/java-keyring/src/main/java/com/github/javakeyring/internal/kde/KWalletBackend.java b/java-keyring/src/main/java/com/github/javakeyring/internal/kde/KWalletBackend.java index b127156..454f9dd 100644 --- a/java-keyring/src/main/java/com/github/javakeyring/internal/kde/KWalletBackend.java +++ b/java-keyring/src/main/java/com/github/javakeyring/internal/kde/KWalletBackend.java @@ -32,7 +32,7 @@ import org.freedesktop.dbus.annotations.DBusInterfaceName; import org.freedesktop.dbus.connections.impl.DBusConnection; -import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder; +//import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder; import org.freedesktop.dbus.interfaces.DBusInterface; import java.io.IOException; @@ -47,15 +47,8 @@ public class KWalletBackend implements KeyringBackend { public KWalletBackend() throws BackendNotSupportedException { try { - // connection = DBusConnectionBuilder.forAddress(BusAddress.of(System.getProperty("DBUS_TCP_SESSION"))) - // .withRegisterSelf(true) - // .withShared(true) - // .transportConfig() - // .withAdditionalConfig("TIMEOUT", 10000) - // .back() - // .build(); - - connection = DBusConnectionBuilder.forSessionBus().build(); + //connection = DBusConnectionBuilder.forSessionBus().build(); + connection = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION); wallet = connection.getRemoteObject("org.kde.kwalletd5", "/modules/kwalletd5", KWallet.class, true); wallet.localWallet(); //attempt connection to wallet } catch (Exception e) { diff --git a/java-keyring/src/test/java/com/github/javakeyring/KeyringTest.java b/java-keyring/src/test/java/com/github/javakeyring/KeyringTest.java index f1c3872..2854288 100644 --- a/java-keyring/src/test/java/com/github/javakeyring/KeyringTest.java +++ b/java-keyring/src/test/java/com/github/javakeyring/KeyringTest.java @@ -32,6 +32,8 @@ import static org.junit.Assert.assertNotNull; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.jna.Platform; @@ -54,6 +56,8 @@ public class KeyringTest { private static final String PASSWORD3 = "password3"; + private static final Logger LOGGER = LoggerFactory.getLogger(KeyringTest.class); + /** * Test of create method, of class Keyring. */ @@ -61,6 +65,8 @@ public class KeyringTest { public void testCreateZeroArgs() throws Exception { try (Keyring keyring = Keyring.create()) { assertNotNull(keyring); + KeyringStorageType type = keyring.getKeyringStorageType(); + LOGGER.warn("Running tests on {}", type); } } diff --git a/java-keyring/src/test/java/com/github/javakeyring/internal/KeyringBackendFactoryTest.java b/java-keyring/src/test/java/com/github/javakeyring/internal/KeyringBackendFactoryTest.java index f7fad93..75a0e45 100644 --- a/java-keyring/src/test/java/com/github/javakeyring/internal/KeyringBackendFactoryTest.java +++ b/java-keyring/src/test/java/com/github/javakeyring/internal/KeyringBackendFactoryTest.java @@ -33,6 +33,7 @@ import com.github.javakeyring.BackendNotSupportedException; + public class KeyringBackendFactoryTest { @Test diff --git a/java-keyring/src/test/java/com/github/javakeyring/kde/KWalletBackendTest.java b/java-keyring/src/test/java/com/github/javakeyring/kde/KWalletBackendTest.java index 2411320..8bea9c2 100644 --- a/java-keyring/src/test/java/com/github/javakeyring/kde/KWalletBackendTest.java +++ b/java-keyring/src/test/java/com/github/javakeyring/kde/KWalletBackendTest.java @@ -30,7 +30,6 @@ import com.github.javakeyring.Keyring; import com.github.javakeyring.KeyringStorageType; import com.github.javakeyring.PasswordAccessException; -import com.github.javakeyring.internal.KeyringBackend; import com.github.javakeyring.internal.freedesktop.FreedesktopKeyringBackend; import com.github.javakeyring.internal.kde.KWalletBackend; import com.sun.jna.Platform; @@ -64,18 +63,20 @@ public void testSetup() throws Exception { */ @Test public void testPasswordFlow() throws Exception { - assumeTrue(Platform.isLinux() && Keyring.create().getKeyringStorageType() == KeyringStorageType.KWALLET); - KeyringBackend backend = new KWalletBackend(); - catchThrowable(() -> backend.deletePassword(SERVICE, ACCOUNT)); - checkExistenceOfPasswordEntry(backend); - backend.setPassword(SERVICE, ACCOUNT, PASSWORD); - assertThat(backend.getPassword(SERVICE, ACCOUNT)).isEqualTo(PASSWORD); - backend.deletePassword(SERVICE, ACCOUNT); - assertThatThrownBy(() -> backend.getPassword(SERVICE, ACCOUNT)).isInstanceOf(PasswordAccessException.class); + assumeTrue(Platform.isLinux()); + assumeTrue(catchThrowable(KWalletBackend::new) == null); + Keyring keyring = Keyring.create(); + assertThat(keyring.getKeyringStorageType()).isEqualTo(KeyringStorageType.KWALLET); + catchThrowable(() -> keyring.deletePassword(SERVICE, ACCOUNT)); + checkExistenceOfPasswordEntry(keyring); + keyring.setPassword(SERVICE, ACCOUNT, PASSWORD); + assertThat(keyring.getPassword(SERVICE, ACCOUNT)).isEqualTo(PASSWORD); + keyring.deletePassword(SERVICE, ACCOUNT); + assertThatThrownBy(() -> keyring.getPassword(SERVICE, ACCOUNT)).isInstanceOf(PasswordAccessException.class); } - private static void checkExistenceOfPasswordEntry(KeyringBackend backend) { - assertThatThrownBy(() -> backend.getPassword(SERVICE, ACCOUNT)) + private static void checkExistenceOfPasswordEntry(Keyring keyring) { + assertThatThrownBy(() -> keyring.getPassword(SERVICE, ACCOUNT)) .as("Please remove password entry '%s' " + "by using Keychain Access before running the tests", SERVICE) .isNotNull(); } diff --git a/pom.xml b/pom.xml index aa68401..90b91e3 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,21 @@ + + ch.qos.logback + logback-core + 1.4.11 + + + com.github.hypfvieh + dbus-java-core + 4.3.0 + + + com.github.hypfvieh + dbus-java-transport-jnr-unixsocket + 4.3.0 + de.swiesend secret-service @@ -58,16 +73,6 @@ jna-platform 5.13.0 - - com.github.hypfvieh - dbus-java-transport-jnr-unixsocket - 4.3.0 - - - com.github.hypfvieh - dbus-java-core - 4.3.0 - org.ow2.asm asm @@ -83,6 +88,11 @@ slf4j-api 2.0.7 + + org.slf4j + slf4j-simple + 2.0.7 + pt.davidafsilva.apple jkeychain