Class NTLMUtilities
- java.lang.Object
-
- org.apache.mina.proxy.handlers.http.ntlm.NTLMUtilities
-
- All Implemented Interfaces:
NTLMConstants
public class NTLMUtilities extends Object implements NTLMConstants
NTLMUtilities.java - NTLM functions used for authentication and unit testing.- Since:
- MINA 2.0.0-M3
- Author:
- Apache MINA Project
-
-
Field Summary
-
Fields inherited from interface org.apache.mina.proxy.handlers.http.ntlm.NTLMConstants
DEFAULT_FLAGS, DEFAULT_OS_VERSION, FLAG_NEGOTIATE_128_BIT_ENCRYPTION, FLAG_NEGOTIATE_56_BIT_ENCRYPTION, FLAG_NEGOTIATE_ALWAYS_SIGN, FLAG_NEGOTIATE_ANONYMOUS, FLAG_NEGOTIATE_DATAGRAM_STYLE, FLAG_NEGOTIATE_DOMAIN_SUPPLIED, FLAG_NEGOTIATE_KEY_EXCHANGE, FLAG_NEGOTIATE_LAN_MANAGER_KEY, FLAG_NEGOTIATE_LOCAL_CALL, FLAG_NEGOTIATE_NTLM, FLAG_NEGOTIATE_NTLM2, FLAG_NEGOTIATE_OEM, FLAG_NEGOTIATE_SEAL, FLAG_NEGOTIATE_SIGN, FLAG_NEGOTIATE_TARGET_INFO, FLAG_NEGOTIATE_UNICODE, FLAG_NEGOTIATE_WORKSTATION_SUPPLIED, FLAG_REQUEST_SERVER_AUTH_REALM, FLAG_TARGET_TYPE_DOMAIN, FLAG_TARGET_TYPE_SERVER, FLAG_TARGET_TYPE_SHARE, FLAG_UNIDENTIFIED_1, FLAG_UNIDENTIFIED_10, FLAG_UNIDENTIFIED_11, FLAG_UNIDENTIFIED_2, FLAG_UNIDENTIFIED_3, FLAG_UNIDENTIFIED_4, FLAG_UNIDENTIFIED_5, FLAG_UNIDENTIFIED_6, FLAG_UNIDENTIFIED_7, FLAG_UNIDENTIFIED_8, FLAG_UNIDENTIFIED_9, MESSAGE_TYPE_1, MESSAGE_TYPE_2, MESSAGE_TYPE_3, NTLM_SIGNATURE, TARGET_INFORMATION_SUBBLOCK_DNS_DOMAIN_NAME_TYPE, TARGET_INFORMATION_SUBBLOCK_DOMAIN_TYPE, TARGET_INFORMATION_SUBBLOCK_FQDNS_HOSTNAME_TYPE, TARGET_INFORMATION_SUBBLOCK_PARENT_DNS_DOMAIN_NAME_TYPE, TARGET_INFORMATION_SUBBLOCK_SERVER_TYPE, TARGET_INFORMATION_SUBBLOCK_TERMINATOR_TYPE
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]createType1Message(String workStation, String domain, Integer customFlags, byte[] osVersion)see http://davenport.sourceforge.net/ntlm.html#theType1Messagestatic byte[]createType3Message(String user, String password, byte[] challenge, String target, String workstation, Integer serverFlags, byte[] osVersion)static byte[]extractChallengeFromType2Message(byte[] msg)Extracts the NTLM challenge from the type 2 message as an 8 byte array.static intextractFlagsFromType2Message(byte[] msg)Extracts the NTLM flags from the type 2 message.static byte[]extractTargetInfoFromType2Message(byte[] msg, Integer msgFlags)Extracts the target information block from the type 2 message.static StringextractTargetNameFromType2Message(byte[] msg, Integer msgFlags)Extracts the target name from the type 2 message.static byte[]getOsVersion()Tries to return a valid OS version on Windows systems.static voidprintTargetInformationBlockFromType2Message(byte[] msg, Integer msgFlags, PrintWriter out)Prints to thePrintWriterthe target information block extracted from the type 2 message.static byte[]readSecurityBufferTarget(byte[] msg, int securityBufferOffset)Reads the byte array described by the security buffer stored at thesecurityBufferOffsetoffset.static voidwriteOSVersion(byte majorVersion, byte minorVersion, short buildNumber, byte[] b, int offset)Writes the Windows OS version passed in as three byte values (majorVersion.minorVersion.buildNumber) to the given byte array atoffset.static byte[]writeSecurityBuffer(short length, int bufferOffset)static voidwriteSecurityBuffer(short length, short allocated, int bufferOffset, byte[] b, int offset)Writes a security buffer to the given arraybat offsetoffset.static intwriteSecurityBufferAndUpdatePointer(ByteArrayOutputStream baos, short len, int pointer)Writes a security buffer and returns the pointer of the position where to write the next security buffer.
-
-
-
Method Detail
-
writeSecurityBuffer
public static final byte[] writeSecurityBuffer(short length, int bufferOffset)- Parameters:
length- The length of the security bufferbufferOffset- The offset in the security buffer- Returns:
- Th created buffer
- See Also:
writeSecurityBuffer(short, short, int, byte[], int)
-
writeSecurityBuffer
public static final void writeSecurityBuffer(short length, short allocated, int bufferOffset, byte[] b, int offset)Writes a security buffer to the given arraybat offsetoffset. A security buffer defines a pointer to an area in the data that defines some data with a variable length. This allows to have a semi-fixed length header thus making a little bit easier the decoding process in the NTLM protocol.- Parameters:
length- the length of the security bufferallocated- the allocated space for the security buffer (should be greater or equal tolengthbufferOffset- the offset from the main array where the currently defined security buffer will be writtenb- the buffer in which we write the security bufferoffset- the offset at which to write to the b buffer
-
writeOSVersion
public static final void writeOSVersion(byte majorVersion, byte minorVersion, short buildNumber, byte[] b, int offset)Writes the Windows OS version passed in as three byte values (majorVersion.minorVersion.buildNumber) to the given byte array atoffset.- Parameters:
majorVersion- the major version numberminorVersion- the minor version numberbuildNumber- the build numberb- the target byte arrayoffset- the offset at which to write in the array
-
getOsVersion
public static final byte[] getOsVersion()
Tries to return a valid OS version on Windows systems. If it fails to do so or if we're running on another OS then a fake Windows XP OS version is returned because the protocol uses it.- Returns:
- a NTLM OS version byte buffer
-
createType1Message
public static final byte[] createType1Message(String workStation, String domain, Integer customFlags, byte[] osVersion)
see http://davenport.sourceforge.net/ntlm.html#theType1Message- Parameters:
workStation- the workstation namedomain- the domain namecustomFlags- custom flags, if null thenNTLMConstants.DEFAULT_CONSTANTSis usedosVersion- the os version of the client, if null thenNTLMConstants.DEFAULT_OS_VERSIONis used- Returns:
- the type 1 message
-
writeSecurityBufferAndUpdatePointer
public static final int writeSecurityBufferAndUpdatePointer(ByteArrayOutputStream baos, short len, int pointer) throws IOException
Writes a security buffer and returns the pointer of the position where to write the next security buffer.- Parameters:
baos- the stream where the security buffer is writtenlen- the length of the security bufferpointer- the position where the security buffer can be written- Returns:
- the position where the next security buffer will be written
- Throws:
IOException- if writing to the ByteArrayOutputStream fails
-
extractChallengeFromType2Message
public static final byte[] extractChallengeFromType2Message(byte[] msg)
Extracts the NTLM challenge from the type 2 message as an 8 byte array.- Parameters:
msg- the type 2 message byte array- Returns:
- the challenge
-
extractFlagsFromType2Message
public static final int extractFlagsFromType2Message(byte[] msg)
Extracts the NTLM flags from the type 2 message.- Parameters:
msg- the type 2 message byte array- Returns:
- the proxy flags as an int
-
readSecurityBufferTarget
public static final byte[] readSecurityBufferTarget(byte[] msg, int securityBufferOffset)Reads the byte array described by the security buffer stored at thesecurityBufferOffsetoffset.- Parameters:
msg- the message where to read the security buffer and it's valuesecurityBufferOffset- the offset at which to read the security buffer- Returns:
- a new byte array holding the data pointed by the security buffer
-
extractTargetNameFromType2Message
public static final String extractTargetNameFromType2Message(byte[] msg, Integer msgFlags) throws UnsupportedEncodingException
Extracts the target name from the type 2 message.- Parameters:
msg- the type 2 message byte arraymsgFlags- the flags if null then flags are extracted from the type 2 message- Returns:
- the target name
- Throws:
UnsupportedEncodingException- if unable to use the needed UTF-16LE or ASCII charsets
-
extractTargetInfoFromType2Message
public static final byte[] extractTargetInfoFromType2Message(byte[] msg, Integer msgFlags)Extracts the target information block from the type 2 message.- Parameters:
msg- the type 2 message byte arraymsgFlags- the flags if null then flags are extracted from the type 2 message- Returns:
- the target info
-
printTargetInformationBlockFromType2Message
public static final void printTargetInformationBlockFromType2Message(byte[] msg, Integer msgFlags, PrintWriter out) throws UnsupportedEncodingExceptionPrints to thePrintWriterthe target information block extracted from the type 2 message.- Parameters:
msg- the type 2 messagemsgFlags- the flags if null then flags are extracted from the type 2 messageout- the output target for the information- Throws:
UnsupportedEncodingException- if unable to use the needed UTF-16LE or ASCII charsets
-
createType3Message
public static final byte[] createType3Message(String user, String password, byte[] challenge, String target, String workstation, Integer serverFlags, byte[] osVersion)
- Parameters:
user- the user namepassword- the user passwordchallenge- the challenge responsetarget- the target nameworkstation- the client workstation's nameserverFlags- the flags set by the clientosVersion- the os version of the client- Returns:
- the type 3 message
- See Also:
- NTLM message type
-
-