From e186400da8ddb2ef72842b957bbf1adfc181979c Mon Sep 17 00:00:00 2001 From: Ralph Plawetzki Date: Mon, 22 Feb 2021 18:01:49 +0100 Subject: [PATCH] Widen integrations-api to check whether keychain is locked --- pom.xml | 6 +++--- .../linux/keychain/KDEWalletKeychainAccess.java | 7 +++++++ .../linux/keychain/SecretServiceKeychainAccess.java | 10 ++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c9fd5c4..546d78d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.cryptomator integrations-linux - 0.1.1 + 0.2.0-SNAPSHOT integrations-linux Provides optional Linux services used by Cryptomator @@ -38,8 +38,8 @@ UTF-8 - 0.1.3 - 1.2.1 + 1.0.0-beta2 + 1.5.0 1.1.1 30.0-jre 1.7.30 diff --git a/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java b/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java index a7b5c7b..0e5bb6b 100644 --- a/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java +++ b/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java @@ -47,6 +47,11 @@ public boolean isSupported() { return wallet.map(ConnectedWallet::isSupported).orElse(false); } + @Override + public boolean isLocked() { + return wallet.map(ConnectedWallet::isLocked).orElse(false); + } + @Override public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException { Preconditions.checkState(wallet.isPresent(), "Keychain not supported."); @@ -84,6 +89,8 @@ public boolean isSupported() { return wallet.isEnabled(); } + public boolean isLocked() { return !wallet.isOpen(Static.DEFAULT_WALLET); } + public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException { try { if (walletIsOpen() && diff --git a/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java b/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java index 4962ad5..755cf63 100644 --- a/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java +++ b/src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java @@ -23,6 +23,16 @@ public boolean isSupported() { } } + @Override + 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) { + return true; + } + } + @Override public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException { try (SimpleCollection keyring = new SimpleCollection()) {