@@ -81,29 +81,29 @@ public void removePropertyChangeListener(PropertyChangeListener pcl) {
8181 * @throws IOException Sending failed due to technical reasons.
8282 */
8383 private void sendEncryptedMessage (Map <String , Object > msg ) throws IOException {
84- boolean unlockRequested = false ;
84+ var unlockRequested = false ;
8585
8686 if (!isConnected ()) {
8787 throw new IllegalStateException (NOT_CONNECTED );
8888 }
8989
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 ();
9292
9393 if (msg .containsKey ("triggerUnlock" ) && msg .get ("triggerUnlock" ).equals ("true" )) {
9494 msg .remove ("triggerUnlock" );
9595 unlockRequested = true ;
9696 }
9797
98- String strMsg = jsonTxt (msg );
98+ var strMsg = jsonTxt (msg );
9999 log .trace ("Send - encrypting the following message: {}" , strMsg );
100100
101101 box = new TweetNaclFast .Box (publicKey , keyPair .getSecretKey ());
102102
103- String encrypted = b64encode (box .box (strMsg .getBytes (), nonce ));
103+ var encrypted = b64encode (box .box (strMsg .getBytes (), nonce ));
104104
105105 // 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 >();
107107 message .put ("action" , msg .get ("action" ).toString ());
108108 message .put ("message" , encrypted );
109109 message .put ("nonce" , b64encode (nonce ));
@@ -128,7 +128,7 @@ private void sendEncryptedMessage(Map<String, Object> msg) throws IOException {
128128 * @throws KeepassProxyAccessException It was impossible to process the requested action.
129129 */
130130 private JSONObject getEncryptedResponseAndDecrypt (String action ) throws IOException , KeepassProxyAccessException {
131- JSONObject response = getCleartextResponse ();
131+ var response = getCleartextResponse ();
132132
133133 // Handle signals
134134 while (!response .has ("error" ) && isSignal (response )) {
@@ -148,16 +148,16 @@ private JSONObject getEncryptedResponseAndDecrypt(String action) throws IOExcept
148148 throw new KeepassProxyAccessException ("ErrorCode: " + response .getString ("errorCode" ) + ", " + response .getString ("error" ));
149149 }
150150
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 );
153153
154154 if (bMessage == null ) {
155155 throw new KeepassProxyAccessException ("Error: message could not be decrypted" );
156156 }
157157
158- String decrypted = new String (bMessage , StandardCharsets .UTF_8 );
158+ var decrypted = new String (bMessage , StandardCharsets .UTF_8 );
159159 log .trace ("Decrypted message: {}" , decrypted );
160- JSONObject decryptedResponse = new JSONObject (decrypted );
160+ var decryptedResponse = new JSONObject (decrypted );
161161
162162 if (!decryptedResponse .has ("success" )) {
163163 throw new KeepassProxyAccessException ("ErrorCode: " + response .getString ("errorCode" ) + ", " + response .getString ("error" ));
@@ -186,7 +186,7 @@ protected void changePublicKeys() throws IOException, KeepassProxyAccessExceptio
186186 throw new IllegalStateException (NOT_CONNECTED );
187187 }
188188
189- TweetNaclFast . Box . KeyPair keyPair = TweetNaclFast .Box .keyPair ();
189+ var keyPair = TweetNaclFast .Box .keyPair ();
190190
191191 // Send change-public-keys request
192192 sendCleartextMessage (jsonTxt (Map .of (
@@ -195,13 +195,13 @@ protected void changePublicKeys() throws IOException, KeepassProxyAccessExceptio
195195 "nonce" , b64encode (nonce ),
196196 "clientID" , clientID
197197 )));
198- JSONObject response = getCleartextResponse ();
198+ var response = getCleartextResponse ();
199199
200200 if (!response .has ("success" )) {
201201 throw new KeepassProxyAccessException ("ErrorCode: " + response .getString ("errorCode" ) + ", " + response .getString ("error" ));
202202 }
203203
204- byte [] publicKey = b64decode (response .getString ("publicKey" ).getBytes ());
204+ var publicKey = b64decode (response .getString ("publicKey" ).getBytes ());
205205 box = new TweetNaclFast .Box (publicKey , keyPair .getSecretKey ());
206206
207207 if (credentials .isEmpty ()) {
@@ -223,16 +223,16 @@ protected void changePublicKeys() throws IOException, KeepassProxyAccessExceptio
223223 * @throws KeepassProxyAccessException It was impossible to associate KeePassXC with a new client.
224224 */
225225 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 ();
228228
229229 // Send associate request
230230 sendEncryptedMessage (Map .of (
231231 "action" , "associate" ,
232232 "key" , b64encode (keyPair .getPublicKey ()),
233233 "idKey" , b64encode (idKeyPair .getPublicKey ())
234234 ));
235- JSONObject response = getEncryptedResponseAndDecrypt ("associate" );
235+ var response = getEncryptedResponseAndDecrypt ("associate" );
236236
237237 credentials .orElseThrow (() -> new IllegalStateException (MISSING_CLASS )).setAssociateId (response .getString ("id" ));
238238 credentials .orElseThrow (() -> new IllegalStateException (MISSING_CLASS )).setIdKeyPublicKey (idKeyPair .getPublicKey ());
@@ -249,7 +249,7 @@ public void associate() throws IOException, KeepassProxyAccessException {
249249 public String getDatabasehash () throws IOException , KeepassProxyAccessException {
250250 // Send get-databasehash request
251251 sendEncryptedMessage (Map .of ("action" , "get-databasehash" ));
252- JSONObject response = getEncryptedResponseAndDecrypt ("get-databasehash" );
252+ var response = getEncryptedResponseAndDecrypt ("get-databasehash" );
253253
254254 return response .getString ("hash" );
255255 }
@@ -265,11 +265,11 @@ public String getDatabasehash() throws IOException, KeepassProxyAccessException
265265 */
266266 public String getDatabasehash (boolean triggerUnlock ) throws IOException , KeepassProxyAccessException {
267267 // 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
269269 map .put ("action" , "get-databasehash" );
270270 map .put ("triggerUnlock" , Boolean .toString (triggerUnlock ));
271271 sendEncryptedMessage (map );
272- JSONObject response = getEncryptedResponseAndDecrypt ("get-databasehash" );
272+ var response = getEncryptedResponseAndDecrypt ("get-databasehash" );
273273
274274 return response .getString ("hash" );
275275 }
@@ -306,10 +306,10 @@ public void testAssociate(String id, String key) throws IOException, KeepassProx
306306 * @throws KeepassProxyAccessException No credentials found for the given URL.
307307 */
308308 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 ();
310310 // Syntax check for list
311311 for (Map <String , String > m : list ) {
312- JSONObject o = new JSONObject (m );
312+ var o = new JSONObject (m );
313313 if (!(o .has ("id" ) && o .has ("key" ) && o .length () == 2 )) {
314314 throw new KeepassProxyAccessException ("JSON object key is malformed" );
315315 }
@@ -464,8 +464,8 @@ private String jsonTxt(Map<String, Object> keysValues) {
464464 * Increment nonce by 1
465465 */
466466 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 );
469469 nonce = dbuf .array ();
470470 }
471471
0 commit comments