java.lang.Object
net.i2p.util.PasswordManager
net.i2p.router.util.RouterPasswordManager
net.i2p.router.web.ConsolePasswordManager
Manage both plaintext and salted/hashed password storage in
router.config.Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final SecureRandomGenerates password salts.private static final PatternSplits a stored hash into its parts.private static final StringUser name the console password is stored under.private static final intPBKDF2 rounds used when hashing a password.private static final StringOld plaintext console password property, migrated to a hash.private static final StringProperty marking the password migration as done.private static final StringSuffix of the hashed password property.Fields inherited from class RouterPasswordManager
_contextFields inherited from class PasswordManager
PROP_B64, PROP_MD5, PROP_PW, PROP_SHASH, SALT_LENGTH, SHASH_LENGTHModifier and TypeFieldDescriptionprotected static final StringStored obfuscated as b64 of the UTF-8 bytes.protected static final StringStored as the hex of the MD5 hash of the UTF-8 bytes.protected static final StringStored as plain text.protected static final StringStored as the b64 of the 16 byte salt + the 32 byte hash of the UTF-8 bytes.protected static final intLength of the random salt prefixed to each stored hash, in bytes.protected static final intStored hash length in bytes (salt + session key, 48).Constructor Summary
ConstructorsConstructorDescriptionCreate a manager over the router's config store, migrating any legacy plaintext "consolePassword" entry to the salted/hash form on the way in.Method Summary
Modifier and TypeMethodDescriptionbooleanStraight MD5.private booleancheckPBKDF2(String realm, String user, String pw) PBKDF2 hash for password storage.Get all MD5 usernames and passwords.Get all users with PBKDF2 passwords.(package private) static byte[]Decode a fixed-width hex string into exactly hex.length()/2 bytes.(package private) static StringHexEncode(byte[] data) Encode a byte array to a lowercase hex string.private booleanMigrate from plaintext to MD5 hash Ref: RFC 2617.booleanStraight MD5, no salt Compatible with Jetty and RFC 2617.private booleansavePBKDF2(String realm, String subrealm, String user, String pw) Save password as PBKDF2 hash.Methods inherited from class RouterPasswordManager
migrate, remove, save, saveB64, saveHash, savePlainModifier and TypeMethodDescriptionprotected booleanmigrate()Migrate from plaintext to salt/hash.booleanRemove password, any kind.booleanbooleanThis will fail if if user contains '#' or '=' or starts with '!'.booleanThis will fail if user contains '#' or '=' or starts with '!'.booleanThis will fail if pw contains a '#' or if user contains '#' or '=' or starts with '!'.Methods inherited from class PasswordManager
check, checkB64, checkHash, checkHash, checkPlain, createHash, get, getB64, getPlain, md5Hex, md5Hex, md5Sum, sha256Hex, sha256Hex, sha256SumModifier and TypeMethodDescriptionbooleanChecks both plaintext and hash.booleanChecks a password stored base64-encoded.booleanCheck pw against b64 salt+hash, as generated byPasswordManager.createHash(String).booleanWith random salt.booleancheckPlain(String realm, String user, String pw) Checks a password stored in plaintext.createHash(String pw) Create a salt+hash, to be saved and verified later by verifyHash().Either plain or b64.Retrieve the base64-stored password.Retrieve the plaintext-stored password.static StringStraight MD5, no salt Will return the MD5 sum of the data, compatible with Jetty and RFC 2617.static StringStraight MD5, no salt Will return the MD5 sum of "user:subrealm:pw", compatible with Jetty and RFC 2617.static byte[]md5Sum(byte[] data) Standard MD5 checksum.static StringReturn the SHA256 sum of the data, compatible with RFC 7616.static StringStraight SHA256, no salt Will return the SHA256 sum of "user:subrealm:pw", compatible with RFC 7616.static byte[]sha256Sum(byte[] data) Standard SHA-256 checksum.
Field Details
PROP_MIGRATED
Property marking the password migration as done.- See Also:
PROP_CONSOLE_OLD
Old plaintext console password property, migrated to a hash.- See Also:
CONSOLE_USER
User name the console password is stored under.- See Also:
PROP_PBKDF2
Suffix of the hashed password property.- See Also:
PBKDF2_ITERATIONS
private static final int PBKDF2_ITERATIONSPBKDF2 rounds used when hashing a password.- See Also:
COLON_SPLIT
Splits a stored hash into its parts._random
Generates password salts.
Constructor Details
ConsolePasswordManager
Create a manager over the router's config store, migrating any legacy plaintext "consolePassword" entry to the salted/hash form on the way in.- Parameters:
ctx- the router context whose config store holds the passwords
Method Details
checkMD5
Straight MD5. Compatible with Jetty.- Parameters:
realm- e.g. i2cp, routerconsole, etc.subrealm- the HTTP digest subrealm, hashed between the user and the passworduser- null or "" for no user, already trimmedpw- plain text, already trimmed- Returns:
- if pw verified
checkPBKDF2
PBKDF2 hash for password storage. Backward compatible - checks PBKDF2 first, falls back to MD5.- Parameters:
realm- e.g. i2cp, routerconsole, etc.user- null or "" for no user, already trimmedpw- plain text, already trimmed- Returns:
- if pw verified
HexDecode
Decode a fixed-width hex string into exactly hex.length()/2 bytes.DELIBERATE DEVIATION from the DataHelper canonical-source rule:
DataHelper.fromHexString(String)decodes via BigInteger and returns the minimum-length, sign-aware representation - a leading '0' nibble is stripped and a first nibble of 8-f gains an extra 0x00 byte. Password salts and hashes must round-trip at their exact stored width; using fromHexString here corrupted ~15/16 of PBKDF2 credentials and locked users out of the console.- Parameters:
hex- even-length hex string, either case, no prefix- Returns:
- decoded bytes, always exactly hex.length()/2 long
- Throws:
IllegalArgumentException- on odd length or non-hex character
getMD5
getPBKDF2
migrateConsole
private boolean migrateConsole()Migrate from plaintext to MD5 hash Ref: RFC 2617.- Returns:
- success or nothing to migrate
saveMD5
Straight MD5, no salt Compatible with Jetty and RFC 2617.Upgrades to PBKDF2 on save (subrealm is unused for PBKDF2).
- Parameters:
realm- The full realm, e.g.routerconsole.auth.i2prouter, etc.subrealm- unused (for backward compatibility)user- non-null, non-empty, already trimmedpw- the plain text password to hash- Returns:
- true if the PBKDF2 entry reached
router.config; false if the JCE provider rejects PBKDF2 or the key spec
savePBKDF2
Save password as PBKDF2 hash. Backward compatible - saves new PBKDF2, keeps old MD5 for migration.- Parameters:
realm- The full realmsubrealm- unused for PBKDF2user- non-null, non-emptypw- the plain text password to hash- Returns:
- true if the PBKDF2 entry reached
router.config; false if the JCE provider rejects PBKDF2 or the key spec
HexEncode
Encode a byte array to a lowercase hex string. Two hex characters per byte with leading zeros.- Parameters:
data- the byte array to encode- Returns:
- lowercase hex string