java.lang.Object
org.codelibs.jcifs.smb1.NtlmPasswordAuthentication
- All Implemented Interfaces:
Serializable,Principal
This class stores and encrypts NTLM user credentials. The default
credentials are retrieved from the
org.codelibs.jcifs.smb1.smb1.client.domain,
org.codelibs.jcifs.smb1.smb1.client.username, and org.codelibs.jcifs.smb1.smb1.client.password
properties.
Read jCIFS Exceptions and NtlmAuthenticator for related information.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final NtlmPasswordAuthenticationAnonymous credentials instance with empty domain, username, and password. -
Constructor Summary
ConstructorsConstructorDescriptionNtlmPasswordAuthentication(String userInfo) Create an NtlmPasswordAuthentication object from a userinfo string.NtlmPasswordAuthentication(String domain, String username, byte[] challenge, byte[] ansiHash, byte[] unicodeHash) Create an NtlmPasswordAuthentication object with raw password hashes.NtlmPasswordAuthentication(String domain, String username, String password) Create an NtlmPasswordAuthentication object from domain, username, and password. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares twoNtlmPasswordAuthenticationobjects for equality.byte[]getAnsiHash(byte[] challenge) Computes the 24 byte ANSI password hash given the 8 byte server challenge.Returns the domain.static byte[]getLMv2Response(byte[] responseKeyLM, byte[] serverChallenge, byte[] clientChallenge) Creates the LMv2 response for the supplied keys and challenges.static byte[]getLMv2Response(String domain, String user, String password, byte[] challenge, byte[] clientChallenge) Creates the LMv2 response for the supplied information.getName()Return the domain and username in the format:domain\\username.static byte[]getNTLM2Response(byte[] nTOWFv1, byte[] serverChallenge, byte[] clientChallenge) Creates the NTLM2 response for the supplied information.static byte[]getNTLMResponse(String password, byte[] challenge) Generate the Unicode MD4 hash for the password associated with these credentials.static byte[]getNTLMv2Response(byte[] responseKeyNT, byte[] serverChallenge, byte[] clientChallenge, long nanos1601, byte[] targetInfo) Creates the NTLMv2 response for the supplied information.Returns the password in plain text ornullif the raw password hashes were used to construct thisNtlmPasswordAuthenticationobject which will be the case when NTLM HTTP Authentication is used.static byte[]getPreNTLMResponse(String password, byte[] challenge) Generate the ANSI DES hash for the password associated with these credentials.byte[]getSigningKey(byte[] challenge) Returns the signing key for SMB signing.byte[]getUnicodeHash(byte[] challenge) Computes the 24 byte Unicode password hash given the 8 byte server challenge.Returns the username.byte[]getUserSessionKey(byte[] challenge) Returns the effective user session key.inthashCode()Return the upcased username hash code.static byte[]Generates the NTOWFv1 hash for the given password.static byte[]Generates the NTOWFv2 hash for the given domain, username, and password.toString()Return the domain and username in the format:domain\\username.
-
Field Details
-
ANONYMOUS
Anonymous credentials instance with empty domain, username, and password.
-
-
Constructor Details
-
NtlmPasswordAuthentication
Create an NtlmPasswordAuthentication object from a userinfo string.- Parameters:
userInfo- the user information string in the format "domain;user:pass"
-
NtlmPasswordAuthentication
Create an NtlmPasswordAuthentication object from domain, username, and password.- Parameters:
domain- the authentication domainusername- the username to authenticate withpassword- the password to authenticate with
-
NtlmPasswordAuthentication
public NtlmPasswordAuthentication(String domain, String username, byte[] challenge, byte[] ansiHash, byte[] unicodeHash) Create an NtlmPasswordAuthentication object with raw password hashes.- Parameters:
domain- the authentication domainusername- the username to authenticate withchallenge- the server challenge bytesansiHash- the ANSI password hashunicodeHash- the Unicode password hash
-
-
Method Details
-
getPreNTLMResponse
Generate the ANSI DES hash for the password associated with these credentials.- Parameters:
password- the password to hashchallenge- the server challenge bytes- Returns:
- the ANSI DES hash response
-
getNTLMResponse
Generate the Unicode MD4 hash for the password associated with these credentials.- Parameters:
password- the password to hashchallenge- the server challenge bytes- Returns:
- the Unicode MD4 hash response
-
getLMv2Response
public static byte[] getLMv2Response(String domain, String user, String password, byte[] challenge, byte[] clientChallenge) Creates the LMv2 response for the supplied information.- Parameters:
domain- The domain in which the username exists.user- The username.password- The user's password.challenge- The server challenge.clientChallenge- The client challenge (nonce).- Returns:
- the LMv2 response bytes
-
getNTLM2Response
public static byte[] getNTLM2Response(byte[] nTOWFv1, byte[] serverChallenge, byte[] clientChallenge) Creates the NTLM2 response for the supplied information.- Parameters:
nTOWFv1- the NTOWFv1 hashserverChallenge- the server challenge bytesclientChallenge- the client challenge bytes- Returns:
- the NTLM2 response bytes
-
nTOWFv1
Generates the NTOWFv1 hash for the given password.- Parameters:
password- the password to hash- Returns:
- the NTOWFv1 hash bytes
-
nTOWFv2
Generates the NTOWFv2 hash for the given domain, username, and password.- Parameters:
domain- the authentication domainusername- the usernamepassword- the password- Returns:
- the NTOWFv2 hash bytes
-
getLMv2Response
public static byte[] getLMv2Response(byte[] responseKeyLM, byte[] serverChallenge, byte[] clientChallenge) Creates the LMv2 response for the supplied keys and challenges.- Parameters:
responseKeyLM- the LM response keyserverChallenge- the server challenge bytesclientChallenge- the client challenge bytes- Returns:
- the LMv2 response bytes
-
getNTLMv2Response
public static byte[] getNTLMv2Response(byte[] responseKeyNT, byte[] serverChallenge, byte[] clientChallenge, long nanos1601, byte[] targetInfo) Creates the NTLMv2 response for the supplied information.- Parameters:
responseKeyNT- the NT response keyserverChallenge- the server challenge bytesclientChallenge- the client challenge bytesnanos1601- the timestamp in nanoseconds since 1601targetInfo- the target information from the Type 2 message- Returns:
- the NTLMv2 response bytes
-
getDomain
Returns the domain.- Returns:
- the authentication domain
-
getUsername
Returns the username.- Returns:
- the username
-
getPassword
Returns the password in plain text ornullif the raw password hashes were used to construct thisNtlmPasswordAuthenticationobject which will be the case when NTLM HTTP Authentication is used. There is no way to retrieve a users password in plain text unless it is supplied by the user at runtime.- Returns:
- the password or null if using raw hashes
-
getName
Return the domain and username in the format:domain\\username. This is equivalent totoString(). -
getAnsiHash
public byte[] getAnsiHash(byte[] challenge) Computes the 24 byte ANSI password hash given the 8 byte server challenge.- Parameters:
challenge- the server challenge bytes- Returns:
- the ANSI password hash
-
getUnicodeHash
public byte[] getUnicodeHash(byte[] challenge) Computes the 24 byte Unicode password hash given the 8 byte server challenge.- Parameters:
challenge- the server challenge bytes- Returns:
- the Unicode password hash
-
getSigningKey
Returns the signing key for SMB signing.- Parameters:
challenge- the server challenge bytes- Returns:
- the signing key
- Throws:
SmbException- if an error occurs generating the signing key
-
getUserSessionKey
public byte[] getUserSessionKey(byte[] challenge) Returns the effective user session key.- Parameters:
challenge- The server challenge.- Returns:
- A
byte[]containing the effective user session key, used in SMB MAC signing and NTLMSSP signing and sealing.
-
equals
Compares twoNtlmPasswordAuthenticationobjects for equality. TwoNtlmPasswordAuthenticationobjects are equal if their caseless domain and username fields are equal and either both hashes are external and they are equal or both internally supplied passwords are equal. If oneNtlmPasswordAuthenticationobject has external hashes (meaning negotiated via NTLM HTTP Authentication) and the other does not they will not be equal. This is technically not correct however the server 8 byte challage would be required to compute and compare the password hashes but that it not available with this method. -
hashCode
public int hashCode()Return the upcased username hash code. -
toString
Return the domain and username in the format:domain\\username. This is equivalent togetName().
-