Skip to content

Commit 4741b06

Browse files
committed
Use existing methods in integrations-api for association
1 parent 0aea086 commit 4741b06

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ public KeePassXCAccess() {
2828
@Override
2929
public boolean isLocked() { return proxy.getDatabasehash().isEmpty(); }
3030

31-
private boolean needsAssociation() { return !proxy.connectionAvailable(); }
32-
33-
private 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+
}
3438

3539
public String unlock() { return proxy.getDatabasehash(true); }
3640

@@ -40,6 +44,7 @@ public void storePassphrase(String vault, CharSequence password) throws Keychain
4044
if (isLocked()) {
4145
throw new KeychainAccessException("Failed to store password. KeePassXC database is locked. Needs to be unlocked first");
4246
}
47+
ensureAssociation();
4348
if (!proxy.loginExists(vault, null, false, List.of(proxy.exportConnection()), password.toString())
4449
&& !proxy.setLogin(vault, null, null, "Vault", password.toString(), "default", "default", "default")) {
4550
throw new KeychainAccessException("Storing of the password failed");
@@ -51,6 +56,7 @@ public char[] loadPassphrase(String vault) throws KeychainAccessException {
5156
if (isLocked()) {
5257
throw new KeychainAccessException("Failed to load password. KeePassXC database is locked. Needs to be unlocked first");
5358
}
59+
ensureAssociation();
5460
vault = URL_SCHEME + vault;
5561
var answer = proxy.getLogins(vault, null, false, List.of(proxy.exportConnection()));
5662
if (answer.isEmpty() || null == answer.get("entries")) {

0 commit comments

Comments
 (0)