aboutsummaryrefslogtreecommitdiff
path: root/src/core/or/sendme.c
AgeCommit message (Collapse)Author
2020-07-29Remove the connection_t.outbuf_flushlen fieldNick Mathewson
This was once used for rate-limiting, but now it's only for accounting. It hasn't served a useful purpose in a long time. Closes ticket 33097.
2020-05-06Use __attribute__((fallthrough)) rather than magic GCC comments.Nick Mathewson
GCC added an implicit-fallthrough warning a while back, where it would complain if you had a nontrivial "case:" block that didn't end with break, return, or something like that. Clang recently added the same thing. GCC, however, would let you annotate a fall-through as intended by any of various magic "/* fall through */" comments. Clang, however, only seems to like "__attribute__((fallthrough))". Fortunately, GCC accepts that too. A previous commit in this branch defined a FALLTHROUGH macro to do the right thing if GNUC is defined; here we replace all of our "fall through" comments with uses of that macro. This is an automated commit, made with the following perl one-liner: #!/usr/bin/perl -i -p s#/\* *falls? ?thr.*?\*/#FALLTHROUGH;#i; (In order to avoid conflicts, I'm applying this script separately to each maint branch. This is the 0.4.3 version.)
2020-01-08It's 2020. Update the copyright dates with "make update-copyright"Nick Mathewson
2019-06-11trunnel: Rename sendme.trunnel to sendme_cell.trunnelDavid Goulet
This is to avoid having two sendme.{c|h} in the repository since the subsystem is implemented in src/core/or/sendme.{c|h}. Fixes #30769 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-06-03sendme: Do not decrement window in a log_debug()David Goulet
If "Log debug ..." is not set, the decrement never happens. This lead to the package/deliver window to be out of sync at the stream level and thus breaking the connection after 50+ cells. Fixes #30628 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-05-22Merge branch 'ticket30428_041_02_squashed'Nick Mathewson
2019-05-22sendme: Add non fatal asserts for extra safetyDavid Goulet
Two non fatal asserts are added in this commit. First one is to see if the SENDME digest list kept on the circuit for validation ever grows bigger than the maximum number of expected SENDME on a circuit (currently 10). The second one is to know if we ever send more than one SENDME at a time on a circuit. In theory, we shouldn't but if we ever do, the v1 implementation wouldn't work because we only keep one single cell digest (the previous cell to the SENDME) on the circuit/cpath. Thus, sending two SENDME consecutively will lead to a mismatch on the other side because the same cell digest would be use and thus the circuit would collapse. Finally, add an extra debug log in case we emit a v0 which also includes the consensus emit version in that case. Part of #30428 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-05-22sendme: Always pop last SENDME digest from circuitDavid Goulet
We must not accumulate digests on the circuit if the other end point is using another SENDME version that is not using those digests like v0. This commit makes it that we always pop the digest regardless of the version. Part of #30428 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-05-22sendme: Clarify how sendme_circuit_cell_is_next() worksDavid Goulet
Commit 4ef8470fa5480d3b was actually reverted before because in the end we needed to do this minus 1 check on the window. This commit clarifies that in the code, takes the useful comment changes from 4ef8470fa5480d3b and makes sendme_circuit_cell_is_next() private since it behaves in a very specific way that one external caller might expect. Part of #30428. Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-05-22sendme: Properly record SENDMEs on both edgesDavid Goulet
Turns out that we were only recording the "b_digest" but to have bidirectionnal authenticated SENDMEs, we need to use the "f_digest" in the forward cell situation. Because of the cpath refactoring, this commit plays with the crypt_path_ and relay_crypto_t API a little bit in order to respect the abstractions. Previously, we would record the cell digest as the SENDME digest in the decrypt cell function but to avoid code duplication (both directions needs to record), we now do that right after iff the cell is recognized (at the edge). It is now done in circuit_receive_relay_cell() instead. We now also record the cell digest as the SENDME digest in both relay cell encryption functions since they are split depending on the direction. relay_encrypt_cell_outbound() and relay_encrypt_cell_inbound() need to consider recording the cell digest depending on their direction (f vs b digest). Fixes #30428 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-05-22sendme: Never fallback to v0 if unknown versionDavid Goulet
There was a missing cell version check against our max supported version. In other words, we do not fallback to v0 anymore in case we do know the SENDME version. We can either handle it or not, never fallback to the unauthenticated version in order to avoid gaming the authenticated logic. Add a unit tests making sure we properly test that and also test that we can always handle the default emit and accepted versions. Fixes #30428 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-05-22sendme: Validate v1 SENDMEs on both client and exit sideDavid Goulet
The validation of the SENDME cell is now done as the very first thing when receiving it for both client and exit. On failure to validate, the circuit is closed as detailed in the specification. Part of #30428 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-05-22sendme: Record cell digest on both client and exitDavid Goulet
It turns out that only the exit side is validating the authenticated SENDME v1 logic and never the client side. Which means that if a client ever uploaded data towards an exit, the authenticated SENDME logic wouldn't apply. For this to work, we have to record the cell digest client side as well which introduced a new function that supports both type of edges. This also removes a test that is not valid anymore which was that we didn't allow cell recording on an origin circuit (client). Part of #30428 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-05-15fix typos, whitespace, commentsRoger Dingledine
2019-05-13sendme: Fix coverity CID 1444999David Goulet
The code flow in theory can end up with a layer_hint to be NULL but in practice it should never happen because with an origin circuit, we must have the layer_hint. Just in case, BUG() on it if we ever end up in this situation and recover by closing the circuit. Fixes #30467. Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-05-03Hiding crypt_path_t: Hide 'crypto' usage in sendme.cGeorge Kadianakis
2019-05-02sendme: Improve logging messagesDavid Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29sendme: Do not poke at crypto.sendme_digest directlyDavid Goulet
As per review from nickm, keep as much as we can the relay_crypto_t object opaque. Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29sendme: Better function namesDavid Goulet
From nickm's review, improve the names of some functions. Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29sendme: Move note_cell_digest() to relay_crypto moduleDavid Goulet
Because this function is poking within the relay_crypto_t object, move the function to the module so we can keep it opaque as much as possible. Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29sendme: Add helper to note the cell digestDavid Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29sendme: Helper to know if next cell is a SENDMEDavid Goulet
We'll use it this in order to know when to hash the cell for the SENDME instead of doing it at every cell. Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29prop289: Keep the digest bytes, not the objectDavid Goulet
The digest object is as large as the entire internal digest object's state, which is often much larger than the actual set of bytes you're transmitting. This commit makes it that we keep the digest itself which is 20 bytes. Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29prop289: Move digest matching in its own functionDavid Goulet
No behavior change but code had to be refactored a bit. Also, the tor_memcmp() was changed to tor_memneq(). Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29prop289: Rename packaged functions with better nameDavid Goulet
The circuit and stream level functions that update the package window have been renamed to have a "_note_" in them to make their purpose more clear. Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29prop289: Use a 20 bytes digest instead of 4David Goulet
To achieve such, this commit also changes the trunnel declaration to use a union instead of a seperate object for the v1 data. A constant is added for the digest length so we can use it within the SENDME code giving us a single reference. Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29tests: Implement unit tests for SENDME v1David Goulet
Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29prop289: Remember the last cell digest for v1 SENDMEsDavid Goulet
In order to do so, depending on where the cell is going, we'll keep the last cell digest that is either received inbound or sent outbound. Then it can be used for validation. Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29prop289: Match the SENDME digestDavid Goulet
Now that we keep the last seen cell digests on the Exit side on the circuit object, use that to match the SENDME v1 transforming this whole process into a real authenticated SENDME mechanism. Part of #26841 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29prop289: Keep track of the last seen cell digestsDavid Goulet
This makes tor remember the last seen digest of a cell if that cell is the last one before a SENDME on the Exit side. Closes #26839 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29prop289: Support SENDME v1 cell parsingDavid Goulet
This commit makes tor able to parse and handle a SENDME version 1. It will look at the consensus parameter "sendme_accept_min_version" to know what is the minimum version it should look at. IMPORTANT: At this commit, the validation of the cell is not fully implemented. For this, we need #26839 to be completed that is to match the SENDME digest with the last cell digest. Closes #26841 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29prop289: Support sending SENDME version 1David Goulet
This code will obey the consensus parameter "sendme_emit_min_version" to know which SENDME version it should send. For now, the default is 0 and the parameter is not yet used in the consensus. This commit adds the support to send version 1 SENDMEs but aren't sent on the wire at this commit. Closes #26840 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29prop289: Add two consensus parametersDavid Goulet
In order to be able to deploy the authenticated SENDMEs, these two consensus parameters are needed to control the minimum version that we can emit and accept. See section 4 in prop289 for more details. Note that at this commit, the functions that return the values aren't used so compilation fails if warnings are set to errors. Closes #26842 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29sendme: Add helper functions for DATA cell packagingDavid Goulet
When we are about to send a DATA cell, we have to decrement the package window for both the circuit and stream level. This commit adds helper functions to handle the package window decrement. Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29sendme: Add helper functions for DATA cell deliveryDavid Goulet
When we get a relay DATA cell delivered, we have to decrement the deliver window on both the circuit and stream level. This commit adds helper functions to handle the deliver window decrement. Part of #26840 Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29sendme: Refactor SENDME cell processingDavid Goulet
This is a bit of a complicated commit. It moves code but also refactors part of it. No behavior change, the idea is to split things up so we can better handle and understand how SENDME cells are processed where ultimately it will be easier to handle authenticated SENDMEs (prop289) using the intermediate functions added in this commit. The entry point for the cell arriving at the edge (Client or Exit), is connection_edge_process_relay_cell() for which we look if it is a circuit or stream level SENDME. This commit refactors that part where two new functions are introduced to process each of the SENDME types. The sendme_process_circuit_level() has basically two code paths. If we are a Client (the circuit is origin) or we are an Exit. Depending on which, the package window is updated accordingly. Then finally, we resume the reading on every edge streams on the circuit. The sendme_process_stream_level() applies on the edge connection which will update the package window if needed and then will try to empty the inbuf if need be because we can now deliver more cells. Again, no behavior change but in order to split that code properly into their own functions and outside the relay.c file, code modification was needed. Part of #26840. Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29sendme: Modernize and cleanup old moved codeDavid Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-04-29sendme: Move code to the new files sendme.{c|h}David Goulet
Take apart the SENDME cell specific code and put it in sendme.{c|h}. This is part of prop289 that implements authenticated SENDMEs. Creating those new files allow for the already huge relay.c to not grow in LOC and makes it easier to handle and test the SENDME cells in an isolated way. This commit only moves code. No behavior change. Signed-off-by: David Goulet <dgoulet@torproject.org>