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

X509Chain behaviour inconsistent on Windows and Linux #29164

Closed
toady opened this issue Apr 4, 2019 · 9 comments · Fixed by dotnet/corefx#37237
Closed

X509Chain behaviour inconsistent on Windows and Linux #29164

toady opened this issue Apr 4, 2019 · 9 comments · Fixed by dotnet/corefx#37237

Comments

@toady
Copy link

toady commented Apr 4, 2019

We are running into a problem where the same chain is successfully built on Windows, populating ChainElements; yet fails with PartialChain on Linux, only having the leaf certificate in ChainElements;

Whole trust chain is loaded into ChainPolicy.ExtraStore prior to validating the leaf. Verification flags do not affect the resulting ChainStatus and ChainElements in any way.

It's reproducable on 2.2 runtime with the following basic code:

var collection = new[]
{
    "MIIFCzCCA3OgAwIBAgIBATANBgkqhkiG9w0BAQsFADAbMRkwFwYDVQQFExBiMmVkMTMwN2RlZDM5NjNkMB4XDTE2MDUyNjE3MTUxMFoXDTI2MDUyNDE3MTUxMFowHzEdMBsGA1UEAwwUQW5kcm9pZCBLZXlzdG9yZSBLZXkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCm60G5QQ/NpwR9CrWn2etjkb72z/haaTQzZmfMZeCp88AcWR22PyQhj7Pp4f2S5mHq9GETpiVAg4wSN72gTEjInVVHO5JYGlOXQTNLZ6tepkNeD6rTbVDYY72LCCeWl4KIMulpwWtrJruCXgxHzfTYExcz3EdZNXD/sGYySSLxtfC27SUGFmwmP0n1PYYCNUYFaVxjjlqfL6iz5ecQV2fdK4ABRPJ0XAvmoYeTwY3zoPRyl/ZmrZQYpBLinT9WgU0zKa9rX/6TMVZmCqHn43W/wmRtUG4DwP8vpU4G3Aw1nyJlGlPy7H/j89HL+6YCKpnoV31jlw/Nr7ZTgjHNIrHnAgMBAAGjggHUMIIB0DAfBgNVHSMEGDAWgBR3CcbscN4IGsrMU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ld+7yvHVgt1cVzJx9xnyGCC23UaicMDSXYrB4I4WHXPGjxhZuCuPBLTdOLU8YRvMYdEvYebWHMpvwGCF6bAx3JBpIeOQ1wDB5y0USicV3YgYGmi+NZfhA4URSh77Yd6uuJOJENRaNVTzk"
};

var certificates = new X509Certificate2[collection.Length];
for (int i = 0; i < collection.Length; ++i)
{
    var bytes = Convert.FromBase64String(collection[i]);

    certificates[i] = new X509Certificate2(bytes);
}

using (var chain = new X509Chain())
{
    chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
    chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;

    for (int i = 1; i < certificates.Length; ++i)
    {
        chain.ChainPolicy.ExtraStore.Add(certificates[i]);
    }

    var success = chain.Build(certificates[0]);

    Console.WriteLine("Success: {0}", success);

    Console.WriteLine("Statuses:");
    foreach (var status in chain.ChainStatus)
    {
        Console.WriteLine("\t{0}", status.Status);
    }

    Console.WriteLine("Elements:");
    foreach (var element in chain.ChainElements)
    {
        Console.WriteLine("\t{0}", element.Certificate.Subject);
    }
}

On windows output is:

Success: True
Statuses:
        UntrustedRoot
        NotValidForUsage
        InvalidBasicConstraints
Elements:
        CN=Android Keystore Key
        SERIALNUMBER=b2ed1307ded3963d
        SERIALNUMBER=87f4514475ba0a2b
        SERIALNUMBER=f92009e853b6b045

As expected, the whole chain is there.

Yet on Linux it fails to build:

Success: True
Statuses:
	PartialChain
Elements:
	CN=Android Keystore Key

I'm also attaching the example project with Dockerfile based dotnet:2.2-aspnetcore-runtime (and docker launch target).

X509ChainExample.zip

@toady
Copy link
Author

toady commented Apr 4, 2019

This is probably the same issue as in #28314 (closed), except a valid certificate chain is already built and attached here. It seems like the ExtraStore is ignored on Linux.

@bartonjs
Copy link
Member

bartonjs commented Apr 4, 2019

