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 // Based on [MS-NLMP]: NT LAN Manager (NTLM) Authentication Protocol |
| 6 // Specification version 28.0 [1]. Additional NTLM reference [2]. |
| 7 // |
| 8 // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
| 9 // [2] http://davenport.sourceforge.net/ntlm.html |
| 10 |
| 11 #ifndef NET_BASE_NTLM_CLIENT_H_ |
| 12 #define NET_BASE_NTLM_CLIENT_H_ |
| 13 |
| 14 #include <stddef.h> |
| 15 #include <stdint.h> |
| 16 |
| 17 #include <memory> |
| 18 #include <string> |
| 19 |
| 20 #include "base/strings/string16.h" |
| 21 #include "base/strings/string_piece.h" |
| 22 #include "net/base/net_export.h" |
| 23 #include "net/ntlm/ntlm_constants.h" |
| 24 |
| 25 namespace net { |
| 26 namespace ntlm { |
| 27 |
| 28 // Provides an implementation of an NTLMv1 Client. |
| 29 // |
| 30 // The implementation supports NTLMv1 with extended session security (NTLM2). |
| 31 class NET_EXPORT_PRIVATE NtlmClient { |
| 32 public: |
| 33 NtlmClient(); |
| 34 ~NtlmClient(); |
| 35 |
| 36 // Returns a new buffer containing the Negotiate message that the caller |
| 37 // is responsible for cleaning up. |
| 38 void GetNegotiateMessage(uint8_t** negotiate_message, |
| 39 size_t* negotiate_message_len) const; |
| 40 |
| 41 // Returns a new buffer containing the Authenticate message that the caller |
| 42 // is responsible for cleaning up. |
| 43 bool GenerateAuthenticateMessage(const base::string16& domain, |
| 44 const base::string16& username, |
| 45 const base::string16& password, |
| 46 const std::string& hostname, |
| 47 const uint8_t* client_challenge, |
| 48 const uint8_t* challenge_message, |
| 49 size_t challenge_message_len, |
| 50 uint8_t** authenticate_message, |
| 51 size_t* authenticate_message_len) const; |
| 52 |
| 53 private: |
| 54 // Returns the length of the Authenticate message based on the length of the |
| 55 // variable length parts of the message and whether Unicode support was |
| 56 // negotiated. |
| 57 size_t CalculateAuthenticateMessageLength(bool is_unicode, |
| 58 const base::string16& domain, |
| 59 const base::string16& username, |
| 60 const std::string& hostname) const; |
| 61 |
| 62 void CalculatePayloadSizes(bool is_unicode, |
| 63 const base::string16& domain, |
| 64 const base::string16& username, |
| 65 const std::string& hostname, |
| 66 SecurityBuffer* lm_info, |
| 67 SecurityBuffer* ntlm_info, |
| 68 SecurityBuffer* domain_info, |
| 69 SecurityBuffer* username_info, |
| 70 SecurityBuffer* hostname_info, |
| 71 size_t* authenticate_message_len) const; |
| 72 |
| 73 // Returns the length of the header part of the Authenticate message. |
| 74 // NOTE: When NTLMv2 support is added this is no longer a fixed value. |
| 75 size_t GetAuthenticateHeaderLength() const; |
| 76 |
| 77 // Returns the length of the NTLM response. |
| 78 // NOTE: When NTLMv2 support is added this is no longer a fixed value. |
| 79 size_t GetNtlmResponseLength() const; |
| 80 |
| 81 // Generates the negotiate message (which is always the same) into |
| 82 // |negotiate_message_|. |
| 83 void GenerateNegotiateMessage(); |
| 84 |
| 85 NegotiateFlags negotiate_flags_; |
| 86 std::unique_ptr<uint8_t[]> negotiate_message_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(NtlmClient); |
| 89 }; |
| 90 |
| 91 } // namespace ntlm |
| 92 } // namespace net |
| 93 |
| 94 #endif // NET_BASE_NTLM_CLIENT_H_ |
OLD | NEW |