162306a36Sopenharmony_ci/* SPDX-License-Identifier: LGPL-2.1 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (c) International Business Machines Corp., 2002,2007 562306a36Sopenharmony_ci * Author(s): Steve French (sfrench@us.ibm.com) 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#define NTLMSSP_SIGNATURE "NTLMSSP" 1062306a36Sopenharmony_ci/* Message Types */ 1162306a36Sopenharmony_ci#define NtLmNegotiate cpu_to_le32(1) 1262306a36Sopenharmony_ci#define NtLmChallenge cpu_to_le32(2) 1362306a36Sopenharmony_ci#define NtLmAuthenticate cpu_to_le32(3) 1462306a36Sopenharmony_ci#define UnknownMessage cpu_to_le32(8) 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/* Negotiate Flags */ 1762306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_UNICODE 0x01 /* Text strings are unicode */ 1862306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_OEM 0x02 /* Text strings are in OEM */ 1962306a36Sopenharmony_ci#define NTLMSSP_REQUEST_TARGET 0x04 /* Srv returns its auth realm */ 2062306a36Sopenharmony_ci/* define reserved9 0x08 */ 2162306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_SIGN 0x0010 /* Request signing capability */ 2262306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_SEAL 0x0020 /* Request confidentiality */ 2362306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_DGRAM 0x0040 2462306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_LM_KEY 0x0080 /* Use LM session key */ 2562306a36Sopenharmony_ci/* defined reserved 8 0x0100 */ 2662306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_NTLM 0x0200 /* NTLM authentication */ 2762306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_NT_ONLY 0x0400 /* Lanman not allowed */ 2862306a36Sopenharmony_ci#define NTLMSSP_ANONYMOUS 0x0800 2962306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED 0x1000 /* reserved6 */ 3062306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED 0x2000 3162306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_LOCAL_CALL 0x4000 /* client/server same machine */ 3262306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x8000 /* Sign. All security levels */ 3362306a36Sopenharmony_ci#define NTLMSSP_TARGET_TYPE_DOMAIN 0x10000 3462306a36Sopenharmony_ci#define NTLMSSP_TARGET_TYPE_SERVER 0x20000 3562306a36Sopenharmony_ci#define NTLMSSP_TARGET_TYPE_SHARE 0x40000 3662306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_EXTENDED_SEC 0x80000 /* NB:not related to NTLMv2 pwd*/ 3762306a36Sopenharmony_ci/* #define NTLMSSP_REQUEST_INIT_RESP 0x100000 */ 3862306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_IDENTIFY 0x100000 3962306a36Sopenharmony_ci#define NTLMSSP_REQUEST_ACCEPT_RESP 0x200000 /* reserved5 */ 4062306a36Sopenharmony_ci#define NTLMSSP_REQUEST_NON_NT_KEY 0x400000 4162306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_TARGET_INFO 0x800000 4262306a36Sopenharmony_ci/* #define reserved4 0x1000000 */ 4362306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_VERSION 0x2000000 /* we only set for SMB2+ */ 4462306a36Sopenharmony_ci/* #define reserved3 0x4000000 */ 4562306a36Sopenharmony_ci/* #define reserved2 0x8000000 */ 4662306a36Sopenharmony_ci/* #define reserved1 0x10000000 */ 4762306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_128 0x20000000 4862306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_KEY_XCH 0x40000000 4962306a36Sopenharmony_ci#define NTLMSSP_NEGOTIATE_56 0x80000000 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci/* Define AV Pair Field IDs */ 5262306a36Sopenharmony_cienum av_field_type { 5362306a36Sopenharmony_ci NTLMSSP_AV_EOL = 0, 5462306a36Sopenharmony_ci NTLMSSP_AV_NB_COMPUTER_NAME, 5562306a36Sopenharmony_ci NTLMSSP_AV_NB_DOMAIN_NAME, 5662306a36Sopenharmony_ci NTLMSSP_AV_DNS_COMPUTER_NAME, 5762306a36Sopenharmony_ci NTLMSSP_AV_DNS_DOMAIN_NAME, 5862306a36Sopenharmony_ci NTLMSSP_AV_DNS_TREE_NAME, 5962306a36Sopenharmony_ci NTLMSSP_AV_FLAGS, 6062306a36Sopenharmony_ci NTLMSSP_AV_TIMESTAMP, 6162306a36Sopenharmony_ci NTLMSSP_AV_RESTRICTION, 6262306a36Sopenharmony_ci NTLMSSP_AV_TARGET_NAME, 6362306a36Sopenharmony_ci NTLMSSP_AV_CHANNEL_BINDINGS 6462306a36Sopenharmony_ci}; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* Although typedefs are not commonly used for structure definitions */ 6762306a36Sopenharmony_ci/* in the Linux kernel, in this particular case they are useful */ 6862306a36Sopenharmony_ci/* to more closely match the standards document for NTLMSSP from */ 6962306a36Sopenharmony_ci/* OpenGroup and to make the code more closely match the standard in */ 7062306a36Sopenharmony_ci/* appearance */ 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_citypedef struct _SECURITY_BUFFER { 7362306a36Sopenharmony_ci __le16 Length; 7462306a36Sopenharmony_ci __le16 MaximumLength; 7562306a36Sopenharmony_ci __le32 BufferOffset; /* offset to buffer */ 7662306a36Sopenharmony_ci} __attribute__((packed)) SECURITY_BUFFER; 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_citypedef struct _NEGOTIATE_MESSAGE { 7962306a36Sopenharmony_ci __u8 Signature[sizeof(NTLMSSP_SIGNATURE)]; 8062306a36Sopenharmony_ci __le32 MessageType; /* NtLmNegotiate = 1 */ 8162306a36Sopenharmony_ci __le32 NegotiateFlags; 8262306a36Sopenharmony_ci SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */ 8362306a36Sopenharmony_ci SECURITY_BUFFER WorkstationName; /* RFC 1001 and ASCII */ 8462306a36Sopenharmony_ci /* SECURITY_BUFFER for version info not present since we 8562306a36Sopenharmony_ci do not set the version is present flag */ 8662306a36Sopenharmony_ci char DomainString[]; 8762306a36Sopenharmony_ci /* followed by WorkstationString */ 8862306a36Sopenharmony_ci} __attribute__((packed)) NEGOTIATE_MESSAGE, *PNEGOTIATE_MESSAGE; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci#define NTLMSSP_REVISION_W2K3 0x0F 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci/* See MS-NLMP section 2.2.2.10 */ 9362306a36Sopenharmony_cistruct ntlmssp_version { 9462306a36Sopenharmony_ci __u8 ProductMajorVersion; 9562306a36Sopenharmony_ci __u8 ProductMinorVersion; 9662306a36Sopenharmony_ci __le16 ProductBuild; /* we send the cifs.ko module version here */ 9762306a36Sopenharmony_ci __u8 Reserved[3]; 9862306a36Sopenharmony_ci __u8 NTLMRevisionCurrent; /* currently 0x0F */ 9962306a36Sopenharmony_ci} __packed; 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci/* see MS-NLMP section 2.2.1.1 */ 10262306a36Sopenharmony_cistruct negotiate_message { 10362306a36Sopenharmony_ci __u8 Signature[sizeof(NTLMSSP_SIGNATURE)]; 10462306a36Sopenharmony_ci __le32 MessageType; /* NtLmNegotiate = 1 */ 10562306a36Sopenharmony_ci __le32 NegotiateFlags; 10662306a36Sopenharmony_ci SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */ 10762306a36Sopenharmony_ci SECURITY_BUFFER WorkstationName; /* RFC 1001 and ASCII */ 10862306a36Sopenharmony_ci struct ntlmssp_version Version; 10962306a36Sopenharmony_ci /* SECURITY_BUFFER */ 11062306a36Sopenharmony_ci char DomainString[]; 11162306a36Sopenharmony_ci /* followed by WorkstationString */ 11262306a36Sopenharmony_ci} __packed; 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_citypedef struct _CHALLENGE_MESSAGE { 11562306a36Sopenharmony_ci __u8 Signature[sizeof(NTLMSSP_SIGNATURE)]; 11662306a36Sopenharmony_ci __le32 MessageType; /* NtLmChallenge = 2 */ 11762306a36Sopenharmony_ci SECURITY_BUFFER TargetName; 11862306a36Sopenharmony_ci __le32 NegotiateFlags; 11962306a36Sopenharmony_ci __u8 Challenge[CIFS_CRYPTO_KEY_SIZE]; 12062306a36Sopenharmony_ci __u8 Reserved[8]; 12162306a36Sopenharmony_ci SECURITY_BUFFER TargetInfoArray; 12262306a36Sopenharmony_ci /* SECURITY_BUFFER for version info not present since we 12362306a36Sopenharmony_ci do not set the version is present flag */ 12462306a36Sopenharmony_ci} __attribute__((packed)) CHALLENGE_MESSAGE, *PCHALLENGE_MESSAGE; 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_citypedef struct _AUTHENTICATE_MESSAGE { 12762306a36Sopenharmony_ci __u8 Signature[sizeof(NTLMSSP_SIGNATURE)]; 12862306a36Sopenharmony_ci __le32 MessageType; /* NtLmsAuthenticate = 3 */ 12962306a36Sopenharmony_ci SECURITY_BUFFER LmChallengeResponse; 13062306a36Sopenharmony_ci SECURITY_BUFFER NtChallengeResponse; 13162306a36Sopenharmony_ci SECURITY_BUFFER DomainName; 13262306a36Sopenharmony_ci SECURITY_BUFFER UserName; 13362306a36Sopenharmony_ci SECURITY_BUFFER WorkstationName; 13462306a36Sopenharmony_ci SECURITY_BUFFER SessionKey; 13562306a36Sopenharmony_ci __le32 NegotiateFlags; 13662306a36Sopenharmony_ci /* SECURITY_BUFFER for version info not present since we 13762306a36Sopenharmony_ci do not set the version is present flag */ 13862306a36Sopenharmony_ci char UserString[]; 13962306a36Sopenharmony_ci} __attribute__((packed)) AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE; 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci/* 14262306a36Sopenharmony_ci * Size of the session key (crypto key encrypted with the password 14362306a36Sopenharmony_ci */ 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ciint decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, struct cifs_ses *ses); 14662306a36Sopenharmony_ciint build_ntlmssp_negotiate_blob(unsigned char **pbuffer, u16 *buflen, 14762306a36Sopenharmony_ci struct cifs_ses *ses, 14862306a36Sopenharmony_ci struct TCP_Server_Info *server, 14962306a36Sopenharmony_ci const struct nls_table *nls_cp); 15062306a36Sopenharmony_ciint build_ntlmssp_smb3_negotiate_blob(unsigned char **pbuffer, u16 *buflen, 15162306a36Sopenharmony_ci struct cifs_ses *ses, 15262306a36Sopenharmony_ci struct TCP_Server_Info *server, 15362306a36Sopenharmony_ci const struct nls_table *nls_cp); 15462306a36Sopenharmony_ciint build_ntlmssp_auth_blob(unsigned char **pbuffer, u16 *buflen, 15562306a36Sopenharmony_ci struct cifs_ses *ses, 15662306a36Sopenharmony_ci struct TCP_Server_Info *server, 15762306a36Sopenharmony_ci const struct nls_table *nls_cp); 158