Skip to content

System.Security.Cryptography.Tests outerloop tests broken #117243

Closed

Description

@ManickaP

Multiple outerloop tests broken with:

System.Security.Cryptography.X509Certificates.Tests.RevocationTests.DynamicRevocationTests.RevokeEndEntityWithInvalidRevocationSignature(pkiOptions: AllRevocation) [FAIL]
      System.AggregateException : One or more errors occurred. (Assert.Equal() Failure: Collections differ
                                   ↓ (pos 2)
      Expected: [NoError, NoError, RevocationStatusUnknown | OfflineRevocation]
      Actual:   [NoError, NoError, Revoked]
                                   ↑ (pos 2)) (Assert.Equal() Failure: Collections differ
                                   ↓ (pos 2)
      Expected: [NoError, NoError, RevocationStatusUnknown | OfflineRevocation]
      Actual:   [NoError, NoError, Revoked]
                                   ↑ (pos 2)) (Assert.Equal() Failure: Collections differ
                                   ↓ (pos 2)
...

Based on Kusto data, this seems to be broken for quite a while (seeing failures as far as April).

Example log: https://helixr1107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-117207-merge-a7140fac46094fc59f/System.Security.Cryptography.Tests/1/console.66205cf5.log?helixlogtype=result

Activity

  1. added
    untriaged
    on Jul 2, 2025
  2. added
    needs-area-label
    on Jul 2, 2025
  3. added
    untriaged
    and removed
    untriaged
    needs-area-label
    on Jul 2, 2025
  4. dotnet-policy-service commented on Jul 2, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones
    See info in area-owners.md if you want to be subscribed.

  5. added
    os-linux
    on Jul 2, 2025
  6. bartonjs commented on Jul 10, 2025

    @bartonjs
    Member

    Offhand, it looks like OSSL 3.5 has decided to treat "it says revoked, but the signature is invalid" as "so it's revoked, I guess". But more investigation is required.

  7. added
    needs-further-triage
    and removed
    untriaged
    on Jul 22, 2025
  8. added this to the 10.0.0 milestone on Jul 22, 2025
  9. jeffhandley commented on Jul 22, 2025

    @jeffhandley
    Member

    Marking as 10.0.0 for completing the investigation to verify the likely change in behavior from OpenSSL, which would result in changing the test's assertion.

  10. vcsjones commented on Jul 31, 2025

    @vcsjones
    Member

    I started looking at this. It's not new in OpenSSL 3.5. It happened somewhere between 3.0 and 3.5, we just jumped from 3.0 to 3.5.

    I have an automated bisect going against OpenSSL between 3.0 and 3.5 to find the commit that introduced the change so we can understand what the intention was. Will report back.

  11. vcsjones commented on Aug 3, 2025

    @vcsjones
    Member

    Okay. This is an interesting one. I can also reproduce it against OpenSSL 3.0.

    A bisect of the runtime shows it started in 00b0050. /cc @bartonjs

    On e231b75:

    Image

    On 00b0050:

    Image

    More interestingly, I cannot reproduce any of the failures if I run any of the theories individually. I suspect something is getting memoized when it shouldn't, or some cache key that was introduced in that commit is not taking something in to account.

  12. vcsjones commented on Aug 3, 2025

    @vcsjones
    Member

    It also fails non-deterministically. Sometimes it's 1 failure, or 4 failures, or something in-between.

  13. vcsjones commented on Aug 3, 2025

    @vcsjones
    Member

    More anecdotal information: Changing BuildVariantFactories to only return [RSA] instead of [RSA, ECDsa] fixes it. So that is the source of the non-determinism.

  14. vcsjones commented on Aug 3, 2025

    @vcsjones
    Member

    In short: the combination of CorruptRevocationSignature and ECDsa revocation responders does not seem to work.

  15. added
    test-bug
    and removed
    needs-further-triage
    on Aug 3, 2025
  16. vcsjones commented on Aug 4, 2025

    @vcsjones
    Member

    More interestingly, I cannot reproduce any of the failures if I run any of the theories individually.

    Actually I can, that was the non-determinism biting me.

  17. bartonjs commented on Aug 4, 2025

    @bartonjs
    Member

    I changed the local algorithm variance to EC-DSA only, and saw the failures on OSSL 3.

    Looking at how I corrupt signatures, it's position ^2 in one place, and 5 in two others. 5 bytes in for an EC-DSA signature on secp521r1 is part of the DER structure. OSSL might be getting angry at "the signature isn't even structurally valid".

    I'm going to try running a few times with all tampers at ^2, which should always be part of the signature payload. The first run passed.

  18. bartonjs commented on Aug 4, 2025

    @bartonjs
    Member

    So, changing to ^2 has made me not see a failure in a half hour of constant runs...

    but I'm confused now, as the ECDsa factory uses secp384r1, not secp521r1. 384r1 would be a 48 byte field width, so won't clear the 127 bytes for needing the SEQUENCE length to get bigger.. but [5] would be the first byte of an INTEGER value, so maybe OSSL is getting angry about a bit pattern it ends up with...

    There are only two special ones:

    0b0000_0000_0xxx_xxxx and 0b1111_1111_1xxx_xxxx. I guess there's a 1/512 chance that it was a 0x00 followed by 0x80+ or 0xFF followed by 0x7F- and got flipped to an invalid integer... but then, man, I got lucky to fail 7 tests when I first forced all the tests to be EC-DSA only.

  19. bartonjs commented on Aug 4, 2025

    @bartonjs
    Member

    aaaaaaand... confirmed!

    I captured an output from right before a failure (reverting everything to edit at [5]):

    It looks like a perfectly valid OCSP Response:

    $ xxd -r -p | openssl ocsp -respin - -resp_text
    308201B50A0100A08201AE308201AA06092B06010505073001010482019B308201973082011CA1819
    D30819A313F303D060355040B1336416C6C5265766F636174696F6E2C20526F6F74417574686F7269
    747948617344657369676E617465644F637370526573706F6E64657231363034060355040A132D526
    5766F6B65456E64456E7469747957697468496E76616C69645265766F636174696F6E5369676E6174
    757265311F301D0603550403131641205265766F636174696F6E20546573742043412030180F32303
    235303830343139303130325A306930673041300906052B0E03021A05000414C3F0DE9A33CB98D894
    2D83AF5FD197B8687261F80414B9097AB0038F2C7691D12F54CCB8ED8CB724161602084B5F518A4F9
    864B9A111180F32303235303830343139303130315A180F32303235303830343139303130325A300A
    06082A8648CE3D04030203690030660231004CFC4BCC67A42CFC2B6B443FA54BE5ABF679F99100C6E
    CC832B25E108210D2364720F67EA24C01A7FB7A4E474EBACFD302310097252AB34D1EE0172DED91BE
    BEA162B801779160E22965670D93854B13135081B02EC1AA32D97F4DCC291B537BBC5502
    
    OCSP Response Data:
        OCSP Response Status: successful (0x0)
        Response Type: Basic OCSP Response
        Version: 1 (0x0)
        Responder Id: OU = "AllRevocation, RootAuthorityHasDesignatedOcspResponder", O = RevokeEndEntityWithInvalidRevocationSignature, CN = A Revocation Test CA 0
        Produced At: Aug  4 19:01:02 2025 GMT
        Responses:
        Certificate ID:
          Hash Algorithm: sha1
          Issuer Name Hash: C3F0DE9A33CB98D8942D83AF5FD197B8687261F8
          Issuer Key Hash: B9097AB0038F2C7691D12F54CCB8ED8CB7241616
          Serial Number: 4B5F518A4F9864B9
        Cert Status: revoked
        Revocation Time: Aug  4 19:01:01 2025 GMT
        This Update: Aug  4 19:01:02 2025 GMT
    
        Signature Algorithm: ecdsa-with-SHA256
        Signature Value:
            30:66:02:31:00:4c:fc:4b:cc:67:a4:2c:fc:2b:6b:44:3f:a5:
            4b:e5:ab:f6:79:f9:91:00:c6:ec:c8:32:b2:5e:10:82:10:d2:
            36:47:20:f6:7e:a2:4c:01:a7:fb:7a:4e:47:4e:ba:cf:d3:02:
            31:00:97:25:2a:b3:4d:1e:e0:17:2d:ed:91:be:be:a1:62:b8:
            01:77:91:60:e2:29:65:67:0d:93:85:4b:13:13:50:81:b0:2e:
            c1:aa:32:d9:7f:4d:cc:29:1b:53:7b:bc:55:02
    Response Verify Failure
    

    But eagle eyed BER nerds will notice 02:31:00:4c, which violates the rules of BER INTEGER.

    but then, man, I got lucky to fail 7 tests when I first forced all the tests to be EC-DSA only.

    You (me) should look at how many passed, though. Law of large numbers, my friend.

  20. vcsjones commented on Aug 4, 2025

    @vcsjones
    Member

    But eagle eyed BER nerds will notice 02:31:00:4c, which violates the rules of BER INTEGER

    Makes sense, but I am not sure why "corrupting it but not corrupting it enough" means "Revoked".

  21. PranavSenthilnathan commented on Aug 4, 2025

    @PranavSenthilnathan
    Member

    There are only two special ones:

    0b0000_0000_0xxx_xxxx and 0b1111_1111_1xxx_xxxx. I guess there's a 1/512 chance that it was a 0x00 followed by 0x80+ or 0xFF followed by 0x7F- and got flipped to an invalid integer... but then, man, I got lucky to fail 7 tests when I first forced all the tests to be EC-DSA only.

    If r in unsigned form is 384 bits in length and has the high bit set (50% chance assuming that r is uniformly distributed), then in unsigned form it would be 0b0000_0000_1xxx_xxxx. Tampering would make that invalid (0b1111_1111_1xxx_xxxx). So I'd expect it to happen over half the time..

  22. bartonjs commented on Aug 4, 2025

    @bartonjs
    Member

    The high bit won't have a full 50% chance of being a 1, since the modulus isn't 2^^384, but, yeah, that's a good point... it should have been failing any time that there was a padding byte set to 0.

    Oddly enough, every failure I captured was the "now the top 9 bits are 0", which means the signature was encoded as having a negative number...

    SIGH.

    [5] isn't the 5th byte, it's the 6th. I was looking at the wrong byte in my memory projection.

    So, yes, the problem is actually

    • The r value has bit 383 set, so it needs a 0x00 padding byte.
    • I then come along and flip the byte after the padding byte, it now goes from 0b1xxx_xxxx to 0b0xxx_xxxx.
    • That makes it invalid.

    Which is, as you say, roughly 50% of the time.

  23. bartonjs commented on Aug 4, 2025

    @bartonjs
    Member

    And as I've nerd-sniped myself... I believe it's a
    49.9999999999999999999999999999999999999999999999999999999999999999999999999991% chance, since p=0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF

    But, sure, if you don't live your life to what... 78 significant figures, you can call it 50% 😄

  24. locked and limited conversation to collaborators on Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Securityos-linuxtest-bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions