Skip to content

Commit 857ece7

Browse files
authored
Merge d9ae05d into af1b255
2 parents af1b255 + d9ae05d commit 857ece7

File tree

8 files changed

+108
-6
lines changed

8 files changed

+108
-6
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
**Features**:
1010

1111
- Add support for Profiling feature. ([#479](https://github.com/getsentry/sentry-rust/pull/479))
12+
- Add `SSL_VERIFY` option to disable certificates verification. ([#508](https://github.com/getsentry/sentry-rust/pull/508))
1213

1314
**Internal**:
1415

Diff for: sentry-core/src/clientoptions.rs

+8
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ pub struct ClientOptions {
128128
/// The timeout on client drop for draining events on shutdown.
129129
pub shutdown_timeout: Duration,
130130
// Other options not documented in Unified API
131+
/// Disable SSL verification.
132+
///
133+
/// # Warning
134+
///
135+
/// This introduces significant vulnerabilities, and should only be used as a last resort.
136+
pub accept_invalid_certs: bool,
131137
/// Enable Release Health Session tracking.
132138
///
133139
/// When automatic session tracking is enabled, a new "user-mode" session
@@ -206,6 +212,7 @@ impl fmt::Debug for ClientOptions {
206212
.field("http_proxy", &self.http_proxy)
207213
.field("https_proxy", &self.https_proxy)
208214
.field("shutdown_timeout", &self.shutdown_timeout)
215+
.field("accept_invalid_certs", &self.accept_invalid_certs)
209216
.field("auto_session_tracking", &self.auto_session_tracking)
210217
.field("session_mode", &self.session_mode)
211218
.field("extra_border_frames", &self.extra_border_frames)
@@ -240,6 +247,7 @@ impl Default for ClientOptions {
240247
http_proxy: None,
241248
https_proxy: None,
242249
shutdown_timeout: Duration::from_secs(2),
250+
accept_invalid_certs: false,
243251
auto_session_tracking: false,
244252
session_mode: SessionMode::Application,
245253
extra_border_frames: vec![],

Diff for: sentry/Cargo.toml

+10-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ transport = ["reqwest", "native-tls"]
4545
reqwest = ["reqwest_", "httpdate", "tokio"]
4646
curl = ["curl_", "httpdate"]
4747
surf-h1 = ["surf_/h1-client", "httpdate"]
48-
surf = ["surf_/curl-client", "httpdate", "tokio"]
49-
native-tls = ["reqwest_/default-tls"]
50-
rustls = ["reqwest_/rustls-tls"]
51-
ureq = ["ureq_/tls", "httpdate"]
52-
ureq-native-tls = ["ureq_/native-tls", "httpdate"]
48+
surf = ["surf_/curl-client", "http-client", "httpdate", "isahc", "tokio"]
49+
native-tls = ["reqwest_/default-tls", "native-tls_", "ureq-native-tls"]
50+
rustls = ["reqwest_/rustls-tls", "rustls_", "webpki-roots"]
51+
ureq = ["ureq_/tls", "httpdate", "rustls_", "webpki-roots"]
52+
ureq-native-tls = ["ureq_/native-tls", "httpdate", "native-tls_"]
5353

5454
[dependencies]
5555
sentry-core = { version = "0.27.0", path = "../sentry-core", features = ["client"] }
@@ -67,9 +67,14 @@ reqwest_ = { package = "reqwest", version = "0.11", optional = true, features =
6767
curl_ = { package = "curl", version = "0.4.25", optional = true }
6868
httpdate = { version = "1.0.0", optional = true }
6969
surf_ = { package = "surf", version = "2.0.0", optional = true, default-features = false }
70+
http-client = { version = "6.5.3", optional = true }
71+
isahc = { version = "0.9.14", optional = true }
7072
serde_json = { version = "1.0.48", optional = true }
7173
tokio = { version = "1.0", features = ["rt"], optional = true }
7274
ureq_ = { package = "ureq", version = "2.3.0", optional = true, default-features = false }
75+
native-tls_ = { package = "native-tls", version = "0.2.8", optional = true }
76+
rustls_ = { package = "rustls", version = "0.20.6", optional = true, features = ["dangerous_configuration"] }
77+
webpki-roots = { version = "0.22.5", optional = true }
7378

7479
[dev-dependencies]
7580
sentry-anyhow = { path = "../sentry-anyhow" }

Diff for: sentry/src/defaults.rs

+3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ pub fn apply_defaults(mut opts: ClientOptions) -> ClientOptions {
113113
.or_else(|| std::env::var("https_proxy").ok().map(Cow::Owned))
114114
.or_else(|| opts.http_proxy.clone());
115115
}
116+
if let Ok(accept_invalid_certs) = std::env::var("SSL_VERIFY") {
117+
opts.accept_invalid_certs = !accept_invalid_certs.parse().unwrap_or(true);
118+
}
116119
opts
117120
}
118121

Diff for: sentry/src/transports/curl.rs

+6
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ impl CurlHttpTransport {
3535
let auth = dsn.to_auth(Some(&user_agent)).to_string();
3636
let url = dsn.envelope_api_url().to_string();
3737
let scheme = dsn.scheme();
38+
let accept_invalid_certs = options.accept_invalid_certs;
3839

3940
let mut handle = client;
4041
let thread = TransportThread::new(move |envelope, rl| {
4142
handle.reset();
4243
handle.url(&url).unwrap();
4344
handle.custom_request("POST").unwrap();
4445

46+
if accept_invalid_certs {
47+
handle.ssl_verify_host(false).unwrap();
48+
handle.ssl_verify_peer(false).unwrap();
49+
}
50+
4551
match (scheme, &http_proxy, &https_proxy) {
4652
(Scheme::Https, _, &Some(ref proxy)) => {
4753
if let Err(err) = handle.proxy(proxy) {

Diff for: sentry/src/transports/reqwest.rs

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ impl ReqwestHttpTransport {
3232
fn new_internal(options: &ClientOptions, client: Option<ReqwestClient>) -> Self {
3333
let client = client.unwrap_or_else(|| {
3434
let mut builder = reqwest_::Client::builder();
35+
if options.accept_invalid_certs {
36+
builder = builder.danger_accept_invalid_certs(true);
37+
}
3538
if let Some(url) = options.http_proxy.as_ref() {
3639
match Proxy::http(url.as_ref()) {
3740
Ok(proxy) => {

Diff for: sentry/src/transports/surf.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use std::time::Duration;
22

3+
use isahc::{
4+
config::{Configurable, SslOption},
5+
HttpClient,
6+
};
37
use surf_::{http::headers as SurfHeaders, Client as SurfClient, StatusCode};
48

59
use super::tokio_thread::TransportThread;
@@ -28,7 +32,20 @@ impl SurfHttpTransport {
2832
}
2933

3034
fn new_internal(options: &ClientOptions, client: Option<SurfClient>) -> Self {
31-
let client = client.unwrap_or_else(SurfClient::new);
35+
let client = if let Some(client) = client {
36+
client
37+
} else {
38+
let mut http_client = http_client::isahc::IsahcClient::new();
39+
if options.accept_invalid_certs {
40+
let hc = HttpClient::builder()
41+
.ssl_options(SslOption::DANGER_ACCEPT_INVALID_CERTS)
42+
.build()
43+
.unwrap();
44+
http_client = http_client::isahc::IsahcClient::from_client(hc);
45+
}
46+
SurfClient::with_http_client(http_client)
47+
};
48+
3249
let dsn = options.dsn.as_ref().unwrap();
3350
let user_agent = options.user_agent.to_owned();
3451
let auth = dsn.to_auth(Some(&user_agent)).to_string();

Diff for: sentry/src/transports/ureq.rs

+59
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
use std::sync::Arc;
12
use std::time::Duration;
3+
#[cfg(feature = "rustls")]
4+
use std::time::SystemTime;
25

6+
#[cfg(feature = "native-tls")]
7+
use native_tls_::TlsConnector;
8+
#[cfg(feature = "rustls")]
9+
use rustls_::{
10+
client::{ServerCertVerified, ServerCertVerifier},
11+
Certificate, ClientConfig, Error, OwnedTrustAnchor, RootCertStore, ServerName,
12+
};
313
#[cfg(doc)]
414
use ureq_ as ureq;
515
use ureq_::{Agent, AgentBuilder, Proxy};
16+
#[cfg(feature = "rustls")]
17+
use webpki_roots::TLS_SERVER_ROOTS;
618

719
use super::thread::TransportThread;
820

@@ -33,6 +45,53 @@ impl UreqHttpTransport {
3345
let agent = agent.unwrap_or_else(|| {
3446
let mut builder = AgentBuilder::new();
3547

48+
if options.accept_invalid_certs {
49+
#[cfg(feature = "native-tls")]
50+
{
51+
let tls_connector = TlsConnector::builder()
52+
.danger_accept_invalid_certs(true)
53+
.build()
54+
.unwrap();
55+
builder = builder.tls_connector(Arc::new(tls_connector));
56+
}
57+
58+
#[cfg(feature = "rustls")]
59+
{
60+
struct NoVerifier;
61+
62+
impl ServerCertVerifier for NoVerifier {
63+
fn verify_server_cert(
64+
&self,
65+
_end_entity: &Certificate,
66+
_intermediates: &[Certificate],
67+
_server_name: &ServerName,
68+
_scts: &mut dyn Iterator<Item = &[u8]>,
69+
_ocsp_response: &[u8],
70+
_now: SystemTime,
71+
) -> Result<ServerCertVerified, Error> {
72+
Ok(ServerCertVerified::assertion())
73+
}
74+
}
75+
76+
let mut root_store = RootCertStore::empty();
77+
root_store.add_server_trust_anchors(TLS_SERVER_ROOTS.0.iter().map(|ta| {
78+
OwnedTrustAnchor::from_subject_spki_name_constraints(
79+
ta.subject,
80+
ta.spki,
81+
ta.name_constraints,
82+
)
83+
}));
84+
let mut config = ClientConfig::builder()
85+
.with_safe_defaults()
86+
.with_root_certificates(root_store)
87+
.with_no_client_auth();
88+
config
89+
.dangerous()
90+
.set_certificate_verifier(Arc::new(NoVerifier));
91+
builder = builder.tls_config(Arc::new(config));
92+
}
93+
}
94+
3695
match (scheme, &options.http_proxy, &options.https_proxy) {
3796
(Scheme::Https, _, &Some(ref proxy)) => match Proxy::new(proxy) {
3897
Ok(proxy) => {

0 commit comments

Comments
 (0)