Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: talk/session/media/srtpfilter_unittest.cc

Issue 1455233005: Revert of Convert internal representation of Srtp cryptos from string to int. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/session/media/srtpfilter.cc ('k') | webrtc/base/opensslstreamadapter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2004 Google Inc. 3 * Copyright 2004 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // Complete the negotiation. 501 // Complete the negotiation.
502 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); 502 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL));
503 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); 503 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE));
504 504
505 EXPECT_FALSE(f1_.IsActive()); 505 EXPECT_FALSE(f1_.IsActive());
506 EXPECT_FALSE(f2_.IsActive()); 506 EXPECT_FALSE(f2_.IsActive());
507 } 507 }
508 508
509 // Test directly setting the params with AES_CM_128_HMAC_SHA1_80 509 // Test directly setting the params with AES_CM_128_HMAC_SHA1_80
510 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_80) { 510 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_80) {
511 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 511 EXPECT_TRUE(f1_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_80,
512 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80, 512 kTestKey1, kTestKeyLen,
513 CS_AES_CM_128_HMAC_SHA1_80,
513 kTestKey2, kTestKeyLen)); 514 kTestKey2, kTestKeyLen));
514 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2, 515 EXPECT_TRUE(f2_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_80,
515 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80, 516 kTestKey2, kTestKeyLen,
517 CS_AES_CM_128_HMAC_SHA1_80,
516 kTestKey1, kTestKeyLen)); 518 kTestKey1, kTestKeyLen));
517 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 519 EXPECT_TRUE(f1_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_80,
518 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80, 520 kTestKey1, kTestKeyLen,
521 CS_AES_CM_128_HMAC_SHA1_80,
519 kTestKey2, kTestKeyLen)); 522 kTestKey2, kTestKeyLen));
520 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2, 523 EXPECT_TRUE(f2_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_80,
521 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80, 524 kTestKey2, kTestKeyLen,
525 CS_AES_CM_128_HMAC_SHA1_80,
522 kTestKey1, kTestKeyLen)); 526 kTestKey1, kTestKeyLen));
523 EXPECT_TRUE(f1_.IsActive()); 527 EXPECT_TRUE(f1_.IsActive());
524 EXPECT_TRUE(f2_.IsActive()); 528 EXPECT_TRUE(f2_.IsActive());
525 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); 529 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80);
526 } 530 }
527 531
528 // Test directly setting the params with AES_CM_128_HMAC_SHA1_32 532 // Test directly setting the params with AES_CM_128_HMAC_SHA1_32
529 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_32) { 533 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_32) {
530 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, 534 EXPECT_TRUE(f1_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_32,
531 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 535 kTestKey1, kTestKeyLen,
536 CS_AES_CM_128_HMAC_SHA1_32,
532 kTestKey2, kTestKeyLen)); 537 kTestKey2, kTestKeyLen));
533 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey2, 538 EXPECT_TRUE(f2_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_32,
534 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 539 kTestKey2, kTestKeyLen,
540 CS_AES_CM_128_HMAC_SHA1_32,
535 kTestKey1, kTestKeyLen)); 541 kTestKey1, kTestKeyLen));
536 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, 542 EXPECT_TRUE(f1_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_32,
537 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 543 kTestKey1, kTestKeyLen,
544 CS_AES_CM_128_HMAC_SHA1_32,
538 kTestKey2, kTestKeyLen)); 545 kTestKey2, kTestKeyLen));
539 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey2, 546 EXPECT_TRUE(f2_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_32,
540 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 547 kTestKey2, kTestKeyLen,
548 CS_AES_CM_128_HMAC_SHA1_32,
541 kTestKey1, kTestKeyLen)); 549 kTestKey1, kTestKeyLen));
542 EXPECT_TRUE(f1_.IsActive()); 550 EXPECT_TRUE(f1_.IsActive());
543 EXPECT_TRUE(f2_.IsActive()); 551 EXPECT_TRUE(f2_.IsActive());
544 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_32, CS_AES_CM_128_HMAC_SHA1_32); 552 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_32, CS_AES_CM_128_HMAC_SHA1_32);
545 } 553 }
546 554
547 // Test directly setting the params with bogus keys 555 // Test directly setting the params with bogus keys
548 TEST_F(SrtpFilterTest, TestSetParamsKeyTooShort) { 556 TEST_F(SrtpFilterTest, TestSetParamsKeyTooShort) {
549 EXPECT_FALSE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 557 EXPECT_FALSE(f1_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_80,
550 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80, 558 kTestKey1, kTestKeyLen - 1,
559 CS_AES_CM_128_HMAC_SHA1_80,
551 kTestKey1, kTestKeyLen - 1)); 560 kTestKey1, kTestKeyLen - 1));
552 EXPECT_FALSE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 561 EXPECT_FALSE(f1_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_80,
553 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80, 562 kTestKey1, kTestKeyLen - 1,
563 CS_AES_CM_128_HMAC_SHA1_80,
554 kTestKey1, kTestKeyLen - 1)); 564 kTestKey1, kTestKeyLen - 1));
555 } 565 }
556 566
557 #if defined(ENABLE_EXTERNAL_AUTH) 567 #if defined(ENABLE_EXTERNAL_AUTH)
558 TEST_F(SrtpFilterTest, TestGetSendAuthParams) { 568 TEST_F(SrtpFilterTest, TestGetSendAuthParams) {
559 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, 569 EXPECT_TRUE(f1_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_32,
560 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 570 kTestKey1, kTestKeyLen,
571 CS_AES_CM_128_HMAC_SHA1_32,
561 kTestKey2, kTestKeyLen)); 572 kTestKey2, kTestKeyLen));
562 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, 573 EXPECT_TRUE(f1_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_32,
563 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32, 574 kTestKey1, kTestKeyLen,
575 CS_AES_CM_128_HMAC_SHA1_32,
564 kTestKey2, kTestKeyLen)); 576 kTestKey2, kTestKeyLen));
565 uint8_t* auth_key = NULL; 577 uint8_t* auth_key = NULL;
566 int auth_key_len = 0, auth_tag_len = 0; 578 int auth_key_len = 0, auth_tag_len = 0;
567 EXPECT_TRUE(f1_.GetRtpAuthParams(&auth_key, &auth_key_len, &auth_tag_len)); 579 EXPECT_TRUE(f1_.GetRtpAuthParams(&auth_key, &auth_key_len, &auth_tag_len));
568 EXPECT_TRUE(auth_key != NULL); 580 EXPECT_TRUE(auth_key != NULL);
569 EXPECT_EQ(20, auth_key_len); 581 EXPECT_EQ(20, auth_key_len);
570 EXPECT_EQ(4, auth_tag_len); 582 EXPECT_EQ(4, auth_tag_len);
571 } 583 }
572 #endif 584 #endif
573 585
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 cricket::SrtpSession s1_; 622 cricket::SrtpSession s1_;
611 cricket::SrtpSession s2_; 623 cricket::SrtpSession s2_;
612 char rtp_packet_[sizeof(kPcmuFrame) + 10]; 624 char rtp_packet_[sizeof(kPcmuFrame) + 10];
613 char rtcp_packet_[sizeof(kRtcpReport) + 4 + 10]; 625 char rtcp_packet_[sizeof(kRtcpReport) + 4 + 10];
614 int rtp_len_; 626 int rtp_len_;
615 int rtcp_len_; 627 int rtcp_len_;
616 }; 628 };
617 629
618 // Test that we can set up the session and keys properly. 630 // Test that we can set up the session and keys properly.
619 TEST_F(SrtpSessionTest, TestGoodSetup) { 631 TEST_F(SrtpSessionTest, TestGoodSetup) {
620 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 632 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
621 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 633 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
622 } 634 }
623 635
624 // Test that we can't change the keys once set. 636 // Test that we can't change the keys once set.
625 TEST_F(SrtpSessionTest, TestBadSetup) { 637 TEST_F(SrtpSessionTest, TestBadSetup) {
626 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 638 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
627 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 639 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
628 EXPECT_FALSE( 640 EXPECT_FALSE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey2, kTestKeyLen));
629 s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2, kTestKeyLen)); 641 EXPECT_FALSE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey2, kTestKeyLen));
630 EXPECT_FALSE(
631 s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2, kTestKeyLen));
632 } 642 }
633 643
634 // Test that we fail keys of the wrong length. 644 // Test that we fail keys of the wrong length.
635 TEST_F(SrtpSessionTest, TestKeysTooShort) { 645 TEST_F(SrtpSessionTest, TestKeysTooShort) {
636 EXPECT_FALSE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 1)); 646 EXPECT_FALSE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, 1));
637 EXPECT_FALSE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 1)); 647 EXPECT_FALSE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, 1));
638 } 648 }
639 649
640 // Test that we can encrypt and decrypt RTP/RTCP using AES_CM_128_HMAC_SHA1_80. 650 // Test that we can encrypt and decrypt RTP/RTCP using AES_CM_128_HMAC_SHA1_80.
641 TEST_F(SrtpSessionTest, TestProtect_AES_CM_128_HMAC_SHA1_80) { 651 TEST_F(SrtpSessionTest, TestProtect_AES_CM_128_HMAC_SHA1_80) {
642 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 652 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
643 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 653 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
644 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_80); 654 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_80);
645 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_80); 655 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_80);
646 TestUnprotectRtp(CS_AES_CM_128_HMAC_SHA1_80); 656 TestUnprotectRtp(CS_AES_CM_128_HMAC_SHA1_80);
647 TestUnprotectRtcp(CS_AES_CM_128_HMAC_SHA1_80); 657 TestUnprotectRtcp(CS_AES_CM_128_HMAC_SHA1_80);
648 } 658 }
649 659
650 // Test that we can encrypt and decrypt RTP/RTCP using AES_CM_128_HMAC_SHA1_32. 660 // Test that we can encrypt and decrypt RTP/RTCP using AES_CM_128_HMAC_SHA1_32.
651 TEST_F(SrtpSessionTest, TestProtect_AES_CM_128_HMAC_SHA1_32) { 661 TEST_F(SrtpSessionTest, TestProtect_AES_CM_128_HMAC_SHA1_32) {
652 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, kTestKeyLen)); 662 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_32, kTestKey1, kTestKeyLen));
653 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, kTestKeyLen)); 663 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_32, kTestKey1, kTestKeyLen));
654 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_32); 664 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_32);
655 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_32); 665 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_32);
656 TestUnprotectRtp(CS_AES_CM_128_HMAC_SHA1_32); 666 TestUnprotectRtp(CS_AES_CM_128_HMAC_SHA1_32);
657 TestUnprotectRtcp(CS_AES_CM_128_HMAC_SHA1_32); 667 TestUnprotectRtcp(CS_AES_CM_128_HMAC_SHA1_32);
658 } 668 }
659 669
660 TEST_F(SrtpSessionTest, TestGetSendStreamPacketIndex) { 670 TEST_F(SrtpSessionTest, TestGetSendStreamPacketIndex) {
661 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, kTestKeyLen)); 671 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_32, kTestKey1, kTestKeyLen));
662 int64_t index; 672 int64_t index;
663 int out_len = 0; 673 int out_len = 0;
664 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, 674 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_,
665 sizeof(rtp_packet_), &out_len, &index)); 675 sizeof(rtp_packet_), &out_len, &index));
666 // |index| will be shifted by 16. 676 // |index| will be shifted by 16.
667 int64_t be64_index = static_cast<int64_t>(rtc::NetworkToHost64(1 << 16)); 677 int64_t be64_index = static_cast<int64_t>(rtc::NetworkToHost64(1 << 16));
668 EXPECT_EQ(be64_index, index); 678 EXPECT_EQ(be64_index, index);
669 } 679 }
670 680
671 // Test that we fail to unprotect if someone tampers with the RTP/RTCP paylaods. 681 // Test that we fail to unprotect if someone tampers with the RTP/RTCP paylaods.
672 TEST_F(SrtpSessionTest, TestTamperReject) { 682 TEST_F(SrtpSessionTest, TestTamperReject) {
673 int out_len; 683 int out_len;
674 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 684 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
675 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 685 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
676 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_80); 686 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_80);
677 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_80); 687 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_80);
678 rtp_packet_[0] = 0x12; 688 rtp_packet_[0] = 0x12;
679 rtcp_packet_[1] = 0x34; 689 rtcp_packet_[1] = 0x34;
680 EXPECT_FALSE(s2_.UnprotectRtp(rtp_packet_, rtp_len_, &out_len)); 690 EXPECT_FALSE(s2_.UnprotectRtp(rtp_packet_, rtp_len_, &out_len));
681 EXPECT_FALSE(s2_.UnprotectRtcp(rtcp_packet_, rtcp_len_, &out_len)); 691 EXPECT_FALSE(s2_.UnprotectRtcp(rtcp_packet_, rtcp_len_, &out_len));
682 } 692 }
683 693
684 // Test that we fail to unprotect if the payloads are not authenticated. 694 // Test that we fail to unprotect if the payloads are not authenticated.
685 TEST_F(SrtpSessionTest, TestUnencryptReject) { 695 TEST_F(SrtpSessionTest, TestUnencryptReject) {
686 int out_len; 696 int out_len;
687 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 697 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
688 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 698 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
689 EXPECT_FALSE(s2_.UnprotectRtp(rtp_packet_, rtp_len_, &out_len)); 699 EXPECT_FALSE(s2_.UnprotectRtp(rtp_packet_, rtp_len_, &out_len));
690 EXPECT_FALSE(s2_.UnprotectRtcp(rtcp_packet_, rtcp_len_, &out_len)); 700 EXPECT_FALSE(s2_.UnprotectRtcp(rtcp_packet_, rtcp_len_, &out_len));
691 } 701 }
692 702
693 // Test that we fail when using buffers that are too small. 703 // Test that we fail when using buffers that are too small.
694 TEST_F(SrtpSessionTest, TestBuffersTooSmall) { 704 TEST_F(SrtpSessionTest, TestBuffersTooSmall) {
695 int out_len; 705 int out_len;
696 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 706 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
697 EXPECT_FALSE(s1_.ProtectRtp(rtp_packet_, rtp_len_, 707 EXPECT_FALSE(s1_.ProtectRtp(rtp_packet_, rtp_len_,
698 sizeof(rtp_packet_) - 10, &out_len)); 708 sizeof(rtp_packet_) - 10, &out_len));
699 EXPECT_FALSE(s1_.ProtectRtcp(rtcp_packet_, rtcp_len_, 709 EXPECT_FALSE(s1_.ProtectRtcp(rtcp_packet_, rtcp_len_,
700 sizeof(rtcp_packet_) - 14, &out_len)); 710 sizeof(rtcp_packet_) - 14, &out_len));
701 } 711 }
702 712
703 TEST_F(SrtpSessionTest, TestReplay) { 713 TEST_F(SrtpSessionTest, TestReplay) {
704 static const uint16_t kMaxSeqnum = static_cast<uint16_t>(-1); 714 static const uint16_t kMaxSeqnum = static_cast<uint16_t>(-1);
705 static const uint16_t seqnum_big = 62275; 715 static const uint16_t seqnum_big = 62275;
706 static const uint16_t seqnum_small = 10; 716 static const uint16_t seqnum_small = 10;
707 static const uint16_t replay_window = 1024; 717 static const uint16_t replay_window = 1024;
708 int out_len; 718 int out_len;
709 719
710 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 720 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
711 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen)); 721 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen));
712 722
713 // Initial sequence number. 723 // Initial sequence number.
714 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_) + 2, seqnum_big); 724 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_) + 2, seqnum_big);
715 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, sizeof(rtp_packet_), 725 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, sizeof(rtp_packet_),
716 &out_len)); 726 &out_len));
717 727
718 // Replay within the 1024 window should succeed. 728 // Replay within the 1024 window should succeed.
719 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_) + 2, 729 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_) + 2,
720 seqnum_big - replay_window + 1); 730 seqnum_big - replay_window + 1);
721 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, sizeof(rtp_packet_), 731 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, sizeof(rtp_packet_),
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 srtp_stat_.AddUnprotectRtcpResult(err_status_fail); 926 srtp_stat_.AddUnprotectRtcpResult(err_status_fail);
917 EXPECT_EQ(-1, mode_); 927 EXPECT_EQ(-1, mode_);
918 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); 928 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
919 // Now the error will be triggered again. 929 // Now the error will be triggered again.
920 Reset(); 930 Reset();
921 rtc::Thread::Current()->SleepMs(210); 931 rtc::Thread::Current()->SleepMs(210);
922 srtp_stat_.AddUnprotectRtcpResult(err_status_fail); 932 srtp_stat_.AddUnprotectRtcpResult(err_status_fail);
923 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); 933 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
924 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); 934 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
925 } 935 }
OLDNEW
« no previous file with comments | « talk/session/media/srtpfilter.cc ('k') | webrtc/base/opensslstreamadapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698