Skip to content

Commit 240ba5d

Browse files
committed
http: add support for client certificates
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, and there is only respected when the SSL backend is "schannel".
1 parent c12409f commit 240ba5d

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>
@@ -563,6 +568,9 @@ public bool IsCertificateVerificationEnabled
563568
}
564569
}
565570

571+
public bool AutomaticallyUseClientCertificates =>
572+
TryGetSetting(null, KnownGitCfg.Credential.SectionName, KnownGitCfg.Http.SslAutoClientCert, out string value) && value.ToBooleanyOrDefault(false);
573+
566574
public string CustomCertificateBundlePath =>
567575
TryGetPathSetting(KnownEnvars.GitSslCaInfo, KnownGitCfg.Http.SectionName, KnownGitCfg.Http.SslCaInfo, out string value) ? value : null;
568576

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)