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

feat: add support for SOCKS5 proxy #1063

Merged
merged 42 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d65feb1
Added socks5_proxy to options
JoshuaMoelans Oct 29, 2024
e9b61a6
correct options freeing
JoshuaMoelans Oct 29, 2024
b3f8c76
Update CHANGELOG.md
JoshuaMoelans Oct 30, 2024
ca44621
Add socks5_proxy attribute to curl_transport_state
JoshuaMoelans Oct 30, 2024
3287b64
formatting
JoshuaMoelans Oct 30, 2024
ad6ef46
refactor to use single proxy attribute
JoshuaMoelans Oct 30, 2024
50b57fb
format
JoshuaMoelans Oct 30, 2024
f9fea04
Added back deprecated http_proxy API
JoshuaMoelans Oct 30, 2024
5ce42fb
formatting
JoshuaMoelans Oct 30, 2024
11bedad
refactor sentry_transport_winhttp.c to use opts->proxy
JoshuaMoelans Oct 30, 2024
2e45f63
formatting
JoshuaMoelans Oct 30, 2024
f31f7d5
Merge branch 'master' into feat/socks5_proxy_joshua
JoshuaMoelans Nov 12, 2024
c21416a
Merge branch 'master' into feat/socks5_proxy_joshua
JoshuaMoelans Nov 12, 2024
ac09ba7
update crashpad dependency
JoshuaMoelans Nov 13, 2024
9922815
fix: update minimum libcurl version check to 7.21.7
JoshuaMoelans Nov 13, 2024
498dc94
update crashpad dependency
JoshuaMoelans Nov 13, 2024
f44dad6
test: add proxy integration tests
JoshuaMoelans Nov 14, 2024
df77a14
get latest crashpad changes
JoshuaMoelans Nov 14, 2024
eb0a2b8
feat: add example.c run-args for http and socks5 proxy
JoshuaMoelans Nov 14, 2024
56df66e
test: changed test name + added more mitmdump startup time
JoshuaMoelans Nov 14, 2024
0ab5c68
chore: format
JoshuaMoelans Nov 14, 2024
20e611c
test: add mitmproxy to requirements.txt
JoshuaMoelans Nov 14, 2024
1d1f3d1
test: add skip for proxy test on non-MacOS platforms
JoshuaMoelans Nov 14, 2024
43805fd
test: move socksproxy-off assert into AssertionError check for Linux …
JoshuaMoelans Nov 15, 2024
e6bc54c
test: change expected http log length to match platform
JoshuaMoelans Nov 15, 2024
ae3ca77
test: order of operations
JoshuaMoelans Nov 15, 2024
63f2f58
test: run http proxy tests on all platforms
JoshuaMoelans Nov 15, 2024
1e0f1c8
test: add special case for Windows Autoproxy
JoshuaMoelans Nov 15, 2024
7233e44
apply suggestions from code review
JoshuaMoelans Nov 18, 2024
abca3c5
Merge branch 'master' into feat/socks5_proxy_joshua
JoshuaMoelans Nov 18, 2024
22982f8
chore: added comments about proxy behaviour
JoshuaMoelans Nov 20, 2024
8f02444
cleaned up test and moved comments to proper place
JoshuaMoelans Nov 20, 2024
a8877f7
chore: fix minor comment typo
JoshuaMoelans Nov 20, 2024
20c37ed
chore: added api documentation
JoshuaMoelans Nov 21, 2024
f5e6259
Update include/sentry.h
JoshuaMoelans Nov 21, 2024
a7c1af3
Update CONTRIBUTING.md
JoshuaMoelans Nov 21, 2024
7f50f6e
update crashpad submodule
JoshuaMoelans Nov 21, 2024
dfc6050
Merge remote-tracking branch 'origin/feat/socks5_proxy_joshua' into f…
JoshuaMoelans Nov 21, 2024
429fcfd
Merge branch 'master' into feat/socks5_proxy_joshua
JoshuaMoelans Nov 21, 2024
881c017
update crashpad submodule (again)
JoshuaMoelans Nov 21, 2024
140be40
updated CHANGELOG.md
JoshuaMoelans Nov 21, 2024
37d075c
updated CHANGELOG.md again
JoshuaMoelans Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

