| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 REMOTING_PROTOCOL_JINGLE_SESSION_H_ | 5 #ifndef REMOTING_PROTOCOL_JINGLE_SESSION_H_ |
| 6 #define REMOTING_PROTOCOL_JINGLE_SESSION_H_ | 6 #define REMOTING_PROTOCOL_JINGLE_SESSION_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "crypto/rsa_private_key.h" | |
| 11 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| 12 #include "remoting/protocol/session.h" | 11 #include "remoting/protocol/session.h" |
| 13 #include "third_party/libjingle/source/talk/base/sigslot.h" | 12 #include "third_party/libjingle/source/talk/base/sigslot.h" |
| 14 #include "third_party/libjingle/source/talk/p2p/base/session.h" | 13 #include "third_party/libjingle/source/talk/p2p/base/session.h" |
| 15 | 14 |
| 16 namespace remoting { | 15 namespace remoting { |
| 17 | |
| 18 namespace protocol { | 16 namespace protocol { |
| 19 | 17 |
| 18 class Authenticator; |
| 20 class JingleChannelConnector; | 19 class JingleChannelConnector; |
| 21 class JingleSessionManager; | 20 class JingleSessionManager; |
| 22 | 21 |
| 23 // Implements protocol::Session that work over libjingle session (the | 22 // Implements protocol::Session that work over libjingle session (the |
| 24 // cricket::Session object is passed to Init() method). Created | 23 // cricket::Session object is passed to Init() method). Created |
| 25 // by JingleSessionManager for incoming and outgoing connections. | 24 // by JingleSessionManager for incoming and outgoing connections. |
| 26 class JingleSession : public protocol::Session, | 25 class JingleSession : public protocol::Session, |
| 27 public sigslot::has_slots<> { | 26 public sigslot::has_slots<> { |
| 28 public: | 27 public: |
| 29 // Session interface. | 28 // Session interface. |
| 30 virtual void SetStateChangeCallback( | 29 virtual void SetStateChangeCallback( |
| 31 const StateChangeCallback& callback) OVERRIDE; | 30 const StateChangeCallback& callback) OVERRIDE; |
| 32 virtual Error error() OVERRIDE; | 31 virtual Error error() OVERRIDE; |
| 33 virtual void CreateStreamChannel( | 32 virtual void CreateStreamChannel( |
| 34 const std::string& name, | 33 const std::string& name, |
| 35 const StreamChannelCallback& callback) OVERRIDE; | 34 const StreamChannelCallback& callback) OVERRIDE; |
| 36 virtual void CreateDatagramChannel( | 35 virtual void CreateDatagramChannel( |
| 37 const std::string& name, | 36 const std::string& name, |
| 38 const DatagramChannelCallback& callback) OVERRIDE; | 37 const DatagramChannelCallback& callback) OVERRIDE; |
| 39 virtual void CancelChannelCreation(const std::string& name) OVERRIDE; | 38 virtual void CancelChannelCreation(const std::string& name) OVERRIDE; |
| 40 virtual const std::string& jid() OVERRIDE; | 39 virtual const std::string& jid() OVERRIDE; |
| 41 virtual const CandidateSessionConfig* candidate_config() OVERRIDE; | 40 virtual const CandidateSessionConfig* candidate_config() OVERRIDE; |
| 42 virtual const SessionConfig& config() OVERRIDE; | 41 virtual const SessionConfig& config() OVERRIDE; |
| 43 virtual void set_config(const SessionConfig& config) OVERRIDE; | 42 virtual void set_config(const SessionConfig& config) OVERRIDE; |
| 44 virtual const std::string& initiator_token() OVERRIDE; | |
| 45 virtual void set_initiator_token(const std::string& initiator_token) OVERRIDE; | |
| 46 virtual const std::string& receiver_token() OVERRIDE; | |
| 47 virtual void set_receiver_token(const std::string& receiver_token) OVERRIDE; | |
| 48 virtual void set_shared_secret(const std::string& secret) OVERRIDE; | |
| 49 virtual const std::string& shared_secret() OVERRIDE; | |
| 50 virtual void Close() OVERRIDE; | 43 virtual void Close() OVERRIDE; |
| 51 | 44 |
| 52 private: | 45 private: |
| 53 friend class JingleDatagramConnector; | 46 friend class JingleDatagramConnector; |
| 54 friend class JingleSessionManager; | 47 friend class JingleSessionManager; |
| 55 friend class JingleStreamConnector; | 48 friend class JingleStreamConnector; |
| 56 | 49 |
| 57 typedef std::map<std::string, JingleChannelConnector*> ChannelConnectorsMap; | 50 typedef std::map<std::string, JingleChannelConnector*> ChannelConnectorsMap; |
| 58 | 51 |
| 59 // Create a JingleSession used in client mode. A server certificate is | 52 // Takes ownership of |authenticator|. |
| 60 // required. | |
| 61 static JingleSession* CreateClientSession(JingleSessionManager* manager, | |
| 62 const std::string& host_public_key); | |
| 63 | |
| 64 // Create a JingleSession used in server mode. A server certificate and | |
| 65 // private key is provided. |key| is copied in the constructor. | |
| 66 // | |
| 67 // TODO(sergeyu): Remove |certificate| and |key| when we stop using TLS. | |
| 68 static JingleSession* CreateServerSession( | |
| 69 JingleSessionManager* manager, | |
| 70 const std::string& certificate, | |
| 71 crypto::RSAPrivateKey* key); | |
| 72 | |
| 73 // TODO(sergeyu): Change type of |peer_public_key| to RSAPublicKey. | |
| 74 JingleSession(JingleSessionManager* jingle_session_manager, | 53 JingleSession(JingleSessionManager* jingle_session_manager, |
| 75 const std::string& local_cert, | 54 cricket::Session* cricket_session, |
| 76 crypto::RSAPrivateKey* local_private_key, | 55 Authenticator* authenticator); |
| 77 const std::string& peer_public_key); | |
| 78 virtual ~JingleSession(); | 56 virtual ~JingleSession(); |
| 79 | 57 |
| 80 // Called by JingleSessionManager. | 58 // Called by JingleSessionManager. |
| 81 void set_candidate_config(const CandidateSessionConfig* candidate_config); | 59 void set_candidate_config(const CandidateSessionConfig* candidate_config); |
| 82 const std::string& local_certificate() const; | 60 |
| 83 void Init(cricket::Session* cricket_session); | 61 // Sends session-initiate for new session. |
| 62 void SendSessionInitiate(); |
| 84 | 63 |
| 85 // Close all the channels and terminate the session. |result| | 64 // Close all the channels and terminate the session. |result| |
| 86 // defines error code that should returned to currently opened | 65 // defines error code that should returned to currently opened |
| 87 // channels. |error| specified new value for error(). | 66 // channels. |error| specified new value for error(). |
| 88 void CloseInternal(int result, Error error); | 67 void CloseInternal(int result, Error error); |
| 89 | 68 |
| 90 bool HasSession(cricket::Session* cricket_session); | 69 bool HasSession(cricket::Session* cricket_session); |
| 91 cricket::Session* ReleaseSession(); | 70 cricket::Session* ReleaseSession(); |
| 92 | 71 |
| 93 // Initialize the session configuration from a received connection response | 72 // Initialize the session configuration from a received connection response |
| (...skipping 22 matching lines...) Expand all Loading... |
| 116 // Called by JingleChannelConnector when it has finished connecting | 95 // Called by JingleChannelConnector when it has finished connecting |
| 117 // the channel, to remove itself from the table of pending connectors. The | 96 // the channel, to remove itself from the table of pending connectors. The |
| 118 // connector assumes responsibility for destroying itself after this call. | 97 // connector assumes responsibility for destroying itself after this call. |
| 119 void OnChannelConnectorFinished(const std::string& name, | 98 void OnChannelConnectorFinished(const std::string& name, |
| 120 JingleChannelConnector* connector); | 99 JingleChannelConnector* connector); |
| 121 | 100 |
| 122 const cricket::ContentInfo* GetContentInfo() const; | 101 const cricket::ContentInfo* GetContentInfo() const; |
| 123 | 102 |
| 124 void SetState(State new_state); | 103 void SetState(State new_state); |
| 125 | 104 |
| 105 static cricket::SessionDescription* CreateSessionDescription( |
| 106 const CandidateSessionConfig* candidate_config, |
| 107 const buzz::XmlElement* authenticator_message); |
| 108 |
| 126 // JingleSessionManager that created this session. Guaranteed to | 109 // JingleSessionManager that created this session. Guaranteed to |
| 127 // exist throughout the lifetime of the session. | 110 // exist throughout the lifetime of the session. |
| 128 JingleSessionManager* jingle_session_manager_; | 111 JingleSessionManager* jingle_session_manager_; |
| 129 | 112 |
| 130 // Certificates used for connection. Currently only receiving side | 113 scoped_ptr<Authenticator> authenticator_; |
| 131 // has a certificate. | |
| 132 std::string local_cert_; | |
| 133 std::string remote_cert_; | |
| 134 | |
| 135 // Private key used in SSL server sockets. | |
| 136 scoped_ptr<crypto::RSAPrivateKey> local_private_key_; | |
| 137 | |
| 138 // Public key of the peer. | |
| 139 std::string peer_public_key_; | |
| 140 | |
| 141 // Shared secret to use in channel authentication. This is currently only | |
| 142 // used in IT2Me. | |
| 143 std::string shared_secret_; | |
| 144 | 114 |
| 145 State state_; | 115 State state_; |
| 146 StateChangeCallback state_change_callback_; | 116 StateChangeCallback state_change_callback_; |
| 147 | 117 |
| 148 Error error_; | 118 Error error_; |
| 149 | 119 |
| 150 bool closing_; | 120 bool closing_; |
| 151 | 121 |
| 152 // JID of the other side. Set when the connection is initialized, | 122 // JID of the other side. Set when the connection is initialized, |
| 153 // and never changed after that. | 123 // and never changed after that. |
| 154 std::string jid_; | 124 std::string jid_; |
| 155 | 125 |
| 156 // The corresponding libjingle session. | 126 // The corresponding libjingle session. |
| 157 cricket::Session* cricket_session_; | 127 cricket::Session* cricket_session_; |
| 158 | 128 |
| 159 SessionConfig config_; | 129 SessionConfig config_; |
| 160 bool config_set_; | 130 bool config_set_; |
| 161 | 131 |
| 162 std::string initiator_token_; | |
| 163 std::string receiver_token_; | |
| 164 | |
| 165 // These data members are only set on the receiving side. | 132 // These data members are only set on the receiving side. |
| 166 scoped_ptr<const CandidateSessionConfig> candidate_config_; | 133 scoped_ptr<const CandidateSessionConfig> candidate_config_; |
| 167 | 134 |
| 168 // Channels that are currently being connected. | 135 // Channels that are currently being connected. |
| 169 ChannelConnectorsMap channel_connectors_; | 136 ChannelConnectorsMap channel_connectors_; |
| 170 | 137 |
| 171 ScopedRunnableMethodFactory<JingleSession> task_factory_; | 138 ScopedRunnableMethodFactory<JingleSession> task_factory_; |
| 172 | 139 |
| 173 DISALLOW_COPY_AND_ASSIGN(JingleSession); | 140 DISALLOW_COPY_AND_ASSIGN(JingleSession); |
| 174 }; | 141 }; |
| 175 | 142 |
| 176 } // namespace protocol | 143 } // namespace protocol |
| 177 | 144 |
| 178 } // namespace remoting | 145 } // namespace remoting |
| 179 | 146 |
| 180 #endif // REMOTING_PROTOCOL_JINGLE_SESSION_H_ | 147 #endif // REMOTING_PROTOCOL_JINGLE_SESSION_H_ |
| OLD | NEW |