userver: userver/server/handlers/auth/digest/standalone_checker.hpp Source File
Loading...
Searching...
No Matches
standalone_checker.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/handlers/auth/digest/standalone_checker.hpp
4/// @brief @copybrief server::handlers::auth::digest::AuthStandaloneCheckerBase
5
6#include <chrono>
7#include <cstdint>
8#include <functional>
9#include <random>
10#include <string_view>
11
12#include <userver/cache/expirable_lru_cache.hpp>
13#include <userver/concurrent/mpsc_queue.hpp>
14#include <userver/concurrent/variable.hpp>
15#include <userver/crypto/hash.hpp>
16#include <userver/rcu/rcu_map.hpp>
17#include <userver/server/handlers/auth/digest/auth_checker_base.hpp>
18#include <userver/server/handlers/auth/digest/auth_checker_settings.hpp>
19#include <userver/server/handlers/auth/digest/directives_parser.hpp>
20#include <userver/server/http/http_request.hpp>
21#include <userver/server/http/http_response.hpp>
22#include <userver/server/http/http_status.hpp>
23#include <userver/server/request/request_context.hpp>
24
25USERVER_NAMESPACE_BEGIN
26
27namespace server::handlers::auth::digest {
28
29struct NonceInfo final {
30 NonceInfo();
31 NonceInfo(const std::string& nonce, TimePoint expiration_time, std::int64_t nonce_count);
32 std::string nonce;
33 TimePoint expiration_time;
34 std::int64_t nonce_count;
35};
36
37/// @ingroup userver_base_classes
38///
39/// @brief Class for digest authentication checker. Implements a stand-alone
40/// digest-authentication logic.
42public:
43 AuthStandaloneCheckerBase(
44 const AuthCheckerSettings& digest_settings,
45 std::string&& realm,
46 const SecdistConfig& secdist_config,
47 std::size_t ways,
48 std::size_t way_size
49 );
50
51 [[nodiscard]] bool SupportsUserAuth() const noexcept override { return true; }
52
53 std::optional<UserData> FetchUserData(const std::string& username) const override;
55 const std::string& username,
56 const std::string& nonce,
57 std::int64_t nonce_count,
58 TimePoint nonce_creation_time
59 ) const override;
60
61 void PushUnnamedNonce(std::string nonce) const override;
63
64 virtual std::optional<UserData::HA1> GetHA1(std::string_view username) const = 0;
65
66private:
68 // potentially we store ALL user's data
69 // great chance to occupy large block of memory
70 mutable rcu::RcuMap<std::string, concurrent::Variable<NonceInfo>> user_data_;
71 // cache for "unnamed" nonces,
72 // i.e initial nonces not tied to any user
73 mutable NonceCache unnamed_nonces_;
74};
75
76} // namespace server::handlers::auth::digest
77
78USERVER_NAMESPACE_END