12c593315Sopenharmony_ci/* 22c593315Sopenharmony_ci * nghttp2 - HTTP/2 C Library 32c593315Sopenharmony_ci * 42c593315Sopenharmony_ci * Copyright (c) 2012 Tatsuhiro Tsujikawa 52c593315Sopenharmony_ci * 62c593315Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 72c593315Sopenharmony_ci * a copy of this software and associated documentation files (the 82c593315Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 92c593315Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 102c593315Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 112c593315Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 122c593315Sopenharmony_ci * the following conditions: 132c593315Sopenharmony_ci * 142c593315Sopenharmony_ci * The above copyright notice and this permission notice shall be 152c593315Sopenharmony_ci * included in all copies or substantial portions of the Software. 162c593315Sopenharmony_ci * 172c593315Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 182c593315Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 192c593315Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 202c593315Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 212c593315Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 222c593315Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 232c593315Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 242c593315Sopenharmony_ci */ 252c593315Sopenharmony_ci#ifndef TLS_H 262c593315Sopenharmony_ci#define TLS_H 272c593315Sopenharmony_ci 282c593315Sopenharmony_ci#include "nghttp2_config.h" 292c593315Sopenharmony_ci 302c593315Sopenharmony_ci#include <cinttypes> 312c593315Sopenharmony_ci 322c593315Sopenharmony_ci#include <openssl/ssl.h> 332c593315Sopenharmony_ci 342c593315Sopenharmony_ci#include "ssl_compat.h" 352c593315Sopenharmony_ci 362c593315Sopenharmony_cinamespace nghttp2 { 372c593315Sopenharmony_ci 382c593315Sopenharmony_cinamespace tls { 392c593315Sopenharmony_ci 402c593315Sopenharmony_ci// Acquire OpenSSL global lock to share SSL_CTX across multiple 412c593315Sopenharmony_ci// threads. The constructor acquires lock and destructor unlocks. 422c593315Sopenharmony_ciclass LibsslGlobalLock { 432c593315Sopenharmony_cipublic: 442c593315Sopenharmony_ci LibsslGlobalLock(); 452c593315Sopenharmony_ci LibsslGlobalLock(const LibsslGlobalLock &) = delete; 462c593315Sopenharmony_ci LibsslGlobalLock &operator=(const LibsslGlobalLock &) = delete; 472c593315Sopenharmony_ci}; 482c593315Sopenharmony_ci 492c593315Sopenharmony_ci// Recommended general purpose "Intermediate compatibility" cipher 502c593315Sopenharmony_ci// suites for TLSv1.2 by mozilla. 512c593315Sopenharmony_ci// 522c593315Sopenharmony_ci// https://wiki.mozilla.org/Security/Server_Side_TLS 532c593315Sopenharmony_ciconstexpr char DEFAULT_CIPHER_LIST[] = 542c593315Sopenharmony_ci "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-" 552c593315Sopenharmony_ci "AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-" 562c593315Sopenharmony_ci "POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-" 572c593315Sopenharmony_ci "AES256-GCM-SHA384"; 582c593315Sopenharmony_ci 592c593315Sopenharmony_ci// Recommended general purpose "Modern compatibility" cipher suites 602c593315Sopenharmony_ci// for TLSv1.3 by mozilla. 612c593315Sopenharmony_ci// 622c593315Sopenharmony_ci// https://wiki.mozilla.org/Security/Server_Side_TLS 632c593315Sopenharmony_ciconstexpr char DEFAULT_TLS13_CIPHER_LIST[] = 642c593315Sopenharmony_ci#if OPENSSL_1_1_1_API && !defined(OPENSSL_IS_BORINGSSL) 652c593315Sopenharmony_ci "TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256" 662c593315Sopenharmony_ci#else 672c593315Sopenharmony_ci "" 682c593315Sopenharmony_ci#endif 692c593315Sopenharmony_ci ; 702c593315Sopenharmony_ci 712c593315Sopenharmony_ciconstexpr auto NGHTTP2_TLS_MIN_VERSION = TLS1_VERSION; 722c593315Sopenharmony_ci#ifdef TLS1_3_VERSION 732c593315Sopenharmony_ciconstexpr auto NGHTTP2_TLS_MAX_VERSION = TLS1_3_VERSION; 742c593315Sopenharmony_ci#else // !TLS1_3_VERSION 752c593315Sopenharmony_ciconstexpr auto NGHTTP2_TLS_MAX_VERSION = TLS1_2_VERSION; 762c593315Sopenharmony_ci#endif // !TLS1_3_VERSION 772c593315Sopenharmony_ci 782c593315Sopenharmony_ciconst char *get_tls_protocol(SSL *ssl); 792c593315Sopenharmony_ci 802c593315Sopenharmony_cistruct TLSSessionInfo { 812c593315Sopenharmony_ci const char *cipher; 822c593315Sopenharmony_ci const char *protocol; 832c593315Sopenharmony_ci const uint8_t *session_id; 842c593315Sopenharmony_ci bool session_reused; 852c593315Sopenharmony_ci size_t session_id_length; 862c593315Sopenharmony_ci}; 872c593315Sopenharmony_ci 882c593315Sopenharmony_ciTLSSessionInfo *get_tls_session_info(TLSSessionInfo *tls_info, SSL *ssl); 892c593315Sopenharmony_ci 902c593315Sopenharmony_ci// Returns true iff the negotiated protocol is TLSv1.2. 912c593315Sopenharmony_cibool check_http2_tls_version(SSL *ssl); 922c593315Sopenharmony_ci 932c593315Sopenharmony_ci// Returns true iff the negotiated cipher suite is in HTTP/2 cipher 942c593315Sopenharmony_ci// block list. 952c593315Sopenharmony_cibool check_http2_cipher_block_list(SSL *ssl); 962c593315Sopenharmony_ci 972c593315Sopenharmony_ci// Returns true if SSL/TLS requirement for HTTP/2 is fulfilled. 982c593315Sopenharmony_ci// To fulfill the requirement, the following 2 terms must be hold: 992c593315Sopenharmony_ci// 1002c593315Sopenharmony_ci// 1. The negotiated protocol must be TLSv1.2. 1012c593315Sopenharmony_ci// 2. The negotiated cipher cuite is not listed in the block list 1022c593315Sopenharmony_ci// described in RFC 7540. 1032c593315Sopenharmony_cibool check_http2_requirement(SSL *ssl); 1042c593315Sopenharmony_ci 1052c593315Sopenharmony_ci// Initializes OpenSSL library 1062c593315Sopenharmony_civoid libssl_init(); 1072c593315Sopenharmony_ci 1082c593315Sopenharmony_ci// Sets TLS min and max versions to |ssl_ctx|. This function returns 1092c593315Sopenharmony_ci// 0 if it succeeds, or -1. 1102c593315Sopenharmony_ciint ssl_ctx_set_proto_versions(SSL_CTX *ssl_ctx, int min, int max); 1112c593315Sopenharmony_ci 1122c593315Sopenharmony_ci} // namespace tls 1132c593315Sopenharmony_ci 1142c593315Sopenharmony_ci} // namespace nghttp2 1152c593315Sopenharmony_ci 1162c593315Sopenharmony_ci#endif // TLS_H 117