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