Skip to content

Commit

Permalink
test for SHA1 CAs
Browse files Browse the repository at this point in the history
  • Loading branch information
nicrowe00 committed Mar 6, 2024
1 parent eedd88e commit b0f3acc
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
47 changes: 47 additions & 0 deletions sha1-validation/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

bool sha1RsaSignatureOnLastElementInChain = false;

HttpClientHandler handler = new HttpClientHandler {
CheckCertificateRevocationList = true,
ServerCertificateCustomValidationCallback = ServerCertificateCustomValidation,
};

HttpClient client = new HttpClient(handler);

try
{
HttpResponseMessage response = await client.GetAsync("https://redhat.com");

string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"{sha1RsaSignatureOnLastElementInChain}");
Console.WriteLine("PASS");
return 0;
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
Console.WriteLine("FAIL");
return 1;
}

handler.Dispose();
client.Dispose();

bool ServerCertificateCustomValidation(HttpRequestMessage requestMessage, X509Certificate2? certificate, X509Chain? chain, SslPolicyErrors sslErrors)
{
foreach (var element in chain!.ChainElements)
{
var cert = element.Certificate;
Console.WriteLine($"{cert.SubjectName.Name} {cert.SignatureAlgorithm.FriendlyName}");
}
if ( chain.ChainElements.Last().Certificate.SignatureAlgorithm.FriendlyName != "sha1RSA" )
{
sha1RsaSignatureOnLastElementInChain = true;
}

Console.WriteLine($"Errors: {sslErrors}");
return sslErrors == SslPolicyErrors.None;
}
18 changes: 18 additions & 0 deletions sha1-validation/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "sha1-validation",
"enabled": true,
"requiresSdk": true,
"version": "6.0",
"versionSpecific": true,
"type": "bash",
"cleanup": true,
"skipWhen": [
],
"ignoredRIDs":[
"alpine",
"fedora",
"centos",
"rhel7",
"rhel8"
]
}
6 changes: 6 additions & 0 deletions sha1-validation/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -euo pipefail
IFS=$'\n\t'

dotnet run
10 changes: 10 additions & 0 deletions sha1-validation/tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>

0 comments on commit b0f3acc

Please sign in to comment.