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_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "crypto/ec_private_key.h" | 24 #include "crypto/ec_private_key.h" |
25 #include "crypto/ec_signature_creator.h" | 25 #include "crypto/ec_signature_creator.h" |
26 #include "crypto/signature_creator.h" | 26 #include "crypto/signature_creator.h" |
27 #include "net/base/asn1_util.h" | 27 #include "net/base/asn1_util.h" |
28 #include "net/base/connection_type_histograms.h" | 28 #include "net/base/connection_type_histograms.h" |
29 #include "net/base/net_log.h" | 29 #include "net/base/net_log.h" |
30 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
31 #include "net/base/server_bound_cert_service.h" | 31 #include "net/base/server_bound_cert_service.h" |
32 #include "net/http/http_network_session.h" | 32 #include "net/http/http_network_session.h" |
33 #include "net/http/http_server_properties.h" | 33 #include "net/http/http_server_properties.h" |
| 34 #include "net/spdy/spdy_credential_builder.h" |
34 #include "net/spdy/spdy_frame_builder.h" | 35 #include "net/spdy/spdy_frame_builder.h" |
35 #include "net/spdy/spdy_http_utils.h" | 36 #include "net/spdy/spdy_http_utils.h" |
36 #include "net/spdy/spdy_protocol.h" | 37 #include "net/spdy/spdy_protocol.h" |
37 #include "net/spdy/spdy_session_pool.h" | 38 #include "net/spdy/spdy_session_pool.h" |
38 #include "net/spdy/spdy_stream.h" | 39 #include "net/spdy/spdy_stream.h" |
39 | 40 |
40 namespace net { | 41 namespace net { |
41 | 42 |
42 namespace { | 43 namespace { |
43 | 44 |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 return syn_frame.release(); | 620 return syn_frame.release(); |
620 } | 621 } |
621 | 622 |
622 SpdyCredentialControlFrame* SpdySession::CreateCredentialFrame( | 623 SpdyCredentialControlFrame* SpdySession::CreateCredentialFrame( |
623 const std::string& origin, | 624 const std::string& origin, |
624 SSLClientCertType type, | 625 SSLClientCertType type, |
625 const std::string& key, | 626 const std::string& key, |
626 const std::string& cert, | 627 const std::string& cert, |
627 RequestPriority priority) { | 628 RequestPriority priority) { |
628 DCHECK(is_secure_); | 629 DCHECK(is_secure_); |
629 unsigned char secret[32]; // 32 bytes from the spec | 630 SSLClientSocket* ssl_socket = GetSSLClientSocket(); |
630 GetSSLClientSocket()->ExportKeyingMaterial("SPDY certificate proof", | 631 DCHECK(ssl_socket); |
631 true, origin, | 632 DCHECK(ssl_socket->WasChannelIDSent()); |
632 secret, arraysize(secret)); | |
633 | |
634 // Convert the key string into a vector<unit8> | |
635 std::vector<uint8> key_data; | |
636 for (size_t i = 0; i < key.length(); i++) { | |
637 key_data.push_back(key[i]); | |
638 } | |
639 | |
640 std::vector<uint8> proof; | |
641 switch (type) { | |
642 case CLIENT_CERT_ECDSA_SIGN: { | |
643 base::StringPiece spki_piece; | |
644 asn1::ExtractSPKIFromDERCert(cert, &spki_piece); | |
645 std::vector<uint8> spki(spki_piece.data(), | |
646 spki_piece.data() + spki_piece.size()); | |
647 scoped_ptr<crypto::ECPrivateKey> private_key( | |
648 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( | |
649 ServerBoundCertService::kEPKIPassword, key_data, spki)); | |
650 scoped_ptr<crypto::ECSignatureCreator> creator( | |
651 crypto::ECSignatureCreator::Create(private_key.get())); | |
652 creator->Sign(secret, arraysize(secret), &proof); | |
653 break; | |
654 } | |
655 default: | |
656 NOTREACHED(); | |
657 } | |
658 | 633 |
659 SpdyCredential credential; | 634 SpdyCredential credential; |
660 GURL origin_url(origin); | 635 std::string tls_unique; |
661 credential.slot = | 636 ssl_socket->GetTLSUniqueChannelBinding(&tls_unique); |
662 credential_state_.SetHasCredential(origin_url); | 637 size_t slot = credential_state_.SetHasCredential(GURL(origin)); |
663 credential.certs.push_back(cert); | 638 int rv = SpdyCredentialBuilder::Build(tls_unique, type, key, cert, slot, |
664 credential.proof.assign(proof.begin(), proof.end()); | 639 &credential); |
| 640 DCHECK_EQ(OK, rv); |
| 641 if (rv != OK) |
| 642 return NULL; |
665 | 643 |
666 DCHECK(buffered_spdy_framer_.get()); | 644 DCHECK(buffered_spdy_framer_.get()); |
667 scoped_ptr<SpdyCredentialControlFrame> credential_frame( | 645 scoped_ptr<SpdyCredentialControlFrame> credential_frame( |
668 buffered_spdy_framer_->CreateCredentialFrame(credential)); | 646 buffered_spdy_framer_->CreateCredentialFrame(credential)); |
669 | 647 |
670 if (net_log().IsLoggingAllEvents()) { | 648 if (net_log().IsLoggingAllEvents()) { |
671 net_log().AddEvent( | 649 net_log().AddEvent( |
672 NetLog::TYPE_SPDY_SESSION_SEND_CREDENTIAL, | 650 NetLog::TYPE_SPDY_SESSION_SEND_CREDENTIAL, |
673 base::Bind(&NetLogSpdyCredentialCallback, credential.slot, &origin)); | 651 base::Bind(&NetLogSpdyCredentialCallback, credential.slot, &origin)); |
674 } | 652 } |
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1970 SSLClientSocket* SpdySession::GetSSLClientSocket() const { | 1948 SSLClientSocket* SpdySession::GetSSLClientSocket() const { |
1971 if (!is_secure_) | 1949 if (!is_secure_) |
1972 return NULL; | 1950 return NULL; |
1973 SSLClientSocket* ssl_socket = | 1951 SSLClientSocket* ssl_socket = |
1974 reinterpret_cast<SSLClientSocket*>(connection_->socket()); | 1952 reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
1975 DCHECK(ssl_socket); | 1953 DCHECK(ssl_socket); |
1976 return ssl_socket; | 1954 return ssl_socket; |
1977 } | 1955 } |
1978 | 1956 |
1979 } // namespace net | 1957 } // namespace net |
OLD | NEW |