Skip to content

[skip ci] ngx_http_lua_ffi_ssl_get_client_hello_ciphers() #2415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/ngx_http_lua_ssl_client_helloby.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,60 @@ ngx_http_lua_ffi_ssl_get_client_hello_ext_present(ngx_http_request_t *r,
}


int ngx_http_lua_ffi_ssl_get_client_hello_ciphers(ngx_http_request_t *r,
unsigned short **ciphers, size_t *cipherslen, char **err)
{
ngx_ssl_conn_t *ssl_conn;
size_t ciphersuites_length;
const unsigned char *ciphers_raw;


if (r->connection == NULL || r->connection->ssl == NULL) {
*err = "bad request";
return NGX_ERROR;
}

ssl_conn = r->connection->ssl->connection;
if (ssl_conn == NULL) {
*err = "bad ssl conn";
return NGX_ERROR;
}

#ifdef SSL_ERROR_WANT_CLIENT_HELLO_CB
ciphersuites_length = SSL_client_hello_get0_ciphers(ssl_conn, &ciphers_raw);

if (!ciphersuites_length) {
*err = "failed SSL_client_hello_get0_ciphers()";
return NGX_DECLINED;
}

if (ciphersuites_length %2 != 0) {
*err = "SSL_client_hello_get0_ciphers() odd ciphersuites_length";
return NGX_DECLINED;
}

*cipherslen = ciphersuites_length / 2;

*ciphers = ngx_palloc(r->connection->pool, sizeof(int) * (*cipherslen));
if (*ciphers == NULL) {
*err = "failed to ngx_palloc() for the ciphers' array";
return NGX_ERROR;
}

for (int i = 0 ; i < *cipherslen ; i++) {
uint16_t cipher = (ciphers_raw[i*2] << 8) | ciphers_raw[i*2 + 1];

(*ciphers)[i] = cipher;
}

return NGX_OK;
#else
*err = "OpenSSL too old to support this function";
return NGX_ERROR;
#endif
}


int
ngx_http_lua_ffi_ssl_set_protocols(ngx_http_request_t *r,
int protocols, char **err)
Expand Down
Loading