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

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
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/'.
*/
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);

/**
* 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
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?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curl supports socks-proxies since https://curl.se/ch/7.21.7.html ; our minimum required version is currently 7.10.7 -> This might need to be updated to ensure socks-proxies work.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be aware that we have a runtime and a compile-time check for libcurl.

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