Skip to content

Commit 29ff6a6

Browse files
committed
Disable timeouts for other requests without manual user input
1 parent 2e31f88 commit 29ff6a6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,18 @@ public abstract class Connection implements AutoCloseable {
4545
private final long RESPONSE_DELAY_MS = 500;
4646
private final ScheduledExecutorService scheduler;
4747

48+
private final int RESPONSE_TIMEOUT_S = 5;
49+
4850
protected final String PROXY_NAME = "org.keepassxc.KeePassXC.BrowserServer";
4951
private final String NOT_CONNECTED = "Not connected to KeePassXC. Call connect().";
5052
private final String KEYEXCHANGE_MISSING = "Public keys need to be exchanged. Call changePublicKeys().";
5153
private final String MISSING_CLASS = "Credentials have not been initialized";
5254
public final String EXCEPTION_INFO = "Delaying association dialog response lookup due to https://github.com/keepassxreboot/keepassxc/issues/7099";
5355

56+
private static final Set<String> REQUESTS_WITHOUT_MANUAL_USER_INPUT = Set.of(
57+
"change-public-keys","get-databasehash","test-associate","get-database-groups"
58+
);
59+
5460
public Connection() {
5561
byte[] array = new byte[nonceLength];
5662
new Random().nextBytes(array);
@@ -267,11 +273,12 @@ private synchronized JSONObject getEncryptedResponseAndDecrypt(String action, by
267273
var response = new JSONObject();
268274

269275
try {
270-
// associate requires user input, other requests don't
271-
if (action.equals("associate")) {
272-
response = executorService.submit(new MessageConsumer(action, nonce)).get();
276+
// requests that don't require user input need to receive an answer within
277+
// the specified timeout
278+
if (REQUESTS_WITHOUT_MANUAL_USER_INPUT.contains(action)) {
279+
response = executorService.submit(new MessageConsumer(action, nonce)).get(RESPONSE_TIMEOUT_S, TimeUnit.SECONDS);
273280
} else {
274-
response = executorService.submit(new MessageConsumer(action, nonce)).get(5, TimeUnit.SECONDS);
281+
response = executorService.submit(new MessageConsumer(action, nonce)).get();
275282
}
276283
} catch (TimeoutException toe) {
277284
throw new KeepassProxyAccessException("Timeout for action '" + action + "'");

0 commit comments

Comments
 (0)