Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include <memory> | |
| 12 | |
| 13 #include "webrtc/base/gunit.h" | |
| 14 #include "webrtc/media/base/fakemediaengine.h" | |
| 15 #include "webrtc/ortc/ortcfactory.h" | |
| 16 #include "webrtc/ortc/testrtpparameters.h" | |
| 17 #include "webrtc/p2p/base/fakepackettransport.h" | |
| 18 | |
| 19 namespace webrtc { | |
| 20 | |
| 21 static const char kTestKeyParams1[] = | |
| 22 "inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz"; | |
| 23 static const char kTestKeyParams2[] = | |
| 24 "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR"; | |
| 25 static const char kTestKeyParams3[] = | |
|
Taylor Brandstetter
2017/03/02 23:51:10
nit: Could these constants have names that make it
| |
| 26 "inline:e166KFlKzJsGW0d5apX+rrI05vxbrvMJEzFI14aTDCa63IRTlLK4iH66uOI="; | |
| 27 | |
| 28 static const cricket::CryptoParams kTestCryptoParams1(1, | |
| 29 "AES_CM_128_HMAC_SHA1_80", | |
| 30 kTestKeyParams1, | |
| 31 ""); | |
| 32 static const cricket::CryptoParams kTestCryptoParams2(1, | |
| 33 "AES_CM_128_HMAC_SHA1_80", | |
| 34 kTestKeyParams2, | |
| 35 ""); | |
| 36 static const cricket::CryptoParams kTestCryptoParams3(1, | |
| 37 "AEAD_AES_256_GCM", | |
| 38 kTestKeyParams3, | |
| 39 ""); | |
| 40 | |
| 41 // This test uses fake packet transports and a fake media engine, in order to | |
| 42 // test the SrtpTransport at only an API level. Any end-to-end test should go in | |
| 43 // ortcfactory_integrationtest.cc instead. | |
| 44 class SrtpTransportTest : public testing::Test { | |
| 45 public: | |
| 46 SrtpTransportTest() { | |
| 47 fake_media_engine_ = new cricket::FakeMediaEngine(); | |
| 48 // Note: This doesn't need to use fake network classes, since it uses | |
| 49 // FakePacketTransports. | |
| 50 auto result = OrtcFactory::Create( | |
| 51 nullptr, nullptr, nullptr, nullptr, nullptr, | |
| 52 std::unique_ptr<cricket::MediaEngineInterface>(fake_media_engine_)); | |
| 53 ortc_factory_ = result.MoveValue(); | |
| 54 rtp_transport_controller_ = | |
| 55 ortc_factory_->CreateRtpTransportController().MoveValue(); | |
| 56 | |
| 57 fake_packet_transport_.reset(new rtc::FakePacketTransport("fake")); | |
| 58 auto srtp_transport_result = ortc_factory_->CreateSrtpTransport( | |
| 59 rtcp_parameters_, fake_packet_transport_.get(), nullptr, | |
| 60 rtp_transport_controller_.get()); | |
| 61 srtp_transport_ = srtp_transport_result.MoveValue(); | |
| 62 } | |
| 63 | |
| 64 protected: | |
| 65 // Owned by |ortc_factory_|. | |
| 66 cricket::FakeMediaEngine* fake_media_engine_; | |
| 67 std::unique_ptr<OrtcFactoryInterface> ortc_factory_; | |
| 68 std::unique_ptr<RtpTransportControllerInterface> rtp_transport_controller_; | |
| 69 std::unique_ptr<SrtpTransportInterface> srtp_transport_; | |
| 70 RtcpParameters rtcp_parameters_; | |
| 71 std::unique_ptr<rtc::FakePacketTransport> fake_packet_transport_; | |
| 72 }; | |
| 73 | |
| 74 // Tests that setting the SRTP send/receive key succeeds. | |
| 75 TEST_F(SrtpTransportTest, SetSrtpSendAndReceiveKey) { | |
| 76 EXPECT_TRUE(srtp_transport_->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
| 77 EXPECT_TRUE(srtp_transport_->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
| 78 auto sender_result = ortc_factory_->CreateRtpSender(cricket::MEDIA_TYPE_AUDIO, | |
| 79 srtp_transport_.get()); | |
| 80 EXPECT_TRUE(sender_result.ok()); | |
| 81 auto receiver_result = ortc_factory_->CreateRtpReceiver( | |
| 82 cricket::MEDIA_TYPE_AUDIO, srtp_transport_.get()); | |
| 83 EXPECT_TRUE(receiver_result.ok()); | |
| 84 } | |
| 85 | |
| 86 // Tests that setting the SRTP send/receive key twice is not supported. | |
| 87 TEST_F(SrtpTransportTest, SetSrtpSendAndReceiveKeyTwice) { | |
| 88 EXPECT_TRUE(srtp_transport_->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
| 89 EXPECT_TRUE(srtp_transport_->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
| 90 EXPECT_EQ(srtp_transport_->SetSrtpSendKey(kTestCryptoParams2).type(), | |
|
Taylor Brandstetter
2017/03/02 23:51:10
nit: The EXPECT_EQ macro should have the expected
| |
| 91 RTCErrorType::UNSUPPORTED_OPERATION); | |
| 92 EXPECT_EQ(srtp_transport_->SetSrtpReceiveKey(kTestCryptoParams1).type(), | |
| 93 RTCErrorType::UNSUPPORTED_OPERATION); | |
| 94 // Ensure that the senders and receivers can be created despite the previous | |
| 95 // errors. | |
| 96 auto sender_result = ortc_factory_->CreateRtpSender(cricket::MEDIA_TYPE_AUDIO, | |
| 97 srtp_transport_.get()); | |
| 98 EXPECT_TRUE(sender_result.ok()); | |
| 99 auto receiver_result = ortc_factory_->CreateRtpReceiver( | |
| 100 cricket::MEDIA_TYPE_AUDIO, srtp_transport_.get()); | |
| 101 EXPECT_TRUE(receiver_result.ok()); | |
| 102 } | |
| 103 | |
| 104 // Test that the SRTP send key and receive key must have the same cipher suite. | |
| 105 TEST_F(SrtpTransportTest, SetSrtpSendAndReceiveKeyDifferentCipherSuite) { | |
| 106 EXPECT_TRUE(srtp_transport_->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
| 107 EXPECT_EQ(srtp_transport_->SetSrtpReceiveKey(kTestCryptoParams3).type(), | |
| 108 RTCErrorType::UNSUPPORTED_OPERATION); | |
| 109 EXPECT_TRUE(srtp_transport_->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
| 110 // Ensure that the senders and receivers can be created despite the previous | |
| 111 // error. | |
| 112 auto sender_result = ortc_factory_->CreateRtpSender(cricket::MEDIA_TYPE_AUDIO, | |
| 113 srtp_transport_.get()); | |
| 114 EXPECT_TRUE(sender_result.ok()); | |
| 115 auto receiver_result = ortc_factory_->CreateRtpReceiver( | |
| 116 cricket::MEDIA_TYPE_AUDIO, srtp_transport_.get()); | |
| 117 EXPECT_TRUE(receiver_result.ok()); | |
| 118 } | |
| 119 | |
| 120 class SrtpTransportTestWithMediaType | |
| 121 : public SrtpTransportTest, | |
| 122 public ::testing::WithParamInterface<cricket::MediaType> {}; | |
| 123 | |
| 124 // Tests that the senders cannot be created before setting the keys. | |
| 125 TEST_P(SrtpTransportTestWithMediaType, CreateSenderBeforeSettingKeys) { | |
| 126 auto sender_result = | |
| 127 ortc_factory_->CreateRtpSender(GetParam(), srtp_transport_.get()); | |
| 128 EXPECT_EQ(sender_result.error().type(), RTCErrorType::UNSUPPORTED_PARAMETER); | |
| 129 EXPECT_TRUE(srtp_transport_->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
| 130 sender_result = | |
| 131 ortc_factory_->CreateRtpSender(GetParam(), srtp_transport_.get()); | |
| 132 EXPECT_EQ(sender_result.error().type(), RTCErrorType::UNSUPPORTED_PARAMETER); | |
| 133 EXPECT_TRUE(srtp_transport_->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
| 134 // Ensure that after the keys are set, a sender can be created, despite the | |
| 135 // previous errors. | |
| 136 sender_result = | |
| 137 ortc_factory_->CreateRtpSender(GetParam(), srtp_transport_.get()); | |
| 138 EXPECT_TRUE(sender_result.ok()); | |
| 139 } | |
| 140 | |
| 141 // Tests that the receivers cannot be created before setting the keys. | |
| 142 TEST_P(SrtpTransportTestWithMediaType, CreateReceiverBeforeSettingKeys) { | |
| 143 auto receiver_result = | |
| 144 ortc_factory_->CreateRtpReceiver(GetParam(), srtp_transport_.get()); | |
| 145 EXPECT_EQ(receiver_result.error().type(), | |
| 146 RTCErrorType::UNSUPPORTED_PARAMETER); | |
| 147 EXPECT_TRUE(srtp_transport_->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
| 148 receiver_result = | |
| 149 ortc_factory_->CreateRtpReceiver(GetParam(), srtp_transport_.get()); | |
| 150 EXPECT_EQ(receiver_result.error().type(), | |
| 151 RTCErrorType::UNSUPPORTED_PARAMETER); | |
| 152 EXPECT_TRUE(srtp_transport_->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
| 153 // Ensure that after the keys are set, a receiver can be created, despite the | |
| 154 // previous errors. | |
| 155 receiver_result = | |
| 156 ortc_factory_->CreateRtpReceiver(GetParam(), srtp_transport_.get()); | |
| 157 EXPECT_TRUE(receiver_result.ok()); | |
| 158 } | |
| 159 | |
| 160 INSTANTIATE_TEST_CASE_P(SenderCreatationTest, | |
| 161 SrtpTransportTestWithMediaType, | |
| 162 ::testing::Values(cricket::MEDIA_TYPE_AUDIO, | |
| 163 cricket::MEDIA_TYPE_VIDEO)); | |
| 164 | |
| 165 } // namespace webrtc | |
| OLD | NEW |