Repository navigation
[Security] Fix SecProtocolMetadata callback bindings. - #26799
rolfbjarne wants to merge 8 commits into
Conversation
Convert the peer certificate callback from sec_certificate_t through a borrowed SecCertificate2 wrapper before exposing its SecCertificateRef. Treat a false native signature-list result as unavailable instead of throwing on success. Retrieve the PSK block target using the public named delegate and retain its borrowed DispatchData arguments rather than taking ownership of native callback references. Correct the OCSP exception spelling. Extend the existing TLS metadata fixture with peer-certificate traversal, null-handler checks, optional collection access checks, and metadata disposal. Optional collections may be absent, and the fixture has no TLS-PSK server, so these tests do not guarantee execution of every callback. Extract only the binding corrections and all SecProtocolMetadata test hunks from #26704 at 5e2f4cb. Leave the five owner-lifetime guards and their result-local scaffolding to the parent PR; public API signatures and direct native checks/returns remain unchanged apart from the signature success-condition fix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The PSK trampoline and ownership correction remain unexecuted by tests.
Review effort: Balanced
Findings: 1
What changed in this PR
Corrects Security TLS metadata callback marshalling, ownership, and availability handling.
Changes:
- Fixes certificate and PSK callback wrappers.
- Corrects signature-list success handling and OCSP spelling.
- Expands TLS metadata tests and resource disposal.
| File | Description |
|---|---|
src/Security/SecProtocolMetadata.cs |
Corrects callback bindings and native object ownership. |
tests/monotouch-test/Security/SecProtocolMetadataTest.cs |
Adds callback, optional-data, null-handler, and disposal coverage. |
Add a controlled local TLS-PSK listener and client instead of relying on the public TLS endpoint, which never invokes the pre-shared-key callback. Require exactly one callback with the configured key and identity, keep both DispatchData wrappers past callback return and connection teardown, verify their contents, and dispose them. Also check the null-handler contract. Use a test-only native PSK configuration import because the existing public AddPreSharedKey overload configures legacy DH parameters rather than a key/identity pair. Keep production bindings and the parent-only owner-lifetime changes untouched. Detach event handlers on their serial queue before disposing captured state so assertion and timeout paths clean up safely. Validation: the complete modified fixture compiles against the built Microsoft.macOS assembly and NUnit using a compile-only TestRuntime stub. An equivalent native loopback handshake, callback retention, and teardown probe passed five runs on the available SDK. Full managed test execution remains blocked by the missing macOS workload and unavailable Xcode 27. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
Replace placeholder XML documentation for SetOcspResponseForPeerHandler and SetSignatureAlgorithmsForPeerHandler with their actual synchronous enumeration behavior. Describe callback data, handshake-dependent availability, null/disposed/unavailable exceptions, and the lifetime and disposal responsibility of received OCSP DispatchData wrappers. Clarify that these methods do not register callbacks for future updates, and note the signature accessor can be used while responding to a TLS challenge. No executable code or public API signatures change. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Compare keys.Count directly with Is.EqualTo instead of using Has.Count. NUnit 4.6.1 implements the latter through PropertyConstraint and a reflection-created generic delegate that is unavailable under NativeAOT, causing AccessPreSharedKeys to fail in the three NativeAOT configurations on every platform in build 15531969. The callback still must execute exactly once, and the retained key/identity payload checks remain unchanged. A focused .NET 11 NativeAOT reproduction with the CI NUnit version reproduces the exact missing-native-code exception before this change. The direct comparison passes for one callback and reports expected/actual values for zero and two callbacks. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…adata-binding-fixes
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Require CheckOptionalAccess to observe at least one callback whenever a native accessor reports accessible data. Return only after validating the unavailable exception and its zero-callback contract. Add a managed regression proving that successful access without callbacks fails, while a real callback and unavailable data are handled correctly. Exercise supported signature enumeration during a controlled loopback TLS client-certificate challenge. Reuse the existing self-signed certificate factory, require client authentication on the listener, and assert that enumeration completes without an exception and invokes at least one signature callback. This covers the true native return path that would throw under the original inverted condition, rather than relying on optional public-server data. Report callback exceptions on the test thread, complete the certificate challenge, and cancel both connections on their serial queue. Guard late challenge callbacks during teardown so they do not access disposed captured state. Production API and parent-only lifetime guards remain untouched. Validation: the complete fixture compiles against the built macOS assembly and NUnit 4.6.1, and its managed optional-access regression passes. An equivalent native loopback certificate challenge returned success with 20 signature callbacks in each of three runs. Full Apple test-app execution remains unavailable with the local Xcode 26.3/no-Xcode product build. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…adata-binding-fixes
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🔥 [CI Build #3d98825] Test results 🔥Test results❌ Tests failed on VSTS: test results 1 tests crashed, 84 tests failed, 134 tests passed. Failures❌ monotouch tests (iOS)20 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (MacCatalyst)20 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (macOS)20 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (tvOS)20 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ windows tests🔥 Failed catastrophically on VSTS: test results - windows (no summary found). Html Report (VSDrops) Download ❌ Tests on macOS Sonoma (14) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Sequoia (15) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Tahoe (26) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Golden Gate (27) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS testsLinux Build VerificationPipeline on Agent |


Convert the peer certificate callback from sec_certificate_t through a borrowed SecCertificate2 wrapper before exposing its SecCertificateRef. Treat a false native signature-list result as unavailable instead of throwing on success. Retrieve the PSK block target using the public named delegate and retain its borrowed DispatchData arguments rather than taking ownership of native callback references. Correct the OCSP exception spelling and document the OCSP and signature accessors' synchronous callback and failure behavior.
Extend the existing TLS metadata fixture with peer-certificate traversal, null-handler checks, optional collection access checks, and metadata disposal. Optional collections may be absent, so the public-server test does not guarantee execution of every callback. A separate controlled loopback TLS-PSK test requires one PSK callback and verifies both captured DispatchData payloads remain readable after callback return and connection teardown before disposing them.
Extract the binding corrections and all original SecProtocolMetadata test hunks from #26704 at 5e2f4cb, with the additional PSK regression and documentation requested during review. Leave the five owner-lifetime guards and their result-local scaffolding to the parent PR; public API signatures and direct native checks/returns remain unchanged apart from the signature success-condition fix.
🤖 Pull request created by Copilot