It's not that ExtraStore isn't used, it's that OpenSSL says that the 2nd entry isn't a valid issuer for the first.

Windows is building the chain and reporting NotValidForUsage and InvalidBasicConstraints. OpenSSL says "this is clearly not an issuer I need to consider because it doesn't have the certSign key usage bit" (NotValidForUsage). It likely would have then noticed the basic constraints ca=false and ruled it out on those grounds, too.

While we do try to do work to make even invalid chains build the same way, ultimately we let the system X.509 libraries do the work, and I don't think there's any way we can really coerce OpenSSL into having a different opinion here.

@toady
Copy link
Author

toady commented Apr 8, 2019

Another inconsistency is about revocation lists, for example this certificate:

MIIEqDCCAxKgAwIBAgIBATALBgkqhkiG9w0BAQswKTEZMBcGA1UEBRMQYTY3MzUxZjRkM2NjYzc5NTEMMAoGA1UEDAwDVEVFMB4XDTE5MDQwNTExNTMyOVoXDTE5MDQxMjExNTMyOVowHzEdMBsGA1UEAxMUQW5kcm9pZCBLZXlzdG9yZSBLZXkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDLDCB4+prYRG0JV6UpDh0XajbszDNXEGnjoHQ0o6pk23/eXm1N+3Z/HSh8dw3+Umtig/wyNB/IrKXfvEQoiZTtNu476bX7mc+fd5U5vFY4/a5RIrRAnE7z5IlbSagoUjlv/MmHlhnuXxR9P3pbijCCbY+oxzYbUy+UqwlyO22oOFcH2EXnt6zO4EMFRX4IkijxZGtew37XcKIcXfpggXwq1YWBZ21Wvzm8KPuLrz+PC7MzrkVCtEPB4EbOCSpdn7k1QRUj4joHRZJuyZB/0ZB/k8Vhf0AWvLiV2XZSRPdxzLqjPJt/H+p/h33tjbJpO4PKmo5ESkqpjMeOJnSfLSsDAgMBAAGjggFnMIIBYzALBgNVHQ8EBAMCBLAwCAYDVR0fBAEAMIIBSAYKKwYBBAHWeQIBEQSCATgwggE0AgECCgEBAgEDCgEBBCD5tPKQ5Ro6TlJR+SMSMdKsO0PEWXH9ZdjM8yAUgCM7WgQAME2/hUVJBEcwRTEfMB0EGGNvbS50ZWNobm9tb3MuYmV0YS5kZWJ1ZwIBDDEiBCB/9Og4sODdcmEFRNLXct5yeBLDRYuvvO2tLZhXuQoXJDCBsqEOMQwCAQMCAQICAQECAQCiAwIBAaMEAgIIAKUFMQMCAQSmCDEGAgEFAgEEv4FIBQIDAQABv4MQCAIGAWntWL4Sv4MRCAIGAWoRZUISv4MSCAIGAWoRZUISv4N3AgUAv4U9CAIGAWnt/Sk+v4U+AwIBAL+FQCowKAQgU0HmsmRpeacOV2UwB6HzEBaUIeyb3Z8aVkj3Wt4AWvEBAf8KAQC/hUEFAgMBOOS/hUIFAgMDFK8wCwYJKoZIhvcNAQELA4IBgQBtMC26d82nPQk7XbdpYrnaikspnk2PJrkrnbr723L+n3c5fBpT1IzvMJJsLnwd+F2Qywgg1lMljLs+W0W+kL0PVmiR0XR6q8iAVMl7hiJuInmQfv04W76VryhShfxBjtUES9NCfI7yNI3Lef65+yW+z9KQWDEkQp7iJrGJzd+ltW7516j8N+OS/Vma/MpXz6124pSDtAqSUMH9AkfL17DzYQePNi49arwfzXAAZfMH64qt9VvQUtC473baWMT0RDM4UbJ3oki/LrR8rWssBtGiyMIoFcOqt0Qwyx4gXShc1b0aAz5YKLi4RoUhjfO84nuNyjfmbGmDsWbqkPGQ/ckaZQpCZ8cLtHRzdtPqITpPz67Y5JMoGc+MXH755hPNt0lLLIcHFC4CuBJ/ywr2BaEcnfaRpeeOyJIg61N6ICFMaxUp7V1p5PEzpTyrhINkExJ18U5DyI5XSW0fintd7GJ8DGMU8Sg6jvXtGRmB/EFG4LIl0mNxaxuuYj6kI6tRBgs=

