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_DEVICE_TO_DEVICE_SECURE_CONTEXT_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_DEVICE_TO_DEVICE_SECURE_CONTEXT_H |
6 #define COMPONENTS_PROXIMITY_AUTH_DEVICE_TO_DEVICE_SECURE_CONTEXT_H | 6 #define COMPONENTS_PROXIMITY_AUTH_DEVICE_TO_DEVICE_SECURE_CONTEXT_H |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
11 #include "components/proximity_auth/secure_context.h" | 12 #include "components/proximity_auth/secure_context.h" |
12 | 13 |
13 namespace securemessage { | 14 namespace securemessage { |
14 class Header; | 15 class Header; |
15 } | 16 } |
16 | 17 |
17 namespace proximity_auth { | 18 namespace proximity_auth { |
18 | 19 |
19 class SecureMessageDelegate; | 20 class SecureMessageDelegate; |
20 | 21 |
21 // SecureContext implementation for the DeviceToDevice protocol. | 22 // SecureContext implementation for the DeviceToDevice protocol. |
22 class DeviceToDeviceSecureContext : public SecureContext { | 23 class DeviceToDeviceSecureContext : public SecureContext { |
23 public: | 24 public: |
24 DeviceToDeviceSecureContext( | 25 DeviceToDeviceSecureContext( |
25 scoped_ptr<SecureMessageDelegate> secure_message_delegate, | 26 std::unique_ptr<SecureMessageDelegate> secure_message_delegate, |
26 const std::string& symmetric_key, | 27 const std::string& symmetric_key, |
27 const std::string& responder_auth_message_, | 28 const std::string& responder_auth_message_, |
28 ProtocolVersion protocol_version); | 29 ProtocolVersion protocol_version); |
29 | 30 |
30 ~DeviceToDeviceSecureContext() override; | 31 ~DeviceToDeviceSecureContext() override; |
31 | 32 |
32 // SecureContext: | 33 // SecureContext: |
33 void Decode(const std::string& encoded_message, | 34 void Decode(const std::string& encoded_message, |
34 const MessageCallback& callback) override; | 35 const MessageCallback& callback) override; |
35 void Encode(const std::string& message, | 36 void Encode(const std::string& message, |
36 const MessageCallback& callback) override; | 37 const MessageCallback& callback) override; |
37 ProtocolVersion GetProtocolVersion() const override; | 38 ProtocolVersion GetProtocolVersion() const override; |
38 std::string GetChannelBindingData() const override; | 39 std::string GetChannelBindingData() const override; |
39 | 40 |
40 private: | 41 private: |
41 // Callback for unwrapping a secure message. |callback| will be invoked with | 42 // Callback for unwrapping a secure message. |callback| will be invoked with |
42 // the decrypted payload if the message is unwrapped successfully; otherwise | 43 // the decrypted payload if the message is unwrapped successfully; otherwise |
43 // it will be invoked with an empty string. | 44 // it will be invoked with an empty string. |
44 void HandleUnwrapResult( | 45 void HandleUnwrapResult( |
45 const DeviceToDeviceSecureContext::MessageCallback& callback, | 46 const DeviceToDeviceSecureContext::MessageCallback& callback, |
46 bool verified, | 47 bool verified, |
47 const std::string& payload, | 48 const std::string& payload, |
48 const securemessage::Header& header); | 49 const securemessage::Header& header); |
49 | 50 |
50 // Delegate for handling the creation and unwrapping of SecureMessages. | 51 // Delegate for handling the creation and unwrapping of SecureMessages. |
51 scoped_ptr<SecureMessageDelegate> secure_message_delegate_; | 52 std::unique_ptr<SecureMessageDelegate> secure_message_delegate_; |
52 | 53 |
53 // The symmetric key used to create and unwrap messages. | 54 // The symmetric key used to create and unwrap messages. |
54 const std::string symmetric_key_; | 55 const std::string symmetric_key_; |
55 | 56 |
56 // The [Responder Auth] message received from the remote device during | 57 // The [Responder Auth] message received from the remote device during |
57 // authentication. | 58 // authentication. |
58 const std::string responder_auth_message_; | 59 const std::string responder_auth_message_; |
59 | 60 |
60 // The protocol version supported by the remote device. | 61 // The protocol version supported by the remote device. |
61 const ProtocolVersion protocol_version_; | 62 const ProtocolVersion protocol_version_; |
62 | 63 |
63 // The last sequence number of the message sent or received. | 64 // The last sequence number of the message sent or received. |
64 int last_sequence_number_; | 65 int last_sequence_number_; |
65 | 66 |
66 base::WeakPtrFactory<DeviceToDeviceSecureContext> weak_ptr_factory_; | 67 base::WeakPtrFactory<DeviceToDeviceSecureContext> weak_ptr_factory_; |
67 | 68 |
68 DISALLOW_COPY_AND_ASSIGN(DeviceToDeviceSecureContext); | 69 DISALLOW_COPY_AND_ASSIGN(DeviceToDeviceSecureContext); |
69 }; | 70 }; |
70 | 71 |
71 } // namespace proximity_auth | 72 } // namespace proximity_auth |
72 | 73 |
73 #endif // COMPONENTS_PROXIMITY_AUTH_DEVICE_TO_DEVICE_SECURE_CONTEXT_H | 74 #endif // COMPONENTS_PROXIMITY_AUTH_DEVICE_TO_DEVICE_SECURE_CONTEXT_H |
OLD | NEW |