Skip to content

Commit

Permalink
Merge pull request #7 from githubtaotao/main
Browse files Browse the repository at this point in the history
use max supported version instead of client version
  • Loading branch information
ThatcherT authored Nov 15, 2024
2 parents 7d71deb + a58c6f8 commit 892cc6e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
56 changes: 32 additions & 24 deletions src/ngx_http_ssl_ja4_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,36 +114,44 @@ int ngx_ssl_ja4(ngx_connection_t *c, ngx_pool_t *pool, ngx_ssl_ja4_t *ja4)

/* SSLVersion*/
// get string version:
const char *version_str = SSL_get_version(ssl);
int client_version_int = SSL_client_version(ssl);
int max_version_int = SSL_get_max_proto_version(ssl);
int version_int = 0;

if (strcmp(version_str, SSL3_VERSION_STR) == 0)
if (max_version_int > client_version_int)
{
ja4->version = "s3";
}
else if (strcmp(version_str, TLS1_VERSION_STR) == 0)
{
ja4->version = "10";
}
else if (strcmp(version_str, TLS1_1_VERSION_STR) == 0)
{
ja4->version = "11";
}
else if (strcmp(version_str, TLS1_2_VERSION_STR) == 0)
{
ja4->version = "12";
}
else if (strcmp(version_str, TLS1_3_VERSION_STR) == 0)
{
ja4->version = "13";
}
else if (strcmp(version_str, QUICV1_VERSION_STR) == 0)
{
ja4->version = "q1";
version_int = max_version_int;
}
else
{
ja4->version = "00"; // Unknown or unhandled version
version_int = client_version_int;
}

switch(version_int)
{
case SSL3_VERSION_INT:
ja4->version = "s3";
break;
case TLS1_VERSION_INT:
ja4->version = "10";
break;
case TLS1_1_VERSION_INT:
ja4->version = "11";
break;
case TLS1_2_VERSION_INT:
ja4->version = "12";
break;
case TLS1_3_VERSION_INT:
ja4->version = "13";
break;
case QUICV1_VERSION_INT:
ja4->version = "q1";
break;
default:
ja4->version = "00";
break;
}

/* Cipher suites */
ja4->ciphers = NULL;
ja4->ciphers_sz = 0;
Expand Down
17 changes: 9 additions & 8 deletions src/ngx_http_ssl_ja4_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,15 @@ typedef struct ngx_ssl_ja4l_s
} ngx_ssl_ja4l_t;

// CONSTANTS
#define SSL3_VERSION_STR "SSLv3"
#define TLS1_VERSION_STR "TLSv1"
#define TLS1_1_VERSION_STR "TLSv1.1"
#define TLS1_2_VERSION_STR "TLSv1.2"
#define TLS1_3_VERSION_STR "TLSv1.3"
#define DTLS1_VERSION_STR "DTLSv1"
#define DTLS1_2_VERSION_STR "DTLSv1.2"
#define QUICV1_VERSION_STR "QUICv1"
#define SSL3_VERSION_INT 0x0300
#define TLS1_VERSION_INT 0x0301
#define TLS1_1_VERSION_INT 0x0302
#define TLS1_2_VERSION_INT 0x0303
#define TLS1_3_VERSION_INT 0x0304
#define DTLS1_VERSION_INT 0xFEFF
#define DTLS1_2_VERSION_INT 0xFEFD
#define QUICV1_VERSION_INT 0x0001


/**
* Grease values to be ignored.
Expand Down

0 comments on commit 892cc6e

Please sign in to comment.