Skip to content

Commit

Permalink
Fixes non-ascii ALPN values (#37)
Browse files Browse the repository at this point in the history
* fix for issue #21, original order

* fix for issue #30 ALPN values

* fix for issue #16
  • Loading branch information
noeltimothy authored Dec 20, 2023
1 parent 5032e48 commit 2636182
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions python/ja4.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,15 @@ def to_ja4s(x, debug_stream):
version = TLS_MAPPER[x['version']] if x['version'] in TLS_MAPPER else '00'

alpn = '00'
if 'alpn' in x:
alpn = x['alpn']
elif 'alpn_list' in x:
if 'alpn_list' in x:
if isinstance(x['alpn_list'], list):
alpn = x['alpn_list'][0]
else:
alpn = x['alpn_list']
if len(alpn) > 2:
alpn = f"{alpn[0]}{alpn[-1]}"
if ord(alpn[0]) > 127:
alpn = '99'

x['JA4S'] = f"{ptype}{version}{ext_len}{alpn}_{x['ciphers']}_{extensions}"
x['JA4S_r'] = f"{ptype}{version}{ext_len}{alpn}_{x['ciphers']}_{','.join(x['extensions'])}"
Expand Down Expand Up @@ -232,14 +234,18 @@ def to_ja4(x, debug_stream):
version = TLS_MAPPER[x['version']] if x['version'] in TLS_MAPPER else '00'

alpn = '00'
if 'alpn' in x:
alpn = x['alpn']
elif 'alpn_list' in x:
if 'alpn_list' in x:
if isinstance(x['alpn_list'], list):
alpn = x['alpn_list'][0]
else:
alpn = x['alpn_list']

if len(alpn) > 2:
alpn = f"{alpn[0]}{alpn[-1]}"

if ord(alpn[0]) > 127:
alpn = '99'

x['JA4'] = f"{ptype}{version}{sni}{cipher_len}{ext_len}{alpn}_{sorted_ciphers}_{sorted_extensions}"
x['JA4_o'] = f"{ptype}{version}{sni}{cipher_len}{ext_len}{alpn}_{original_ciphers}_{original_extensions}"
x['JA4_r'] = f"{ptype}{version}{sni}{cipher_len}{ext_len}{alpn}_{x['sorted_ciphers']}_{x['sorted_extensions']}"
Expand Down

0 comments on commit 2636182

Please sign in to comment.