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

Relax SystemTrustCertificateWithCustomRootTrust test #55423

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,15 @@ public static void BuildChainExtraStoreUntrustedRoot()
public static void SystemTrustCertificateWithCustomRootTrust(bool addCertificateToCustomRootTrust)
{
using (var microsoftDotCom = new X509Certificate2(TestData.MicrosoftDotComSslCertBytes))
using (var microsoftDotComIssuer = new X509Certificate2(TestData.MicrosoftDotComIssuerBytes))
using (var testCert = new X509Certificate2(TestFiles.ChainPfxFile, TestData.ChainPfxPassword))
using (var chainHolder = new ChainHolder())
{
X509Chain chain = chainHolder.Chain;
chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
chain.ChainPolicy.VerificationTime = microsoftDotCom.NotBefore.AddSeconds(1);
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
chain.ChainPolicy.ExtraStore.Add(microsoftDotComIssuer);

if (addCertificateToCustomRootTrust)
{
Expand All @@ -269,16 +271,29 @@ public static void SystemTrustCertificateWithCustomRootTrust(bool addCertificate
{
Assert.False(chain.Build(microsoftDotCom));

// Linux and Windows do not search the default system root stores when CustomRootTrust is enabled
// Historically, Windows has not searched system stores when CustomRootTrust is enabled.
// That seems to have recently (as of 2021-07-09) changed.

Assert.InRange(chain.ChainElements.Count, 2, 3);

if (chain.ChainElements.Count < 3)
{
Assert.Equal(X509ChainStatusFlags.PartialChain, chain.AllStatusFlags());
}
else
{
Assert.Equal(X509ChainStatusFlags.UntrustedRoot, chain.AllStatusFlags());
}

// Check some known conditions.

if (PlatformDetection.UsesAppleCrypto)
{
Assert.Equal(3, chain.ChainElements.Count);
Assert.Equal(X509ChainStatusFlags.UntrustedRoot, chain.AllStatusFlags());
}
else
else if (OperatingSystem.IsLinux())
{
Assert.Equal(2, chain.ChainElements.Count);
Assert.Equal(X509ChainStatusFlags.PartialChain, chain.AllStatusFlags());
}
}
}
Expand Down