2323 */
2424public abstract class Connection implements AutoCloseable {
2525
26- private static final Logger log = LoggerFactory .getLogger (Connection .class );
26+ private static final Logger LOG = LoggerFactory .getLogger (Connection .class );
2727 private final PropertyChangeSupport support ;
2828
2929 private TweetNaclFast .Box box ;
@@ -48,10 +48,10 @@ public abstract class Connection implements AutoCloseable {
4848 private final int RESPONSE_TIMEOUT_S = 5 ;
4949
5050 protected final String PROXY_NAME = "org.keepassxc.KeePassXC.BrowserServer" ;
51- private final String NOT_CONNECTED = "Not connected to KeePassXC. Call connect()." ;
52- private final String KEYEXCHANGE_MISSING = "Public keys need to be exchanged. Call changePublicKeys()." ;
53- private final String MISSING_CLASS = "Credentials have not been initialized" ;
54- public final String EXCEPTION_INFO = "Delaying association dialog response lookup due to https://github.com/keepassxreboot/keepassxc/issues/7099" ;
51+ private static final String NOT_CONNECTED = "Not connected to KeePassXC. Call connect()." ;
52+ private static final String KEYEXCHANGE_MISSING = "Public keys need to be exchanged. Call changePublicKeys()." ;
53+ private static final String MISSING_CLASS = "Credentials have not been initialized" ;
54+ public static final String EXCEPTION_INFO = "Delaying association dialog response lookup due to https://github.com/keepassxreboot/keepassxc/issues/7099" ;
5555
5656 private static final Set <String > REQUESTS_WITHOUT_MANUAL_USER_INPUT = Set .of (
5757 "change-public-keys" ,"get-databasehash" ,"test-associate" ,"get-database-groups"
@@ -88,24 +88,24 @@ public void run() {
8888 while (keepRunning ()) {
8989 var response = getCleartextResponse ();
9090 if (!response .isEmpty ()) {
91- if (!isSignal (response )) log .trace ("Response added to queue: {}" , response );
91+ if (!isSignal (response )) LOG .trace ("Response added to queue: {}" , response );
9292 queue .offer (response );
9393 errorCount = 0 ;
9494 } else {
9595 errorCount ++;
9696 if (errorCount > MAX_ERROR_COUNT ) {
97- log .info ("Too much errors - stopping MessagePublisher" );
97+ LOG .info ("Too much errors - stopping MessagePublisher" );
9898 doStop ();
9999 try {
100100 terminateConnection ();
101101 } catch (IOException e ) {
102- log .error (e .toString (), e .getCause ());
102+ LOG .error (e .toString (), e .getCause ());
103103 }
104104 reconnect ();
105105 }
106106 }
107107 }
108- log .debug ("MessagePublisher stopped" );
108+ LOG .debug ("MessagePublisher stopped" );
109109 }
110110 }
111111
@@ -119,7 +119,6 @@ class MessageConsumer implements Callable<JSONObject> {
119119 *
120120 * @param action We are searching for a message with a certain action and
121121 * @param nonce a certain nonce.
122- * @return The message that was looked up.
123122 */
124123 public MessageConsumer (String action , byte [] nonce ) {
125124 this .action = action ;
@@ -140,22 +139,22 @@ public JSONObject call() throws Exception {
140139 }
141140 if (response .toString ().equals ("{}" )) {
142141 queue .remove (response );
143- log .trace ("KeePassXC send an empty response: {}" , response );
142+ LOG .trace ("KeePassXC send an empty response: {}" , response );
144143 continue ;
145144 }
146145 for (JSONObject message : queue ) {
147- log .trace ("Checking in queue message {}, looking for action '{}' and nonce {}" , message , action , b64encode (incrementNonce (nonce )));
146+ LOG .trace ("Checking in queue message {}, looking for action '{}' and nonce {}" , message , action , b64encode (incrementNonce (nonce )));
148147 if (message .has ("error" ) && message .getString ("action" ).equals (action )) {
149148 queue .remove (message );
150- log .trace ("Found in and retrieved from queue: {}" , message );
149+ LOG .trace ("Found in and retrieved from queue: {}" , message );
151150 return message ;
152151 }
153152 if (message .has ("action" )
154153 && message .getString ("action" ).equals (action )
155154 && message .has ("nonce" )
156155 && message .getString ("nonce" ).equals (b64encode (incrementNonce (nonce )))) {
157156 queue .remove (message );
158- log .trace ("Retrieved from queue: {}" , message );
157+ LOG .trace ("Retrieved from queue: {}" , message );
159158 return message ;
160159 }
161160 }
@@ -166,7 +165,7 @@ public JSONObject call() throws Exception {
166165
167166 void lauchMessagePublisher () {
168167 messagePublisher = new MessagePublisher ();
169- log .debug ("MessagePublisher started" );
168+ LOG .debug ("MessagePublisher started" );
170169 executorService .execute (messagePublisher );
171170 }
172171
@@ -255,7 +254,7 @@ private synchronized byte[] sendEncryptedMessage(Map<String, Object> msg) throws
255254 }
256255
257256 var strMsg = jsonTxt (msg );
258- log .trace ("Send - encrypting the following message: {}" , strMsg );
257+ LOG .trace ("Send - encrypting the following message: {}" , strMsg );
259258
260259 box = new TweetNaclFast .Box (publicKey , keyPair .getSecretKey ());
261260 nonce = ramdomGenerateNonce ();
@@ -300,7 +299,7 @@ private synchronized JSONObject getEncryptedResponseAndDecrypt(String action, by
300299 } catch (TimeoutException toe ) {
301300 throw new KeepassProxyAccessException ("Timeout for action '" + action + "'" );
302301 } catch (InterruptedException | ExecutionException e ) {
303- log .error (e .toString (), e .getCause ());
302+ LOG .error (e .toString (), e .getCause ());
304303 }
305304
306305 if (response .has ("error" )) {
@@ -315,7 +314,7 @@ private synchronized JSONObject getEncryptedResponseAndDecrypt(String action, by
315314 }
316315
317316 var decrypted = new String (bMessage , StandardCharsets .UTF_8 );
318- log .trace ("Decrypted message: {}" , decrypted );
317+ LOG .trace ("Decrypted message: {}" , decrypted );
319318 var decryptedResponse = new JSONObject (decrypted );
320319
321320 if (!decryptedResponse .has ("success" )) {
@@ -352,7 +351,7 @@ protected void changePublicKeys() throws IOException, KeepassProxyAccessExceptio
352351 try {
353352 response = executorService .submit (new MessageConsumer ("change-public-keys" , nonce )).get ();
354353 } catch (InterruptedException | ExecutionException e ) {
355- log .error (e .toString (), e .getCause ());
354+ LOG .error (e .toString (), e .getCause ());
356355 }
357356
358357 if (!response .has ("success" )) {
@@ -400,7 +399,7 @@ public void associate() throws IOException, KeepassProxyAccessException {
400399 try {
401400 response = getEncryptedResponseAndDecrypt ("associate" , nonce );
402401 } catch (KeepassProxyAccessException e ) {
403- log .error (e .toString (), e .getCause ());
402+ LOG .error (e .toString (), e .getCause ());
404403 }
405404 assert response != null ;
406405 credentials .orElseThrow (() -> new IllegalStateException (MISSING_CLASS )).setAssociateId (response .getString ("id" ));
0 commit comments