Skip to content

Regression: NSUrlSessionHandler.ServerCertificateCustomValidationCallback behavior change #23764

Closed

Description

@dotMorten

Apple platform

iOS

Framework version

net9.0-*

Affected platform version

9.0.300

Description

The ServerCertificateCustomValidationCallback has started returning a new value for SslPolicyErrors for the test code provided below.

Steps to Reproduce

Repro method. This used to pass and match behavior of HttpClientHandler and SocketsHttpHandler.

        [TestMethod]
        public async Task RemoteCertificate_ForceFailure()
        {
            // Verifies that the default certificate validator is called for a normal request, and that it can be forced to fail
            int calls = 0;
            Exception callbackAssertFail = null;

#if __IOS__
            var handler = new NSUrlSessionHandler();
            handler.ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
#else
            var handler = new System.Net.Http.SocketsHttpHandler();
            handler.SslOptions.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
#endif
            {
                Interlocked.Increment(ref calls);
                try
                {
                    Assert.AreEqual(SslPolicyErrors.None, sslPolicyErrors, "sslPolicyErrors"); // Fails on iOS since 9.0.300. Now returns `RemoteCertificateChainErrors`
                }
                catch (Exception ex)
                {
                    callbackAssertFail = ex;
                }
                return false;
            };

            var client = new HttpClient(handler);
            // Disable keep-alive and cache to force reconnection for each request
            client.DefaultRequestHeaders.ConnectionClose = true;
            client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true, NoStore = true };

            var responseTask = client.GetAsync(new Uri("https://sha256.badssl.com/")); // valid certificate
            try { await responseTask; }
            catch (HttpRequestException) { /* expected */ }
            
            // Expect our validator to be called once
            Assert.AreEqual(1, calls, "numCalls");
            if (callbackAssertFail != null)
            {
                throw callbackAssertFail;
            }
        }

Did you find any workaround?

No

Relevant logs

No response

