Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / proximity_auth / cryptauth / cryptauth_enroller_impl.h
blobd34bf30a4d3107b7fca3696e963ab058b0043d1f
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_ENROLLER_IMPL_H
6 #define COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_ENROLLER_IMPL_H
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "components/proximity_auth/cryptauth/cryptauth_enroller.h"
13 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h"
15 namespace proximity_auth {
17 class CryptAuthClient;
18 class CryptAuthClientFactory;
19 class CryptAuthClientFactoryImpl;
20 class SecureMessageDelegate;
22 // Implementation of CryptAuthEnroller to perform enrollment in two steps:
23 // 1. SetupEnrollment:
24 // Obtain a session public key from CryptAuth used to encrypt enrollment
25 // data. Generate an ephemeral public key and derive a session symmetric
26 // key.
27 // 2. FinishEnrollment:
28 // Encrypt the enrollment data with the session symmetric key, and send the
29 // payload and device's public key to CryptAuth.
30 class CryptAuthEnrollerImpl : public CryptAuthEnroller {
31 public:
32 // |client_factory| creates CryptAuthClient instances for making API calls.
33 // |crypto_delegate| is responsible for SecureMessage operations.
34 CryptAuthEnrollerImpl(
35 scoped_ptr<CryptAuthClientFactory> client_factory,
36 scoped_ptr<SecureMessageDelegate> secure_message_delegate);
37 ~CryptAuthEnrollerImpl() override;
39 // CryptAuthEnroller:
40 void Enroll(const std::string& user_public_key,
41 const std::string& user_private_key,
42 const cryptauth::GcmDeviceInfo& device_info,
43 cryptauth::InvocationReason invocation_reason,
44 const EnrollmentFinishedCallback& callback) override;
46 private:
47 // Callbacks for SetupEnrollment.
48 void OnSetupEnrollmentSuccess(
49 const cryptauth::SetupEnrollmentResponse& response);
50 void OnSetupEnrollmentFailure(const std::string& error);
52 // Callbacks for FinishEnrollment.
53 void OnFinishEnrollmentSuccess(
54 const cryptauth::FinishEnrollmentResponse& response);
55 void OnFinishEnrollmentFailure(const std::string& error);
57 // Callbacks for SecureMessageDelegate operations.
58 void OnKeyPairGenerated(const std::string& public_key,
59 const std::string& private_key);
60 void OnKeyDerived(const std::string& symmetric_key);
61 void OnInnerSecureMessageCreated(const std::string& inner_message);
62 void OnOuterSecureMessageCreated(const std::string& outer_message);
64 // Creates the CryptAuthClient instances to make API requests.
65 scoped_ptr<CryptAuthClientFactory> client_factory_;
67 // Handles SecureMessage operations.
68 scoped_ptr<SecureMessageDelegate> secure_message_delegate_;
70 // The CryptAuthClient for the latest request.
71 scoped_ptr<CryptAuthClient> cryptauth_client_;
73 // The ephemeral key-pair generated for a single enrollment.
74 std::string session_public_key_;
75 std::string session_private_key_;
77 // The user's persistent key-pair identifying the local device.
78 std::string user_public_key_;
79 std::string user_private_key_;
81 // Contains information of the device to enroll.
82 cryptauth::GcmDeviceInfo device_info_;
84 // The reason telling the server why the enrollment happened.
85 cryptauth::InvocationReason invocation_reason_;
87 // The setup information returned from the SetupEnrollment API call.
88 cryptauth::SetupEnrollmentInfo setup_info_;
90 // Callback invoked when the enrollment is done.
91 EnrollmentFinishedCallback callback_;
93 // The derived ephemeral symmetric key.
94 std::string symmetric_key_;
96 base::WeakPtrFactory<CryptAuthEnrollerImpl> weak_ptr_factory_;
98 DISALLOW_COPY_AND_ASSIGN(CryptAuthEnrollerImpl);
101 } // namespace proximity_auth
103 #endif // COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_ENROLLER_IMPL_H