• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_DEVICE_BOUND_SESSIONS_SESSION_CHALLENGE_PARAM_H_
6 #define NET_DEVICE_BOUND_SESSIONS_SESSION_CHALLENGE_PARAM_H_
7 
8 #include <optional>
9 #include <string>
10 #include <vector>
11 
12 #include "net/base/net_export.h"
13 #include "net/http/structured_headers.h"
14 
15 // Forward declarations.
16 class GURL;
17 namespace net {
18 class HttpResponseHeaders;
19 }
20 
21 namespace net::device_bound_sessions {
22 
23 // Class to parse Sec-Session-Challenge header.
24 // See explainer for details:
25 // https://github.com/WICG/dbsc/blob/main/README.md.
26 // It is a RFC 8941 list of challenges for the associated DBSC sessions.
27 // Example:
28 // Sec-Session-Challenge: "challenge";id="session_id".
29 // Sec-Session-Challenge: "challenge";id="session_id", "challenge1";id="id1".
30 // The session id may be unknown during the session registration, hence it can
31 // be omitted:
32 // Sec-Session-Challenge: "challenge".
33 // It is possible to have multiple Sec-Session-Challenge headers in
34 // one response. If multiple challenges are given for one specific session,
35 // the last one will take effect.
36 class NET_EXPORT SessionChallengeParam {
37  public:
38   SessionChallengeParam(SessionChallengeParam&& other) noexcept;
39   SessionChallengeParam& operator=(SessionChallengeParam&& other) noexcept;
40 
41   ~SessionChallengeParam();
42 
43   // Returns a vector of valid instances from the headers.
44   static std::vector<SessionChallengeParam> CreateIfValid(
45       const GURL& request_url,
46       const HttpResponseHeaders* headers);
47 
session_id()48   const std::optional<std::string>& session_id() const { return session_id_; }
challenge()49   const std::string& challenge() const { return challenge_; }
50 
51  private:
52   SessionChallengeParam(std::optional<std::string> session_id,
53                         std::string challenge);
54 
55   static std::optional<SessionChallengeParam> ParseItem(
56       const structured_headers::ParameterizedMember& session_challenge);
57 
58   std::optional<std::string> session_id_;
59   std::string challenge_;
60 };
61 }  // namespace net::device_bound_sessions
62 
63 #endif  // NET_DEVICE_BOUND_SESSIONS_SESSION_CHALLENGE_PARAM_H_
64