Activity

  1. dotMorten commented on May 27, 2025

    @dotMorten
    ContributorAuthor
  2. mstefarov commented on May 27, 2025

    @mstefarov
    The certificate from sha256.badssl.com
    -----BEGIN CERTIFICATE-----
    MIIFADCCA+igAwIBAgISBljRV2npFllM5ADixo1ctjLrMA0GCSqGSIb3DQE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YTeqkMhJpJvlVUxSRbqwlZtEFWDywzChwxbJ8rcrkTMCIBm+6mZtAs5f
    Cqv7ybqZiveKT+9a5JpFsr/6/G8j79PsAHYAEvFONL1TckyEBhnDjz96E/jntWKH
    iJxtMAWE6+WGJjoAAAGWy3P8EQAABAMARzBFAiBEAt7wHQFLPg23deCecS78jgxX
    3V8dx7pJOcLyFteVTQIhAOQMwoz6Aw8BS47eS+trtMv1VeQN/Ex/mo4hNxtkM7uL
    MA0GCSqGSIb3DQEBCwUAA4IBAQCubRQKSX7qJl2vaSLTh9asDdH2pMxy0pnhN1gn
    y50/D7drjPnQnnp0bK73BDVWhtYm2ZK0uLjywRynCP+YLLDRIsrOk4WhdMYrA61c
    xykP25JziHcbCn8vZMv/KFGesLF3d8MTjFTRw9QFLZZOMJKKxf0F2IzfNWPv3B7q
    MHN44dE4bZ4I1iU0vET1+l8vmXplUtlJUwed5hEkFGRkna0mW83qN7hkzLgZQUil
    9pXdM2RBT5+K6s2kdis120JV8I5hx/7GN7BlugVW0Blh4Z+hcwrxJYVj/WXCFd/X
    A3djaywLH7HWdRk7PqDJpn9zGpxd0rbcNS2yxqqckoLuy/Wm
    -----END CERTIFICATE-----
    
    OpenSSL info dump
    $ openssl x509 -noout -text -in 'sha256-badssl.cer'
    Certificate:
        Data:
            Version: 3 (0x2)
            Serial Number:
                06:58:d1:57:69:e9:16:59:4c:e4:00:e2:c6:8d:5c:b6:32:eb
            Signature Algorithm: sha256WithRSAEncryption
            Issuer: C = US, O = Let's Encrypt, CN = R10
            Validity
                Not Before: May 13 20:03:05 2025 GMT
                Not After : Aug 11 20:03:04 2025 GMT
            Subject: CN = *.badssl.com
            Subject Public Key Info:
                Public Key Algorithm: rsaEncryption
                    Public-Key: (2048 bit)
                    Modulus:
                        00:d5:bb:8e:cc:82:ab:16:9d:84:57:93:69:8b:71:
                        72:db:57:ff:05:3b:53:1d:b9:bf:2b:80:49:43:e9:
                        45:c6:8b:f1:1b:ea:77:05:38:8d:55:51:8a:3c:a0:
                        50:d6:d9:f6:70:46:f9:46:6a:ca:ff:74:f6:f3:1c:
                        64:9e:0d:a9:06:59:55:36:e7:1a:7b:7a:bb:de:1f:
                        8f:d7:f4:9d:66:4c:0e:08:2f:95:65:a9:39:2d:9f:
                        d8:8d:7f:41:92:6d:02:65:43:26:64:cf:0c:23:e0:
                        28:01:ce:71:06:98:bf:dc:ba:97:25:30:1f:3b:47:
                        58:3e:85:25:a6:c2:8d:06:dd:a5:2d:84:83:3a:c4:
                        1b:bb:85:2e:87:a9:de:b0:79:7f:e3:db:7d:01:1b:
                        41:76:72:19:1f:c3:b8:a8:57:33:ca:a6:d6:8a:d9:
                        fb:7c:58:cb:91:c3:d5:38:35:39:16:b2:97:cb:ff:
                        fc:72:f8:42:72:e4:09:96:0e:7e:1f:b4:95:a0:72:
                        43:cb:96:23:fb:a0:83:62:54:52:f3:8c:83:8e:23:
                        6f:d8:03:6f:d3:d0:65:7a:e0:60:0a:72:a3:db:40:
                        ac:9e:4a:cd:ee:fc:cd:a5:5e:cd:aa:88:df:5b:9b:
                        c4:cf:02:c1:21:71:63:6d:77:42:07:7d:b0:48:52:
                        12:43
                    Exponent: 65537 (0x10001)
            X509v3 extensions:
                X509v3 Key Usage: critical
                    Digital Signature, Key Encipherment
                X509v3 Extended Key Usage:
                    TLS Web Server Authentication, TLS Web Client Authentication
                X509v3 Basic Constraints: critical
                    CA:FALSE
                X509v3 Subject Key Identifier:
                    B3:8A:3F:CD:EE:AA:F8:B9:78:51:03:1E:9B:25:BB:8D:A1:A7:0E:BC
                X509v3 Authority Key Identifier:
                    BB:BC:C3:47:A5:E4:BC:A9:C6:C3:A4:72:0C:10:8D:A2:35:E1:C8:E8
                Authority Information Access:
                    CA Issuers - URI:http://r10.i.lencr.org/
                X509v3 Subject Alternative Name:
                    DNS:*.badssl.com, DNS:badssl.com
                X509v3 Certificate Policies:
                    Policy: 2.23.140.1.2.1
                X509v3 CRL Distribution Points:
                    Full Name:
                      URI:http://r10.c.lencr.org/108.crl
                CT Precertificate SCTs:
                    Signed Certificate Timestamp:
                        Version   : v1 (0x0)
                        Log ID    : CC:FB:0F:6A:85:71:09:65:FE:95:9B:53:CE:E9:B2:7C:
                                    22:E9:85:5C:0D:97:8D:B6:A9:7E:54:C0:FE:4C:0D:B0
                        Timestamp : May 13 21:01:36.217 2025 GMT
                        Extensions: none
                        Signature : ecdsa-with-SHA256
                                    30:44:02:20:61:37:AA:90:C8:49:A4:9B:E5:55:4C:52:
                                    45:BA:B0:95:9B:44:15:60:F2:C3:30:A1:C3:16:C9:F2:
                                    B7:2B:91:33:02:20:19:BE:EA:66:6D:02:CE:5F:0A:AB:
                                    FB:C9:BA:99:8A:F7:8A:4F:EF:5A:E4:9A:45:B2:BF:FA:
                                    FC:6F:23:EF:D3:EC
                    Signed Certificate Timestamp:
                        Version   : v1 (0x0)
                        Log ID    : 12:F1:4E:34:BD:53:72:4C:84:06:19:C3:8F:3F:7A:13:
                                    F8:E7:B5:62:87:88:9C:6D:30:05:84:EB:E5:86:26:3A
                        Timestamp : May 13 21:01:38.193 2025 GMT
                        Extensions: none
                        Signature : ecdsa-with-SHA256
                                    30:45:02:20:44:02:DE:F0:1D:01:4B:3E:0D:B7:75:E0:
                                    9E:71:2E:FC:8E:0C:57:DD:5F:1D:C7:BA:49:39:C2:F2:
                                    16:D7:95:4D:02:21:00:E4:0C:C2:8C:FA:03:0F:01:4B:
                                    8E:DE:4B:EB:6B:B4:CB:F5:55:E4:0D:FC:4C:7F:9A:8E:
                                    21:37:1B:64:33:BB:8B
        Signature Algorithm: sha256WithRSAEncryption
        Signature Value:
            ae:6d:14:0a:49:7e:ea:26:5d:af:69:22:d3:87:d6:ac:0d:d1:
            f6:a4:cc:72:d2:99:e1:37:58:27:cb:9d:3f:0f:b7:6b:8c:f9:
            d0:9e:7a:74:6c:ae:f7:04:35:56:86:d6:26:d9:92:b4:b8:b8:
            f2:c1:1c:a7:08:ff:98:2c:b0:d1:22:ca:ce:93:85:a1:74:c6:
            2b:03:ad:5c:c7:29:0f:db:92:73:88:77:1b:0a:7f:2f:64:cb:
            ff:28:51:9e:b0:b1:77:77:c3:13:8c:54:d1:c3:d4:05:2d:96:
            4e:30:92:8a:c5:fd:05:d8:8c:df:35:63:ef:dc:1e:ea:30:73:
            78:e1:d1:38:6d:9e:08:d6:25:34:bc:44:f5:fa:5f:2f:99:7a:
            65:52:d9:49:53:07:9d:e6:11:24:14:64:64:9d:ad:26:5b:cd:
            ea:37:b8:64:cc:b8:19:41:48:a5:f6:95:dd:33:64:41:4f:9f:
            8a:ea:cd:a4:76:2b:35:db:42:55:f0:8e:61:c7:fe:c6:37:b0:
            65:ba:05:56:d0:19:61:e1:9f:a1:73:0a:f1:25:85:63:fd:65:
            c2:15:df:d7:03:77:63:6b:2c:0b:1f:b1:d6:75:19:3b:3e:a0:
            c9:a6:7f:73:1a:9c:5d:d2:b6:dc:35:2d:b2:c6:aa:9c:92:82:
            ee:cb:f5:a6
    
  3. dotMorten commented on May 27, 2025

    @dotMorten
    ContributorAuthor

    I noticed the regression started on May 13, when 9.0.300 shipped, but from @mstefarov's dump above, that's also when the certificate was renewed. I rolled back to 9.0.202 and still seeing the issue :(
    The phone browser doesn't reject this certificate though, so I wonder if there's something else that causes the existing code to not like this certificate?

  4. rolfbjarne commented on May 28, 2025

    @rolfbjarne
    Member

    Moving to dotnet/runtime, because I've managed to distill this down to a console app: console-c460bb5.zip

    Binlog:

    msbuild.binlog.zip

    Code:

    using System;
    using System.Collections.Generic;
    using System.Runtime.InteropServices;
    using System.Security.Cryptography.X509Certificates;
    using System.Threading.Tasks;
    
    class App
    {
        public static int Main ()
        {
            var certs = new List<X509Certificate2>();
            var cert0String = "MIIFADCCA+igAwIBAgISBljRV2npFllM5ADixo1ctjLrMA0GCSqGSIb3DQEBCwUAMDMxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQwwCgYDVQQDEwNSMTAwHhcNMjUwNTEzMjAwMzA1Whc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8EQAABAMARzBFAiBEAt7wHQFLPg23deCecS78jgxX3V8dx7pJOcLyFteVTQIhAOQMwoz6Aw8BS47eS+trtMv1VeQN/Ex/mo4hNxtkM7uLMA0GCSqGSIb3DQEBCwUAA4IBAQCubRQKSX7qJl2vaSLTh9asDdH2pMxy0pnhN1gny50/D7drjPnQnnp0bK73BDVWhtYm2ZK0uLjywRynCP+YLLDRIsrOk4WhdMYrA61cxykP25JziHcbCn8vZMv/KFGesLF3d8MTjFTRw9QFLZZOMJKKxf0F2IzfNWPv3B7qMHN44dE4bZ4I1iU0vET1+l8vmXplUtlJUwed5hEkFGRkna0mW83qN7hkzLgZQUil9pXdM2RBT5+K6s2kdis120JV8I5hx/7GN7BlugVW0Blh4Z+hcwrxJYVj/WXCFd/XA3djaywLH7HWdRk7PqDJpn9zGpxd0rbcNS2yxqqckoLuy/Wm";
            var cert0Bytes = Convert.FromBase64String(cert0String);
            var cert0 = X509CertificateLoader.LoadCertificate(cert0Bytes);
            certs.Add(cert0);
            var cert1String = "MIIFBTCCAu2gAwIBAgIQS6hSk/eaL6JzBkuoBI110DANBgkqhkiG9w0BAQsFADBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBYMTAeFw0yNDAzMTMwMDAwMDBaFw0yNzAzMTIyMzU5NTlaMDMxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQwwCgYDVQQDEwNSMTAwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDPV+XmxFQS7bRH/sknWHZGUCiMHT6I3wWd1bUYKb3dtVq/+vbOo76vACFLYlpaPAEvxVgD9on/jhFD68G14BQHlo9vH9fnuoE5CXVlt8KvGFs3Jijno/QHK20a/6tYvJWuQP/py1fEtVt/eA0YYbwX51TGu0mRzW4Y0YCF7qZlNrx06rxQTOr8IfM4FpOUurDT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mqDtmiXLnzqTpXbI+suyCsohKRg6Un0RC47+cpiVwHiXZAW+cn8eiNIjqbVgXLxKPpdzvvtTnOPlC7SQZSYmdunr3Bf9b77AiC/ZidstK36dRILKz7OA54=";
            var cert1Bytes = Convert.FromBase64String(cert1String);
            var cert1 = X509CertificateLoader.LoadCertificate(cert1Bytes);
            certs.Add(cert1);
            var cert2String = "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAwTzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2VhcmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBYMTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygch77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6UA5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sWT8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyHB5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UCB5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUvKBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWnOlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTnjh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbwqHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CIrU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkqhkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZLubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KKNFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7UrTkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdCjNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVcoyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPAmRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57demyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=";
            var cert2Bytes = Convert.FromBase64String(cert2String);
            var cert2 = X509CertificateLoader.LoadCertificate(cert2Bytes);
            certs.Add(cert2);
    
            var certificates = certs.ToArray();
    
            var certificate = certificates[0];
    
            var chain = new X509Chain();
            chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
            chain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
            chain.ChainPolicy.ExtraStore.AddRange(certificates);
    
            foreach (var c in certs)
            {
                Console.WriteLine($"Certificate: {c.Subject} ({c.Thumbprint})");
                Console.WriteLine($"  Issuer: {c.Issuer}");
                Console.WriteLine($"  NotBefore: {c.NotBefore}");
                Console.WriteLine($"  NotAfter: {c.NotAfter}");
                Console.WriteLine($"  SerialNumber: {c.SerialNumber}");
                Console.WriteLine($"  Version: {c.Version}");
                Console.WriteLine($"  HasPrivateKey: {c.HasPrivateKey}");
                Console.WriteLine();
            }
    
            var rv = chain.Build(certificate);
            Console.WriteLine(rv ? "Chain build succeeded" : "CHAIN BUILD FAILURE");
            if (!rv)         {
                foreach (var status in chain.ChainStatus) {
                    Console.WriteLine($"ChainStatus: {status.Status} - {status.StatusInformation}");
                }
            }
            return rv ? 0 : 1;
        }
    }

    prints:

    $ dotnet run
    Certificate: CN=*.badssl.com (2C640ABED4E490194885E96BA2349824BF07D36D)
      Issuer: CN=R10, O=Let's Encrypt, C=US
      NotBefore: 5/13/2025 10:03:05 PM
      NotAfter: 8/11/2025 10:03:04 PM
      SerialNumber: 0658D15769E916594CE400E2C68D5CB632EB
      Version: 3
      HasPrivateKey: False
    
    Certificate: CN=R10, O=Let's Encrypt, C=US (00ABEFD055F9A9C784FFDEABD1DCDD8FED741436)
      Issuer: CN=ISRG Root X1, O=Internet Security Research Group, C=US
      NotBefore: 3/13/2024 1:00:00 AM
      NotAfter: 3/13/2027 12:59:59 AM
      SerialNumber: 4BA85293F79A2FA273064BA8048D75D0
      Version: 3
      HasPrivateKey: False
    
    Certificate: CN=ISRG Root X1, O=Internet Security Research Group, C=US (CABD2A79A1076A31F21D253635CB039D4329A5E8)
      Issuer: CN=ISRG Root X1, O=Internet Security Research Group, C=US
      NotBefore: 6/4/2015 1:04:38 PM
      NotAfter: 6/4/2035 1:04:38 PM
      SerialNumber: 008210CFB0D240E3594463E0BB63828B00
      Version: 3
      HasPrivateKey: False
    
    CHAIN BUILD FAILURE
    ChainStatus: RevocationStatusUnknown - An incomplete certificate revocation check occurred.
    
    $ dotnet --info
    Details
    $ dotnet --info
    .NET SDK:
     Version:           9.0.300
     Commit:            15606fe0a8
     Workload version:  9.0.300-manifests.87b8cca8
     MSBuild version:   17.14.5+edd3bbf37
    
    Runtime Environment:
     OS Name:     Mac OS X
     OS Version:  15.5
     OS Platform: Darwin
     RID:         osx-arm64
     Base Path:   /usr/local/share/dotnet/sdk/9.0.300/
    
    .NET workloads installed:
     [ios]
       Installation Source: SDK 9.0.300
       Manifest Version:    18.4.9289/9.0.100
       Manifest Path:       /usr/local/share/dotnet/sdk-manifests/9.0.100/microsoft.net.sdk.ios/18.4.9289/WorkloadManifest.json
       Install Type:        FileBased
    
    Configured to use loose manifests when installing new manifests.
    
    Host:
      Version:      9.0.5
      Architecture: arm64
      Commit:       e36e4d1a8f
    
    .NET SDKs installed:
      7.0.410 [/usr/local/share/dotnet/sdk]
      8.0.304 [/usr/local/share/dotnet/sdk]
      8.0.402 [/usr/local/share/dotnet/sdk]
      9.0.100 [/usr/local/share/dotnet/sdk]
      9.0.102 [/usr/local/share/dotnet/sdk]
      9.0.103 [/usr/local/share/dotnet/sdk]
      9.0.106 [/usr/local/share/dotnet/sdk]
      9.0.203 [/usr/local/share/dotnet/sdk]
      9.0.300 [/usr/local/share/dotnet/sdk]
    
    .NET runtimes installed:
      Microsoft.AspNetCore.App 7.0.20 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 8.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 9.0.0-rc.2.24474.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 9.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 9.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 9.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 9.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 6.0.36 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
      Microsoft.NETCore.App 7.0.20 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
      Microsoft.NETCore.App 8.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
      Microsoft.NETCore.App 9.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
      Microsoft.NETCore.App 9.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
      Microsoft.NETCore.App 9.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
      Microsoft.NETCore.App 9.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
    
    Other architectures found:
      None
    
    Environment variables:
      Not set
    
    global.json file:
      Not found
    
    Learn more:
      https://aka.ms/dotnet/info
    
    Download .NET:
      https://aka.ms/dotnet/download
    
  5. transferred this issue fromdotnet/macioson May 28, 2025
  6. wfurt commented on May 28, 2025

    @wfurt
    Member

    that like chain build change.

  7. rolfbjarne commented on Jul 4, 2025

    @rolfbjarne
    Member

    Downloading sha256.badssl.com's certificate (https://crt.sh/?q=28b3bb3370523318551dbefb031d681022d9c0ae35004aad83783c1ad43e8884), and verifying using security verify, shows that the certificate doesn't validate:

    $ security verify -v -R require -c /Users/rolf/Downloads/18388510143.crt
    Cert Verify Result: revocation check not successful for each cert
    ---
    Certificate chain
     0: *.badssl.com
        <cert(0x14e00e000) s: *.badssl.com i: R10>
     1: R10
        <cert(0x14e00e800) s: R10 i: ISRG Root X1>
     2: ISRG Root X1
        <cert(0x14e00f000) s: ISRG Root X1 i: ISRG Root X1>
    ---
    Certificate errors
     0: *.badssl.com
        [RevocationResponseRequired]
     1: R10
     2: ISRG Root X1
    ---
    Trust evaluation results
    {
        TrustEvaluationDate = "2025-07-04 11:59:26 +0000";
        TrustResultDetails =     (
                    {
                RevocationResponseRequired = 0;
                StatusCodes =             (
                    "-2147408861"
                );
            },
                    {
            },
                    {
            }
        );
        TrustResultValue = 5;
    }
    ---
    Trust evaluation errors
    Error Domain=NSOSStatusErrorDomain Code=-67635 ""*.badssl.com","R10","ISRG Root X1" certificates do not meet pinning requirements" UserInfo={NSLocalizedDescription="*.badssl.com","R10","ISRG Root X1" certificates do not meet pinning requirements, NSUnderlyingError=0x6000016dce40 {Error Domain=NSOSStatusErrorDomain Code=-67635 "Certificate 0 \u201c*.badssl.com\u201d has errors: Failed to check revocation;" UserInfo={NSLocalizedDescription=Certificate 0 \u201c*.badssl.com\u201d has errors: Failed to check revocation;}}}
    

    However, passing the url to security verify results in success:

    $ security verify -v -R require https://sha256.badssl.com
    connection to sha256.badssl.com port 443 (tcp) opened
    connection to sha256.badssl.com port 443 (tcp) closed
    ...certificate verification successful.
    ---
    Certificate chain
     0: *.badssl.com
        <cert(0x147011e00) s: *.badssl.com i: R10>
     1: R10
        <cert(0x147012600) s: R10 i: ISRG Root X1>
     2: ISRG Root X1
        <cert(0x147012e00) s: ISRG Root X1 i: ISRG Root X1>
    ---
    No extended validation result found
    Certificate Transparency (CT) status: verified
    ---
    Trust evaluation results
    {
        TrustCertificateTransparency = 1;
        TrustEvaluationDate = "2025-07-04 12:03:44 +0000";
        TrustResultDetails =     (
                    {
            },
                    {
            },
                    {
            }
        );
        TrustResultValue = 4;
    }
    
  8. bartonjs commented on Sep 5, 2025

    @bartonjs
    Member

    The chain build in a previous comment has revocation checking enabled, by virtue of not turning it off.

    Let's Encrypt stopped issuing certificates with registered OCSP endpoints, and the listed leaf certificate shows that it was issued after that point. So, partly, this is "Apple doesn't correctly process CRLs", with the "regression" inducing change having been external (the cert reissuance... as was already noted). (We specify kSecRevocationUseAnyAvailableMethod, but Apple's chain engine seems to decide that means "OCSP for the target cert, but CRL might be OK for CAs")

    As far as I can tell NSUrlSessionHandler always has revocation checking enabled for custom callbacks, which is where this is coming from. For SocketsHttpHandler there are options regarding revocation. If NSUrlSessionHandler doesn't actually know what the underlying revocation check status is, but does know that the underlying system was willing to continue with the connection, then perhaps NSUrlSessionHandler wants to set chain.ChainPolicy.VerificationFlags |= X509ChainVerificationFlags.AllowEndRevocationUnknown; (which will make chain.Build() return true if that was the only problem) -- there are two other RevocationUnknown flags (intermediate CAs and the root), NSUrlSessionHandler may or may not want to set them, depending on what the underlying OS is doing.

  9. bartonjs commented on Sep 5, 2025

    @bartonjs
    Member

    @rolfbjarne I don't seem to be able to transfer this back; but there's nothing that we can do for it in dotnet/runtime.

  10. added this to the Future milestone on Sep 5, 2025
  11. transferred this issue fromdotnet/runtimeon Sep 8, 2025
  12. rolfbjarne commented on Sep 8, 2025

    @rolfbjarne
    Member

    @bartonjs thanks for your help diagnosing this! I've moved this back to dotnet/macios now.

    So I guess there are a few options here:

    1. Add an SslClientAuthenticationOptions SslOptions property to NSUrlSessionHandler, basically copying whatever SocketsHttpHandler does. There's quite a few properties in SslClientAuthenticationOptions though, and implementing them all doesn't look trivial, and might not even be possible to do in NSUrlSessionHandler due to API limitations in Apple's NSURLSessionHandler.
    2. Add a CertificateChainPolicy property to NSUrlSessionHandler, and using that value here:
      chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
      chain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
      .
    3. Just change the verification flag to |= AllowEndRevocationUnknown as @bartonjs suggests.

    I'm leaning towards 2, because:

    1. This is either a lot of work (which I'm hesitant to do when I'm not a security expert, nor do we have any on the team), or we ignore most of the settings in the SslClientAuthenticationOptions (which doesn't seem ideal either).
    2. Fairly easy to implement, developers can opt-in as they see fit, and it's flexible.
    3. Trivial to implement, but not very flexible, developer can't opt in or out of this new behavior.
  13. added a commit that references this issue on Sep 8, 2025
    fa60de2
  14. rolfbjarne commented on Sep 8, 2025

    @rolfbjarne
    Member

    PR is up: #23767

  15. added
    enhancement
    on Sep 8, 2025
  16. dotMorten commented on Sep 8, 2025

    @dotMorten
    ContributorAuthor

    @rolfbjarne I'd lean towards 3. My argument is it'll match behavior of other handlers, and thus you get consistent behavior across platforms you target. Possible with a combination with 2, so that you can opt-out of it, but defaults to matching SocketsHttpHandler behavior.

  17. rolfbjarne commented on Sep 9, 2025

    @rolfbjarne
    Member

    @rolfbjarne I'd lean towards 3. My argument is it'll match behavior of other handlers, and thus you get consistent behavior across platforms you target. Possible with a combination with 2, so that you can opt-out of it, but defaults to matching SocketsHttpHandler behavior.

    I ended up doing 2 + 3, so the default behavior is consistent with other platforms + it's configurable, so you can get the old behavior if you want, or use other flags if Apple breaks something else.

  18. added a commit that references this issue on Sep 9, 2025
    97d260a
  19. dotMorten commented on Oct 21, 2025

    @dotMorten
    ContributorAuthor

    I can confirm our tests just started passing for this on iOS too with the latest .NET 9 update! Thanks @rolfbjarne

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions