Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / components / proximity_auth / device_to_device_secure_context.h
blob62e3296ddea99be918e154d77e1b4f2739bf0be7
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_DEVICE_TO_DEVICE_SECURE_CONTEXT_H
6 #define COMPONENTS_PROXIMITY_AUTH_DEVICE_TO_DEVICE_SECURE_CONTEXT_H
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "components/proximity_auth/secure_context.h"
13 namespace securemessage {
14 class Header;
17 namespace proximity_auth {
19 class SecureMessageDelegate;
21 // SecureContext implementation for the DeviceToDevice protocol.
22 class DeviceToDeviceSecureContext : public SecureContext {
23 public:
24 DeviceToDeviceSecureContext(
25 scoped_ptr<SecureMessageDelegate> secure_message_delegate,
26 const std::string& symmetric_key,
27 const std::string& responder_auth_message_,
28 ProtocolVersion protocol_version);
30 ~DeviceToDeviceSecureContext() override;
32 // SecureContext:
33 void Decode(const std::string& encoded_message,
34 const MessageCallback& callback) override;
35 void Encode(const std::string& message,
36 const MessageCallback& callback) override;
37 ProtocolVersion GetProtocolVersion() const override;
39 // Returns the message received from the remote device that authenticates it.
40 // This message should have been received during the handshake that
41 // establishes the secure channel.
42 std::string GetReceivedAuthMessage() const;
44 private:
45 // Callback for unwrapping a secure message. |callback| will be invoked with
46 // the decrypted payload if the message is unwrapped successfully; otherwise
47 // it will be invoked with an empty string.
48 void HandleUnwrapResult(
49 const DeviceToDeviceSecureContext::MessageCallback& callback,
50 bool verified,
51 const std::string& payload,
52 const securemessage::Header& header);
54 // Delegate for handling the creation and unwrapping of SecureMessages.
55 scoped_ptr<SecureMessageDelegate> secure_message_delegate_;
57 // The symmetric key used to create and unwrap messages.
58 const std::string symmetric_key_;
60 // The [Responder Auth] message received from the remote device during
61 // authentication.
62 const std::string responder_auth_message_;
64 // The protocol version supported by the remote device.
65 const ProtocolVersion protocol_version_;
67 // The last sequence number of the message sent or received.
68 int last_sequence_number_;
70 base::WeakPtrFactory<DeviceToDeviceSecureContext> weak_ptr_factory_;
72 DISALLOW_COPY_AND_ASSIGN(DeviceToDeviceSecureContext);
75 } // namespace proximity_auth
77 #endif // COMPONENTS_PROXIMITY_AUTH_DEVICE_TO_DEVICE_SECURE_CONTEXT_H