Skip to content

Commit d7c0d81

Browse files
committed
Merge branch 'develop' into main
2 parents b79740c + c9624da commit d7c0d81

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# keepassxc-cryptomator
22
![keepassxc-cryptomator](keepassxc-cryptomator.svg)
33

4+
[![Java CI with Maven](https://github.com/purejava/keepassxc-cryptomator/workflows/Java%20CI%20with%20Maven/badge.svg)](https://github.com/purejava/keepassxc-cryptomator/actions?query=workflow%3A%22Java+CI+with+Maven%22)
5+
[![Maven Central](https://img.shields.io/maven-central/v/org.purejava/keepassxc-cryptomator.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22org.purejava%22%20AND%20a:%22keepassxc-cryptomator%22)
6+
[![License](https://img.shields.io/github/license/purejava/keepassxc-cryptomator.svg)](https://github.com/purejava/keepassxc-cryptomator/blob/master/LICENSE)
47
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate?hosted_button_id=XVX9ZM7WE4ANL)
58

69
Store Cryptomator vault passwords in KeePassXC

pom.xml

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

5151
<!-- runtime dependencies -->
52-
<api.version>0.2.1-SNAPSHOT</api.version>
52+
<api.version>1.0.0-beta3</api.version>
5353
<keepassxc-proxy.version>0.0.3</keepassxc-proxy.version>
5454
<guava.version>30.0-jre</guava.version>
5555
<slf4j.version>1.7.30</slf4j.version>

src/main/java/org/purejava/integrations/keychain/KeePassXCAccess.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,47 @@ public KeePassXCAccess() {
2828
@Override
2929
public boolean isLocked() { return proxy.getDatabasehash().isEmpty(); }
3030

31-
@Override
32-
public boolean needsAssociation() { return !proxy.connectionAvailable(); }
33-
34-
@Override
35-
public boolean associate() { return proxy.associate(); }
31+
private void ensureAssociation() throws KeychainAccessException {
32+
if (!proxy.connectionAvailable()) { // Proxy needs association
33+
if (!proxy.associate()) {
34+
throw new KeychainAccessException("Association with KeePassXC database failed");
35+
}
36+
}
37+
}
3638

3739
public String unlock() { return proxy.getDatabasehash(true); }
3840

3941
@Override
4042
public void storePassphrase(String vault, CharSequence password) throws KeychainAccessException {
4143
vault = URL_SCHEME + vault;
4244
if (isLocked()) {
43-
throw new KeychainAccessException("Storing of the passphrase failed");
45+
throw new KeychainAccessException("Failed to store password. KeePassXC database is locked. Needs to be unlocked first");
4446
}
47+
ensureAssociation();
4548
if (!proxy.loginExists(vault, null, false, List.of(proxy.exportConnection()), password.toString())
4649
&& !proxy.setLogin(vault, null, null, "Vault", password.toString(), "default", "default", "default")) {
47-
throw new KeychainAccessException("Storing of the passphrase failed");
50+
throw new KeychainAccessException("Storing of the password failed");
4851
}
4952
}
5053

5154
@Override
5255
public char[] loadPassphrase(String vault) throws KeychainAccessException {
5356
if (isLocked()) {
54-
throw new KeychainAccessException("Loading of the passphrase failed");
57+
throw new KeychainAccessException("Failed to load password. KeePassXC database is locked. Needs to be unlocked first");
5558
}
59+
ensureAssociation();
5660
vault = URL_SCHEME + vault;
57-
Map<String, Object> answer = proxy.getLogins(vault, null, false, List.of(proxy.exportConnection()));
61+
var answer = proxy.getLogins(vault, null, false, List.of(proxy.exportConnection()));
5862
if (answer.isEmpty() || null == answer.get("entries")) {
59-
throw new KeychainAccessException("Loading of the passphrase failed");
63+
throw new KeychainAccessException("No password found for vault " + vault.substring(URL_SCHEME.length()));
6064
}
61-
List<Object> array = (ArrayList<Object>) answer.get("entries");
62-
Map<String, Object> credentials = (HashMap<String, Object>) array.get(0);
65+
var array = (ArrayList<Object>) answer.get("entries");
66+
var credentials = (HashMap<String, Object>) array.get(0);
6367
if (credentials.get("password") != null) {
64-
String password = (String) credentials.get("password");
68+
var password = (String) credentials.get("password");
6569
return password.toCharArray();
6670
} else {
67-
throw new KeychainAccessException("Loading of the passphrase failed");
71+
throw new KeychainAccessException("Loading of the password failed");
6872
}
6973
}
7074

0 commit comments

Comments
 (0)