Skip to content

Commit 80e9610

Browse files
committed
1 parent fd45bc5 commit 80e9610

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/main/java/org/keepassxc/Connection.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.beans.PropertyChangeListener;
1313
import java.beans.PropertyChangeSupport;
1414
import java.io.IOException;
15-
import java.nio.ByteBuffer;
1615
import java.nio.charset.StandardCharsets;
1716
import java.util.*;
1817
import java.util.concurrent.*;
@@ -36,6 +35,9 @@ public abstract class Connection implements AutoCloseable {
3635
final MessagePublisher messagePublisher = new MessagePublisher();
3736
private final ConcurrentLinkedQueue<JSONObject> queue = new ConcurrentLinkedQueue<>();
3837

38+
private final long RESPONSE_DELAY_MS = 500;
39+
private final ScheduledExecutorService scheduler;
40+
3941
protected final String PROXY_NAME = "org.keepassxc.KeePassXC.BrowserServer";
4042
private final String NOT_CONNECTED = "Not connected to KeePassXC. Call connect().";
4143
private final String KEYEXCHANGE_MISSING = "Public keys need to be exchanged. Call changePublicKeys().";
@@ -48,6 +50,7 @@ public Connection() {
4850
nonce = TweetNaclFast.randombytes(nonceLength);
4951
credentials = Optional.empty();
5052
support = new PropertyChangeSupport(this);
53+
scheduler = Executors.newSingleThreadScheduledExecutor();
5154
}
5255

5356
class MessagePublisher implements Runnable {
@@ -296,11 +299,27 @@ public void associate() throws IOException, KeepassProxyAccessException {
296299
"key", b64encode(keyPair.getPublicKey()),
297300
"idKey", b64encode(idKeyPair.getPublicKey())
298301
));
299-
var response = getEncryptedResponseAndDecrypt("associate");
300302

301-
credentials.orElseThrow(() -> new IllegalStateException(MISSING_CLASS)).setAssociateId(response.getString("id"));
302-
credentials.orElseThrow(() -> new IllegalStateException(MISSING_CLASS)).setIdKeyPublicKey(idKeyPair.getPublicKey());
303-
support.firePropertyChange("associated", null, credentials);
303+
// TODO:
304+
// Revert after Qt bug is fixed:
305+
// getEncryptedResponseAndDecrypt needs to be run delayed and more important:
306+
// a KeepassProxyAccessException needs to be thrown to interrupt the current program flow
307+
// otherwise bringing up the association dialog blocks due to a Qt bug,
308+
// see https://github.com/keepassxreboot/keepassxc/issues/7099
309+
Runnable lookupResponse = () -> {
310+
JSONObject response = null;
311+
try {
312+
response = getEncryptedResponseAndDecrypt("associate");
313+
} catch (KeepassProxyAccessException e) {
314+
log.error(e.toString(), e.getCause());
315+
}
316+
assert response != null;
317+
credentials.orElseThrow(() -> new IllegalStateException(MISSING_CLASS)).setAssociateId(response.getString("id"));
318+
credentials.orElseThrow(() -> new IllegalStateException(MISSING_CLASS)).setIdKeyPublicKey(idKeyPair.getPublicKey());
319+
support.firePropertyChange("associated", null, credentials);
320+
};
321+
scheduler.schedule(lookupResponse, RESPONSE_DELAY_MS, TimeUnit.MILLISECONDS);
322+
throw new KeepassProxyAccessException("Delaying association dialog response lookup due to https://github.com/keepassxreboot/keepassxc/issues/7099");
304323
}
305324

306325
/**

0 commit comments

Comments
 (0)