OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_PROTOBUF_H_ | |
6 #define NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_PROTOBUF_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 | |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 #include "base/logging.h" | |
15 #include "base/macros.h" | |
16 #include "base/stl_util.h" | |
17 #include "base/strings/string_piece.h" | |
18 #include "net/base/net_export.h" | |
19 #include "net/quic/crypto/crypto_protocol.h" | |
20 | |
21 namespace net { | |
22 | |
23 // QuicServerConfigProtobuf contains QUIC server config block and the private | |
24 // keys needed to prove ownership. | |
25 // TODO(rch): sync with server more rationally. | |
26 class NET_EXPORT_PRIVATE QuicServerConfigProtobuf { | |
27 public: | |
28 // PrivateKey contains a QUIC tag of a key exchange algorithm and a | |
29 // serialised private key for that algorithm. The format of the serialised | |
30 // private key is specific to the algorithm in question. | |
31 class NET_EXPORT_PRIVATE PrivateKey { | |
32 public: | |
33 QuicTag tag() const { return tag_; } | |
34 void set_tag(QuicTag tag) { tag_ = tag; } | |
35 std::string private_key() const { return private_key_; } | |
36 void set_private_key(const std::string& key) { private_key_ = key; } | |
37 | |
38 private: | |
39 QuicTag tag_; | |
40 std::string private_key_; | |
41 }; | |
42 | |
43 QuicServerConfigProtobuf(); | |
44 ~QuicServerConfigProtobuf(); | |
45 | |
46 size_t key_size() const { return keys_.size(); } | |
47 | |
48 const PrivateKey& key(size_t i) const { | |
49 DCHECK_GT(keys_.size(), i); | |
50 return *keys_[i]; | |
51 } | |
52 | |
53 std::string config() const { return config_; } | |
54 | |
55 void set_config(base::StringPiece config) { config.CopyToString(&config_); } | |
56 | |
57 QuicServerConfigProtobuf::PrivateKey* add_key() { | |
58 keys_.push_back(new PrivateKey); | |
59 return keys_.back(); | |
60 } | |
61 | |
62 void clear_key() { STLDeleteElements(&keys_); } | |
63 | |
64 bool has_primary_time() const { return primary_time_ > 0; } | |
65 | |
66 int64_t primary_time() const { return primary_time_; } | |
67 | |
68 void set_primary_time(int64_t primary_time) { primary_time_ = primary_time; } | |
69 | |
70 bool has_priority() const { return priority_ > 0; } | |
71 | |
72 uint64_t priority() const { return priority_; } | |
73 | |
74 void set_priority(int64_t priority) { priority_ = priority; } | |
75 | |
76 bool has_source_address_token_secret_override() const { | |
77 return !source_address_token_secret_override_.empty(); | |
78 } | |
79 | |
80 std::string source_address_token_secret_override() const { | |
81 return source_address_token_secret_override_; | |
82 } | |
83 | |
84 void set_source_address_token_secret_override( | |
85 base::StringPiece source_address_token_secret_override) { | |
86 source_address_token_secret_override.CopyToString( | |
87 &source_address_token_secret_override_); | |
88 } | |
89 | |
90 private: | |
91 std::vector<PrivateKey*> keys_; | |
92 | |
93 // config_ is a serialised config in QUIC wire format. | |
94 std::string config_; | |
95 | |
96 // primary_time_ contains a UNIX epoch seconds value that indicates when this | |
97 // config should become primary. | |
98 int64_t primary_time_; | |
99 | |
100 // Relative priority of this config vs other configs with the same | |
101 // primary time. For use as a secondary sort key when selecting the | |
102 // primary config. | |
103 uint64_t priority_; | |
104 | |
105 // Optional override to the secret used to box/unbox source address | |
106 // tokens when talking to clients that select this server config. | |
107 // It can be of any length as it is fed into a KDF before use. | |
108 std::string source_address_token_secret_override_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(QuicServerConfigProtobuf); | |
111 }; | |
112 | |
113 } // namespace net | |
114 | |
115 #endif // NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_PROTOBUF_H_ | |
OLD | NEW |