File: attestation_flow_adaptive.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; 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,806; 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 (118 lines) | stat: -rw-r--r-- 4,818 bytes parent folder | download | duplicates (8)
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
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_ATTESTATION_ATTESTATION_FLOW_ADAPTIVE_H_
#define CHROMEOS_ASH_COMPONENTS_ATTESTATION_ATTESTATION_FLOW_ADAPTIVE_H_

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

#include "base/component_export.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/ash/components/attestation/attestation_flow.h"
#include "chromeos/ash/components/attestation/attestation_flow_factory.h"
#include "chromeos/ash/components/attestation/attestation_flow_status_reporter.h"
#include "chromeos/ash/components/attestation/attestation_flow_type_decider.h"
#include "chromeos/ash/components/dbus/attestation/interface.pb.h"
#include "chromeos/ash/components/dbus/constants/attestation_constants.h"
#include "components/account_id/account_id.h"

namespace ash {
namespace attestation {

// An attestation flow that adaptively chooses the preferred attestation flow
// object to perform the attestation flow, and falls back to the legacy
// attestation if the default (platform-side integrated) attestation flow fails.
class COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_ATTESTATION)
    AttestationFlowAdaptive : public AttestationFlow {
 public:
  explicit AttestationFlowAdaptive(std::unique_ptr<ServerProxy> server_proxy);

  // A constructor that injects the type decider and the factory. Used for
  // testing.
  AttestationFlowAdaptive(
      std::unique_ptr<ServerProxy> server_proxy,
      std::unique_ptr<AttestationFlowTypeDecider> type_decider,
      std::unique_ptr<AttestationFlowFactory> factory);

  ~AttestationFlowAdaptive() override;

  void GetCertificate(
      AttestationCertificateProfile certificate_profile,
      const AccountId& account_id,
      const std::string& request_origin,
      bool force_new_key,
      ::attestation::KeyType key_crypto_type,
      const std::string& key_name,
      const std::optional<AttestationFlow::CertProfileSpecificData>&
          profile_specific_data,
      CertificateCallback callback) override;

 private:
  // The collection of parameters of `GetCertificate()` except for the callback.
  struct GetCertificateParams;

  // Called when the validity of the default attestation flow is checked.
  // Performs actions for verbosity, e.g., logging, before invoking
  // `StartGetCertificate()`.
  void OnCheckAttestationFlowType(
      const GetCertificateParams& params,
      std::unique_ptr<AttestationFlowStatusReporter> status_reporter,
      CertificateCallback callback,
      bool is_integrated_flow_possible);

  // Starts the default attestation flow if valid, otherwise just use the
  // fallback flow.
  void StartGetCertificate(
      const GetCertificateParams& params,
      std::unique_ptr<AttestationFlowStatusReporter> status_reporter,
      CertificateCallback callback,
      bool is_default_flow_valid);

  // Initialize the factory if needed. This can be called multiple times. This
  // function is designed to be idempotent.
  void InitializeAttestationFlowFactory();

  // Called when the default attestation flow returns the result. Runs
  // `callback` if the flow succeeds; otherwise, try the fallback.
  void OnGetCertificateWithDefaultFlow(
      const GetCertificateParams& params,
      std::unique_ptr<AttestationFlowStatusReporter> status_reporter,
      CertificateCallback callback,
      AttestationStatus status,
      const std::string& pem_certificate_chain);

  // Called when the fallback flow returns the result.
  void OnGetCertificateWithFallbackFlow(
      std::unique_ptr<AttestationFlowStatusReporter> status_reporter,
      CertificateCallback callback,
      AttestationStatus status,
      const std::string& pem_certificate_chain);

  // If `true`, the `InitializeAttestationFlowFactory()` performs no-ops.
  bool is_attestation_flow_initialized_ = false;

  // `ServerProxy` object passed during construction. Used by the type decider
  // to gather proxy information, and the attestation flow factory to
  // initialize.
  std::unique_ptr<ServerProxy> server_proxy_;
  // Owened by either `server_proxy_` or `attestation_flow_factory_`.
  const raw_ptr<ServerProxy, DanglingUntriaged> raw_server_proxy_;

  // `AttestationFlowTypeDecider` object that decides which attestation flow
  // type we can use.
  std::unique_ptr<AttestationFlowTypeDecider> attestation_flow_type_decider_;

  // The factory that creates the attestation flow objects.
  std::unique_ptr<AttestationFlowFactory> attestation_flow_factory_;

  base::WeakPtrFactory<AttestationFlowAdaptive> weak_factory_{this};
};

}  // namespace attestation
}  // namespace ash

#endif  // CHROMEOS_ASH_COMPONENTS_ATTESTATION_ATTESTATION_FLOW_ADAPTIVE_H_