Skip to content

Commit 24f514a

Browse files
committed
Add support to http.sslVerify
1 parent 5d8b5f4 commit 24f514a

File tree

8 files changed

+71
-32
lines changed

8 files changed

+71
-32
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

+39-27
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,44 @@ impl Default for Remote {
4444
let mut redirected_base_url = None::<String>;
4545
let allow_redirects = Arc::new(atomic::AtomicBool::new(false));
4646

47-
// We may error while configuring, which is expected as part of the internal protocol. The error will be
48-
// 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();
47+
fn setup_client_builder(allow_redirects: Arc<atomic::AtomicBool>) -> reqwest::blocking::ClientBuilder {
48+
reqwest::blocking::ClientBuilder::new()
49+
.connect_timeout(std::time::Duration::from_secs(20))
50+
.http1_title_case_headers()
51+
.redirect(reqwest::redirect::Policy::custom({
52+
move |attempt| {
53+
if allow_redirects.load(atomic::Ordering::Relaxed) {
54+
let curr_url = attempt.url();
55+
let prev_urls = attempt.previous();
5856

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()
57+
match prev_urls.first() {
58+
Some(prev_url) if prev_url.host_str() != curr_url.host_str() => {
59+
// git does not want to be redirected to a different host.
60+
attempt.stop()
61+
}
62+
_ => {
63+
// emulate default git behaviour which relies on curl default behaviour apparently.
64+
const CURL_DEFAULT_REDIRS: usize = 50;
65+
if prev_urls.len() >= CURL_DEFAULT_REDIRS {
66+
attempt.error("too many redirects")
67+
} else {
68+
attempt.follow()
69+
}
7170
}
7271
}
72+
} else {
73+
attempt.stop()
7374
}
74-
} else {
75-
attempt.stop()
7675
}
77-
}
78-
}))
76+
}))
77+
}
78+
79+
// We may error while configuring, which is expected as part of the internal protocol. The error will be
80+
// received and the sender of the request might restart us.
81+
let client_ssl_verify = setup_client_builder(allow_redirects.clone()).build()?;
82+
83+
let client_no_ssl_verify = setup_client_builder(allow_redirects.clone())
84+
.danger_accept_invalid_certs(false)
7985
.build()?;
8086

8187
for Request {
@@ -86,6 +92,12 @@ impl Default for Remote {
8692
config,
8793
} in req_recv
8894
{
95+
let client = if config.ssl_verify {
96+
&client_ssl_verify
97+
} else {
98+
&client_no_ssl_verify
99+
};
100+
89101
let effective_url = redirect::swap_tails(redirected_base_url.as_deref(), &base_url, url.clone());
90102
let mut req_builder = if upload_body_kind.is_some() {
91103
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/fixtures/make_config_repos.sh

+5
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,8 @@ mkdir not-a-repo-with-files;
164164
(cd not-a-repo-with-files
165165
touch this that
166166
)
167+
168+
git init no-ssl-verify
169+
(cd no-ssl-verify
170+
git config http.sslVerify false
171+
)

gix/tests/repository/config/transport_options.rs

+13
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

@@ -314,4 +318,13 @@ mod http {
314318
assert_eq!(opts.proxy.as_deref(), Some("http://localhost:9090"));
315319
assert_eq!(opts.follow_redirects, FollowRedirects::Initial);
316320
}
321+
322+
#[test]
323+
fn no_ssl_verify() {
324+
let repo = repo("no-ssl-verify");
325+
326+
let opts = http_options(&repo, None, "https://example.com/does/not/matter");
327+
328+
assert!(!opts.ssl_verify);
329+
}
317330
}

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)