summaryrefslogtreecommitdiff
path: root/src/test
AgeCommit message (Collapse)Author
2023-09-13Add diagnostic log message for compression bombs.Alexander Færøy
This patch causes `tor_compress_is_compression_bomb()` to emit a warning-level log message that lets us learn the potential ratio of the input to output buffer sizes. Hopefully, this will give us a bit of a better idea whether the compression bomb ratio needs some tuning. See: tpo/core/tor#40739.
2023-08-22Merge remote-tracking branch 'mbeth-private/ticket40821_mr'David Goulet
2023-08-15CI: Diagnostic for failure in test_rebind cleanupMicah Elizabeth Scott
I saw this test fail intermittently due to what seemed like a filesystem race in docker? The cleanup task was failing with a 'directory not empty' error, despite trying to do a recursive 'rm'. This patch adds an 'ls' to the same directory, hoping the output might be useful to diagnose future intermittent failures.
2023-08-11test_dos: Fixes for uninitialized stack memoryMicah Elizabeth Scott
This was causing CI failures that didn't reproduce on my local machine. The DoS subsystem now has a new assert() which triggers a BUG on some nonzero memory contents (or_conn->tracked_for_dos_mitigation), and uninitialized stack memory might be nonzero.
2023-08-11Extend DoS protection to IP addresses with known relaysMicah Elizabeth Scott
This exemption used to be helpful in keeping exit relays from tripping the DoS detection subsystem and losing Tor connectivity. Now exit relays block re-entry into the network (tor issue #2667) so it's no longer needed. We'd like to re-enable protection on these addresses to avoid giving attackers a way around our DoS mitigations.
2023-08-09Extend DoS protection to partially-open channelsMicah Elizabeth Scott
tor only marks a channel as 'open' once the TLS and OR handshakes have both completed, and normal "client" (ORPort) DoS protection is not enabled until the channel becomes open. This patch adds an additional earlier initialization path for DoS protection on incoming TLS connections. This leaves the existing dos_new_client_conn() call sites intact, but adds a guard against multiple-initialization using the existing tracked_for_dos_mitigation flag. Other types of channels shouldn't be affected by this patch.
2023-06-27Bug 40566: Remove unused BDP estimatorsMike Perry
2023-06-23Add congestion control tests to build.Mike Perry
2023-06-23Add CWND test vectorsMike Perry
2023-06-23Add RTT Test VectorsMike Perry
2023-06-23Add clock heuristic test vector for congestion control.Mike Perry
2023-06-23Export variables and functions for CC unit tests.Mike Perry
2023-06-23Bug 40709: Update and clean up tests for consensus paramsMike Perry
2023-06-22Bug 40569: Reduce accepted range for negotiated cc_sendme_incMike Perry
2023-06-20Bug 40808: Change KISTSchedRunInterval range and default; add ↵Mike Perry
KISTSchedRunIntervalClient
2023-06-15Change git.tpo URLs to gitlab.tpoDavid Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2023-06-01test: Really fix the mem leak from prior commitDavid Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2023-06-01test: Fix a mem leak reported by CoverityDavid Goulet
Here is the report: *** CID 1531835: Resource leaks (RESOURCE_LEAK) /src/test/test_crypto_slow.c: 683 in test_crypto_equix() 677 678 /* Solve phase: Make sure the test vector matches */ 679 memset(&output, 0xa5, sizeof output); 680 equix_result result; 681 result = equix_solve(solve_ctx, challenge_literal, 682 challenge_len, &output); >>> CID 1531835: Resource leaks (RESOURCE_LEAK) >>> Variable "solve_ctx" going out of scope leaks the storage it points to. Signed-off-by: David Goulet <dgoulet@torproject.org>
2023-05-28hs_pow: Add CompiledProofOfWorkHash torrc optionMicah Elizabeth Scott
This exposes the new fallback behavior in hashx via a new AUTOBOOL configuration option, available to both clients and services. The default should be fine for nearly everyone, but it might be necessary to enable or disable the compiler manually for diagnostic purposes. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-28hs_pow: Update for equix API to fix issue 40794Micah Elizabeth Scott
This change adapts the hs_pow layer and unit tests to API changes in hashx and equix which modify the fault recovery responsibilities and reporting behaivor. This and the corresponding implementation changes in hashx and equix form the fix for #40794, both solving the segfault and giving hashx a way to report those failures up the call chain without them being mistaken for a different error (unusable seed) that would warrant a retry. To handle these new late compiler failures with a minimum of fuss or inefficiency, the failover is delegated to the internals of hashx and tor needs only pass in a EQUIX_CTX_TRY_COMPILE flag to get the behavior that tor was previously responsible for implementing. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-28test_sandbox: equix crypto test case for issue 40794Micah Elizabeth Scott
This is an additional test case for test_sandbox that runs a small subset of test_crypto_equix() inside the syscall sandbox, where mprotect() is filtered. It's reasonable for the sandbox to disallow JIT. We could revise this policy if we want, but it seems a good default for now. The problem in issue 40794 is that both equix and hashx need improvements in their API to handle failures after allocation time, and this failure occurs while the hash function is being compiled. With this commit only, the segfault from issue 40794 is reproduced. Subsequent commits will fix the segfault and revise the API. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-25test: Fix parseconf to account for ClientUseIPv6 change for dirauth disabledDavid Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2023-05-25test: Fix parseconf to account for ClientUseIPv6 changeDavid Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2023-05-24Merge branch 'tor-gitlab/mr/711'David Goulet
2023-05-24token_bucket_ctr: replace 32-bit wallclock time with monotimeMicah Elizabeth Scott
This started as a response to ticket #40792 where Coverity is complaining about a potential year 2038 bug where we cast time_t from approx_time() to uint32_t for use in token_bucket_ctr. There was a larger can of worms though, since token_bucket really doesn't want to be using wallclock time here. I audited the call sites for approx_time() and changed any that used a 32-bit cast or made inappropriate use of wallclock time. Things like certificate lifetime, consensus intervals, etc. need wallclock time. Measurements of rates over time, however, are better served with a monotonic timer that does not try and sync with wallclock ever. Looking closer at token_bucket, its design is a bit odd because it was initially intended for use with tick units but later forked into token_bucket_rw which uses ticks to count bytes per second, and token_bucket_ctr which uses seconds to count slower events. The rates represented by either token bucket can't be lower than 1 per second, so the slower timer in 'ctr' is necessary to represent the slower rates of things like connections or introduction packets or rendezvous attempts. I considered modifying token_bucket to use 64-bit timestamps overall instead of 32-bit, but that seemed like an unnecessarily invasive change that would grant some peace of mind but probably not help much. I was more interested in removing the dependency on wallclock time. The token_bucket_rw timer already uses monotonic time. This patch converts token_bucket_ctr to use monotonic time as well. It introduces a new monotime_coarse_absolute_sec(), which is currently the same as nsec divided by a billion but could be optimized easily if we ever need to. This patch also might fix a rollover bug.. I haven't tested this extensively but I don't think the previous version of the rollover code on either token bucket was correct, and I would expect it to get stuck after the first rollover. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-24Merge branch 'tor-gitlab/mr/709'David Goulet
2023-05-24Merge branch 'tor-gitlab/mr/710'David Goulet
2023-05-24test_hs_descriptor: Add a test case that fails without the fix for 40793Micah Elizabeth Scott
This adds a bit more to hs_descriptor/test_decode_descriptor, mostly testing pow-params and triggering the tor_assert() in issue #40793. There was no mechanism for adding arbitrary test strings to the encrypted portion of the desc without duplicating encode logic. One option might be to publicize get_inner_encrypted_layer_plaintext enough to add a mock implementation. In this patch I opt for what seems like the simplest solution, at the cost of a small amount of #ifdef noise. The unpacked descriptor grows a new test-only member that's used for dropping arbitrary data in at encode time. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-24Merge branch 'tor-gitlab/mr/703'David Goulet
2023-05-11test_crypto: avoid memory leak in some hashx test failuresMicah Elizabeth Scott
This should fix one of the warnings in issue #40792. I was sloppy with freeing memory in the failure cases for test_crypto_hashx. ASAN didn't notice but coverity did. Okay, I'll eat my vegetables and put hashx_ctx's deinit in an upper scope and use 'goto done' correctly like a properly diligent C programmer. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-11Fix unit tests.Mike Perry
2023-05-10hs_pow: Modify challenge format, include blinded HS idMicah Elizabeth Scott
This is a protocol breaking change that implements nickm's changes to prop 327 to add an algorithm personalization string and blinded HS id to the EquiX challenge string for our onion service client puzzle. This corresponds with the spec changes in torspec!130, and it fixes a proposed vulnerability documented in ticket tor#40789. Clients and services prior to this patch will no longer be compatible with the proposed "v1" proof-of-work protocol. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10hs_pow: client side effort adjustmentMicah Elizabeth Scott
The goal of this patch is to add an additional mechanism for adjusting PoW effort upwards, where clients rather than services can choose to solve their puzzles at a higher effort than what was suggested in the descriptor. I wanted to use hs_cache's existing unreachability stats to drive this effort bump, but this revealed some cases where a circuit (intro or rend) closed early on can end up in hs_cache with an all zero intro point key, where nobody will find it. This moves intro_auth_pk initialization earlier in a couple places and adds nonfatal asserts to catch the problem if it shows up elsewhere. The actual effort adjustment method I chose is to multiply the suggested effort by (1 + unresponsive_count), then ensure the result is at least 1. If a service has suggested effort of 0 but we fail to connect, retries will all use an effort of 1. If the suggestion was 50, we'll try 50, 100, 150, 200, etc. This is bounded both by our client effort limit and by the limit on unresponsive_count (currently 5). Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10hs_pow: leak fix, free the contents of pqueue entries in ↵Micah Elizabeth Scott
hs_pow_free_service_state Asan catches this pretty readily when ending a service gracefully while a DoS is in progress and the queue is full of items that haven't yet timed out. The module boundaries in hs_circuit are quite fuzzy here, but I'm trying to follow the vibe of the existing hs_pow code. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10hs_pow: Represent equix_solution as a byte arrayMicah Elizabeth Scott
This patch is intended to clarify the points at which we convert between the internal representation of an equix_solution and a portable but opaque byte array representation. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10hs_pow: Fix nonce cache entry leakMicah Elizabeth Scott
This leak was showing up in address sanitizer runs of test_hs_pow, but it will also happen during normal operation as seeds are rotated. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10hs_pow: Define seed_head as uint8_t[4] instead of uint32_tMicah Elizabeth Scott
This is more consistent with the specification, and it's much less confusing with endianness. This resolves the underlying cause of the earlier byte-swap. This patch itself does not change the wire protocol at all, it's just tidying up the types we use at the trunnel layer. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10hs_pow: Don't require uint128_tMicah Elizabeth Scott
We were using a native uint128_t to represent the hs_pow nonce, but as the comments note it's more portable and more flexible to use a byte array. Indeed the uint128_t was a problem for 32-bit platforms. This swaps in a new implementation that uses multiple machine words to implement the nonce incrementation. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10hs_pow: unswap byte order of seed_head fieldMicah Elizabeth Scott
In proposal 327, "POW_SEED is the first 4 bytes of the seed used". The proposal doesn't specifically mention the data type of this field, and the code in hs_pow so far treats it as an integer but semantically it's more like the first four bytes of an already-encoded little endian blob. This leads to a byte swap, since the type confusion takes place in a little-endian subsystem but the wire encoding of seed_head uses tor's default of big endian. This patch does not address the underlying type confusion, it's a minimal change that only swaps the byte order and updates unit tests accordingly. Further changes will clean up the data types. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10test_hs_pow: add test vectors for our hs_pow client puzzleMicah Elizabeth Scott
This adds test vectors for the overall client puzzle at the hs_pow and hs_cell layers. These are similar to the crypto/equix tests, but they also cover particulars of our hs_pow format like the conversion to byte arrays, the replay cache, the effort test, and the formatting of the equix challenge string. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10hs_pow: Replace libb2 dependency with hashx's internal blake2Micah Elizabeth Scott
This forgoes another external library dependency, and instead introduces a compatibility header so that interested parties (who already depend on equix, like hs_pow and unit tests) can use the implementation of blake2b included in hashx. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10test_crypto: add equix and hashx testsMicah Elizabeth Scott
This adds test vectors for the Equi-X proof of work algorithm and the Hash-X function it's based on. The overall Equi-X test takes about 10 seconds to run on my machine, so it's in test_crypto_slow. The hashx test still covers both the compiled and interpreted versions of the hash function. There aren't any official test vectors for Equi-X or for its particular configuration of Hash-X, so I made some up based on the current implementation. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10test_crypto: add blake2b test vectorsMicah Elizabeth Scott
I'm planning on swapping blake2b implementations, and this test is intended to prevent regressions. Right now blake2b is only used by hs_pow. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10hs_pow: Make proof-of-work support optional in configureMicah Elizabeth Scott
This adds a new "pow" module for the user-visible proof of work support in ./configure, and this disables src/feature/hs/hs_pow at compile-time. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10hs_metrics: Proof of Work pqueue depth, suggested effortMicah Elizabeth Scott
Adds two new metrics for hs_pow, and an internal parameter within hs_metrics for implementing gauge parameters that reset before every update. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10pass time around as a parameterRoger Dingledine
should help with unit testing
2023-05-10hs: Priority queue for rendezvous requestsDavid Goulet
If PoW are enabled, use a priority queue by effort for the rendezvous requests hooked into the mainloop. Signed-off-by: David Goulet <dgoulet@torproject.org>
2023-05-10hs: Client now solve PoW if presentDavid Goulet
At this commit, the tor main loop solves it. We might consider moving this to the CPU pool at some point. Signed-off-by: David Goulet <dgoulet@torproject.org>
2023-05-10hs: Add solve and verify PoW functionsDavid Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2023-04-06Prop#329 Tests: Add tests for the conflux poolMike Perry