Commit 39b8e90
authored
Honour certificate verification mode when custom trust roots are set (TransportServices) (#185)
Fixes #184.
## Motivation
With `trustRoots: .certificates(...)`, the TransportServices transports
install a verify block that anchors the custom roots and then calls
`SecTrustEvaluateAsyncWithError` on the trust exactly as
Network.framework configured it — with the default SSL policy, which
includes hostname matching. The configured `CertificateVerification`
mode is never consulted there:
- `.noHostnameVerification` behaves like full verification: any
certificate whose SANs don't cover the dialled endpoint is rejected
(`errSSLBadCert`), even though the chain validates against the custom
roots. This breaks private-CA deployments whose certs deliberately carry
no DNS/IP SANs, and peers dialled by IP address. The identical
configuration works with the Posix transport, where the mode maps to
NIOSSL's `certificateVerification = .noHostnameVerification`.
- `.noVerification` still installs the evaluating block and can fail the
handshake despite verification being explicitly disabled.
## Modifications
The verify block now receives the verification mode and whether it is
evaluating server or client certificates:
- `.noHostnameVerification`: the trust is re-policied with
`SecPolicyCreateSSL(<role>, nil)` before evaluation — chain validation
against the custom anchors is unchanged, hostname matching is skipped.
- `.noVerification`: no verify block is installed (the callers already
set `sec_protocol_options_set_peer_authentication_required(false)` for
this mode), matching NIOSSL semantics.
- `.fullVerification`: behaviour unchanged.
## Result
`.noHostnameVerification` + custom trust roots connects when the chain
is valid but the hostname doesn't match, on both client and server
TransportServices transports, matching the Posix transport.
New regression test (`testClientNoHostnameVerificationIgnoresHostname`)
covers all client/server transport combinations; without the source
change the two TransportServices-client cases fail with
`NWError.tls(-9808)`. Existing TLS suites pass
(`HTTP2TransportTLSEnabledTests`, `TLSConfigurationTests`).1 parent 2ca31f0 commit 39b8e90
4 files changed
Lines changed: 79 additions & 6 deletions
File tree
- Sources/GRPCNIOTransportHTTP2TransportServices
- Tests/GRPCNIOTransportHTTP2Tests
Lines changed: 30 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
328 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
329 | 343 | | |
330 | 344 | | |
331 | 345 | | |
| |||
337 | 351 | | |
338 | 352 | | |
339 | 353 | | |
340 | | - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
341 | 358 | | |
342 | 359 | | |
343 | 360 | | |
| |||
373 | 390 | | |
374 | 391 | | |
375 | 392 | | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
376 | 403 | | |
377 | 404 | | |
378 | 405 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
442 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
443 | 447 | | |
444 | 448 | | |
445 | 449 | | |
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | | - | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
338 | 342 | | |
339 | 343 | | |
340 | 344 | | |
Lines changed: 39 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
503 | 538 | | |
504 | 539 | | |
505 | 540 | | |
| |||
746 | 781 | | |
747 | 782 | | |
748 | 783 | | |
749 | | - | |
| 784 | + | |
| 785 | + | |
750 | 786 | | |
751 | 787 | | |
752 | 788 | | |
| |||
755 | 791 | | |
756 | 792 | | |
757 | 793 | | |
| 794 | + | |
758 | 795 | | |
759 | 796 | | |
760 | 797 | | |
| |||
766 | 803 | | |
767 | 804 | | |
768 | 805 | | |
| 806 | + | |
769 | 807 | | |
770 | 808 | | |
771 | 809 | | |
| |||
0 commit comments