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

Unified Diff: net/quic/quic_utils.cc

Issue 11633030: Send the ClientHello handshake message. Fix a bug in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix QuicStreamFactoryTest properly Created 8 years 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698