@@ -81,29 +81,29 @@ public void removePropertyChangeListener(PropertyChangeListener pcl) {
81
81
* @throws IOException Sending failed due to technical reasons.
82
82
*/
83
83
private void sendEncryptedMessage (Map <String , Object > msg ) throws IOException {
84
- boolean unlockRequested = false ;
84
+ var unlockRequested = false ;
85
85
86
86
if (!isConnected ()) {
87
87
throw new IllegalStateException (NOT_CONNECTED );
88
88
}
89
89
90
- byte [] publicKey = credentials .orElseThrow (() -> new IllegalStateException (KEYEXCHANGE_MISSING )).getServerPublicKey ();
91
- TweetNaclFast . Box . KeyPair keyPair = credentials .orElseThrow (() -> new IllegalStateException (KEYEXCHANGE_MISSING )).getOwnKeypair ();
90
+ var publicKey = credentials .orElseThrow (() -> new IllegalStateException (KEYEXCHANGE_MISSING )).getServerPublicKey ();
91
+ var keyPair = credentials .orElseThrow (() -> new IllegalStateException (KEYEXCHANGE_MISSING )).getOwnKeypair ();
92
92
93
93
if (msg .containsKey ("triggerUnlock" ) && msg .get ("triggerUnlock" ).equals ("true" )) {
94
94
msg .remove ("triggerUnlock" );
95
95
unlockRequested = true ;
96
96
}
97
97
98
- String strMsg = jsonTxt (msg );
98
+ var strMsg = jsonTxt (msg );
99
99
log .trace ("Send - encrypting the following message: {}" , strMsg );
100
100
101
101
box = new TweetNaclFast .Box (publicKey , keyPair .getSecretKey ());
102
102
103
- String encrypted = b64encode (box .box (strMsg .getBytes (), nonce ));
103
+ var encrypted = b64encode (box .box (strMsg .getBytes (), nonce ));
104
104
105
105
// Map.of can't be used here, because we need a mutable object
106
- Map < String , Object > message = new HashMap <>();
106
+ var message = new HashMap <String , Object >();
107
107
message .put ("action" , msg .get ("action" ).toString ());
108
108
message .put ("message" , encrypted );
109
109
message .put ("nonce" , b64encode (nonce ));
@@ -128,7 +128,7 @@ private void sendEncryptedMessage(Map<String, Object> msg) throws IOException {
128
128
* @throws KeepassProxyAccessException It was impossible to process the requested action.
129
129
*/
130
130
private JSONObject getEncryptedResponseAndDecrypt (String action ) throws IOException , KeepassProxyAccessException {
131
- JSONObject response = getCleartextResponse ();
131
+ var response = getCleartextResponse ();
132
132
133
133
// Handle signals
134
134
while (!response .has ("error" ) && isSignal (response )) {
@@ -148,16 +148,16 @@ private JSONObject getEncryptedResponseAndDecrypt(String action) throws IOExcept
148
148
throw new KeepassProxyAccessException ("ErrorCode: " + response .getString ("errorCode" ) + ", " + response .getString ("error" ));
149
149
}
150
150
151
- byte [] serverNonce = b64decode (response .getString ("nonce" ).getBytes ());
152
- byte [] bMessage = box .open (b64decode (response .getString ("message" ).getBytes ()), serverNonce );
151
+ var serverNonce = b64decode (response .getString ("nonce" ).getBytes ());
152
+ var bMessage = box .open (b64decode (response .getString ("message" ).getBytes ()), serverNonce );
153
153
154
154
if (bMessage == null ) {
155
155
throw new KeepassProxyAccessException ("Error: message could not be decrypted" );
156
156
}
157
157
158
- String decrypted = new String (bMessage , StandardCharsets .UTF_8 );
158
+ var decrypted = new String (bMessage , StandardCharsets .UTF_8 );
159
159
log .trace ("Decrypted message: {}" , decrypted );
160
- JSONObject decryptedResponse = new JSONObject (decrypted );
160
+ var decryptedResponse = new JSONObject (decrypted );
161
161
162
162
if (!decryptedResponse .has ("success" )) {
163
163
throw new KeepassProxyAccessException ("ErrorCode: " + response .getString ("errorCode" ) + ", " + response .getString ("error" ));
@@ -186,7 +186,7 @@ protected void changePublicKeys() throws IOException, KeepassProxyAccessExceptio
186
186
throw new IllegalStateException (NOT_CONNECTED );
187
187
}
188
188
189
- TweetNaclFast . Box . KeyPair keyPair = TweetNaclFast .Box .keyPair ();
189
+ var keyPair = TweetNaclFast .Box .keyPair ();
190
190
191
191
// Send change-public-keys request
192
192
sendCleartextMessage (jsonTxt (Map .of (
@@ -195,13 +195,13 @@ protected void changePublicKeys() throws IOException, KeepassProxyAccessExceptio
195
195
"nonce" , b64encode (nonce ),
196
196
"clientID" , clientID
197
197
)));
198
- JSONObject response = getCleartextResponse ();
198
+ var response = getCleartextResponse ();
199
199
200
200
if (!response .has ("success" )) {
201
201
throw new KeepassProxyAccessException ("ErrorCode: " + response .getString ("errorCode" ) + ", " + response .getString ("error" ));
202
202
}
203
203
204
- byte [] publicKey = b64decode (response .getString ("publicKey" ).getBytes ());
204
+ var publicKey = b64decode (response .getString ("publicKey" ).getBytes ());
205
205
box = new TweetNaclFast .Box (publicKey , keyPair .getSecretKey ());
206
206
207
207
if (credentials .isEmpty ()) {
@@ -223,16 +223,16 @@ protected void changePublicKeys() throws IOException, KeepassProxyAccessExceptio
223
223
* @throws KeepassProxyAccessException It was impossible to associate KeePassXC with a new client.
224
224
*/
225
225
public void associate () throws IOException , KeepassProxyAccessException {
226
- TweetNaclFast . Box . KeyPair idKeyPair = TweetNaclFast .Box .keyPair ();
227
- TweetNaclFast . Box . KeyPair keyPair = credentials .orElseThrow (() -> new IllegalStateException (KEYEXCHANGE_MISSING )).getOwnKeypair ();
226
+ var idKeyPair = TweetNaclFast .Box .keyPair ();
227
+ var keyPair = credentials .orElseThrow (() -> new IllegalStateException (KEYEXCHANGE_MISSING )).getOwnKeypair ();
228
228
229
229
// Send associate request
230
230
sendEncryptedMessage (Map .of (
231
231
"action" , "associate" ,
232
232
"key" , b64encode (keyPair .getPublicKey ()),
233
233
"idKey" , b64encode (idKeyPair .getPublicKey ())
234
234
));
235
- JSONObject response = getEncryptedResponseAndDecrypt ("associate" );
235
+ var response = getEncryptedResponseAndDecrypt ("associate" );
236
236
237
237
credentials .orElseThrow (() -> new IllegalStateException (MISSING_CLASS )).setAssociateId (response .getString ("id" ));
238
238
credentials .orElseThrow (() -> new IllegalStateException (MISSING_CLASS )).setIdKeyPublicKey (idKeyPair .getPublicKey ());
@@ -249,7 +249,7 @@ public void associate() throws IOException, KeepassProxyAccessException {
249
249
public String getDatabasehash () throws IOException , KeepassProxyAccessException {
250
250
// Send get-databasehash request
251
251
sendEncryptedMessage (Map .of ("action" , "get-databasehash" ));
252
- JSONObject response = getEncryptedResponseAndDecrypt ("get-databasehash" );
252
+ var response = getEncryptedResponseAndDecrypt ("get-databasehash" );
253
253
254
254
return response .getString ("hash" );
255
255
}
@@ -265,11 +265,11 @@ public String getDatabasehash() throws IOException, KeepassProxyAccessException
265
265
*/
266
266
public String getDatabasehash (boolean triggerUnlock ) throws IOException , KeepassProxyAccessException {
267
267
// Send get-databasehash request with triggerUnlock, if needed
268
- Map < String , Object > map = new HashMap <>(); // Map.of can't be used here, because we need a mutable object
268
+ var map = new HashMap <String , Object >(); // Map.of can't be used here, because we need a mutable object
269
269
map .put ("action" , "get-databasehash" );
270
270
map .put ("triggerUnlock" , Boolean .toString (triggerUnlock ));
271
271
sendEncryptedMessage (map );
272
- JSONObject response = getEncryptedResponseAndDecrypt ("get-databasehash" );
272
+ var response = getEncryptedResponseAndDecrypt ("get-databasehash" );
273
273
274
274
return response .getString ("hash" );
275
275
}
@@ -306,10 +306,10 @@ public void testAssociate(String id, String key) throws IOException, KeepassProx
306
306
* @throws KeepassProxyAccessException No credentials found for the given URL.
307
307
*/
308
308
public JSONObject getLogins (String url , String submitUrl , boolean httpAuth , List <Map <String , String >> list ) throws IOException , KeepassProxyAccessException {
309
- JSONArray array = new JSONArray ();
309
+ var array = new JSONArray ();
310
310
// Syntax check for list
311
311
for (Map <String , String > m : list ) {
312
- JSONObject o = new JSONObject (m );
312
+ var o = new JSONObject (m );
313
313
if (!(o .has ("id" ) && o .has ("key" ) && o .length () == 2 )) {
314
314
throw new KeepassProxyAccessException ("JSON object key is malformed" );
315
315
}
@@ -464,8 +464,8 @@ private String jsonTxt(Map<String, Object> keysValues) {
464
464
* Increment nonce by 1
465
465
*/
466
466
private void incrementNonce () {
467
- int newNonce = ByteBuffer .wrap (nonce ).getInt () + 1 ;
468
- ByteBuffer dbuf = ByteBuffer .allocate (24 ).putInt (newNonce );
467
+ var newNonce = ByteBuffer .wrap (nonce ).getInt () + 1 ;
468
+ var dbuf = ByteBuffer .allocate (24 ).putInt (newNonce );
469
469
nonce = dbuf .array ();
470
470
}
471
471
0 commit comments