You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ntlm.h 4.8KB

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