Simplify DtlsTransport state.

Make a few more members const, remove members that aren't used,
set max ssl version number on construction and remove setter.

Bug: none
Change-Id: I6c1a7cabf1e795e027f1bc53b994517e9aef0e93
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213780
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33622}
This commit is contained in:
Tommi
2021-04-03 17:53:54 +02:00
committed by Commit Bot
parent 41c873ca97
commit 653bab6790
8 changed files with 30 additions and 57 deletions

View File

@ -134,14 +134,13 @@ void StreamInterfaceChannel::Close() {
DtlsTransport::DtlsTransport(IceTransportInternal* ice_transport, DtlsTransport::DtlsTransport(IceTransportInternal* ice_transport,
const webrtc::CryptoOptions& crypto_options, const webrtc::CryptoOptions& crypto_options,
webrtc::RtcEventLog* event_log) webrtc::RtcEventLog* event_log,
: transport_name_(ice_transport->transport_name()), rtc::SSLProtocolVersion max_version)
component_(ice_transport->component()), : component_(ice_transport->component()),
ice_transport_(ice_transport), ice_transport_(ice_transport),
downward_(NULL), downward_(NULL),
srtp_ciphers_(crypto_options.GetSupportedDtlsSrtpCryptoSuites()), srtp_ciphers_(crypto_options.GetSupportedDtlsSrtpCryptoSuites()),
ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_12), ssl_max_version_(max_version),
crypto_options_(crypto_options),
event_log_(event_log) { event_log_(event_log) {
RTC_DCHECK(ice_transport_); RTC_DCHECK(ice_transport_);
ConnectToIceTransport(); ConnectToIceTransport();
@ -149,16 +148,12 @@ DtlsTransport::DtlsTransport(IceTransportInternal* ice_transport,
DtlsTransport::~DtlsTransport() = default; DtlsTransport::~DtlsTransport() = default;
const webrtc::CryptoOptions& DtlsTransport::crypto_options() const {
return crypto_options_;
}
DtlsTransportState DtlsTransport::dtls_state() const { DtlsTransportState DtlsTransport::dtls_state() const {
return dtls_state_; return dtls_state_;
} }
const std::string& DtlsTransport::transport_name() const { const std::string& DtlsTransport::transport_name() const {
return transport_name_; return ice_transport_->transport_name();
} }
int DtlsTransport::component() const { int DtlsTransport::component() const {
@ -199,17 +194,6 @@ rtc::scoped_refptr<rtc::RTCCertificate> DtlsTransport::GetLocalCertificate()
return local_certificate_; return local_certificate_;
} }
bool DtlsTransport::SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) {
if (dtls_active_) {
RTC_LOG(LS_ERROR) << "Not changing max. protocol version "
"while DTLS is negotiating";
return false;
}
ssl_max_version_ = version;
return true;
}
bool DtlsTransport::SetDtlsRole(rtc::SSLRole role) { bool DtlsTransport::SetDtlsRole(rtc::SSLRole role) {
if (dtls_) { if (dtls_) {
RTC_DCHECK(dtls_role_); RTC_DCHECK(dtls_role_);

View File

@ -101,13 +101,14 @@ class DtlsTransport : public DtlsTransportInternal {
// //
// |event_log| is an optional RtcEventLog for logging state changes. It should // |event_log| is an optional RtcEventLog for logging state changes. It should
// outlive the DtlsTransport. // outlive the DtlsTransport.
explicit DtlsTransport(IceTransportInternal* ice_transport, DtlsTransport(
IceTransportInternal* ice_transport,
const webrtc::CryptoOptions& crypto_options, const webrtc::CryptoOptions& crypto_options,
webrtc::RtcEventLog* event_log); webrtc::RtcEventLog* event_log,
rtc::SSLProtocolVersion max_version = rtc::SSL_PROTOCOL_DTLS_12);
~DtlsTransport() override; ~DtlsTransport() override;
const webrtc::CryptoOptions& crypto_options() const override;
DtlsTransportState dtls_state() const override; DtlsTransportState dtls_state() const override;
const std::string& transport_name() const override; const std::string& transport_name() const override;
int component() const override; int component() const override;
@ -142,8 +143,6 @@ class DtlsTransport : public DtlsTransportInternal {
bool GetOption(rtc::Socket::Option opt, int* value) override; bool GetOption(rtc::Socket::Option opt, int* value) override;
bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) override;
// Find out which TLS version was negotiated // Find out which TLS version was negotiated
bool GetSslVersionBytes(int* version) const override; bool GetSslVersionBytes(int* version) const override;
// Find out which DTLS-SRTP cipher was negotiated // Find out which DTLS-SRTP cipher was negotiated
@ -191,7 +190,7 @@ class DtlsTransport : public DtlsTransportInternal {
const absl::string_view RECEIVING_ABBREV[2] = {"_", "R"}; const absl::string_view RECEIVING_ABBREV[2] = {"_", "R"};
const absl::string_view WRITABLE_ABBREV[2] = {"_", "W"}; const absl::string_view WRITABLE_ABBREV[2] = {"_", "W"};
rtc::StringBuilder sb; rtc::StringBuilder sb;
sb << "DtlsTransport[" << transport_name_ << "|" << component_ << "|" sb << "DtlsTransport[" << transport_name() << "|" << component_ << "|"
<< RECEIVING_ABBREV[receiving()] << WRITABLE_ABBREV[writable()] << "]"; << RECEIVING_ABBREV[receiving()] << WRITABLE_ABBREV[writable()] << "]";
return sb.Release(); return sb.Release();
} }
@ -224,20 +223,18 @@ class DtlsTransport : public DtlsTransportInternal {
webrtc::SequenceChecker thread_checker_; webrtc::SequenceChecker thread_checker_;
std::string transport_name_; const int component_;
int component_;
DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW; DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW;
// Underlying ice_transport, not owned by this class. // Underlying ice_transport, not owned by this class.
IceTransportInternal* ice_transport_; IceTransportInternal* const ice_transport_;
std::unique_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream std::unique_ptr<rtc::SSLStreamAdapter> dtls_; // The DTLS stream
StreamInterfaceChannel* StreamInterfaceChannel*
downward_; // Wrapper for ice_transport_, owned by dtls_. downward_; // Wrapper for ice_transport_, owned by dtls_.
std::vector<int> srtp_ciphers_; // SRTP ciphers to use with DTLS. const std::vector<int> srtp_ciphers_; // SRTP ciphers to use with DTLS.
bool dtls_active_ = false; bool dtls_active_ = false;
rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_;
absl::optional<rtc::SSLRole> dtls_role_; absl::optional<rtc::SSLRole> dtls_role_;
rtc::SSLProtocolVersion ssl_max_version_; const rtc::SSLProtocolVersion ssl_max_version_;
webrtc::CryptoOptions crypto_options_;
rtc::Buffer remote_fingerprint_value_; rtc::Buffer remote_fingerprint_value_;
std::string remote_fingerprint_algorithm_; std::string remote_fingerprint_algorithm_;

View File

@ -31,7 +31,8 @@ class DtlsTransportFactory {
virtual std::unique_ptr<DtlsTransportInternal> CreateDtlsTransport( virtual std::unique_ptr<DtlsTransportInternal> CreateDtlsTransport(
IceTransportInternal* ice, IceTransportInternal* ice,
const webrtc::CryptoOptions& crypto_options) = 0; const webrtc::CryptoOptions& crypto_options,
rtc::SSLProtocolVersion max_version) = 0;
}; };
} // namespace cricket } // namespace cricket

View File

@ -18,6 +18,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "absl/base/attributes.h"
#include "api/crypto/crypto_options.h" #include "api/crypto/crypto_options.h"
#include "api/dtls_transport_interface.h" #include "api/dtls_transport_interface.h"
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
@ -28,7 +29,6 @@
#include "rtc_base/ssl_certificate.h" #include "rtc_base/ssl_certificate.h"
#include "rtc_base/ssl_fingerprint.h" #include "rtc_base/ssl_fingerprint.h"
#include "rtc_base/ssl_stream_adapter.h" #include "rtc_base/ssl_stream_adapter.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
namespace cricket { namespace cricket {
@ -64,8 +64,6 @@ class DtlsTransportInternal : public rtc::PacketTransportInternal {
public: public:
~DtlsTransportInternal() override; ~DtlsTransportInternal() override;
virtual const webrtc::CryptoOptions& crypto_options() const = 0;
virtual DtlsTransportState dtls_state() const = 0; virtual DtlsTransportState dtls_state() const = 0;
virtual int component() const = 0; virtual int component() const = 0;
@ -109,7 +107,10 @@ class DtlsTransportInternal : public rtc::PacketTransportInternal {
const uint8_t* digest, const uint8_t* digest,
size_t digest_len) = 0; size_t digest_len) = 0;
virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) = 0; ABSL_DEPRECATED("Set the max version via construction.")
bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) {
return true;
}
// Expose the underneath IceTransport. // Expose the underneath IceTransport.
virtual IceTransportInternal* ice_transport() = 0; virtual IceTransportInternal* ice_transport() = 0;

View File

@ -86,10 +86,9 @@ class DtlsTestClient : public sigslot::has_slots<> {
fake_ice_transport_->SignalReadPacket.connect( fake_ice_transport_->SignalReadPacket.connect(
this, &DtlsTestClient::OnFakeIceTransportReadPacket); this, &DtlsTestClient::OnFakeIceTransportReadPacket);
dtls_transport_ = std::make_unique<DtlsTransport>(fake_ice_transport_.get(), dtls_transport_ = std::make_unique<DtlsTransport>(
webrtc::CryptoOptions(), fake_ice_transport_.get(), webrtc::CryptoOptions(),
/*event_log=*/nullptr); /*event_log=*/nullptr, ssl_max_version_);
dtls_transport_->SetSslMaxProtocolVersion(ssl_max_version_);
// Note: Certificate may be null here if testing passthrough. // Note: Certificate may be null here if testing passthrough.
dtls_transport_->SetLocalCertificate(certificate_); dtls_transport_->SetLocalCertificate(certificate_);
dtls_transport_->SignalWritableState.connect( dtls_transport_->SignalWritableState.connect(

View File

@ -146,9 +146,6 @@ class FakeDtlsTransport : public DtlsTransportInternal {
rtc::SSLFingerprint(alg, rtc::MakeArrayView(digest, digest_len)); rtc::SSLFingerprint(alg, rtc::MakeArrayView(digest, digest_len));
return true; return true;
} }
bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) override {
return true;
}
bool SetDtlsRole(rtc::SSLRole role) override { bool SetDtlsRole(rtc::SSLRole role) override {
dtls_role_ = std::move(role); dtls_role_ = std::move(role);
return true; return true;
@ -160,12 +157,6 @@ class FakeDtlsTransport : public DtlsTransportInternal {
*role = *dtls_role_; *role = *dtls_role_;
return true; return true;
} }
const webrtc::CryptoOptions& crypto_options() const override {
return crypto_options_;
}
void SetCryptoOptions(const webrtc::CryptoOptions& crypto_options) {
crypto_options_ = crypto_options;
}
bool SetLocalCertificate( bool SetLocalCertificate(
const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override { const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override {
do_dtls_ = true; do_dtls_ = true;
@ -303,7 +294,6 @@ class FakeDtlsTransport : public DtlsTransportInternal {
absl::optional<rtc::SSLRole> dtls_role_; absl::optional<rtc::SSLRole> dtls_role_;
int crypto_suite_ = rtc::SRTP_AES128_CM_SHA1_80; int crypto_suite_ = rtc::SRTP_AES128_CM_SHA1_80;
absl::optional<int> ssl_cipher_suite_; absl::optional<int> ssl_cipher_suite_;
webrtc::CryptoOptions crypto_options_;
DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW; DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW;

View File

@ -414,14 +414,14 @@ JsepTransportController::CreateDtlsTransport(
if (config_.dtls_transport_factory) { if (config_.dtls_transport_factory) {
dtls = config_.dtls_transport_factory->CreateDtlsTransport( dtls = config_.dtls_transport_factory->CreateDtlsTransport(
ice, config_.crypto_options); ice, config_.crypto_options, config_.ssl_max_version);
} else { } else {
dtls = std::make_unique<cricket::DtlsTransport>(ice, config_.crypto_options, dtls = std::make_unique<cricket::DtlsTransport>(ice, config_.crypto_options,
config_.event_log); config_.event_log,
config_.ssl_max_version);
} }
RTC_DCHECK(dtls); RTC_DCHECK(dtls);
dtls->SetSslMaxProtocolVersion(config_.ssl_max_version);
dtls->ice_transport()->SetIceRole(ice_role_); dtls->ice_transport()->SetIceRole(ice_role_);
dtls->ice_transport()->SetIceTiebreaker(ice_tiebreaker_); dtls->ice_transport()->SetIceTiebreaker(ice_tiebreaker_);
dtls->ice_transport()->SetIceConfig(ice_config_); dtls->ice_transport()->SetIceConfig(ice_config_);

View File

@ -57,7 +57,8 @@ class FakeDtlsTransportFactory : public cricket::DtlsTransportFactory {
public: public:
std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport( std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
cricket::IceTransportInternal* ice, cricket::IceTransportInternal* ice,
const webrtc::CryptoOptions& crypto_options) override { const webrtc::CryptoOptions& crypto_options,
rtc::SSLProtocolVersion max_version) override {
return std::make_unique<FakeDtlsTransport>( return std::make_unique<FakeDtlsTransport>(
static_cast<cricket::FakeIceTransport*>(ice)); static_cast<cricket::FakeIceTransport*>(ice));
} }