| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 using cricket::DataCodec; | 66 using cricket::DataCodec; |
| 67 using cricket::NS_JINGLE_RTP; | 67 using cricket::NS_JINGLE_RTP; |
| 68 using cricket::MEDIA_TYPE_AUDIO; | 68 using cricket::MEDIA_TYPE_AUDIO; |
| 69 using cricket::MEDIA_TYPE_VIDEO; | 69 using cricket::MEDIA_TYPE_VIDEO; |
| 70 using cricket::MEDIA_TYPE_DATA; | 70 using cricket::MEDIA_TYPE_DATA; |
| 71 using cricket::SEC_DISABLED; | 71 using cricket::SEC_DISABLED; |
| 72 using cricket::SEC_ENABLED; | 72 using cricket::SEC_ENABLED; |
| 73 using cricket::SEC_REQUIRED; | 73 using cricket::SEC_REQUIRED; |
| 74 using rtc::CS_AES_CM_128_HMAC_SHA1_32; | 74 using rtc::CS_AES_CM_128_HMAC_SHA1_32; |
| 75 using rtc::CS_AES_CM_128_HMAC_SHA1_80; | 75 using rtc::CS_AES_CM_128_HMAC_SHA1_80; |
| 76 using rtc::CS_AEAD_AES_128_GCM; |
| 77 using rtc::CS_AEAD_AES_256_GCM; |
| 76 using webrtc::RtpExtension; | 78 using webrtc::RtpExtension; |
| 77 | 79 |
| 78 static const AudioCodec kAudioCodecs1[] = { | 80 static const AudioCodec kAudioCodecs1[] = { |
| 79 AudioCodec(103, "ISAC", 16000, -1, 1), | 81 AudioCodec(103, "ISAC", 16000, -1, 1), |
| 80 AudioCodec(102, "iLBC", 8000, 13300, 1), | 82 AudioCodec(102, "iLBC", 8000, 13300, 1), |
| 81 AudioCodec(0, "PCMU", 8000, 64000, 1), | 83 AudioCodec(0, "PCMU", 8000, 64000, 1), |
| 82 AudioCodec(8, "PCMA", 8000, 64000, 1), | 84 AudioCodec(8, "PCMA", 8000, 64000, 1), |
| 83 AudioCodec(117, "red", 8000, 0, 1), | 85 AudioCodec(117, "red", 8000, 0, 1), |
| 84 AudioCodec(107, "CN", 48000, 0, 1)}; | 86 AudioCodec(107, "CN", 48000, 0, 1)}; |
| 85 | 87 |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 const cricket::AudioContentDescription* audio_content_desc = | 448 const cricket::AudioContentDescription* audio_content_desc = |
| 447 static_cast<const cricket::AudioContentDescription*>(description); | 449 static_cast<const cricket::AudioContentDescription*>(description); |
| 448 ASSERT(audio_content_desc != NULL); | 450 ASSERT(audio_content_desc != NULL); |
| 449 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { | 451 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { |
| 450 if (audio_content_desc->codecs()[i].name == "CN") | 452 if (audio_content_desc->codecs()[i].name == "CN") |
| 451 return false; | 453 return false; |
| 452 } | 454 } |
| 453 return true; | 455 return true; |
| 454 } | 456 } |
| 455 | 457 |
| 458 void TestVideoGcmCipher(bool gcm_offer, bool gcm_answer) { |
| 459 MediaSessionOptions offer_opts; |
| 460 offer_opts.recv_video = true; |
| 461 offer_opts.crypto_options.enable_gcm_crypto_suites = gcm_offer; |
| 462 MediaSessionOptions answer_opts; |
| 463 answer_opts.recv_video = true; |
| 464 answer_opts.crypto_options.enable_gcm_crypto_suites = gcm_answer; |
| 465 f1_.set_secure(SEC_ENABLED); |
| 466 f2_.set_secure(SEC_ENABLED); |
| 467 std::unique_ptr<SessionDescription> offer( |
| 468 f1_.CreateOffer(offer_opts, NULL)); |
| 469 ASSERT_TRUE(offer.get() != NULL); |
| 470 std::unique_ptr<SessionDescription> answer( |
| 471 f2_.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 472 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 473 const ContentInfo* vc = answer->GetContentByName("video"); |
| 474 ASSERT_TRUE(ac != NULL); |
| 475 ASSERT_TRUE(vc != NULL); |
| 476 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 477 EXPECT_EQ(std::string(NS_JINGLE_RTP), vc->type); |
| 478 const AudioContentDescription* acd = |
| 479 static_cast<const AudioContentDescription*>(ac->description); |
| 480 const VideoContentDescription* vcd = |
| 481 static_cast<const VideoContentDescription*>(vc->description); |
| 482 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 483 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 484 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 485 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc |
| 486 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 487 if (gcm_offer && gcm_answer) { |
| 488 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); |
| 489 } else { |
| 490 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
| 491 } |
| 492 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
| 493 EXPECT_EQ(MAKE_VECTOR(kVideoCodecsAnswer), vcd->codecs()); |
| 494 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc |
| 495 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
| 496 if (gcm_offer && gcm_answer) { |
| 497 ASSERT_CRYPTO(vcd, 1U, CS_AEAD_AES_256_GCM); |
| 498 } else { |
| 499 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 500 } |
| 501 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
| 502 } |
| 503 |
| 456 protected: | 504 protected: |
| 457 MediaSessionDescriptionFactory f1_; | 505 MediaSessionDescriptionFactory f1_; |
| 458 MediaSessionDescriptionFactory f2_; | 506 MediaSessionDescriptionFactory f2_; |
| 459 TransportDescriptionFactory tdf1_; | 507 TransportDescriptionFactory tdf1_; |
| 460 TransportDescriptionFactory tdf2_; | 508 TransportDescriptionFactory tdf2_; |
| 461 }; | 509 }; |
| 462 | 510 |
| 463 // Create a typical audio offer, and ensure it matches what we expect. | 511 // Create a typical audio offer, and ensure it matches what we expect. |
| 464 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOffer) { | 512 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOffer) { |
| 465 f1_.set_secure(SEC_ENABLED); | 513 f1_.set_secure(SEC_ENABLED); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 static_cast<const AudioContentDescription*>(ac->description); | 807 static_cast<const AudioContentDescription*>(ac->description); |
| 760 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 808 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 761 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); | 809 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 762 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc | 810 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc |
| 763 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw | 811 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 764 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 812 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 765 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); | 813 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
| 766 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); | 814 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); |
| 767 } | 815 } |
| 768 | 816 |
| 817 // Create a typical audio answer with GCM ciphers enabled, and ensure it |
| 818 // matches what we expect. |
| 819 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerGcm) { |
| 820 f1_.set_secure(SEC_ENABLED); |
| 821 f2_.set_secure(SEC_ENABLED); |
| 822 MediaSessionOptions options; |
| 823 options.crypto_options.enable_gcm_crypto_suites = true; |
| 824 std::unique_ptr<SessionDescription> offer( |
| 825 f1_.CreateOffer(options, NULL)); |
| 826 ASSERT_TRUE(offer.get() != NULL); |
| 827 std::unique_ptr<SessionDescription> answer( |
| 828 f2_.CreateAnswer(offer.get(), options, NULL)); |
| 829 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 830 const ContentInfo* vc = answer->GetContentByName("video"); |
| 831 ASSERT_TRUE(ac != NULL); |
| 832 ASSERT_TRUE(vc == NULL); |
| 833 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 834 const AudioContentDescription* acd = |
| 835 static_cast<const AudioContentDescription*>(ac->description); |
| 836 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 837 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 838 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc |
| 839 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 840 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 841 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); |
| 842 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); |
| 843 } |
| 844 |
| 769 // Create a typical video answer, and ensure it matches what we expect. | 845 // Create a typical video answer, and ensure it matches what we expect. |
| 770 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswer) { | 846 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswer) { |
| 771 MediaSessionOptions opts; | 847 MediaSessionOptions opts; |
| 772 opts.recv_video = true; | 848 opts.recv_video = true; |
| 773 f1_.set_secure(SEC_ENABLED); | 849 f1_.set_secure(SEC_ENABLED); |
| 774 f2_.set_secure(SEC_ENABLED); | 850 f2_.set_secure(SEC_ENABLED); |
| 775 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 851 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 776 ASSERT_TRUE(offer.get() != NULL); | 852 ASSERT_TRUE(offer.get() != NULL); |
| 777 std::unique_ptr<SessionDescription> answer( | 853 std::unique_ptr<SessionDescription> answer( |
| 778 f2_.CreateAnswer(offer.get(), opts, NULL)); | 854 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 793 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 869 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 794 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); | 870 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
| 795 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); | 871 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
| 796 EXPECT_EQ(MAKE_VECTOR(kVideoCodecsAnswer), vcd->codecs()); | 872 EXPECT_EQ(MAKE_VECTOR(kVideoCodecsAnswer), vcd->codecs()); |
| 797 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc | 873 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc |
| 798 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux | 874 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
| 799 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 875 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 800 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); | 876 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
| 801 } | 877 } |
| 802 | 878 |
| 879 // Create a typical video answer with GCM ciphers enabled, and ensure it |
| 880 // matches what we expect. |
| 881 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcm) { |
| 882 TestVideoGcmCipher(true, true); |
| 883 } |
| 884 |
| 885 // Create a typical video answer with GCM ciphers enabled for the offer only, |
| 886 // and ensure it matches what we expect. |
| 887 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmOffer) { |
| 888 TestVideoGcmCipher(true, false); |
| 889 } |
| 890 |
| 891 // Create a typical video answer with GCM ciphers enabled for the answer only, |
| 892 // and ensure it matches what we expect. |
| 893 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmAnswer) { |
| 894 TestVideoGcmCipher(false, true); |
| 895 } |
| 896 |
| 803 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswer) { | 897 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswer) { |
| 804 MediaSessionOptions opts; | 898 MediaSessionOptions opts; |
| 805 opts.data_channel_type = cricket::DCT_RTP; | 899 opts.data_channel_type = cricket::DCT_RTP; |
| 806 f1_.set_secure(SEC_ENABLED); | 900 f1_.set_secure(SEC_ENABLED); |
| 807 f2_.set_secure(SEC_ENABLED); | 901 f2_.set_secure(SEC_ENABLED); |
| 808 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 902 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 809 ASSERT_TRUE(offer.get() != NULL); | 903 ASSERT_TRUE(offer.get() != NULL); |
| 810 std::unique_ptr<SessionDescription> answer( | 904 std::unique_ptr<SessionDescription> answer( |
| 811 f2_.CreateAnswer(offer.get(), opts, NULL)); | 905 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 812 const ContentInfo* ac = answer->GetContentByName("audio"); | 906 const ContentInfo* ac = answer->GetContentByName("audio"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 826 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 920 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 827 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); | 921 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
| 828 EXPECT_EQ(MEDIA_TYPE_DATA, vcd->type()); | 922 EXPECT_EQ(MEDIA_TYPE_DATA, vcd->type()); |
| 829 EXPECT_EQ(MAKE_VECTOR(kDataCodecsAnswer), vcd->codecs()); | 923 EXPECT_EQ(MAKE_VECTOR(kDataCodecsAnswer), vcd->codecs()); |
| 830 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc | 924 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc |
| 831 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux | 925 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
| 832 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 926 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 833 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); | 927 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
| 834 } | 928 } |
| 835 | 929 |
| 930 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerGcm) { |
| 931 MediaSessionOptions opts; |
| 932 opts.data_channel_type = cricket::DCT_RTP; |
| 933 opts.crypto_options.enable_gcm_crypto_suites = true; |
| 934 f1_.set_secure(SEC_ENABLED); |
| 935 f2_.set_secure(SEC_ENABLED); |
| 936 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 937 ASSERT_TRUE(offer.get() != NULL); |
| 938 std::unique_ptr<SessionDescription> answer( |
| 939 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 940 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 941 const ContentInfo* vc = answer->GetContentByName("data"); |
| 942 ASSERT_TRUE(ac != NULL); |
| 943 ASSERT_TRUE(vc != NULL); |
| 944 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 945 EXPECT_EQ(std::string(NS_JINGLE_RTP), vc->type); |
| 946 const AudioContentDescription* acd = |
| 947 static_cast<const AudioContentDescription*>(ac->description); |
| 948 const DataContentDescription* vcd = |
| 949 static_cast<const DataContentDescription*>(vc->description); |
| 950 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 951 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 952 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 953 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc |
| 954 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 955 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); |
| 956 EXPECT_EQ(MEDIA_TYPE_DATA, vcd->type()); |
| 957 EXPECT_EQ(MAKE_VECTOR(kDataCodecsAnswer), vcd->codecs()); |
| 958 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc |
| 959 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
| 960 ASSERT_CRYPTO(vcd, 1U, CS_AEAD_AES_256_GCM); |
| 961 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
| 962 } |
| 963 |
| 836 // Verifies that the order of the media contents in the offer is preserved in | 964 // Verifies that the order of the media contents in the offer is preserved in |
| 837 // the answer. | 965 // the answer. |
| 838 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerContentOrder) { | 966 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerContentOrder) { |
| 839 MediaSessionOptions opts; | 967 MediaSessionOptions opts; |
| 840 | 968 |
| 841 // Creates a data only offer. | 969 // Creates a data only offer. |
| 842 opts.recv_audio = false; | 970 opts.recv_audio = false; |
| 843 opts.data_channel_type = cricket::DCT_SCTP; | 971 opts.data_channel_type = cricket::DCT_SCTP; |
| 844 std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); | 972 std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
| 845 ASSERT_TRUE(offer1.get() != NULL); | 973 ASSERT_TRUE(offer1.get() != NULL); |
| (...skipping 1902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2748 ::testing::Combine( | 2876 ::testing::Combine( |
| 2749 ::testing::Values(cricket::MD_SENDONLY, | 2877 ::testing::Values(cricket::MD_SENDONLY, |
| 2750 cricket::MD_RECVONLY, | 2878 cricket::MD_RECVONLY, |
| 2751 cricket::MD_SENDRECV, | 2879 cricket::MD_SENDRECV, |
| 2752 cricket::MD_INACTIVE), | 2880 cricket::MD_INACTIVE), |
| 2753 ::testing::Values(cricket::MD_SENDONLY, | 2881 ::testing::Values(cricket::MD_SENDONLY, |
| 2754 cricket::MD_RECVONLY, | 2882 cricket::MD_RECVONLY, |
| 2755 cricket::MD_SENDRECV, | 2883 cricket::MD_SENDRECV, |
| 2756 cricket::MD_INACTIVE), | 2884 cricket::MD_INACTIVE), |
| 2757 ::testing::Bool())); | 2885 ::testing::Bool())); |
| OLD | NEW |