Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 1e9d602

Browse files
committed
#920 Disable wild card certificate option
1 parent a184d1c commit 1e9d602

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/Titanium.Web.Proxy/Certificates/CertificateManager.cs

+5
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ public ICertificateCache CertificateStorage
283283
/// </summary>
284284
public X509KeyStorageFlags StorageFlag { get; set; } = X509KeyStorageFlags.Exportable;
285285

286+
/// <summary>
287+
/// Disable wild card certificates. Disabled by default.
288+
/// </summary>
289+
public bool DisableWildCardCertificates { get; set; } = false;
290+
286291
/// <summary>
287292
/// For CertificateEngine.DefaultWindows to work we need to also check in personal store
288293
/// </summary>

src/Titanium.Web.Proxy/ExplicitClientHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect
185185
{
186186
sslStream = new SslStream(clientStream, false);
187187

188-
string certName = HttpHelper.GetWildCardDomainName(connectHostname);
188+
string certName = HttpHelper.GetWildCardDomainName(connectHostname, CertificateManager.DisableWildCardCertificates);
189189
certificate = endPoint.GenericCertificate ??
190190
await CertificateManager.CreateServerCertificate(certName);
191191

src/Titanium.Web.Proxy/Helpers/HttpHelper.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ internal static ReadOnlyMemory<char> GetBoundaryFromContentType(string? contentT
137137
/// </summary>
138138
/// <param name="hostname"></param>
139139
/// <returns></returns>
140-
internal static string GetWildCardDomainName(string hostname)
140+
internal static string GetWildCardDomainName(string hostname, bool disableWildCardCertificates)
141141
{
142142
// only for subdomains we need wild card
143143
// example www.google.com or gstatic.google.com
@@ -148,6 +148,11 @@ internal static string GetWildCardDomainName(string hostname)
148148
return hostname;
149149
}
150150

151+
if (disableWildCardCertificates)
152+
{
153+
return hostname;
154+
}
155+
151156
var split = hostname.Split(ProxyConstants.DotSplit);
152157

153158
if (split.Length > 2)

src/Titanium.Web.Proxy/TransparentClientHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private async Task handleClient(TransparentBaseProxyEndPoint endPoint, TcpClient
6666
{
6767
sslStream = new SslStream(clientStream, false);
6868

69-
string certName = HttpHelper.GetWildCardDomainName(httpsHostName);
69+
string certName = HttpHelper.GetWildCardDomainName(httpsHostName, CertificateManager.DisableWildCardCertificates);
7070
certificate = endPoint.GenericCertificate ??
7171
await CertificateManager.CreateServerCertificate(certName);
7272

0 commit comments

Comments
 (0)