java.lang.Object
net.i2p.i2pcontrol.security.SecurityManager
Manage the password storing for I2PControl.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classClean up old authorization tokens to keep the token store slim and fit.Field Summary
Modifier and TypeFieldDescriptionprivate final ConfigurationManagerSupplies the configured passwords.private final I2PAppContextThe context the manager runs in.private final LogLogger for this class.Live tokens, by token string.static final StringSeed password stored when no auth.password has been configured yet.private final SimpleTimer2.TimedEventExpires the tokens as they age out.Constructor Summary
ConstructorsConstructorDescriptionSecurityManager(I2PAppContext ctx, KeyStoreProvider ksp, ConfigurationManager conf) Create the security manager and start the sweeper that expires auth tokens; no token store is loaded here.Method Summary
Modifier and TypeMethodDescriptionHash input one time with SHA-256, return Base64 encoded string.getPasswdHash(String pwd) Hash pwd with using BCrypt with the default salt.private StringGet saved password hash.booleanIs this password correct?booleanIs this password correct?booleanSet new password.voidStop the periodic auth token cleanup timer and clear all tokensvalidatePasswd(String pwd) Add a Authentication Token if the provided password is valid.voidverifyToken(String tokenID) Checks whether the AuthToken with the given ID exists and if it does whether is has expired.
Field Details
DEFAULT_AUTH_PASSWORD
Seed password stored when no auth.password has been configured yet.- See Also:
authTokens
timer
Expires the tokens as they age out._log
Logger for this class._conf
Supplies the configured passwords._context
The context the manager runs in.
Constructor Details
SecurityManager
Create the security manager and start the sweeper that expires auth tokens; no token store is loaded here.- Parameters:
ctx- the application context supplying the logger, random source and SHA-256 generatorksp- may be null (if webapp); currently unused, kept for the APIconf- the configuration manager holding the persisted salt and password hash
Method Details
stopTimedEvents
public void stopTimedEvents()Stop the periodic auth token cleanup timer and clear all tokensgetPasswdHash
getSavedPasswdHash
Get saved password hash. Stores if not previously set.- Returns:
- BCrypt hash of salt and password
getHash
isValid
Is this password correct?- Parameters:
pwd- the plaintext password to compare against the stored BCrypt hash- Returns:
- true if password is valid.
isDefaultPasswordValid
public boolean isDefaultPasswordValid()Is this password correct?- Returns:
- true if password is valid.
validatePasswd
Add a Authentication Token if the provided password is valid. The token will be valid for one day.- Parameters:
pwd- the plaintext password to check; if it matches, a one-day token is issued- Returns:
- AuthToken if password is valid. If password is invalid null will be returned.
setPasswd
Set new password. Old tokens will NOT remain valid, to encourage the new password being tested.- Parameters:
newPasswd- the replacement plaintext password, hashed and stored through the same BCrypt path as the existing one- Returns:
- Returns true if a new password was set.
verifyToken
Checks whether the AuthToken with the given ID exists and if it does whether is has expired.- Parameters:
tokenID- - The token to validate- Throws:
InvalidAuthTokenException- if no token with that ID is knownExpiredAuthTokenException- if the token is known but past its expiry, in which case it is also removed from the store