| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/core/crypto/crypto_utils.h" | 5 #include "net/quic/core/crypto/crypto_utils.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "crypto/hkdf.h" | 9 #include "crypto/hkdf.h" |
| 10 #include "crypto/secure_hash.h" | 10 #include "crypto/secure_hash.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 memcpy(&(*nonce)[bytes_written], orbit.data(), orbit.size()); | 47 memcpy(&(*nonce)[bytes_written], orbit.data(), orbit.size()); |
| 48 bytes_written += orbit.size(); | 48 bytes_written += orbit.size(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 random_generator->RandBytes(&(*nonce)[bytes_written], | 51 random_generator->RandBytes(&(*nonce)[bytes_written], |
| 52 kNonceSize - bytes_written); | 52 kNonceSize - bytes_written); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // static | 55 // static |
| 56 bool CryptoUtils::IsValidSNI(StringPiece sni) { | 56 bool CryptoUtils::IsValidSNI(StringPiece sni) { |
| 57 // TODO(rtenneti): Support RFC2396 hostname. | |
| 58 // NOTE: Microsoft does NOT enforce this spec, so if we throw away hostnames | |
| 59 // based on the above spec, we may be losing some hostnames that windows | |
| 60 // would consider valid. By far the most common hostname character NOT | |
| 61 // accepted by the above spec is '_'. | |
| 62 url::CanonHostInfo host_info; | 57 url::CanonHostInfo host_info; |
| 63 string canonicalized_host(CanonicalizeHost(sni.as_string(), &host_info)); | 58 string canonicalized_host(CanonicalizeHost(sni.as_string(), &host_info)); |
| 64 return !host_info.IsIPAddress() && | 59 return !host_info.IsIPAddress() && |
| 65 IsCanonicalizedHostCompliant(canonicalized_host) && | 60 IsCanonicalizedHostCompliant(canonicalized_host) && |
| 66 sni.find_last_of('.') != string::npos; | 61 sni.find_last_of('.') != string::npos; |
| 67 } | 62 } |
| 68 | 63 |
| 69 // static | 64 // static |
| 70 string CryptoUtils::NormalizeHostname(const char* hostname) { | 65 string CryptoUtils::NormalizeHostname(const char* hostname) { |
| 71 url::CanonHostInfo host_info; | 66 url::CanonHostInfo host_info; |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 const QuicData& serialized = message.GetSerialized(); | 326 const QuicData& serialized = message.GetSerialized(); |
| 332 std::unique_ptr<crypto::SecureHash> hash( | 327 std::unique_ptr<crypto::SecureHash> hash( |
| 333 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | 328 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
| 334 hash->Update(serialized.data(), serialized.length()); | 329 hash->Update(serialized.data(), serialized.length()); |
| 335 uint8_t digest[32]; | 330 uint8_t digest[32]; |
| 336 hash->Finish(digest, sizeof(digest)); | 331 hash->Finish(digest, sizeof(digest)); |
| 337 output->assign(reinterpret_cast<const char*>(&digest), sizeof(digest)); | 332 output->assign(reinterpret_cast<const char*>(&digest), sizeof(digest)); |
| 338 } | 333 } |
| 339 | 334 |
| 340 } // namespace net | 335 } // namespace net |
| OLD | NEW |