Chromium Code Reviews| Index: net/ntlm/ntlm_constants.h |
| diff --git a/net/ntlm/ntlm_constants.h b/net/ntlm/ntlm_constants.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..97a805a6db4422a7b7f751a90b9278d385c45b7d |
| --- /dev/null |
| +++ b/net/ntlm/ntlm_constants.h |
| @@ -0,0 +1,90 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_BASE_NTLM_H_ |
| +#define NET_BASE_NTLM_H_ |
| + |
| +#include <stddef.h> |
| +#include <stdint.h> |
| +#include <type_traits> |
| + |
| +#include "base/macros.h" |
| +#include "net/base/net_export.h" |
| + |
| +namespace net { |
| +namespace ntlm { |
| + |
| +// A security buffer is a structure within an NTLM message that indicates |
| +// the offset from the beginning of the message and the length of a payload |
| +// that occurs later in the message. Within the raw message there is also |
| +// an additional field, however the field is always written with the same |
| +// value as length, and readers must always ignore it. |
| +struct SecurityBuffer { |
| + SecurityBuffer(uint32_t offset, uint16_t length) |
| + : offset(offset), length(length) {} |
| + |
| + 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.
|
| + uint32_t offset; |
| + uint16_t length; |
| +}; |
| + |
| +enum class NtlmVersion { |
| + NTLM_V1 = 0x01, |
| + NTLM_V2 = 0x02, |
| +}; |
| + |
| +// There are 3 types of messages in NTLM. The message type is a field in |
| +// every NTLM message header. |
| +enum class MessageType : uint32_t { |
| + NEGOTIATE = 0x01, |
| + CHALLENGE = 0x02, |
| + AUTHENTICATE = 0x03, |
| +}; |
| + |
| +// Defined in [MS-NLMP] Section 2.2.2.5 |
| +// Only the used subset is defined. |
| +enum class NegotiateFlags : uint32_t { |
| + NONE = 0, |
| + UNICODE = 0x01, |
| + OEM = 0x02, |
| + REQUEST_TARGET = 0x04, |
| + NTLM = 0x200, |
| + ALWAYS_SIGN = 0x8000, |
| + EXTENDED_SESSIONSECURITY = 0x80000, |
| +}; |
| + |
| +constexpr inline NegotiateFlags operator|(NegotiateFlags lhs, |
| + NegotiateFlags rhs) { |
| + using TFlagsInt = std::underlying_type<NegotiateFlags>::type; |
| + |
| + return static_cast<NegotiateFlags>(static_cast<TFlagsInt>(lhs) | |
| + static_cast<TFlagsInt>(rhs)); |
| +} |
| + |
| +constexpr inline NegotiateFlags operator&(NegotiateFlags lhs, |
| + NegotiateFlags rhs) { |
| + using TFlagsInt = std::underlying_type<NegotiateFlags>::type; |
| + |
| + return static_cast<NegotiateFlags>(static_cast<TFlagsInt>(lhs) & |
| + static_cast<TFlagsInt>(rhs)); |
| +} |
| + |
| +static constexpr uint8_t SIGNATURE[] = "NTLMSSP"; |
| +static constexpr size_t SIGNATURE_LEN = arraysize(SIGNATURE); |
| +static constexpr size_t SECURITY_BUFFER_LEN = |
| + (2 * sizeof(uint16_t)) + sizeof(uint32_t); |
| +static constexpr size_t NEGOTIATE_MESSAGE_LEN = 32; |
| +static constexpr size_t RESPONSE_V1_LEN = 24; |
| +static constexpr size_t CHALLENGE_LEN = 8; |
| +static constexpr size_t NTLM_HASH_LEN = 16; |
| + |
| +static constexpr NegotiateFlags NEGOTIATE_MESSAGE_FLAGS = |
| + NegotiateFlags::UNICODE | NegotiateFlags::OEM | |
| + NegotiateFlags::REQUEST_TARGET | NegotiateFlags::NTLM | |
| + NegotiateFlags::ALWAYS_SIGN | NegotiateFlags::EXTENDED_SESSIONSECURITY; |
| + |
| +} // namespace ntlm |
| +} // namespace net |
| + |
| +#endif // NET_BASE_NTLM_H_ |