1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * fs/cifs/ntlmssp.h 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Copyright (c) International Business Machines Corp., 2002,2007 5*4882a593Smuzhiyun * Author(s): Steve French (sfrench@us.ibm.com) 6*4882a593Smuzhiyun * 7*4882a593Smuzhiyun * This library is free software; you can redistribute it and/or modify 8*4882a593Smuzhiyun * it under the terms of the GNU Lesser General Public License as published 9*4882a593Smuzhiyun * by the Free Software Foundation; either version 2.1 of the License, or 10*4882a593Smuzhiyun * (at your option) any later version. 11*4882a593Smuzhiyun * 12*4882a593Smuzhiyun * This library is distributed in the hope that it will be useful, 13*4882a593Smuzhiyun * but WITHOUT ANY WARRANTY; without even the implied warranty of 14*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 15*4882a593Smuzhiyun * the GNU Lesser General Public License for more details. 16*4882a593Smuzhiyun * 17*4882a593Smuzhiyun * You should have received a copy of the GNU Lesser General Public License 18*4882a593Smuzhiyun * along with this library; if not, write to the Free Software 19*4882a593Smuzhiyun * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20*4882a593Smuzhiyun */ 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun #define NTLMSSP_SIGNATURE "NTLMSSP" 23*4882a593Smuzhiyun /* Message Types */ 24*4882a593Smuzhiyun #define NtLmNegotiate cpu_to_le32(1) 25*4882a593Smuzhiyun #define NtLmChallenge cpu_to_le32(2) 26*4882a593Smuzhiyun #define NtLmAuthenticate cpu_to_le32(3) 27*4882a593Smuzhiyun #define UnknownMessage cpu_to_le32(8) 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun /* Negotiate Flags */ 30*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_UNICODE 0x01 /* Text strings are unicode */ 31*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_OEM 0x02 /* Text strings are in OEM */ 32*4882a593Smuzhiyun #define NTLMSSP_REQUEST_TARGET 0x04 /* Srv returns its auth realm */ 33*4882a593Smuzhiyun /* define reserved9 0x08 */ 34*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_SIGN 0x0010 /* Request signing capability */ 35*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_SEAL 0x0020 /* Request confidentiality */ 36*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_DGRAM 0x0040 37*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_LM_KEY 0x0080 /* Use LM session key */ 38*4882a593Smuzhiyun /* defined reserved 8 0x0100 */ 39*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_NTLM 0x0200 /* NTLM authentication */ 40*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_NT_ONLY 0x0400 /* Lanman not allowed */ 41*4882a593Smuzhiyun #define NTLMSSP_ANONYMOUS 0x0800 42*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED 0x1000 /* reserved6 */ 43*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED 0x2000 44*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_LOCAL_CALL 0x4000 /* client/server same machine */ 45*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x8000 /* Sign. All security levels */ 46*4882a593Smuzhiyun #define NTLMSSP_TARGET_TYPE_DOMAIN 0x10000 47*4882a593Smuzhiyun #define NTLMSSP_TARGET_TYPE_SERVER 0x20000 48*4882a593Smuzhiyun #define NTLMSSP_TARGET_TYPE_SHARE 0x40000 49*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_EXTENDED_SEC 0x80000 /* NB:not related to NTLMv2 pwd*/ 50*4882a593Smuzhiyun /* #define NTLMSSP_REQUEST_INIT_RESP 0x100000 */ 51*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_IDENTIFY 0x100000 52*4882a593Smuzhiyun #define NTLMSSP_REQUEST_ACCEPT_RESP 0x200000 /* reserved5 */ 53*4882a593Smuzhiyun #define NTLMSSP_REQUEST_NON_NT_KEY 0x400000 54*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_TARGET_INFO 0x800000 55*4882a593Smuzhiyun /* #define reserved4 0x1000000 */ 56*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_VERSION 0x2000000 /* we do not set */ 57*4882a593Smuzhiyun /* #define reserved3 0x4000000 */ 58*4882a593Smuzhiyun /* #define reserved2 0x8000000 */ 59*4882a593Smuzhiyun /* #define reserved1 0x10000000 */ 60*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_128 0x20000000 61*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_KEY_XCH 0x40000000 62*4882a593Smuzhiyun #define NTLMSSP_NEGOTIATE_56 0x80000000 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun /* Define AV Pair Field IDs */ 65*4882a593Smuzhiyun enum av_field_type { 66*4882a593Smuzhiyun NTLMSSP_AV_EOL = 0, 67*4882a593Smuzhiyun NTLMSSP_AV_NB_COMPUTER_NAME, 68*4882a593Smuzhiyun NTLMSSP_AV_NB_DOMAIN_NAME, 69*4882a593Smuzhiyun NTLMSSP_AV_DNS_COMPUTER_NAME, 70*4882a593Smuzhiyun NTLMSSP_AV_DNS_DOMAIN_NAME, 71*4882a593Smuzhiyun NTLMSSP_AV_DNS_TREE_NAME, 72*4882a593Smuzhiyun NTLMSSP_AV_FLAGS, 73*4882a593Smuzhiyun NTLMSSP_AV_TIMESTAMP, 74*4882a593Smuzhiyun NTLMSSP_AV_RESTRICTION, 75*4882a593Smuzhiyun NTLMSSP_AV_TARGET_NAME, 76*4882a593Smuzhiyun NTLMSSP_AV_CHANNEL_BINDINGS 77*4882a593Smuzhiyun }; 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun /* Although typedefs are not commonly used for structure definitions */ 80*4882a593Smuzhiyun /* in the Linux kernel, in this particular case they are useful */ 81*4882a593Smuzhiyun /* to more closely match the standards document for NTLMSSP from */ 82*4882a593Smuzhiyun /* OpenGroup and to make the code more closely match the standard in */ 83*4882a593Smuzhiyun /* appearance */ 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun typedef struct _SECURITY_BUFFER { 86*4882a593Smuzhiyun __le16 Length; 87*4882a593Smuzhiyun __le16 MaximumLength; 88*4882a593Smuzhiyun __le32 BufferOffset; /* offset to buffer */ 89*4882a593Smuzhiyun } __attribute__((packed)) SECURITY_BUFFER; 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun typedef struct _NEGOTIATE_MESSAGE { 92*4882a593Smuzhiyun __u8 Signature[sizeof(NTLMSSP_SIGNATURE)]; 93*4882a593Smuzhiyun __le32 MessageType; /* NtLmNegotiate = 1 */ 94*4882a593Smuzhiyun __le32 NegotiateFlags; 95*4882a593Smuzhiyun SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */ 96*4882a593Smuzhiyun SECURITY_BUFFER WorkstationName; /* RFC 1001 and ASCII */ 97*4882a593Smuzhiyun /* SECURITY_BUFFER for version info not present since we 98*4882a593Smuzhiyun do not set the version is present flag */ 99*4882a593Smuzhiyun char DomainString[0]; 100*4882a593Smuzhiyun /* followed by WorkstationString */ 101*4882a593Smuzhiyun } __attribute__((packed)) NEGOTIATE_MESSAGE, *PNEGOTIATE_MESSAGE; 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun typedef struct _CHALLENGE_MESSAGE { 104*4882a593Smuzhiyun __u8 Signature[sizeof(NTLMSSP_SIGNATURE)]; 105*4882a593Smuzhiyun __le32 MessageType; /* NtLmChallenge = 2 */ 106*4882a593Smuzhiyun SECURITY_BUFFER TargetName; 107*4882a593Smuzhiyun __le32 NegotiateFlags; 108*4882a593Smuzhiyun __u8 Challenge[CIFS_CRYPTO_KEY_SIZE]; 109*4882a593Smuzhiyun __u8 Reserved[8]; 110*4882a593Smuzhiyun SECURITY_BUFFER TargetInfoArray; 111*4882a593Smuzhiyun /* SECURITY_BUFFER for version info not present since we 112*4882a593Smuzhiyun do not set the version is present flag */ 113*4882a593Smuzhiyun } __attribute__((packed)) CHALLENGE_MESSAGE, *PCHALLENGE_MESSAGE; 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun typedef struct _AUTHENTICATE_MESSAGE { 116*4882a593Smuzhiyun __u8 Signature[sizeof(NTLMSSP_SIGNATURE)]; 117*4882a593Smuzhiyun __le32 MessageType; /* NtLmsAuthenticate = 3 */ 118*4882a593Smuzhiyun SECURITY_BUFFER LmChallengeResponse; 119*4882a593Smuzhiyun SECURITY_BUFFER NtChallengeResponse; 120*4882a593Smuzhiyun SECURITY_BUFFER DomainName; 121*4882a593Smuzhiyun SECURITY_BUFFER UserName; 122*4882a593Smuzhiyun SECURITY_BUFFER WorkstationName; 123*4882a593Smuzhiyun SECURITY_BUFFER SessionKey; 124*4882a593Smuzhiyun __le32 NegotiateFlags; 125*4882a593Smuzhiyun /* SECURITY_BUFFER for version info not present since we 126*4882a593Smuzhiyun do not set the version is present flag */ 127*4882a593Smuzhiyun char UserString[0]; 128*4882a593Smuzhiyun } __attribute__((packed)) AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE; 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun /* 131*4882a593Smuzhiyun * Size of the session key (crypto key encrypted with the password 132*4882a593Smuzhiyun */ 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, struct cifs_ses *ses); 135*4882a593Smuzhiyun void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, struct cifs_ses *ses); 136*4882a593Smuzhiyun int build_ntlmssp_auth_blob(unsigned char **pbuffer, u16 *buflen, 137*4882a593Smuzhiyun struct cifs_ses *ses, 138*4882a593Smuzhiyun const struct nls_table *nls_cp); 139