| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/quic/crypto/crypto_server_config.h" | 5 #include "net/quic/crypto/crypto_server_config.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 130 |
| 131 if (options.id.empty()) { | 131 if (options.id.empty()) { |
| 132 char scid_bytes[16]; | 132 char scid_bytes[16]; |
| 133 rand->RandBytes(scid_bytes, sizeof(scid_bytes)); | 133 rand->RandBytes(scid_bytes, sizeof(scid_bytes)); |
| 134 msg.SetStringPiece(kSCID, StringPiece(scid_bytes, sizeof(scid_bytes))); | 134 msg.SetStringPiece(kSCID, StringPiece(scid_bytes, sizeof(scid_bytes))); |
| 135 } else { | 135 } else { |
| 136 msg.SetStringPiece(kSCID, options.id); | 136 msg.SetStringPiece(kSCID, options.id); |
| 137 } | 137 } |
| 138 | 138 |
| 139 char orbit_bytes[kOrbitSize]; | 139 char orbit_bytes[kOrbitSize]; |
| 140 rand->RandBytes(orbit_bytes, sizeof(orbit_bytes)); | 140 if (options.orbit.size() == kOrbitSize) { |
| 141 memcpy(orbit_bytes, options.orbit.data(), sizeof(orbit_bytes)); |
| 142 } else { |
| 143 DCHECK(options.orbit.empty()); |
| 144 rand->RandBytes(orbit_bytes, sizeof(orbit_bytes)); |
| 145 } |
| 141 msg.SetStringPiece(kORBT, StringPiece(orbit_bytes, sizeof(orbit_bytes))); | 146 msg.SetStringPiece(kORBT, StringPiece(orbit_bytes, sizeof(orbit_bytes))); |
| 142 | 147 |
| 143 if (options.channel_id_enabled) { | 148 if (options.channel_id_enabled) { |
| 144 msg.SetTaglist(kPDMD, kCHID, 0); | 149 msg.SetTaglist(kPDMD, kCHID, 0); |
| 145 } | 150 } |
| 146 | 151 |
| 147 scoped_ptr<QuicData> serialized(CryptoFramer::ConstructHandshakeMessage(msg)); | 152 scoped_ptr<QuicData> serialized(CryptoFramer::ConstructHandshakeMessage(msg)); |
| 148 | 153 |
| 149 scoped_ptr<QuicServerConfigProtobuf> config(new QuicServerConfigProtobuf); | 154 scoped_ptr<QuicServerConfigProtobuf> config(new QuicServerConfigProtobuf); |
| 150 config->set_config(serialized->AsStringPiece()); | 155 config->set_config(serialized->AsStringPiece()); |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 out->SetStringPiece(kSourceAddressTokenTag, | 672 out->SetStringPiece(kSourceAddressTokenTag, |
| 668 NewSourceAddressToken(info.client_ip, rand, info.now)); | 673 NewSourceAddressToken(info.client_ip, rand, info.now)); |
| 669 if (replay_protection_) { | 674 if (replay_protection_) { |
| 670 out->SetStringPiece(kServerNonceTag, NewServerNonce(rand, info.now)); | 675 out->SetStringPiece(kServerNonceTag, NewServerNonce(rand, info.now)); |
| 671 } | 676 } |
| 672 | 677 |
| 673 // The client may have requested a certificate chain. | 678 // The client may have requested a certificate chain. |
| 674 const QuicTag* their_proof_demands; | 679 const QuicTag* their_proof_demands; |
| 675 size_t num_their_proof_demands; | 680 size_t num_their_proof_demands; |
| 676 | 681 |
| 677 if (proof_source_.get() != NULL && | 682 if (proof_source_.get() == NULL || |
| 678 client_hello.GetTaglist(kPDMD, &their_proof_demands, | 683 client_hello.GetTaglist(kPDMD, &their_proof_demands, |
| 679 &num_their_proof_demands) == | 684 &num_their_proof_demands) != |
| 680 QUIC_NO_ERROR) { | 685 QUIC_NO_ERROR) { |
| 681 for (size_t i = 0; i < num_their_proof_demands; i++) { | 686 return; |
| 682 if (their_proof_demands[i] != kX509) { | 687 } |
| 683 continue; | |
| 684 } | |
| 685 | 688 |
| 686 const vector<string>* certs; | 689 bool x509_supported = false, x509_ecdsa_supported = false; |
| 687 string signature; | 690 for (size_t i = 0; i < num_their_proof_demands; i++) { |
| 688 if (!proof_source_->GetProof(info.sni.as_string(), config->serialized, | 691 switch (their_proof_demands[i]) { |
| 689 &certs, &signature)) { | 692 case kX509: |
| 693 x509_supported = true; |
| 694 x509_ecdsa_supported = true; |
| 690 break; | 695 break; |
| 691 } | 696 case kX59R: |
| 697 x509_supported = true; |
| 698 break; |
| 699 } |
| 700 } |
| 692 | 701 |
| 693 StringPiece their_common_set_hashes; | 702 if (!x509_supported) { |
| 694 StringPiece their_cached_cert_hashes; | 703 return; |
| 695 client_hello.GetStringPiece(kCCS, &their_common_set_hashes); | 704 } |
| 696 client_hello.GetStringPiece(kCCRT, &their_cached_cert_hashes); | |
| 697 | 705 |
| 698 const string compressed = CertCompressor::CompressChain( | 706 const vector<string>* certs; |
| 699 *certs, their_common_set_hashes, their_cached_cert_hashes, | 707 string signature; |
| 700 config->common_cert_sets); | 708 if (!proof_source_->GetProof(info.sni.as_string(), config->serialized, |
| 709 x509_ecdsa_supported, &certs, &signature)) { |
| 710 return; |
| 711 } |
| 701 | 712 |
| 702 // kMaxUnverifiedSize is the number of bytes that the certificate chain | 713 StringPiece their_common_set_hashes; |
| 703 // and signature can consume before we will demand a valid | 714 StringPiece their_cached_cert_hashes; |
| 704 // source-address token. | 715 client_hello.GetStringPiece(kCCS, &their_common_set_hashes); |
| 705 // TODO(agl): make this configurable. | 716 client_hello.GetStringPiece(kCCRT, &their_cached_cert_hashes); |
| 706 static const size_t kMaxUnverifiedSize = 400; | 717 |
| 707 if (info.valid_source_address_token || | 718 const string compressed = CertCompressor::CompressChain( |
| 708 signature.size() + compressed.size() < kMaxUnverifiedSize) { | 719 *certs, their_common_set_hashes, their_cached_cert_hashes, |
| 709 out->SetStringPiece(kCertificateTag, compressed); | 720 config->common_cert_sets); |
| 710 out->SetStringPiece(kPROF, signature); | 721 |
| 711 } | 722 // kREJOverheadBytes is a very rough estimate of how much of a REJ |
| 712 break; | 723 // message is taken up by things other than the certificates. |
| 713 } | 724 const size_t kREJOverheadBytes = 112; |
| 725 // kMaxUnverifiedSize is the number of bytes that the certificate chain |
| 726 // and signature can consume before we will demand a valid source-address |
| 727 // token. |
| 728 const size_t kMaxUnverifiedSize = client_hello.size() - kREJOverheadBytes; |
| 729 COMPILE_ASSERT(kClientHelloMinimumSize >= kREJOverheadBytes, |
| 730 overhead_calculation_may_underflow); |
| 731 if (info.valid_source_address_token || |
| 732 signature.size() + compressed.size() < kMaxUnverifiedSize) { |
| 733 out->SetStringPiece(kCertificateTag, compressed); |
| 734 out->SetStringPiece(kPROF, signature); |
| 714 } | 735 } |
| 715 } | 736 } |
| 716 | 737 |
| 717 scoped_refptr<QuicCryptoServerConfig::Config> | 738 scoped_refptr<QuicCryptoServerConfig::Config> |
| 718 QuicCryptoServerConfig::ParseConfigProtobuf( | 739 QuicCryptoServerConfig::ParseConfigProtobuf( |
| 719 QuicServerConfigProtobuf* protobuf) { | 740 QuicServerConfigProtobuf* protobuf) { |
| 720 scoped_ptr<CryptoHandshakeMessage> msg( | 741 scoped_ptr<CryptoHandshakeMessage> msg( |
| 721 CryptoFramer::ParseMessage(protobuf->config())); | 742 CryptoFramer::ParseMessage(protobuf->config())); |
| 722 | 743 |
| 723 if (msg->tag() != kSCFG) { | 744 if (msg->tag() != kSCFG) { |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 } | 1057 } |
| 1037 | 1058 |
| 1038 QuicCryptoServerConfig::Config::Config() | 1059 QuicCryptoServerConfig::Config::Config() |
| 1039 : channel_id_enabled(false), | 1060 : channel_id_enabled(false), |
| 1040 is_primary(false), | 1061 is_primary(false), |
| 1041 primary_time(QuicWallTime::Zero()) {} | 1062 primary_time(QuicWallTime::Zero()) {} |
| 1042 | 1063 |
| 1043 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } | 1064 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } |
| 1044 | 1065 |
| 1045 } // namespace net | 1066 } // namespace net |
| OLD | NEW |