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