proxygen
TestMessages.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #include <fizz/protocol/Params.h>
13 #include <fizz/record/Extensions.h>
14 #include <fizz/record/Types.h>
15 
16 namespace fizz {
17 namespace test {
18 
19 struct TestMessages {
20  template <typename T>
21  static void removeExtension(T& msg, ExtensionType ext) {
22  auto it = findExtension(msg.extensions, ext);
23  msg.extensions.erase(it);
24  }
25 
30  chlo.random.fill(0x44);
31  chlo.legacy_compression_methods.push_back(0x00);
33  SupportedVersions supportedVersions;
34  supportedVersions.versions.push_back(TestProtocolVersion);
35  chlo.extensions.push_back(encodeExtension(std::move(supportedVersions)));
36  SupportedGroups supportedGroups;
37  supportedGroups.named_group_list.push_back(NamedGroup::x25519);
38  supportedGroups.named_group_list.push_back(NamedGroup::secp256r1);
39  chlo.extensions.push_back(encodeExtension(std::move(supportedGroups)));
40  ClientKeyShare keyShare;
41  KeyShareEntry entry;
42  entry.group = NamedGroup::x25519;
43  entry.key_exchange = folly::IOBuf::copyBuffer("keyshare");
44  keyShare.client_shares.push_back(std::move(entry));
45  chlo.extensions.push_back(encodeExtension(std::move(keyShare)));
46  SignatureAlgorithms sigAlgs;
47  sigAlgs.supported_signature_algorithms.push_back(
49  sigAlgs.supported_signature_algorithms.push_back(
51  chlo.extensions.push_back(encodeExtension(std::move(sigAlgs)));
53  ServerName sn;
54  sn.hostname = folly::IOBuf::copyBuffer("www.hostname.com");
55  sni.server_name_list.push_back(std::move(sn));
56  chlo.extensions.push_back(encodeExtension(std::move(sni)));
58  ProtocolName h2;
59  h2.name = folly::IOBuf::copyBuffer("h2");
60  alpn.protocol_name_list.push_back(std::move(h2));
61  chlo.extensions.push_back(encodeExtension(std::move(alpn)));
62  PskKeyExchangeModes modes;
63  modes.modes.push_back(PskKeyExchangeMode::psk_dhe_ke);
64  modes.modes.push_back(PskKeyExchangeMode::psk_ke);
65  chlo.extensions.push_back(encodeExtension(std::move(modes)));
66  chlo.originalEncoding = folly::IOBuf::copyBuffer("clienthelloencoding");
67  return chlo;
68  }
69 
70  static void addPsk(ClientHello& chlo, uint32_t ticketAge = 100000) {
72  PskIdentity ident;
73  ident.psk_identity = folly::IOBuf::copyBuffer("ident");
74  ident.obfuscated_ticket_age = ticketAge;
75  cpk.identities.push_back(std::move(ident));
76  PskBinder binder;
77  binder.binder = folly::IOBuf::copyBuffer("verifydata");
78  cpk.binders.push_back(std::move(binder));
79  chlo.extensions.push_back(encodeExtension(std::move(cpk)));
80  }
81 
83  auto chlo = clientHello();
84  addPsk(chlo);
85  return chlo;
86  }
87 
89  auto chlo = clientHello();
90  chlo.extensions.push_back(encodeExtension(ClientEarlyData()));
91  addPsk(chlo);
92  return chlo;
93  }
94 
99  ServerSupportedVersions supportedVersions;
100  supportedVersions.selected_version = TestProtocolVersion;
101  hrr.extensions.push_back(encodeExtension(std::move(supportedVersions)));
102  HelloRetryRequestKeyShare keyShare;
104  hrr.extensions.push_back(encodeExtension(std::move(keyShare)));
105  hrr.originalEncoding = folly::IOBuf::copyBuffer("hrrencoding");
106  return hrr;
107  }
108 
110  ServerHello shlo;
113  shlo.random.fill(0x44);
115  ServerSupportedVersions supportedVersions;
116  supportedVersions.selected_version = TestProtocolVersion;
117  shlo.extensions.push_back(encodeExtension(std::move(supportedVersions)));
118  ServerKeyShare serverKeyShare;
119  serverKeyShare.server_share.group = NamedGroup::x25519;
120  serverKeyShare.server_share.key_exchange =
121  folly::IOBuf::copyBuffer("servershare");
122  shlo.extensions.push_back(encodeExtension(std::move(serverKeyShare)));
123  shlo.originalEncoding = folly::IOBuf::copyBuffer("shloencoding");
124  return shlo;
125  }
126 
128  auto shlo = serverHello();
129  ServerPresharedKey pskExt;
130  pskExt.selected_identity = 0;
131  shlo.extensions.push_back(encodeExtension(std::move(pskExt)));
132  return shlo;
133  }
134 
136  EndOfEarlyData eoed;
137  eoed.originalEncoding = folly::IOBuf::copyBuffer("eoedencoding");
138  return eoed;
139  }
140 
144  ProtocolName h2;
145  h2.name = folly::IOBuf::copyBuffer("h2");
146  alpn.protocol_name_list.push_back(std::move(h2));
147  encryptedExt.extensions.push_back(encodeExtension(std::move(alpn)));
148  encryptedExt.originalEncoding = folly::IOBuf::copyBuffer("eeencoding");
149  return encryptedExt;
150  }
151 
153  auto ee = encryptedExt();
154  ee.extensions.push_back(encodeExtension(ServerEarlyData()));
155  return ee;
156  }
157 
161  certificate.originalEncoding = folly::IOBuf::copyBuffer("certencoding");
162  return certificate;
163  }
164 
168  cc.uncompressed_length = 0x111111;
170  folly::IOBuf::copyBuffer("compressedcerts");
171  cc.originalEncoding = folly::IOBuf::copyBuffer("compcertencoding");
172  return cc;
173  }
174 
178  verify.signature = folly::IOBuf::copyBuffer("signature");
179  verify.originalEncoding = folly::IOBuf::copyBuffer("certverifyencoding");
180  return verify;
181  }
182 
186  SignatureAlgorithms sigAlgs;
187  sigAlgs.supported_signature_algorithms.push_back(
189  sigAlgs.supported_signature_algorithms.push_back(
191  cr.extensions.push_back(encodeExtension(std::move(sigAlgs)));
192  cr.originalEncoding = folly::IOBuf::copyBuffer("certrequestencoding");
193  return cr;
194  }
195 
196  static Finished finished() {
198  finished.verify_data = folly::IOBuf::copyBuffer("verifydata");
199  finished.originalEncoding = folly::IOBuf::copyBuffer("finishedencoding");
200  return finished;
201  }
202 
205  nst.ticket_lifetime = 100;
206  nst.ticket_age_add = 0x44444444;
208  nst.ticket = folly::IOBuf::copyBuffer("ticket");
209  return nst;
210  }
211 
212  static AppData appData() {
214  return appData;
215  }
216 
217  static AppWrite appWrite() {
219  appWrite.data = folly::IOBuf::copyBuffer("appdata");
220  return appWrite;
221  }
222 
225  appWrite.data = folly::IOBuf::copyBuffer("appdata");
226  return appWrite;
227  }
228 
229  static KeyUpdate keyUpdate(bool reqUpdate) {
231  keyUpdate.request_update = reqUpdate
234  return keyUpdate;
235  }
236 };
237 } // namespace test
238 } // namespace fizz
std::vector< Extension > extensions
Definition: Types.h:218
std::vector< Extension > extensions
Definition: Types.h:228
std::unique_ptr< folly::IOBuf > data
Definition: Params.h:48
#define T(v)
Definition: http_parser.c:233
uint32_t obfuscated_ticket_age
Definition: Extensions.h:56
KeyUpdateRequest request_update
Definition: Types.h:299
std::vector< Extension >::const_iterator findExtension(const std::vector< Extension > &extensions, ExtensionType type)
std::vector< PskBinder > binders
Definition: Extensions.h:65
void verify(int extras)
CertificateCompressionAlgorithm algorithm
Definition: Types.h:245
static void addPsk(ClientHello &chlo, uint32_t ticketAge=100000)
Definition: TestMessages.h:70
static const std::string chlo
static std::unique_ptr< IOBuf > create(std::size_t capacity)
Definition: IOBuf.cpp:229
static NewSessionTicket newSessionTicket()
Definition: TestMessages.h:203
KeyShareEntry server_share
Definition: Extensions.h:41
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
StringPiece alpn
static CertificateMsg certificate()
Definition: TestMessages.h:158
std::vector< PskKeyExchangeMode > modes
Definition: Extensions.h:105
uint32_t uncompressed_length
Definition: Types.h:246
std::vector< NamedGroup > named_group_list
Definition: Extensions.h:23
Buf legacy_session_id_echo
Definition: Types.h:202
The non test part of the code is expected to have failures gtest_output_test_ cc
static EarlyAppWrite earlyAppWrite()
Definition: TestMessages.h:223
Buf certificate_request_context
Definition: Types.h:238
std::vector< KeyShareEntry > client_shares
Definition: Extensions.h:34
static ServerHello serverHello()
Definition: TestMessages.h:109
static Finished finished()
Definition: TestMessages.h:196
Random random
Definition: Types.h:189
NamedGroup group
Definition: Extensions.h:29
Buf certificate_request_context
Definition: Types.h:253
Buf legacy_session_id
Definition: Types.h:190
ProtocolVersion selected_version
Definition: Extensions.h:99
static CertificateRequest certificateRequest()
Definition: TestMessages.h:183
std::vector< Extension > extensions
Definition: Types.h:254
static AppWrite appWrite()
Definition: TestMessages.h:217
static EncryptedExtensions encryptedExt()
Definition: TestMessages.h:141
std::vector< SignatureScheme > supported_signature_algorithms
Definition: Extensions.h:17
Random random
Definition: Types.h:199
static EndOfEarlyData endOfEarlyData()
Definition: TestMessages.h:135
Definition: Actions.h:16
std::vector< Extension > extensions
Definition: Types.h:193
static CertificateVerify certificateVerify()
Definition: TestMessages.h:175
static ClientHello clientHelloPsk()
Definition: TestMessages.h:82
static CompressedCertificate compressedCertificate()
Definition: TestMessages.h:165
std::vector< ProtocolVersion > versions
Definition: Extensions.h:93
std::vector< CipherSuite > cipher_suites
Definition: Types.h:191
static void removeExtension(T &msg, ExtensionType ext)
Definition: TestMessages.h:21
static AppData appData()
Definition: TestMessages.h:212
Buf verify_data
Definition: Types.h:278
ProtocolVersion legacy_version
Definition: Types.h:210
ExtensionType
Definition: Types.h:95
SignatureScheme algorithm
Definition: Types.h:273
std::vector< Extension > extensions
Definition: Types.h:205
StringPiece sni
static const std::string nst
static HelloRetryRequest helloRetryRequest()
Definition: TestMessages.h:95
folly::Optional< Buf > originalEncoding
Definition: Types.h:92
CipherSuite cipher_suite
Definition: Types.h:216
uint32_t ticket_lifetime
Definition: Types.h:284
static EncryptedExtensions encryptedExtEarly()
Definition: TestMessages.h:152
std::vector< ProtocolName > protocol_name_list
Definition: Extensions.h:115
std::vector< PskIdentity > identities
Definition: Extensions.h:64
static KeyUpdate keyUpdate(bool reqUpdate)
Definition: TestMessages.h:229
std::vector< uint8_t > legacy_compression_methods
Definition: Types.h:192
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
static ClientHello clientHello()
Definition: TestMessages.h:26
CipherSuite cipher_suite
Definition: Types.h:203
ProtocolVersion legacy_version
Definition: Types.h:198
std::unique_ptr< folly::IOBuf > data
Definition: Params.h:54
constexpr ProtocolVersion TestProtocolVersion
Definition: ProtocolTest.h:22
static ClientHello clientHelloPskEarly()
Definition: TestMessages.h:88
uint32_t ticket_age_add
Definition: Types.h:285
static ServerHello serverHelloPsk()
Definition: TestMessages.h:127
std::vector< ServerName > server_name_list
Definition: Extensions.h:128