Skip to content

Add http ja5 filter and configuration #2320

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 2 commits into from
Jan 21, 2025
Merged

Conversation

Kutumov
Copy link
Contributor

@Kutumov Kutumov commented Jan 9, 2025

No description provided.

Base automatically changed from vk-2052-ja5-filter to master January 13, 2025 15:52
lib/ja5.h Outdated
@@ -1,7 +1,7 @@
/**
* Tempesta FW
*
* Copyright (C) 2024 Tempesta Technologies, Inc.
* Copyright (C) 2019 Tempesta Technologies, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2025

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1 @@
../../ja5_conf.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this files here, because we don't have any unit tests for ja5. To avoid unresolved symbols please add appropriate functions to fw/t/unit/helpers.c

@@ -0,0 +1 @@
../../ja5_filter.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this file (same as previous one).

INIT_LIST_HEAD(&storage->lru_list);
spin_lock_init(&storage->lru_list_lock);

return (storage->tdb = tdb_open(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where we call tdb_close

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

fw/ja5_conf.c Outdated
he->conns_per_sec = conns_per_sec;
he->records_per_sec = recs_per_sec;
INIT_HLIST_NODE(&he->hlist);
refcount_set(&he->refcnt, 1);

key = hash_calc((char *)&hash, sizeof(hash));
hash_add(tls_filter_cfg_reconfig->hashes, &he->hlist, key);
hash_for_each_possible(filter_cfg_reconfig->hashes, iter, hlist, key) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hash_for_each_possible_safe should be used when entry can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

int ja5_cfgop_finish(TfwCfgSpec *cs);
void ja5_cfgop_cleanup(TfwCfgSpec *cs);

#endif // __JA5_CONF__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/* JA5_CONF */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

fw/ja5_filter.h Outdated

return res;
}
#endif // __JA5_FILTER__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use /* */ for comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@EvgeniiMekhanik
Copy link
Contributor

EvgeniiMekhanik commented Jan 13, 2025

I also have a question, why we calculate hash for each cid in ttls_parse_supported_elliptic_curves. Please also pay attention @const-t .

@EvgeniiMekhanik
Copy link
Contributor

EvgeniiMekhanik commented Jan 13, 2025

I also see strange logic in ttls_parse_alpn_ext where we account sess.ja5t.alpn several times in the loop. I also don't understand has_unknown_alpn flag. If we don't find alpn we drop client and don't need to save any information in hash. @const-t please also pay attention

@const-t
Copy link
Contributor

const-t commented Jan 14, 2025

I also see strange logic in ttls_parse_alpn_ext where we account sess.ja5t.alpn several times in the loop

We do so to have the same hash for each the same alpn sequence. h1, h2, h2, h1 must have different hashes. The same for ttls_parse_supported_elliptic_curves()

If we don't find alpn we drop client and don't need to save any information in hash.

has_unknown_alpn indicates that alpn sequence contains not supported protocol beside supported. It means alpn might be following: http1, h2, unk1, unk2 or unk1, unk2, http1, h2 and they both valid.

@Kutumov Kutumov force-pushed the vk-2052-ja5http-filter branch 3 times, most recently from f51c53d to c7a8243 Compare January 20, 2025 13:37
Make a unified filtering code for any ja5 type.
@Kutumov Kutumov force-pushed the vk-2052-ja5http-filter branch from c7a8243 to 5e583b8 Compare January 21, 2025 03:55
@krizhanovsky krizhanovsky merged commit a9d54be into master Jan 21, 2025
1 check was pending
@krizhanovsky krizhanovsky deleted the vk-2052-ja5http-filter branch January 21, 2025 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants