Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_BASE_NTLM_H_ | |
| 6 #define NET_BASE_NTLM_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 #include <type_traits> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "net/base/net_export.h" | |
| 14 | |
| 15 namespace net { | |
| 16 namespace ntlm { | |
| 17 | |
| 18 // A security buffer is a structure within an NTLM message that indicates | |
| 19 // the offset from the beginning of the message and the length of a payload | |
| 20 // that occurs later in the message. Within the raw message there is also | |
| 21 // an additional field, however the field is always written with the same | |
| 22 // value as length, and readers must always ignore it. | |
| 23 struct SecurityBuffer { | |
| 24 SecurityBuffer(uint32_t offset, uint16_t length) | |
| 25 : offset(offset), length(length) {} | |
| 26 | |
| 27 SecurityBuffer() : SecurityBuffer(0, 0) {} | |
|
Ryan Sleevi
2017/07/10 15:07:57
style nit: Maybe not a newline on 26, but instead
zentaro
2017/07/11 14:00:30
Done.
| |
| 28 uint32_t offset; | |
| 29 uint16_t length; | |
| 30 }; | |
| 31 | |
| 32 enum class NtlmVersion { | |
| 33 NTLM_V1 = 0x01, | |
| 34 NTLM_V2 = 0x02, | |
| 35 }; | |
| 36 | |
| 37 // There are 3 types of messages in NTLM. The message type is a field in | |
| 38 // every NTLM message header. | |
| 39 enum class MessageType : uint32_t { | |
| 40 NEGOTIATE = 0x01, | |
| 41 CHALLENGE = 0x02, | |
| 42 AUTHENTICATE = 0x03, | |
| 43 }; | |
| 44 | |
| 45 // Defined in [MS-NLMP] Section 2.2.2.5 | |
| 46 // Only the used subset is defined. | |
| 47 enum class NegotiateFlags : uint32_t { | |
| 48 NONE = 0, | |
| 49 UNICODE = 0x01, | |
| 50 OEM = 0x02, | |
| 51 REQUEST_TARGET = 0x04, | |
| 52 NTLM = 0x200, | |
| 53 ALWAYS_SIGN = 0x8000, | |
| 54 EXTENDED_SESSIONSECURITY = 0x80000, | |
| 55 }; | |
| 56 | |
| 57 constexpr inline NegotiateFlags operator|(NegotiateFlags lhs, | |
| 58 NegotiateFlags rhs) { | |
| 59 using TFlagsInt = std::underlying_type<NegotiateFlags>::type; | |
| 60 | |
| 61 return static_cast<NegotiateFlags>(static_cast<TFlagsInt>(lhs) | | |
| 62 static_cast<TFlagsInt>(rhs)); | |
| 63 } | |
| 64 | |
| 65 constexpr inline NegotiateFlags operator&(NegotiateFlags lhs, | |
| 66 NegotiateFlags rhs) { | |
| 67 using TFlagsInt = std::underlying_type<NegotiateFlags>::type; | |
| 68 | |
| 69 return static_cast<NegotiateFlags>(static_cast<TFlagsInt>(lhs) & | |
| 70 static_cast<TFlagsInt>(rhs)); | |
| 71 } | |
| 72 | |
| 73 static constexpr uint8_t SIGNATURE[] = "NTLMSSP"; | |
| 74 static constexpr size_t SIGNATURE_LEN = arraysize(SIGNATURE); | |
| 75 static constexpr size_t SECURITY_BUFFER_LEN = | |
| 76 (2 * sizeof(uint16_t)) + sizeof(uint32_t); | |
| 77 static constexpr size_t NEGOTIATE_MESSAGE_LEN = 32; | |
| 78 static constexpr size_t RESPONSE_V1_LEN = 24; | |
| 79 static constexpr size_t CHALLENGE_LEN = 8; | |
| 80 static constexpr size_t NTLM_HASH_LEN = 16; | |
| 81 | |
| 82 static constexpr NegotiateFlags NEGOTIATE_MESSAGE_FLAGS = | |
| 83 NegotiateFlags::UNICODE | NegotiateFlags::OEM | | |
| 84 NegotiateFlags::REQUEST_TARGET | NegotiateFlags::NTLM | | |
| 85 NegotiateFlags::ALWAYS_SIGN | NegotiateFlags::EXTENDED_SESSIONSECURITY; | |
| 86 | |
| 87 } // namespace ntlm | |
| 88 } // namespace net | |
| 89 | |
| 90 #endif // NET_BASE_NTLM_H_ | |
| OLD | NEW |