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

Unified Diff: net/quic/crypto/crypto_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: Remove an extraneous test:: before TestCryptoVisitor Created 7 years, 11 months 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
« no previous file with comments | « net/quic/crypto/crypto_utils.h ('k') | net/quic/quic_client_session.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/crypto/crypto_utils.cc
===================================================================
--- net/quic/crypto/crypto_utils.cc (revision 0)
+++ net/quic/crypto/crypto_utils.cc (revision 0)
@@ -0,0 +1,76 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/quic/crypto/crypto_utils.h"
+
+#include "base/string_piece.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 {
+
+void CryptoUtils::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 CryptoUtils::FillClientHelloMessage(const QuicClientCryptoConfig& 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.
+ uint32 idle_connection_state_lifetime_secs =
+ config.idle_connection_state_lifetime.ToSeconds();
+ value.set(&idle_connection_state_lifetime_secs,
+ sizeof(idle_connection_state_lifetime_secs));
+ message->tag_value_map[kICSL] = value.as_string();
+
+ // Keepalive timeout.
+ uint32 keepalive_timeout_secs = config.keepalive_timeout.ToSeconds();
+ value.set(&keepalive_timeout_secs, sizeof(keepalive_timeout_secs));
+ 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
Property changes on: net/quic/crypto/crypto_utils.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « net/quic/crypto/crypto_utils.h ('k') | net/quic/quic_client_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698