Skip to content

Commit 6d9f914

Browse files
author
Armin Schrenk
authored
Merge pull request #10 from purejava/keychain-isLocked
Widen integrations-api to check whether keychain is locked
2 parents dfd81a0 + 62a94fe commit 6d9f914

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3939

4040
<!-- runtime dependencies -->
41-
<api.version>0.1.3</api.version>
41+
<api.version>1.0.0-beta2</api.version>
4242
<secret-service.version>1.5.0</secret-service.version>
4343
<kdewallet.version>1.1.1</kdewallet.version>
4444
<guava.version>30.0-jre</guava.version>

src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public boolean isSupported() {
4747
return wallet.map(ConnectedWallet::isSupported).orElse(false);
4848
}
4949

50+
@Override
51+
public boolean isLocked() {
52+
return wallet.map(ConnectedWallet::isLocked).orElse(false);
53+
}
54+
5055
@Override
5156
public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
5257
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
@@ -84,6 +89,8 @@ public boolean isSupported() {
8489
return wallet.isEnabled();
8590
}
8691

92+
public boolean isLocked() { return !wallet.isOpen(Static.DEFAULT_WALLET); }
93+
8794
public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
8895
try {
8996
if (walletIsOpen() &&

src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ public boolean isSupported() {
1919
return SimpleCollection.isAvailable();
2020
}
2121

22+
@Override
23+
public boolean isLocked() {
24+
try (@SuppressWarnings("unused") SimpleCollection keyring = new SimpleCollection()) {
25+
// seems like we're able to access the keyring.
26+
return keyring.isLocked();
27+
} catch (IOException | ExceptionInInitializerError | RuntimeException e) {
28+
return true;
29+
}
30+
}
31+
2232
@Override
2333
public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
2434
try (SimpleCollection keyring = new SimpleCollection()) {

0 commit comments

Comments
 (0)