Roll src/third_party/skia 99c7c07:4af6580
[chromium-blink-merge.git] / components / proximity_auth / cryptauth / cryptauth_enroller_impl.h
blob07da5ed4474638e26799e8f2d8538e398bad3fdb
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"
14 namespace proximity_auth {
16 class CryptAuthClient;
17 class CryptAuthClientFactory;
18 class SecureMessageDelegate;
20 // Implementation of CryptAuthEnroller to perform enrollment in two steps:
21 // 1. SetupEnrollment:
22 // Obtain a session public key from CryptAuth used to encrypt enrollment
23 // data. Generate an ephemeral public key and derive a session symmetric
24 // key.
25 // 2. FinishEnrollment:
26 // Encrypt the enrollment data with the session symmetric key, and send the
27 // payload and device's public key to CryptAuth.
28 class CryptAuthEnrollerImpl : public CryptAuthEnroller {
29 public:
30 // |client_factory| creates CryptAuthClient instances for making API calls.
31 // |crypto_delegate| is responsible for SecureMessage operations.
32 CryptAuthEnrollerImpl(
33 scoped_ptr<CryptAuthClientFactory> client_factory,
34 scoped_ptr<SecureMessageDelegate> secure_message_delegate_);
35 ~CryptAuthEnrollerImpl();
37 // CryptAuthEnroller:
38 void Enroll(const cryptauth::GcmDeviceInfo& device_info,
39 cryptauth::InvocationReason invocation_reason,
40 const EnrollmentFinishedCallback& callback) override;
42 private:
43 // Callbacks for SetupEnrollment.
44 void OnSetupEnrollmentSuccess(
45 const cryptauth::SetupEnrollmentResponse& response);
46 void OnSetupEnrollmentFailure(const std::string& error);
48 // Callbacks for FinishEnrollment.
49 void OnFinishEnrollmentSuccess(
50 const cryptauth::FinishEnrollmentResponse& response);
51 void OnFinishEnrollmentFailure(const std::string& error);
53 // Callbacks for SecureMessageDelegate operations.
54 void OnKeyPairGenerated(const std::string& public_key,
55 const std::string& private_key);
56 void OnKeyDerived(const std::string& symmetric_key);
57 void OnInnerSecureMessageCreated(const std::string& inner_message);
58 void OnOuterSecureMessageCreated(const std::string& outer_message);
60 // Creates the CryptAuthClient instances to make API requests.
61 scoped_ptr<CryptAuthClientFactory> client_factory_;
63 // Handles SecureMessage operations.
64 scoped_ptr<SecureMessageDelegate> secure_message_delegate_;
66 // The CryptAuthClient for the latest request.
67 scoped_ptr<CryptAuthClient> cryptauth_client_;
69 // The ephemeral key-pair generated for a single enrollment.
70 std::string session_public_key_;
71 std::string session_private_key_;
73 // Contains information of the device to enroll.
74 cryptauth::GcmDeviceInfo device_info_;
76 // The reason telling the server why the enrollment happened.
77 cryptauth::InvocationReason invocation_reason_;
79 // The setup information returned from the SetupEnrollment API call.
80 cryptauth::SetupEnrollmentInfo setup_info_;
82 // Callback invoked when the enrollment is done.
83 EnrollmentFinishedCallback callback_;
85 // The derived ephemeral symmetric key.
86 std::string symmetric_key_;
88 base::WeakPtrFactory<CryptAuthEnrollerImpl> weak_ptr_factory_;
90 DISALLOW_COPY_AND_ASSIGN(CryptAuthEnrollerImpl);
93 } // namespace proximity_auth
95 #endif // COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_ENROLLER_IMPL_H