QUICHE team | c9b2cec | 2019-01-07 17:54:15 -0500 | [diff] [blame] | 1 | // Copyright 2014 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 | // A binary wrapper for QuicServer. It listens forever on --port |
| 6 | // (default 6121) until it's killed or ctrl-cd to death. |
| 7 | |
QUICHE team | 2bfc754 | 2019-02-26 14:36:06 -0500 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
QUICHE team | c9b2cec | 2019-01-07 17:54:15 -0500 | [diff] [blame] | 10 | #include "base/commandlineflags.h" |
| 11 | #include "base/init_google.h" |
| 12 | #include "net/httpsconnection/certificates.proto.h" |
| 13 | #include "net/httpsconnection/sslcontext.h" |
| 14 | #include "net/third_party/quiche/src/quic/core/crypto/proof_source_google3.h" |
| 15 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 16 | #include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h" |
| 17 | #include "net/third_party/quiche/src/quic/tools/quic_memory_cache_backend.h" |
| 18 | #include "net/third_party/quiche/src/quic/tools/quic_server.h" |
| 19 | |
QUICHE team | 2bfc754 | 2019-02-26 14:36:06 -0500 | [diff] [blame] | 20 | DEFINE_QUIC_COMMAND_LINE_FLAG(int32_t, |
| 21 | port, |
| 22 | 6121, |
| 23 | "The port the quic server will listen on."); |
| 24 | |
| 25 | DEFINE_QUIC_COMMAND_LINE_FLAG( |
| 26 | string, |
QUICHE team | c9b2cec | 2019-01-07 17:54:15 -0500 | [diff] [blame] | 27 | certificate_dir, |
| 28 | "/google/src/head/depot/google3/net/third_party/quiche/src/quic/core/crypto/testdata", |
| 29 | "The directory containing certificate files."); |
QUICHE team | 2bfc754 | 2019-02-26 14:36:06 -0500 | [diff] [blame] | 30 | |
| 31 | DEFINE_QUIC_COMMAND_LINE_FLAG( |
| 32 | string, |
| 33 | intermediate_certificate_name, |
| 34 | "intermediate.crt", |
| 35 | "The name of the file containing the intermediate certificate."); |
| 36 | |
| 37 | DEFINE_QUIC_COMMAND_LINE_FLAG( |
| 38 | string, |
| 39 | leaf_certificate_name, |
| 40 | "test.example.com", |
| 41 | "The name of the file containing the leaf certificate."); |
QUICHE team | c9b2cec | 2019-01-07 17:54:15 -0500 | [diff] [blame] | 42 | |
| 43 | std::unique_ptr<quic::ProofSource> CreateProofSource( |
| 44 | const string& base_directory, |
| 45 | const string& intermediate_cert_name, |
| 46 | const string& leaf_cert_name) { |
| 47 | SetQuicFlag(&FLAGS_disable_permission_validation, true); |
| 48 | |
| 49 | httpsconnection::CertificateConfig config; |
| 50 | config.set_base_directory(base_directory); |
| 51 | config.set_issuing_certificates_file(intermediate_cert_name); |
| 52 | config.add_cert()->set_name(leaf_cert_name); |
| 53 | |
| 54 | auto ssl_ctx = std::make_shared<SSLContext>( |
| 55 | SSLContext::SSL_SERVER_CONTEXT, |
| 56 | SSLContext::SESSION_CACHE_SERVER | |
| 57 | SSLContext::SESSION_CACHE_NO_INTERNAL_STORE); |
| 58 | CHECK_OK(ssl_ctx->Initialize(config)); |
| 59 | |
| 60 | return std::unique_ptr<quic::ProofSource>( |
| 61 | new quic::ProofSourceGoogle3(ssl_ctx, "unused_cert_mpm_version")); |
| 62 | } |
| 63 | |
| 64 | int main(int argc, char* argv[]) { |
QUICHE team | 2bfc754 | 2019-02-26 14:36:06 -0500 | [diff] [blame] | 65 | const char* usage = "Usage: quic_server [options]"; |
| 66 | std::vector<quic::QuicString> non_option_args = |
| 67 | quic::QuicParseCommandLineFlags(usage, argc, argv); |
| 68 | if (!non_option_args.empty()) { |
| 69 | quic::QuicPrintCommandLineFlagHelp(usage); |
| 70 | exit(0); |
QUICHE team | c9b2cec | 2019-01-07 17:54:15 -0500 | [diff] [blame] | 71 | } |
| 72 | |
QUICHE team | 2bfc754 | 2019-02-26 14:36:06 -0500 | [diff] [blame] | 73 | quic::QuicMemoryCacheBackend memory_cache_backend; |
| 74 | if (!GetQuicFlag(FLAGS_quic_response_cache_dir).empty()) { |
| 75 | memory_cache_backend.InitializeBackend( |
| 76 | GetQuicFlag(FLAGS_quic_response_cache_dir)); |
| 77 | } |
QUICHE team | c9b2cec | 2019-01-07 17:54:15 -0500 | [diff] [blame] | 78 | |
QUICHE team | 2bfc754 | 2019-02-26 14:36:06 -0500 | [diff] [blame] | 79 | quic::QuicServer server( |
| 80 | CreateProofSource(GetQuicFlag(FLAGS_certificate_dir), |
| 81 | GetQuicFlag(FLAGS_intermediate_certificate_name), |
| 82 | GetQuicFlag(FLAGS_leaf_certificate_name)), |
| 83 | &memory_cache_backend); |
| 84 | |
| 85 | if (!server.CreateUDPSocketAndListen(quic::QuicSocketAddress( |
| 86 | quic::QuicIpAddress::Any6(), GetQuicFlag(FLAGS_port)))) { |
QUICHE team | c9b2cec | 2019-01-07 17:54:15 -0500 | [diff] [blame] | 87 | return 1; |
| 88 | } |
| 89 | |
| 90 | while (true) { |
| 91 | server.WaitForEvents(); |
| 92 | } |
| 93 | } |