NIOTransportServices TLS verify block prints "Trust failed" to stdout

オープン 初心者向け
#950 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
73/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
swift

調査の方向性

リンク先の Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift にある verify ブロックから始め、TLS オプションの作成時にバックグラウンドアクティビティロガーがどのように利用可能になるかを追ってください。NIOTransportServices を使って、macOS で証明書の検証に失敗した場合の動作を確認してください。失敗理由が stdout に書き込まれなくなり、ロガー経由で引き続き参照できるようになれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Swift
スター
1.1k
フォーク
159
平均マージ
18時間 43分
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

swift-server/async-http-client のほかの issue

swift-server/async-http-client の issue をすべて見る

似ている issue

Swift の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。