Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widen integrations-api to check whether keychain is locked #10

Merged
merged 2 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cryptomator</groupId>
<artifactId>integrations-linux</artifactId>
<version>0.1.1</version>
<version>0.2.0-SNAPSHOT</version>

<name>integrations-linux</name>
<description>Provides optional Linux services used by Cryptomator</description>
Expand Down Expand Up @@ -38,8 +38,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- runtime dependencies -->
<api.version>0.1.3</api.version>
<secret-service.version>1.2.1</secret-service.version>
<api.version>1.0.0-beta2</api.version>
<secret-service.version>1.5.0</secret-service.version>
<kdewallet.version>1.1.1</kdewallet.version>
<guava.version>30.0-jre</guava.version>
<slf4j.version>1.7.30</slf4j.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down