Skip to content

Commit 07885b1

Browse files
committed
nginx-ssl-ja3: grease ciphers
1 parent 2b63fa7 commit 07885b1

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/ngx_ssl_ja3.c

+16-13
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ ngx_ssl_ja3_detail_print(ngx_pool_t *pool, ngx_ssl_ja3_t *ja3)
180180
void
181181
ngx_ssl_ja3_fp(ngx_pool_t *pool, ngx_ssl_ja3_t *ja3, ngx_str_t *out)
182182
{
183-
size_t len = 0, cur = 0;
183+
size_t len = 0, cur = 0, added = 0;
184+
unsigned short us = 0;
184185

185186
if (pool == NULL || ja3 == NULL || out == NULL) {
186187
return;
@@ -229,12 +230,18 @@ ngx_ssl_ja3_fp(ngx_pool_t *pool, ngx_ssl_ja3_t *ja3, ngx_str_t *out)
229230

230231
if (ja3->ciphers_sz) {
231232
for (size_t i = 0; i < ja3->ciphers_sz; ++i) {
232-
if (i > 0) {
233-
ngx_snprintf(out->data + (cur++), 1, "-");
233+
us = ntohs(ja3->ciphers[i]);
234+
if (!ngx_ssl_ja3_is_ext_greased(us)) {
235+
if (added > 0) {
236+
ngx_snprintf(out->data + (cur++), 1, "-");
237+
}
238+
len = ngx_ssj_ja3_num_digits(us);
239+
ngx_snprintf(out->data + cur, len, "%d", us);
240+
cur += len;
241+
if (added == 0) {
242+
added = 1;
243+
}
234244
}
235-
len = ngx_ssj_ja3_num_digits(ja3->ciphers[i]);
236-
ngx_snprintf(out->data + cur, len, "%d", ja3->ciphers[i]);
237-
cur += len;
238245
}
239246
}
240247
ngx_snprintf(out->data + (cur++), 1, ",");
@@ -297,6 +304,7 @@ ngx_ssl_ja3(ngx_connection_t *c, ngx_pool_t *pool, ngx_ssl_ja3_t *ja3) {
297304
int *curves_out = NULL;
298305
int *point_formats_out = NULL;
299306
size_t len = 0;
307+
unsigned short us = 0;
300308

301309
if (! c->ssl) {
302310
return NGX_DECLINED;
@@ -330,13 +338,7 @@ ngx_ssl_ja3(ngx_connection_t *c, ngx_pool_t *pool, ngx_ssl_ja3_t *ja3) {
330338
if (ja3->ciphers == NULL) {
331339
return NGX_DECLINED;
332340
}
333-
334341
ngx_memcpy(ja3->ciphers, ciphers_out, len);
335-
#if NGX_HAVE_LITTLE_ENDIAN
336-
for (size_t i = 0; i < ja3->ciphers_sz; ++i) {
337-
ja3->ciphers[i] = (ja3->ciphers[i] >> 8) | (ja3->ciphers[i] << 8);
338-
}
339-
#endif
340342
}
341343

342344
/* Extensions */
@@ -349,7 +351,8 @@ ngx_ssl_ja3(ngx_connection_t *c, ngx_pool_t *pool, ngx_ssl_ja3_t *ja3) {
349351
return NGX_DECLINED;
350352
}
351353
for (size_t i = 0; i < c->ssl->client_extensions_size; ++i) {
352-
if (! ngx_ssl_ja3_is_ext_greased(c->ssl->client_extensions[i])) {
354+
us = ntohs(c->ssl->client_extensions[i]);
355+
if (! ngx_ssl_ja3_is_ext_greased(us)) {
353356
ja3->extensions[ja3->extensions_sz++] =
354357
c->ssl->client_extensions[i];
355358
}

0 commit comments

Comments
 (0)