Skip to content

Commit 9f1b048

Browse files
authored
http: add support for client certificates (#1152)
Add support for automatically sending client TLS certificates using the Git configuration setting 'http.sslAutoClientCert'. This setting is currently only [present in Git for Windows](https://github.com/git-for-windows/git/blob/c8edb521bdabec14b07e9142e48cab77a40ba339/http.c#L906-L910), and there is only respected when the SSL backend is "schannel". Fixes #369
2 parents 5ffd1cf + 240ba5d commit 9f1b048

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/shared/Core/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public static class Http
158158
public const string SslBackend = "sslBackend";
159159
public const string SslVerify = "sslVerify";
160160
public const string SslCaInfo = "sslCAInfo";
161+
public const string SslAutoClientCert = "sslAutoClientCert";
161162
}
162163

163164
public static class Remote

src/shared/Core/HttpClientFactory.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ public HttpClient CreateClient()
7676
handler = new HttpClientHandler();
7777
}
7878

79+
// Trace Git's chosen SSL/TLS backend
80+
_trace.WriteLine($"Git's SSL/TLS backend is: {_settings.TlsBackend}");
81+
82+
// Mirror Git for Windows and only send client TLS certificates automatically if we're using
83+
// the schannel backend _and_ the user has opted in to sending them.
84+
if (_settings.TlsBackend == TlsBackend.Schannel &&
85+
_settings.AutomaticallyUseClientCertificates)
86+
{
87+
_trace.WriteLine("Configured to automatically send TLS client certificates.");
88+
handler.ClientCertificateOptions = ClientCertificateOption.Automatic;
89+
}
90+
91+
// Configure server certificate verification and warn if we're bypassing validation
92+
7993
// IsCertificateVerificationEnabled takes precedence over custom TLS cert verification
8094
if (!_settings.IsCertificateVerificationEnabled)
8195
{

src/shared/Core/Settings.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ public interface ISettings : IDisposable
119119
/// </summary>
120120
bool IsCertificateVerificationEnabled { get; }
121121

122+
/// <summary>
123+
/// Automatically send client TLS certificates.
124+
/// </summary>
125+
bool AutomaticallyUseClientCertificates { get; }
126+
122127
/// <summary>
123128
/// Get the proxy setting if configured, or null otherwise.
124129
/// </summary>
@@ -570,6 +575,9 @@ public bool IsCertificateVerificationEnabled
570575
}
571576
}
572577

578+
public bool AutomaticallyUseClientCertificates =>
579+
TryGetSetting(null, KnownGitCfg.Credential.SectionName, KnownGitCfg.Http.SslAutoClientCert, out string value) && value.ToBooleanyOrDefault(false);
580+
573581
public string CustomCertificateBundlePath =>
574582
TryGetPathSetting(KnownEnvars.GitSslCaInfo, KnownGitCfg.Http.SectionName, KnownGitCfg.Http.SslCaInfo, out string value) ? value : null;
575583

src/shared/TestInfrastructure/Objects/TestSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class TestSettings : ISettings
3131

3232
public bool IsCertificateVerificationEnabled { get; set; } = true;
3333

34+
public bool AutomaticallyUseClientCertificates { get; set; }
35+
3436
public ProxyConfiguration ProxyConfiguration { get; set; }
3537

3638
public string ParentWindowId { get; set; }

0 commit comments

Comments
 (0)