-
Notifications
You must be signed in to change notification settings - Fork 854
Add jax_fingerprint plugin #12995
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
Open
maskit
wants to merge
35
commits into
apache:master
Choose a base branch
from
maskit:jax
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add jax_fingerprint plugin #12995
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
cb73082
Add jax_fingerprint plugin
maskit b73a738
Add license headers
maskit a213016
Add the new documentation to the toc
maskit 721bcf8
Include limit.h
maskit 1af049c
Include sha.sh instead of sha2.h
maskit 086387b
Don't use std::copy
maskit 7422cb1
Use heterogeneous lookup only if it's available
maskit 175699b
Fix documentation format
maskit 1974f05
Fix documentation
maskit 1f58e3b
Fix documentation format
maskit a49660c
Don't use std::ranges::equal
maskit 698a53a
Fix memory leak
maskit 3ca2e94
Fix logic error
maskit 69b50ef
Adjust type difference
maskit 78916e8
Address some copilot comments
maskit 0992c99
Address some more comments
maskit b4ad96d
Address some more comments
maskit 61df6d2
Address some more comments
maskit 55cb41a
Address some more comments
maskit 4502f6b
Fix the keep mode
maskit f95e5bc
Add a missing break
maskit fbfe64f
Address some more comments
maskit 3dfa525
Address comments
maskit 85bd66e
Minor changes
maskit ef8d25f
Add unit tests for JA4H and restructure the code base
maskit 168cf90
Fix build error
maskit 4efc0d0
Add missing files
maskit 66c4999
Include cctype
maskit c422b08
Fix tests
maskit 28f0b4f
Address copilot comments
maskit 04c499e
Add missing include
maskit 77e18ea
Add autest
maskit 18d722c
Use AddAwaitFileContainsTestRun
maskit f7a5a93
Address copilot comments
maskit e54c4d6
Use ssl_multicert_yaml
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 |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| .. 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:: ../../common.defs | ||
|
|
||
| .. _admin-plugins-jax-fingerprint: | ||
|
|
||
| JAx Fingerprint Plugin | ||
| ********************** | ||
|
|
||
| Description | ||
| =========== | ||
|
|
||
| The JAx Fingerprint plugin generates client fingerprints based on the JA4+ or JA3 algorithms designed by John Althouse. | ||
|
|
||
| Fingerprints can be used for: | ||
|
|
||
| * Client identification and tracking | ||
| * Bot detection and mitigation | ||
| * Security analytics and threat intelligence | ||
| * Understanding client implementation patterns | ||
|
|
||
|
|
||
| Plugin Configuration | ||
| ==================== | ||
|
|
||
| You can use the plugin as a global plugin, a remap plugin, or both. | ||
|
|
||
| To use the plugin as a global plugin, add the following line to :file:`plugin.config`:: | ||
|
|
||
| jax_fingerprint.so --standalone | ||
|
|
||
| To use the plugin as a remap plugin, append the following line to a remap rule on :file:`remap.config`:: | ||
|
|
||
| @plugin=jax_fingerprint.so @pparam=--standalone | ||
|
|
||
| To use the plugin in a hybrid setup (both global and remap plugin), configure it in both :file:`plugin.config` and | ||
| :file:`remap.config` without ``--standalone`` option. | ||
|
|
||
|
|
||
| .. option:: --standalone | ||
|
|
||
| This option enables you to use the plugin as either a global plugin, or a remap plugin. In other | ||
| words, the option needs to be specified if you do not use the hybrid setup. | ||
|
|
||
| .. option:: --method <JA4|JA4H|JA3> | ||
|
|
||
| Fingerprinting method (e.g. JA4, JA3, etc.) to use. This option must be specified. | ||
|
|
||
| .. option:: --mode <overwrite|keep|append> | ||
|
|
||
| This option specifies what to do if requests from clients have the header names that are specified | ||
| by `--header` and/or `--via-header`. Available setting values are "overwrite", "keep" and "append". | ||
| The default mode is "overwrite". | ||
|
|
||
| .. option:: --servernames <servername1,servername2,...> | ||
|
|
||
| This option specifies server name(s) for which the plugin generates fingerprints. | ||
| The value must be provided as a single comma separated value (no space) of server names. | ||
| If the option is not specified, the plugin generates fingerprints for any server names. | ||
|
|
||
| .. option:: --header <header_name> | ||
|
|
||
| This option specifies the name of the header field where the plugin stores the generated fingerprint value. If not specified, header generation will be suppressed. | ||
|
|
||
| .. option:: --via-header <via_header_name> | ||
|
|
||
| This option specifies the name of the header field where the plugin stores the generated fingerprint-via value. If not specified, header generation will be suppressed. | ||
|
|
||
| .. option:: --log-filename <filename> | ||
|
|
||
| This option specifies the filename for the plugin log file. If not specified, log output will be suppressed. | ||
|
|
||
|
|
||
| Plugin Behavior | ||
| =============== | ||
|
|
||
| Global plugin setup | ||
| ------------------- | ||
|
|
||
| Global plugin setup is the best if you: | ||
| * Need a fingerprint on every request | ||
|
|
||
| Remap plugin setup | ||
| ------------------ | ||
|
|
||
| Remap plugin setup is the best if you: | ||
| * Need a fingerprint only on specific paths, or | ||
| * Cannot use Global plugin setup | ||
|
|
||
| .. note:: For JA3 and JA4, fingerprints are always generated at the beginning of connections. Using remap plugin setup only reduces the overhead of adding HTTP headers and logging. | ||
|
|
||
| Hybrid setup | ||
| ------------ | ||
|
|
||
| Hybrid setup is the best if you: | ||
| * Need a fingerprint only for specific server names (in TLS SNI extension), and | ||
| * Need a fingerprint only on specific paths | ||
|
|
||
|
|
||
| Log Output | ||
| ========== | ||
|
|
||
| The plugin outputs a log file in the Traffic Server log directory (typically ``/var/log/trafficserver/``) if a log filename is | ||
| specified by ``--log-filename`` option. | ||
|
|
||
| **Log Format**:: | ||
|
|
||
| [timestamp] Client: <address> <method_name>: <fingerprint> | ||
|
|
||
| **Example**:: | ||
|
|
||
| [Jan 29 10:15:23.456] Client: 192.168.1.100 JA4: t13d1516h2_8daaf6152771_b186095e22b6 | ||
| [Jan 29 10:15:24.123] Client: 10.0.0.50 JA4: t13d1715h2_8daaf6152771_02713d6af862 | ||
|
|
||
|
|
||
| Using HTTP Headers in Origin Requests | ||
| ===================================== | ||
|
|
||
| Origin servers can access the generated fingerprint through the injected HTTP header. | ||
| This allows the origin to: | ||
|
|
||
| * Make access control decisions based on client fingerprints | ||
| * Log fingerprints for security analysis | ||
| * Track client populations and TLS implementation patterns | ||
|
|
||
| The fingerprint-via header allows origin servers to track which Traffic Server proxy handled the request when multiple proxies are deployed. | ||
|
|
||
|
|
||
| Debugging | ||
| ========= | ||
|
|
||
| To enable debug logging for the plugin, set the following in :file:`records.yaml`:: | ||
|
|
||
| records: | ||
| diags: | ||
| debug: | ||
| enabled: 1 | ||
| tags: jax_fingerprint | ||
|
|
||
|
|
||
| Requirements | ||
| ============ | ||
|
|
||
| * Traffic Server must be built with TLS support (OpenSSL or BoringSSL) if you use JA3 or JA4 | ||
|
|
||
|
|
||
| See Also | ||
| ======== | ||
| * JA3 Technical Specification: https://github.com/FoxIO-LLC/ja3 | ||
| * JA4+ Technical Specification: https://github.com/FoxIO-LLC/ja4 | ||
|
|
||
|
|
||
| Example Configuration | ||
| ===================== | ||
|
|
||
| Enable JA4 fingerprinting by hybrid (global + remap) setup | ||
| ---------------------------------------------------------- | ||
|
|
||
| This configuration adds x-my-ja4 header if a connection is established for either abc.example or xyz.example. | ||
|
|
||
| **plugin.config**:: | ||
|
|
||
| jax_fingerprint.so --method JA4 --servernames abc.example,xyz.example | ||
|
|
||
| **remap.config**:: | ||
|
|
||
| map / http://origin.example/ @plugin=jax_fingerprint.so @pparam=--method=JA4 @pparam=--header=x-my-ja4 | ||
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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| ####################### | ||
| # | ||
| # 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. | ||
| # | ||
| ####################### | ||
|
|
||
| add_atsplugin( | ||
| jax_fingerprint | ||
| plugin.cc | ||
| context.cc | ||
| userarg.cc | ||
| header.cc | ||
| log.cc | ||
| ja3/ja3_method.cc | ||
| ja3/ja3_utils.cc | ||
| ja4/ja4_method.cc | ||
| ja4/ja4.cc | ||
| ja4/tls_client_hello_summary.cc | ||
| ja4h/ja4h_method.cc | ||
| ja4h/ja4h.cc | ||
| ja4h/datasource.cc | ||
| ) | ||
| target_link_libraries(jax_fingerprint PRIVATE OpenSSL::Crypto OpenSSL::SSL) | ||
| verify_global_plugin(jax_fingerprint) | ||
|
|
||
| if(BUILD_TESTING) | ||
| add_executable( | ||
| test_jax | ||
| ja3/test_ja3.cc | ||
| ja3/ja3_utils.cc | ||
| ja4/test_ja4.cc | ||
| ja4/ja4.cc | ||
| ja4/tls_client_hello_summary.cc | ||
| ja4h/test_ja4h.cc | ||
| ja4h/ja4h.cc | ||
| ja4h/datasource.cc | ||
| ) | ||
| target_link_libraries(test_jax PRIVATE Catch2::Catch2WithMain OpenSSL::Crypto OpenSSL::SSL) | ||
|
|
||
| add_catch2_test(NAME test_jax COMMAND test_jax) | ||
| endif() |
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,70 @@ | ||
| /** @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 "ts/ts.h" | ||
| #include "plugin.h" | ||
| #include "method.h" | ||
|
|
||
| #include <string> | ||
| #include <unordered_set> | ||
|
|
||
| enum class Mode : int { | ||
| OVERWRITE, | ||
| KEEP, | ||
| APPEND, | ||
| }; | ||
|
|
||
| enum class PluginType : int { | ||
| GLOBAL, | ||
| REMAP, | ||
| }; | ||
|
|
||
| // This hash function enables looking up the set by a string_view without making a temporary string object. | ||
| struct StringHash { | ||
| // Enable heterogeneous lookup | ||
| using is_transparent = void; | ||
|
|
||
| size_t | ||
| operator()(std::string_view sv) const | ||
| { | ||
| return std::hash<std::string_view>{}(sv); | ||
| } | ||
| }; | ||
|
|
||
| struct PluginConfig { | ||
| PluginConfig() { Dbg(dbg_ctl, "New config (%p) has been created", this); } | ||
| ~PluginConfig() { Dbg(dbg_ctl, "Config for (%p) has been deleted", this); } | ||
maskit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| PluginType plugin_type = PluginType::GLOBAL; | ||
| Mode mode = Mode::OVERWRITE; | ||
| struct Method method = {"uninitialized", Method::Type::CONNECTION_BASED, nullptr, nullptr}; | ||
| std::string header_name = ""; | ||
| std::string via_header_name = ""; | ||
| std::string log_filename = ""; | ||
| int user_arg_index = -1; | ||
| TSCont handler = nullptr; // For remap plugin | ||
| bool standalone = false; | ||
| std::unordered_set<std::string, StringHash, std::equal_to<>> servernames; | ||
| TSTextLogObject log_handle = nullptr; | ||
| }; | ||
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.