| 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 #include "net/quic/crypto/crypto_protocol.h" | 5 #include "net/quic/crypto/crypto_protocol.h" |
| 6 | 6 |
| 7 #include <stdarg.h> |
| 8 #include <string.h> |
| 9 |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 |
| 12 using std::string; |
| 13 |
| 7 namespace net { | 14 namespace net { |
| 8 | 15 |
| 9 CryptoHandshakeMessage::CryptoHandshakeMessage() {} | 16 CryptoHandshakeMessage::CryptoHandshakeMessage() {} |
| 10 CryptoHandshakeMessage::~CryptoHandshakeMessage() {} | 17 CryptoHandshakeMessage::~CryptoHandshakeMessage() {} |
| 11 | 18 |
| 12 QuicCryptoConfig::QuicCryptoConfig() | 19 void CryptoHandshakeMessage::SetTaglist(CryptoTag tag, ...) { |
| 13 : version(0), | 20 // Warning, if sizeof(CryptoTag) > sizeof(int) then this function will break |
| 14 idle_connection_state_lifetime(QuicTime::Delta::Zero()), | 21 // because the terminating 0 will only be promoted to int. |
| 15 keepalive_timeout(QuicTime::Delta::Zero()) { | 22 COMPILE_ASSERT(sizeof(CryptoTag) <= sizeof(int), |
| 23 crypto_tag_not_be_larger_than_int_or_varargs_will_break); |
| 24 |
| 25 std::vector<CryptoTag> tags; |
| 26 va_list ap; |
| 27 |
| 28 va_start(ap, tag); |
| 29 for (;;) { |
| 30 CryptoTag tag = va_arg(ap, CryptoTag); |
| 31 if (tag == 0) { |
| 32 break; |
| 33 } |
| 34 tags.push_back(tag); |
| 35 } |
| 36 |
| 37 // Because of the way that we keep tags in memory, we can copy the contents |
| 38 // of the vector and get the correct bytes in wire format. See |
| 39 // crypto_protocol.h. This assumes that the system is little-endian. |
| 40 SetVector(tag, tags); |
| 41 |
| 42 va_end(ap); |
| 16 } | 43 } |
| 17 | 44 |
| 18 QuicCryptoConfig::~QuicCryptoConfig() {} | 45 QuicErrorCode CryptoHandshakeMessage::GetTaglist(CryptoTag tag, |
| 46 const CryptoTag** out_tags, |
| 47 size_t* out_len) const { |
| 48 CryptoTagValueMap::const_iterator it = tag_value_map.find(tag); |
| 49 QuicErrorCode ret = QUIC_NO_ERROR; |
| 19 | 50 |
| 20 void QuicCryptoConfig::SetClientDefaults() { | 51 if (it == tag_value_map.end()) { |
| 21 // Version must be 0. | 52 ret = QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; |
| 22 version = 0; | 53 } else if (it->second.size() % sizeof(CryptoTag) != 0) { |
| 54 ret = QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
| 55 } |
| 23 | 56 |
| 24 // Key exchange methods. | 57 if (ret != QUIC_NO_ERROR) { |
| 25 key_exchange.resize(2); | 58 *out_tags = NULL; |
| 26 key_exchange[0] = kC255; | 59 *out_len = 0; |
| 27 key_exchange[1] = kP256; | 60 return ret; |
| 61 } |
| 28 | 62 |
| 29 // Authenticated encryption algorithms. | 63 *out_tags = reinterpret_cast<const CryptoTag*>(it->second.data()); |
| 30 aead.resize(2); | 64 *out_len = it->second.size() / sizeof(CryptoTag); |
| 31 aead[0] = kAESG; | 65 return ret; |
| 32 aead[1] = kAESH; | |
| 33 | |
| 34 // Congestion control feedback types. | |
| 35 // TODO(wtc): add kINAR when inter-arrival is supported. | |
| 36 congestion_control.resize(1); | |
| 37 congestion_control[0] = kQBIC; | |
| 38 | |
| 39 // Idle connection state lifetime. | |
| 40 idle_connection_state_lifetime = QuicTime::Delta::FromSeconds(300); | |
| 41 | |
| 42 // Keepalive timeout. | |
| 43 keepalive_timeout = QuicTime::Delta::Zero(); // Don't send keepalive probes. | |
| 44 } | 66 } |
| 45 | 67 |
| 46 void QuicCryptoConfig::SetServerDefaults() { | 68 bool CryptoHandshakeMessage::GetString(CryptoTag tag, string* out) const { |
| 47 // Version must be 0. | 69 CryptoTagValueMap::const_iterator it = tag_value_map.find(tag); |
| 48 version = 0; | 70 if (it == tag_value_map.end()) { |
| 49 | 71 return false; |
| 50 // Key exchange methods. | 72 } |
| 51 // Add only NIST curve P-256 for now to ensure it is selected. | 73 *out = it->second; |
| 52 key_exchange.resize(1); | 74 return true; |
| 53 key_exchange[0] = kP256; | |
| 54 | |
| 55 // Authenticated encryption algorithms. | |
| 56 // Add only AES-GCM for now to ensure it is selected. | |
| 57 aead.resize(1); | |
| 58 aead[0] = kAESG; | |
| 59 | |
| 60 // Congestion control feedback types. | |
| 61 // TODO(wtc): add kINAR when inter-arrival is supported. | |
| 62 congestion_control.resize(1); | |
| 63 congestion_control[0] = kQBIC; | |
| 64 | |
| 65 // Idle connection state lifetime. | |
| 66 idle_connection_state_lifetime = QuicTime::Delta::FromSeconds(300); | |
| 67 | |
| 68 // Keepalive timeout. | |
| 69 keepalive_timeout = QuicTime::Delta::Zero(); // Don't send keepalive probes. | |
| 70 } | 75 } |
| 71 | 76 |
| 72 QuicCryptoNegotiatedParams::QuicCryptoNegotiatedParams() | 77 QuicErrorCode CryptoHandshakeMessage::GetUint32(CryptoTag tag, |
| 73 : version(0), | 78 uint32* out) const { |
| 74 key_exchange(0), | 79 CryptoTagValueMap::const_iterator it = tag_value_map.find(tag); |
| 75 aead(0), | 80 QuicErrorCode ret = QUIC_NO_ERROR; |
| 76 congestion_control(0), | |
| 77 idle_connection_state_lifetime(QuicTime::Delta::Zero()) { | |
| 78 } | |
| 79 | 81 |
| 80 QuicCryptoNegotiatedParams::~QuicCryptoNegotiatedParams() {} | 82 if (it == tag_value_map.end()) { |
| 83 ret = QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; |
| 84 } else if (it->second.size() != sizeof(uint32)) { |
| 85 ret = QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
| 86 } |
| 81 | 87 |
| 82 void QuicCryptoNegotiatedParams::SetDefaults() { | 88 if (ret != QUIC_NO_ERROR) { |
| 83 // TODO(wtc): actually negotiate the parameters using client defaults | 89 *out = 0; |
| 84 // and server defaults. | 90 return ret; |
| 91 } |
| 85 | 92 |
| 86 // Version must be 0. | 93 memcpy(out, it->second.data(), sizeof(uint32)); |
| 87 version = 0; | 94 return ret; |
| 88 | |
| 89 // Key exchange method. | |
| 90 key_exchange = kP256; | |
| 91 | |
| 92 // Authenticated encryption algorithm. | |
| 93 aead = kAESG; | |
| 94 | |
| 95 // Congestion control feedback type. | |
| 96 congestion_control = kQBIC; | |
| 97 | |
| 98 // Idle connection state lifetime. | |
| 99 idle_connection_state_lifetime = QuicTime::Delta::FromSeconds(300); | |
| 100 } | 95 } |
| 101 | 96 |
| 102 } // namespace net | 97 } // namespace net |
| OLD | NEW |