Skip to content

Commit

Permalink
Merge branch 'develop' into release/1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Jun 7, 2021
2 parents bcc34aa + 3371cf5 commit eb39be9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- runtime dependencies -->
<api.version>1.0.0-beta2</api.version>
<secret-service.version>1.5.0</secret-service.version>
<kdewallet.version>1.1.1</kdewallet.version>
<api.version>1.0.0-rc1</api.version>
<secret-service.version>1.6.2</secret-service.version>
<kdewallet.version>1.2.1</kdewallet.version>
<guava.version>30.0-jre</guava.version>
<slf4j.version>1.7.30</slf4j.version>
<junit.version>5.7.0</junit.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,24 +23,12 @@ public class KDEWalletKeychainAccess implements KeychainAccessProvider {
private final Optional<ConnectedWallet> 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
public String displayName() {
return "KDE Wallet";
}

@Override
Expand Down Expand Up @@ -85,6 +74,28 @@ public ConnectedWallet(DBusConnection connection) {
this.wallet = new KDEWallet(connection);
}

static Optional<ConnectedWallet> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@

import java.io.IOException;
import java.security.AccessControlException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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();
Expand All @@ -24,7 +28,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;
}
}
Expand Down

0 comments on commit eb39be9

Please sign in to comment.