Top Description Inners Fields Constructors Methods
org.apache.http.impl.auth

pack-priv final Class NTLMEngineImpl

extends Object
implements NTLMEngine
Class Inheritance
All Implemented Interfaces
org.apache.http.impl.auth.NTLMEngine
Imports
java.nio.charset.Charset, java.security.Key, .MessageDigest, .NoSuchAlgorithmException, java.security.cert.Certificate, .CertificateEncodingException, java.util.Arrays, .Locale, .Random, javax.crypto.Cipher, javax.crypto.spec.SecretKeySpec, org.apache.commons.codec.binary.Base64, org.apache.http.Consts

Provides an implementation for NTLMv1, NTLMv2, and NTLM2 Session forms of the NTLM authentication protocol.
Since
4.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
pack-priv static class
pack-priv static class
NTLMEngineImpl.HMACMD5

Cryptography support - HMACMD5 - algorithmically based on various web resources by Karl Wright

pack-priv static class
NTLMEngineImpl.MD4

Cryptography support - MD4.

pack-priv static enum
pack-priv static class
NTLMEngineImpl.NTLMMessage

NTLM message generation, base class

pack-priv static class
NTLMEngineImpl.Type1Message

Type 1 message assembly class

pack-priv static class
NTLMEngineImpl.Type2Message

Type 2 message class

pack-priv static class
NTLMEngineImpl.Type3Message

Type 3 message assembly class

Field Summary

Modifier and TypeField and Description
private static final Charset
DEFAULT_CHARSET

Character encoding

pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
private static final byte[]
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
private static final SecureRandom
RND_GEN

Secure random generator

private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
SIGNATURE

The signature string as bytes in the default encoding

private static final String
private static final Charset
UNICODE_LITTLE_UNMARKED

Unicode encoding

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static String
convertDomain(final String domain)

Convert domain to standard form

private static String
convertHost(final String host)

Convert host to standard form

private static byte[]

Returns:

The blob, used in the calculation of the NTLMv2 Response.
createBlob
(final byte[]
The random 8-byte client challenge.
clientChallenge
,
final byte[]
The target information block from the Type 2 message.
targetInformation
,
final byte[] timestamp)

Creates the NTLMv2 blob from the given target information block and client challenge.

private static Key

Returns:

A DES encryption key created from the key material starting at the specified offset in the given byte array.
createDESKey
(final byte[]
A byte array containing the DES key material.
bytes
,
final int
The offset in the given byte array at which the 7-byte key material starts.
offset
)

Creates a DES encryption key from the given key material.

private static byte[]
encodeLong(final int value)

private static void
encodeLong(final byte[] buf, final int offset, final int value)

pack-priv static int
F(final int x, final int y, final int z)

pack-priv static int
G(final int x, final int y, final int z)

public String
generateType1Msg(final String
Optional Windows domain name. Can be null.
domain
,
final String
Optional Windows workstation name. Can be null.
workstation
)

Implements org.apache.http.impl.auth.NTLMEngine.generateType1Msg.

Generates a Type1 message given the domain and workstation.
public String
generateType3Msg(final String
Windows user name
username
,
final String
Password
password
,
final String
Windows domain name
domain
,
final String
Windows workstation name
workstation
,
final String
Type2 challenge.
challenge
)

Implements org.apache.http.impl.auth.NTLMEngine.generateType3Msg.

Generates a Type3 message given the user credentials and the authentication challenge.
private static Charset

Returns:

the character set.
getCharset
(final int
is the flags.
flags
)

Find the character set based on the flags.

pack-priv static MessageDigest
private static byte[]
pack-priv static String

Returns:

String the message to add to the HTTP request header.
getType1Message
(final String
the computer name of the host requesting authentication.
host
,
final String
The domain to authenticate with.
domain
)

Creates the first message (type 1 message) in the NTLM authentication sequence.

pack-priv static String

Returns:

