File: rlwe_dmserver_client_impl.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (146 lines) | stat: -rw-r--r-- 5,755 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_POLICY_ENROLLMENT_PSM_RLWE_DMSERVER_CLIENT_IMPL_H_
#define CHROME_BROWSER_ASH_POLICY_ENROLLMENT_PSM_RLWE_DMSERVER_CLIENT_IMPL_H_

#include <memory>
#include <optional>
#include <string>

#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "chrome/browser/ash/policy/enrollment/auto_enrollment_state.h"
#include "chrome/browser/ash/policy/enrollment/psm/rlwe_dmserver_client.h"
#include "components/policy/core/common/cloud/device_management_service.h"
#include "components/policy/core/common/cloud/dmserver_job_configurations.h"
#include "components/policy/core/common/cloud/enterprise_metrics.h"
#include "third_party/private_membership/src/private_membership_rlwe.pb.h"

namespace network {
class SharedURLLoaderFactory;
}  // namespace network

namespace private_membership::rlwe {
class PrivateMembershipRlweClient;
}  // namespace private_membership::rlwe

namespace policy::psm {

class RlweDmserverClientImpl : public RlweDmserverClient {
 public:
  using PlaintextId = private_membership::rlwe::RlwePlaintextId;
  using OprfResponse =
      private_membership::rlwe::PrivateMembershipRlweOprfResponse;
  using RlweClient = private_membership::rlwe::PrivateMembershipRlweClient;
  using RlweClientFactory = base::RepeatingCallback<std::unique_ptr<RlweClient>(
      private_membership::rlwe::RlweUseCase,
      const private_membership::rlwe::RlwePlaintextId&)>;

  // Creates PSM RLWE client that generates and holds a randomly generated
  // key.
  static std::unique_ptr<RlweClient> Create(
      private_membership::rlwe::RlweUseCase use_case,
      const PlaintextId& plaintext_id);

  // `device_management_service`, `url_loader_factory`.
  // `device_management_service` must outlive RlweDmserverClientImpl.
  // `rlwe_client_factory` must be callable and must not yield nullptr.
  RlweDmserverClientImpl(
      DeviceManagementService* device_management_service,
      scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
      const PlaintextId& plaintext_id,
      RlweClientFactory rlwe_client_factory);

  // Disallow copy constructor and assignment operator.
  RlweDmserverClientImpl(const RlweDmserverClientImpl&) = delete;
  RlweDmserverClientImpl& operator=(const RlweDmserverClientImpl&) = delete;

  // Cancels the ongoing PSM operation, if any (without calling the operation's
  // callbacks).
  ~RlweDmserverClientImpl() override;

  // Determines membership for the |psm_rlwe_client_|.
  void CheckMembership(CompletionCallback callback) override;

  // Returns true if the PSM protocol is still running,
  // otherwise false.
  bool IsCheckMembershipInProgress() const override;

 private:
  // Records PSM execution result, and stops the protocol.
  void RecordErrorAndStop(ResultHolder result);
  void RecordErrorAndStop(RlweResult result) {
    RecordErrorAndStop(ResultHolder(result));
  }
  void RecordErrorAndStop(AutoEnrollmentDMServerError error) {
    RecordErrorAndStop(ResultHolder(error));
  }

  // Constructs and sends the PSM RLWE OPRF request.
  void SendRlweOprfRequest();

  // If the completion was successful, then it makes another request to
  // DMServer for performing phase two.
  void OnRlweOprfRequestCompletion(DMServerJobResult result);

  // Constructs and sends the PSM RLWE Query request.
  void SendRlweQueryRequest(
      const enterprise_management::PrivateSetMembershipResponse& psm_response);

  // If the completion was successful, then it will parse the result and call
  // the |on_completion_callback_| for |psm_id_|.
  void OnRlweQueryRequestCompletion(const OprfResponse& oprf_response,
                                    DMServerJobResult result);

  // Returns a job config that has TYPE_PSM_REQUEST as job type and |callback|
  // will be executed on completion.
  std::unique_ptr<DMServerJobConfiguration> CreatePsmRequestJobConfiguration(
      DMServerJobConfiguration::Callback callback);

  // Record UMA histogram for timing of successful PSM request.
  void RecordPsmSuccessTimeHistogram();

  // PSM RLWE plaintext id for logging purposes.
  PlaintextId plaintext_id_;

  // PSM RLWE client, used for preparing PSM requests and parsing PSM responses.
  std::unique_ptr<RlweClient> psm_rlwe_client_;

  // Randomly generated device id for the PSM requests.
  std::string random_device_id_;

  // The loader factory to use to perform PSM requests.
  scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;

  // Unowned by RlweDmserverClientImpl. Its used to communicate with the
  // device management service.
  const raw_ptr<DeviceManagementService, DanglingUntriaged>
      device_management_service_;

  // Its being used for both PSM requests e.g. RLWE OPRF request and RLWE query
  // request.
  std::unique_ptr<DeviceManagementService::Job> psm_request_job_;

  // Callback will be triggered upon completing of the protocol.
  CompletionCallback on_completion_callback_;

  // The time when the PSM request started.
  base::TimeTicks time_start_;

  // The UMA histogram suffix. It's set only to ".InitialEnrollment" for an
  // |AutoEnrollmentClient| until PSM will support FRE.
  const std::string uma_suffix_ = kUMASuffixInitialEnrollment;

  // A sequence checker to prevent the race condition of having the possibility
  // of the destructor being called and any of the callbacks.
  SEQUENCE_CHECKER(sequence_checker_);
};

}  // namespace policy::psm

#endif  // CHROME_BROWSER_ASH_POLICY_ENROLLMENT_PSM_RLWE_DMSERVER_CLIENT_IMPL_H_