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
connect
to KeePassXC,ask the user to grant access permission
to their password database- and
get the Friedolin login credentials
from 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 class
static final record
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.purejava.KeepassProxyAccess
TheKeepassProxyAccess
object that we use to access the KeePassXC database. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Asks the user to allow us to access their password database.boolean
connect()
boolean
boolean
@NonNull Task
<KeePassXC.KeePassEntry> @NonNull KeePassXC.KeePassEntry
Gets the user's login credentials for the given URL from the user's KeePassXC database.boolean
storePassword
(@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 keepassTheKeepassProxyAccess
object 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:
True
if we successfully connected to KeePassXC and were granted permission to access the database,false
otherwise.- 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.KeePassEntry
in 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
Task
that doesconnect()
,associate()
, andgetFriedolinLogins()
all in one go. The task's result is anOptional
containing theKeePassXC.KeePassEntry
if 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:
true
if the password was stored successfully,false
otherwise.- Throws:
IllegalStateException
- If the KeePassXC database is locked or otherwise inaccessible.
-