ntlmssp.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* SPDX-License-Identifier: LGPL-2.1 */
  2. /*
  3. *
  4. * Copyright (c) International Business Machines Corp., 2002,2007
  5. * Author(s): Steve French ([email protected])
  6. *
  7. */
  8. #define NTLMSSP_SIGNATURE "NTLMSSP"
  9. /* Message Types */
  10. #define NtLmNegotiate cpu_to_le32(1)
  11. #define NtLmChallenge cpu_to_le32(2)
  12. #define NtLmAuthenticate cpu_to_le32(3)
  13. #define UnknownMessage cpu_to_le32(8)
  14. /* Negotiate Flags */
  15. #define NTLMSSP_NEGOTIATE_UNICODE 0x01 /* Text strings are unicode */
  16. #define NTLMSSP_NEGOTIATE_OEM 0x02 /* Text strings are in OEM */
  17. #define NTLMSSP_REQUEST_TARGET 0x04 /* Srv returns its auth realm */
  18. /* define reserved9 0x08 */
  19. #define NTLMSSP_NEGOTIATE_SIGN 0x0010 /* Request signing capability */
  20. #define NTLMSSP_NEGOTIATE_SEAL 0x0020 /* Request confidentiality */
  21. #define NTLMSSP_NEGOTIATE_DGRAM 0x0040
  22. #define NTLMSSP_NEGOTIATE_LM_KEY 0x0080 /* Use LM session key */
  23. /* defined reserved 8 0x0100 */
  24. #define NTLMSSP_NEGOTIATE_NTLM 0x0200 /* NTLM authentication */
  25. #define NTLMSSP_NEGOTIATE_NT_ONLY 0x0400 /* Lanman not allowed */
  26. #define NTLMSSP_ANONYMOUS 0x0800
  27. #define NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED 0x1000 /* reserved6 */
  28. #define NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED 0x2000
  29. #define NTLMSSP_NEGOTIATE_LOCAL_CALL 0x4000 /* client/server same machine */
  30. #define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x8000 /* Sign. All security levels */
  31. #define NTLMSSP_TARGET_TYPE_DOMAIN 0x10000
  32. #define NTLMSSP_TARGET_TYPE_SERVER 0x20000
  33. #define NTLMSSP_TARGET_TYPE_SHARE 0x40000
  34. #define NTLMSSP_NEGOTIATE_EXTENDED_SEC 0x80000 /* NB:not related to NTLMv2 pwd*/
  35. /* #define NTLMSSP_REQUEST_INIT_RESP 0x100000 */
  36. #define NTLMSSP_NEGOTIATE_IDENTIFY 0x100000
  37. #define NTLMSSP_REQUEST_ACCEPT_RESP 0x200000 /* reserved5 */
  38. #define NTLMSSP_REQUEST_NON_NT_KEY 0x400000
  39. #define NTLMSSP_NEGOTIATE_TARGET_INFO 0x800000
  40. /* #define reserved4 0x1000000 */
  41. #define NTLMSSP_NEGOTIATE_VERSION 0x2000000 /* we only set for SMB2+ */
  42. /* #define reserved3 0x4000000 */
  43. /* #define reserved2 0x8000000 */
  44. /* #define reserved1 0x10000000 */
  45. #define NTLMSSP_NEGOTIATE_128 0x20000000
  46. #define NTLMSSP_NEGOTIATE_KEY_XCH 0x40000000
  47. #define NTLMSSP_NEGOTIATE_56 0x80000000
  48. /* Define AV Pair Field IDs */
  49. enum av_field_type {
  50. NTLMSSP_AV_EOL = 0,
  51. NTLMSSP_AV_NB_COMPUTER_NAME,
  52. NTLMSSP_AV_NB_DOMAIN_NAME,
  53. NTLMSSP_AV_DNS_COMPUTER_NAME,
  54. NTLMSSP_AV_DNS_DOMAIN_NAME,
  55. NTLMSSP_AV_DNS_TREE_NAME,
  56. NTLMSSP_AV_FLAGS,
  57. NTLMSSP_AV_TIMESTAMP,
  58. NTLMSSP_AV_RESTRICTION,
  59. NTLMSSP_AV_TARGET_NAME,
  60. NTLMSSP_AV_CHANNEL_BINDINGS
  61. };
  62. /* Although typedefs are not commonly used for structure definitions */
  63. /* in the Linux kernel, in this particular case they are useful */
  64. /* to more closely match the standards document for NTLMSSP from */
  65. /* OpenGroup and to make the code more closely match the standard in */
  66. /* appearance */
  67. typedef struct _SECURITY_BUFFER {
  68. __le16 Length;
  69. __le16 MaximumLength;
  70. __le32 BufferOffset; /* offset to buffer */
  71. } __attribute__((packed)) SECURITY_BUFFER;
  72. typedef struct _NEGOTIATE_MESSAGE {
  73. __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
  74. __le32 MessageType; /* NtLmNegotiate = 1 */
  75. __le32 NegotiateFlags;
  76. SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */
  77. SECURITY_BUFFER WorkstationName; /* RFC 1001 and ASCII */
  78. /* SECURITY_BUFFER for version info not present since we
  79. do not set the version is present flag */
  80. char DomainString[0];
  81. /* followed by WorkstationString */
  82. } __attribute__((packed)) NEGOTIATE_MESSAGE, *PNEGOTIATE_MESSAGE;
  83. #define NTLMSSP_REVISION_W2K3 0x0F
  84. /* See MS-NLMP section 2.2.2.10 */
  85. struct ntlmssp_version {
  86. __u8 ProductMajorVersion;
  87. __u8 ProductMinorVersion;
  88. __le16 ProductBuild; /* we send the cifs.ko module version here */
  89. __u8 Reserved[3];
  90. __u8 NTLMRevisionCurrent; /* currently 0x0F */
  91. } __packed;
  92. /* see MS-NLMP section 2.2.1.1 */
  93. struct negotiate_message {
  94. __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
  95. __le32 MessageType; /* NtLmNegotiate = 1 */
  96. __le32 NegotiateFlags;
  97. SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */
  98. SECURITY_BUFFER WorkstationName; /* RFC 1001 and ASCII */
  99. struct ntlmssp_version Version;
  100. /* SECURITY_BUFFER */
  101. char DomainString[];
  102. /* followed by WorkstationString */
  103. } __packed;
  104. typedef struct _CHALLENGE_MESSAGE {
  105. __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
  106. __le32 MessageType; /* NtLmChallenge = 2 */
  107. SECURITY_BUFFER TargetName;
  108. __le32 NegotiateFlags;
  109. __u8 Challenge[CIFS_CRYPTO_KEY_SIZE];
  110. __u8 Reserved[8];
  111. SECURITY_BUFFER TargetInfoArray;
  112. /* SECURITY_BUFFER for version info not present since we
  113. do not set the version is present flag */
  114. } __attribute__((packed)) CHALLENGE_MESSAGE, *PCHALLENGE_MESSAGE;
  115. typedef struct _AUTHENTICATE_MESSAGE {
  116. __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
  117. __le32 MessageType; /* NtLmsAuthenticate = 3 */
  118. SECURITY_BUFFER LmChallengeResponse;
  119. SECURITY_BUFFER NtChallengeResponse;
  120. SECURITY_BUFFER DomainName;
  121. SECURITY_BUFFER UserName;
  122. SECURITY_BUFFER WorkstationName;
  123. SECURITY_BUFFER SessionKey;
  124. __le32 NegotiateFlags;
  125. /* SECURITY_BUFFER for version info not present since we
  126. do not set the version is present flag */
  127. char UserString[0];
  128. } __attribute__((packed)) AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE;
  129. /*
  130. * Size of the session key (crypto key encrypted with the password
  131. */
  132. int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, struct cifs_ses *ses);
  133. int build_ntlmssp_negotiate_blob(unsigned char **pbuffer, u16 *buflen,
  134. struct cifs_ses *ses,
  135. struct TCP_Server_Info *server,
  136. const struct nls_table *nls_cp);
  137. int build_ntlmssp_smb3_negotiate_blob(unsigned char **pbuffer, u16 *buflen,
  138. struct cifs_ses *ses,
  139. struct TCP_Server_Info *server,
  140. const struct nls_table *nls_cp);
  141. int build_ntlmssp_auth_blob(unsigned char **pbuffer, u16 *buflen,
  142. struct cifs_ses *ses,
  143. struct TCP_Server_Info *server,
  144. const struct nls_table *nls_cp);