Index: net/quic/quic_utils.cc |
=================================================================== |
--- net/quic/quic_utils.cc (revision 174485) |
+++ net/quic/quic_utils.cc (working copy) |
@@ -6,7 +6,13 @@ |
#include "base/logging.h" |
#include "base/port.h" |
+#include "net/quic/crypto/crypto_protocol.h" |
+#include "net/quic/crypto/quic_random.h" |
+#include "net/quic/quic_clock.h" |
+using base::StringPiece; |
+using std::string; |
+ |
namespace net { |
// static |
@@ -75,4 +81,60 @@ |
return ""; |
} |
+void QuicUtils::GenerateNonce(const QuicClock* clock, |
+ QuicRandom* random_generator, |
+ string* nonce) { |
+ // a 4-byte timestamp + 28 random bytes. |
+ nonce->reserve(kNonceSize); |
+ nonce->resize(kNonceSize); |
+ QuicTime::Delta now = clock->NowAsDeltaSinceUnixEpoch(); |
+ uint32 gmt_unix_time = now.ToSeconds(); |
+ const size_t time_size = sizeof(gmt_unix_time); |
+ memcpy(&(*nonce)[0], &gmt_unix_time, time_size); |
+ random_generator->RandBytes(&(*nonce)[time_size], kNonceSize - time_size); |
+} |
+ |
+void QuicUtils::FillClientHelloMessage(const QuicClientHelloConfig& config, |
+ const string& nonce, |
+ CryptoHandshakeMessage* message) { |
+ message->tag = kCHLO; |
+ |
+ StringPiece value; |
+ |
+ // Version. |
+ value.set(&config.version, sizeof(config.version)); |
+ message->tag_value_map[kVERS] = value.as_string(); |
+ |
+ // Key exchange methods. |
+ value.set(&config.key_exchange[0], |
+ config.key_exchange.size() * sizeof(config.key_exchange[0])); |
+ message->tag_value_map[kKEXS] = value.as_string(); |
+ |
+ // Authenticated encryption algorithms. |
+ value.set(&config.aead[0], config.aead.size() * sizeof(config.aead[0])); |
+ message->tag_value_map[kAEAD] = value.as_string(); |
+ |
+ // Congestion control feedback types. |
+ value.set(&config.congestion_control[0], |
+ config.congestion_control.size() * |
+ sizeof(config.congestion_control[0])); |
+ message->tag_value_map[kCGST] = value.as_string(); |
+ |
+ // Idle connection state lifetime. |
+ value.set(&config.idle_connection_state_lifetime, |
+ sizeof(config.idle_connection_state_lifetime)); |
+ message->tag_value_map[kICSL] = value.as_string(); |
+ |
+ // Keepalive timeout. |
+ value.set(&config.keepalive_timeout, sizeof(config.keepalive_timeout)); |
+ message->tag_value_map[kKATO] = value.as_string(); |
+ |
+ // Connection nonce. |
+ message->tag_value_map[kNONC] = nonce; |
+ |
+ // Server name indication. |
+ // TODO(wtc): if server_hostname_ is a DNS name, store it in |
+ // message->tag_value_map[kSNI]. |
+} |
+ |
} // namespace net |