Skip to content

Commit

Permalink
CustomBuildTool github cert validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy-s committed Jul 1, 2024
1 parent 579ae12 commit 3811a00
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions tools/CustomBuildTool/Github.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,7 @@ public static GithubReleasesResponse CreateRelease(string Version)
{
httpClientHandler.AutomaticDecompression = DecompressionMethods.All;
httpClientHandler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13;
httpClientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) =>
{
if (sslPolicyErrors != SslPolicyErrors.None)
return false;
return cert.Subject.Equals("CN=*.github.com", StringComparison.OrdinalIgnoreCase);
};
httpClientHandler.ServerCertificateCustomValidationCallback = CertValidationCallback;

using (HttpClient httpClient = new HttpClient(httpClientHandler))
{
Expand Down Expand Up @@ -127,13 +121,7 @@ public static bool DeleteRelease(string Version)
{
httpClientHandler.AutomaticDecompression = DecompressionMethods.All;
httpClientHandler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13;
httpClientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) =>
{
if (sslPolicyErrors != SslPolicyErrors.None)
return false;
return cert.Subject.Equals("CN=*.github.com", StringComparison.OrdinalIgnoreCase);
};
httpClientHandler.ServerCertificateCustomValidationCallback = CertValidationCallback;

using (HttpClient httpClient = new HttpClient(httpClientHandler))
{
Expand Down Expand Up @@ -232,13 +220,7 @@ public static GithubReleasesResponse UpdateRelease(string ReleaseId)
{
httpClientHandler.AutomaticDecompression = DecompressionMethods.All;
httpClientHandler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13;
httpClientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) =>
{
if (sslPolicyErrors != SslPolicyErrors.None)
return false;
return cert.Subject.Equals("CN=*.github.com", StringComparison.OrdinalIgnoreCase);
};
httpClientHandler.ServerCertificateCustomValidationCallback = CertValidationCallback;

using (HttpClient httpClient = new HttpClient(httpClientHandler))
{
Expand Down Expand Up @@ -320,13 +302,7 @@ public static GithubAssetsResponse UploadAssets(string Version, string FileName,
{
httpClientHandler.AutomaticDecompression = DecompressionMethods.All;
httpClientHandler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13;
httpClientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) =>
{
if (sslPolicyErrors != SslPolicyErrors.None)
return false;
return cert.Subject.Equals("CN=*.github.com", StringComparison.OrdinalIgnoreCase);
};
httpClientHandler.ServerCertificateCustomValidationCallback = CertValidationCallback;

using (HttpClient httpClient = new HttpClient(httpClientHandler))
{
Expand Down Expand Up @@ -386,6 +362,23 @@ public static GithubAssetsResponse UploadAssets(string Version, string FileName,

return null;
}

private static bool CertValidationCallback(
HttpRequestMessage Rquest,
X509Certificate Cert,
X509Chain Chain,
SslPolicyErrors Errors
)
{
if (Errors != SslPolicyErrors.None)
return false;

if (Cert.Subject.Equals("CN=*.github.com", StringComparison.OrdinalIgnoreCase))
return true;

Program.PrintColorMessage($"[CertValidationCallback] {Cert.Subject}", ConsoleColor.Red);
return false;
}
}

public class GithubRelease : IComparable, IComparable<GithubRelease>, IEquatable<GithubRelease>
Expand Down
Binary file modified tools/CustomBuildTool/bin/Release/CustomBuildTool.exe
Binary file not shown.
Binary file modified tools/CustomBuildTool/bin/Release/CustomBuildTool.pdb
Binary file not shown.

0 comments on commit 3811a00

Please sign in to comment.