← Back to Pull requests

Accept every c_rehash collision suffix, not just .0 #602

Closed
unknown closed this pull request without merging on Sep 07, 2026 15:22 UTC
View on GitHub
unknown unknown commented on Aug 31, 2026 08:48 UTC
Author

_isRehashFormat recognises only a one-digit collision suffix, so openssl rehash links from .10 upward are not seen as c_rehash links at all.

The three barriers

On main the name check is:

guard let lastPathComponent = utf8PathSplitView.last,
    lastPathComponent.count == 10
else { return false }
let filenameParts = lastPathComponent.split(separator: UInt8(ascii: "."))

guard filenameParts.count == 2,
    let filename = filenameParts.first,
    let fileExtension = filenameParts.last,
    fileExtension.count == 1,
    filename.count == 8,
    filename.allSatisfy({ $0.isHexDigit }),
    fileExtension.first == UInt8(ascii: "0")
else { return false }

Three things reject a valid link independently:

1. lastPathComponent.count == 10 — rejects any name longer than HHHHHHHH.D before the extension is examined at all.
2. fileExtension.count == 1 — rejects any suffix of more than one digit.
3. fileExtension.first == UInt8(ascii: "0") — rejects every suffix that does not begin with 0, which for the ids OpenSSL actually writes means everything except .0.

Relaxing any one of them is not enough on its own.

Consequence

The filter lives in loadVerifyLocations(_:context:sendCANames:), which calls _isRehashFormat over the directory contents when sendCANames is set, loads each surviving link as a PEM certificate, and passes it to addCACertificateNameToList so its CA name reaches the client CA list. (addRootCertificate is a different function; it adds a certificate to the trust store and does not walk the directory.)

A CA that lost the hash race is therefore skipped, so its name is absent from the CertificateRequest, and a client holding a certificate from that CA has no reason to send it. The failure is quiet: nothing errors, the handshake just proceeds without the client certificate.

The change

  • fileExtension.allSatisfy({ $0.isDecimalDigit }) replaces the == "0" comparison, mirroring the isHexDigit check on the line above. isDecimalDigit is added to the same UTF8.CodeUnit extension as isHexDigit, in the same shape, reusing the existing asciiZero/asciiNine constants.

  • fileExtension.count == 1 becomes !fileExtension.isEmpty. Emptiness still has to be excluded explicitly, because allSatisfy is vacuously true on an empty collection.

  • lastPathComponent.count == 10 is removed rather than relaxed to >= 10. It is redundant once the parts are checked: filenameParts.count == 2, filename.count == 8 and a non-empty all-digits extension already pin the name to 8 + 1 + digits. A second, looser length check would only be another thing to keep in sync.

  • The split passes omittingEmptySubsequences: false. This is load-bearing. With the default behaviour Collection.split discards empty pieces, so .7f44456a.0, 7f44456a..0 and 7f44456a.0. collapse to the same two parts as 7f44456a.0. The removed count == 10 check had been rejecting exactly those three by accident; the explicit split replaces that accident with an intentional rule, and the reasoning is recorded at the call site.
  • No upper bound on the number of digits is imposed. The reasoning, and the OpenSSL sources it rests on, are in a comment on this PR.

    Tests

    testRehashFormat already asserts a non-digit extension (.z) is rejected; .a is added next to it, since a hex-but-not-decimal character is the case most likely to regress if someone reaches for isHexDigit here.

    testRehashFormatAcceptsCollisionSuffixes creates real symlinks and covers:

  • accepted: 0, 1, 9, 10, 123, 255.

  • rejected: .7f44456a.0, 7f44456a..0, 7f44456a.0., 7f44456a., 7f44456a.0.1 and 7f44456a.r0.
  • Every assertion carries a message saying why that name is in the list. The rejected names are real symlinks to a real certificate, so the name check is the only thing that can reject them. Only the first three depend on the explicit split; the comment in the test says what rejects the other three, so nobody reads the split as decorative.

    The existing getRehashFilename helper is used unchanged. It formats with %08lx.%d and already produces .10, .123 and .255 correctly.

    One existing assertion changes meaning. testRehashFormat builds 7f44456a.1 for its "in rehash format, but not a symlink" case, and on main that passes for the wrong reason: the name is rejected at the "0" comparison, before the symlink check it is meant to exercise. I confirmed this by passing a nonexistent path through the function, where reaching lstat is observable as a throw:

    | Source | _isRehashFormat("/etc/ssl/certs/7f44456a.1") |
    | --- | --- |
    | main | returns false, does not throw — rejected at the name check |
    | this PR | throws — the name is accepted and execution reaches the symlink check |

    After this change the assertion exercises what it was written for.

    Verification

    Run in swift:6.2-noble, the image the Linux 6.2 leg of the shared matrix names (apple/swift-nio, scripts/generate_matrix.sh line 78):

    docker run --rm -v "$PWD":/src -w /src swift:6.2-noble swift test --scratch-path .build-linux
    

    | Run | Result |
    | --- | --- |
    | apple:main (03827c1), unmodified | Executed 339 tests, with 0 failures (0 unexpected) |
    | PR head before this commit, unmodified | Executed 340 tests, with 0 failures (0 unexpected) |
    | With this change | Executed 340 tests, with 0 failures (0 unexpected) |
    | With this change, the matrix's 6.2 argument overrides | Executed 340 tests, with 0 failures (0 unexpected) |
    | New test against apple:main source | 5 failures: .1, .9, .10, .123, .255 |
    | New test against this branch's first commit | 3 failures: .10, .123, .255 |
    | New test against a variant keeping the default split | 3 failures: .7f44456a.0, 7f44456a..0, 7f44456a.0. |

    The last three are negative controls, showing the new assertions have teeth in both directions. swift format lint reports only the pre-existing OrderedImports warnings, unchanged from the baseline.

    The .10 case was reported by @stephenlclarke; I reproduced it here before changing anything.

    ---

    The code in this pull request was written with Claude Fable 5.1. The verification above and this description were written with Claude Opus 5. I have reviewed and tested the change, and I am responsible for its content.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: Lukasa Review duration: 10474m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #602"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%