Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: add support for client certificates #1152

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/shared/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public static class Http
public const string SslBackend = "sslBackend";
public const string SslVerify = "sslVerify";
public const string SslCaInfo = "sslCAInfo";
public const string SslAutoClientCert = "sslAutoClientCert";
}

public static class Remote
Expand Down
14 changes: 14 additions & 0 deletions src/shared/Core/HttpClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ public HttpClient CreateClient()
handler = new HttpClientHandler();
}

// Trace Git's chosen SSL/TLS backend
_trace.WriteLine($"Git's SSL/TLS backend is: {_settings.TlsBackend}");

// Mirror Git for Windows and only send client TLS certificates automatically if we're using
// the schannel backend _and_ the user has opted in to sending them.
if (_settings.TlsBackend == TlsBackend.Schannel &&
_settings.AutomaticallyUseClientCertificates)
{
_trace.WriteLine("Configured to automatically send TLS client certificates.");
handler.ClientCertificateOptions = ClientCertificateOption.Automatic;
}

// Configure server certificate verification and warn if we're bypassing validation

// IsCertificateVerificationEnabled takes precedence over custom TLS cert verification
if (!_settings.IsCertificateVerificationEnabled)
{
Expand Down
8 changes: 8 additions & 0 deletions src/shared/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public interface ISettings : IDisposable
/// </summary>
bool IsCertificateVerificationEnabled { get; }

/// <summary>
/// Automatically send client TLS certificates.
/// </summary>
bool AutomaticallyUseClientCertificates { get; }

/// <summary>
/// Get the proxy setting if configured, or null otherwise.
/// </summary>
Expand Down Expand Up @@ -563,6 +568,9 @@ public bool IsCertificateVerificationEnabled
}
}

public bool AutomaticallyUseClientCertificates =>
TryGetSetting(null, KnownGitCfg.Credential.SectionName, KnownGitCfg.Http.SslAutoClientCert, out string value) && value.ToBooleanyOrDefault(false);

public string CustomCertificateBundlePath =>
TryGetPathSetting(KnownEnvars.GitSslCaInfo, KnownGitCfg.Http.SectionName, KnownGitCfg.Http.SslCaInfo, out string value) ? value : null;

Expand Down
2 changes: 2 additions & 0 deletions src/shared/TestInfrastructure/Objects/TestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class TestSettings : ISettings

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

public bool AutomaticallyUseClientCertificates { get; set; }

public ProxyConfiguration ProxyConfiguration { get; set; }

public string ParentWindowId { get; set; }
Expand Down