If ChainPolicy.RevocationMode is set to X509RevocationMode.Offline, on Windows we end up with RevocationStatusUnknown and OfflineRevocation, yet on Linux it's just RevocationStatusUnknown.

If ChainPolicy.RevocationMode is set to X509RevocationMode.Online, on Windows we once again end up with RevocationStatusUnknown and OfflineRevocation, while on Linux Build method throws CryptographicException:

   at System.Security.Cryptography.DerSequenceReader..ctor(DerTag tagToEat, Byte[] data, Int32 offset, Int32 length)
   at Internal.Cryptography.Pal.CrlCache.GetCdpUrl(X509Certificate2 cert)
   at Internal.Cryptography.Pal.CrlCache.DownloadAndAddCrl(X509Certificate2 cert, SafeX509StoreHandle store, TimeSpan& remainingDownloadTime)
   at Internal.Cryptography.Pal.CrlCache.AddCrlForCertificate(X509Certificate2 cert, SafeX509StoreHandle store, X509RevocationMode revocationMode, DateTime verificationTime, TimeSpan& remainingDownloadTime)
   at Internal.Cryptography.Pal.OpenSslX509ChainProcessor.BuildChain(X509Certificate2 leaf, HashSet`1 candidates, HashSet`1 systemTrusted, OidCollection applicationPolicy, OidCollection certificatePolicy, X509RevocationMode revocationMode, X509RevocationFlag revocationFlag, DateTime verificationTime, TimeSpan& remainingDownloadTime)
   at Internal.Cryptography.Pal.ChainPal.BuildChain(Boolean useMachineContext, ICertificatePal cert, X509Certificate2Collection extraStore, OidCollection applicationPolicy, OidCollection certificatePolicy, X509RevocationMode revocationMode, X509RevocationFlag revocationFlag, DateTime verificationTime, TimeSpan timeout)
   at System.Security.Cryptography.X509Certificates.X509Chain.Build(X509Certificate2 certificate, Boolean throwOnException)
   at System.Security.Cryptography.X509Certificates.X509Chain.Build(X509Certificate2 certificate)
   at X509ChainExample.Program.Main() in C:\Users\stanislav.bobrov\Documents\Visual Studio 2017\Projects\X509ChainExample\Program.cs:line 40

This is due to the certificate apparently having cRL extension with value of octet string 00:

30 08 06 03 55 1D 1F 04 01 00

and the code trying to read an ASN.1 sequence.

Couldn't find any proof in RFC that it's a valid value, but should be more forgiving.

@bartonjs
Copy link
Member

Not throwing during extension processing does seem sensible, and is something that we have control over.

@toady
Copy link
Author

toady commented Apr 11, 2019

@bartonjs, regarding the chain problem, it looks like it's actually corefx code rejecting the certificates from the ExtraStore here, as it throws away any certificate for which Interop.Crypto.X509CheckIssued returned an error.

Interop.Crypto.X509CheckIssued maps to X509_check_issued in openssl, which returns X509_V_ERR_KEYUSAGE_NO_CERTSIGN in case one certificate is indeed signed by another, but key usage is wrong.

I suppose this could be used to actually build the chain with NotValidForUsage flag.

@bartonjs
Copy link
Member

@lil-Toady Ah, then perhaps you should try with a 3.0 preview build, since that code has been entirely replaced with "here, OpenSSL, it's everything I know about everything, do your magic" (no prefilter).

@bartonjs
Copy link
Member

@lil-Toady (That said, I feel like I tried the commandline openssl verify, and it said it couldn't build the chain from the middle to the root, or the leaf to the middle+root, meaning that their normal chain engine probably has the same != 0)

@smartpcr
Copy link

I am still facing the same problem on linux, however, mac/windows are working.

$PSVersionTable Name Value


PSVersion 6.2.2
PSEdition Core
GitCommitId 6.2.2
OS Linux 5.0.0-1022-azure dotnet/corefx#23~18.04.1-Ubuntu SMP Mon Sep 30 19:47:06 UTC 2019
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

@bartonjs
Copy link
Member

@smartpcr As far as I know, PowerShell 6.2 is still based on .NET Core 2.1. Any changes would only really be visible once PowerShell moves to .NET Core 3.0.

But since multiple different problems were discussed in this issue, if you can clarify which problem you're having there might be advice that I can offer.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants