Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3569 part 1: Rework SOCKS5 server code with trunnel #180

Closed
wants to merge 39 commits into from

Conversation

Labels
None yet
Projects
None yet
2 participants
@rl1987
Copy link
Contributor

@rl1987 rl1987 commented Jun 26, 2018

https://trac.torproject.org/projects/tor/ticket/3569

Copy link
Contributor

@nmathewson nmathewson left a comment

Hi! This branch is looking very nice! I have a few small suggestions and requests.

Also, please ignore any comments that you addressed later in your branch. There are a lot of times when I said "this needs documentation" and later you documented it.
Also, please ignore any comments that you addressed later in your branch. There are a lot of times when I said "this needs documentation" and later you documented it.

u32 addr;
}

// And here's the extended stuff from proposal 229
Copy link
Contributor

@nmathewson nmathewson Jun 26, 2018

Let's remove this stuff: we probably are not going to implement proposal 229.

Copy link
Contributor Author

@rl1987 rl1987 Jun 26, 2018

Removed in 055840a.

@@ -85,6 +86,138 @@ socks_request_free_(socks_request_t *req)
tor_free(req);
}

static int
Copy link
Contributor

@nmathewson nmathewson Jun 26, 2018

There should be a documentation comment for this function (and all new functions).

socks4_client_request_t *trunnel_req;

ssize_t parsed =
socks4_client_request_parse(&trunnel_req, (const uint8_t *)raw_data,
Copy link
Contributor

@nmathewson nmathewson Jun 26, 2018

The cast on this line is unnecessary

Copy link
Contributor Author

@rl1987 rl1987 Jun 26, 2018

Fixed (4588211).

goto end;
} else if (parsed == -2) {
res = 0;
if (datalen > 1024) { // XXX
Copy link
Contributor

@nmathewson nmathewson Jun 26, 2018

This should be a named constant, and the warning should probably be different.

Copy link
Contributor Author

@rl1987 rl1987 Jun 26, 2018

No longer comparing datalen to 1024 anywhere in proto_socks.c. Comparing to MAX_SOCKS_MESSAGE_LEN (512 bytes) instead.

if (*is_socks4a) {
// We cannot rely on trunnel here, as we want to detect if
// we have abnormally long hostname field.
char *hostname = (char *)raw_data + SOCKS4_NETWORK_LEN +
Copy link
Contributor

@nmathewson nmathewson Jun 26, 2018

This should use "parsed" instead -- that should tell us the number of bytes that trunnel consumed.

Copy link
Contributor

@nmathewson nmathewson Jun 26, 2018

Also, it should be a const char*, since we don't plan to change it.

Copy link
Contributor Author

@rl1987 rl1987 Jun 26, 2018

To detect hostnames that are overly long (one of the testcases is test_socks.c), we cannot generally rely on trunnel, as it will report failure on entire message. That's the reason for doing this workaround here.

Added const in 5785007.

@@ -433,11 +433,134 @@ process_socks5_userpass_auth(socks_request_t *req)
return res;
}

static int
Copy link
Contributor

@nmathewson nmathewson Jun 26, 2018

Needs documentation.

goto end;
}

*drain_out = (size_t)parsed;
Copy link
Contributor

@nmathewson nmathewson Jun 26, 2018

Add assertion; initialize to 0.

Copy link
Contributor Author

@rl1987 rl1987 Jun 26, 2018

Fixed.

}

static int
process_socks5_client_request(socks_request_t *req,
Copy link
Contributor

@nmathewson nmathewson Jun 26, 2018

Can this argument become const?

Needs docs.

Copy link
Contributor Author

@rl1987 rl1987 Jun 26, 2018

But we may call socks_request_set_socks5_error on this req... Doesn't that violate semantics of const?

@@ -477,8 +600,8 @@ handle_socks_message(const uint8_t *raw_data, size_t datalen, socks_request_t *r
goto end;
}
/* RFC1929 SOCKS5 username/password subnegotiation. */
if ((!req->got_auth && raw_data[0] == 1) ||
req->auth_type == SOCKS_USER_PASS) {
if (!req->got_auth && (raw_data[0] == 1 ||
Copy link
Contributor

@nmathewson nmathewson Jun 26, 2018

I don't understand the reasoning behind this change?

Copy link
Contributor Author

@rl1987 rl1987 Jun 26, 2018

I don't remember exactly, but it has something to do with how our implicit SOCKS FSM works. If I change it back, 5_authenticate_with_data starts failing.

This code will go away when we rework our SOCKS implementation to function like an explicit state machine.

case SOCKS_RESULT_DONE:
res = 1;
break;
case SOCKS_RESULT_TRUNCATED:
Copy link
Contributor

@nmathewson nmathewson Jun 26, 2018

This should have a "falls through" comment so GCC doesn't complain.

Copy link
Contributor Author

@rl1987 rl1987 Jun 26, 2018

Fixed in 90f6153.

@rl1987 rl1987 closed this Jul 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment