1515import java .io .IOException ;
1616import java .io .ObjectInputStream ;
1717import java .io .ObjectOutputStream ;
18+ import java .lang .module .ModuleDescriptor .Version ;
1819import java .nio .file .Files ;
1920import java .nio .file .Path ;
2021import java .nio .file .StandardCopyOption ;
@@ -36,6 +37,8 @@ public class KeepassProxyAccess implements PropertyChangeListener {
3637 private final AtomicReference <ScheduledFuture <?>> scheduledSaveCmd = new AtomicReference <>();
3738 private final ScheduledExecutorService scheduler ;
3839
40+ private final String V2_7_0 = "2.7.0" ;
41+
3942 public KeepassProxyAccess () {
4043 if (SystemUtils .IS_OS_LINUX || SystemUtils .IS_OS_MAC_OSX ) {
4144 connection = new LinuxMacConnection ();
@@ -322,8 +325,12 @@ public JSONObject getDatabaseGroups() {
322325 */
323326 public String generatePassword () {
324327 try {
325- var response = connection .generatePassword ().getJSONArray ("entries" );
326- return response .getJSONObject (0 ).getString ("password" );
328+ var response = connection .generatePassword ();
329+ if (isMinimiumVersion (response .getString ("version" ), V2_7_0 )) {
330+ return response .getString ("password" );
331+ } else {
332+ return response .getJSONArray ("entries" ).getJSONObject (0 ).getString ("password" );
333+ }
327334 } catch (IOException | IllegalStateException | KeepassProxyAccessException | JSONException e ) {
328335 log .info (e .toString (), e .getCause ());
329336 return "" ;
@@ -458,6 +465,17 @@ private void traverse(List<Object> children, Map<String, String> groups) {
458465 });
459466 }
460467
468+ /**
469+ * Compare two software version strings to check for a minimum software version.
470+ *
471+ * @param v1 The first version string.
472+ * @param v2 The second version string.
473+ * @return True in case v1 >= v2, false otherwise.
474+ */
475+ private boolean isMinimiumVersion (String v1 , String v2 ) {
476+ return Version .parse (v1 ).compareTo (Version .parse (v2 )) >= 0 ;
477+ }
478+
461479 @ Override
462480 public void propertyChange (PropertyChangeEvent event ) {
463481 scheduleSave ((Optional <Credentials >) event .getNewValue ());
0 commit comments