23
23
*/
24
24
public abstract class Connection implements AutoCloseable {
25
25
26
- private static final Logger log = LoggerFactory .getLogger (Connection .class );
26
+ private static final Logger LOG = LoggerFactory .getLogger (Connection .class );
27
27
private final PropertyChangeSupport support ;
28
28
29
29
private TweetNaclFast .Box box ;
@@ -48,10 +48,10 @@ public abstract class Connection implements AutoCloseable {
48
48
private final int RESPONSE_TIMEOUT_S = 5 ;
49
49
50
50
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" ;
55
55
56
56
private static final Set <String > REQUESTS_WITHOUT_MANUAL_USER_INPUT = Set .of (
57
57
"change-public-keys" ,"get-databasehash" ,"test-associate" ,"get-database-groups"
@@ -88,24 +88,24 @@ public void run() {
88
88
while (keepRunning ()) {
89
89
var response = getCleartextResponse ();
90
90
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 );
92
92
queue .offer (response );
93
93
errorCount = 0 ;
94
94
} else {
95
95
errorCount ++;
96
96
if (errorCount > MAX_ERROR_COUNT ) {
97
- log .info ("Too much errors - stopping MessagePublisher" );
97
+ LOG .info ("Too much errors - stopping MessagePublisher" );
98
98
doStop ();
99
99
try {
100
100
terminateConnection ();
101
101
} catch (IOException e ) {
102
- log .error (e .toString (), e .getCause ());
102
+ LOG .error (e .toString (), e .getCause ());
103
103
}
104
104
reconnect ();
105
105
}
106
106
}
107
107
}
108
- log .debug ("MessagePublisher stopped" );
108
+ LOG .debug ("MessagePublisher stopped" );
109
109
}
110
110
}
111
111
@@ -119,7 +119,6 @@ class MessageConsumer implements Callable<JSONObject> {
119
119
*
120
120
* @param action We are searching for a message with a certain action and
121
121
* @param nonce a certain nonce.
122
- * @return The message that was looked up.
123
122
*/
124
123
public MessageConsumer (String action , byte [] nonce ) {
125
124
this .action = action ;
@@ -140,22 +139,22 @@ public JSONObject call() throws Exception {
140
139
}
141
140
if (response .toString ().equals ("{}" )) {
142
141
queue .remove (response );
143
- log .trace ("KeePassXC send an empty response: {}" , response );
142
+ LOG .trace ("KeePassXC send an empty response: {}" , response );
144
143
continue ;
145
144
}
146
145
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 )));
148
147
if (message .has ("error" ) && message .getString ("action" ).equals (action )) {
149
148
queue .remove (message );
150
- log .trace ("Found in and retrieved from queue: {}" , message );
149
+ LOG .trace ("Found in and retrieved from queue: {}" , message );
151
150
return message ;
152
151
}
153
152
if (message .has ("action" )
154
153
&& message .getString ("action" ).equals (action )
155
154
&& message .has ("nonce" )
156
155
&& message .getString ("nonce" ).equals (b64encode (incrementNonce (nonce )))) {
157
156
queue .remove (message );
158
- log .trace ("Retrieved from queue: {}" , message );
157
+ LOG .trace ("Retrieved from queue: {}" , message );
159
158
return message ;
160
159
}
161
160
}
@@ -166,7 +165,7 @@ public JSONObject call() throws Exception {
166
165
167
166
void lauchMessagePublisher () {
168
167
messagePublisher = new MessagePublisher ();
169
- log .debug ("MessagePublisher started" );
168
+ LOG .debug ("MessagePublisher started" );
170
169
executorService .execute (messagePublisher );
171
170
}
172
171
@@ -255,7 +254,7 @@ private synchronized byte[] sendEncryptedMessage(Map<String, Object> msg) throws
255
254
}
256
255
257
256
var strMsg = jsonTxt (msg );
258
- log .trace ("Send - encrypting the following message: {}" , strMsg );
257
+ LOG .trace ("Send - encrypting the following message: {}" , strMsg );
259
258
260
259
box = new TweetNaclFast .Box (publicKey , keyPair .getSecretKey ());
261
260
nonce = ramdomGenerateNonce ();
@@ -300,7 +299,7 @@ private synchronized JSONObject getEncryptedResponseAndDecrypt(String action, by
300
299
} catch (TimeoutException toe ) {
301
300
throw new KeepassProxyAccessException ("Timeout for action '" + action + "'" );
302
301
} catch (InterruptedException | ExecutionException e ) {
303
- log .error (e .toString (), e .getCause ());
302
+ LOG .error (e .toString (), e .getCause ());
304
303
}
305
304
306
305
if (response .has ("error" )) {
@@ -315,7 +314,7 @@ private synchronized JSONObject getEncryptedResponseAndDecrypt(String action, by
315
314
}
316
315
317
316
var decrypted = new String (bMessage , StandardCharsets .UTF_8 );
318
- log .trace ("Decrypted message: {}" , decrypted );
317
+ LOG .trace ("Decrypted message: {}" , decrypted );
319
318
var decryptedResponse = new JSONObject (decrypted );
320
319
321
320
if (!decryptedResponse .has ("success" )) {
@@ -352,7 +351,7 @@ protected void changePublicKeys() throws IOException, KeepassProxyAccessExceptio
352
351
try {
353
352
response = executorService .submit (new MessageConsumer ("change-public-keys" , nonce )).get ();
354
353
} catch (InterruptedException | ExecutionException e ) {
355
- log .error (e .toString (), e .getCause ());
354
+ LOG .error (e .toString (), e .getCause ());
356
355
}
357
356
358
357
if (!response .has ("success" )) {
@@ -400,7 +399,7 @@ public void associate() throws IOException, KeepassProxyAccessException {
400
399
try {
401
400
response = getEncryptedResponseAndDecrypt ("associate" , nonce );
402
401
} catch (KeepassProxyAccessException e ) {
403
- log .error (e .toString (), e .getCause ());
402
+ LOG .error (e .toString (), e .getCause ());
404
403
}
405
404
assert response != null ;
406
405
credentials .orElseThrow (() -> new IllegalStateException (MISSING_CLASS )).setAssociateId (response .getString ("id" ));
0 commit comments