-
Notifications
You must be signed in to change notification settings - Fork 855
Refactor jax_fingerprint plugin for better modularity and fewer allocations #13072
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7e610c7
jax: Refactor code ja4 and ja4h
maskit b05a4e7
Rename
maskit fdca4bc
Clean up namespaces
maskit 4d21aaa
Add license header
maskit aad8e18
Fix typo
maskit f79ca4e
Include header files
maskit 62c8dd0
Fix the count of ciphers and extensions
maskit c794576
Replace assertions with real error handling
maskit 2740aef
Check buffer length carefully
maskit 573fa64
Include header
maskit 267f6d6
Include header
maskit 65c3bb6
Fix length comparison
maskit a1a594b
Fix comments
maskit b4ca071
Remove empty anonymous namespace
maskit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ | |
|
|
||
| #include <method.h> | ||
|
|
||
| namespace ja4_method | ||
| namespace ja3 | ||
| { | ||
|
|
||
| extern struct Method method; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
| */ | ||
|
|
||
| #include "ja3_utils.h" | ||
| #include "utils.h" | ||
|
|
||
| #include <catch2/catch_test_macros.hpp> | ||
|
|
||
|
|
||
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /** @file | ||
|
|
||
| @section license License | ||
|
|
||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| #include "datasource.h" | ||
|
|
||
| #include <array> | ||
| #include <algorithm> | ||
|
|
||
| constexpr std::array<std::uint16_t, 16> GREASE_values{0x0a0a, 0x1a1a, 0x2a2a, 0x3a3a, 0x4a4a, 0x5a5a, 0x6a6a, 0x7a7a, | ||
| 0x8a8a, 0x9a9a, 0xaaaa, 0xbaba, 0xcaca, 0xdada, 0xeaea, 0xfafa}; | ||
|
|
||
| ja4::Datasource::Protocol | ||
| ja4::Datasource::get_protocol() | ||
| { | ||
| return this->_protocol; | ||
| } | ||
|
|
||
| int | ||
| ja4::Datasource::get_version() | ||
| { | ||
| return this->_version; | ||
| } | ||
|
|
||
| ja4::Datasource::SNI | ||
| ja4::Datasource::get_sni_type() | ||
| { | ||
| return this->_has_SNI ? ja4::Datasource::SNI::to_domain : ja4::Datasource::SNI::to_IP; | ||
| } | ||
|
|
||
| int | ||
| ja4::Datasource::get_cipher_count() | ||
| { | ||
| return this->_n_ciphers; | ||
| } | ||
|
|
||
| int | ||
| ja4::Datasource::get_extension_count() | ||
| { | ||
| return this->_n_extensions + (this->_has_ALPN ? 1 : 0) + (this->_has_SNI ? 1 : 0); | ||
| } | ||
|
|
||
| /** | ||
| * Check whether @a value is a GREASE value. | ||
| * | ||
| * These are reserved extensions randomly advertised to keep implementations | ||
| * well lubricated. They are ignored in all parts of JA4 because of their | ||
| * random nature. | ||
| * | ||
| * @return Returns true if the value is a GREASE value, false otherwise. | ||
| */ | ||
| bool | ||
| ja4::Datasource::_is_GREASE(uint16_t value) | ||
| { | ||
| return std::binary_search(GREASE_values.begin(), GREASE_values.end(), value); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /** @file | ||
|
|
||
| @section license License | ||
|
|
||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string_view> | ||
| #include <cstdint> | ||
|
|
||
| constexpr uint16_t EXT_SNI{0x0}; | ||
| constexpr uint16_t EXT_ALPN{0x10}; | ||
| constexpr uint16_t EXT_SUPPORTED_VERSIONS{0x2b}; | ||
|
|
||
| namespace ja4 | ||
| { | ||
|
|
||
| class Datasource | ||
| { | ||
| public: | ||
| Datasource() = default; | ||
| virtual ~Datasource() = default; | ||
|
|
||
| enum class Protocol { | ||
| DTLS = 'd', | ||
| QUIC = 'q', | ||
| TLS = 't', | ||
| }; | ||
|
|
||
| enum class SNI { | ||
| to_domain = 'd', | ||
| to_IP = 'i', | ||
| }; | ||
|
|
||
| Protocol get_protocol(); | ||
| int get_version(); | ||
| SNI get_sni_type(); | ||
| int get_cipher_count(); | ||
| int get_extension_count(); | ||
| virtual std::string_view get_first_alpn() = 0; | ||
| virtual void get_cipher_suites_hash(unsigned char out[32]) = 0; | ||
| virtual void get_extension_hash(unsigned char out[32]) = 0; | ||
|
|
||
| protected: | ||
| bool _is_GREASE(uint16_t value); | ||
|
|
||
| Protocol _protocol; | ||
| int _version = 0; | ||
| bool _has_ALPN = false; | ||
| bool _has_SNI = false; | ||
| int _n_ciphers = 0; | ||
| int _n_extensions = 0; | ||
| }; | ||
|
|
||
| } // namespace ja4 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.