23 using namespace folly;
27 DEFINE_bool(server,
false,
"act as a server, otherwise act as a client");
30 DEFINE_int32(resume_count, 0,
"number of additional connections to open");
48 std::shared_ptr<FizzServerContext> serverContext,
49 std::shared_ptr<SSLContext> sslContext)
50 :
evb_(evb), serverContext_(serverContext), sslContext_(sslContext) {
52 socket_->connect(
this,
"::", port, 1000);
62 LOG(
INFO) <<
"TCP connect failed: " << ex.what();
75 LOG(
INFO) <<
"Handshake error: " << ex.what();
81 std::unique_ptr<folly::IOBuf> clientHello)
override {
85 unimplemented_ =
true;
95 throw std::runtime_error(
"getReadBuffer not implemented");
99 CHECK(
false) <<
"readDataAvailable not implemented";
108 std::unique_ptr<IOBuf>
write = IOBuf::create(0);
110 while (!cursor.isAtEnd()) {
112 cursor.pull(&byte, 1);
114 appender.push(&byte, 1);
130 LOG(
INFO) <<
"SSL Handshake error: " << ex.what();
136 return unimplemented_;
153 bool unimplemented_{
false};
164 std::shared_ptr<const FizzClientContext> clientContext)
167 socket_->connect(
this,
"::", port, 1000);
178 LOG(
INFO) <<
"TCP connect failed: " << ex.what();
191 LOG(
INFO) <<
"Handshake error: " << ex.what();
196 "received alert: protocol_version, in state ExpectingServerHello") !=
198 unimplemented_ =
true;
204 throw std::runtime_error(
"getReadBuffer not implemented");
208 CHECK(
false) <<
"readDataAvailable not implemented";
217 std::unique_ptr<IOBuf>
write = IOBuf::create(0);
219 while (!cursor.isAtEnd()) {
221 cursor.pull(&byte, 1);
223 appender.push(&byte, 1);
233 return unimplemented_;
246 bool unimplemented_{
false};
254 return "testrsacert";
262 return "testp256cert";
268 BIO_read_filename(b.get(), FLAGS_cert_file.c_str());
269 std::vector<X509UniquePtr> certs;
271 X509UniquePtr x509(PEM_read_bio_X509(b.get(),
nullptr,
nullptr,
nullptr));
279 throw std::runtime_error(
"could not read cert");
282 b.reset(BIO_new(BIO_s_file()));
283 BIO_read_filename(b.get(), FLAGS_key_file.c_str());
285 PEM_read_bio_PrivateKey(b.get(),
nullptr,
nullptr,
nullptr));
287 std::unique_ptr<SelfCert> cert;
288 if (EVP_PKEY_id(key.get()) == EVP_PKEY_RSA) {
290 }
else if (EVP_PKEY_id(key.get()) == EVP_PKEY_EC) {
293 throw std::runtime_error(
"unknown cert type");
298 auto certManager = std::make_unique<CertManager>();
301 auto ticketCipher = std::make_shared<AES128TicketCipher>();
303 ticketCipher->setTicketSecrets({{
range(ticketSeed)}});
304 ticketCipher->setValidity(std::chrono::seconds(60));
306 auto serverContext = std::make_shared<FizzServerContext>();
307 serverContext->setCertManager(
std::move(certManager));
308 serverContext->setTicketCipher(ticketCipher);
309 serverContext->setSupportedAlpns({
"h2",
"http/1.1"});
310 serverContext->setVersionFallbackEnabled(
true);
313 std::vector<std::unique_ptr<BogoTestServer>> servers;
314 for (
size_t i = 0;
i <= size_t(FLAGS_resume_count);
i++) {
315 servers.push_back(std::make_unique<BogoTestServer>(
316 &evb, FLAGS_port, serverContext,
nullptr));
319 for (
const auto& server : servers) {
320 if (server->unimplemented()) {
321 LOG(
INFO) <<
"Testing unimplemented feature.";
325 for (
const auto& server : servers) {
326 if (!server->success()) {
327 LOG(
INFO) <<
"Connection failed.";
336 auto clientContext = std::make_shared<FizzClientContext>();
337 clientContext->setCompatibilityMode(
true);
339 if (!FLAGS_cert_file.empty()) {
344 if (FLAGS_resume_count >= 1) {
348 std::make_unique<BogoTestClient>(&evb, FLAGS_port, clientContext);
350 if (client->unimplemented()) {
351 LOG(
INFO) <<
"Testing unimplemented feature.";
354 if (!client->success()) {
355 LOG(
INFO) <<
"Connection failed.";
364 for (
int i = 1;
i < argc;
i++) {
365 if (argv[
i][0] ==
'-') {
366 for (
char* j = argv[
i] + 2; *j; j++) {
375 LOG(
INFO) <<
"unknown flag: " << argv[
i];
381 gflags::ParseCommandLineFlags(&argc, &argv,
true);
382 google::InitGoogleLogging(argv[0]);
385 if (FLAGS_port == 0) {
386 throw std::runtime_error(
"must specify port");
std::unique_ptr< SelfCert > readSelfCert()
bool unimplemented() const
void write(const T &in, folly::io::Appender &appender)
std::string getIdentity() const override
DEFINE_int32(port, 0,"port to connect to")
void handshakeSuc(folly::AsyncSSLSocket *) noexceptoverride
std::unique_ptr< X509, X509Deleter > X509UniquePtr
bool isBufferMovable() noexceptoverride
std::unique_ptr< BIO, BioDeleter > BioUniquePtr
void readBufferAvailable(std::unique_ptr< IOBuf > buf) noexceptoverride
int main(int argc, char **argv)
Optional< bool > success_
void fizzHandshakeSuccess(AsyncFizzClient *) noexceptoverride
constexpr detail::Map< Move > move
void readErr(const AsyncSocketException &) noexceptoverride
void fizzHandshakeError(AsyncFizzServer *, folly::exception_wrapper ex) noexceptoverride
void getReadBuffer(void **, size_t *) override
Optional< bool > success_
std::unique_ptr< EVP_PKEY, EvpPkeyDeleter > EvpPkeyUniquePtr
void connectSuccess() noexceptoverride
—— Concurrent Priority Queue Implementation ——
AsyncSocket::UniquePtr socket_
requires E e noexcept(noexcept(s.error(std::move(e))))
std::unique_ptr< AsyncFizzClientT, folly::DelayedDestruction::Destructor > UniquePtr
BogoTestServer(EventBase *evb, uint16_t port, std::shared_ptr< FizzServerContext > serverContext, std::shared_ptr< SSLContext > sslContext)
void connectSuccess() noexceptoverride
std::shared_ptr< const FizzClientContext > clientContext_
void connectErr(const AsyncSocketException &ex) noexceptoverride
void readDataAvailable(size_t) noexceptoverride
void readEOF() noexceptoverride
bool unimplemented() const
static std::vector< std::string > kKnownFlags
Gen range(Value begin, Value end)
std::unique_ptr< AsyncSSLSocket, Destructor > UniquePtr
AsyncFizzClientT< ClientStateMachine > AsyncFizzClient
BogoTestClient(EventBase *evb, uint16_t port, std::shared_ptr< const FizzClientContext > clientContext)
bool isBufferMovable() noexceptoverride
void fizzHandshakeSuccess(AsyncFizzServer *) noexceptoverride
void fizzHandshakeAttemptFallback(std::unique_ptr< folly::IOBuf > clientHello) override
DEFINE_bool(server, false,"act as a server, otherwise act as a client")
AsyncSSLSocket::UniquePtr sslSocket_
AsyncServerSocket::UniquePtr socket_
void readDataAvailable(size_t) noexceptoverride
void getReadBuffer(void **, size_t *) override
void readBufferAvailable(std::unique_ptr< IOBuf > buf) noexceptoverride
void readErr(const AsyncSocketException &) noexceptoverride
AsyncFizzServer::UniquePtr transport_
AsyncSocket::UniquePtr socket_
std::shared_ptr< FizzClientContext > clientContext_
std::shared_ptr< FizzServerContext > serverContext_
void readEOF() noexceptoverride
AsyncFizzClient::UniquePtr transport_
std::unique_ptr< AsyncFizzServerT, folly::DelayedDestruction::Destructor > UniquePtr
AsyncFizzClient::UniquePtr transport_
static constexpr int kUnimplemented
void handshakeErr(folly::AsyncSSLSocket *, const folly::AsyncSocketException &ex) noexceptoverride
AsyncFizzServerT< ServerStateMachine > AsyncFizzServer
std::shared_ptr< SSLContext > sslContext_
void connectErr(const AsyncSocketException &ex) noexceptoverride
AsyncSSLSocket::UniquePtr sslSocket_
std::string getIdentity() const override
std::unique_ptr< AsyncSocket, Destructor > UniquePtr
DEFINE_string(key_file,"","key file")
void fizzHandshakeError(AsyncFizzClient *, folly::exception_wrapper ex) noexceptoverride