Skip to content

Commit d0688e2

Browse files
author
Armin Schrenk
authored
Merge pull request #1 from swiesend/develop
Use secret-service 1.5.0. Closes #2 .
2 parents 52d58e5 + 6513a9e commit d0688e2

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
<!-- runtime dependencies -->
4141
<api.version>0.1.3</api.version>
42-
<secret-service.version>1.2.1</secret-service.version>
42+
<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>
4545
<slf4j.version>1.7.30</slf4j.version>

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.freedesktop.secret.simple.SimpleCollection;
66

77
import java.io.IOException;
8+
import java.security.AccessControlException;
89
import java.util.HashMap;
910
import java.util.List;
1011
import java.util.Map;
@@ -15,24 +16,19 @@ public class SecretServiceKeychainAccess implements KeychainAccessProvider {
1516

1617
@Override
1718
public boolean isSupported() {
18-
try (@SuppressWarnings("unused") SimpleCollection keyring = new SimpleCollection()) {
19-
// seems like we're able to access the keyring.
20-
return true;
21-
} catch (IOException | ExceptionInInitializerError | RuntimeException e) {
22-
return false;
23-
}
19+
return SimpleCollection.isAvailable();
2420
}
2521

2622
@Override
2723
public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
2824
try (SimpleCollection keyring = new SimpleCollection()) {
2925
List<String> list = keyring.getItems(createAttributes(key));
30-
if (list == null) {
26+
if (list == null || list.isEmpty()) {
3127
keyring.createItem(LABEL_FOR_SECRET_IN_KEYRING, passphrase, createAttributes(key));
3228
} else {
3329
changePassphrase(key, passphrase);
3430
}
35-
} catch (IOException e) {
31+
} catch (IOException | AccessControlException e) {
3632
throw new KeychainAccessException("Storing password failed.", e);
3733
}
3834
}
@@ -41,12 +37,12 @@ public void storePassphrase(String key, CharSequence passphrase) throws Keychain
4137
public char[] loadPassphrase(String key) throws KeychainAccessException {
4238
try (SimpleCollection keyring = new SimpleCollection()) {
4339
List<String> list = keyring.getItems(createAttributes(key));
44-
if (list != null) {
40+
if (list != null && !list.isEmpty()) {
4541
return keyring.getSecret(list.get(0));
4642
} else {
4743
return null;
4844
}
49-
} catch (IOException e) {
45+
} catch (IOException | AccessControlException e) {
5046
throw new KeychainAccessException("Loading password failed.", e);
5147
}
5248
}
@@ -55,10 +51,10 @@ public char[] loadPassphrase(String key) throws KeychainAccessException {
5551
public void deletePassphrase(String key) throws KeychainAccessException {
5652
try (SimpleCollection keyring = new SimpleCollection()) {
5753
List<String> list = keyring.getItems(createAttributes(key));
58-
if (list != null) {
54+
if (list != null && !list.isEmpty()) {
5955
keyring.deleteItem(list.get(0));
6056
}
61-
} catch (IOException e) {
57+
} catch (IOException | AccessControlException e) {
6258
throw new KeychainAccessException("Deleting password failed.", e);
6359
}
6460
}
@@ -67,15 +63,16 @@ public void deletePassphrase(String key) throws KeychainAccessException {
6763
public void changePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
6864
try (SimpleCollection keyring = new SimpleCollection()) {
6965
List<String> list = keyring.getItems(createAttributes(key));
70-
if (list != null) {
66+
if (list != null && !list.isEmpty()) {
7167
keyring.updateItem(list.get(0), LABEL_FOR_SECRET_IN_KEYRING, passphrase, createAttributes(key));
7268
}
73-
} catch (IOException e) {
69+
} catch (IOException | AccessControlException e) {
7470
throw new KeychainAccessException("Changing password failed.", e);
7571
}
7672
}
7773

7874
private Map<String, String> createAttributes(String key) {
7975
return Map.of("Vault", key);
8076
}
77+
8178
}

0 commit comments

Comments
 (0)