java.lang.Object
net.i2p.util.PasswordManager
- Direct Known Subclasses:
RouterPasswordManager
Manage both plaintext and salted/hashed password storage in
router.config.There's no state here, so instantiate at will.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextUsed for the log and for reading and writing the password file.protected 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
ConstructorsConstructorDescriptionRemember the app context so lookups reach the property store.Method Summary
Modifier and TypeMethodDescriptionbooleanChecks both plaintext and hash.booleanChecks a password stored base64-encoded.booleanCheck pw against b64 salt+hash, as generated bycreateHash(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
_context
Used for the log and for reading and writing the password file.SALT_LENGTH
protected static final int SALT_LENGTHLength of the random salt prefixed to each stored hash, in bytes.- See Also:
SHASH_LENGTH
protected static final int SHASH_LENGTHStored hash length in bytes (salt + session key, 48).- See Also:
PROP_PW
PROP_B64
Stored obfuscated as b64 of the UTF-8 bytes.- See Also:
PROP_MD5
Stored as the hex of the MD5 hash of the UTF-8 bytes. Compatible with Jetty.- See Also:
PROP_SHASH
Stored as the b64 of the 16 byte salt + the 32 byte hash of the UTF-8 bytes.- See Also:
Constructor Details
PasswordManager
Remember the app context so lookups reach the property store.- Parameters:
ctx- the app context supplying the property store that holds the passwords
Method Details
check
checkPlain
checkB64
checkHash
checkHash
Check pw against b64 salt+hash, as generated bycreateHash(String).- Parameters:
shash- b64 stringpw- plain text non-null, already trimmed- Returns:
- if pw verified
createHash
get
getPlain
getB64
md5Hex
Straight MD5, no salt Will return the MD5 sum of "user:subrealm:pw", compatible with Jetty and RFC 2617.Updated in 0.9.26 to use UTF-8, as implied in RFC 7616/7617 See also http://stackoverflow.com/questions/7242316/what-encoding-should-i-use-for-http-basic-authentication http://stackoverflow.com/questions/702629/utf-8-characters-mangled-in-http-basic-auth-username
- Parameters:
subrealm- to be used in creating the checksumuser- non-null, non-empty, already trimmedpw- non-null, plain text, already trimmed- Returns:
- lower-case hex with leading zeros, 32 chars, or null on error
md5Hex
Straight MD5, no salt Will return the MD5 sum of the data, compatible with Jetty and RFC 2617.Updated in 0.9.26 to use UTF-8, as implied in RFC 7616/7617 See also http://stackoverflow.com/questions/7242316/what-encoding-should-i-use-for-http-basic-authentication
- Parameters:
fullpw- non-null, plain text, already trimmed- Returns:
- lower-case hex with leading zeros, 32 chars, or null on error
sha256Sum
public static byte[] sha256Sum(byte[] data) Standard SHA-256 checksum.- Parameters:
data- non-null- Returns:
- 32 bytes, or empty on error
md5Sum
public static byte[] md5Sum(byte[] data) Standard MD5 checksum.- Parameters:
data- non-null- Returns:
- 16 bytes, or null on error
sha256Hex
Straight SHA256, no salt Will return the SHA256 sum of "user:subrealm:pw", compatible with RFC 7616. NOT currently supported by Jetty.- Parameters:
subrealm- to be used in creating the checksumuser- non-null, non-empty, already trimmedpw- non-null, plain text, already trimmed- Returns:
- lower-case hex with leading zeros, 32 chars, or null on error
sha256Hex