Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class JdbcTotpRepository
- Object
- JdbcTotpRepository
ImplementsTotpRepository
Secrets kept in the server’s database, in the cn1_mfa_totp table of
SecuritySchema.
A secret is what an attacker needs to produce a user’s codes for good, so it is not stored as it is: each is sealed with AES-GCM under a key the database does not hold, with a nonce of its own stored beside it and the user’s name bound in, so a row copied onto another user does not open. Give the key in the configuration, as 32 bytes in base64:
cn1.security.mfa.encryptionKey=... # openssl rand -base64 32
and build the repository with fromConfig. Losing the key loses every
enrolment; changing it does the same.
Fields
public static final String ENCRYPTION_KEY = "cn1.security.mfa.encryptionKey" | The setting that holds the key. |
Constructors
public JdbcTotpRepository(DataSource dataSource, byte[] encryptionKey) |
Methods
Inherited methods
Field details
ENCRYPTION_KEY
public static final String ENCRYPTION_KEY = "cn1.security.mfa.encryptionKey"Constructor details
JdbcTotpRepository
public JdbcTotpRepository(DataSource dataSource, byte[] encryptionKey)Parameters
dataSourceDataSource- Not documented.
encryptionKeybyte[]- 32 bytes
Method details
fromConfig
public static JdbcTotpRepository fromConfig(DataSource dataSource, Config config)A repository whose key is the configuration’s ENCRYPTION_KEY.
On a development profile a server without the setting gets a fixed key and says so, so that a laptop needs no secret; anywhere else the setting is required and the server does not start without it.
setClock
public void setClock(Clock clock)save
public void save(String username, byte[] secret)username, replacing any other.find
public TotpCredential find(String username)username, or null.confirm
public boolean confirm(String username)Returns
advance
public boolean advance(String username, long step)Records that a code of time step step was accepted, if no code of
that step or a later one has been.
The test and the change are one step, which is what makes a code good once: of two requests presenting the same code at the same moment, on one server or two, exactly one is told true.
Returns
confirm
public boolean confirm(String username, byte[] expectedSecret, long step)advance
public boolean advance(String username, byte[] expectedSecret, long step)delete
public boolean delete(String username)