OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_QUIC_CRYPTO_CRYPTO_PROTOCOL_H_ | 5 #ifndef NET_QUIC_CRYPTO_CRYPTO_PROTOCOL_H_ |
6 #define NET_QUIC_CRYPTO_CRYPTO_PROTOCOL_H_ | 6 #define NET_QUIC_CRYPTO_CRYPTO_PROTOCOL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | |
13 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
| 13 #include "net/quic/quic_protocol.h" |
14 | 14 |
15 // Version and Crypto tags are written to the wire with a big-endian | 15 // Version and Crypto tags are written to the wire with a big-endian |
16 // representation of the name of the tag. For example | 16 // representation of the name of the tag. For example |
17 // the client hello tag (CHLO) will be written as the | 17 // the client hello tag (CHLO) will be written as the |
18 // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is | 18 // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is |
19 // stored in memory as a little endian uint32, we need | 19 // stored in memory as a little endian uint32, we need |
20 // to reverse the order of the bytes. | 20 // to reverse the order of the bytes. |
21 // | 21 // |
22 // We use a macro to ensure that no static initialisers are created. Use the | 22 // We use a macro to ensure that no static initialisers are created. Use the |
23 // QuicTag function in normal code. | 23 // MakeQuicTag function in normal code. |
24 #define TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a) | 24 #define TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a) |
25 | 25 |
26 namespace net { | 26 namespace net { |
27 | 27 |
28 // CryptoTag is the type of a tag in the wire protocol. | |
29 typedef uint32 CryptoTag; | |
30 typedef std::string ServerConfigID; | 28 typedef std::string ServerConfigID; |
31 typedef std::map<CryptoTag, std::string> CryptoTagValueMap; | 29 typedef std::map<QuicTag, std::string> QuicTagValueMap; |
32 typedef std::vector<CryptoTag> CryptoTagVector; | |
33 | 30 |
34 const CryptoTag kCHLO = TAG('C', 'H', 'L', 'O'); // Client hello | 31 const QuicTag kCHLO = TAG('C', 'H', 'L', 'O'); // Client hello |
35 const CryptoTag kSHLO = TAG('S', 'H', 'L', 'O'); // Server hello | 32 const QuicTag kSHLO = TAG('S', 'H', 'L', 'O'); // Server hello |
36 const CryptoTag kSCFG = TAG('S', 'C', 'F', 'G'); // Server config | 33 const QuicTag kSCFG = TAG('S', 'C', 'F', 'G'); // Server config |
37 const CryptoTag kREJ = TAG('R', 'E', 'J', '\0'); // Reject | 34 const QuicTag kREJ = TAG('R', 'E', 'J', '\0'); // Reject |
38 | 35 |
39 // Key exchange methods | 36 // Key exchange methods |
40 const CryptoTag kP256 = TAG('P', '2', '5', '6'); // ECDH, Curve P-256 | 37 const QuicTag kP256 = TAG('P', '2', '5', '6'); // ECDH, Curve P-256 |
41 const CryptoTag kC255 = TAG('C', '2', '5', '5'); // ECDH, Curve25519 | 38 const QuicTag kC255 = TAG('C', '2', '5', '5'); // ECDH, Curve25519 |
42 | 39 |
43 // AEAD algorithms | 40 // AEAD algorithms |
44 const CryptoTag kNULL = TAG('N', 'U', 'L', 'L'); // null algorithm | 41 const QuicTag kNULL = TAG('N', 'U', 'L', 'L'); // null algorithm |
45 const CryptoTag kAESG = TAG('A', 'E', 'S', 'G'); // AES128 + GCM | 42 const QuicTag kAESG = TAG('A', 'E', 'S', 'G'); // AES128 + GCM |
46 | 43 |
47 // Congestion control feedback types | 44 // Congestion control feedback types |
48 const CryptoTag kQBIC = TAG('Q', 'B', 'I', 'C'); // TCP cubic | 45 const QuicTag kQBIC = TAG('Q', 'B', 'I', 'C'); // TCP cubic |
49 const CryptoTag kINAR = TAG('I', 'N', 'A', 'R'); // Inter arrival | 46 const QuicTag kINAR = TAG('I', 'N', 'A', 'R'); // Inter arrival |
50 | 47 |
51 // Proof types (i.e. certificate types) | 48 // Proof types (i.e. certificate types) |
52 const CryptoTag kX509 = TAG('X', '5', '0', '9'); // X.509 certificate | 49 const QuicTag kX509 = TAG('X', '5', '0', '9'); // X.509 certificate |
53 | 50 |
54 // Client hello tags | 51 // Client hello tags |
55 const CryptoTag kVERS = TAG('V', 'E', 'R', 'S'); // Version | 52 const QuicTag kVERS = TAG('V', 'E', 'R', 'S'); // Version |
56 const CryptoTag kNONC = TAG('N', 'O', 'N', 'C'); // The connection nonce | 53 const QuicTag kNONC = TAG('N', 'O', 'N', 'C'); // The client's nonce |
57 const CryptoTag kSSID = TAG('S', 'S', 'I', 'D'); // Session ID | 54 const QuicTag kSSID = TAG('S', 'S', 'I', 'D'); // Session ID |
58 const CryptoTag kKEXS = TAG('K', 'E', 'X', 'S'); // Key exchange methods | 55 const QuicTag kKEXS = TAG('K', 'E', 'X', 'S'); // Key exchange methods |
59 const CryptoTag kAEAD = TAG('A', 'E', 'A', 'D'); // Authenticated | 56 const QuicTag kAEAD = TAG('A', 'E', 'A', 'D'); // Authenticated |
60 // encryption algorithms | 57 // encryption algorithms |
61 const CryptoTag kCGST = TAG('C', 'G', 'S', 'T'); // Congestion control | 58 const QuicTag kCGST = TAG('C', 'G', 'S', 'T'); // Congestion control |
62 // feedback types | 59 // feedback types |
63 const CryptoTag kICSL = TAG('I', 'C', 'S', 'L'); // Idle connection state | 60 const QuicTag kICSL = TAG('I', 'C', 'S', 'L'); // Idle connection state |
64 // lifetime | 61 // lifetime |
65 const CryptoTag kKATO = TAG('K', 'A', 'T', 'O'); // Keepalive timeout | 62 const QuicTag kKATO = TAG('K', 'A', 'T', 'O'); // Keepalive timeout |
66 const CryptoTag kSNI = TAG('S', 'N', 'I', '\0'); // Server name | 63 const QuicTag kSNI = TAG('S', 'N', 'I', '\0'); // Server name |
67 // indication | 64 // indication |
68 const CryptoTag kPUBS = TAG('P', 'U', 'B', 'S'); // Public key values | 65 const QuicTag kPUBS = TAG('P', 'U', 'B', 'S'); // Public key values |
69 const CryptoTag kSCID = TAG('S', 'C', 'I', 'D'); // Server config id | 66 const QuicTag kSCID = TAG('S', 'C', 'I', 'D'); // Server config id |
70 const CryptoTag kSRCT = TAG('S', 'R', 'C', 'T'); // Source-address token | 67 const QuicTag kORBT = TAG('O', 'B', 'I', 'T'); // Server orbit. |
71 const CryptoTag kORBT = TAG('O', 'B', 'I', 'T'); // Server orbit. | 68 const QuicTag kPDMD = TAG('P', 'D', 'M', 'D'); // Proof demand. |
72 const CryptoTag kPDMD = TAG('P', 'D', 'M', 'D'); // Proof demand. | 69 const QuicTag kPROF = TAG('P', 'R', 'O', 'F'); // Proof (signature). |
73 const CryptoTag kCERT = TAG('C', 'E', 'R', 'T'); // Certificate chain | 70 const QuicTag kCCS = TAG('C', 'C', 'S', 0); // Common certificate set |
74 const CryptoTag kPROF = TAG('P', 'R', 'O', 'F'); // Proof (signature). | 71 const QuicTag kCCRT = TAG('C', 'C', 'R', 'T'); // Cached certificate |
75 const CryptoTag kCCS = TAG('C', 'C', 'S', 0); // Common certificate set | 72 const QuicTag kEXPY = TAG('E', 'X', 'P', 'Y'); // Expiry |
76 const CryptoTag kCCRT = TAG('C', 'C', 'R', 'T'); // Cached certificate | 73 |
| 74 // These tags have a special form so that they appear either at the beginning |
| 75 // or the end of a handshake message. Since handshake messages are sorted by |
| 76 // tag value, the tags with 0 at the end will sort first and those with 255 at |
| 77 // the end will sort last. |
| 78 // |
| 79 // The certificate chain should have a tag that will cause it to be sorted at |
| 80 // the end of any handshake messages because it's likely to be large and the |
| 81 // client might be able to get everything that it needs from the small values at |
| 82 // the beginning. |
| 83 // |
| 84 // Likewise tags with random values should be towards the beginning of the |
| 85 // message because the server mightn't hold state for a rejected client hello |
| 86 // and therefore the client may have issues reassembling the rejection message |
| 87 // in the event that it sent two client hellos. |
| 88 const QuicTag kServerNonceTag = |
| 89 TAG('S', 'N', 'O', 0); // The server's nonce |
| 90 const QuicTag kSourceAddressTokenTag = |
| 91 TAG('S', 'T', 'K', 0); // Source-address token |
| 92 const QuicTag kCertificateTag = |
| 93 TAG('C', 'R', 'T', 255); // Certificate chain |
77 | 94 |
78 #undef TAG | 95 #undef TAG |
79 | 96 |
80 const size_t kMaxEntries = 128; // Max number of entries in a message. | 97 const size_t kMaxEntries = 128; // Max number of entries in a message. |
81 | 98 |
82 const size_t kNonceSize = 32; // Size in bytes of the connection nonce. | 99 const size_t kNonceSize = 32; // Size in bytes of the connection nonce. |
83 | 100 |
84 const size_t kOrbitSize = 8; // Number of bytes in an orbit value. | 101 const size_t kOrbitSize = 8; // Number of bytes in an orbit value. |
85 | 102 |
86 // kProofSignatureLabel is prepended to server configs before signing to avoid | 103 // kProofSignatureLabel is prepended to server configs before signing to avoid |
87 // any cross-protocol attacks on the signature. | 104 // any cross-protocol attacks on the signature. |
88 const char kProofSignatureLabel[] = "QUIC server config signature"; | 105 const char kProofSignatureLabel[] = "QUIC server config signature"; |
89 | 106 |
90 } // namespace net | 107 } // namespace net |
91 | 108 |
92 #endif // NET_QUIC_CRYPTO_CRYPTO_PROTOCOL_H_ | 109 #endif // NET_QUIC_CRYPTO_CRYPTO_PROTOCOL_H_ |
OLD | NEW |