OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_ENROLLER_IMPL_H | |
6 #define COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_ENROLLER_IMPL_H | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "components/proximity_auth/cryptauth/cryptauth_enroller.h" | |
14 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" | |
15 | |
16 namespace proximity_auth { | |
17 | |
18 class CryptAuthClient; | |
19 class CryptAuthClientFactory; | |
20 class CryptAuthClientFactoryImpl; | |
21 class SecureMessageDelegate; | |
22 | |
23 // Implementation of CryptAuthEnroller to perform enrollment in two steps: | |
24 // 1. SetupEnrollment: | |
25 // Obtain a session public key from CryptAuth used to encrypt enrollment | |
26 // data. Generate an ephemeral public key and derive a session symmetric | |
27 // key. | |
28 // 2. FinishEnrollment: | |
29 // Encrypt the enrollment data with the session symmetric key, and send the | |
30 // payload and device's public key to CryptAuth. | |
31 class CryptAuthEnrollerImpl : public CryptAuthEnroller { | |
32 public: | |
33 // |client_factory| creates CryptAuthClient instances for making API calls. | |
34 // |crypto_delegate| is responsible for SecureMessage operations. | |
35 CryptAuthEnrollerImpl( | |
36 std::unique_ptr<CryptAuthClientFactory> client_factory, | |
37 std::unique_ptr<SecureMessageDelegate> secure_message_delegate); | |
38 ~CryptAuthEnrollerImpl() override; | |
39 | |
40 // CryptAuthEnroller: | |
41 void Enroll(const std::string& user_public_key, | |
42 const std::string& user_private_key, | |
43 const cryptauth::GcmDeviceInfo& device_info, | |
44 cryptauth::InvocationReason invocation_reason, | |
45 const EnrollmentFinishedCallback& callback) override; | |
46 | |
47 private: | |
48 // Callbacks for SetupEnrollment. | |
49 void OnSetupEnrollmentSuccess( | |
50 const cryptauth::SetupEnrollmentResponse& response); | |
51 void OnSetupEnrollmentFailure(const std::string& error); | |
52 | |
53 // Callbacks for FinishEnrollment. | |
54 void OnFinishEnrollmentSuccess( | |
55 const cryptauth::FinishEnrollmentResponse& response); | |
56 void OnFinishEnrollmentFailure(const std::string& error); | |
57 | |
58 // Callbacks for SecureMessageDelegate operations. | |
59 void OnKeyPairGenerated(const std::string& public_key, | |
60 const std::string& private_key); | |
61 void OnKeyDerived(const std::string& symmetric_key); | |
62 void OnInnerSecureMessageCreated(const std::string& inner_message); | |
63 void OnOuterSecureMessageCreated(const std::string& outer_message); | |
64 | |
65 // Creates the CryptAuthClient instances to make API requests. | |
66 std::unique_ptr<CryptAuthClientFactory> client_factory_; | |
67 | |
68 // Handles SecureMessage operations. | |
69 std::unique_ptr<SecureMessageDelegate> secure_message_delegate_; | |
70 | |
71 // The CryptAuthClient for the latest request. | |
72 std::unique_ptr<CryptAuthClient> cryptauth_client_; | |
73 | |
74 // The ephemeral key-pair generated for a single enrollment. | |
75 std::string session_public_key_; | |
76 std::string session_private_key_; | |
77 | |
78 // The user's persistent key-pair identifying the local device. | |
79 std::string user_public_key_; | |
80 std::string user_private_key_; | |
81 | |
82 // Contains information of the device to enroll. | |
83 cryptauth::GcmDeviceInfo device_info_; | |
84 | |
85 // The reason telling the server why the enrollment happened. | |
86 cryptauth::InvocationReason invocation_reason_; | |
87 | |
88 // The setup information returned from the SetupEnrollment API call. | |
89 cryptauth::SetupEnrollmentInfo setup_info_; | |
90 | |
91 // Callback invoked when the enrollment is done. | |
92 EnrollmentFinishedCallback callback_; | |
93 | |
94 // The derived ephemeral symmetric key. | |
95 std::string symmetric_key_; | |
96 | |
97 base::WeakPtrFactory<CryptAuthEnrollerImpl> weak_ptr_factory_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(CryptAuthEnrollerImpl); | |
100 }; | |
101 | |
102 } // namespace proximity_auth | |
103 | |
104 #endif // COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_ENROLLER_IMPL_H | |
OLD | NEW |