• 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_REGISTRATION_FETCHER_PARAM_H_
6 #define NET_DEVICE_BOUND_SESSIONS_REGISTRATION_FETCHER_PARAM_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/containers/span.h"
12 #include "crypto/signature_verifier.h"
13 #include "net/base/net_export.h"
14 #include "net/http/http_response_headers.h"
15 #include "net/http/structured_headers.h"
16 #include "url/gurl.h"
17 
18 namespace net::device_bound_sessions {
19 
20 // Class to parse Sec-Session-Registration header.
21 // See explainer for details:
22 // https://github.com/WICG/dbsc/blob/main/README.md#start-session
23 // The header format for the session registration is a list of
24 // algorithm tokens, the list have two parameters, one is a string
25 // representing the challenge, the other is a string representing
26 // the path. Example:
27 // (RS256 ES256);path="start";challenge="code"
28 class NET_EXPORT RegistrationFetcherParam {
29  public:
30   RegistrationFetcherParam(RegistrationFetcherParam&& other);
31   RegistrationFetcherParam& operator=(
32       RegistrationFetcherParam&& other) noexcept;
33 
34   // Disabled to make accidental copies compile errors.
35   RegistrationFetcherParam(const RegistrationFetcherParam& other) = delete;
36   RegistrationFetcherParam& operator=(const RegistrationFetcherParam&) = delete;
37   ~RegistrationFetcherParam();
38 
39   // Returns a vector of valid instances.
40   // TODO(chlily): Get IsolationInfo from the request as well
41   static std::vector<RegistrationFetcherParam> CreateIfValid(
42       const GURL& request_url,
43       const HttpResponseHeaders* headers);
44 
45   // Convenience constructor for testing.
46   static RegistrationFetcherParam CreateInstanceForTesting(
47       GURL registration_endpoint,
48       std::vector<crypto::SignatureVerifier::SignatureAlgorithm>
49           supported_algos,
50       std::string challenge,
51       std::optional<std::string> authorization);
52 
registration_endpoint()53   const GURL& registration_endpoint() const { return registration_endpoint_; }
54 
55   base::span<const crypto::SignatureVerifier::SignatureAlgorithm>
supported_algos()56   supported_algos() const {
57     return supported_algos_;
58   }
59 
challenge()60   const std::string& challenge() const { return challenge_; }
61 
authorization()62   const std::optional<std::string>& authorization() const {
63     return authorization_;
64   }
65 
TakeRegistrationEndpoint()66   GURL TakeRegistrationEndpoint() { return std::move(registration_endpoint_); }
67 
TakeChallenge()68   std::string TakeChallenge() { return std::move(challenge_); }
69 
TakeAuthorization()70   std::optional<std::string> TakeAuthorization() {
71     return std::move(authorization_);
72   }
73 
74  private:
75   RegistrationFetcherParam(
76       GURL registration_endpoint,
77       std::vector<crypto::SignatureVerifier::SignatureAlgorithm>
78           supported_algos,
79       std::string challenge,
80       std::optional<std::string> authorization);
81 
82   static std::optional<RegistrationFetcherParam> ParseItem(
83       const GURL& request_url,
84       const structured_headers::ParameterizedMember& session_registration);
85 
86   // TODO(chlily): Store last-updated time and last-updated isolationinfo as
87   // needed.
88   GURL registration_endpoint_;
89   std::vector<crypto::SignatureVerifier::SignatureAlgorithm> supported_algos_;
90   std::string challenge_;
91   std::optional<std::string> authorization_;
92 };
93 
94 }  // namespace net::device_bound_sessions
95 
96 #endif  // NET_DEVICE_BOUND_SESSIONS_REGISTRATION_FETCHER_PARAM_H_
97