NIOTransportServices TLS verify block prints "Trust failed" to stdout

Open Beginner friendly
#950 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
73/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
swift

Research direction

Start with Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift at the linked verify block and trace how the background activity logger is made available when TLS options are created. Confirm the behavior on macOS with NIOTransportServices using a certificate verification failure; done when the failure reason is no longer written to stdout and remains available through the logger.

Written by the indexing model from the issue text.

Description

Description

On Darwin with NIOTransportServices, when certificate verification fails, the verify block installed by TLSConfiguration.getNWProtocolTLSOptions writes the failure to standard output:

https://github.com/swift-server/async-http-client/blob/6b7549b3faa176f12b000f0fe95204695383288b/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift#L202-L207

The verify block was added in #350 (for #292) and is installed whenever certificateVerification != .fullVerification || trustRoots != nil. Because TLSConfiguration.makeClientConfiguration() sets trustRoots to .default, this also happens with the default client configuration.

For a command-line tool that prints machine-readable output (for example JSON) on stdout, the extra line corrupts the output.

Steps to reproduce
  1. On macOS, use HTTPClient(eventLoopGroupProvider: .singleton) with the default configuration.
  2. Send a request to a host whose certificate fails verification (for example https://wrong.host.badssl.com).
  3. Standard output contains Trust failed: “*.badssl.com” certificate name does not match input.
Expected behavior

The library does not write to stdout.

The message carries the specific reason for the failure (expired, name mismatch, untrusted), which the NWTLSError the request fails with does not include. So rather than dropping it, it could go to the background activity logger (for example at debug level), which is already available where the TLS options are created.

Workaround

Setting tlsConfiguration.trustRoots = nil (with .fullVerification) avoids installing the verify block, so Network.framework evaluates trust itself and nothing is printed.

Environment
  • async-http-client 1.36.0; the print is also present on main (6b7549b)
  • macOS, NIOTransportServices
Dominant language
Swift
Stars
1.1k
Forks
159
Avg merge
18h 43m
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from swift-server/async-http-client

All issues in swift-server/async-http-client

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.