mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-16 15:20:42 +01:00

The TransportController will be replaced by the JsepTransportController and JsepTransport will be replace be JsepTransport2. The JsepTransportController will take the entire SessionDescription and handle the RtcpMux, Sdes and BUNDLE internally. The ownership model is also changed. The P2P layer transports are not ref-counted and will be owned by the JsepTransport2. In ORTC aspect, RtpTransportAdapter is now a wrapper over RtpTransport or SrtpTransport and it implements the public and internal interface by calling the transport underneath. Bug: webrtc:8587 Change-Id: Ia7fa61288a566f211f8560072ea0eecaf19e48df Reviewed-on: https://webrtc-review.googlesource.com/59586 Commit-Queue: Zhi Huang <zhihuang@webrtc.org> Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22693}
125 lines
5.5 KiB
C++
125 lines
5.5 KiB
C++
/*
|
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include <memory>
|
|
|
|
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
|
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
|
|
#include "media/base/fakemediaengine.h"
|
|
#include "ortc/ortcfactory.h"
|
|
#include "ortc/testrtpparameters.h"
|
|
#include "p2p/base/fakepackettransport.h"
|
|
#include "rtc_base/gunit.h"
|
|
|
|
namespace webrtc {
|
|
|
|
static const char kTestSha1KeyParams1[] =
|
|
"inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz";
|
|
static const char kTestSha1KeyParams2[] =
|
|
"inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR";
|
|
static const char kTestGcmKeyParams3[] =
|
|
"inline:e166KFlKzJsGW0d5apX+rrI05vxbrvMJEzFI14aTDCa63IRTlLK4iH66uOI=";
|
|
|
|
static const cricket::CryptoParams kTestSha1CryptoParams1(
|
|
1,
|
|
"AES_CM_128_HMAC_SHA1_80",
|
|
kTestSha1KeyParams1,
|
|
"");
|
|
static const cricket::CryptoParams kTestSha1CryptoParams2(
|
|
1,
|
|
"AES_CM_128_HMAC_SHA1_80",
|
|
kTestSha1KeyParams2,
|
|
"");
|
|
static const cricket::CryptoParams kTestGcmCryptoParams3(1,
|
|
"AEAD_AES_256_GCM",
|
|
kTestGcmKeyParams3,
|
|
"");
|
|
|
|
// This test uses fake packet transports and a fake media engine, in order to
|
|
// test the SrtpTransport at only an API level. Any end-to-end test should go in
|
|
// ortcfactory_integrationtest.cc instead.
|
|
class SrtpTransportTest : public testing::Test {
|
|
public:
|
|
SrtpTransportTest() {
|
|
fake_media_engine_ = new cricket::FakeMediaEngine();
|
|
// Note: This doesn't need to use fake network classes, since it uses
|
|
// FakePacketTransports.
|
|
auto result = OrtcFactory::Create(
|
|
nullptr, nullptr, nullptr, nullptr, nullptr,
|
|
std::unique_ptr<cricket::MediaEngineInterface>(fake_media_engine_),
|
|
CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory());
|
|
ortc_factory_ = result.MoveValue();
|
|
rtp_transport_controller_ =
|
|
ortc_factory_->CreateRtpTransportController().MoveValue();
|
|
|
|
fake_packet_transport_.reset(new rtc::FakePacketTransport("fake"));
|
|
auto srtp_transport_result = ortc_factory_->CreateSrtpTransport(
|
|
rtp_transport_parameters_, fake_packet_transport_.get(), nullptr,
|
|
rtp_transport_controller_.get());
|
|
srtp_transport_ = srtp_transport_result.MoveValue();
|
|
}
|
|
|
|
protected:
|
|
// Owned by |ortc_factory_|.
|
|
cricket::FakeMediaEngine* fake_media_engine_;
|
|
std::unique_ptr<OrtcFactoryInterface> ortc_factory_;
|
|
std::unique_ptr<RtpTransportControllerInterface> rtp_transport_controller_;
|
|
std::unique_ptr<SrtpTransportInterface> srtp_transport_;
|
|
RtpTransportParameters rtp_transport_parameters_;
|
|
std::unique_ptr<rtc::FakePacketTransport> fake_packet_transport_;
|
|
};
|
|
|
|
// Tests that setting the SRTP send/receive key succeeds.
|
|
TEST_F(SrtpTransportTest, SetSrtpSendAndReceiveKey) {
|
|
EXPECT_TRUE(srtp_transport_->SetSrtpSendKey(kTestSha1CryptoParams1).ok());
|
|
EXPECT_TRUE(srtp_transport_->SetSrtpReceiveKey(kTestSha1CryptoParams2).ok());
|
|
auto sender_result = ortc_factory_->CreateRtpSender(cricket::MEDIA_TYPE_AUDIO,
|
|
srtp_transport_.get());
|
|
EXPECT_TRUE(sender_result.ok());
|
|
auto receiver_result = ortc_factory_->CreateRtpReceiver(
|
|
cricket::MEDIA_TYPE_AUDIO, srtp_transport_.get());
|
|
EXPECT_TRUE(receiver_result.ok());
|
|
}
|
|
|
|
// Tests that setting the SRTP send/receive key twice is not supported.
|
|
TEST_F(SrtpTransportTest, SetSrtpSendAndReceiveKeyTwice) {
|
|
EXPECT_TRUE(srtp_transport_->SetSrtpSendKey(kTestSha1CryptoParams1).ok());
|
|
EXPECT_TRUE(srtp_transport_->SetSrtpReceiveKey(kTestSha1CryptoParams2).ok());
|
|
EXPECT_EQ(RTCErrorType::UNSUPPORTED_OPERATION,
|
|
srtp_transport_->SetSrtpSendKey(kTestSha1CryptoParams2).type());
|
|
EXPECT_EQ(RTCErrorType::UNSUPPORTED_OPERATION,
|
|
srtp_transport_->SetSrtpReceiveKey(kTestSha1CryptoParams1).type());
|
|
// Ensure that the senders and receivers can be created despite the previous
|
|
// errors.
|
|
auto sender_result = ortc_factory_->CreateRtpSender(cricket::MEDIA_TYPE_AUDIO,
|
|
srtp_transport_.get());
|
|
EXPECT_TRUE(sender_result.ok());
|
|
auto receiver_result = ortc_factory_->CreateRtpReceiver(
|
|
cricket::MEDIA_TYPE_AUDIO, srtp_transport_.get());
|
|
EXPECT_TRUE(receiver_result.ok());
|
|
}
|
|
|
|
// Test that the SRTP send key and receive key must have the same cipher suite.
|
|
TEST_F(SrtpTransportTest, SetSrtpSendAndReceiveKeyDifferentCipherSuite) {
|
|
EXPECT_TRUE(srtp_transport_->SetSrtpSendKey(kTestSha1CryptoParams1).ok());
|
|
EXPECT_EQ(RTCErrorType::UNSUPPORTED_OPERATION,
|
|
srtp_transport_->SetSrtpReceiveKey(kTestGcmCryptoParams3).type());
|
|
EXPECT_TRUE(srtp_transport_->SetSrtpReceiveKey(kTestSha1CryptoParams2).ok());
|
|
// Ensure that the senders and receivers can be created despite the previous
|
|
// error.
|
|
auto sender_result = ortc_factory_->CreateRtpSender(cricket::MEDIA_TYPE_AUDIO,
|
|
srtp_transport_.get());
|
|
EXPECT_TRUE(sender_result.ok());
|
|
auto receiver_result = ortc_factory_->CreateRtpReceiver(
|
|
cricket::MEDIA_TYPE_AUDIO, srtp_transport_.get());
|
|
EXPECT_TRUE(receiver_result.ok());
|
|
}
|
|
|
|
} // namespace webrtc
|