iPXE
ntlm.h
Go to the documentation of this file.
1 #ifndef _IPXE_NTLM_H
2 #define _IPXE_NTLM_H
3 
4 /** @file
5  *
6  * NT LAN Manager (NTLM) authentication
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <stdint.h>
14 #include <ipxe/crypto.h>
15 #include <ipxe/md5.h>
16 
17 /** A message header */
18 struct ntlm_header {
19  /** Magic signature */
21  /** Message type */
23 } __attribute__ (( packed ));
24 
25 /** Magic signature */
26 #define NTLM_MAGIC { 'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0' }
27 
28 /** Message types */
29 enum ntlm_type {
30  /** Negotiate message type */
31  NTLM_NEGOTIATE = 0x00000001UL,
32  /** Challenge message type */
33  NTLM_CHALLENGE = 0x00000002UL,
34  /** Authenticate message */
35  NTLM_AUTHENTICATE = 0x00000003UL,
36 };
37 
38 /** Negotiation flags */
39 enum ntlm_flags {
40  /** Negotiate key exchange */
41  NTLM_NEGOTIATE_KEY_EXCH = 0x20000000UL,
42  /** Negotiate extended security */
44  /** Negotiate always sign */
46  /** Negotiate NTLM key */
47  NTLM_NEGOTIATE_NTLM = 0x00000200UL,
48  /** Request target name and information */
49  NTLM_REQUEST_TARGET = 0x00000004UL,
50  /** Negotiate Unicode character encoding */
51  NTLM_NEGOTIATE_UNICODE = 0x00000001UL,
52 };
53 
54 /** A version descriptor */
55 struct ntlm_version {
56  /** Product major version */
58  /** Product minor version */
60  /** Product build number */
62  /** Reserved */
64  /** NTLMSSP revision */
66 } __attribute__ (( packed ));
67 
68 /** A nonce */
69 struct ntlm_nonce {
70  /** Raw bytes */
72 } __attribute__ (( packed ));
73 
74 /** A variable-length data descriptor */
75 struct ntlm_data {
76  /** Length (in bytes) */
78  /** Maximum length (in bytes)
79  *
80  * Should always be set equal to the length; this field is
81  * entirely superfluous.
82  */
84  /** Offset from start of message header */
86 } __attribute__ (( packed ));
87 
88 /** A Negotiate message */
90  /** Message header */
92  /** Negotiation flags */
94  /** Domain name */
95  struct ntlm_data domain;
96  /** Workstation name */
98 } __attribute__ (( packed ));
99 
100 /** A Challenge message */
102  /** Message header */
104  /** Target name */
105  struct ntlm_data name;
106  /** Negotiation flags */
108  /** Server nonce */
110  /** Reserved */
112  /** Target information */
113  struct ntlm_data info;
114 } __attribute__ (( packed ));
115 
116 /** An Authenticate message */
118  /** Message header */
120  /** LAN Manager response */
121  struct ntlm_data lm;
122  /** NT response */
123  struct ntlm_data nt;
124  /** Domain name */
126  /** User name */
127  struct ntlm_data user;
128  /** Workstation name */
130  /** Session key */
132  /** Negotiation flags */
134 } __attribute__ (( packed ));
135 
136 /** A LAN Manager response */
138  /** HMAC-MD5 digest */
140  /** Client nonce */
142 } __attribute__ (( packed ));
143 
144 /** An NT response */
146  /** HMAC-MD5 digest */
148  /** Response version */
150  /** Highest response version */
152  /** Reserved */
154  /** Current time */
156  /** Client nonce */
158  /** Must be zero */
160 } __attribute__ (( packed ));
161 
162 /** NTLM version */
163 #define NTLM_VERSION_NTLMV2 0x01
164 
165 /** NTLM challenge information */
167  /** Server nonce */
168  struct ntlm_nonce *nonce;
169  /** Target information */
170  void *target;
171  /** Length of target information */
172  size_t len;
173 };
174 
175 /** An NTLM verification key */
176 struct ntlm_key {
177  /** Raw bytes */
179 };
180 
181 extern const struct ntlm_negotiate ntlm_negotiate;
182 extern int ntlm_challenge ( struct ntlm_challenge *challenge, size_t len,
183  struct ntlm_challenge_info *info );
184 extern void ntlm_key ( const char *domain, const char *username,
185  const char *password, struct ntlm_key *key );
186 extern void ntlm_response ( struct ntlm_challenge_info *info,
187  struct ntlm_key *key, struct ntlm_nonce *nonce,
188  struct ntlm_lm_response *lm,
189  struct ntlm_nt_response *nt );
190 extern size_t ntlm_authenticate ( struct ntlm_challenge_info *info,
191  const char *domain, const char *username,
192  const char *workstation,
193  struct ntlm_lm_response *lm,
194  struct ntlm_nt_response *nt,
195  struct ntlm_authenticate *auth );
196 extern size_t ntlm_authenticate_len ( struct ntlm_challenge_info *info,
197  const char *domain, const char *username,
198  const char *workstation );
199 
200 #endif /* _IPXE_NTLM_H */
struct ntlm_nonce * nonce
Server nonce.
Definition: ntlm.h:168
#define __attribute__(x)
Definition: compiler.h:10
int ntlm_challenge(struct ntlm_challenge *challenge, size_t len, struct ntlm_challenge_info *info)
Parse NTLM Challenge.
Definition: ntlm.c:69
unsigned short uint16_t
Definition: stdint.h:11
A variable-length data descriptor.
Definition: ntlm.h:75
uint8_t magic[8]
Magic signature.
Definition: ntlm.h:20
uint8_t major
Product major version.
Definition: ntlm.h:57
uint8_t minor
Product minor version.
Definition: ntlm.h:59
u32 info
Definition: ar9003_mac.h:24
uint8_t digest[MD5_DIGEST_SIZE]
HMAC-MD5 digest.
Definition: ntlm.h:147
struct ntlm_data lm
LAN Manager response.
Definition: ntlm.h:121
uint8_t high
Highest response version.
Definition: ntlm.h:151
uint8_t reserved_a[6]
Reserved.
Definition: ntlm.h:153
size_t ntlm_authenticate(struct ntlm_challenge_info *info, const char *domain, const char *username, const char *workstation, struct ntlm_lm_response *lm, struct ntlm_nt_response *nt, struct ntlm_authenticate *auth)
Construct NTLM Authenticate message.
Definition: ntlm.c:267
Negotiate NTLM key.
Definition: ntlm.h:47
unsigned long long uint64_t
Definition: stdint.h:13
FILE_SECBOOT(PERMITTED)
ntlm_flags
Negotiation flags.
Definition: ntlm.h:39
Cryptographic API.
size_t len
Length of target information.
Definition: ntlm.h:172
struct ntlm_header header
Message header.
Definition: ntlm.h:119
uint16_t len
Length (in bytes)
Definition: ntlm.h:77
Authenticate message.
Definition: ntlm.h:35
uint64_t time
Current time.
Definition: ntlm.h:155
uint8_t reserved[3]
Reserved.
Definition: ntlm.h:63
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint16_t build
Product build number.
Definition: ntlm.h:61
struct ntlm_data domain
Domain name.
Definition: ntlm.h:95
Negotiate always sign.
Definition: ntlm.h:45
void ntlm_response(struct ntlm_challenge_info *info, struct ntlm_key *key, struct ntlm_nonce *nonce, struct ntlm_lm_response *lm, struct ntlm_nt_response *nt)
Construct NTLM responses.
Definition: ntlm.c:167
uint8_t digest[MD5_DIGEST_SIZE]
HMAC-MD5 digest.
Definition: ntlm.h:139
ring len
Length.
Definition: dwmac.h:231
An Authenticate message.
Definition: ntlm.h:117
uint8_t version
Response version.
Definition: ntlm.h:149
An NTLM verification key.
Definition: ntlm.h:176
ntlm_type
Message types.
Definition: ntlm.h:29
struct ntlm_nonce nonce
Client nonce.
Definition: ntlm.h:157
uint32_t flags
Negotiation flags.
Definition: ntlm.h:93
uint16_t max_len
Maximum length (in bytes)
Definition: ntlm.h:83
struct ntlm_data workstation
Workstation name.
Definition: ntlm.h:129
uint32_t flags
Negotiation flags.
Definition: ntlm.h:107
A message header.
Definition: ntlm.h:18
struct ntlm_data domain
Domain name.
Definition: ntlm.h:125
unsigned char uint8_t
Definition: stdint.h:10
Challenge message type.
Definition: ntlm.h:33
struct ntlm_header header
Message header.
Definition: ntlm.h:91
A nonce.
Definition: ntlm.h:69
void * target
Target information.
Definition: ntlm.h:170
struct ntlm_data session
Session key.
Definition: ntlm.h:131
struct ntlm_nonce nonce
Client nonce.
Definition: ntlm.h:141
Negotiate extended security.
Definition: ntlm.h:43
size_t ntlm_authenticate_len(struct ntlm_challenge_info *info, const char *domain, const char *username, const char *workstation)
Calculate NTLM Authenticate message length.
Definition: ntlm.c:326
unsigned int uint32_t
Definition: stdint.h:12
static struct dynamic_item password
Definition: login_ui.c:37
u8 nonce[32]
Nonce value.
Definition: wpa.h:52
uint32_t zero
Must be zero.
Definition: ntlm.h:159
struct ntlm_data nt
NT response.
Definition: ntlm.h:123
uint32_t flags
Negotiation flags.
Definition: ntlm.h:133
struct ntlm_data name
Target name.
Definition: ntlm.h:105
struct ntlm_data user
User name.
Definition: ntlm.h:127
struct ntlm_data workstation
Workstation name.
Definition: ntlm.h:97
Negotiate key exchange.
Definition: ntlm.h:41
struct ntlm_data info
Target information.
Definition: ntlm.h:113
Negotiate message type.
Definition: ntlm.h:31
struct ntlm_header header
Message header.
Definition: ntlm.h:103
A Challenge message.
Definition: ntlm.h:101
uint8_t raw[MD5_DIGEST_SIZE]
Raw bytes.
Definition: ntlm.h:178
uint8_t reserved[8]
Reserved.
Definition: ntlm.h:111
uint8_t revision
NTLMSSP revision.
Definition: ntlm.h:65
uint32_t offset
Offset from start of message header.
Definition: ntlm.h:85
uint32_t type
Message type.
Definition: ntlm.h:22
uint8_t raw[8]
Raw bytes.
Definition: ntlm.h:71
static struct dynamic_item username
Definition: login_ui.c:36
#define MD5_DIGEST_SIZE
MD5 digest size.
Definition: md5.h:73
A version descriptor.
Definition: ntlm.h:55
struct ntlm_nonce nonce
Server nonce.
Definition: ntlm.h:109
NTLM challenge information.
Definition: ntlm.h:166
An NT response.
Definition: ntlm.h:145
MD5 algorithm.
Request target name and information.
Definition: ntlm.h:49
A LAN Manager response.
Definition: ntlm.h:137
Negotiate Unicode character encoding.
Definition: ntlm.h:51
union @391 key
Sense key.
Definition: scsi.h:18
struct mschapv2_nt_response nt
NT response.
Definition: mschapv2.h:16
void ntlm_key(const char *domain, const char *username, const char *password, struct ntlm_key *key)
Calculate NTLM verification key.
Definition: ntlm.c:115
A Negotiate message.
Definition: ntlm.h:89