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