Commit Graph

994 Commits (477bb239a0b25f4a56d343a2298b865a24009ce6)
 

Author SHA1 Message Date
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 765c0dac05 Fix site precedence handling, and use all_sites and all_ports
Actually, no need to check all_sites or all_ports, because strstr(3) on
OpenBSD reads that "If little is an empty string, big is returned", and
if all_sites or all_ports is set, site or port (little/needle) is empty.
But using all_sites and all_ports should improve performance by avoiding
the strstr() call.
3 years ago
Soner Tari e654ca4e2c Fix memory leaks in filter
Add attributes
Update documentation
3 years ago
Soner Tari f44f12456c Fix unit tests with WITHOUT_USERAUTH
And update documentation
3 years ago
Soner Tari 2ff0f728e5 Use template macros for code reuse, and append to linked lists
Add to the end of linked lists for correct list ordering, but btrees
cannot obey this ordering.
Also, update the unit tests accordingly.
And fix compile with WITHOUT_USERAUTH.
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 15991dfb93 Use kbtree BST for exact match in user, keyword, and ip 'from' fields
So, now we use two separate data structures: binary search trees (BST)
for exact match and linked lists for substring match.

Currently, only user, keyword, and ip 'from' fields in filtering rules
use these two data structures. This also means that now we support exact
and substring matches in 'from' fields.

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.

We have modifed kbtree to support complex data structures in from
fields.
3 years ago
Soner Tari 95dd3bb9f8 Update khash, fixes typos 3 years ago
Soner Tari ec816e7db6 Fix documentation of user desc keyword exact search 3 years ago
Soner Tari 2b4cbd27fd Increase max tokens for filter rules to 17
+= port + serverport

And improve documentation
3 years ago
Soner Tari e844f30886 Convert warning and info logs in filtering rules to fine debug logs 3 years ago
Soner Tari 66f7a88374 Move DivertUsers/PassUsers options to filter.c
The DivertUsers and PassUsers options will be deprecated in favor of
filtering rules in the future.
3 years ago
Soner Tari 21fed37a92 Rename tmp_global_opts to global_tmp_opts 3 years ago
Soner Tari fd6c852355 Move filtering rules to filter.c/h
Also, fix certain and possible memory leaks in debug printing
And improve code
3 years ago
Soner Tari 14f68457fb Fix the ordering of sites, ports, and macro values in filtering rules
all_sites and all_ports rules should be at the end of their lists, they
should be searched last, because they are the least specific rules in
their lists, hence have lower precedences.

Also, obey the order of rules in conf files by adding sites, ports, and
macro values to their lists in the same order they are in conf files.

Update the unit and e2e tests accordingly, and improve.
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 dc34bc1ccf Add e2e tests for filtering rules
End-to-end tests now require testproxy v0.0.4, which supports the new
Reconnect command for the Pass filtering rule.

Split mode with the -n option also supports filtering rules, so the
Divert rule can enable the divert mode even with the -n option. This is
because the purpose of the -n option is to convert sslproxy into an
sslsplit, and we want to support filtering rules in sslsplit-like
sslproxy too.
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 db9974617f Improve documentation
The Include and Define options, the ordering in config options, etc.
3 years ago
Soner Tari 712733b329 Reuse debug print of filter rule
Actually, the PassSite option will be deprecated, but reuse for
correctness.
3 years ago
Soner Tari 17630340d2 Add unit tests for filtering rules
for both the parser and the translator

TODO: Add reject tests
3 years ago
Soner Tari e4d27bee99 Return 2 to indicate the end of structured proxyspec, not 1
Return value of 1 is for ending macro expansion. Otherwise, it coincided
with closing brace retval, which was wrongly breaking out of the while
loop in load_proxyspec_struct().

TODO: Use enums for return values.
3 years ago
Soner Tari 41dccaff14 Increase max tokens for filter rules to 15
+= master + cert
3 years ago
Soner Tari f5bb67f581 Error out if struct proxyspec is not complete
The default proto is tcp, so we allow the Proto option to be omitted.
3 years ago
Soner Tari c7e43f359d Do not allow empty option values except for the closing brace in struct proxyspecs
It is better to error out earlier than to pass the option down to be
rejected by its handler (the handler may fail to reject, as was the case
with a couple of options).
3 years ago
Soner Tari abb301c418 Fail if struct ProxySpec has no arguments or closing brace 3 years ago
Soner Tari d877b9a635 Fix and improve get_name_value() and unit tests
Fix possible segfault if name has leading white space
Pass the name param to get_name_value() as char *, so it cannot be
modified ever

Improve unit tests for get_name_value and proxyspec_parse
3 years ago
Soner Tari ab7674b652 Do not allow Include option within include files, no recursive include files
Prevent infinitely recursive include files
3 years ago
Soner Tari 01ff382267 Do not allow macro within macro, no recursive macro definitions
Prevent infinite macro expansion
3 years ago
Soner Tari 206734e4b6 Return -1 on error from all configuration functions, never exit()
And use all those return values.

Since we support include files now, we should be able to report in which
include file the error has occured. This is not possible if functions
just bail out calling exit(), because the user has to scroll back stderr
lines to find which include file has failed loading (a line starting
with 'Conf: ').

Plus, calling exit() on errors reduces unit testability of functions.

Also, handle all possible out of memory conditions in opts.c.
3 years ago
Soner Tari c38c065923 Add Include option for loading configuration from an include file 3 years ago
Soner Tari 0f5ed122fb Add Define option for macro definitions and macro expansion to filtering rules
The new Define option can be used for defining macros to be used in
filtering rules. Macro names must begin with a '$' char. Macro values
must be separated with spaces.

Macros are expanded by rewriting the rule with the values of macro.

PassSite rules do not support macros (the PassSite option will be
deprecated in favor of filtering rules in the future).
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 0c9fe83bb5 Update unit tests with master and cert log actions 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 357e6050db Do not init content logging for the connection if its log action is disabled
So now, we don't create any content log file if that log action is
disabled.
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 0787e74bd1 Rename FILTER_ACTION_IGNORE to FILTER_ACTION_MATCH
Match is a better term than ignore, if the other actions are not
returned but there is a matching filter rule. Otherwise, it is up to the
caller to ignore a match or not. Plus, we can implement Match filtering
rule too, e.g. for content logging as in OpenBSD/pf.
3 years ago
Soner Tari 5d84587195 Add -Q test config option
Quits after loading and testing all configuration.
3 years ago
Soner Tari 37f82aa84e Simplify get_name_value() 3 years ago
Soner Tari 42fecffb70 Silence error message issued for Divert option non-yes|no value
If the value for the Divert option is not yes|no, it is assumed to be a
Divert filtering rule. So the parser for filtering rules should issue
any errors.
3 years ago
Soner Tari e993ccdb5d Add FILTER_ACTION_IGNORE action
Differentiate filter action for site match from no site match. The
search should stop if a match is found, even if the action does not
change anything in effect (divert/split action in divert/split mode,
respectively) or the action is ignored (pass action in passthrough
mode).
3 years ago
Soner Tari 9c8e56d5df Fix unit tests for proxyspec parser caused by tmp global opts change
Pass a non-NULL tmp global opts arg to proxyspec_parse() for its global
split flag accessed in the function.
3 years ago
Soner Tari b5944cc190 Fix split mode proxy specifications on the command line
Split mode structured proxy specifications were fine.
3 years ago
Soner Tari c63309c766 Fix the precedence of multiple divert options used in conf file
The Divert option is not equivalent to the command line -n option.
Also, move the global static split var to tmp struct removed after
config is finished.
3 years ago