Skip to content

Commit dbd9812

Browse files
call ngx_ssl_get_ciphers instead.
1 parent 6c3f3f0 commit dbd9812

File tree

1 file changed

+8
-86
lines changed

1 file changed

+8
-86
lines changed

src/ngx_http_lua_ssl_certby.c

Lines changed: 8 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -965,102 +965,24 @@ int
965965
ngx_http_lua_ffi_ssl_ciphers(ngx_http_request_t *r, char **pciphers,
966966
size_t *cipherslen, char **err)
967967
{
968-
ngx_pool_t *pool;
969-
ngx_ssl_conn_t *ssl_conn;
968+
ngx_int_t rc;
969+
ngx_str_t ciphers;
970970
ngx_connection_t *c;
971971

972-
if (r->connection == NULL || r->connection->ssl == NULL) {
972+
c = r->connection;
973+
if (c == NULL || c->ssl == NULL) {
973974
*err = "bad request";
974975
return NGX_ERROR;
975976
}
976977

977-
ssl_conn = r->connection->ssl->connection;
978-
if (ssl_conn == NULL) {
979-
*err = "bad ssl conn";
980-
return NGX_ERROR;
981-
}
982-
983-
pool = r->pool;
984-
c = ngx_ssl_get_connection(ssl_conn);
985-
986-
#ifdef SSL_CTRL_GET_RAW_CIPHERLIST
987-
988-
int n, i, bytes;
989-
size_t len;
990-
u_char *ciphers, *p;
991-
const SSL_CIPHER *cipher;
992-
993-
bytes = SSL_get0_raw_cipherlist(c->ssl->connection, NULL);
994-
n = SSL_get0_raw_cipherlist(c->ssl->connection, &ciphers);
995-
996-
if (n <= 0) {
997-
*cipherslen = 0;
998-
return NGX_OK;
999-
}
1000-
1001-
len = 0;
1002-
n /= bytes;
1003-
1004-
for (i = 0; i < n; i++) {
1005-
cipher = SSL_CIPHER_find(c->ssl->connection, ciphers + i * bytes);
1006-
1007-
if (cipher) {
1008-
len += ngx_strlen(SSL_CIPHER_get_name(cipher));
1009-
1010-
} else {
1011-
len += sizeof("0x") - 1 + bytes * (sizeof("00") - 1);
1012-
}
1013-
1014-
len += sizeof(":") - 1;
1015-
}
1016-
1017-
*pciphers = ngx_pnalloc(pool, len);
1018-
if (*pciphers == NULL) {
1019-
*err = "no memory";
1020-
return NGX_ERROR;
1021-
}
1022-
1023-
p = (u_char *) *pciphers;
1024-
1025-
for (i = 0; i < n; i++) {
1026-
cipher = SSL_CIPHER_find(c->ssl->connection, ciphers + i * bytes);
1027-
1028-
if (cipher) {
1029-
p = ngx_sprintf(p, "%s", SSL_CIPHER_get_name(cipher));
1030-
1031-
} else {
1032-
p = ngx_sprintf(p, "0x");
1033-
p = ngx_hex_dump(p, ciphers + i * bytes, bytes);
1034-
}
1035-
1036-
*p++ = ':';
1037-
}
1038-
1039-
p--;
1040-
1041-
*cipherslen = p - (u_char *) *pciphers;
1042-
1043-
#else
1044-
1045-
u_char buf[4096];
1046-
1047-
if (SSL_get_shared_ciphers(c->ssl->connection, (char *) buf, 4096)
1048-
== NULL)
1049-
{
1050-
*cipherslen = 0;
1051-
return NGX_OK;
1052-
}
1053-
1054-
*cipherslen = ngx_strlen(buf);
1055-
*pciphers = ngx_pnalloc(pool, *cipherslen);
1056-
if (*pciphers == NULL) {
978+
rc = ngx_ssl_get_ciphers(c, r->pool, &ciphers);
979+
if (rc != NGX_OK) {
1057980
*err = "no memory";
1058981
return NGX_ERROR;
1059982
}
1060983

1061-
ngx_memcpy(*pciphers, buf, *cipherslen);
1062-
1063-
#endif
984+
*pciphers = (char *) ciphers.data;
985+
*cipherslen = ciphers.len;
1064986

1065987
return NGX_OK;
1066988
}

0 commit comments

Comments
 (0)