138c8a9a5SSteve French /* SPDX-License-Identifier: LGPL-2.1 */ 238c8a9a5SSteve French /* 338c8a9a5SSteve French * 438c8a9a5SSteve French * Copyright (c) International Business Machines Corp., 2002,2007 538c8a9a5SSteve French * Author(s): Steve French (sfrench@us.ibm.com) 638c8a9a5SSteve French * 738c8a9a5SSteve French */ 838c8a9a5SSteve French 938c8a9a5SSteve French #define NTLMSSP_SIGNATURE "NTLMSSP" 1038c8a9a5SSteve French /* Message Types */ 1138c8a9a5SSteve French #define NtLmNegotiate cpu_to_le32(1) 1238c8a9a5SSteve French #define NtLmChallenge cpu_to_le32(2) 1338c8a9a5SSteve French #define NtLmAuthenticate cpu_to_le32(3) 1438c8a9a5SSteve French #define UnknownMessage cpu_to_le32(8) 1538c8a9a5SSteve French 1638c8a9a5SSteve French /* Negotiate Flags */ 1738c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_UNICODE 0x01 /* Text strings are unicode */ 1838c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_OEM 0x02 /* Text strings are in OEM */ 1938c8a9a5SSteve French #define NTLMSSP_REQUEST_TARGET 0x04 /* Srv returns its auth realm */ 2038c8a9a5SSteve French /* define reserved9 0x08 */ 2138c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_SIGN 0x0010 /* Request signing capability */ 2238c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_SEAL 0x0020 /* Request confidentiality */ 2338c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_DGRAM 0x0040 2438c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_LM_KEY 0x0080 /* Use LM session key */ 2538c8a9a5SSteve French /* defined reserved 8 0x0100 */ 2638c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_NTLM 0x0200 /* NTLM authentication */ 2738c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_NT_ONLY 0x0400 /* Lanman not allowed */ 2838c8a9a5SSteve French #define NTLMSSP_ANONYMOUS 0x0800 2938c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED 0x1000 /* reserved6 */ 3038c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED 0x2000 3138c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_LOCAL_CALL 0x4000 /* client/server same machine */ 3238c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x8000 /* Sign. All security levels */ 3338c8a9a5SSteve French #define NTLMSSP_TARGET_TYPE_DOMAIN 0x10000 3438c8a9a5SSteve French #define NTLMSSP_TARGET_TYPE_SERVER 0x20000 3538c8a9a5SSteve French #define NTLMSSP_TARGET_TYPE_SHARE 0x40000 3638c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_EXTENDED_SEC 0x80000 /* NB:not related to NTLMv2 pwd*/ 3738c8a9a5SSteve French /* #define NTLMSSP_REQUEST_INIT_RESP 0x100000 */ 3838c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_IDENTIFY 0x100000 3938c8a9a5SSteve French #define NTLMSSP_REQUEST_ACCEPT_RESP 0x200000 /* reserved5 */ 4038c8a9a5SSteve French #define NTLMSSP_REQUEST_NON_NT_KEY 0x400000 4138c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_TARGET_INFO 0x800000 4238c8a9a5SSteve French /* #define reserved4 0x1000000 */ 4338c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_VERSION 0x2000000 /* we only set for SMB2+ */ 4438c8a9a5SSteve French /* #define reserved3 0x4000000 */ 4538c8a9a5SSteve French /* #define reserved2 0x8000000 */ 4638c8a9a5SSteve French /* #define reserved1 0x10000000 */ 4738c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_128 0x20000000 4838c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_KEY_XCH 0x40000000 4938c8a9a5SSteve French #define NTLMSSP_NEGOTIATE_56 0x80000000 5038c8a9a5SSteve French 5138c8a9a5SSteve French /* Define AV Pair Field IDs */ 5238c8a9a5SSteve French enum av_field_type { 5338c8a9a5SSteve French NTLMSSP_AV_EOL = 0, 5438c8a9a5SSteve French NTLMSSP_AV_NB_COMPUTER_NAME, 5538c8a9a5SSteve French NTLMSSP_AV_NB_DOMAIN_NAME, 5638c8a9a5SSteve French NTLMSSP_AV_DNS_COMPUTER_NAME, 5738c8a9a5SSteve French NTLMSSP_AV_DNS_DOMAIN_NAME, 5838c8a9a5SSteve French NTLMSSP_AV_DNS_TREE_NAME, 5938c8a9a5SSteve French NTLMSSP_AV_FLAGS, 6038c8a9a5SSteve French NTLMSSP_AV_TIMESTAMP, 6138c8a9a5SSteve French NTLMSSP_AV_RESTRICTION, 6238c8a9a5SSteve French NTLMSSP_AV_TARGET_NAME, 6338c8a9a5SSteve French NTLMSSP_AV_CHANNEL_BINDINGS 6438c8a9a5SSteve French }; 6538c8a9a5SSteve French 6638c8a9a5SSteve French /* Although typedefs are not commonly used for structure definitions */ 6738c8a9a5SSteve French /* in the Linux kernel, in this particular case they are useful */ 6838c8a9a5SSteve French /* to more closely match the standards document for NTLMSSP from */ 6938c8a9a5SSteve French /* OpenGroup and to make the code more closely match the standard in */ 7038c8a9a5SSteve French /* appearance */ 7138c8a9a5SSteve French 7238c8a9a5SSteve French typedef struct _SECURITY_BUFFER { 7338c8a9a5SSteve French __le16 Length; 7438c8a9a5SSteve French __le16 MaximumLength; 7538c8a9a5SSteve French __le32 BufferOffset; /* offset to buffer */ 7638c8a9a5SSteve French } __attribute__((packed)) SECURITY_BUFFER; 7738c8a9a5SSteve French 7838c8a9a5SSteve French typedef struct _NEGOTIATE_MESSAGE { 7938c8a9a5SSteve French __u8 Signature[sizeof(NTLMSSP_SIGNATURE)]; 8038c8a9a5SSteve French __le32 MessageType; /* NtLmNegotiate = 1 */ 8138c8a9a5SSteve French __le32 NegotiateFlags; 8238c8a9a5SSteve French SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */ 8338c8a9a5SSteve French SECURITY_BUFFER WorkstationName; /* RFC 1001 and ASCII */ 8438c8a9a5SSteve French /* SECURITY_BUFFER for version info not present since we 8538c8a9a5SSteve French do not set the version is present flag */ 8638c8a9a5SSteve French char DomainString[]; 8738c8a9a5SSteve French /* followed by WorkstationString */ 8838c8a9a5SSteve French } __attribute__((packed)) NEGOTIATE_MESSAGE, *PNEGOTIATE_MESSAGE; 8938c8a9a5SSteve French 9038c8a9a5SSteve French #define NTLMSSP_REVISION_W2K3 0x0F 9138c8a9a5SSteve French 9238c8a9a5SSteve French /* See MS-NLMP section 2.2.2.10 */ 9338c8a9a5SSteve French struct ntlmssp_version { 9438c8a9a5SSteve French __u8 ProductMajorVersion; 9538c8a9a5SSteve French __u8 ProductMinorVersion; 9638c8a9a5SSteve French __le16 ProductBuild; /* we send the cifs.ko module version here */ 9738c8a9a5SSteve French __u8 Reserved[3]; 9838c8a9a5SSteve French __u8 NTLMRevisionCurrent; /* currently 0x0F */ 9938c8a9a5SSteve French } __packed; 10038c8a9a5SSteve French 10138c8a9a5SSteve French /* see MS-NLMP section 2.2.1.1 */ 10238c8a9a5SSteve French struct negotiate_message { 10338c8a9a5SSteve French __u8 Signature[sizeof(NTLMSSP_SIGNATURE)]; 10438c8a9a5SSteve French __le32 MessageType; /* NtLmNegotiate = 1 */ 10538c8a9a5SSteve French __le32 NegotiateFlags; 10638c8a9a5SSteve French SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */ 10738c8a9a5SSteve French SECURITY_BUFFER WorkstationName; /* RFC 1001 and ASCII */ 10838c8a9a5SSteve French struct ntlmssp_version Version; 10938c8a9a5SSteve French /* SECURITY_BUFFER */ 11038c8a9a5SSteve French char DomainString[]; 11138c8a9a5SSteve French /* followed by WorkstationString */ 11238c8a9a5SSteve French } __packed; 11338c8a9a5SSteve French 11438c8a9a5SSteve French typedef struct _CHALLENGE_MESSAGE { 11538c8a9a5SSteve French __u8 Signature[sizeof(NTLMSSP_SIGNATURE)]; 11638c8a9a5SSteve French __le32 MessageType; /* NtLmChallenge = 2 */ 11738c8a9a5SSteve French SECURITY_BUFFER TargetName; 11838c8a9a5SSteve French __le32 NegotiateFlags; 11938c8a9a5SSteve French __u8 Challenge[CIFS_CRYPTO_KEY_SIZE]; 12038c8a9a5SSteve French __u8 Reserved[8]; 12138c8a9a5SSteve French SECURITY_BUFFER TargetInfoArray; 12238c8a9a5SSteve French /* SECURITY_BUFFER for version info not present since we 12338c8a9a5SSteve French do not set the version is present flag */ 12438c8a9a5SSteve French } __attribute__((packed)) CHALLENGE_MESSAGE, *PCHALLENGE_MESSAGE; 12538c8a9a5SSteve French 12638c8a9a5SSteve French typedef struct _AUTHENTICATE_MESSAGE { 12738c8a9a5SSteve French __u8 Signature[sizeof(NTLMSSP_SIGNATURE)]; 12838c8a9a5SSteve French __le32 MessageType; /* NtLmsAuthenticate = 3 */ 12938c8a9a5SSteve French SECURITY_BUFFER LmChallengeResponse; 13038c8a9a5SSteve French SECURITY_BUFFER NtChallengeResponse; 13138c8a9a5SSteve French SECURITY_BUFFER DomainName; 13238c8a9a5SSteve French SECURITY_BUFFER UserName; 13338c8a9a5SSteve French SECURITY_BUFFER WorkstationName; 13438c8a9a5SSteve French SECURITY_BUFFER SessionKey; 13538c8a9a5SSteve French __le32 NegotiateFlags; 136*6bd52f41SMeetakshi Setiya struct ntlmssp_version Version; 137*6bd52f41SMeetakshi Setiya /* SECURITY_BUFFER */ 13838c8a9a5SSteve French char UserString[]; 13938c8a9a5SSteve French } __attribute__((packed)) AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE; 14038c8a9a5SSteve French 14138c8a9a5SSteve French /* 14238c8a9a5SSteve French * Size of the session key (crypto key encrypted with the password 14338c8a9a5SSteve French */ 14438c8a9a5SSteve French 14538c8a9a5SSteve French int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, struct cifs_ses *ses); 14638c8a9a5SSteve French int build_ntlmssp_negotiate_blob(unsigned char **pbuffer, u16 *buflen, 14738c8a9a5SSteve French struct cifs_ses *ses, 14838c8a9a5SSteve French struct TCP_Server_Info *server, 14938c8a9a5SSteve French const struct nls_table *nls_cp); 15038c8a9a5SSteve French int build_ntlmssp_smb3_negotiate_blob(unsigned char **pbuffer, u16 *buflen, 15138c8a9a5SSteve French struct cifs_ses *ses, 15238c8a9a5SSteve French struct TCP_Server_Info *server, 15338c8a9a5SSteve French const struct nls_table *nls_cp); 15438c8a9a5SSteve French int build_ntlmssp_auth_blob(unsigned char **pbuffer, u16 *buflen, 15538c8a9a5SSteve French struct cifs_ses *ses, 15638c8a9a5SSteve French struct TCP_Server_Info *server, 15738c8a9a5SSteve French const struct nls_table *nls_cp); 158