From fe54f7eaeaf9b10c1322fc66bc97ee06d778ccaf Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Mon, 7 Jun 2021 17:01:19 +0200 Subject: [PATCH 1/3] update SecretService, fixes #5 --- pom.xml | 2 +- .../cryptomator/linux/keychain/SecretServiceKeychainAccess.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 02a3a81..775219d 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ 1.0.0-beta2 - 1.5.0 + 1.6.2 1.1.1 30.0-jre 1.7.30 diff --git a/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java b/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java index 1d6c714..72cdd1c 100644 --- a/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java +++ b/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java @@ -24,7 +24,7 @@ public boolean isLocked() { try (@SuppressWarnings("unused") SimpleCollection keyring = new SimpleCollection()) { // seems like we're able to access the keyring. return keyring.isLocked(); - } catch (IOException | ExceptionInInitializerError | RuntimeException e) { + } catch (IOException e) { return true; } } From 632f89d079364e276b0b541e49099db66caa37ab Mon Sep 17 00:00:00 2001 From: Ralph Plawetzki Date: Mon, 7 Jun 2021 17:06:44 +0200 Subject: [PATCH 2/3] Refactor DBus Connection Initialization (#9) Refactor DBus Connection Initialization Fixes cryptomator#6 Co-authored-by: Sebastian Stenzel --- pom.xml | 2 +- .../keychain/KDEWalletKeychainAccess.java | 42 +++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 775219d..e30634f 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ 1.0.0-beta2 1.6.2 - 1.1.1 + 1.2.1 30.0-jre 1.7.30 5.7.0 diff --git a/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java b/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java index 0e5bb6b..a5af938 100644 --- a/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java +++ b/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java @@ -4,6 +4,7 @@ import org.cryptomator.integrations.keychain.KeychainAccessException; import org.cryptomator.integrations.keychain.KeychainAccessProvider; import org.freedesktop.dbus.connections.impl.DBusConnection; +import org.freedesktop.dbus.exceptions.DBusConnectionException; import org.freedesktop.dbus.exceptions.DBusException; import org.kde.KWallet; import org.kde.Static; @@ -22,24 +23,7 @@ public class KDEWalletKeychainAccess implements KeychainAccessProvider { private final Optional wallet; public KDEWalletKeychainAccess() { - ConnectedWallet wallet = null; - try { - DBusConnection conn = null; - try { - conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION); - } catch (RuntimeException e) { - if (e.getMessage() == "Cannot Resolve Session Bus Address") { - LOG.warn("SESSION DBus not found."); - } - } - if (conn == null) { - conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SYSTEM); - } - wallet = new ConnectedWallet(conn); - } catch (DBusException e) { - LOG.warn("Connecting to D-Bus failed.", e); - } - this.wallet = Optional.ofNullable(wallet); + this.wallet = ConnectedWallet.connect(); } @Override @@ -85,6 +69,28 @@ public ConnectedWallet(DBusConnection connection) { this.wallet = new KDEWallet(connection); } + static Optional connect() { + try { + return Optional.of(new ConnectedWallet(getConnection())); + } catch (DBusException e) { + LOG.warn("Connecting to D-Bus failed.", e); + return Optional.empty(); + } + } + + private static DBusConnection getConnection() throws DBusException { + try { + return DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION); + } catch (DBusConnectionException ce) { + LOG.warn("SESSION DBus not found, falling back to SYSTEM DBus"); + try { + return DBusConnection.getConnection(DBusConnection.DBusBusType.SYSTEM); + } catch (DBusException e) { + throw e; + } + } + } + public boolean isSupported() { return wallet.isEnabled(); } From 3371cf5ea5ff4578d584a123836f2f6d916ac76b Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Mon, 7 Jun 2021 17:18:45 +0200 Subject: [PATCH 3/3] implement KeychainAccessProvider.displayName() --- pom.xml | 2 +- .../cryptomator/linux/keychain/KDEWalletKeychainAccess.java | 5 +++++ .../linux/keychain/SecretServiceKeychainAccess.java | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e30634f..c01c931 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ UTF-8 - 1.0.0-beta2 + 1.0.0-rc1 1.6.2 1.2.1 30.0-jre diff --git a/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java b/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java index a5af938..58721da 100644 --- a/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java +++ b/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java @@ -26,6 +26,11 @@ public KDEWalletKeychainAccess() { this.wallet = ConnectedWallet.connect(); } + @Override + public String displayName() { + return "KDE Wallet"; + } + @Override public boolean isSupported() { return wallet.map(ConnectedWallet::isSupported).orElse(false); diff --git a/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java b/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java index 72cdd1c..9dd4963 100644 --- a/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java +++ b/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java @@ -6,7 +6,6 @@ import java.io.IOException; import java.security.AccessControlException; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -14,6 +13,11 @@ public class SecretServiceKeychainAccess implements KeychainAccessProvider { private final String LABEL_FOR_SECRET_IN_KEYRING = "Cryptomator"; + @Override + public String displayName() { + return "Gnome Keyring"; + } + @Override public boolean isSupported() { return SimpleCollection.isAvailable();