Skip to content

Commit 3da348e

Browse files
committed
DRAFT: Add support to http.sslVerify
1 parent 5d8b5f4 commit 3da348e

File tree

7 files changed

+56
-30
lines changed

7 files changed

+56
-30
lines changed

gix-transport/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ base64 = { version = "0.21.0", optional = true }
7878
curl = { version = "0.4", optional = true }
7979

8080
# for http-client-reqwest
81-
reqwest = { version = "0.11.12", optional = true, default-features = false, features = ["blocking"] }
81+
reqwest = { version = "0.11.12", optional = true, default-features = false, features = ["blocking", "rustls-tls"] }
8282

8383
## If used in conjunction with `async-client`, the `connect()` method will become available along with supporting the git protocol over TCP,
8484
## where the TCP stream is created using this crate.

gix-transport/src/client/blocking_io/http/curl/remote.rs

+3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub fn new() -> (
157157
verbose,
158158
ssl_ca_info,
159159
ssl_version,
160+
ssl_verify,
160161
http_version,
161162
backend,
162163
},
@@ -194,6 +195,8 @@ pub fn new() -> (
194195
}
195196
}
196197

198+
handle.ssl_verify_peer(ssl_verify)?;
199+
197200
if let Some(http_version) = http_version {
198201
let version = match http_version {
199202
HttpVersion::V1_1 => curl::easy::HttpVersion::V11,

gix-transport/src/client/blocking_io/http/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ pub struct Options {
179179
pub ssl_ca_info: Option<PathBuf>,
180180
/// The SSL version or version range to use, or `None` to let the TLS backend determine which versions are acceptable.
181181
pub ssl_version: Option<SslVersionRangeInclusive>,
182+
/// Controls whether to perform ssl identity verification or not
183+
pub ssl_verify: bool,
182184
/// The HTTP version to enforce. If unset, it is implementation defined.
183185
pub http_version: Option<HttpVersion>,
184186
/// Backend specific options, if available.

gix-transport/src/client/blocking_io/http/reqwest/remote.rs

+38-25
Original file line numberDiff line numberDiff line change
@@ -46,36 +46,43 @@ impl Default for Remote {
4646

4747
// We may error while configuring, which is expected as part of the internal protocol. The error will be
4848
// received and the sender of the request might restart us.
49-
let client = reqwest::blocking::ClientBuilder::new()
50-
.connect_timeout(std::time::Duration::from_secs(20))
51-
.http1_title_case_headers()
52-
.redirect(reqwest::redirect::Policy::custom({
53-
let allow_redirects = allow_redirects.clone();
54-
move |attempt| {
55-
if allow_redirects.load(atomic::Ordering::Relaxed) {
56-
let curr_url = attempt.url();
57-
let prev_urls = attempt.previous();
49+
fn setup_client_builder(allow_redirects: Arc<atomic::AtomicBool>) -> reqwest::blocking::ClientBuilder {
50+
reqwest::blocking::ClientBuilder::new()
51+
.connect_timeout(std::time::Duration::from_secs(20))
52+
.http1_title_case_headers()
53+
.redirect(reqwest::redirect::Policy::custom({
54+
let allow_redirects = allow_redirects.clone();
55+
move |attempt| {
56+
if allow_redirects.load(atomic::Ordering::Relaxed) {
57+
let curr_url = attempt.url();
58+
let prev_urls = attempt.previous();
5859

59-
match prev_urls.first() {
60-
Some(prev_url) if prev_url.host_str() != curr_url.host_str() => {
61-
// git does not want to be redirected to a different host.
62-
attempt.stop()
63-
}
64-
_ => {
65-
// emulate default git behaviour which relies on curl default behaviour apparently.
66-
const CURL_DEFAULT_REDIRS: usize = 50;
67-
if prev_urls.len() >= CURL_DEFAULT_REDIRS {
68-
attempt.error("too many redirects")
69-
} else {
70-
attempt.follow()
60+
match prev_urls.first() {
61+
Some(prev_url) if prev_url.host_str() != curr_url.host_str() => {
62+
// git does not want to be redirected to a different host.
63+
attempt.stop()
64+
}
65+
_ => {
66+
// emulate default git behaviour which relies on curl default behaviour apparently.
67+
const CURL_DEFAULT_REDIRS: usize = 50;
68+
if prev_urls.len() >= CURL_DEFAULT_REDIRS {
69+
attempt.error("too many redirects")
70+
} else {
71+
attempt.follow()
72+
}
7173
}
7274
}
75+
} else {
76+
attempt.stop()
7377
}
74-
} else {
75-
attempt.stop()
7678
}
77-
}
78-
}))
79+
}))
80+
}
81+
82+
let client_ssl_verify = setup_client_builder(allow_redirects.clone()).build()?;
83+
84+
let client_no_ssl_verify = setup_client_builder(allow_redirects.clone())
85+
.danger_accept_invalid_certs(false)
7986
.build()?;
8087

8188
for Request {
@@ -86,6 +93,12 @@ impl Default for Remote {
8693
config,
8794
} in req_recv
8895
{
96+
let client = if config.ssl_verify {
97+
&client_ssl_verify
98+
} else {
99+
&client_no_ssl_verify
100+
};
101+
89102
let effective_url = redirect::swap_tails(redirected_base_url.as_deref(), &base_url, url.clone());
90103
let mut req_builder = if upload_body_kind.is_some() {
91104
client.post(&effective_url)

gix/src/repository/config/transport.rs

+8
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,14 @@ impl crate::Repository {
405405
}
406406
}
407407

408+
{
409+
let key = "http.sslVerify";
410+
opts.ssl_verify = config
411+
.boolean_filter_by_key(key, &mut trusted_only)
412+
.and_then(Result::ok)
413+
.unwrap_or(true)
414+
}
415+
408416
#[cfg(feature = "blocking-http-transport-curl")]
409417
{
410418
let key = "http.schannelCheckRevoke";

gix/tests/repository/config/transport_options.rs

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ mod http {
5555
verbose,
5656
ssl_ca_info,
5757
ssl_version,
58+
ssl_verify,
5859
http_version,
5960
backend,
6061
} = http_options(&repo, None, "https://example.com/does/not/matter");
@@ -106,6 +107,9 @@ mod http {
106107
max: version
107108
})
108109
);
110+
111+
assert!(ssl_verify);
112+
109113
assert_eq!(http_version, Some(HttpVersion::V1_1));
110114
}
111115

src/plumbing/progress.rs

-4
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,6 @@ static GIT_CONFIG: &[Record] = &[
408408
config: "http.sslCipherList",
409409
usage: NotPlanned { reason: "on demand" }
410410
},
411-
Record {
412-
config: "http.sslVerify",
413-
usage: NotPlanned { reason: "on demand" }
414-
},
415411
Record {
416412
config: "http.sslCert",
417413
usage: NotPlanned { reason: "on demand" }

0 commit comments

Comments
 (0)