File tree Expand file tree Collapse file tree
tests/examples/ngtcp2-openssl Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -184,6 +184,7 @@ members = [
184184 " tests/examples/nghttp2" ,
185185 " tests/examples/nghttp3" ,
186186 " tests/examples/ngtcp2" ,
187+ " tests/examples/ngtcp2-openssl" ,
187188 " tests/examples/openblas" ,
188189 " tests/examples/openmp" ,
189190 " tests/examples/openssl" ,
Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ package = {
4646 include_dirs = {
4747 " */lib/includes" ,
4848 " */crypto/includes" ,
49+ " */lib" ,
50+ " */crypto" ,
4951 " mcpp_generated/include" ,
5052 " mcpp_generated" ,
5153 },
@@ -92,6 +94,11 @@ package = {
9294 features = {
9395 [" default" ] = { implies = { " staticlib" } },
9496 [" staticlib" ] = { defines = { " NGTCP2_STATICLIB" } },
97+ [" openssl" ] = {
98+ implies = { " staticlib" },
99+ sources = { " */crypto/shared.c" , " */crypto/ossl/ossl.c" },
100+ deps = { [" compat.openssl" ] = " 3.5.9" },
101+ },
95102 },
96103 targets = { [" ngtcp2" ] = { kind = " lib" } },
97104 deps = {},
Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " ngtcp2-openssl-tests"
3+ version = " 0.1.0"
4+
5+ [dependencies .compat ]
6+ ngtcp2 = { version = " 1.26.0" , features = [" openssl" ] }
7+
8+ [indices ]
9+ compat = { path = " ../../.." }
Original file line number Diff line number Diff line change 1+ #include < ngtcp2/ngtcp2_crypto_ossl.h>
2+ #include < openssl/ssl.h>
3+
4+ #include < memory>
5+
6+ // 同时建立客户端和服务端 TLS 会话,验证静态库的后端符号和 OpenSSL 传递依赖
7+ int main () {
8+ if (ngtcp2_crypto_ossl_init () != 0 ) return 1 ;
9+ std::unique_ptr<SSL_CTX , decltype (&SSL_CTX_free)> factory (SSL_CTX_new (TLS_method ()), SSL_CTX_free);
10+ if (!factory) return 2 ;
11+ for (bool server : {false , true }) {
12+ std::unique_ptr<SSL , decltype (&SSL_free)> tls (SSL_new (factory.get ()), SSL_free);
13+ if (!tls) return 3 ;
14+ ngtcp2_crypto_ossl_ctx* raw = nullptr ;
15+ if (ngtcp2_crypto_ossl_ctx_new (&raw, tls.get ()) != 0 ) return 4 ;
16+ std::unique_ptr<ngtcp2_crypto_ossl_ctx, decltype (&ngtcp2_crypto_ossl_ctx_del)> session (raw, ngtcp2_crypto_ossl_ctx_del);
17+ if (ngtcp2_crypto_ossl_ctx_get_ssl (session.get ()) != tls.get ()) return 5 ;
18+ auto status = server ? ngtcp2_crypto_ossl_configure_server_session (tls.get ())
19+ : ngtcp2_crypto_ossl_configure_client_session (tls.get ());
20+ if (status != 0 ) return 6 ;
21+ }
22+ ngtcp2_crypto_ossl_free ();
23+ return 0 ;
24+ }
You can’t perform that action at this time.
0 commit comments