#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/ntlm/ntlm_client.h"
#include <string.h>
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/logging.h"
#include "base/numerics/safe_math.h"
#include "base/strings/utf_string_conversions.h"
#include "net/ntlm/ntlm.h"
#include "net/ntlm/ntlm_buffer_reader.h"
#include "net/ntlm/ntlm_buffer_writer.h"
#include "net/ntlm/ntlm_constants.h"
namespace net::ntlm {
namespace {
bool ParseChallengeMessage(
base::span<const uint8_t> challenge_message,
NegotiateFlags* challenge_flags,
base::span<uint8_t, kChallengeLen> server_challenge) { … }
bool ParseChallengeMessageV2(
base::span<const uint8_t> challenge_message,
NegotiateFlags* challenge_flags,
base::span<uint8_t, kChallengeLen> server_challenge,
std::vector<AvPair>* av_pairs) { … }
bool WriteAuthenticateMessage(NtlmBufferWriter* authenticate_writer,
SecurityBuffer lm_payload,
SecurityBuffer ntlm_payload,
SecurityBuffer domain_payload,
SecurityBuffer username_payload,
SecurityBuffer hostname_payload,
SecurityBuffer session_key_payload,
NegotiateFlags authenticate_flags) { … }
bool WriteResponsePayloads(
NtlmBufferWriter* authenticate_writer,
base::span<const uint8_t, kResponseLenV1> lm_response,
base::span<const uint8_t, kResponseLenV1> ntlm_response) { … }
bool WriteResponsePayloadsV2(
NtlmBufferWriter* authenticate_writer,
base::span<const uint8_t, kResponseLenV1> lm_response,
base::span<const uint8_t, kNtlmProofLenV2> v2_proof,
base::span<const uint8_t> v2_proof_input,
base::span<const uint8_t> updated_target_info) { … }
bool WriteStringPayloads(NtlmBufferWriter* authenticate_writer,
bool is_unicode,
const std::u16string& domain,
const std::u16string& username,
const std::string& hostname) { … }
size_t GetStringPayloadLength(const std::u16string& str, bool is_unicode) { … }
size_t GetStringPayloadLength(const std::string& str, bool is_unicode) { … }
bool ComputeSecurityBuffer(uint32_t* offset,
size_t length,
SecurityBuffer* buffer) { … }
}
NtlmClient::NtlmClient(NtlmFeatures features)
: … { … }
NtlmClient::~NtlmClient() = default;
std::vector<uint8_t> NtlmClient::GetNegotiateMessage() const { … }
void NtlmClient::GenerateNegotiateMessage() { … }
std::vector<uint8_t> NtlmClient::GenerateAuthenticateMessage(
const std::u16string& domain,
const std::u16string& username,
const std::u16string& password,
const std::string& hostname,
const std::string& channel_bindings,
const std::string& spn,
uint64_t client_time,
base::span<const uint8_t, kChallengeLen> client_challenge,
base::span<const uint8_t> server_challenge_message) const { … }
bool NtlmClient::CalculatePayloadLayout(
bool is_unicode,
const std::u16string& domain,
const std::u16string& username,
const std::string& hostname,
size_t updated_target_info_len,
SecurityBuffer* lm_info,
SecurityBuffer* ntlm_info,
SecurityBuffer* domain_info,
SecurityBuffer* username_info,
SecurityBuffer* hostname_info,
SecurityBuffer* session_key_info,
size_t* authenticate_message_len) const { … }
size_t NtlmClient::GetAuthenticateHeaderLength() const { … }
size_t NtlmClient::GetNtlmResponseLength(size_t updated_target_info_len) const { … }
}