From 0232fb014b5e450eafa42ab7683e4f80274f25fa Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> Date: Mon, 14 Oct 2019 11:20:07 +0900 Subject: [PATCH] Define openssl specific error codes in ngtcp2_crypto_openssl.h --- crypto/includes/CMakeLists.txt | 6 ++++ crypto/includes/Makefile.am | 4 +++ crypto/includes/ngtcp2/ngtcp2_crypto.h | 15 +++----- .../includes/ngtcp2/ngtcp2_crypto_openssl.h | 34 +++++++++++++++++++ crypto/openssl/openssl.c | 1 + 5 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h diff --git a/crypto/includes/CMakeLists.txt b/crypto/includes/CMakeLists.txt index 87d97b3d..aaa85fb4 100644 --- a/crypto/includes/CMakeLists.txt +++ b/crypto/includes/CMakeLists.txt @@ -24,3 +24,9 @@ install(FILES ngtcp2/ngtcp2_crypto.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ngtcp2") + +if(OPENSSL_FOUND) + install(FILES + ngtcp2/ngtcp2_crypto_openssl.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ngtcp2") +endif() diff --git a/crypto/includes/Makefile.am b/crypto/includes/Makefile.am index 5f45e598..7e0589a3 100644 --- a/crypto/includes/Makefile.am +++ b/crypto/includes/Makefile.am @@ -22,3 +22,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. nobase_include_HEADERS = ngtcp2/ngtcp2_crypto.h + +if HAVE_OPENSSL +nobase_include_HEADERS += ngtcp2/ngtcp2_crypto_openssl.h +endif diff --git a/crypto/includes/ngtcp2/ngtcp2_crypto.h b/crypto/includes/ngtcp2/ngtcp2_crypto.h index ad10ea9b..d22daef4 100644 --- a/crypto/includes/ngtcp2/ngtcp2_crypto.h +++ b/crypto/includes/ngtcp2/ngtcp2_crypto.h @@ -35,15 +35,6 @@ extern "C" { #define NGTCP2_CRYPTO_INITIAL_KEYLEN 16 #define NGTCP2_CRYPTO_INITIAL_IVLEN 12 -#if defined(__cplusplus) && __cplusplus >= 201103L -typedef enum ngtcp2_crypto_lib_error : int { -#else -typedef enum ngtcp2_crypto_lib_error { -#endif - NGTCP2_CRYPTO_ERR_TLS_WANT_X509_LOOKUP = -301, - NGTCP2_CRYPTO_ERR_TLS_WANT_CLIENT_HELLO_CB = -302, -} ngtcp2_crypto_lib_error; - /** * @function * @@ -491,7 +482,11 @@ NGTCP2_EXTERN int ngtcp2_crypto_update_and_install_key( * libngtcp2_crypto_openssl is linked, |tls| must be a pointer to SSL * object. * - * This function returns 0 if it succeeds, or -1. + * This function returns 0 if it succeeds, or a negative error code. + * The generic error code is -1 if a specific error code is not + * suitable. The error codes less than -10000 are specific to + * underlying TLS implementation. For OpenSSL, the error codes are + * defined in ngtcp2_crypto_openssl.h. */ NGTCP2_EXTERN int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn, void *tls, diff --git a/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h b/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h new file mode 100644 index 00000000..7ccb383e --- /dev/null +++ b/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h @@ -0,0 +1,34 @@ +/* + * ngtcp2 + * + * Copyright (c) 2019 ngtcp2 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef NGTCP2_CRYPTO_OPENSSL_H +#define NGTCP2_CRYPTO_OPENSSL_H + +#include <ngtcp2/ngtcp2.h> + +/* OpenSSL specific error codes */ +#define NGTCP2_CRYPTO_ERR_TLS_WANT_X509_LOOKUP -10001 +#define NGTCP2_CRYPTO_ERR_TLS_WANT_CLIENT_HELLO_CB -10002 + +#endif /* NGTCP2_CRYPTO_OPENSSL_H */ diff --git a/crypto/openssl/openssl.c b/crypto/openssl/openssl.c index b1c8be54..890bf0c8 100644 --- a/crypto/openssl/openssl.c +++ b/crypto/openssl/openssl.c @@ -29,6 +29,7 @@ #include <assert.h> #include <ngtcp2/ngtcp2_crypto.h> +#include <ngtcp2/ngtcp2_crypto_openssl.h> #include <openssl/ssl.h> #include <openssl/evp.h> -- GitLab