2 * nghttp2 - HTTP/2 C Library
4 * Copyright (c) 2012 Tatsuhiro Tsujikawa
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "nghttp2_config.h"
32 #include <openssl/ssl.h>
34 #include "ssl_compat.h"
40 // Acquire OpenSSL global lock to share SSL_CTX across multiple
41 // threads. The constructor acquires lock and destructor unlocks.
42 class LibsslGlobalLock {
45 LibsslGlobalLock(const LibsslGlobalLock &) = delete;
46 LibsslGlobalLock &operator=(const LibsslGlobalLock &) = delete;
49 // Recommended general purpose "Modern compatibility" cipher suites by
52 // https://wiki.mozilla.org/Security/Server_Side_TLS
53 constexpr char DEFAULT_CIPHER_LIST[] =
54 "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-"
55 "CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-"
56 "SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-"
57 "AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256";
59 constexpr char DEFAULT_TLS13_CIPHER_LIST[] =
61 TLS_DEFAULT_CIPHERSUITES
62 #else // !OPENSSL_1_1_1_API
64 #endif // !OPENSSL_1_1_1_API
67 constexpr auto NGHTTP2_TLS_MIN_VERSION = TLS1_VERSION;
69 constexpr auto NGHTTP2_TLS_MAX_VERSION = TLS1_3_VERSION;
70 #else // !TLS1_3_VERSION
71 constexpr auto NGHTTP2_TLS_MAX_VERSION = TLS1_2_VERSION;
72 #endif // !TLS1_3_VERSION
74 const char *get_tls_protocol(SSL *ssl);
76 struct TLSSessionInfo {
79 const uint8_t *session_id;
81 size_t session_id_length;
84 TLSSessionInfo *get_tls_session_info(TLSSessionInfo *tls_info, SSL *ssl);
86 // Returns true iff the negotiated protocol is TLSv1.2.
87 bool check_http2_tls_version(SSL *ssl);
89 // Returns true iff the negotiated cipher suite is in HTTP/2 cipher
91 bool check_http2_cipher_black_list(SSL *ssl);
93 // Returns true if SSL/TLS requirement for HTTP/2 is fulfilled.
94 // To fulfill the requirement, the following 2 terms must be hold:
96 // 1. The negotiated protocol must be TLSv1.2.
97 // 2. The negotiated cipher cuite is not listed in the black list
98 // described in RFC 7540.
99 bool check_http2_requirement(SSL *ssl);
101 // Initializes OpenSSL library
104 // Sets TLS min and max versions to |ssl_ctx|. This function returns
105 // 0 if it succeeds, or -1.
106 int ssl_ctx_set_proto_versions(SSL_CTX *ssl_ctx, int min, int max);
110 } // namespace nghttp2