OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
9 #include "crypto/ec_private_key.h" | 9 #include "crypto/ec_private_key.h" |
10 #include "crypto/ec_signature_creator.h" | 10 #include "crypto/ec_signature_creator.h" |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 crypto::ECSignatureCreator::Create(private_key.get())); | 551 crypto::ECSignatureCreator::Create(private_key.get())); |
552 creator->Sign(secret, arraysize(secret), &proof_data); | 552 creator->Sign(secret, arraysize(secret), &proof_data); |
553 proof->assign(proof_data.begin(), proof_data.end()); | 553 proof->assign(proof_data.begin(), proof_data.end()); |
554 } | 554 } |
555 | 555 |
556 } // namespace | 556 } // namespace |
557 | 557 |
558 // Constructs a standard SPDY SYN_STREAM frame for a GET request with | 558 // Constructs a standard SPDY SYN_STREAM frame for a GET request with |
559 // a credential set. | 559 // a credential set. |
560 SpdyFrame* ConstructCredentialRequestFrame(int slot, const GURL& url, | 560 SpdyFrame* ConstructCredentialRequestFrame(int slot, const GURL& url, |
561 int stream_id) { | 561 int stream_id) { |
562 const SpdyHeaderInfo syn_headers = { | 562 const SpdyHeaderInfo syn_headers = { |
563 SYN_STREAM, | 563 SYN_STREAM, |
564 stream_id, | 564 stream_id, |
565 0, | 565 0, |
566 ConvertRequestPriorityToSpdyPriority(LOWEST, 3), | 566 ConvertRequestPriorityToSpdyPriority(LOWEST, 3), |
567 slot, | 567 slot, |
568 CONTROL_FLAG_FIN, | 568 CONTROL_FLAG_FIN, |
569 false, | 569 false, |
570 INVALID, | 570 INVALID, |
571 NULL, | 571 NULL, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 callback.WaitForResult(); | 728 callback.WaitForResult(); |
729 | 729 |
730 EXPECT_EQ(ERR_IO_PENDING, http_stream2->ReadResponseHeaders( | 730 EXPECT_EQ(ERR_IO_PENDING, http_stream2->ReadResponseHeaders( |
731 callback.callback())); | 731 callback.callback())); |
732 data.RunFor(1); | 732 data.RunFor(1); |
733 EXPECT_EQ(OK, callback.WaitForResult()); | 733 EXPECT_EQ(OK, callback.WaitForResult()); |
734 ASSERT_TRUE(response.headers.get() != NULL); | 734 ASSERT_TRUE(response.headers.get() != NULL); |
735 ASSERT_EQ(200, response.headers->response_code()); | 735 ASSERT_EQ(200, response.headers->response_code()); |
736 } | 736 } |
737 | 737 |
738 class MockECSignatureCreator : public crypto::ECSignatureCreator { | |
739 public: | |
740 explicit MockECSignatureCreator(crypto::ECPrivateKey* key) : key_(key) {} | |
741 | |
742 virtual bool Sign(const uint8* data, | |
743 int data_len, | |
744 std::vector<uint8>* signature) OVERRIDE { | |
745 std::vector<uint8> private_key_value; | |
746 key_->ExportValue(&private_key_value); | |
747 std::string head = "fakesignature"; | |
748 std::string tail = "/fakesignature"; | |
749 | |
750 signature->clear(); | |
751 signature->insert(signature->end(), head.begin(), head.end()); | |
752 signature->insert(signature->end(), private_key_value.begin(), | |
753 private_key_value.end()); | |
754 signature->insert(signature->end(), '-'); | |
755 signature->insert(signature->end(), data, data + data_len); | |
756 signature->insert(signature->end(), tail.begin(), tail.end()); | |
757 return true; | |
758 } | |
759 | |
760 private: | |
761 crypto::ECPrivateKey* key_; | |
762 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreator); | |
763 }; | |
764 | |
765 class MockECSignatureCreatorFactory : public crypto::ECSignatureCreatorFactory { | |
766 public: | |
767 MockECSignatureCreatorFactory() {} | |
768 virtual ~MockECSignatureCreatorFactory() {} | |
769 | |
770 virtual crypto::ECSignatureCreator* Create( | |
771 crypto::ECPrivateKey* key) OVERRIDE { | |
772 return new MockECSignatureCreator(key); | |
773 } | |
774 private: | |
775 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreatorFactory); | |
776 }; | |
777 | |
778 TEST_F(SpdyHttpStreamSpdy3Test, SendCredentialsEC) { | 738 TEST_F(SpdyHttpStreamSpdy3Test, SendCredentialsEC) { |
779 scoped_ptr<crypto::ECSignatureCreatorFactory> ec_signature_creator_factory( | |
780 new MockECSignatureCreatorFactory()); | |
781 crypto::ECSignatureCreator::SetFactoryForTesting( | |
782 ec_signature_creator_factory.get()); | |
783 | |
784 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = | 739 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = |
785 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); | 740 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); |
786 scoped_ptr<ServerBoundCertService> server_bound_cert_service( | 741 scoped_ptr<ServerBoundCertService> server_bound_cert_service( |
787 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), | 742 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), |
788 sequenced_worker_pool)); | 743 sequenced_worker_pool)); |
789 std::string cert; | 744 std::string cert; |
790 std::string proof; | 745 std::string proof; |
791 GetECServerBoundCertAndProof("http://www.gmail.com/", | 746 GetECServerBoundCertAndProof("http://www.gmail.com/", |
792 server_bound_cert_service.get(), | 747 server_bound_cert_service.get(), |
793 &cert, &proof); | 748 &cert, &proof); |
794 | 749 |
795 TestSendCredentials(server_bound_cert_service.get(), cert, proof); | 750 TestSendCredentials(server_bound_cert_service.get(), cert, proof); |
796 | 751 |
797 sequenced_worker_pool->Shutdown(); | 752 sequenced_worker_pool->Shutdown(); |
798 } | 753 } |
799 | 754 |
800 #endif // !defined(USE_OPENSSL) | 755 #endif // !defined(USE_OPENSSL) |
801 | 756 |
802 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 757 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
803 // methods. | 758 // methods. |
804 | 759 |
805 } // namespace net | 760 } // namespace net |
OLD | NEW |