Class PasskeyStore
java.lang.Object
com.iizix.server.user.passkey.PasskeyStore
The passkeys in the server database (CC-LOGIN-L8-PASSKEYS): the tables
IZS.USER_HANDLES and IZS.USER_CREDENTIALS of createPasskeyTables.sql beside this class, created here at the first use on a database of any age - the server's createBaseTables.sql runs on an empty database only (the model is the load balancer's DBLoadBalancer.createTables).The column recovery of IZS.USER_CREDENTIALS came after the table (CC-LOGIN-PASSKEY-SECOND-FACTOR, T1-039): a table that was created without it gains it here, by ALTER TABLE ... ADD COLUMN, nullable, so that the passkeys already stored keep NULL in it, which is read as no (the model is the Push engine's SubscriptionStore.ensureSchema).
Every method takes a pooled connection of its own, commits what it wrote, and returns the connection. A row of a user goes with the user: the foreign keys delete it.
- Author:
- Christopher Mindus
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe schema and the table probed to tell whether the script ran: the LAST table it creates.static final StringThe schema and the table probed to tell whether the script ran: the LAST table it creates.static final StringThe name of the SQL script beside this class.Method Summary
Modifier and TypeMethodDescriptionstatic booleancreateTables(Connection conn) Creates the passkey tables if required, on the connection given, which is committed when they are created.static StoredPasskeyfind(byte[] credentialId) Finds a passkey by its credential ID.static longfindUser(byte[] handle) Finds the user of a user handle.static StringGets the class-loader resource name of the SQL script.static byte[]getUserHandle(long userID) Gets the WebAuthn user handle of a user, made when the user has none: 64 random bytes.static booleaninsert(StoredPasskey passkey) Stores a new passkey.static List<StoredPasskey> Lists the passkeys of a user for a relying party, the newest first.static booleanrecordUse(StoredPasskey passkey, long signCount, boolean backedUp, long now) Records a use of a passkey: the signature counter, the backup state and the time.static booleanRemoves a passkey of a user.static intremoveAll(Connection conn, long userID) Removes every passkey of a user inside the caller's transaction, whatever the relying party: the development reset of the administrator (DevelopmentAdminReset).static booleanRenames a passkey of a user.static voidreset()Forgets that the tables exist: the next use probes the database again.
Field Details
SCHEMA
The schema and the table probed to tell whether the script ran: the LAST table it creates.- See Also:
PROBE_TABLE
The schema and the table probed to tell whether the script ran: the LAST table it creates.- See Also:
SCRIPT
Method Details
getScriptResource
Gets the class-loader resource name of the SQL script.- Returns:
- The resource name,
com/iizix/server/user/passkey/createPasskeyTables.sql.
createTables
Creates the passkey tables if required, on the connection given, which is committed when they are created. Two servers on one database may both try: the one that finds a table made in the meantime by the other probes again and goes on. A table of passkeys that was created without the columnrecoverygains it.- Parameters:
conn- The connection.- Returns:
- true if they were created here, false when they existed.
- Throws:
SQLException- For SQL errors.
reset
public static void reset()Forgets that the tables exist: the next use probes the database again. For a server whose connection pool was replaced, and for tests.getUserHandle
Gets the WebAuthn user handle of a user, made when the user has none: 64 random bytes.- Parameters:
userID- The user ID.- Returns:
- The user handle.
- Throws:
SQLException- For SQL errors, among them a user that does not exist.
findUser
Finds the user of a user handle.- Parameters:
handle- The user handle.- Returns:
- The user ID, -1 when no user has the handle.
- Throws:
NullPointerException- Ifhandleis null.SQLException- For SQL errors.
find
Finds a passkey by its credential ID.- Parameters:
credentialId- The credential ID.- Returns:
- The passkey, null when there is none.
- Throws:
NullPointerException- IfcredentialIdis null.SQLException- For SQL errors.
list
Lists the passkeys of a user for a relying party, the newest first.- Parameters:
userID- The user ID.rpId- The relying party ID.- Returns:
- The passkeys, empty when the user has none.
- Throws:
SQLException- For SQL errors.
insert
Stores a new passkey.- Parameters:
passkey- The passkey.- Returns:
- true when it is stored, false when a passkey with its credential ID exists - for this user or for any other.
- Throws:
NullPointerException- Ifpasskeyis null.SQLException- For SQL errors.
recordUse
public static boolean recordUse(StoredPasskey passkey, long signCount, boolean backedUp, long now) throws SQLException Records a use of a passkey: the signature counter, the backup state and the time. The counter is written only when it is the stored one still, so that of two uses of one counter value the second is refused.- Parameters:
passkey- The passkey as it was read.signCount- The signature counter of the assertion.backedUp- The backup state of the assertion.now- The time of the use, epoch milliseconds.- Returns:
- true when the use is recorded, false when the passkey is gone or its counter moved since it was read.
- Throws:
NullPointerException- Ifpasskeyis null.SQLException- For SQL errors.
rename
Renames a passkey of a user.- Parameters:
userID- The user ID.key- The key of the passkey,StoredPasskey.key.nickname- The new name.- Returns:
- true when it is renamed, false when the user has no such passkey.
- Throws:
SQLException- For SQL errors.
remove
Removes a passkey of a user.- Parameters:
userID- The user ID.key- The key of the passkey,StoredPasskey.key.- Returns:
- true when it is removed, false when the user has no such passkey.
- Throws:
SQLException- For SQL errors.
removeAll
Removes every passkey of a user inside the caller's transaction, whatever the relying party: the development reset of the administrator (DevelopmentAdminReset). Nothing is committed here. A database without the table has no passkey to remove: the table is looked for, never created, and its absence is not an error. The user handle stays.- Parameters:
conn- The connection of the caller's transaction.userID- The user ID.- Returns:
- The number of passkeys removed.
- Throws:
SQLException- For SQL errors.