**Features**:
- Add SOCKS5 proxy support ([#1063](https://github.com/getsentry/sentry-native/pull/1063))

## 0.7.11

**Fixes**:
Expand Down
23 changes: 20 additions & 3 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -964,17 +964,34 @@ SENTRY_API void sentry_options_set_dist_n(
SENTRY_API const char *sentry_options_get_dist(const sentry_options_t *opts);

/**
* Configures the http proxy.
* Configures the proxy.
*
* The given proxy has to include the full scheme, eg. `http://some.proxy/`.
* The given proxy has to include the full scheme,
* eg. `http://some.proxy/`or 'socks5://some.proxy/'.
JoshuaMoelans marked this conversation as resolved.
Show resolved Hide resolved
*/
SENTRY_API void sentry_options_set_proxy(
sentry_options_t *opts, const char *proxy);
SENTRY_API void sentry_options_set_proxy_n(
sentry_options_t *opts, const char *proxy, size_t proxy_len);

/**
* Returns the configured proxy.
*/
SENTRY_API const char *sentry_options_get_proxy(const sentry_options_t *opts);

/**
* Configures the proxy.
*
* The given proxy has to include the full scheme,
* eg. `http://some.proxy/`or 'socks5://some.proxy/'.
*/
SENTRY_API void sentry_options_set_http_proxy(
sentry_options_t *opts, const char *proxy);
SENTRY_API void sentry_options_set_http_proxy_n(
sentry_options_t *opts, const char *proxy, size_t proxy_len);
JoshuaMoelans marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns the configured http proxy.
* Returns the configured proxy.
*/
SENTRY_API const char *sentry_options_get_http_proxy(
const sentry_options_t *opts);
Expand Down
7 changes: 4 additions & 3 deletions src/backends/sentry_backend_crashpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,10 @@ crashpad_backend_startup(
if (minidump_url) {
SENTRY_TRACEF("using minidump URL \"%s\"", minidump_url);
}
bool success = data->client->StartHandler(handler, database, database,
minidump_url ? minidump_url : "",
options->http_proxy ? options->http_proxy : "", annotations, arguments,
bool success = data->client->StartHandler(handler, database,
database, // TODO update to not only use http_proxy
JoshuaMoelans marked this conversation as resolved.
Show resolved Hide resolved
minidump_url ? minidump_url : "", options->proxy ? options->proxy : "",
annotations, arguments,
/* restartable */ true,
/* asynchronous_start */ false, attachments);
sentry_free(minidump_url);
Expand Down
31 changes: 25 additions & 6 deletions src/sentry_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ sentry_options_free(sentry_options_t *opts)
sentry_free(opts->user_agent);
sentry_free(opts->environment);
sentry_free(opts->dist);
sentry_free(opts->http_proxy);
sentry_free(opts->proxy);
sentry_free(opts->ca_certs);
sentry_free(opts->transport_thread_name);
sentry__path_free(opts->database_path);
Expand Down Expand Up @@ -234,25 +234,44 @@ sentry_options_get_dist(const sentry_options_t *opts)
return opts->dist;
}

void
sentry_options_set_proxy_n(
sentry_options_t *opts, const char *proxy, size_t proxy_len)
{
sentry_free(opts->proxy);
opts->proxy = sentry__string_clone_n(proxy, proxy_len);
}

void
sentry_options_set_proxy(sentry_options_t *opts, const char *proxy)
{
sentry_free(opts->proxy);
opts->proxy = sentry__string_clone(proxy);
}

const char *
sentry_options_get_proxy(const sentry_options_t *opts)
{
return opts->proxy;
}

void
sentry_options_set_http_proxy_n(
sentry_options_t *opts, const char *proxy, size_t proxy_len)
{
sentry_free(opts->http_proxy);
opts->http_proxy = sentry__string_clone_n(proxy, proxy_len);
sentry_options_set_proxy_n(opts, proxy, proxy_len);
}

void
sentry_options_set_http_proxy(sentry_options_t *opts, const char *proxy)
{
sentry_free(opts->http_proxy);
opts->http_proxy = sentry__string_clone(proxy);
sentry_options_set_proxy(opts, proxy);
}

const char *
sentry_options_get_http_proxy(const sentry_options_t *opts)
{
return opts->http_proxy;
return sentry_options_get_proxy(opts);
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef struct sentry_options_s {
char *release;
char *environment;
char *dist;
char *http_proxy;
char *proxy;
char *ca_certs;
char *transport_thread_name;
char *sdk_name;
Expand Down
10 changes: 5 additions & 5 deletions src/transports/sentry_transport_curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typedef struct curl_transport_state_s {
sentry_dsn_t *dsn;
CURL *curl_handle;
char *user_agent;
char *http_proxy;
char *proxy;
char *ca_certs;
sentry_rate_limiter_t *ratelimiter;
bool debug;
Expand Down Expand Up @@ -54,7 +54,7 @@ sentry__curl_bgworker_state_free(void *_state)
sentry__rate_limiter_free(state->ratelimiter);
sentry_free(state->ca_certs);
sentry_free(state->user_agent);
sentry_free(state->http_proxy);
sentry_free(state->proxy);
sentry_free(state);
}

Expand Down Expand Up @@ -101,7 +101,7 @@ sentry__curl_transport_start(
curl_bgworker_state_t *state = sentry__bgworker_get_state(bgworker);

state->dsn = sentry__dsn_incref(options->dsn);
state->http_proxy = sentry__string_clone(options->http_proxy);
state->proxy = sentry__string_clone(options->proxy);
state->user_agent = sentry__string_clone(options->user_agent);
state->ca_certs = sentry__string_clone(options->ca_certs);
state->curl_handle = curl_easy_init();
Expand Down Expand Up @@ -215,8 +215,8 @@ sentry__curl_send_task(void *_envelope, void *_state)
curl_easy_setopt(curl, CURLOPT_HEADERDATA, (void *)&info);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);

if (state->http_proxy) {
curl_easy_setopt(curl, CURLOPT_PROXY, state->http_proxy);
if (state->proxy) { // TODO do we need to process the proxy here?
supervacuus marked this conversation as resolved.
Show resolved Hide resolved
JoshuaMoelans marked this conversation as resolved.
Show resolved Hide resolved
curl_easy_setopt(curl, CURLOPT_PROXY, state->proxy);
}
if (state->ca_certs) {
curl_easy_setopt(curl, CURLOPT_CAINFO, state->ca_certs);
Expand Down
6 changes: 3 additions & 3 deletions src/transports/sentry_transport_winhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ sentry__winhttp_transport_start(
sentry__bgworker_setname(bgworker, opts->transport_thread_name);

// ensure the proxy starts with `http://`, otherwise ignore it
if (opts->http_proxy
&& strstr(opts->http_proxy, "http://") == opts->http_proxy) {
const char *ptr = opts->http_proxy + 7;
if (opts->proxy
&& strstr(opts->proxy, "http://") == opts->proxy) {
const char *ptr = opts->proxy + 7;
const char *slash = strchr(ptr, '/');
if (slash) {
char *copy = sentry__string_clone_n(ptr, slash - ptr);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_uninit.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ SENTRY_TEST(invalid_dsn)
SENTRY_TEST(invalid_proxy)
{
sentry_options_t *options = sentry_options_new();
sentry_options_set_http_proxy(options, "invalid");
sentry_options_set_proxy(options, "invalid");

TEST_CHECK(sentry_init(options) == 0);

Expand Down
Loading