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
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.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.booleanStraight MD5, no salt Compatible with Jetty and RFC 2617.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.
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
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
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
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