This class calculates the two "responses" to the nonce supplied by the server
as a part of NTLM authentication.
Much gratitude to the authors of this page, esp. for NTLMv2 info:
http://davenport.sourceforge.net/ntlm.html
answerLmChallenge
public static byte[] answerLmChallenge(String pwd,
byte[] nonce)
throws UnsupportedEncodingException
answerLmv2Challenge
public static byte[] answerLmv2Challenge(String domain,
String user,
String password,
byte[] nonce,
byte[] clientNonce)
throws UnsupportedEncodingException
answerNtChallenge
public static byte[] answerNtChallenge(String password,
byte[] nonce)
throws UnsupportedEncodingException
answerNtlmv2Challenge
public static byte[] answerNtlmv2Challenge(String domain,
String user,
String password,
byte[] nonce,
byte[] targetInfo,
byte[] clientNonce)
throws UnsupportedEncodingException
answerNtlmv2Challenge
public static byte[] answerNtlmv2Challenge(String domain,
String user,
String password,
byte[] nonce,
byte[] targetInfo,
byte[] clientNonce,
byte[] timestamp)
throws UnsupportedEncodingException
answerNtlmv2Challenge
public static byte[] answerNtlmv2Challenge(String domain,
String user,
String password,
byte[] nonce,
byte[] targetInfo,
byte[] clientNonce,
long now)
throws UnsupportedEncodingException
convertPassword
private static byte[] convertPassword(String password)
throws UnsupportedEncodingException
Used by answerNtlmChallenge. We need the password converted to caps,
narrowed and padded/truncated to 14 chars...
createBlob
private static byte[] createBlob(byte[] targetInformation,
byte[] clientChallenge,
byte[] timestamp)
Creates the NTLMv2 blob from the given target information block and
client challenge.
targetInformation
- The target information block from the Type 2
message.clientChallenge
- The random 8-byte client challenge.
- The blob, used in the calculation of the NTLMv2 Response.
createTimestamp
public static byte[] createTimestamp(long time)
Creates a timestamp in the format used in NTLMv2 responses.
Public so it could be unit tested.
time
- current time, as returned from System.currentTimeMillis
- little-endian byte array of number of tenths of microseconds since
Jan 1, 1601
encryptNonce
private static byte[] encryptNonce(byte[] key,
byte[] nonce)
hmacMD5
private static byte[] hmacMD5(byte[] data,
byte[] key)
Calculates the HMAC-MD5 hash of the given data using the specified
hashing key.
data
- The data for which the hash will be calculated.key
- The hashing key.
- The HMAC-MD5 hash of the given data.
lmv2Response
private static byte[] lmv2Response(byte[] hash,
byte[] clientData,
byte[] challenge)
Creates the LMv2 Response from the given hash, client data, and
Type 2 challenge.
hash
- The NTLMv2 Hash.clientData
- The client data (blob or client challenge).challenge
- The server challenge from the Type 2 message.
- The response (either NTLMv2 or LMv2, depending on the
client data).
makeDESkey
private static byte[] makeDESkey(byte[] buf,
int off)
Turns a 7-byte DES key into an 8-byte one by adding parity bits. All
implementations of DES seem to want an 8-byte key.
md5
private static byte[] md5(byte[] data)
ntHash
private static byte[] ntHash(String password)
throws UnsupportedEncodingException
Creates the md4 hash of the unicode password. This is used as the DES
key when encrypting the nonce for NTLM challenge-response
ntv2Hash
private static byte[] ntv2Hash(String domain,
String user,
String password)
throws UnsupportedEncodingException