org.apache.mina.proxy.handlers.http.ntlm
Class NTLMUtilities

java.lang.Object
  extended by 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
Version:
$Rev: 685703 $, $Date: 2008-08-14 00:14:47 +0200 (Do, 14 Aug 2008) $
Author:
The Apache MINA Project (dev@mina.apache.org)

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
 
Constructor Summary
NTLMUtilities()
           
 
Method Summary
static byte[] createType1Message(String workStation, String domain, Integer customFlags, byte[] osVersion)
          see http://davenport.sourceforge.net/ntlm.html#theType1Message
static byte[] createType3Message(String user, String password, byte[] challenge, String target, String workstation, Integer serverFlags, byte[] osVersion)
          http://davenport.sourceforge.net/ntlm.html#theType3Message
static byte[] extractChallengeFromType2Message(byte[] msg)
           
static int extractFlagsFromType2Message(byte[] msg)
           
static byte[] extractTargetInfoFromType2Message(byte[] msg, Integer msgFlags)
           
static String extractTargetNameFromType2Message(byte[] msg, Integer msgFlags)
           
static byte[] getOsVersion()
          Tries to return a valid Os version on windows systems.
static void printTargetInformationBlockFromType2Message(byte[] msg, Integer msgFlags, PrintWriter out)
           
static void writeOSVersion(byte majorVersion, byte minorVersion, short buildNumber, byte[] b, int offset)
           
static byte[] writeSecurityBuffer(short length, int bufferOffset)
           
static void writeSecurityBuffer(short length, short allocated, int bufferOffset, byte[] b, int offset)
          Writes a security buffer to the given array b at offset offset.
static int writeSecurityBufferAndUpdatePointer(ByteArrayOutputStream baos, short len, int pointer)
          Write a security buffer and returns the pointer of the position where to write the next security buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NTLMUtilities

public NTLMUtilities()
Method Detail

writeSecurityBuffer

public static final byte[] writeSecurityBuffer(short length,
                                               int bufferOffset)
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 array b at offset offset.

Parameters:
length - the length of the security buffer
allocated - the allocated space for the security buffer (should be greater or equal to length
bufferOffset - the offset since the beginning of the b buffer where the buffer iswritten
b - the buffer in which we write the security buffer
offset - the offset at which to write to the buffer

writeOSVersion

public static final void writeOSVersion(byte majorVersion,
                                        byte minorVersion,
                                        short buildNumber,
                                        byte[] b,
                                        int offset)

getOsVersion

public static final byte[] getOsVersion()
Tries to return a valid Os version on windows systems.


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 name
domain - the domain name
customFlags - custom flags, if null then NTLMConstants.DEFAULT_CONSTANTS is used
osVersion - the os version of the client, if null then NTLMConstants.DEFAULT_OS_VERSION is used
Returns:

writeSecurityBufferAndUpdatePointer

public static final int writeSecurityBufferAndUpdatePointer(ByteArrayOutputStream baos,
                                                            short len,
                                                            int pointer)
                                                     throws IOException
Write 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 written
len - the length of the security buffer
pointer - the position where the security buffer can be written
Returns:
the position where the next security buffer will be written
Throws:
IOException

extractChallengeFromType2Message

public static final byte[] extractChallengeFromType2Message(byte[] msg)

extractFlagsFromType2Message

public static final int extractFlagsFromType2Message(byte[] msg)

extractTargetNameFromType2Message

public static final String extractTargetNameFromType2Message(byte[] msg,
                                                             Integer msgFlags)
                                                      throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

extractTargetInfoFromType2Message

public static final byte[] extractTargetInfoFromType2Message(byte[] msg,
                                                             Integer msgFlags)

printTargetInformationBlockFromType2Message

public static final void printTargetInformationBlockFromType2Message(byte[] msg,
                                                                     Integer msgFlags,
                                                                     PrintWriter out)
                                                              throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

createType3Message

public static final byte[] createType3Message(String user,
                                              String password,
                                              byte[] challenge,
                                              String target,
                                              String workstation,
                                              Integer serverFlags,
                                              byte[] osVersion)
http://davenport.sourceforge.net/ntlm.html#theType3Message



Copyright © 2004-2010 Apache MINA Project. All Rights Reserved.