Skip to content

Commit d1d5b73

Browse files
authored
feature: added ngx_http_lua_ffi_ssl_get_client_hello_ext_present().
1 parent 0581262 commit d1d5b73

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/ngx_http_lua_ssl_client_helloby.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,51 @@ ngx_http_lua_ffi_ssl_get_client_hello_ext(ngx_http_request_t *r,
662662
}
663663

664664

665+
int
666+
ngx_http_lua_ffi_ssl_get_client_hello_ext_present(ngx_http_request_t *r,
667+
int **extensions, size_t *extensions_len, char **err)
668+
{
669+
ngx_ssl_conn_t *ssl_conn;
670+
int got_extensions;
671+
size_t ext_len;
672+
int *ext_out;
673+
/* OPENSSL will allocate memory for us and make the ext_out point to it */
674+
675+
676+
if (r->connection == NULL || r->connection->ssl == NULL) {
677+
*err = "bad request";
678+
return NGX_ERROR;
679+
}
680+
681+
ssl_conn = r->connection->ssl->connection;
682+
if (ssl_conn == NULL) {
683+
*err = "bad ssl conn";
684+
return NGX_ERROR;
685+
}
686+
687+
#ifdef SSL_ERROR_WANT_CLIENT_HELLO_CB
688+
got_extensions = SSL_client_hello_get1_extensions_present(ssl_conn,
689+
&ext_out, &ext_len);
690+
if (!got_extensions || !ext_out || !ext_len) {
691+
*err = "failed SSL_client_hello_get1_extensions_present()";
692+
return NGX_DECLINED;
693+
}
694+
695+
*extensions = ngx_palloc(r->connection->pool, sizeof(int) * ext_len);
696+
if (*extensions != NULL) {
697+
ngx_memcpy(*extensions, ext_out, sizeof(int) * ext_len);
698+
*extensions_len = ext_len;
699+
}
700+
701+
OPENSSL_free(ext_out);
702+
return NGX_OK;
703+
#else
704+
*err = "OpenSSL too old to support this function";
705+
return NGX_ERROR;
706+
#endif
707+
}
708+
709+
665710
int
666711
ngx_http_lua_ffi_ssl_set_protocols(ngx_http_request_t *r,
667712
int protocols, char **err)

0 commit comments

Comments
 (0)