ssl_server_socket.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (c) 2012 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. // NOTE: This class is provided to support existing Chromium consumers; it is
  6. // NOT intended for use in NEW code. Configuring a TLS server correctly is a
  7. // security-sensitive activity with many subtle nuances, and thus care should be
  8. // taken to discuss with //net/OWNERS before any new usages.
  9. //
  10. // As such, this header should be treated as an internal implementation detail
  11. // of //net (where it's used for some unit test infrastructure), not as
  12. // appropriate for general use.
  13. //
  14. // See https://crbug.com/621176 for more details.
  15. #ifndef NET_SOCKET_SSL_SERVER_SOCKET_H_
  16. #define NET_SOCKET_SSL_SERVER_SOCKET_H_
  17. #include <memory>
  18. #include "net/base/completion_once_callback.h"
  19. #include "net/base/net_export.h"
  20. #include "net/socket/ssl_socket.h"
  21. #include "net/socket/stream_socket.h"
  22. #include "third_party/boringssl/src/include/openssl/base.h"
  23. namespace crypto {
  24. class RSAPrivateKey;
  25. } // namespace crypto
  26. namespace net {
  27. struct SSLServerConfig;
  28. class SSLPrivateKey;
  29. class X509Certificate;
  30. // A server socket that uses SSL as the transport layer.
  31. class SSLServerSocket : public SSLSocket {
  32. public:
  33. ~SSLServerSocket() override = default;
  34. // Perform the SSL server handshake, and notify the supplied callback
  35. // if the process completes asynchronously. If Disconnect is called before
  36. // completion then the callback will be silently, as for other StreamSocket
  37. // calls.
  38. virtual int Handshake(CompletionOnceCallback callback) = 0;
  39. };
  40. class SSLServerContext {
  41. public:
  42. virtual ~SSLServerContext() = default;
  43. // Creates an SSL server socket over an already-connected transport socket.
  44. // The caller must ensure the returned socket does not outlive the server
  45. // context.
  46. //
  47. // The caller starts the SSL server handshake by calling Handshake on the
  48. // returned socket.
  49. virtual std::unique_ptr<SSLServerSocket> CreateSSLServerSocket(
  50. std::unique_ptr<StreamSocket> socket) = 0;
  51. };
  52. // Creates an SSL server socket context where all sockets spawned using this
  53. // context will share the same session cache.
  54. //
  55. // The caller must provide the server certificate and private key to use.
  56. // It takes a reference to |certificate| and |pkey|.
  57. // The |ssl_config| parameter is copied.
  58. //
  59. NET_EXPORT std::unique_ptr<SSLServerContext> CreateSSLServerContext(
  60. X509Certificate* certificate,
  61. EVP_PKEY* pkey,
  62. const SSLServerConfig& ssl_config);
  63. // As above, but takes an RSAPrivateKey object. Deprecated, use the EVP_PKEY
  64. // version instead.
  65. // TODO(mattm): convert existing callers and remove this function.
  66. NET_EXPORT std::unique_ptr<SSLServerContext> CreateSSLServerContext(
  67. X509Certificate* certificate,
  68. const crypto::RSAPrivateKey& key,
  69. const SSLServerConfig& ssl_config);
  70. NET_EXPORT std::unique_ptr<SSLServerContext> CreateSSLServerContext(
  71. X509Certificate* certificate,
  72. scoped_refptr<SSLPrivateKey> key,
  73. const SSLServerConfig& ssl_config);
  74. } // namespace net
  75. #endif // NET_SOCKET_SSL_SERVER_SOCKET_H_