Module jcifs

Class NtlmContext

java.lang.Object
org.codelibs.jcifs.smb.impl.NtlmContext
All Implemented Interfaces:
SSPContext

public class NtlmContext extends Object implements SSPContext
For initiating NTLM authentication (including NTLMv2). If you want to add NTLMv2 authentication support to something this is what you want to use. See the code for details. Note that JCIFS does not implement the acceptor side of NTLM authentication.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static org.bouncycastle.asn1.ASN1ObjectIdentifier
    The NTLMSSP OID (1.3.6.1.4.1.311.2.2.10) used in SPNEGO negotiation.
  • Constructor Summary

    Constructors
    Constructor
    Description
    NtlmContext(CIFSContext tc, NtlmPasswordAuthenticator auth, boolean doSigning)
    Creates a new NTLM security context with the specified parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    calculateMIC(byte[] data)
    Calculates a Message Integrity Code (MIC) for the given data.
    protected Type3Message
    Creates a Type 3 message based on the received Type 2 message.
    void
    Disposes of the security context and releases any associated resources.
    int
    Gets the negotiated context flags.
    Gets the NetBIOS name of the remote endpoint.
    byte[]
    Gets the server's NTLM challenge bytes.
    byte[]
    Gets the signing key for the session.
    org.bouncycastle.asn1.ASN1ObjectIdentifier[]
    Gets the array of supported security mechanism OIDs.
    byte[]
    initSecContext(byte[] token, int offset, int len)
    Initializes the security context with the given token.
    protected void
    Initializes session security keys for signing and sealing.
    boolean
    Checks whether the security context is established.
    boolean
    Checks whether Message Integrity Code (MIC) is available for use.
    boolean
    isPreferredMech(org.bouncycastle.asn1.ASN1ObjectIdentifier mechanism)
    Checks whether the specified mechanism is the preferred mechanism.
    boolean
    isSupported(org.bouncycastle.asn1.ASN1ObjectIdentifier mechanism)
    Checks whether the specified security mechanism is supported.
    protected byte[]
    makeAuthenticate(byte[] token)
    Creates a Type 3 (authentication) message in response to a Type 2 (challenge) message.
    protected byte[]
    makeNegotiate(byte[] token)
    Creates a Type 1 (negotiation) message to initiate NTLM authentication.
    void
    setTargetName(String targetName)
    Sets the target server's Service Principal Name (SPN).
    boolean
    Checks whether this mechanism supports message integrity.
     
    void
    verifyMIC(byte[] data, byte[] mic)
    Verifies a Message Integrity Code (MIC) for the given data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • NTLMSSP_OID

      public static org.bouncycastle.asn1.ASN1ObjectIdentifier NTLMSSP_OID
      The NTLMSSP OID (1.3.6.1.4.1.311.2.2.10) used in SPNEGO negotiation.
  • Constructor Details

    • NtlmContext

      public NtlmContext(CIFSContext tc, NtlmPasswordAuthenticator auth, boolean doSigning)
      Creates a new NTLM security context with the specified parameters.
      Parameters:
      tc - context to use
      auth - credentials
      doSigning - whether signing is requested
  • Method Details

    • getSupportedMechs

      public org.bouncycastle.asn1.ASN1ObjectIdentifier[] getSupportedMechs()
      Gets the array of supported security mechanism OIDs.
      Specified by:
      getSupportedMechs in interface SSPContext
      Returns:
      array of supported mechanism OIDs
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getFlags

      public int getFlags()
      Gets the negotiated context flags.
      Specified by:
      getFlags in interface SSPContext
      Returns:
      context flags
      See Also:
    • isSupported

      public boolean isSupported(org.bouncycastle.asn1.ASN1ObjectIdentifier mechanism)
      Checks whether the specified security mechanism is supported.
      Specified by:
      isSupported in interface SSPContext
      Parameters:
      mechanism - the security mechanism OID to check
      Returns:
      whether the specified mechanism is supported
      See Also:
    • isPreferredMech

      public boolean isPreferredMech(org.bouncycastle.asn1.ASN1ObjectIdentifier mechanism)
      Checks whether the specified mechanism is the preferred mechanism.
      Specified by:
      isPreferredMech in interface SSPContext
      Parameters:
      mechanism - the selected mechanism OID
      Returns:
      whether the specified mechanism is preferred
      See Also:
    • isEstablished

      public boolean isEstablished()
      Description copied from interface: SSPContext
      Checks whether the security context is established.
      Specified by:
      isEstablished in interface SSPContext
      Returns:
      whether the context is established
    • getServerChallenge

      public byte[] getServerChallenge()
      Gets the server's NTLM challenge bytes.
      Returns:
      the server's challenge
    • getSigningKey

      public byte[] getSigningKey()
      Description copied from interface: SSPContext
      Gets the signing key for the session.
      Specified by:
      getSigningKey in interface SSPContext
      Returns:
      the signing key for the session
    • getNetbiosName

      public String getNetbiosName()
      Description copied from interface: SSPContext
      Gets the NetBIOS name of the remote endpoint.
      Specified by:
      getNetbiosName in interface SSPContext
      Returns:
      the name of the remote endpoint
    • setTargetName

      public void setTargetName(String targetName)
      Sets the target server's Service Principal Name (SPN).
      Parameters:
      targetName - the target's SPN
    • initSecContext

      public byte[] initSecContext(byte[] token, int offset, int len) throws SmbException
      Description copied from interface: SSPContext
      Initializes the security context with the given token.
      Specified by:
      initSecContext in interface SSPContext
      Parameters:
      token - the input token bytes
      offset - offset into the token array
      len - length of token data
      Returns:
      result token
      Throws:
      SmbException - if an SMB protocol error occurs
    • makeAuthenticate

      protected byte[] makeAuthenticate(byte[] token) throws SmbException
      Creates a Type 3 (authentication) message in response to a Type 2 (challenge) message.
      Parameters:
      token - the Type 2 message bytes
      Returns:
      the Type 3 message bytes
      Throws:
      SmbException - if an error occurs during message creation
    • createType3Message

      protected Type3Message createType3Message(Type2Message msg2) throws GeneralSecurityException, CIFSException
      Creates a Type 3 message based on the received Type 2 message.
      Parameters:
      msg2 - the Type 2 message received from the server
      Returns:
      the Type 3 message to send to the server
      Throws:
      GeneralSecurityException - if a cryptographic error occurs
      CIFSException - if a CIFS protocol error occurs
    • makeNegotiate

      protected byte[] makeNegotiate(byte[] token)
      Creates a Type 1 (negotiation) message to initiate NTLM authentication.
      Parameters:
      token - unused in this implementation
      Returns:
      the Type 1 message bytes
    • initSessionSecurity

      protected void initSessionSecurity(byte[] mk)
      Initializes session security keys for signing and sealing.
      Parameters:
      mk - the master key to derive session keys from
    • supportsIntegrity

      public boolean supportsIntegrity()
      Description copied from interface: SSPContext
      Checks whether this mechanism supports message integrity.
      Specified by:
      supportsIntegrity in interface SSPContext
      Returns:
      whether this mechanisms supports integrity
    • isMICAvailable

      public boolean isMICAvailable()
      Description copied from interface: SSPContext
      Checks whether Message Integrity Code (MIC) is available for use.
      Specified by:
      isMICAvailable in interface SSPContext
      Returns:
      whether MIC can be used
    • calculateMIC

      public byte[] calculateMIC(byte[] data) throws CIFSException
      Description copied from interface: SSPContext
      Calculates a Message Integrity Code (MIC) for the given data.
      Specified by:
      calculateMIC in interface SSPContext
      Parameters:
      data - the data to calculate MIC for
      Returns:
      MIC
      Throws:
      CIFSException - if an error occurs calculating the MIC
    • verifyMIC

      public void verifyMIC(byte[] data, byte[] mic) throws CIFSException
      Description copied from interface: SSPContext
      Verifies a Message Integrity Code (MIC) for the given data.
      Specified by:
      verifyMIC in interface SSPContext
      Parameters:
      data - the data to verify
      mic - the MIC to verify against
      Throws:
      CIFSException - if the MIC verification fails or an error occurs
    • dispose

      public void dispose() throws SmbException
      Disposes of the security context and releases any associated resources.
      Specified by:
      dispose in interface SSPContext
      Throws:
      SmbException
      See Also: