Commit Graph

75 Commits (dfb783d7ba187187453b44f316a849b789c4f7e6)

Author SHA1 Message Date
Soner Tari dfb783d7ba Release v0.9.5
Bump version to 0.9.5
Update copyright year to 2024
Update NEWS
4 months ago
Soner Tari 01d0b156d6 Decouple autossl code handling underlying bufs
And clean up redundant child callbacks
2 years ago
Soner Tari 63a48308cd Fix autossl without STARTTLS in divert mode
In the previous implementation, the use case for autossl was assumed to
be STARTTLS with POP3 or SMTP. But there are users who use autossl with
HTTP too. The split mode was fine, but the divert mode was broken. This
change makes autossl a generic upgrade mechanism.
Also fix sslproxy line in autossl, change p to s if upgraded.
Add e2e tests for autossl in divert and split mode.
2 years ago
Soner Tari fce838e43b Move code handling underlying bevs to autossl
Non-autossl protos do not have underlying bevs, so we should not try
check them. But there are still a couple of functions left which needs
to be moved to autossl.
2 years ago
Soner Tari fec19b8c8b Remove unnecessary function calls 2 years ago
Soner Tari 76ea48f2d0 Remove srvdst_xferred flag
Setting srvdst.bev to NULL can be used as a flag to indicate that we
have reused the srvdst of the parent as the dst of the first child conn.
This also prevents access to srvdst.bev after we do the xfer, without
any extra flag.
2 years ago
Soner Tari 02a6cc12e6 Remove redundant srvdst_xferred flag in child ctx 2 years ago
Soner Tari dc40f74c13 Update copyright year to 2022 2 years ago
Soner Tari 722c2f59d2 Disable srvdst events asap when xferring to child and in split mode
This is the correct implementation. And disabling later on is
problematic while terminating, and can even cause a crash.
2 years ago
Soner Tari 3efac5658f Fix build errors with OpenSSL 3.0.x, but not deprecation warnings
This patch fixes errors only, so that build succeeds, but deprecation
warnings remain. It seems we need considerable changes to replace those
deprecated functions in the warnings.
2 years ago
Soner Tari add8bcda09 Add line_num to filtering rules with DEBUG_PROXY
Error out unit tests if DEBUG_PROXY enabled, because we debug print
line_num if DEBUG_PROXY enabled. We cannot support line_num in expected
debug output, it would make things complicated with very little benefit.
3 years ago
Soner Tari 775ae774ea Set conn term flag only, do not free conn in eventcb
Rename reconnected_ssl flag to reconnected
Improve e2e tests
3 years ago
Soner Tari 8f63ec7f82 Add ReconnectSSL option to enforce SSL options in struct filtering rules
The ReconnectSSL option allows rule developers to write struct filtering
rules using SNI and CN SSL specifications to override the SSL
configuration of a connection.

Otherwise, without this new option, filtering rules cannot change SSL
options using SSL filtering fields to match connections (the SSL config
in the rule would not have any effect on the server side of the matching
connection). Without ReconnectSSL, only DstIP and DstPort fields can be
used to override the SSL config of a connection.

If the ReconnectSSL option in a struct filtering rule is set, we
disconnect and free the server side of the matching SSL connection, and
reconnect it with the SSL options in the matching struct filtering rule.
This enforces the SSL config in the rule.

Do not use the ReconnectSSL option if server disconnect is not desirable
or acceptable in your case.
3 years ago
Soner Tari e8f35ce587 Reapply dsthost filter after user auth
We have to apply the DstHost filter both (1) as early as in
pxy_conn_connect() and also (2) after user owner of the conn is
determined in srvdst connected callback functions for tcp and ssl.

Otherwise, we cannot override SSL options of conns if we don't apply it
before SSL establishment (1), and we cannot apply user auth filtering
rules if we don't apply after determining the user owner of conn (2).

This commit actually adds the same calls in the same places as they were
before the structured filtering rules were introduced.

So for example, now we have to apply filters 4x for an HTTPS conn: 2x
dsthost, 1x ssl, and 1x http.
3 years ago
Soner Tari 05d5412515 Fix warning for unused ctx debug param in pxy_conn_set_filter_action() 3 years ago
Soner Tari 18fb6f4dd7 Apply dstip filter before ssl server conn setup
So that we can replace the SSL/TLS configuration of the conn with the
one in the matching filtering rule. Otherwise, once the server conn is
established, we cannot change the SSL config, or would risk confusing
the SSL routines.
3 years ago
Soner Tari 6c988b0f4a Add structured filtering rules to specify conn options
Now all connection oriented proxy options possible to specify
per-proxyspec or globally can be specified in structured filtering rules
to be selectively applied to connections too. One line filtering rules
can specify filter and log actions only.

For example, we can enable/disable user authentication, protocol
validation, server ssl verification, and many other options
per-connection, or configure SSL/TLS connection options per-connection.

So, now we replace the conn_opts struct of a connection's ctx with the
conn_opts struct of the matching structured filtering rule. (One line
filtering rules have a NULL conn_opts, so we first check if the
conn_opts is not NULL.)
3 years ago
Soner Tari 14c8d417c9 Move connection oriented options to a new conn_opts struct 3 years ago
Soner Tari 396db70a87 Rename parent/child dst/src addrs to divert and return addrs 3 years ago
Soner Tari dff3f90c62 Add DEBUG_PROXY around debug func params 3 years ago
Soner Tari f056f699c1 Add port option to all site specs, fix precedences in filtering rules
Now, all of the 'to' site fields in filtering rules can specify a port,
not just the dstip sites.

Fix the precedence of sites in the same type of rules. For example, if
we find a match with an sni site, we should not stop searching for a
match in cn, because a matching cn site may have a higher precedence
than the matching sni site. We should apply the action of the cn site,
although sni rules have precedence over cn. The same applies to http
host and uri rules too.

Fix the precedence of dstip rules.

Improve and update unit and e2e tests accordingly.
3 years ago
Soner Tari 017f0f8631 Improve and clean up code and documentation 3 years ago
Soner Tari 9d2e523cd0 Use Aho-Corasick machines for substring matching
Now, the filter uses B-trees for exact string matching and Aho-Corasick
machines for substring matching. B-trees and AC machines are exported to
linked lists for debug logging only.

Also,
- Separate all_sites and all_ports filters from substring filters. They
are not related with substring filters actually, and ACM keywords cannot
be empty strings anyway. So now they should be handled separately too.
- Improve debug logging of filtering rules.
- Update unit tests accordingly, and improve.
- Fix pxyconn_filter(), keep searching for a match in substring filters
if exact match does not have a matching site rule.
- Increase common names max len and tokens. weather.gov has 73 tokens.
- Rename keyword to desc.
- Update documentation.
- Clean up.
3 years ago
Soner Tari 477bb239a0 Do not tokenize ssl_names if there is no rule to match exact common names 3 years ago
Soner Tari 9959bb48e9 Fix argc inc in cn token loop 3 years ago
Soner Tari 4f36a21c78 Use kbtree BST for exact match in site and port 'to' fields
So, for 'to' fields too, we use two separate data structures: binary
search trees (BST) for exact match and linked lists for substring match.

Now all 'from' and 'to' fields in filtering rules use these two data
structures.

To repeat, filtering rules should be written with exact matches instead
of substring matches, as much as possible. Because BST search must be
much faster than substring search over linked lists.

To repeat, we have modifed kbtree to support complex data structures in
from fields.

Also, update the unit tests accordingly.
3 years ago
Soner Tari e844f30886 Convert warning and info logs in filtering rules to fine debug logs 3 years ago
Soner Tari c8f09d162a Add port field to Dst Host filter rules, and refactor for code reuse
Now the target IP address filters can use port specs too.
Refactor for code reuse, create filter_action struct used by rules,
sites, and ports.
Also, improve code and documentation.
3 years ago
Soner Tari 39e1d87783 Fix deferred pass filter action in SSL filter
Do not call protopassthrough_engage() twice. If we call it to apply the
deferred pass action and also set the ctx->pass flag, it will be called
again in protossl_setup_src_ssl(). So, just set the flag and leave the
rest to protossl_setup_src_ssl().
3 years ago
Soner Tari 446cc29f5f Don't change log action if not specified, and obey the order of filtering rules
Filtering rules can enable/disable or don't change logging. If a rule
does not mention a log action, its logging should not change. So, binary
log action fields were not enough to represent those 3 possibilities,
hence we have increased the size of those fields to 2-bits.

We should obey the order of rules as they are written in the conf file,
because latter rules should be able to override the log actions of
earlier rules. So, keep the order.
3 years ago
Soner Tari ac3607a841 Add deferred pass and block actions
We should defer pass and/or block actions as long as possible, because a
higher precedence rule in SSL filter should be able to override (cancel)
deferred pass and block actions taken by a lower precedence rule in Dst
Host filter. And in HTTP filter the same applies to deferred block
actions taken by Dst Host and SSL filters.

Also, thanks to this new deferred actions, now HTTP filter can keep
enabled divert and split modes. In other words, a higher precedence HTTP
filter rule can cancel a deferred block action set by a lower precedence
rule earlier, which was not possible before without deferred actions and
rule precedence.

And other improvements.
3 years ago
Soner Tari 11884271fd Add negation prefix ! to log actions
Now filtering rules can disable log actions too. This is possible thanks
to the newly added precedence field of rules. Log actions of filtering
rules at higher precedence can modify logging now. In other words, more
specific rules can change the log actions of more general rules.
HTTP filtering rules can only disable logging.
3 years ago
Soner Tari cc7bd4a332 Add precedence to filtering rules
Now we assign precedence to each filtering rule. More specific rules
have higher precedence. So, filtering rules at lower precedence cannot
override the actions applied to a conn by filtering rules at higher
precedence.
The other precedence rules still apply.
3 years ago
Soner Tari 8ec97d779f Do not take log actions in HTTP filtering rules
Log actions specified in HTTP filter rules can never enable disabled
logging, because their loggers would not be initialized.

Perhaps we should initialize them in the log submit function, if they
are initialized yet.
3 years ago
Soner Tari 8a57d52f62 Add master and cert log actions
Also, improve documentation
3 years ago
Soner Tari f0c2ca6819 Add Match action and connect|content|pcap|mirror log actions in filtering rules
- Match action is added to be used with log actions only, the other
filter actions can specify log actions too
- Log actions do not configure any loggers. Global loggers for
respective log actions should have been configured for those log actions
to have any effect.
- If no filter rules are defined for a proxyspec, all log actions are
enabled. Otherwise, all log actions are disabled, and filtering rules
should enable them specifically.
- Fix max number of tokens in proxyspec and filter parsers
- Fix issues with rejecting unknown args in filter rule parser
- Do not use filter_rules field of proxyspec after config finished, it
is used for filter configuration and freed afterwards
3 years ago
Soner Tari 99c852972e Implement filter actions
- SSL and Dst Host filters can take all of the actions.

- HTTP filter can only take block action, not divert, split, or pass.
Because, we cannot tear a conn down and reconnect its src, after the
processing of HTTP request header is complete, e.g. SSLproxy line has
already been added to its dst buffer. Also, any change in child conns
would affect listening programs too.

- The precedence of filters is as Dst Host > SSL > HTTP.

- The precedence of actions is as Divert > Split > Pass > Block. This is
only for the same type of filter.

- The precedence of match sites is as sni > cn for ssl filter and host >
uri for http filter.

For example, pass action of dst host filter is taken before split action
of ssl filter, due to the precedence order of filters.

For example, pass action of sni site is taken before split action of cn,
due to the precedence order of sites.

We now create src ssl before enabling src to be able to take divert or
split actions of SSL filter. Otherwise, we wouldn't be able to switch
between divert and split while enabling src, only pass or block action
could be taken at that stage.

Also, refactor and clean up.
3 years ago
Soner Tari 475a7ebcda Add Divert|Split|Pass|Block filtering rules
(Divert|Split|Pass|Block)
  ([from (
        user (username|*) [desc keyword]|
        ip (clientaddr|*)|
        *)]
    [to (
        sni (servername[*]|*)|
        cn (commonname[*]|*)|
        host (host[*]|*)|
        uri (uri[*]|*)|
        ip (serveraddr|*)|
        *)]
  |*)

Also, fix a couple of issues with filter rule handling
Clean up
3 years ago
Soner Tari ff3bcab3f1 Add exact bit, do not add slashes around sites, avoid unnecessary strdups
Limit site len to 200
3 years ago
Soner Tari 85fb1bd214 Add new data structure for general filtering rules
Now PassSite rules are considered as pass rule and added to the new data
structure. PassSite option will be deprecated in the future.
3 years ago
Soner Tari 6a4a70bb06 Avoid strdup() and simplify passsite search
Also, improve code, tests, and documentation
3 years ago
Soner Tari 982880ccfe Restructure passsite filter data structure
Now we don't go over all of the passsite rules in a linked list trying
to apply passsite to the sni or common names of a conn. Instead, we now
have user+keyword, keyword, ip, and all lists. For example, if we find
the conn user in the user+keyword list and a passsite in that list
matches, we don't look into other lists.

This change is expected to improve the performance of passsite
processing considerably, because in the earlier implementation we had to
go over all of the passsite rules trying to match passsite.

And this solution uses a correct data structure, even if not the best.
For example, each user or keyword in passsite rules is strdup()'ed only
once.

Note that a better solution could use, say, a hash table for users,
instead of a linked list. But hash tables are not suitable for keywords
or sites, because we search for substring matches with them, not exact
matches.

Also, this fixes passsite rules without any filters defined, i.e. to be
applied to all connections.

Also, now e2e tests error exit if WITHOUT_USERAUTH is enabled. E2e tests
require UserAuth enabled.
3 years ago
Soner Tari 56237558cd Refactor protossl_pass_site() to reduce and decouple code for substring and exact search 3 years ago
Soner Tari f2d4ef61c9 Add support for passsite substring match
Now the site field in PassSite option can have an '*' suffix to search
for a match anywhere in sni or common names. Note that this is not a
regex or wildcard search.

Previously, we only supported exact matches in sni and between slashes
in common names. This change makes it possible to cover multiple sites
in one PassSite option. In fact, without this change, certain sites
could not be added as passsite, because it was impossible to know their
subdomain names beforehand, for example *.fbcdn.net, which may have many
subdomain names in place of asterisk.

So to use substring match, append an '*' to a site name in PassSite
option (the asterisk is removed before substring search). For example,
use ".fbcdn.net*" to match all subdomains of fbcdn.net, notice the
asterisk at the end.

We also add a warning log starting with "Closing on ssl error without
passsite match" to report sites that can be added as passsite, which is
expected to help in writing PassSite rules.

Also, we now set dstaddr_str earlier in conn handling, so we can print
it in debug logs. This also helps in IDLE and EXPIRED conn logs.
3 years ago
Soner Tari 9a7e2c35f3 Avoid multithreading issues by duping the site arg as a local var
If more than one thread enters protossl_pass_site() with the same
proxyspec, they all use spec->opts->passsites->site. Since
protossl_pass_site() modifies the site arg, spec->opts->passsites->site
may be broken. For example, /example.org/ may become /example.or//,
which really happened.
3 years ago
Soner Tari 9123732739 Fix possible segfaults with srvdst_xferred, autossl and passthrough
- Fix segfault introduced in previous commit to prevent extra eof event.
We should NULL srvdst.bev after terminating child dst xferred from
srvdst of parent, so that we don't try to access srvdst.bev. This
happens if child conn with dst xferred from parent srvdst is terminated
before parent conn.

- Fix autossl crash trying to engage passthrough mode. We cannot engage
passthrough mode in autossl, because src is already enabled. But we
shouldn't crash either. These changes are expected to fix other possible
segfaults if passthrough is engaged on eventcb of a child conn.
3 years ago
Soner Tari 69753b250c Add split mode of operation similar to SSLsplit
The -n command line option enables split mode for all proxyspecs,
effectively making sslproxy behave like sslsplit.
Divert option can be set/unset globally and per-proxyspec.
Add e2e tests for split mode, and update make file for tests
accordingly.
Update documentation accordingly.
Improve code reuse, remove duplicate functions.

This change deserves a release of its own, hence v0.8.4.
3 years ago
Soner Tari 596aebb2f3 Update version to 0.8.3 and copyright year to 2021 3 years ago
Soner Tari 151b305c2f Do not pass null arg to log_*_printf()
vfprintf %s NULL in "Error from bufferevent: %i:%s %lu:%i:%s:%i:%s:%i:%s
"
Error from bufferevent: 32:Broken pipe 50327584:32:Broken pipe:2:system
library:4095:(null)
4 years ago
Soner Tari 80d10a94c3 Move classify_user into identify_user
Otherwise, we cannot classify user if we need to issue identify_user
events, in case database is busy or locked. We should call classify_user
callback right after the user is identified.
So we introduce classify_user callback to achieve that, which fixes the
classify_user behavior for autssl proto too.

Return void in pxy_userauth
Fix typo in clasify
4 years ago