Skip to content

Commit 157e033

Browse files
committed
Merge branch 'develop' into main
2 parents 8c9f24b + 909d20f commit 157e033

File tree

4 files changed

+137
-14
lines changed

4 files changed

+137
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Add `keepassxc-proxy-access` as a dependency to your project.
1515
<dependency>
1616
<groupId>org.purejava</groupId>
1717
<artifactId>keepassxc-proxy-access</artifactId>
18-
<version>0.0.3</version>
18+
<version>0.0.4</version>
1919
</dependency>
2020
```
2121

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.purejava</groupId>
88
<artifactId>keepassxc-proxy-access</artifactId>
9-
<version>0.0.3</version>
9+
<version>0.0.4</version>
1010
<packaging>jar</packaging>
1111

1212
<name>keepassxc-proxy-access</name>
@@ -54,9 +54,9 @@
5454
<maven.compiler.target>1.9</maven.compiler.target>
5555

5656
<tweetnacl.version>1.1.2</tweetnacl.version>
57-
<junixsocket.version>2.3.3</junixsocket.version>
58-
<json.version>20201115</json.version>
59-
<commons-lang3.version>3.11</commons-lang3.version>
57+
<junixsocket.version>2.3.4</junixsocket.version>
58+
<json.version>20210307</json.version>
59+
<commons-lang3.version>3.12.0</commons-lang3.version>
6060
<junit.version>5.7.0</junit.version>
6161
<slf4j.version>1.7.30</slf4j.version>
6262
</properties>

src/main/java/org/keepassxc/Connection.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ public String getDatabasehash(boolean triggerUnlock) throws IOException, Keepass
275275
}
276276

277277
/**
278-
* Request for testing if this client has been associated with KeePassXC.
278+
* Request for testing if the public IdKey and the public AssociateId are valid and enable this client
279+
* to talk to KeePassXC. With valid IDs, the client is considered associated with KeePassXC.
279280
* The test is positive when no exception is thrown.
280281
*
281282
* @param id The identifier of the KeePassXC database connection to be tested.
@@ -329,7 +330,7 @@ public JSONObject getLogins(String url, String submitUrl, boolean httpAuth, List
329330
}
330331

331332
/**
332-
* Request to store a new entry in the current KeePassXC database.
333+
* Request to store a new entry or update an existing entry in the current KeePassXC database.
333334
*
334335
* @param url The URL to be saved. The title of the new entry is the hostname of the URL.
335336
* @param submitUrl URL that can be passed along amd gets added to entry properties.
@@ -341,8 +342,8 @@ public JSONObject getLogins(String url, String submitUrl, boolean httpAuth, List
341342
* the given groupUuid, the standard group is used to store the entry.
342343
* @param groupUuid Identifier to decide, where to store the entry. For an existing group, the groupUuid must be
343344
* given, otherwise the standard group is used to store the entry.
344-
* @param uuid Identifier whether an existing entry is updated or a new one is created. If empty, the entry is
345-
* stored in the given groupUuid.
345+
* @param uuid Identifier whether an existing entry is updated or a new one is created. To update an existing entry,
346+
* its current uuid is required. If empty, a new entry is stored in the given groupUuid.
346347
* @return An object that contains the key "success" with the value "true" in case the request was successful.
347348
* @throws IOException The request to store credentials failed due to technical reasons.
348349
* @throws KeepassProxyAccessException Credentials could not be stored in the KeePassXC database.

src/main/java/org/purejava/KeepassProxyAccess.java

Lines changed: 127 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ public KeepassProxyAccess() {
6060
}
6161

6262
/**
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
6464
* so that it can be used to send requests to and receive requests from a KeePassXC database.
65+
* @see org.purejava.Credentials
66+
*
6567
* @return An Optional of the Credentials read from disc in case they are available, an empty Optional otherwise.
6668
*/
6769
private Optional<Credentials> loadCredentials() {
@@ -77,8 +79,10 @@ private Optional<Credentials> loadCredentials() {
7779

7880

7981
/**
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
8183
* operation that might fail.
84+
* @see org.purejava.Credentials
85+
*
8286
* @param credentials An Optional of the Credentials to be saved.
8387
*/
8488
private void scheduleSave(Optional<Credentials> credentials) {
@@ -95,7 +99,9 @@ private void scheduleSave(Optional<Credentials> credentials) {
9599
}
96100

97101
/**
98-
* Saves @see org.purejava.Credentials to disc.
102+
* Saves {@link org.purejava.Credentials Credentials} to disc.
103+
* @see org.purejava.Credentials
104+
*
99105
* @param credentials An Optional of the Credentials to be saved.
100106
*/
101107
private void saveCredentials(Optional<Credentials> credentials) {
@@ -118,15 +124,24 @@ private void saveCredentials(Optional<Credentials> credentials) {
118124
}
119125

120126
/**
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.
122128
*
123-
* @return The entered associateID and returned IDKeyPublicKey.
129+
* @return The entered associateID and returned IDKeyPublicKey stored on association.
124130
*/
125131
public Map<String, String> exportConnection() {
126132
return Map.of("id", connection.getAssociateId(),
127133
"key", connection.getIdKeyPairPublicKey());
128134
}
129135

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+
*/
130145
public boolean connect() {
131146
try {
132147
connection.connect();
@@ -136,6 +151,12 @@ public boolean connect() {
136151
}
137152
}
138153

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+
*/
139160
public boolean associate() {
140161
try {
141162
connection.associate();
@@ -146,6 +167,15 @@ public boolean associate() {
146167
}
147168
}
148169

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+
*/
149179
public boolean connectionAvailable() {
150180
return getIdKeyPairPublicKey() != null &&
151181
!getIdKeyPairPublicKey().isEmpty() &&
@@ -154,6 +184,14 @@ public boolean connectionAvailable() {
154184
testAssociate(getAssociateId(), getIdKeyPairPublicKey());
155185
}
156186

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+
*/
157195
public boolean testAssociate(String id, String key) {
158196
try {
159197
connection.testAssociate(id, key);
@@ -164,6 +202,14 @@ public boolean testAssociate(String id, String key) {
164202
}
165203
}
166204

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+
*/
167213
public String getDatabasehash(boolean... unlock) {
168214
try {
169215
if (unlock.length > 1) {
@@ -180,6 +226,16 @@ public String getDatabasehash(boolean... unlock) {
180226
}
181227
}
182228

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+
*/
183239
public Map<String, Object> getLogins(String url, String submitUrl, boolean httpAuth, List<Map<String, String>> list) {
184240
try {
185241
return connection.getLogins(url, submitUrl, httpAuth, list).toMap();
@@ -189,6 +245,19 @@ public Map<String, Object> getLogins(String url, String submitUrl, boolean httpA
189245
}
190246
}
191247

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+
*/
192261
public boolean loginExists(String url, String submitUrl, boolean httpAuth, List<Map<String, String>> list, String password) {
193262
var response = getLogins(url, submitUrl, httpAuth, list);
194263
if (response.isEmpty()) {
@@ -202,6 +271,23 @@ public boolean loginExists(String url, String submitUrl, boolean httpAuth, List<
202271
return false;
203272
}
204273

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+
*/
205291
public boolean setLogin(String url, String submitUrl, String id, String login, String password, String group, String groupUuid, String uuid) {
206292
try {
207293
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
212298
}
213299
}
214300

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+
*/
215306
public JSONObject getDatabaseGroups() {
216307
try {
217308
return connection.getDatabaseGroups();
@@ -221,6 +312,11 @@ public JSONObject getDatabaseGroups() {
221312
}
222313
}
223314

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+
*/
224320
public String generatePassword() {
225321
try {
226322
var response = connection.generatePassword().getJSONArray("entries");
@@ -231,6 +327,11 @@ public String generatePassword() {
231327
}
232328
}
233329

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+
*/
234335
public boolean lockDatabase() {
235336
try {
236337
connection.lockDatabase();
@@ -241,6 +342,15 @@ public boolean lockDatabase() {
241342
}
242343
}
243344

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+
*/
244354
public Map<String, String> createNewGroup(String path) {
245355
try {
246356
return getNewGroupId(connection.createNewGroup(path));
@@ -250,6 +360,13 @@ public Map<String, String> createNewGroup(String path) {
250360
}
251361
}
252362

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+
*/
253370
public String getTotp(String uuid) {
254371
try {
255372
return connection.getTotp(uuid).getString("totp");
@@ -319,5 +436,10 @@ public String getAssociateId() {
319436
return connection.getAssociateId();
320437
}
321438

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+
*/
322444
public ScheduledExecutorService getScheduler() { return scheduler; }
323445
}

0 commit comments

Comments
 (0)