ssl_server_config.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Copyright 2015 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. #ifndef NET_SSL_SSL_SERVER_CONFIG_H_
  5. #define NET_SSL_SSL_SERVER_CONFIG_H_
  6. #include <stdint.h>
  7. #include <utility>
  8. #include <vector>
  9. #include "base/callback.h"
  10. #include "base/containers/flat_map.h"
  11. #include "base/memory/raw_ptr.h"
  12. #include "net/base/net_export.h"
  13. #include "net/socket/next_proto.h"
  14. #include "net/ssl/ssl_config.h"
  15. #include "third_party/abseil-cpp/absl/types/optional.h"
  16. #include "third_party/boringssl/src/include/openssl/base.h"
  17. namespace net {
  18. class ClientCertVerifier;
  19. // A collection of server-side SSL-related configuration settings.
  20. struct NET_EXPORT SSLServerConfig {
  21. enum ClientCertType {
  22. NO_CLIENT_CERT,
  23. OPTIONAL_CLIENT_CERT,
  24. REQUIRE_CLIENT_CERT,
  25. };
  26. // Defaults
  27. SSLServerConfig();
  28. SSLServerConfig(const SSLServerConfig& other);
  29. ~SSLServerConfig();
  30. // The minimum and maximum protocol versions that are enabled.
  31. // (Use the SSL_PROTOCOL_VERSION_xxx enumerators defined in ssl_config.h)
  32. // SSL 2.0 and SSL 3.0 are not supported. If version_max < version_min, it
  33. // means no protocol versions are enabled.
  34. uint16_t version_min = kDefaultSSLVersionMin;
  35. uint16_t version_max = kDefaultSSLVersionMax;
  36. // Whether early data is enabled on this connection. The caller is obligated
  37. // to reject early data that is non-safe to be replayed.
  38. bool early_data_enabled = false;
  39. // Presorted list of cipher suites which should be explicitly prevented from
  40. // being used in addition to those disabled by the net built-in policy.
  41. //
  42. // By default, all cipher suites supported by the underlying SSL
  43. // implementation will be enabled except for:
  44. // - Null encryption cipher suites.
  45. // - Weak cipher suites: < 80 bits of security strength.
  46. // - FORTEZZA cipher suites (obsolete).
  47. // - IDEA cipher suites (RFC 5469 explains why).
  48. // - Anonymous cipher suites.
  49. // - ECDSA cipher suites on platforms that do not support ECDSA signed
  50. // certificates, as servers may use the presence of such ciphersuites as a
  51. // hint to send an ECDSA certificate.
  52. // The ciphers listed in |disabled_cipher_suites| will be removed in addition
  53. // to the above list.
  54. //
  55. // Though cipher suites are sent in TLS as "uint8_t CipherSuite[2]", in
  56. // big-endian form, they should be declared in host byte order, with the
  57. // first uint8_t occupying the most significant byte.
  58. // Ex: To disable TLS_RSA_WITH_RC4_128_MD5, specify 0x0004, while to
  59. // disable TLS_ECDH_ECDSA_WITH_RC4_128_SHA, specify 0xC002.
  60. std::vector<uint16_t> disabled_cipher_suites;
  61. // If true, causes only ECDHE cipher suites to be enabled.
  62. bool require_ecdhe = false;
  63. // cipher_suite_for_testing, if set, causes the server to only support the
  64. // specified cipher suite in TLS 1.2 and below. This should only be used in
  65. // unit tests.
  66. absl::optional<uint16_t> cipher_suite_for_testing;
  67. // signature_algorithm_for_testing, if set, causes the server to only support
  68. // the specified signature algorithm in TLS 1.2 and below. This should only be
  69. // used in unit tests.
  70. absl::optional<uint16_t> signature_algorithm_for_testing;
  71. // curves_for_testing, if not empty, specifies the list of NID values (e.g.
  72. // NID_X25519) to configure as supported curves for the TLS connection.
  73. std::vector<int> curves_for_testing;
  74. // Sets the requirement for client certificates during handshake.
  75. ClientCertType client_cert_type = NO_CLIENT_CERT;
  76. // List of DER-encoded X.509 DistinguishedName of certificate authorities
  77. // to be included in the CertificateRequest handshake message,
  78. // if client certificates are required.
  79. std::vector<std::string> cert_authorities;
  80. // Provides the ClientCertVerifier that is to be used to verify
  81. // client certificates during the handshake.
  82. // The |client_cert_verifier| continues to be owned by the caller,
  83. // and must outlive any sockets spawned from this SSLServerContext.
  84. // This field is meaningful only if client certificates are requested.
  85. // If a verifier is not provided then all certificates are accepted.
  86. raw_ptr<ClientCertVerifier> client_cert_verifier = nullptr;
  87. // The list of application level protocols supported with ALPN (Application
  88. // Layer Protocol Negotiation), in decreasing order of preference. Protocols
  89. // will be advertised in this order during TLS handshake.
  90. NextProtoVector alpn_protos;
  91. // ALPS TLS extension is enabled and corresponding data is sent to client if
  92. // client also enabled ALPS, for each NextProto in |application_settings|.
  93. // Data might be empty.
  94. base::flat_map<NextProto, std::vector<uint8_t>> application_settings;
  95. // If non-empty, the DER-encoded OCSP response to staple.
  96. std::vector<uint8_t> ocsp_response;
  97. // If non-empty, the serialized SignedCertificateTimestampList to send in the
  98. // handshake.
  99. std::vector<uint8_t> signed_cert_timestamp_list;
  100. // If specified, called at the start of each connection with the ClientHello.
  101. // Returns true to continue the handshake and false to fail it.
  102. base::RepeatingCallback<bool(const SSL_CLIENT_HELLO*)>
  103. client_hello_callback_for_testing;
  104. // If specified, causes the specified alert to be sent immediately after the
  105. // handshake.
  106. absl::optional<uint8_t> alert_after_handshake_for_testing;
  107. // This is a workaround for BoringSSL's scopers not being copyable. See
  108. // https://crbug.com/boringssl/431.
  109. class NET_EXPORT ECHKeysContainer {
  110. public:
  111. ECHKeysContainer();
  112. // Intentionally allow implicit conversion from bssl::UniquePtr.
  113. ECHKeysContainer( // NOLINT(google-explicit-constructor)
  114. bssl::UniquePtr<SSL_ECH_KEYS> keys);
  115. ~ECHKeysContainer();
  116. ECHKeysContainer(const ECHKeysContainer& other);
  117. ECHKeysContainer& operator=(const ECHKeysContainer& other);
  118. // Forward APIs from bssl::UniquePtr.
  119. SSL_ECH_KEYS* get() const { return keys_.get(); }
  120. explicit operator bool() const { return static_cast<bool>(keys_); }
  121. // This is defined out-of-line to avoid an ssl.h include.
  122. void reset(SSL_ECH_KEYS* keys = nullptr);
  123. private:
  124. bssl::UniquePtr<SSL_ECH_KEYS> keys_;
  125. };
  126. // If not nullptr, an ECH configuration to use on the server.
  127. ECHKeysContainer ech_keys;
  128. };
  129. } // namespace net
  130. #endif // NET_SSL_SSL_SERVER_CONFIG_H_