From 9f738be8937d675929b43a149d706160641a089d Mon Sep 17 00:00:00 2001 From: David Goulet Date: Wed, 29 May 2019 14:05:16 -0400 Subject: hs: Limit the amount of relayed INTRODUCE2 This commit add the hs_dos.{c|h} file that has the purpose of having the anti-DoS code for onion services. At this commit, it only has one which is a function that decides if an INTRODUCE2 can be sent on the given introduction service circuit (S<->IP) using a simple token bucket. The rate per second is 25 and allowed burst to 200. Basic defenses on #15516. Signed-off-by: David Goulet --- src/feature/rend/rendmid.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/feature/rend/rendmid.c') diff --git a/src/feature/rend/rendmid.c b/src/feature/rend/rendmid.c index 849f355990..192da166ee 100644 --- a/src/feature/rend/rendmid.c +++ b/src/feature/rend/rendmid.c @@ -18,6 +18,7 @@ #include "feature/rend/rendmid.h" #include "feature/stats/rephist.h" #include "feature/hs/hs_circuitmap.h" +#include "feature/hs/hs_dos.h" #include "feature/hs/hs_intropoint.h" #include "core/or/or_circuit_st.h" @@ -180,6 +181,14 @@ rend_mid_introduce_legacy(or_circuit_t *circ, const uint8_t *request, goto err; } + /* Before sending, lets make sure this cell can be sent on the service + * circuit asking the DoS defenses. */ + if (!hs_dos_can_send_intro2(intro_circ)) { + log_info(LD_PROTOCOL, "Can't relay INTRODUCE1 v2 cell due to DoS " + "limitations. Sending NACK to client."); + goto err; + } + log_info(LD_REND, "Sending introduction request for service %s " "from circ %u to circ %u", -- cgit v1.2.3-54-g00ecf