java.lang.Object
org.codelibs.jcifs.smb.impl.NtlmContext
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionstatic org.bouncycastle.asn1.ASN1ObjectIdentifierThe NTLMSSP OID (1.3.6.1.4.1.311.2.2.10) used in SPNEGO negotiation. -
Constructor Summary
ConstructorsConstructorDescriptionNtlmContext(CIFSContext tc, NtlmPasswordAuthenticator auth, boolean doSigning) Creates a new NTLM security context with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]calculateMIC(byte[] data) Calculates a Message Integrity Code (MIC) for the given data.protected Type3MessageCreates a Type 3 message based on the received Type 2 message.voiddispose()Disposes of the security context and releases any associated resources.intgetFlags()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 voidinitSessionSecurity(byte[] mk) Initializes session security keys for signing and sealing.booleanChecks whether the security context is established.booleanChecks whether Message Integrity Code (MIC) is available for use.booleanisPreferredMech(org.bouncycastle.asn1.ASN1ObjectIdentifier mechanism) Checks whether the specified mechanism is the preferred mechanism.booleanisSupported(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.voidsetTargetName(String targetName) Sets the target server's Service Principal Name (SPN).booleanChecks whether this mechanism supports message integrity.toString()voidverifyMIC(byte[] data, byte[] mic) Verifies a Message Integrity Code (MIC) for the given data.
-
Field Details
-
NTLMSSP_OID
public static org.bouncycastle.asn1.ASN1ObjectIdentifier NTLMSSP_OIDThe NTLMSSP OID (1.3.6.1.4.1.311.2.2.10) used in SPNEGO negotiation.
-
-
Constructor Details
-
NtlmContext
Creates a new NTLM security context with the specified parameters.- Parameters:
tc- context to useauth- credentialsdoSigning- whether signing is requested
-
-
Method Details
-
getSupportedMechs
public org.bouncycastle.asn1.ASN1ObjectIdentifier[] getSupportedMechs()Gets the array of supported security mechanism OIDs.- Specified by:
getSupportedMechsin interfaceSSPContext- Returns:
- array of supported mechanism OIDs
- See Also:
-
toString
-
getFlags
public int getFlags()Gets the negotiated context flags.- Specified by:
getFlagsin interfaceSSPContext- Returns:
- context flags
- See Also:
-
isSupported
public boolean isSupported(org.bouncycastle.asn1.ASN1ObjectIdentifier mechanism) Checks whether the specified security mechanism is supported.- Specified by:
isSupportedin interfaceSSPContext- 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:
isPreferredMechin interfaceSSPContext- Parameters:
mechanism- the selected mechanism OID- Returns:
- whether the specified mechanism is preferred
- See Also:
-
isEstablished
public boolean isEstablished()Description copied from interface:SSPContextChecks whether the security context is established.- Specified by:
isEstablishedin interfaceSSPContext- 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:SSPContextGets the signing key for the session.- Specified by:
getSigningKeyin interfaceSSPContext- Returns:
- the signing key for the session
-
getNetbiosName
Description copied from interface:SSPContextGets the NetBIOS name of the remote endpoint.- Specified by:
getNetbiosNamein interfaceSSPContext- Returns:
- the name of the remote endpoint
-
setTargetName
Sets the target server's Service Principal Name (SPN).- Parameters:
targetName- the target's SPN
-
initSecContext
Description copied from interface:SSPContextInitializes the security context with the given token.- Specified by:
initSecContextin interfaceSSPContext- Parameters:
token- the input token bytesoffset- offset into the token arraylen- length of token data- Returns:
- result token
- Throws:
SmbException- if an SMB protocol error occurs
-
makeAuthenticate
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 occursCIFSException- 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:SSPContextChecks whether this mechanism supports message integrity.- Specified by:
supportsIntegrityin interfaceSSPContext- Returns:
- whether this mechanisms supports integrity
-
isMICAvailable
public boolean isMICAvailable()Description copied from interface:SSPContextChecks whether Message Integrity Code (MIC) is available for use.- Specified by:
isMICAvailablein interfaceSSPContext- Returns:
- whether MIC can be used
-
calculateMIC
Description copied from interface:SSPContextCalculates a Message Integrity Code (MIC) for the given data.- Specified by:
calculateMICin interfaceSSPContext- Parameters:
data- the data to calculate MIC for- Returns:
- MIC
- Throws:
CIFSException- if an error occurs calculating the MIC
-
verifyMIC
Description copied from interface:SSPContextVerifies a Message Integrity Code (MIC) for the given data.- Specified by:
verifyMICin interfaceSSPContext- Parameters:
data- the data to verifymic- the MIC to verify against- Throws:
CIFSException- if the MIC verification fails or an error occurs
-
dispose
Disposes of the security context and releases any associated resources.- Specified by:
disposein interfaceSSPContext- Throws:
SmbException- See Also:
-