10f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 50f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "net/quic/crypto/quic_crypto_server_config.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <stdarg.h> 87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/stl_util.h" 1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "net/quic/crypto/aes_128_gcm_12_encrypter.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/quic/crypto/crypto_handshake_message.h" 126d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "net/quic/crypto/crypto_secret_boxer.h" 137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "net/quic/crypto/crypto_server_config_protobuf.h" 14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/quic/crypto/quic_random.h" 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/quic/crypto/strike_register_client.h" 16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/quic/quic_time.h" 17c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/quic/test_tools/mock_clock.h" 1846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "net/quic/test_tools/quic_test_utils.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)using base::StringPiece; 237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)using std::make_pair; 247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)using std::map; 257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)using std::pair; 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)using std::string; 277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)using std::vector; 28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace net { 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace test { 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class QuicCryptoServerConfigPeer { 33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) explicit QuicCryptoServerConfigPeer(QuicCryptoServerConfig* server_config) 35b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) : server_config_(server_config) {} 36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_refptr<QuicCryptoServerConfig::Config> GetConfig(string config_id) { 385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu base::AutoLock locked(server_config_->configs_lock_); 395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu if (config_id == "<primary>") { 405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return scoped_refptr<QuicCryptoServerConfig::Config>( 415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu server_config_->primary_config_); 425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } else { 435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return server_config_->GetConfigWithScid(config_id); 445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bool ConfigHasDefaultSourceAddressTokenBoxer(string config_id) { 485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_refptr<QuicCryptoServerConfig::Config> config = GetConfig(config_id); 495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return config->source_address_token_boxer == 505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu &(server_config_->default_source_address_token_boxer_); 51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu string NewSourceAddressToken( 545c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu string config_id, 555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu IPEndPoint ip, 565c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu QuicRandom* rand, 575c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu QuicWallTime now) { 585c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return server_config_->NewSourceAddressToken( 5903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *GetConfig(config_id), ip, rand, now, NULL); 605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 615c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 626d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) HandshakeFailureReason ValidateSourceAddressToken(string config_id, 636d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) StringPiece srct, 646d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) IPEndPoint ip, 656d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) QuicWallTime now) { 665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return server_config_->ValidateSourceAddressToken( 675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *GetConfig(config_id), srct, ip, now); 68c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 69c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 706d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) string NewServerNonce(QuicRandom* rand, QuicWallTime now) const { 716d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) return server_config_->NewServerNonce(rand, now); 726d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) } 736d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 746d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) HandshakeFailureReason ValidateServerNonce(StringPiece token, 756d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) QuicWallTime now) { 766d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) return server_config_->ValidateServerNonce(token, now); 776d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) } 786d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Lock* GetStrikeRegisterClientLock() { 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return &server_config_->strike_register_client_lock_; 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // CheckConfigs compares the state of the Configs in |server_config_| to the 847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // description given as arguments. The arguments are given as NULL-terminated 857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // pairs. The first of each pair is the server config ID of a Config. The 867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // second is a boolean describing whether the config is the primary. For 877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // example: 887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // CheckConfigs(NULL); // checks that no Configs are loaded. 897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // 907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // // Checks that exactly three Configs are loaded with the given IDs and 917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // // status. 927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // CheckConfigs( 937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // "id1", false, 947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // "id2", true, 957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // "id3", false, 967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // NULL); 977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void CheckConfigs(const char* server_config_id1, ...) { 987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) va_list ap; 997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) va_start(ap, server_config_id1); 1007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) vector<pair<ServerConfigID, bool> > expected; 1027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool first = true; 1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) for (;;) { 1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const char* server_config_id; 1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (first) { 1067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) server_config_id = server_config_id1; 1077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) first = false; 1087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } else { 1097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) server_config_id = va_arg(ap, const char*); 1107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (!server_config_id) { 1137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 1147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // varargs will promote the value to an int so we have to read that from 1177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // the stack and cast down. 1187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const bool is_primary = static_cast<bool>(va_arg(ap, int)); 1197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) expected.push_back(make_pair(server_config_id, is_primary)); 1207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) va_end(ap); 1237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::AutoLock locked(server_config_->configs_lock_); 1257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ASSERT_EQ(expected.size(), server_config_->configs_.size()) 1277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) << ConfigsDebug(); 1287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) for (QuicCryptoServerConfig::ConfigMap::const_iterator 1307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) i = server_config_->configs_.begin(); 1317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) i != server_config_->configs_.end(); ++i) { 1327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool found = false; 1337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) for (vector<pair<ServerConfigID, bool> >::iterator j = expected.begin(); 1347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) j != expected.end(); ++j) { 1357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (i->first == j->first && i->second->is_primary == j->second) { 1367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) found = true; 1377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) j->first.clear(); 1387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 1397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ASSERT_TRUE(found) << "Failed to find match for " << i->first 1437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) << " in configs:\n" << ConfigsDebug(); 1447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // ConfigsDebug returns a string that contains debugging information about 1487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // the set of Configs loaded in |server_config_| and their status. 1497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // ConfigsDebug() should be called after acquiring 1507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // server_config_->configs_lock_. 1517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) string ConfigsDebug() { 1527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (server_config_->configs_.empty()) { 1537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return "No Configs in QuicCryptoServerConfig"; 1547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) string s; 1577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) for (QuicCryptoServerConfig::ConfigMap::const_iterator 1597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) i = server_config_->configs_.begin(); 1607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) i != server_config_->configs_.end(); ++i) { 1617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const scoped_refptr<QuicCryptoServerConfig::Config> config = i->second; 1627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (config->is_primary) { 1637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) s += "(primary) "; 1647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } else { 1657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) s += " "; 1667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) s += config->id; 1687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) s += "\n"; 1697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return s; 1727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void SelectNewPrimaryConfig(int seconds) { 1757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::AutoLock locked(server_config_->configs_lock_); 1767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) server_config_->SelectNewPrimaryConfig( 1777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) QuicWallTime::FromUNIXSeconds(seconds)); 1787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 180c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 1817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const QuicCryptoServerConfig* server_config_; 182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 183c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class TestStrikeRegisterClient : public StrikeRegisterClient { 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) explicit TestStrikeRegisterClient(QuicCryptoServerConfig* config) 1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : config_(config), 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) is_known_orbit_called_(false) { 1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual bool IsKnownOrbit(StringPiece orbit) const OVERRIDE { 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Ensure that the strike register client lock is not held. 1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QuicCryptoServerConfigPeer peer(config_); 1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Lock* m = peer.GetStrikeRegisterClientLock(); 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // In Chromium, we will dead lock if the lock is held by the current thread. 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Chromium doesn't have AssertNotHeld API call. 1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // m->AssertNotHeld(); 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::AutoLock lock(*m); 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) is_known_orbit_called_ = true; 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void VerifyNonceIsValidAndUnique( 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StringPiece nonce, 2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QuicWallTime now, 2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ResultCallback* cb) OVERRIDE { 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LOG(FATAL) << "Not implemented"; 2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool is_known_orbit_called() { return is_known_orbit_called_; } 2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QuicCryptoServerConfig* config_; 2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) mutable bool is_known_orbit_called_; 2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 218c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST(QuicCryptoServerConfigTest, ServerConfig) { 219868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) QuicRandom* rand = QuicRandom::GetInstance(); 220868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); 221c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockClock clock; 222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 223c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<CryptoHandshakeMessage>( 224868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) server.AddDefaultConfig(rand, &clock, 225868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) QuicCryptoServerConfig::ConfigOptions())); 226c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 227c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST(QuicCryptoServerConfigTest, GetOrbitIsCalledWithoutTheStrikeRegisterLock) { 2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QuicRandom* rand = QuicRandom::GetInstance(); 2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockClock clock; 2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestStrikeRegisterClient* strike_register = 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new TestStrikeRegisterClient(&server); 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) server.SetStrikeRegisterClient(strike_register); 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QuicCryptoServerConfig::ConfigOptions options; 2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<CryptoHandshakeMessage>( 2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) server.AddDefaultConfig(rand, &clock, options)); 2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(strike_register->is_known_orbit_called()); 2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 243c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST(QuicCryptoServerConfigTest, SourceAddressTokens) { 2445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const string kPrimary = "<primary>"; 2455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const string kOverride = "Config with custom source address token key"; 2465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu MockClock clock; 2485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu clock.AdvanceTime(QuicTime::Delta::FromSeconds(1000000)); 2495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu QuicWallTime now = clock.WallNow(); 2515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const QuicWallTime original_time = now; 2525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 253868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) QuicRandom* rand = QuicRandom::GetInstance(); 254868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); 2555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu QuicCryptoServerConfigPeer peer(&server); 2565c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2575c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_ptr<CryptoHandshakeMessage>( 2585c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu server.AddDefaultConfig(rand, &clock, 2595c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu QuicCryptoServerConfig::ConfigOptions())); 2605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2615c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Add a config that overrides the default boxer. 2625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu QuicCryptoServerConfig::ConfigOptions options; 2635c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu options.id = kOverride; 2645c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_ptr<QuicServerConfigProtobuf> protobuf( 2655c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu QuicCryptoServerConfig::GenerateConfig(rand, &clock, options)); 2665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu protobuf->set_source_address_token_secret_override("a secret key"); 2675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Lower priority than the default config. 2685c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu protobuf->set_priority(1); 2695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_ptr<CryptoHandshakeMessage>( 2705c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu server.AddConfig(protobuf.get(), now)); 2715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu EXPECT_TRUE(peer.ConfigHasDefaultSourceAddressTokenBoxer(kPrimary)); 2735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu EXPECT_FALSE(peer.ConfigHasDefaultSourceAddressTokenBoxer(kOverride)); 2745c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 27546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) IPEndPoint ip4 = IPEndPoint(Loopback4(), 1); 27646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) IPEndPoint ip4d = IPEndPoint(ConvertIPv4NumberToIPv6Number(ip4.address()), 1); 27746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) IPEndPoint ip6 = IPEndPoint(Loopback6(), 2); 278c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Primary config generates configs that validate successfully. 2805c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const string token4 = peer.NewSourceAddressToken(kPrimary, ip4, rand, now); 28146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) const string token4d = peer.NewSourceAddressToken(kPrimary, ip4d, rand, now); 2825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const string token6 = peer.NewSourceAddressToken(kPrimary, ip6, rand, now); 2836d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) EXPECT_EQ(HANDSHAKE_OK, peer.ValidateSourceAddressToken( 2846d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) kPrimary, token4, ip4, now)); 2856d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(HANDSHAKE_OK, peer.ValidateSourceAddressToken( 2866d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) kPrimary, token4, ip4d, now)); 2876d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(SOURCE_ADDRESS_TOKEN_DIFFERENT_IP_ADDRESS_FAILURE, 2886d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) peer.ValidateSourceAddressToken(kPrimary, token4, ip6, now)); 2896d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(HANDSHAKE_OK, peer.ValidateSourceAddressToken( 2906d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) kPrimary, token4d, ip4, now)); 2916d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(HANDSHAKE_OK, peer.ValidateSourceAddressToken( 2926d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) kPrimary, token4d, ip4d, now)); 2936d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(SOURCE_ADDRESS_TOKEN_DIFFERENT_IP_ADDRESS_FAILURE, 2946d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) peer.ValidateSourceAddressToken(kPrimary, token4d, ip6, now)); 2956d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(HANDSHAKE_OK, peer.ValidateSourceAddressToken( 2966d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) kPrimary, token6, ip6, now)); 2975c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Override config generates configs that validate successfully. 2995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const string override_token4 = peer.NewSourceAddressToken( 3005c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu kOverride, ip4, rand, now); 3015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const string override_token6 = peer.NewSourceAddressToken( 3025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu kOverride, ip6, rand, now); 3036d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(HANDSHAKE_OK, peer.ValidateSourceAddressToken( 3045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu kOverride, override_token4, ip4, now)); 3056d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(SOURCE_ADDRESS_TOKEN_DIFFERENT_IP_ADDRESS_FAILURE, 3066d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) peer.ValidateSourceAddressToken(kOverride, override_token4, ip6, 3076d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) now)); 3086d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(HANDSHAKE_OK, peer.ValidateSourceAddressToken( 3095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu kOverride, override_token6, ip6, now)); 3105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 3115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Tokens generated by the primary config do not validate 3125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // successfully against the override config, and vice versa. 3136d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE, 3146d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) peer.ValidateSourceAddressToken(kOverride, token4, ip4, now)); 3156d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE, 3166d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) peer.ValidateSourceAddressToken(kOverride, token6, ip6, now)); 3176d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE, 3186d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) peer.ValidateSourceAddressToken(kPrimary, override_token4, ip4, 3196d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) now)); 3206d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE, 3216d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) peer.ValidateSourceAddressToken(kPrimary, override_token6, ip6, 3226d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) now)); 3235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 3245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Validation fails after tokens expire. 325c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) now = original_time.Add(QuicTime::Delta::FromSeconds(86400 * 7)); 3266d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(SOURCE_ADDRESS_TOKEN_EXPIRED_FAILURE, 3276d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now)); 328c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 329c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) now = original_time.Subtract(QuicTime::Delta::FromSeconds(3600 * 2)); 3306d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) DCHECK_EQ(SOURCE_ADDRESS_TOKEN_CLOCK_SKEW_FAILURE, 3316d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now)); 3326d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)} 3336d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 3346d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)TEST(QuicCryptoServerConfigTest, ValidateServerNonce) { 3356d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) QuicRandom* rand = QuicRandom::GetInstance(); 3366d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); 3376d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) QuicCryptoServerConfigPeer peer(&server); 3386d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 3396d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) StringPiece message("hello world"); 3406d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) const size_t key_size = CryptoSecretBoxer::GetKeySize(); 3416d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) scoped_ptr<uint8[]> key(new uint8[key_size]); 3426d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) memset(key.get(), 0x11, key_size); 3436d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 3446d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) CryptoSecretBoxer boxer; 3456d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) boxer.SetKey(StringPiece(reinterpret_cast<char*>(key.get()), key_size)); 3466d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) const string box = boxer.Box(rand, message); 3476d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) MockClock clock; 3486d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) QuicWallTime now = clock.WallNow(); 3496d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) const QuicWallTime original_time = now; 3506d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) EXPECT_EQ(SERVER_NONCE_DECRYPTION_FAILURE, 3516d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) peer.ValidateServerNonce(box, now)); 3526d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 3536d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) string server_nonce = peer.NewServerNonce(rand, now); 3546d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) EXPECT_EQ(HANDSHAKE_OK, peer.ValidateServerNonce(server_nonce, now)); 3556d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) EXPECT_EQ(SERVER_NONCE_NOT_UNIQUE_FAILURE, 3566d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) peer.ValidateServerNonce(server_nonce, now)); 3576d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 3586d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) now = original_time.Add(QuicTime::Delta::FromSeconds(1000 * 7)); 3596d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) server_nonce = peer.NewServerNonce(rand, now); 3606d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) EXPECT_EQ(HANDSHAKE_OK, peer.ValidateServerNonce(server_nonce, now)); 361c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 362c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 3637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class CryptoServerConfigsTest : public ::testing::Test { 3647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public: 3657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) CryptoServerConfigsTest() 3667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) : rand_(QuicRandom::GetInstance()), 3677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) config_(QuicCryptoServerConfig::TESTING, rand_), 3687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_(&config_) {} 3697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void SetUp() { 3717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1000)); 3727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 3737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // SetConfigs constructs suitable config protobufs and calls SetConfigs on 3757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // |config_|. The arguments are given as NULL-terminated pairs. The first of 3767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // each pair is the server config ID of a Config. The second is the 3777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // |primary_time| of that Config, given in epoch seconds. (Although note 3787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // that, in these tests, time is set to 1000 seconds since the epoch.) For 3797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // example: 3807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // SetConfigs(NULL); // calls |config_.SetConfigs| with no protobufs. 3817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // 3827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // // Calls |config_.SetConfigs| with two protobufs: one for a Config with 3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // // a |primary_time| of 900 and priority 1, and another with 3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // // a |primary_time| of 1000 and priority 2. 3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // CheckConfigs( 3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // "id1", 900, 1, 3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // "id2", 1000, 2, 3897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // NULL); 3907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // 3917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // If the server config id starts with "INVALID" then the generated protobuf 3927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // will be invalid. 3937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void SetConfigs(const char* server_config_id1, ...) { 3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const char kOrbit[] = "12345678"; 3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) va_list ap; 3977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) va_start(ap, server_config_id1); 3987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool has_invalid = false; 3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool is_empty = true; 4007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) vector<QuicServerConfigProtobuf*> protobufs; 4027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool first = true; 4037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) for (;;) { 4047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const char* server_config_id; 4057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (first) { 4067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) server_config_id = server_config_id1; 4077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) first = false; 4087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } else { 4097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) server_config_id = va_arg(ap, const char*); 4107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 4117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (!server_config_id) { 4137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 4147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 4157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) is_empty = false; 4177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int primary_time = va_arg(ap, int); 4185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int priority = va_arg(ap, int); 4197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) QuicCryptoServerConfig::ConfigOptions options; 4217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) options.id = server_config_id; 4225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) options.orbit = kOrbit; 4237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) QuicServerConfigProtobuf* protobuf( 4245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QuicCryptoServerConfig::GenerateConfig(rand_, &clock_, options)); 4257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) protobuf->set_primary_time(primary_time); 4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) protobuf->set_priority(priority); 4277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (string(server_config_id).find("INVALID") == 0) { 4287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) protobuf->clear_key(); 4297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) has_invalid = true; 4307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 4317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) protobufs.push_back(protobuf); 4327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 4337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_EQ(!has_invalid && !is_empty, 4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) config_.SetConfigs(protobufs, clock_.WallNow())); 4367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) STLDeleteElements(&protobufs); 4377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 4387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) protected: 4407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) QuicRandom* const rand_; 4417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MockClock clock_; 4427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) QuicCryptoServerConfig config_; 4437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) QuicCryptoServerConfigPeer test_peer_; 4447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}; 4457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, NoConfigs) { 4477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_.CheckConfigs(NULL); 4487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 4497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, MakePrimaryFirst) { 4517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Make sure that "b" is primary even though "a" comes first. 4525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 1100, 1, 4535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 900, 1, 4547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 4557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_.CheckConfigs( 4567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "a", false, 4577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "b", true, 4587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 4597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 4607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, MakePrimarySecond) { 4627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Make sure that a remains primary after b is added. 4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 900, 1, 4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 1100, 1, 4657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 4667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_.CheckConfigs( 4677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "a", true, 4687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "b", false, 4697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 4707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 4717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, Delete) { 4737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Ensure that configs get deleted when removed. 4745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 800, 1, 4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 900, 1, 4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 1100, 1, 4777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", false, 4805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", true, 4815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", false, 4825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 4835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("b", 900, 1, 4845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 1100, 1, 4857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 4867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_.CheckConfigs( 4877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "b", true, 4887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "c", false, 4897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 4907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 4917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, DeletePrimary) { 4935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Ensure that deleting the primary config works. 4945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 800, 1, 4955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 900, 1, 4965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 1100, 1, 4975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 4985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 4995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", false, 5005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", true, 5015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", false, 5025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 800, 1, 5045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 1100, 1, 5057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 5065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 5075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", true, 5085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", false, 5095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, FailIfDeletingAllConfigs) { 5135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Ensure that configs get deleted when removed. 5145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 800, 1, 5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 900, 1, 5167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 5177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_.CheckConfigs( 5187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "a", false, 5197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "b", true, 5205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs(NULL); 5225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Config change is rejected, still using old configs. 5235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 5245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", false, 5255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", true, 5265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, ChangePrimaryTime) { 5305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Check that updates to primary time get picked up. 5315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 400, 1, 5325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 800, 1, 5335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 1200, 1, 5345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.SelectNewPrimaryConfig(500); 5365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 5375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", true, 5385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", false, 5395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", false, 5405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 1200, 1, 5425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 800, 1, 5435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 400, 1, 5445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.SelectNewPrimaryConfig(500); 5465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 5475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", false, 5485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", false, 5495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", true, 5505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, AllConfigsInThePast) { 5545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Check that the most recent config is selected. 5555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 400, 1, 5565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 800, 1, 5575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 1200, 1, 5585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.SelectNewPrimaryConfig(1500); 5605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 5615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", false, 5625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", false, 5635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", true, 5645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, AllConfigsInTheFuture) { 5685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Check that the first config is selected. 5695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 400, 1, 5705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 800, 1, 5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 1200, 1, 5725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.SelectNewPrimaryConfig(100); 5745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 5755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", true, 5765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", false, 5775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", false, 5785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, SortByPriority) { 5825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Check that priority is used to decide on a primary config when 5835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // configs have the same primary time. 5845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 900, 1, 5855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 900, 2, 5865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 900, 3, 5875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", true, 5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", false, 5917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "c", false, 5927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 5935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.SelectNewPrimaryConfig(800); 5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", true, 5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", false, 5975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", false, 5985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 5995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.SelectNewPrimaryConfig(1000); 6005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 6015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", true, 6025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", false, 6035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", false, 6045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 6055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Change priorities and expect sort order to change. 6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 900, 2, 6085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 900, 1, 6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 900, 0, 6105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 6115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 6125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", false, 6135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", false, 6145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", true, 6155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 6165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.SelectNewPrimaryConfig(800); 6175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", false, 6195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", false, 6205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", true, 6215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 6225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.SelectNewPrimaryConfig(1000); 6235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_peer_.CheckConfigs( 6245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "a", false, 6255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", false, 6265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", true, 6275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NULL); 6287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 6297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 6307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, AdvancePrimary) { 6317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Check that a new primary config is enabled at the right time. 6325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 900, 1, 6335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 1100, 1, 6347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 6357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_.SelectNewPrimaryConfig(1000); 6367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_.CheckConfigs( 6377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "a", true, 6387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "b", false, 6397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 6407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_.SelectNewPrimaryConfig(1101); 6417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_.CheckConfigs( 6427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "a", false, 6437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "b", true, 6447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 6457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 6467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 6477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(CryptoServerConfigsTest, InvalidConfigs) { 6487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Ensure that invalid configs don't change anything. 6495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 800, 1, 6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "b", 900, 1, 6515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 1100, 1, 6527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 6537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_.CheckConfigs( 6547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "a", false, 6557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "b", true, 6567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "c", false, 6577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 6585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetConfigs("a", 800, 1, 6595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "c", 1100, 1, 6605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "INVALID1", 1000, 1, 6617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 6627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) test_peer_.CheckConfigs( 6637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "a", false, 6647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "b", true, 6657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) "c", false, 6667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NULL); 6677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 6687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace test 6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace net 671