java.lang.Object
page.codeberg.friedolyn.crypto.KeePassXC
An easy-to-use wrapper around
KeepassProxyAccess to access the KeePassXC
password manager. This class provides methods to
connectto KeePassXC,ask the user to grant access permissionto their password database- and
get the Friedolin login credentialsfrom the database.
KeepassProxyAccess stores the credentials needed to access the KeePassXC database for us, so we don't have to
worry about that.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classstatic final record -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.purejava.KeepassProxyAccessTheKeepassProxyAccessobject that we use to access the KeePassXC database. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAsks the user to allow us to access their password database.booleanconnect()booleanboolean@NonNull Task<KeePassXC.KeePassEntry> @NonNull KeePassXC.KeePassEntryGets the user's login credentials for the given URL from the user's KeePassXC database.booleanstorePassword(@NonNull URL url, @NonNull String user, char[] password) Saves the given password for the given URL in the KeePassXC database.
-
Field Details
-
keepass
private final org.purejava.KeepassProxyAccess keepassTheKeepassProxyAccessobject that we use to access the KeePassXC database.
-
-
Constructor Details
-
KeePassXC
public KeePassXC()
-
-
Method Details
-
connect
public boolean connect()- Returns:
KeepassProxyAccess.connect()
-
connectionIsAvailable
public boolean connectionIsAvailable()- Returns:
KeepassProxyAccess.connectionAvailable()
-
databaseIsLocked
public boolean databaseIsLocked()- Returns:
KeepassProxyAccess.isDatabaseLocked()
-
associate
public boolean associate()Asks the user to allow us to access their password database. Requires a prior call toconnect().- Returns:
Trueif we successfully connected to KeePassXC and were granted permission to access the database,falseotherwise.- API Note:
- This method will block the current thread until the user has granted access or a timeout of 60 seconds has passed.
-
getLogins
@NonNull public @NonNull KeePassXC.KeePassEntry getLogins(@NonNull @NonNull URL url) throws org.openqa.selenium.NotFoundException, IllegalStateException Gets the user's login credentials for the given URL from the user's KeePassXC database.- Parameters:
url- The URL for which to get the user's login credentials.- Returns:
- The user's login credentials for the given URL as stored in the KeePassXC database.
- Throws:
org.openqa.selenium.NotFoundException- If there are no login credentials for the given URL in the KeePassXC database.IllegalStateException- If the KeePassXC database is locked or otherwise not accessible to us.
-
getFriedolinLogins
@NonNull public KeePassXC.KeePassEntry getFriedolinLogins() throws org.openqa.selenium.NotFoundException, IllegalStateException- Returns:
- The first
KeePassXC.KeePassEntryin the user's KeePassXC database whose URL matchesFriedolyn.BASE_URL. - Throws:
org.openqa.selenium.NotFoundException- If there are no Friedolin login credentials in the KeePassXC database.IllegalStateException- If the KeePassXC database is locked or otherwise not accessible to us.
-
getAssociateAndLoginTask
- Returns:
- A
Taskthat doesconnect(),associate(), andgetFriedolinLogins()all in one go. The task's result is anOptionalcontaining theKeePassXC.KeePassEntryif everything went well orOptional.empty()if an error occurred.
-
storePassword
public boolean storePassword(@NonNull @NonNull URL url, @NonNull @NonNull String user, char[] password) throws IllegalStateException Saves the given password for the given URL in the KeePassXC database.- Parameters:
url- The URL which the login credentials are valid for.user- The user name used to log in to the given URL.password- The password to authenticate with the service at the given URL.- Returns:
trueif the password was stored successfully,falseotherwise.- Throws:
IllegalStateException- If the KeePassXC database is locked or otherwise inaccessible.
-