net.i2p.util
Class PasswordManager

java.lang.Object
  extended by net.i2p.util.PasswordManager
Direct Known Subclasses:
RouterPasswordManager

public class PasswordManager
extends Object

Manage both plaintext and salted/hashed password storage in router.config. There's no state here, so instantiate at will.

Since:
0.9.4

Field Summary
protected static String PROP_B64
          stored obfuscated as b64 of the UTF-8 bytes
protected static String PROP_CRYPT
          stored as a Unix crypt string
protected static String PROP_MD5
          stored as the hex of the MD5 hash of the ISO-8859-1 bytes.
protected static String PROP_PW
          stored as plain text
protected static String PROP_SHASH
          stored as the b64 of the 16 byte salt + the 32 byte hash of the UTF-8 bytes
protected static int SALT_LENGTH
           
protected static int SHASH_LENGTH
          48
 
Constructor Summary
PasswordManager(I2PAppContext ctx)
           
 
Method Summary
 boolean check(String realm, String user, String pw)
          Checks both plaintext and hash
 boolean checkB64(String realm, String user, String pw)
           
 boolean checkHash(String realm, String user, String pw)
          With random salt
 boolean checkPlain(String realm, String user, String pw)
           
 String get(String realm, String user)
          Either plain or b64
 String getB64(String realm, String user)
           
 String getPlain(String realm, String user)
           
static String md5Hex(String fullpw)
          Straight MD5, no salt Will return the MD5 sum of the data, compatible with Jetty and RFC 2617.
static String md5Hex(String subrealm, String user, String pw)
          Straight 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SALT_LENGTH

protected static final int SALT_LENGTH
See Also:
Constant Field Values

SHASH_LENGTH

protected static final int SHASH_LENGTH
48

See Also:
Constant Field Values

PROP_PW

protected static final String PROP_PW
stored as plain text

See Also:
Constant Field Values

PROP_B64

protected static final String PROP_B64
stored obfuscated as b64 of the UTF-8 bytes

See Also:
Constant Field Values

PROP_MD5

protected static final String PROP_MD5
stored as the hex of the MD5 hash of the ISO-8859-1 bytes. Compatible with Jetty.

See Also:
Constant Field Values

PROP_CRYPT

protected static final String PROP_CRYPT
stored as a Unix crypt string

See Also:
Constant Field Values

PROP_SHASH

protected static final String PROP_SHASH
stored as the b64 of the 16 byte salt + the 32 byte hash of the UTF-8 bytes

See Also:
Constant Field Values
Constructor Detail

PasswordManager

public PasswordManager(I2PAppContext ctx)
Method Detail

check

public boolean check(String realm,
                     String user,
                     String pw)
Checks both plaintext and hash

Parameters:
realm - e.g. i2cp, routerconsole, etc.
user - null or "" for no user, already trimmed
pw - plain text, already trimmed
Returns:
if pw verified

checkPlain

public boolean checkPlain(String realm,
                          String user,
                          String pw)
Parameters:
realm - e.g. i2cp, routerconsole, etc.
user - null or "" for no user, already trimmed
pw - plain text, already trimmed
Returns:
if pw verified

checkB64

public boolean checkB64(String realm,
                        String user,
                        String pw)
Parameters:
realm - e.g. i2cp, routerconsole, etc.
user - null or "" for no user, already trimmed
pw - plain text, already trimmed
Returns:
if pw verified

checkHash

public boolean checkHash(String realm,
                         String user,
                         String pw)
With random salt

Parameters:
realm - e.g. i2cp, routerconsole, etc.
user - null or "" for no user, already trimmed
pw - plain text, already trimmed
Returns:
if pw verified

get

public String get(String realm,
                  String user)
Either plain or b64

Parameters:
realm - e.g. i2cp, routerconsole, etc.
user - null or "" for no user, already trimmed
Returns:
the pw or null

getPlain

public String getPlain(String realm,
                       String user)
Parameters:
realm - e.g. i2cp, routerconsole, etc.
user - null or "" for no user, already trimmed
Returns:
the pw or null

getB64

public String getB64(String realm,
                     String user)
Parameters:
realm - e.g. i2cp, routerconsole, etc.
user - null or "" for no user, already trimmed
Returns:
the decoded pw or null

md5Hex

public static String md5Hex(String subrealm,
                            String user,
                            String pw)
Straight MD5, no salt Will return the MD5 sum of "user:subrealm:pw", compatible with Jetty and RFC 2617.

Parameters:
subrealm - to be used in creating the checksum
user - non-null, non-empty, already trimmed
pw - non-null, plain text, already trimmed
Returns:
lower-case hex with leading zeros, 32 chars, or null on error

md5Hex

public static String md5Hex(String fullpw)
Straight MD5, no salt Will return the MD5 sum of the data, compatible with Jetty and RFC 2617.

Parameters:
fullpw - non-null, plain text, already trimmed
Returns:
lower-case hex with leading zeros, 32 chars, or null on error

md5Sum

public static byte[] md5Sum(byte[] data)
Standard MD5 checksum

Parameters:
data - non-null
Returns:
16 bytes, or null on error