From f3ecdb981c172cdfafbe92c939eb25ddcc1ae96e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bostr=C3=B6m?= Date: Tue, 8 Sep 2015 12:11:54 +0200 Subject: [PATCH] Replacing SSLIdentity* with scoped_refptr in TransportChannel layer. BUG=webrtc:4927 R=tommi@webrtc.org, torbjorng@webrtc.org Review URL: https://codereview.webrtc.org/1304043008 . Cr-Commit-Position: refs/heads/master@{#9885} --- talk/app/webrtc/statscollector.cc | 2 +- talk/app/webrtc/statscollector_unittest.cc | 2 +- webrtc/p2p/base/dtlstransport.h | 4 +- webrtc/p2p/base/dtlstransportchannel.cc | 25 ++-- webrtc/p2p/base/dtlstransportchannel.h | 95 +++++++------- .../p2p/base/dtlstransportchannel_unittest.cc | 8 +- webrtc/p2p/base/fakesession.h | 118 ++++++++---------- webrtc/p2p/base/p2ptransportchannel.h | 87 +++++++------ webrtc/p2p/base/transport.cc | 8 +- webrtc/p2p/base/transport.h | 4 +- webrtc/p2p/base/transportchannel.h | 7 +- webrtc/p2p/base/transportchannelimpl.h | 7 +- webrtc/p2p/base/transportchannelproxy.cc | 12 +- webrtc/p2p/base/transportchannelproxy.h | 36 +++--- 14 files changed, 199 insertions(+), 216 deletions(-) diff --git a/talk/app/webrtc/statscollector.cc b/talk/app/webrtc/statscollector.cc index 7f5f925b82..a634521ecc 100644 --- a/talk/app/webrtc/statscollector.cc +++ b/talk/app/webrtc/statscollector.cc @@ -714,7 +714,7 @@ void StatsCollector::ExtractSessionInfo() { transport = session_->GetTransport(transport_iter.second.content_name); rtc::scoped_ptr cert; - if (transport && transport->GetRemoteCertificate(cert.accept())) { + if (transport && transport->GetRemoteSSLCertificate(cert.accept())) { StatsReport* r = AddCertificateReports(cert.get()); if (r) remote_cert_report_id = r->id(); diff --git a/talk/app/webrtc/statscollector_unittest.cc b/talk/app/webrtc/statscollector_unittest.cc index fd1ad617af..9950a77b4f 100644 --- a/talk/app/webrtc/statscollector_unittest.cc +++ b/talk/app/webrtc/statscollector_unittest.cc @@ -673,7 +673,7 @@ class StatsCollectorTest : public testing::Test { static_cast( transport->CreateChannel(channel_stats.component)); EXPECT_FALSE(channel == NULL); - channel->SetRemoteCertificate(remote_cert_copy.get()); + channel->SetRemoteSSLCertificate(remote_cert_copy.get()); // Configure MockWebRtcSession EXPECT_CALL(session_, GetTransport(transport_stats.content_name)) diff --git a/webrtc/p2p/base/dtlstransport.h b/webrtc/p2p/base/dtlstransport.h index 9fd3ba3274..8850cfc29a 100644 --- a/webrtc/p2p/base/dtlstransport.h +++ b/webrtc/p2p/base/dtlstransport.h @@ -92,9 +92,7 @@ class DtlsTransport : public Base { certificate_ = nullptr; } - // TODO(hbos): SetLocalCertificate - if (!channel->SetLocalIdentity( - certificate_ ? certificate_->identity() : nullptr)) { + if (!channel->SetLocalCertificate(certificate_)) { return BadTransportDescription("Failed to set local identity.", error_desc); } diff --git a/webrtc/p2p/base/dtlstransportchannel.cc b/webrtc/p2p/base/dtlstransportchannel.cc index f56001ba4d..bf1dc35e75 100644 --- a/webrtc/p2p/base/dtlstransportchannel.cc +++ b/webrtc/p2p/base/dtlstransportchannel.cc @@ -95,7 +95,6 @@ DtlsTransportChannelWrapper::DtlsTransportChannelWrapper( channel_(channel), downward_(NULL), dtls_state_(STATE_NONE), - local_identity_(NULL), ssl_role_(rtc::SSL_CLIENT), ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10) { channel_->SignalReadableState.connect(this, @@ -133,10 +132,10 @@ void DtlsTransportChannelWrapper::Connect() { channel_->Connect(); } -bool DtlsTransportChannelWrapper::SetLocalIdentity( - rtc::SSLIdentity* identity) { +bool DtlsTransportChannelWrapper::SetLocalCertificate( + const rtc::scoped_refptr& certificate) { if (dtls_state_ != STATE_NONE) { - if (identity == local_identity_) { + if (certificate == local_certificate_) { // This may happen during renegotiation. LOG_J(LS_INFO, this) << "Ignoring identical DTLS identity"; return true; @@ -146,8 +145,8 @@ bool DtlsTransportChannelWrapper::SetLocalIdentity( } } - if (identity) { - local_identity_ = identity; + if (certificate) { + local_certificate_ = certificate; dtls_state_ = STATE_OFFERED; } else { LOG_J(LS_INFO, this) << "NULL DTLS identity supplied. Not doing DTLS"; @@ -156,13 +155,9 @@ bool DtlsTransportChannelWrapper::SetLocalIdentity( return true; } -bool DtlsTransportChannelWrapper::GetLocalIdentity( - rtc::SSLIdentity** identity) const { - if (!local_identity_) - return false; - - *identity = local_identity_->GetReference(); - return true; +rtc::scoped_refptr +DtlsTransportChannelWrapper::GetLocalCertificate() const { + return local_certificate_; } bool DtlsTransportChannelWrapper::SetSslMaxProtocolVersion( @@ -245,7 +240,7 @@ bool DtlsTransportChannelWrapper::SetRemoteFingerprint( return true; } -bool DtlsTransportChannelWrapper::GetRemoteCertificate( +bool DtlsTransportChannelWrapper::GetRemoteSSLCertificate( rtc::SSLCertificate** cert) const { if (!dtls_) return false; @@ -265,7 +260,7 @@ bool DtlsTransportChannelWrapper::SetupDtls() { downward_ = downward; - dtls_->SetIdentity(local_identity_->GetReference()); + dtls_->SetIdentity(local_certificate_->identity()->GetReference()); dtls_->SetMode(rtc::SSL_MODE_DTLS); dtls_->SetMaxProtocolVersion(ssl_max_version_); dtls_->SetServerRole(ssl_role_); diff --git a/webrtc/p2p/base/dtlstransportchannel.h b/webrtc/p2p/base/dtlstransportchannel.h index 9c14314135..68bf4c00d2 100644 --- a/webrtc/p2p/base/dtlstransportchannel.h +++ b/webrtc/p2p/base/dtlstransportchannel.h @@ -33,12 +33,12 @@ class StreamInterfaceChannel : public rtc::StreamInterface { bool OnPacketReceived(const char* data, size_t size); // Implementations of StreamInterface - virtual rtc::StreamState GetState() const { return state_; } - virtual void Close() { state_ = rtc::SS_CLOSED; } - virtual rtc::StreamResult Read(void* buffer, size_t buffer_len, - size_t* read, int* error); - virtual rtc::StreamResult Write(const void* data, size_t data_len, - size_t* written, int* error); + rtc::StreamState GetState() const override { return state_; } + void Close() override { state_ = rtc::SS_CLOSED; } + rtc::StreamResult Read(void* buffer, size_t buffer_len, + size_t* read, int* error) override; + rtc::StreamResult Write(const void* data, size_t data_len, + size_t* written, int* error) override; private: TransportChannel* channel_; // owned by DtlsTransportChannelWrapper @@ -91,41 +91,42 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { // channel -- the TransportChannel we are wrapping DtlsTransportChannelWrapper(Transport* transport, TransportChannelImpl* channel); - virtual ~DtlsTransportChannelWrapper(); + ~DtlsTransportChannelWrapper() override; - virtual void SetIceRole(IceRole role) { + void SetIceRole(IceRole role) override { channel_->SetIceRole(role); } - virtual IceRole GetIceRole() const { + IceRole GetIceRole() const override { return channel_->GetIceRole(); } - virtual bool SetLocalIdentity(rtc::SSLIdentity *identity); - virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const; + bool SetLocalCertificate( + const rtc::scoped_refptr& certificate) override; + rtc::scoped_refptr GetLocalCertificate() const override; - virtual bool SetRemoteFingerprint(const std::string& digest_alg, - const uint8* digest, - size_t digest_len); - virtual bool IsDtlsActive() const { return dtls_state_ != STATE_NONE; } + bool SetRemoteFingerprint(const std::string& digest_alg, + const uint8* digest, + size_t digest_len) override; + bool IsDtlsActive() const override { return dtls_state_ != STATE_NONE; } // Called to send a packet (via DTLS, if turned on). - virtual int SendPacket(const char* data, size_t size, - const rtc::PacketOptions& options, - int flags); + int SendPacket(const char* data, size_t size, + const rtc::PacketOptions& options, + int flags) override; // TransportChannel calls that we forward to the wrapped transport. - virtual int SetOption(rtc::Socket::Option opt, int value) { + int SetOption(rtc::Socket::Option opt, int value) override { return channel_->SetOption(opt, value); } - virtual bool GetOption(rtc::Socket::Option opt, int* value) { + bool GetOption(rtc::Socket::Option opt, int* value) override { return channel_->GetOption(opt, value); } - virtual int GetError() { + int GetError() override { return channel_->GetError(); } - virtual bool GetStats(ConnectionInfos* infos) { + bool GetStats(ConnectionInfos* infos) override { return channel_->GetStats(infos); } - virtual const std::string SessionId() const { + const std::string SessionId() const override { return channel_->SessionId(); } @@ -134,31 +135,31 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { // Set up the ciphers to use for DTLS-SRTP. If this method is not called // before DTLS starts, or |ciphers| is empty, SRTP keys won't be negotiated. // This method should be called before SetupDtls. - virtual bool SetSrtpCiphers(const std::vector& ciphers); + bool SetSrtpCiphers(const std::vector& ciphers) override; // Find out which DTLS-SRTP cipher was negotiated - virtual bool GetSrtpCipher(std::string* cipher); + bool GetSrtpCipher(std::string* cipher) override; - virtual bool GetSslRole(rtc::SSLRole* role) const; - virtual bool SetSslRole(rtc::SSLRole role); + bool GetSslRole(rtc::SSLRole* role) const override; + bool SetSslRole(rtc::SSLRole role) override; // Find out which DTLS cipher was negotiated - virtual bool GetSslCipher(std::string* cipher); + bool GetSslCipher(std::string* cipher) override; // Once DTLS has been established, this method retrieves the certificate in // use by the remote peer, for use in external identity verification. - virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const; + bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert) const override; // Once DTLS has established (i.e., this channel is writable), this method // extracts the keys negotiated during the DTLS handshake, for use in external // encryption. DTLS-SRTP uses this to extract the needed SRTP keys. // See the SSLStreamAdapter documentation for info on the specific parameters. - virtual bool ExportKeyingMaterial(const std::string& label, - const uint8* context, - size_t context_len, - bool use_context, - uint8* result, - size_t result_len) { + bool ExportKeyingMaterial(const std::string& label, + const uint8* context, + size_t context_len, + bool use_context, + uint8* result, + size_t result_len) override { return (dtls_.get()) ? dtls_->ExportKeyingMaterial(label, context, context_len, use_context, @@ -167,34 +168,34 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { } // TransportChannelImpl calls. - virtual Transport* GetTransport() { + Transport* GetTransport() override { return transport_; } - virtual TransportChannelState GetState() const { + TransportChannelState GetState() const override { return channel_->GetState(); } - virtual void SetIceTiebreaker(uint64 tiebreaker) { + void SetIceTiebreaker(uint64 tiebreaker) override { channel_->SetIceTiebreaker(tiebreaker); } - virtual void SetIceCredentials(const std::string& ice_ufrag, - const std::string& ice_pwd) { + void SetIceCredentials(const std::string& ice_ufrag, + const std::string& ice_pwd) override { channel_->SetIceCredentials(ice_ufrag, ice_pwd); } - virtual void SetRemoteIceCredentials(const std::string& ice_ufrag, - const std::string& ice_pwd) { + void SetRemoteIceCredentials(const std::string& ice_ufrag, + const std::string& ice_pwd) override { channel_->SetRemoteIceCredentials(ice_ufrag, ice_pwd); } - virtual void SetRemoteIceMode(IceMode mode) { + void SetRemoteIceMode(IceMode mode) override { channel_->SetRemoteIceMode(mode); } - virtual void Connect(); + void Connect() override; - virtual void OnSignalingReady() { + void OnSignalingReady() override { channel_->OnSignalingReady(); } - virtual void OnCandidate(const Candidate& candidate) { + void OnCandidate(const Candidate& candidate) override { channel_->OnCandidate(candidate); } @@ -230,7 +231,7 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { StreamInterfaceChannel* downward_; // Wrapper for channel_, owned by dtls_. std::vector srtp_ciphers_; // SRTP ciphers to use with DTLS. State dtls_state_; - rtc::SSLIdentity* local_identity_; + rtc::scoped_refptr local_certificate_; rtc::SSLRole ssl_role_; rtc::SSLProtocolVersion ssl_max_version_; rtc::Buffer remote_fingerprint_value_; diff --git a/webrtc/p2p/base/dtlstransportchannel_unittest.cc b/webrtc/p2p/base/dtlstransportchannel_unittest.cc index 34aa651af7..10640f99e3 100644 --- a/webrtc/p2p/base/dtlstransportchannel_unittest.cc +++ b/webrtc/p2p/base/dtlstransportchannel_unittest.cc @@ -842,10 +842,10 @@ TEST_F(DtlsTransportChannelTest, TestCertificatesBeforeConnect) { ASSERT_NE(certificate1->ssl_certificate().ToPEMString(), certificate2->ssl_certificate().ToPEMString()); ASSERT_FALSE( - client1_.transport()->GetRemoteCertificate(remote_cert1.accept())); + client1_.transport()->GetRemoteSSLCertificate(remote_cert1.accept())); ASSERT_FALSE(remote_cert1 != NULL); ASSERT_FALSE( - client2_.transport()->GetRemoteCertificate(remote_cert2.accept())); + client2_.transport()->GetRemoteSSLCertificate(remote_cert2.accept())); ASSERT_FALSE(remote_cert2 != NULL); } @@ -868,11 +868,11 @@ TEST_F(DtlsTransportChannelTest, TestCertificatesAfterConnect) { // Each side's remote certificate is the other side's local certificate. ASSERT_TRUE( - client1_.transport()->GetRemoteCertificate(remote_cert1.accept())); + client1_.transport()->GetRemoteSSLCertificate(remote_cert1.accept())); ASSERT_EQ(remote_cert1->ToPEMString(), certificate2->ssl_certificate().ToPEMString()); ASSERT_TRUE( - client2_.transport()->GetRemoteCertificate(remote_cert2.accept())); + client2_.transport()->GetRemoteSSLCertificate(remote_cert2.accept())); ASSERT_EQ(remote_cert2->ToPEMString(), certificate1->ssl_certificate().ToPEMString()); } diff --git a/webrtc/p2p/base/fakesession.h b/webrtc/p2p/base/fakesession.h index 5597a44dfa..bd3c089025 100644 --- a/webrtc/p2p/base/fakesession.h +++ b/webrtc/p2p/base/fakesession.h @@ -47,15 +47,14 @@ class FakeTransportChannel : public TransportChannelImpl, int component) : TransportChannelImpl(content_name, component), transport_(transport), - dest_(NULL), + dest_(nullptr), state_(STATE_INIT), async_(false), - identity_(NULL), do_dtls_(false), role_(ICEROLE_UNKNOWN), tiebreaker_(0), remote_ice_mode_(ICEMODE_FULL), - dtls_fingerprint_("", NULL, 0), + dtls_fingerprint_("", nullptr, 0), ssl_role_(rtc::SSL_CLIENT), connection_count_(0) { } @@ -77,11 +76,11 @@ class FakeTransportChannel : public TransportChannelImpl, async_ = async; } - virtual Transport* GetTransport() { + Transport* GetTransport() override { return transport_; } - virtual TransportChannelState GetState() const { + TransportChannelState GetState() const override { if (connection_count_ == 0) { return TransportChannelState::STATE_FAILED; } @@ -93,36 +92,38 @@ class FakeTransportChannel : public TransportChannelImpl, return TransportChannelState::STATE_FAILED; } - virtual void SetIceRole(IceRole role) { role_ = role; } - virtual IceRole GetIceRole() const { return role_; } - virtual void SetIceTiebreaker(uint64 tiebreaker) { tiebreaker_ = tiebreaker; } - virtual void SetIceCredentials(const std::string& ice_ufrag, - const std::string& ice_pwd) { + void SetIceRole(IceRole role) override { role_ = role; } + IceRole GetIceRole() const override { return role_; } + void SetIceTiebreaker(uint64 tiebreaker) override { + tiebreaker_ = tiebreaker; + } + void SetIceCredentials(const std::string& ice_ufrag, + const std::string& ice_pwd) override { ice_ufrag_ = ice_ufrag; ice_pwd_ = ice_pwd; } - virtual void SetRemoteIceCredentials(const std::string& ice_ufrag, - const std::string& ice_pwd) { + void SetRemoteIceCredentials(const std::string& ice_ufrag, + const std::string& ice_pwd) override { remote_ice_ufrag_ = ice_ufrag; remote_ice_pwd_ = ice_pwd; } - virtual void SetRemoteIceMode(IceMode mode) { remote_ice_mode_ = mode; } - virtual bool SetRemoteFingerprint(const std::string& alg, const uint8* digest, - size_t digest_len) { + void SetRemoteIceMode(IceMode mode) override { remote_ice_mode_ = mode; } + bool SetRemoteFingerprint(const std::string& alg, const uint8* digest, + size_t digest_len) override { dtls_fingerprint_ = rtc::SSLFingerprint(alg, digest, digest_len); return true; } - virtual bool SetSslRole(rtc::SSLRole role) { + bool SetSslRole(rtc::SSLRole role) override { ssl_role_ = role; return true; } - virtual bool GetSslRole(rtc::SSLRole* role) const { + bool GetSslRole(rtc::SSLRole* role) const override { *role = ssl_role_; return true; } - virtual void Connect() { + void Connect() override { if (state_ == STATE_INIT) { state_ = STATE_CONNECTING; } @@ -147,7 +148,7 @@ class FakeTransportChannel : public TransportChannelImpl, // This simulates the delivery of candidates. dest_ = dest; dest_->dest_ = this; - if (identity_ && dest_->identity_) { + if (certificate_ && dest_->certificate_) { do_dtls_ = true; dest_->do_dtls_ = true; NegotiateSrtpCiphers(); @@ -177,8 +178,8 @@ class FakeTransportChannel : public TransportChannelImpl, void SetReceivingTimeout(int timeout) override {} - virtual int SendPacket(const char* data, size_t len, - const rtc::PacketOptions& options, int flags) { + int SendPacket(const char* data, size_t len, + const rtc::PacketOptions& options, int flags) override { if (state_ != STATE_CONNECTED) { return -1; } @@ -195,22 +196,22 @@ class FakeTransportChannel : public TransportChannelImpl, } return static_cast(len); } - virtual int SetOption(rtc::Socket::Option opt, int value) { + int SetOption(rtc::Socket::Option opt, int value) override { return true; } - virtual bool GetOption(rtc::Socket::Option opt, int* value) { + bool GetOption(rtc::Socket::Option opt, int* value) override { return true; } - virtual int GetError() { + int GetError() override { return 0; } - virtual void OnSignalingReady() { + void OnSignalingReady() override { } - virtual void OnCandidate(const Candidate& candidate) { + void OnCandidate(const Candidate& candidate) override { } - virtual void OnMessage(rtc::Message* msg) { + void OnMessage(rtc::Message* msg) override { PacketMessageData* data = static_cast( msg->pdata); dest_->SignalReadPacket(dest_, data->packet.data(), @@ -218,26 +219,26 @@ class FakeTransportChannel : public TransportChannelImpl, delete data; } - bool SetLocalIdentity(rtc::SSLIdentity* identity) { - identity_ = identity; + bool SetLocalCertificate( + const rtc::scoped_refptr& certificate) override { + certificate_ = certificate; return true; } - - void SetRemoteCertificate(rtc::FakeSSLCertificate* cert) { + void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) { remote_cert_ = cert; } - virtual bool IsDtlsActive() const { + bool IsDtlsActive() const override { return do_dtls_; } - virtual bool SetSrtpCiphers(const std::vector& ciphers) { + bool SetSrtpCiphers(const std::vector& ciphers) override { srtp_ciphers_ = ciphers; return true; } - virtual bool GetSrtpCipher(std::string* cipher) { + bool GetSrtpCipher(std::string* cipher) override { if (!chosen_srtp_cipher_.empty()) { *cipher = chosen_srtp_cipher_; return true; @@ -245,19 +246,16 @@ class FakeTransportChannel : public TransportChannelImpl, return false; } - virtual bool GetSslCipher(std::string* cipher) { + bool GetSslCipher(std::string* cipher) override { return false; } - virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const { - if (!identity_) - return false; - - *identity = identity_->GetReference(); - return true; + rtc::scoped_refptr + GetLocalCertificate() const override { + return certificate_; } - virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const { + bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert) const override { if (!remote_cert_) return false; @@ -265,12 +263,12 @@ class FakeTransportChannel : public TransportChannelImpl, return true; } - virtual bool ExportKeyingMaterial(const std::string& label, - const uint8* context, - size_t context_len, - bool use_context, - uint8* result, - size_t result_len) { + bool ExportKeyingMaterial(const std::string& label, + const uint8* context, + size_t context_len, + bool use_context, + uint8* result, + size_t result_len) override { if (!chosen_srtp_cipher_.empty()) { memset(result, 0xff, result_len); return true; @@ -307,7 +305,7 @@ class FakeTransportChannel : public TransportChannelImpl, FakeTransportChannel* dest_; State state_; bool async_; - rtc::SSLIdentity* identity_; + rtc::scoped_refptr certificate_; rtc::FakeSSLCertificate* remote_cert_; bool do_dtls_; std::vector srtp_ciphers_; @@ -350,9 +348,7 @@ class FakeTransport : public Transport { dest_ = dest; for (ChannelMap::iterator it = channels_.begin(); it != channels_.end(); ++it) { - // TODO(hbos): SetLocalCertificate - it->second->SetLocalIdentity( - certificate_ ? certificate_->identity() : nullptr); + it->second->SetLocalCertificate(certificate_); SetChannelDestination(it->first, it->second); } } @@ -373,7 +369,7 @@ class FakeTransport : public Transport { using Transport::remote_description; protected: - virtual TransportChannelImpl* CreateTransportChannel(int component) { + TransportChannelImpl* CreateTransportChannel(int component) override { if (channels_.find(component) != channels_.end()) { return NULL; } @@ -384,7 +380,7 @@ class FakeTransport : public Transport { channels_[component] = channel; return channel; } - virtual void DestroyTransportChannel(TransportChannelImpl* channel) { + void DestroyTransportChannel(TransportChannelImpl* channel) override { channels_.erase(channel->component()); delete channel; } @@ -411,11 +407,8 @@ class FakeTransport : public Transport { FakeTransportChannel* dest_channel = NULL; if (dest_) { dest_channel = dest_->GetFakeChannel(component); - if (dest_channel) { - // TODO(hbos): SetLocalCertificate - dest_channel->SetLocalIdentity( - dest_->certificate_ ? dest_->certificate_->identity() : nullptr); - } + if (dest_channel) + dest_channel->SetLocalCertificate(dest_->certificate_); } channel->SetDestination(dest_channel); } @@ -467,9 +460,8 @@ class FakeSession : public BaseSession { } } - virtual TransportChannel* CreateChannel( - const std::string& content_name, - int component) { + TransportChannel* CreateChannel(const std::string& content_name, + int component) override { if (fail_create_channel_) { return NULL; } @@ -493,7 +485,7 @@ class FakeSession : public BaseSession { } protected: - virtual Transport* CreateTransport(const std::string& content_name) { + Transport* CreateTransport(const std::string& content_name) override { return new FakeTransport(signaling_thread(), worker_thread(), content_name); } diff --git a/webrtc/p2p/base/p2ptransportchannel.h b/webrtc/p2p/base/p2ptransportchannel.h index 335ee7d166..af761a65e7 100644 --- a/webrtc/p2p/base/p2ptransportchannel.h +++ b/webrtc/p2p/base/p2ptransportchannel.h @@ -55,33 +55,33 @@ class P2PTransportChannel : public TransportChannelImpl, int component, P2PTransport* transport, PortAllocator *allocator); - virtual ~P2PTransportChannel(); + ~P2PTransportChannel() override; // From TransportChannelImpl: - virtual Transport* GetTransport() { return transport_; } - virtual TransportChannelState GetState() const; - virtual void SetIceRole(IceRole role); - virtual IceRole GetIceRole() const { return ice_role_; } - virtual void SetIceTiebreaker(uint64 tiebreaker); - virtual void SetIceCredentials(const std::string& ice_ufrag, - const std::string& ice_pwd); - virtual void SetRemoteIceCredentials(const std::string& ice_ufrag, - const std::string& ice_pwd); - virtual void SetRemoteIceMode(IceMode mode); - virtual void Connect(); - virtual void OnSignalingReady(); - virtual void OnCandidate(const Candidate& candidate); + Transport* GetTransport() override { return transport_; } + TransportChannelState GetState() const override; + void SetIceRole(IceRole role) override; + IceRole GetIceRole() const override { return ice_role_; } + void SetIceTiebreaker(uint64 tiebreaker) override; + void SetIceCredentials(const std::string& ice_ufrag, + const std::string& ice_pwd) override; + void SetRemoteIceCredentials(const std::string& ice_ufrag, + const std::string& ice_pwd) override; + void SetRemoteIceMode(IceMode mode) override; + void Connect() override; + void OnSignalingReady() override; + void OnCandidate(const Candidate& candidate) override; // Sets the receiving timeout in milliseconds. // This also sets the check_receiving_delay proportionally. - virtual void SetReceivingTimeout(int receiving_timeout_ms); + void SetReceivingTimeout(int receiving_timeout_ms) override; // From TransportChannel: - virtual int SendPacket(const char *data, size_t len, - const rtc::PacketOptions& options, int flags); - virtual int SetOption(rtc::Socket::Option opt, int value); - virtual bool GetOption(rtc::Socket::Option opt, int* value); - virtual int GetError() { return error_; } - virtual bool GetStats(std::vector* stats); + int SendPacket(const char *data, size_t len, + const rtc::PacketOptions& options, int flags) override; + int SetOption(rtc::Socket::Option opt, int value) override; + bool GetOption(rtc::Socket::Option opt, int* value) override; + int GetError() override { return error_; } + bool GetStats(std::vector* stats) override; const Connection* best_connection() const { return best_connection_; } void set_incoming_only(bool value) { incoming_only_ = value; } @@ -93,61 +93,60 @@ class P2PTransportChannel : public TransportChannelImpl, IceMode remote_ice_mode() const { return remote_ice_mode_; } // DTLS methods. - virtual bool IsDtlsActive() const { return false; } + bool IsDtlsActive() const override { return false; } // Default implementation. - virtual bool GetSslRole(rtc::SSLRole* role) const { + bool GetSslRole(rtc::SSLRole* role) const override { return false; } - virtual bool SetSslRole(rtc::SSLRole role) { + bool SetSslRole(rtc::SSLRole role) override { return false; } // Set up the ciphers to use for DTLS-SRTP. - virtual bool SetSrtpCiphers(const std::vector& ciphers) { + bool SetSrtpCiphers(const std::vector& ciphers) override { return false; } // Find out which DTLS-SRTP cipher was negotiated. - virtual bool GetSrtpCipher(std::string* cipher) { + bool GetSrtpCipher(std::string* cipher) override { return false; } // Find out which DTLS cipher was negotiated. - virtual bool GetSslCipher(std::string* cipher) { + bool GetSslCipher(std::string* cipher) override { return false; } - // Returns false because the channel is not encrypted by default. - virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const { - return false; + // Returns null because the channel is not encrypted by default. + rtc::scoped_refptr GetLocalCertificate() const override { + return nullptr; } - virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const { + bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert) const override { return false; } // Allows key material to be extracted for external encryption. - virtual bool ExportKeyingMaterial( - const std::string& label, - const uint8* context, - size_t context_len, - bool use_context, - uint8* result, - size_t result_len) { + bool ExportKeyingMaterial(const std::string& label, + const uint8* context, + size_t context_len, + bool use_context, + uint8* result, + size_t result_len) override { return false; } - virtual bool SetLocalIdentity(rtc::SSLIdentity* identity) { + bool SetLocalCertificate( + const rtc::scoped_refptr& certificate) override { return false; } // Set DTLS Remote fingerprint. Must be after local identity set. - virtual bool SetRemoteFingerprint( - const std::string& digest_alg, - const uint8* digest, - size_t digest_len) { + bool SetRemoteFingerprint(const std::string& digest_alg, + const uint8* digest, + size_t digest_len) override { return false; } @@ -213,7 +212,7 @@ class P2PTransportChannel : public TransportChannelImpl, void OnNominated(Connection* conn); - virtual void OnMessage(rtc::Message *pmsg); + void OnMessage(rtc::Message *pmsg) override; void OnSort(); void OnPing(); diff --git a/webrtc/p2p/base/transport.cc b/webrtc/p2p/base/transport.cc index 5f28c40e93..3322e3898a 100644 --- a/webrtc/p2p/base/transport.cc +++ b/webrtc/p2p/base/transport.cc @@ -140,20 +140,20 @@ bool Transport::GetCertificate( Bind(&Transport::GetCertificate_w, this, certificate)); } -bool Transport::GetRemoteCertificate(rtc::SSLCertificate** cert) { +bool Transport::GetRemoteSSLCertificate(rtc::SSLCertificate** cert) { // Channels can be deleted on the worker thread, so for safety the remote // certificate is acquired on the worker thread. return worker_thread_->Invoke( - Bind(&Transport::GetRemoteCertificate_w, this, cert)); + Bind(&Transport::GetRemoteSSLCertificate_w, this, cert)); } -bool Transport::GetRemoteCertificate_w(rtc::SSLCertificate** cert) { +bool Transport::GetRemoteSSLCertificate_w(rtc::SSLCertificate** cert) { ASSERT(worker_thread()->IsCurrent()); if (channels_.empty()) return false; ChannelMap::iterator iter = channels_.begin(); - return iter->second->GetRemoteCertificate(cert); + return iter->second->GetRemoteSSLCertificate(cert); } void Transport::SetChannelReceivingTimeout(int timeout_ms) { diff --git a/webrtc/p2p/base/transport.h b/webrtc/p2p/base/transport.h index 2e94c74436..9dc5a40216 100644 --- a/webrtc/p2p/base/transport.h +++ b/webrtc/p2p/base/transport.h @@ -208,7 +208,7 @@ class Transport : public rtc::MessageHandler, bool GetCertificate(rtc::scoped_refptr* certificate); // Get a copy of the remote certificate in use by the specified channel. - bool GetRemoteCertificate(rtc::SSLCertificate** cert); + bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert); // Create, destroy, and lookup the channels of this type by their components. TransportChannelImpl* CreateChannel(int component); @@ -437,7 +437,7 @@ class Transport : public rtc::MessageHandler, ContentAction action, std::string* error_desc); bool GetStats_w(TransportStats* infos); - bool GetRemoteCertificate_w(rtc::SSLCertificate** cert); + bool GetRemoteSSLCertificate_w(rtc::SSLCertificate** cert); void SetChannelReceivingTimeout_w(int timeout_ms); diff --git a/webrtc/p2p/base/transportchannel.h b/webrtc/p2p/base/transportchannel.h index 15b38eee84..e0dcc3719f 100644 --- a/webrtc/p2p/base/transportchannel.h +++ b/webrtc/p2p/base/transportchannel.h @@ -108,11 +108,12 @@ class TransportChannel : public sigslot::has_slots<> { // Finds out which DTLS cipher was negotiated. virtual bool GetSslCipher(std::string* cipher) = 0; - // Gets a copy of the local SSL identity, owned by the caller. - virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const = 0; + // Gets the local RTCCertificate used for DTLS. + virtual rtc::scoped_refptr + GetLocalCertificate() const = 0; // Gets a copy of the remote side's SSL certificate, owned by the caller. - virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const = 0; + virtual bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert) const = 0; // Allows key material to be extracted for external encryption. virtual bool ExportKeyingMaterial(const std::string& label, diff --git a/webrtc/p2p/base/transportchannelimpl.h b/webrtc/p2p/base/transportchannelimpl.h index 75d56aa09b..2d660f70f2 100644 --- a/webrtc/p2p/base/transportchannelimpl.h +++ b/webrtc/p2p/base/transportchannelimpl.h @@ -82,11 +82,8 @@ class TransportChannelImpl : public TransportChannel { virtual void OnCandidate(const Candidate& candidate) = 0; // DTLS methods - // Set DTLS local identity. The identity object is not copied, but the caller - // retains ownership and must delete it after this TransportChannelImpl is - // destroyed. - // TODO(bemasc): Fix the ownership semantics of this method. - virtual bool SetLocalIdentity(rtc::SSLIdentity* identity) = 0; + virtual bool SetLocalCertificate( + const rtc::scoped_refptr& certificate) = 0; // Set DTLS Remote fingerprint. Must be after local identity set. virtual bool SetRemoteFingerprint(const std::string& digest_alg, diff --git a/webrtc/p2p/base/transportchannelproxy.cc b/webrtc/p2p/base/transportchannelproxy.cc index 79772514c6..f7946dd96f 100644 --- a/webrtc/p2p/base/transportchannelproxy.cc +++ b/webrtc/p2p/base/transportchannelproxy.cc @@ -189,22 +189,22 @@ bool TransportChannelProxy::GetSslCipher(std::string* cipher) { return impl_->GetSslCipher(cipher); } -bool TransportChannelProxy::GetLocalIdentity( - rtc::SSLIdentity** identity) const { +rtc::scoped_refptr +TransportChannelProxy::GetLocalCertificate() const { ASSERT(rtc::Thread::Current() == worker_thread_); if (!impl_) { - return false; + return nullptr; } - return impl_->GetLocalIdentity(identity); + return impl_->GetLocalCertificate(); } -bool TransportChannelProxy::GetRemoteCertificate( +bool TransportChannelProxy::GetRemoteSSLCertificate( rtc::SSLCertificate** cert) const { ASSERT(rtc::Thread::Current() == worker_thread_); if (!impl_) { return false; } - return impl_->GetRemoteCertificate(cert); + return impl_->GetRemoteSSLCertificate(cert); } bool TransportChannelProxy::ExportKeyingMaterial(const std::string& label, diff --git a/webrtc/p2p/base/transportchannelproxy.h b/webrtc/p2p/base/transportchannelproxy.h index 3a69bccb4c..3d55d10694 100644 --- a/webrtc/p2p/base/transportchannelproxy.h +++ b/webrtc/p2p/base/transportchannelproxy.h @@ -35,39 +35,39 @@ class TransportChannelProxy : public TransportChannel, public: TransportChannelProxy(const std::string& content_name, int component); - virtual ~TransportChannelProxy(); + ~TransportChannelProxy() override; TransportChannelImpl* impl() { return impl_; } - virtual TransportChannelState GetState() const; + TransportChannelState GetState() const override; // Sets the implementation to which we will proxy. void SetImplementation(TransportChannelImpl* impl); // Implementation of the TransportChannel interface. These simply forward to // the implementation. - virtual int SendPacket(const char* data, size_t len, - const rtc::PacketOptions& options, - int flags); - virtual int SetOption(rtc::Socket::Option opt, int value); - virtual bool GetOption(rtc::Socket::Option opt, int* value); - virtual int GetError(); + int SendPacket(const char* data, size_t len, + const rtc::PacketOptions& options, + int flags) override; + int SetOption(rtc::Socket::Option opt, int value) override; + bool GetOption(rtc::Socket::Option opt, int* value) override; + int GetError() override; virtual IceRole GetIceRole() const; - virtual bool GetStats(ConnectionInfos* infos); - virtual bool IsDtlsActive() const; - virtual bool GetSslRole(rtc::SSLRole* role) const; + bool GetStats(ConnectionInfos* infos) override; + bool IsDtlsActive() const override; + bool GetSslRole(rtc::SSLRole* role) const override; virtual bool SetSslRole(rtc::SSLRole role); - virtual bool SetSrtpCiphers(const std::vector& ciphers); - virtual bool GetSrtpCipher(std::string* cipher); - virtual bool GetSslCipher(std::string* cipher); - virtual bool GetLocalIdentity(rtc::SSLIdentity** identity) const; - virtual bool GetRemoteCertificate(rtc::SSLCertificate** cert) const; - virtual bool ExportKeyingMaterial(const std::string& label, + bool SetSrtpCiphers(const std::vector& ciphers) override; + bool GetSrtpCipher(std::string* cipher) override; + bool GetSslCipher(std::string* cipher) override; + rtc::scoped_refptr GetLocalCertificate() const override; + bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert) const override; + bool ExportKeyingMaterial(const std::string& label, const uint8* context, size_t context_len, bool use_context, uint8* result, - size_t result_len); + size_t result_len) override; private: // Catch signals from the implementation channel. These just forward to the