6#include <userver/server/handlers/auth/auth_checker_base.hpp>
14#include <userver/crypto/hash.hpp>
15#include <userver/rcu/rcu_map.hpp>
16#include <userver/server/handlers/auth/digest/auth_checker_settings.hpp>
17#include <userver/server/handlers/auth/digest/directives_parser.hpp>
18#include <userver/server/http/http_request.hpp>
19#include <userver/server/http/http_response.hpp>
20#include <userver/server/http/http_status.hpp>
21#include <userver/server/request/request_context.hpp>
23USERVER_NAMESPACE_BEGIN
25namespace server::handlers::
auth::digest {
27using TimePoint = std::chrono::time_point<std::chrono::system_clock>;
42 std::string
GetHash(std::string_view data)
const;
45 using HashAlgorithm = std::function<std::string(
46 std::string_view, crypto::hash::OutputEncoding)>;
47 HashAlgorithm hash_algorithm_;
51struct UserData
final {
52 using HA1 = utils::NonLoggable<
class HA1Tag, std::string>;
54 UserData(HA1 ha1, std::string nonce, TimePoint timestamp,
55 std::int64_t nonce_count);
60 std::int64_t nonce_count{};
80 ~AuthCheckerBase()
override;
84 const http::HttpRequest& request,
85 request::RequestContext& request_context)
const final;
95 const std::string& username)
const = 0;
99 const std::string& nonce, std::int64_t nonce_count,
100 TimePoint nonce_creation_time)
const = 0;
110 enum class ValidateResult { kOk, kWrongUserData, kDuplicateRequest };
112 const UserData& user_data)
const;
115 std::string CalculateDigest(
const UserData::HA1& ha1_non_loggable,
120 std::string_view etag)
const;
122 std::string ConstructResponseDirectives(std::string_view nonce,
125 AuthCheckResult StartNewAuthSession(std::string username, std::string&& nonce,
127 http::HttpResponse& response)
const;
129 const std::string qops_;
130 const std::string realm_;
131 const std::string domains_;
132 std::string_view algorithm_;
133 const bool is_session_;
134 const bool is_proxy_;
135 const std::chrono::milliseconds nonce_ttl_;
137 const Hasher digest_hasher_;
139 const std::string authenticate_header_;
140 const std::string authorization_header_;
141 const std::string authenticate_info_header_;