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

Handle IdLinkage X509 chain building status. #41691

Merged
merged 2 commits into from Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -190,14 +190,34 @@ static void MergeStatusCodes(CFTypeRef key, CFTypeRef value, void* context)
// just ignore it for now.
}
else if (CFEqual(keyString, CFSTR("NonEmptySubject")) || CFEqual(keyString, CFSTR("GrayListedKey")) ||
CFEqual(keyString, CFSTR("CTRequired")) || CFEqual(keyString, CFSTR("GrayListedLeaf")))
CFEqual(keyString, CFSTR("CTRequired")) || CFEqual(keyString, CFSTR("GrayListedLeaf")) ||
CFEqual(keyString, CFSTR("IdLinkage")))
{
// Not a "problem" that we report.
}
else
{
#if defined DEBUG || defined DEBUGGING_UNKNOWN_VALUE
printf("Unknown Chain Status: %s\n", CFStringGetCStringPtr(keyString, CFStringGetSystemEncoding()));
CFIndex keyStringLength = CFStringGetLength(keyString);
CFIndex maxEncodedLength = CFStringGetMaximumSizeForEncoding(keyStringLength, kCFStringEncodingUTF8) + 1;
char* keyStringBuffer = malloc(maxEncodedLength);

if (keyStringBuffer)
{
if (CFStringGetCString(keyString, keyStringBuffer, maxEncodedLength, kCFStringEncodingUTF8))
{
printf("Unknown Chain Status: %s\n", keyStringBuffer);
}
else
{
printf("Unknown Chain Status. Could not get string.");
}
free(keyStringBuffer);
}
else
{
printf("Unknown Chain Status. Could not allocate string.");
}
#endif
*pStatus |= PAL_X509ChainErrorUnknownValue;
}
Expand Down
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Linq;
using System.Runtime.InteropServices;
using Test.Cryptography;
using Xunit;

Expand Down Expand Up @@ -450,6 +451,65 @@ public static void CustomTrustModeWithNoCustomTrustCerts()
}
}

[Fact]
public static void MismatchKeyIdentifiers()
{
X509Extension[] intermediateExtensions = new [] {
new X509BasicConstraintsExtension(
certificateAuthority: true,
hasPathLengthConstraint: false,
pathLengthConstraint: 0,
critical: true),
new X509Extension(
"2.5.29.14",
"0414C7AC28EFB300F46F9406ED155628A123633E556F".HexToByteArray(),
critical: false)
};

X509Extension[] endEntityExtensions = new [] {
new X509BasicConstraintsExtension(
certificateAuthority: false,
hasPathLengthConstraint: false,
pathLengthConstraint: 0,
critical: true),
new X509Extension(
"2.5.29.35",
"30168014A84A6A63047DDDBAE6D139B7A64565EFF3A8ECA1".HexToByteArray(),
critical: false)
};

TestDataGenerator.MakeTestChain3(
out X509Certificate2 endEntityCert,
out X509Certificate2 intermediateCert,
out X509Certificate2 rootCert,
intermediateExtensions: intermediateExtensions,
endEntityExtensions: endEntityExtensions);

using (endEntityCert)
using (intermediateCert)
using (rootCert)
using (ChainHolder chainHolder = new ChainHolder())
{
X509Chain chain = chainHolder.Chain;
chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
chain.ChainPolicy.VerificationTime = endEntityCert.NotBefore.AddSeconds(1);
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
chain.ChainPolicy.CustomTrustStore.Add(rootCert);
chain.ChainPolicy.ExtraStore.Add(intermediateCert);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Assert.False(chain.Build(endEntityCert), "chain.Build");
Assert.Equal(X509ChainStatusFlags.PartialChain, chain.AllStatusFlags());
}
else
{
Assert.True(chain.Build(endEntityCert), "chain.Build");
Assert.Equal(3, chain.ChainElements.Count);
}
}
}

private static X509Certificate2 TamperSignature(X509Certificate2 input)
{
byte[] cert = input.RawData;
Expand Down