Land Recent QUIC changes

QUIC: use QuicTag/QuicTagVector throughout.

crypto_protocol.h has had CryptoTag and CryptoTagVector. Then quic_protocol.h
got QuicVersionTag and QuicVersionTagList because it didn't want to depend on
crypto_protocol.h

This change uses a single QuicTag and QuicTagVector throughout the code,
including the crypto code.

Merge internal change: 45230337

QUIC: move random values to the beginning and the certifiate chain to the end.

jar suggested that the certificate chain should have a tag that will cause it
to be sorted at the end of any handshake messages because it's likely to be
large and the client might be able to get everything that it needs from the
small values at the beginning.

Likewise he argued that tags with random values should be towards the beginning
of the message because the server mightn't hold state for a rejected client
hello and therefore the client may have issues reassembling the rejection
message in the event that it sent two client hellos.

This change tweaks the tag values to achieve that ordering.

Merge internal change: 45228375

Removing obselete TODOs

Merge internal change: 45219448

Use the idle connection state timeout negotiated in crypto handshake.

Merge internal change: 45176251

QUIC: address wtc's followup comments on cl/44792710.

This change addresses wtc's comments on cl/44792710. There should be no
semantic differences.

Merge internal change: 45051718

QUIC - Fixed HasRetransmittableData enum to have the correct values.

Fixed comments from rch

Merge internal change: 45143336

Change the QUIC version number to a new value which is amenable to frequent i ncrementing.

Merge internal change: 45111687

QUIC: run clang-format over .../quic/crypto.

I ran:
  for x in $(ls -1 *.cc *.h) ; do clang-format -i $x -style Google; echo $x;
done

And then used git add -p to manually review the changes. In the cases where I
didn't care, I went with what the tool produced.

Merge internal change: 45053104

QUIC: address wtc's followup comments on cl/44792710.

This change addresses wtc's comments on cl/44792710. There should be no
semantic differences.

Merge internal change: 45051718

Minor cleanup of ReliableQuicStreamTest output. Also change MockConnection to create a NiceMock version of the Helper to avoid annoying GMock messages.

Merge internal change: 45010564

QUIC: partly deflake EndToEndTest.LargePost

Since cl/44690884, some runs of this test have timed out. Everything
appears to be working ok, just not fast enough. It's possible that the
additional packet `losses' caused by decryption failures when we lose
the client hello are convincing the congestion control that the loss
rate is very high.

However, since I have a trip to NIST this week, this change removes the
flake by reverting a tiny part of cl/44690884.

Sadly there is another flake in the test which this CL doesn't fix.
Details in the bug.

Merge internal change: 45008247

Fix a bug in QUIC header compression handling where buffered headers were not handled properly.

Merge internal change: 45007035

QUIC: tiny test cleanup.

wtc suggested this in a post-submission comment.

Merge internal change: 44898354

QUIC: add expiry to server configs and have the GFE generate random server configs.

Server configs need an expiry because they are effectively certificates. This
change has the GFE generate server configs with the same expiry as the primary
certificate.

It also switches the GFE to generating random server configs at startup.
(Random in the sense of random keys and orbit values.)

Originally I wanted to have the server config persist over a restart and so
derived them, deterministically, from the primary, private key with a todo to
diversify the orbit. However, since we don't have any shared strike registers
at the moment that doesn't seem to be worth the complexity. Also, figuring out
how to diversify the orbit value in a per-GFE sense is really messy (include
the hostname? include the port? Which port?). So this CL goes for simple and
secure.

Merge internal change: 44898035

QUIC: use 24-bit lengths for public values.

If ideal lattices don't work out then we may end up with Diffie-Hellman public
values that are larger than 16-bits. (Hopefully not, but you never know.)

Merge internal change: 44897191

QUIC: have the client echo the server's nonce.

This reflects a comment from wtc previously that this would be a good idea.

Merge internal change: 44896699

QUIC: steps 12 and 13, forward secure mode.

Merge internal change: 44896363

Fix LOG(DFATAL) when client sends invalid stream frame with fin.

Merge internal change: 44871764

[email protected]

Review URL: https://chromiumcodereview.appspot.com/14816006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199190 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/quic/quic_protocol.h b/net/quic/quic_protocol.h
index c3fd9a0..31fab86 100644
--- a/net/quic/quic_protocol.h
+++ b/net/quic/quic_protocol.h
@@ -36,9 +36,10 @@
 typedef QuicPacketSequenceNumber QuicFecGroupNumber;
 typedef uint64 QuicPublicResetNonceProof;
 typedef uint8 QuicPacketEntropyHash;
-typedef uint32 QuicVersionTag;
-typedef std::vector<QuicVersionTag> QuicVersionTagList;
 typedef uint32 QuicHeaderId;
+// QuicTag is the type of a tag in the wire protocol.
+typedef uint32 QuicTag;
+typedef std::vector<QuicTag> QuicTagVector;
 
 // TODO(rch): Consider Quic specific names for these constants.
 // Maximum size in bytes of a QUIC packet.
@@ -75,7 +76,7 @@
 // Index of the first byte in a QUIC packet of encrypted data.
 NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(bool include_version);
 // Returns true if |version| is a supported protocol version.
-NET_EXPORT_PRIVATE bool IsSupportedVersion(QuicVersionTag version);
+NET_EXPORT_PRIVATE bool IsSupportedVersion(QuicTag version);
 
 // Index of the first byte in a QUIC packet which is used in hash calculation.
 const size_t kStartOfHashData = 0;
@@ -95,13 +96,13 @@
 const int64 kDefaultTimeoutUs = 600000000;  // 10 minutes.
 
 enum Retransmission {
-  NOT_RETRANSMISSION = 0,
-  IS_RETRANSMISSION = 1,
+  NOT_RETRANSMISSION,
+  IS_RETRANSMISSION,
 };
 
 enum HasRetransmittableData {
-  HAS_RETRANSMITTABLE_DATA = 0,
-  NO_RETRANSMITTABLE_DATA = 1,
+  NO_RETRANSMITTABLE_DATA,
+  HAS_RETRANSMITTABLE_DATA,
 };
 
 enum QuicFrameType {
@@ -233,6 +234,11 @@
   QUIC_PROOF_INVALID,
   // A crypto message was received with a duplicate tag.
   QUIC_CRYPTO_DUPLICATE_TAG,
+  // A crypto message was received with the wrong encryption level (i.e. it
+  // should have been encrypted but was not.)
+  QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT,
+  // The server config for a server has expired.
+  QUIC_CRYPTO_SERVER_CONFIG_EXPIRED,
 
   // No error. Used as bound while iterating.
   QUIC_LAST_ERROR,
@@ -248,8 +254,11 @@
 // The TAG macro is used in header files to ensure that we don't create static
 // initialisers. In normal code, the MakeQuicTag function should be used.
 #define TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a)
-const QuicVersionTag kUnsupportedVersion = -1;
-const QuicVersionTag kQuicVersion1 = TAG('Q', '1', '.', '0');
+const QuicTag kUnsupportedVersion = -1;
+// Each time the wire format changes, this need needs to be incremented.
+// At some point, we will actually freeze the wire format and make an official
+// version number, but this works for now.
+const QuicTag kQuicVersion1 = TAG('Q', '0', '0', '1');
 #undef TAG
 
 // MakeQuicTag returns a value given the four bytes. For example:
@@ -267,7 +276,7 @@
   QuicGuid guid;
   bool reset_flag;
   bool version_flag;
-  QuicVersionTagList versions;
+  QuicTagVector versions;
 };
 
 // Header for Data or FEC packets.