The type 3 message.
getType3Message
(final String
The user name. This should not include the domain name.
user
,
final String
The password.
password
,
final String
The host that is originating the authentication request.
host
,
final String
The domain to authenticate within.
domain
,
final byte[]
the 8 byte array the server sent.
nonce
,
final int type2Flags, final String target, final byte[] targetInformation)

Creates the type 3 message using the given server nonce.

pack-priv static String

Returns:

The type 3 message.
getType3Message
(final String
The user name. This should not include the domain name.
user
,
final String
The password.
password
,
final String
The host that is originating the authentication request.
host
,
final String
The domain to authenticate within.
domain
,
final byte[]
the 8 byte array the server sent.
nonce
,
final int type2Flags, final String target, final byte[] targetInformation, final Certificate peerServerCertificate, final byte[] type1Message, final byte[] type2Message)

Creates the type 3 message using the given server nonce.

pack-priv static int
H(final int x, final int y, final int z)

pack-priv static byte[]
hmacMD5(final byte[] value, final byte[] key)

Calculates HMAC-MD5

private static byte[]

Returns:

The LM Hash of the given password, used in the calculation of the LM Response.
lmHash
(final String
The password.
password
)

Creates the LM Hash of the user's password.

private static byte[]

Returns:

The response (either LM or NTLM, depending on the provided hash).
lmResponse
(final byte[]
The LM or NTLM Hash.
hash
,
final byte[]
The server challenge from the Type 2 message.
challenge
)

Creates the LM Response from the given hash and Type 2 challenge.

private static byte[]

Returns:

The LMv2 Hash, used in the calculation of the NTLMv2 and LMv2 Responses.
lmv2Hash
(final String domain, final String user, final byte[] ntlmHash)

Creates the LMv2 Hash of the user's password.

private static byte[]

Returns:

The response (either NTLMv2 or LMv2, depending on the client data).
lmv2Response
(final byte[]
The NTLMv2 Hash.
hash
,
final byte[]
The server challenge from the Type 2 message.
challenge
,
final byte[]
The client data (blob or client challenge).
clientData
)

Creates the LMv2 Response from the given hash, client data, and Type 2 challenge.

private static byte[]
makeRandomChallenge(final Random random)

Calculate a challenge block

private static byte[]
makeSecondaryKey(final Random random)

Calculate a 16-byte secondary key

pack-priv static byte[]

Returns:

The NTLM2 Session Response. This is placed in the NTLM response field of the Type 3 message; the LM response field contains the client challenge, null-padded to 24 bytes.
ntlm2SessionResponse
(final byte[] ntlmHash, final byte[] challenge, final byte[] clientChallenge)

Calculates the NTLM2 Session Response for the given challenge, using the specified password and client challenge.

private static byte[]

Returns:

The NTLM Hash of the given password, used in the calculation of the NTLM Response and the NTLMv2 and LMv2 Hashes.
ntlmHash
(final String
The password.
password
)

Creates the NTLM Hash of the user's password.

private static byte[]

Returns:

The NTLMv2 Hash, used in the calculation of the NTLMv2 and LMv2 Responses.
ntlmv2Hash
(final String domain, final String user, final byte[] ntlmHash)

Creates the NTLMv2 Hash of the user's password.

private static void
oddParity(final byte[]
The data whose parity bits are to be adjusted for odd parity.
bytes
)

Applies odd parity to the given byte array.

pack-priv static byte[]
RC4(final byte[] value, final byte[] key)

Calculates RC4

private static byte[]
readSecurityBuffer(final byte[] src, final int index)

private static int
readULong(final byte[] src, final int index)

private static int
readUShort(final byte[] src, final int index)

pack-priv static int
rotintlft(final int val, final int numbits)

private static String
stripDotSuffix(final String value)

Strip dot suffix from a name

pack-priv static void
writeULong(final byte[] buffer, final int value, final int offset)

pack-priv static void
writeUShort(final byte[] buffer, final int value, final int offset)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait