@@ -60,8 +60,10 @@ public KeepassProxyAccess() {
60
60
}
61
61
62
62
/**
63
- * Loads the @see org.purejava.Credentials from disc, if available, to setup this library
63
+ * Loads the {@link org.purejava.Credentials Credentials} from disc, if available, to setup this library
64
64
* so that it can be used to send requests to and receive requests from a KeePassXC database.
65
+ * @see org.purejava.Credentials
66
+ *
65
67
* @return An Optional of the Credentials read from disc in case they are available, an empty Optional otherwise.
66
68
*/
67
69
private Optional <Credentials > loadCredentials () {
@@ -77,8 +79,10 @@ private Optional<Credentials> loadCredentials() {
77
79
78
80
79
81
/**
80
- * Saves @see org.purejava.Credentials in a delayed background thread to disc, as this is a time consuming
82
+ * Saves {@link org.purejava.Credentials Credentials} in a delayed background thread to disc, as this is a time consuming
81
83
* operation that might fail.
84
+ * @see org.purejava.Credentials
85
+ *
82
86
* @param credentials An Optional of the Credentials to be saved.
83
87
*/
84
88
private void scheduleSave (Optional <Credentials > credentials ) {
@@ -95,7 +99,9 @@ private void scheduleSave(Optional<Credentials> credentials) {
95
99
}
96
100
97
101
/**
98
- * Saves @see org.purejava.Credentials to disc.
102
+ * Saves {@link org.purejava.Credentials Credentials} to disc.
103
+ * @see org.purejava.Credentials
104
+ *
99
105
* @param credentials An Optional of the Credentials to be saved.
100
106
*/
101
107
private void saveCredentials (Optional <Credentials > credentials ) {
@@ -118,15 +124,24 @@ private void saveCredentials(Optional<Credentials> credentials) {
118
124
}
119
125
120
126
/**
121
- * Convenience method to get the connection parameters that are required to identify the right KeePassXC database.
127
+ * Convenience method to get the connection parameters that are required to identify the KeePassXC database.
122
128
*
123
- * @return The entered associateID and returned IDKeyPublicKey.
129
+ * @return The entered associateID and returned IDKeyPublicKey stored on association .
124
130
*/
125
131
public Map <String , String > exportConnection () {
126
132
return Map .of ("id" , connection .getAssociateId (),
127
133
"key" , connection .getIdKeyPairPublicKey ());
128
134
}
129
135
136
+ /**
137
+ * Establish a connection to the KeePassXC proxy. This is required for every session.
138
+ * The closing of the connection is handled automatically.
139
+ * @see org.keepassxc.LinuxMacConnection
140
+ * @see org.keepassxc.WindowsConnection
141
+ *
142
+ * @return True, if connecting to the proxy was successful, false, if connecting failed due to technical reasons
143
+ * or the proxy wasn't started.
144
+ */
130
145
public boolean connect () {
131
146
try {
132
147
connection .connect ();
@@ -136,6 +151,12 @@ public boolean connect() {
136
151
}
137
152
}
138
153
154
+ /**
155
+ * Connects KeePassXC with a new client. This is required once, on connecting a new client to KeePassXC and
156
+ * creates the public idKey and the public associateId.
157
+ *
158
+ * @return True, if it was possible to associate KeePassXC with a new client, false otherwise.
159
+ */
139
160
public boolean associate () {
140
161
try {
141
162
connection .associate ();
@@ -146,6 +167,15 @@ public boolean associate() {
146
167
}
147
168
}
148
169
170
+ /**
171
+ * Checks, if this client has been associated with KeePassXC and if the association is still valid. To establish
172
+ * a connection to KeePassXC, the public idKey and the public associateId are required. With these parameters,
173
+ * {@link org.purejava.KeepassProxyAccess#testAssociate(String, String) testAssociate} is called to verify the
174
+ * association. A valid association enables the client to send requests to and receive requests from KeePassXC.
175
+ * @see org.purejava.KeepassProxyAccess#testAssociate(String, String)
176
+ *
177
+ * @return True, if a valid association with KeePassXC exists, false otherwise.
178
+ */
149
179
public boolean connectionAvailable () {
150
180
return getIdKeyPairPublicKey () != null &&
151
181
!getIdKeyPairPublicKey ().isEmpty () &&
@@ -154,6 +184,14 @@ public boolean connectionAvailable() {
154
184
testAssociate (getAssociateId (), getIdKeyPairPublicKey ());
155
185
}
156
186
187
+ /**
188
+ * Request for testing if the public idKey and the public associateId are valid and enable this client
189
+ * to talk to KeePassXC. With valid IDs, the client is considered associated with KeePassXC.
190
+ *
191
+ * @param id The identifier of the KeePassXC database connection to be tested.
192
+ * @param key The public key of the idKeyPair to be tested.
193
+ * @return True, if the id and the key are valid, false otherwise.
194
+ */
157
195
public boolean testAssociate (String id , String key ) {
158
196
try {
159
197
connection .testAssociate (id , key );
@@ -164,6 +202,14 @@ public boolean testAssociate(String id, String key) {
164
202
}
165
203
}
166
204
205
+ /**
206
+ * Request for receiving the database hash (SHA256) of the current active KeePassXC database.
207
+ * The request can be send in conjunction with an optional request to unlock the KeePassXC database.
208
+ *
209
+ * @param unlock When true, the KeePassXC application is brought to the front and unlock is requested from the user.
210
+ * @return The database hash of the current active KeePassXC database in case the hash could be retrieved,
211
+ * an empty String otherwise.
212
+ */
167
213
public String getDatabasehash (boolean ... unlock ) {
168
214
try {
169
215
if (unlock .length > 1 ) {
@@ -180,6 +226,16 @@ public String getDatabasehash(boolean... unlock) {
180
226
}
181
227
}
182
228
229
+ /**
230
+ * Request credentials from KeePassXC databases for a given URL.
231
+ *
232
+ * @param url The URL credentials are looked up for.
233
+ * @param submitUrl URL that can be passed along amd gets added to entry properties.
234
+ * @param httpAuth Include database entries into search that are restricted to HTTP Basic Auth.
235
+ * @param list Id / key combinations identifying and granting access to KeePassXC databases.
236
+ * @return A Map that contains all found credentials together with additional information, in case credentials
237
+ * were found, an empty Map otherwise.
238
+ */
183
239
public Map <String , Object > getLogins (String url , String submitUrl , boolean httpAuth , List <Map <String , String >> list ) {
184
240
try {
185
241
return connection .getLogins (url , submitUrl , httpAuth , list ).toMap ();
@@ -189,6 +245,19 @@ public Map<String, Object> getLogins(String url, String submitUrl, boolean httpA
189
245
}
190
246
}
191
247
248
+ /**
249
+ * Checks, if a password is stored in the KeePassXC databases. This method calls
250
+ * {@link org.purejava.KeepassProxyAccess#getLogins(String, String, boolean, List) getLogins} to search
251
+ * the KeePassXC databases.
252
+ * @see org.purejava.KeepassProxyAccess#getLogins(String, String, boolean, List)
253
+ *
254
+ * @param url The URL credentials are looked up for.
255
+ * @param submitUrl URL that can be passed along amd gets added to entry properties.
256
+ * @param httpAuth Include database entries into search that are restricted to HTTP Basic Auth.
257
+ * @param list Id / key combinations identifying and granting access to KeePassXC databases.
258
+ * @param password Password to check.
259
+ * @return True, if the password was found in a KeePassXC database, false otherwise.
260
+ */
192
261
public boolean loginExists (String url , String submitUrl , boolean httpAuth , List <Map <String , String >> list , String password ) {
193
262
var response = getLogins (url , submitUrl , httpAuth , list );
194
263
if (response .isEmpty ()) {
@@ -202,6 +271,23 @@ public boolean loginExists(String url, String submitUrl, boolean httpAuth, List<
202
271
return false ;
203
272
}
204
273
274
+ /**
275
+ * Request to store a new entry or update an existing entry in the current KeePassXC database.
276
+ *
277
+ * @param url The URL to be saved. The title of the new entry is the hostname of the URL.
278
+ * @param submitUrl URL that can be passed along amd gets added to entry properties.
279
+ * @param id An identifier for the KeePassXC database connection - ignored at the moment.
280
+ * @param login The username to be saved.
281
+ * @param password The password to be saved.
282
+ * @param group The group name to be used for new entries. Must contain something to use an existing group, but
283
+ * the content is ignored, as a group is identified by the groupUuid. In case there is no group with
284
+ * the given groupUuid, the standard group is used to store the entry.
285
+ * @param groupUuid Identifier to decide, where to store the entry. For an existing group, the groupUuid must be
286
+ * given, otherwise the standard group is used to store the entry.
287
+ * @param uuid Identifier whether an existing entry is updated or a new one is created. To update an existing entry,
288
+ * its current uuid is required. If empty, a new entry is stored in the given groupUuid.
289
+ * @return True, if the entry could be stored/updated, false otherwise.
290
+ */
205
291
public boolean setLogin (String url , String submitUrl , String id , String login , String password , String group , String groupUuid , String uuid ) {
206
292
try {
207
293
var response = connection .setLogin (url , submitUrl , id , login , password , group , groupUuid , uuid );
@@ -212,6 +298,11 @@ public boolean setLogin(String url, String submitUrl, String id, String login, S
212
298
}
213
299
}
214
300
301
+ /**
302
+ * Request to retrieve all database groups together with their groupUuids.
303
+ *
304
+ * @return An object that contains the database groups and groupUuids in case the request was successful, an empty object otherwise.
305
+ */
215
306
public JSONObject getDatabaseGroups () {
216
307
try {
217
308
return connection .getDatabaseGroups ();
@@ -221,6 +312,11 @@ public JSONObject getDatabaseGroups() {
221
312
}
222
313
}
223
314
315
+ /**
316
+ * Request to generate a password according to the password generator settings.
317
+ *
318
+ * @return The newly generated password in case the generation was successful, an empty String otherwise.
319
+ */
224
320
public String generatePassword () {
225
321
try {
226
322
var response = connection .generatePassword ().getJSONArray ("entries" );
@@ -231,6 +327,11 @@ public String generatePassword() {
231
327
}
232
328
}
233
329
330
+ /**
331
+ * Request for locking the database from client.
332
+ *
333
+ * @return True, if the database could not locked, false if something went wrong.
334
+ */
234
335
public boolean lockDatabase () {
235
336
try {
236
337
connection .lockDatabase ();
@@ -241,6 +342,15 @@ public boolean lockDatabase() {
241
342
}
242
343
}
243
344
345
+ /**
346
+ * Request to create a new group for the given name or path. If the group already exists, its contents and
347
+ * groupUuid stay untouched.
348
+ *
349
+ * @param path Name or path. A path of the format level1/level2 creates a group level1 on the root level and a
350
+ * group level2 as a child of level1.
351
+ * @return A Map containing the last part of the path name of the group (key: "name") that was created with its according groupUuid (key: "uuid")
352
+ * in case the group could be created, an empty Map otherwise.
353
+ */
244
354
public Map <String , String > createNewGroup (String path ) {
245
355
try {
246
356
return getNewGroupId (connection .createNewGroup (path ));
@@ -250,6 +360,13 @@ public Map<String, String> createNewGroup(String path) {
250
360
}
251
361
}
252
362
363
+ /**
364
+ * Request the actual TOTP for the given entry, identified by its uuid. If TOTP is not configured for the entry,
365
+ * an empty String is returned.
366
+ *
367
+ * @param uuid The uuid of the entry.
368
+ * @return The TOTP for the entry or an empty String in case TOTP is not configured for that entry or an error occurred.
369
+ */
253
370
public String getTotp (String uuid ) {
254
371
try {
255
372
return connection .getTotp (uuid ).getString ("totp" );
@@ -319,5 +436,10 @@ public String getAssociateId() {
319
436
return connection .getAssociateId ();
320
437
}
321
438
439
+ /**
440
+ * Getter for the ScheduledExecutorService in case the service needs to be shutdown from outside this library.
441
+ *
442
+ * @return A reference to the ScheduledExecutorService.
443
+ */
322
444
public ScheduledExecutorService getScheduler () { return scheduler ; }
323
445
}
0 commit comments