Welcome! Log In Create A New Profile

Advanced

[nginx] SSL: added $ssl_alpn_protocol variable.

Vladimir Homutov
October 20, 2021 01:28PM
details: https://hg.nginx.org/nginx/rev/eb6c77e6d55d
branches:
changeset: 7935:eb6c77e6d55d
user: Vladimir Homutov <vl@nginx.com>
date: Thu Oct 14 11:46:23 2021 +0300
description:
SSL: added $ssl_alpn_protocol variable.

The variable contains protocol selected by ALPN during handshake and
is empty otherwise.

diffstat:

src/event/ngx_event_openssl.c | 30 ++++++++++++++++++++++++++++++
src/event/ngx_event_openssl.h | 2 ++
src/http/modules/ngx_http_ssl_module.c | 3 +++
src/stream/ngx_stream_ssl_module.c | 3 +++
4 files changed, 38 insertions(+), 0 deletions(-)

diffs (78 lines):

diff -r 61abb35bb8cf -r eb6c77e6d55d src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c Fri Oct 15 10:02:15 2021 +0300
+++ b/src/event/ngx_event_openssl.c Thu Oct 14 11:46:23 2021 +0300
@@ -4699,6 +4699,36 @@ ngx_ssl_get_server_name(ngx_connection_t


ngx_int_t
+ngx_ssl_get_alpn_protocol(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
+{
+#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
+
+ unsigned int len;
+ const unsigned char *data;
+
+ SSL_get0_alpn_selected(c->ssl->connection, &data, &len);
+
+ if (len > 0) {
+
+ s->data = ngx_pnalloc(pool, len);
+ if (s->data == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_memcpy(s->data, data, len);
+ s->len = len;
+
+ return NGX_OK;
+ }
+
+#endif
+
+ s->len = 0;
+ return NGX_OK;
+}
+
+
+ngx_int_t
ngx_ssl_get_raw_certificate(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
{
size_t len;
diff -r 61abb35bb8cf -r eb6c77e6d55d src/event/ngx_event_openssl.h
--- a/src/event/ngx_event_openssl.h Fri Oct 15 10:02:15 2021 +0300
+++ b/src/event/ngx_event_openssl.h Thu Oct 14 11:46:23 2021 +0300
@@ -265,6 +265,8 @@ ngx_int_t ngx_ssl_get_early_data(ngx_con
ngx_str_t *s);
ngx_int_t ngx_ssl_get_server_name(ngx_connection_t *c, ngx_pool_t *pool,
ngx_str_t *s);
+ngx_int_t ngx_ssl_get_alpn_protocol(ngx_connection_t *c, ngx_pool_t *pool,
+ ngx_str_t *s);
ngx_int_t ngx_ssl_get_raw_certificate(ngx_connection_t *c, ngx_pool_t *pool,
ngx_str_t *s);
ngx_int_t ngx_ssl_get_certificate(ngx_connection_t *c, ngx_pool_t *pool,
diff -r 61abb35bb8cf -r eb6c77e6d55d src/http/modules/ngx_http_ssl_module.c
--- a/src/http/modules/ngx_http_ssl_module.c Fri Oct 15 10:02:15 2021 +0300
+++ b/src/http/modules/ngx_http_ssl_module.c Thu Oct 14 11:46:23 2021 +0300
@@ -358,6 +358,9 @@ static ngx_http_variable_t ngx_http_ssl
{ ngx_string("ssl_server_name"), NULL, ngx_http_ssl_variable,
(uintptr_t) ngx_ssl_get_server_name, NGX_HTTP_VAR_CHANGEABLE, 0 },

+ { ngx_string("ssl_alpn_protocol"), NULL, ngx_http_ssl_variable,
+ (uintptr_t) ngx_ssl_get_alpn_protocol, NGX_HTTP_VAR_CHANGEABLE, 0 },
+
{ ngx_string("ssl_client_cert"), NULL, ngx_http_ssl_variable,
(uintptr_t) ngx_ssl_get_certificate, NGX_HTTP_VAR_CHANGEABLE, 0 },

diff -r 61abb35bb8cf -r eb6c77e6d55d src/stream/ngx_stream_ssl_module.c
--- a/src/stream/ngx_stream_ssl_module.c Fri Oct 15 10:02:15 2021 +0300
+++ b/src/stream/ngx_stream_ssl_module.c Thu Oct 14 11:46:23 2021 +0300
@@ -266,6 +266,9 @@ static ngx_stream_variable_t ngx_stream
{ ngx_string("ssl_server_name"), NULL, ngx_stream_ssl_variable,
(uintptr_t) ngx_ssl_get_server_name, NGX_STREAM_VAR_CHANGEABLE, 0 },

+ { ngx_string("ssl_alpn_protocol"), NULL, ngx_stream_ssl_variable,
+ (uintptr_t) ngx_ssl_get_alpn_protocol, NGX_STREAM_VAR_CHANGEABLE, 0 },
+
{ ngx_string("ssl_client_cert"), NULL, ngx_stream_ssl_variable,
(uintptr_t) ngx_ssl_get_certificate, NGX_STREAM_VAR_CHANGEABLE, 0 },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] SSL: added $ssl_alpn_protocol variable.

Vladimir Homutov 304 October 20, 2021 01:28PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 302
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready