Package jcifs.ntlmssp

Class Type3Message

  • All Implemented Interfaces:
    NtlmFlags

    public class Type3Message
    extends NtlmMessage
    Represents an NTLMSSP Type-3 message.
    • Constructor Detail

      • Type3Message

        public Type3Message​(CIFSContext tc)
        Creates a Type-3 message using default values from the current environment.
        Parameters:
        tc - context to use
      • Type3Message

        public Type3Message​(CIFSContext tc,
                            Type2Message type2,
                            String targetName,
                            String password,
                            String domain,
                            String user,
                            String workstation,
                            int flags)
                     throws GeneralSecurityException,
                            CIFSException
        Creates a Type-3 message in response to the given Type-2 message.
        Parameters:
        tc - context to use
        type2 - The Type-2 message which this represents a response to.
        targetName - SPN of the target system, optional
        password - The password to use when constructing the response.
        domain - The domain in which the user has an account.
        user - The username for the authenticating user.
        workstation - The workstation from which authentication is taking place.
        flags -
        Throws:
        GeneralSecurityException
        CIFSException
      • Type3Message

        public Type3Message​(CIFSContext tc,
                            Type2Message type2,
                            String targetName,
                            String password,
                            String domain,
                            String user,
                            String workstation,
                            int flags,
                            boolean nonAnonymous)
                     throws GeneralSecurityException,
                            CIFSException
        Creates a Type-3 message in response to the given Type-2 message.
        Parameters:
        tc - context to use
        type2 - The Type-2 message which this represents a response to.
        targetName - SPN of the target system, optional
        password - The password to use when constructing the response.
        domain - The domain in which the user has an account.
        user - The username for the authenticating user.
        workstation - The workstation from which authentication is taking place.
        flags -
        nonAnonymous - actually perform authentication with empty password
        Throws:
        GeneralSecurityException
        CIFSException
      • Type3Message

        public Type3Message​(CIFSContext tc,
                            Type2Message type2,
                            String targetName,
                            byte[] passwordHash,
                            String domain,
                            String user,
                            String workstation,
                            int flags)
                     throws CIFSException,
                            GeneralSecurityException
        Creates a Type-3 message in response to the given Type-2 message.
        Parameters:
        tc - context to use
        type2 - The Type-2 message which this represents a response to.
        targetName - SPN of the target system, optional
        passwordHash - The NT password hash to use when constructing the response.
        domain - The domain in which the user has an account.
        user - The username for the authenticating user.
        workstation - The workstation from which authentication is taking place.
        flags -
        Throws:
        GeneralSecurityException
        CIFSException
      • Type3Message

        public Type3Message​(CIFSContext tc,
                            Type2Message type2,
                            String targetName,
                            byte[] passwordHash,
                            String password,
                            String domain,
                            String user,
                            String workstation,
                            int flags,
                            boolean nonAnonymous)
                     throws GeneralSecurityException,
                            CIFSException
        Creates a Type-3 message in response to the given Type-2 message.
        Parameters:
        tc - context to use
        type2 - The Type-2 message which this represents a response to.
        targetName - SPN of the target system, optional
        passwordHash - The NT password hash, takes precedence over password (which is no longer required unless legacy LM authentication is needed)
        password - The password to use when constructing the response.
        domain - The domain in which the user has an account.
        user - The username for the authenticating user.
        workstation - The workstation from which authentication is taking place.
        flags -
        nonAnonymous - actually perform authentication with empty password
        Throws:
        GeneralSecurityException
        CIFSException
      • Type3Message

        public Type3Message​(int flags,
                            byte[] lmResponse,
                            byte[] ntResponse,
                            String domain,
                            String user,
                            String workstation)
        Creates a Type-3 message with the specified parameters.
        Parameters:
        flags - The flags to apply to this message.
        lmResponse - The LanManager/LMv2 response.
        ntResponse - The NT/NTLMv2 response.
        domain - The domain in which the user has an account.
        user - The username for the authenticating user.
        workstation - The workstation from which authentication is taking place.
      • Type3Message

        public Type3Message​(byte[] material)
                     throws IOException
        Creates a Type-3 message using the given raw Type-3 material.
        Parameters:
        material - The raw Type-3 material used to construct this message.
        Throws:
        IOException - If an error occurs while parsing the material.
    • Method Detail

      • getDefaultFlags

        public static int getDefaultFlags​(CIFSContext tc)
        Returns the default flags for a generic Type-3 message in the current environment.
        Parameters:
        tc - context to use
        Returns:
        An int containing the default flags.
      • getDefaultFlags

        public static int getDefaultFlags​(CIFSContext tc,
                                          Type2Message type2)
        Returns the default flags for a Type-3 message created in response to the given Type-2 message in the current environment.
        Parameters:
        tc - context to use
        type2 - The Type-2 message.
        Returns:
        An int containing the default flags.
      • getLMResponse

        public byte[] getLMResponse()
        Returns the LanManager/LMv2 response.
        Returns:
        A byte[] containing the LanManager response.
      • setLMResponse

        public void setLMResponse​(byte[] lmResponse)
        Sets the LanManager/LMv2 response for this message.
        Parameters:
        lmResponse - The LanManager response.
      • getNTResponse

        public byte[] getNTResponse()
        Returns the NT/NTLMv2 response.
        Returns:
        A byte[] containing the NT/NTLMv2 response.
      • setNTResponse

        public void setNTResponse​(byte[] ntResponse)
        Sets the NT/NTLMv2 response for this message.
        Parameters:
        ntResponse - The NT/NTLMv2 response.
      • getDomain

        public String getDomain()
        Returns the domain in which the user has an account.
        Returns:
        A String containing the domain for the user.
      • setDomain

        public void setDomain​(String domain)
        Sets the domain for this message.
        Parameters:
        domain - The domain.
      • getUser

        public String getUser()
        Returns the username for the authenticating user.
        Returns:
        A String containing the user for this message.
      • setUser

        public void setUser​(String user)
        Sets the user for this message.
        Parameters:
        user - The user.
      • getWorkstation

        public String getWorkstation()
        Returns the workstation from which authentication is being performed.
        Returns:
        A String containing the workstation.
      • setWorkstation

        public void setWorkstation​(String workstation)
        Sets the workstation for this message.
        Parameters:
        workstation - The workstation.
      • getMasterKey

        public byte[] getMasterKey()
        The real session key if the regular session key is actually the encrypted version used for key exchange.
        Returns:
        A byte[] containing the session key.
      • getEncryptedSessionKey

        public byte[] getEncryptedSessionKey()
        Returns the session key. This is the encrypted session key included in the message, if the actual session key is desired use getMasterKey() instead.
        Returns:
        A byte[] containing the encrypted session key.
      • setEncryptedSessionKey

        public void setEncryptedSessionKey​(byte[] sessionKey)
        Sets the session key.
        Parameters:
        sessionKey - The session key.
      • getMic

        public byte[] getMic()
        Returns:
        A byte[] containing the message integrity code.
      • setMic

        public void setMic​(byte[] mic)
        Parameters:
        mic - NTLM mic to set (16 bytes)
      • isMICRequired

        public boolean isMICRequired()
        Returns:
        whether a MIC should be calulated
      • toByteArray

        public byte[] toByteArray()
                           throws IOException
        Description copied from class: NtlmMessage
        Returns the raw byte representation of this message.
        Specified by:
        toByteArray in class NtlmMessage
        Returns:
        A byte[] containing the raw message material.
        Throws:
        IOException
      • getLMResponse

        public static byte[] getLMResponse​(CIFSContext tc,
                                           Type2Message type2,
                                           String password)
                                    throws GeneralSecurityException
        Constructs the LanManager response to the given Type-2 message using the supplied password.
        Parameters:
        tc - context to use
        type2 - The Type-2 message.
        password - The password.
        Returns:
        A byte[] containing the LanManager response.
        Throws:
        GeneralSecurityException
      • getNTLMv2Response

        public static byte[] getNTLMv2Response​(CIFSContext tc,
                                               Type2Message type2,
                                               byte[] responseKeyNT,
                                               byte[] clientChallenge,
                                               byte[] clientChallengeInfo,
                                               long ts)
        Parameters:
        tc - context to use
        type2 - The Type-2 message.
        responseKeyNT -
        clientChallenge -
        clientChallengeInfo -
        ts - timestamp (nanos since 1601)
        Returns:
        A byte[] containing the NTLMv2 response.
      • getNTResponse

        public static byte[] getNTResponse​(CIFSContext tc,
                                           Type2Message type2,
                                           String password)
                                    throws GeneralSecurityException
        Constructs the NT response to the given Type-2 message using the supplied password.
        Parameters:
        tc - context to use
        type2 - The Type-2 message.
        password - The password.
        Returns:
        A byte[] containing the NT response.
        Throws:
        GeneralSecurityException
      • getNTResponse

        public static byte[] getNTResponse​(CIFSContext tc,
                                           Type2Message type2,
                                           byte[] passwordHash)
                                    throws GeneralSecurityException
        Constructs the NT response to the given Type-2 message using the supplied password.
        Parameters:
        tc - context to use
        type2 - The Type-2 message.
        passwordHash - The NT password hash.
        Returns:
        A byte[] containing the NT response.
        Throws:
        GeneralSecurityException