diff --git a/wolfSSH/Makefile b/wolfSSH/Makefile index d077ace6..9f12b7ee 100644 --- a/wolfSSH/Makefile +++ b/wolfSSH/Makefile @@ -16,7 +16,10 @@ SOURCES = chapter01.md \ chapter11.md \ chapter12.md \ chapter13.md \ - chapter14.md + chapter14.md \ + chapter15.md \ + chapter16.md \ + chapter17.md ifeq ($(DOC_LANG),JA) PDF = wolfSSH-Manual-jp.pdf diff --git a/wolfSSH/header.txt b/wolfSSH/header.txt index c966340c..11e09bda 100644 --- a/wolfSSH/header.txt +++ b/wolfSSH/header.txt @@ -8,7 +8,7 @@ header-includes: # Fancy page headers - \usepackage{fancyhdr} - \pagestyle{fancy} - - \fancyfoot[LO,RE]{COPYRIGHT \copyright 2024 wolfSSL Inc.} + - \fancyfoot[LO,RE]{COPYRIGHT \copyright 2026 wolfSSL Inc.} # Wrap long syntax highlighting code blocks - \usepackage{fvextra} - \DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}} diff --git a/wolfSSH/mkdocs-ja.yml b/wolfSSH/mkdocs-ja.yml index e5d3c006..8712d94b 100644 --- a/wolfSSH/mkdocs-ja.yml +++ b/wolfSSH/mkdocs-ja.yml @@ -17,7 +17,10 @@ nav: - "11. サポートとコンサルティング": chapter11.md - "12. wolfSSHのアップデート": chapter12.md - "13. APIリファレンス": chapter13.md - - "14. wolfSSL SFTP API リファレンス": chapter14.md + - "14. SFTP API リファレンス": chapter14.md + - "15. SCP API リファレンス": chapter15.md + - "16. その他のAPIリファレンス": chapter16.md + - "17. プリプロセッサ ガードマクロ": chapter17.md theme: name: null custom_dir: ../mkdocs-material/material diff --git a/wolfSSH/mkdocs.yml b/wolfSSH/mkdocs.yml index c541b857..42d7748c 100644 --- a/wolfSSH/mkdocs.yml +++ b/wolfSSH/mkdocs.yml @@ -17,7 +17,10 @@ nav: - "11. Support and Consulting": chapter11.md - "12. wolfSSH Updates": chapter12.md - "13. API Reference": chapter13.md - - "14. wolfSSL SFTP API Reference": chapter14.md + - "14. SFTP API Reference": chapter14.md + - "15. SCP API Reference": chapter15.md + - "16. Additional API Reference": chapter16.md + - "17. Preprocessor Guard Macros": chapter17.md theme: name: null custom_dir: ../mkdocs-material/material diff --git a/wolfSSH/src-ja/chapter01.md b/wolfSSH/src-ja/chapter01.md index ae5c48b4..4d0d76b7 100644 --- a/wolfSSH/src-ja/chapter01.md +++ b/wolfSSH/src-ja/chapter01.md @@ -1,49 +1,59 @@ # イントロダクション +このマニュアルは組み込み用 wolfSSH ライブラリの技術ガイドとして書かれています。wolfSSH のビルド方法と使い始め方を説明し、ビルドオプション、機能、サポートなどの概要を提供します。 -このマニュアルは組み込み用wolfSSHライブラリの技術解説書としてお読みいただけるように書かれています。wolfSSHをビルドして起動することから始まり、ビルドオプション、機能、サポートなどの概要を提供します。 - -wolfSSHはC言語で書かれたSSH(セキュアシェル)サーバー実装で、wolfSSLから利用可能なwolfCryptを使用します。さらに、マルチプラットフォームで使用できるようにゼロから構築されています。また、SSHv2仕様に準拠しています。 +wolfSSH は C 言語で書かれた SSH(セキュアシェル)サーバーおよびクライアントの実装で、wolfSSL からも利用可能な wolfCrypt ライブラリを使用します。さらに、wolfSSH はマルチプラットフォームで利用できるようにゼロから構築されています。この実装は SSH v2 仕様に基づいています。 ## プロトコル概要 -SSHは2つの通信端点に多重化されたデータストリームを提供する一連の階層化されたプロトコルです。一般的には、サーバー上のシェルへの接続を保護するために利用されます。ですが、ファイルを安全にコピーしたり、Xディスプレイプロトコルをトンネリングするのにも利用されています。 +SSH は、2 つのピア間で多重化されたデータストリームを提供する階層化されたプロトコル群です。一般的には、サーバー上のシェルへの接続を保護するために利用されます。ただし、2 台のマシン間でファイルを安全にコピーしたり、X ディスプレイプロトコルをトンネリングしたりするためにもよく利用されます。 + +## wolfSSH をお勧めする理由 + +wolfSSH ライブラリは ANSI C で記述された軽量な SSHv2 サーバーおよびクライアントライブラリで、そのサイズの小ささ、速度、機能セットから、主に組み込み機器、RTOS、リソース制約のある環境をターゲットにしています。ロイヤリティフリーの価格設定と優れたクロスプラットフォームサポートにより、標準的な動作環境でも広く利用されています。wolfSSH は業界標準の SSH v2 をサポートしています。wolfSSH は wolfCrypt ライブラリによって支えられています。wolfCrypt 暗号ライブラリのあるバージョンは FIPS 140-3 認証(認証番号 #4718)および FIPS 140-2 認証(認証番号 #3389)を取得しています。追加情報については、wolfCrypt FIPS FAQ を参照するか、fips@wolfssl.com までお問い合わせください。 + +### 機能 + +- SSH v2.0(サーバーおよびクライアント) + +- 最小フットプリントサイズ 33kB + +- 実行時メモリ使用量 1.4KB〜2KB(設定可能な受信バッファは含まず) + +- 複数のハッシュ関数: SHA-1、SHA-2(SHA-256、SHA-384、SHA-512) + +- ブロック暗号および認証付き暗号: AES-CBC、AES-CTR、AES-GCM(128、192、256 ビット鍵) -## wolfSSHをお勧めする理由 +- メッセージ認証: HMAC-SHA1、HMAC-SHA1-96、HMAC-SHA2-256、HMAC-SHA2-512 -wolfSSHはANSI Cで記述された軽量のSSHv2サーバーライブラリで、サイズが軽量でありスピード、機能セットに富んでいる点から、組み込み機器、リアルタイムOSおよびリソース制約のある環境をターゲットにしています。wolfSSHは業界標準のSSH v2をサポートし、さらに先進的なアルゴリズム(ChaCha20, Poly1305, NTRU とSHA-3)も提供しています。wolfSSHを支えているのはwolfCrypt暗号化ライブラリで、このライブラリはFIPS140-2認証(認証#2425)を受けています。より詳細はwolfCrypt FIPS FAQを参照されるかあるいはfacts@wolfssl.comまでお知らせください。 +- 暗号と MAC は接続の方向ごとに個別にネゴシエーション +- 鍵交換オプション: DH(グループ 1、14、16 およびグループ交換)、ECDH(曲線 NISTP256、NISTP384、NISTP521)、Curve25519 -### 機能(特徴) +- ポスト量子ハイブリッド鍵交換: ML-KEM-768 と Curve25519 または NIST P-256 の組み合わせ、ML-KEM-1024 と NIST P-384 の組み合わせ +- 公開鍵認証オプション: RSA(ssh-rsa、rsa-sha2-256、rsa-sha2-512)、ECDSA(曲線 NISTP256、NISTP384、NISTP521)、Ed25519、およびポスト量子の ML-DSA-44、ML-DSA-65、ML-DSA-87(単独、または ECDSA、Ed25519、Ed448 とのコンポジット)。ホスト鍵とユーザー認証の両方に対応 -- SSH v2.0 (サーバー機能) +- RSA も ECDSA も含まないビルド(Ed25519 のみのビルドなど)に対応 -- 最小フットプリント:33kB +- SHA-1 および AES-CBC アルゴリズムはコンパイルされますが、デフォルトでは提示されません -- 実行時メモリ消費量:1.4KB ~ 2KB (受信バッファは含まず) +- Terrapin 攻撃(CVE-2023-48795)への対策である厳格な鍵交換(strict KEX)をデフォルトで有効化 -- ハッシュ関数: SHA-1, SHA-2 (SHA-256, SHA-384, SHA-512), BLAKE2b, Poly +- データ量または送信パケット数をトリガーとする鍵の再交換 -- 暗号アルゴリズム:Block, Stream, and Authenticated Ciphers: AES (CBC, CTR, GCM, CCM), Camellia, ChaCha +- ユーザー認証のサポート(パスワード、keyboard-interactive、公開鍵認証) -- 公開鍵オプション: RSA, DH, EDH, NTRU +- シンプルな API -- ECDH と ECDSA で次の楕円曲線をサポート: NISTP256, NISTP384, NISTP, Curve25519, Ed +- ホスト鍵およびユーザー認証向けの PEM および DER 形式の X.509 証明書サポート(RFC 6187)。ML-DSA 証明書を含みます -- クライアント認証をサポート(RSA key, password) +- wolfSSHd における OpenSSH 証明書によるユーザー認証 -- シンプルなAPI +- TPM 2.0 に格納されたホスト鍵とユーザー鍵、および Windows 証明書ストアからのホスト鍵 -- PEM and DER certificate support +- ハードウェア暗号サポート: Intel AES-NI サポート、Intel AVX1/2、RDRAND、RDSEED、Cavium NITROX サポート、STM32F2/F4 ハードウェア暗号サポート、Freescale CAU / mmCAU / SEC、Microchip PIC32MZ -- ハードウエア暗号サポート: - - Intel AES-NI support - - Intel AVX1/2 - - RDRAND - - RDSEED - - Cavium NITROX - - STM32F2/F4 ハードウエア暗号 - - Freescale CAU / mmCAU / SEC - - Microchip PIC32MZ +- SFTP、SCP、SSH-AGENT、ローカルおよびリモートポートフォワーディング(クライアントおよびサーバー)のサポート +- SSH サーバーデーモン wolfSSHd と SSH クライアントアプリケーション wolfssh diff --git a/wolfSSH/src-ja/chapter02.md b/wolfSSH/src-ja/chapter02.md index 76774981..49b052e7 100644 --- a/wolfSSH/src-ja/chapter02.md +++ b/wolfSSH/src-ja/chapter02.md @@ -1,102 +1,129 @@ -# wolfSSHのビルド +# wolfSSH のビルド -wolfSSHはポータビリティを念頭において開発されているので多くのシステム上に移植するのは容易にできるはずです。ですが、もし移植上で問題がありましたら https://www.wolfssl.com/forums を参照されるか support@wolfssl.com へ質問をお寄せください。 +wolfSSH はポータビリティを念頭において開発されているので、多くのシステム上で概ね容易にビルドできるはずです。もしビルドで問題がありましたら、遠慮なくサポートフォーラム https://www.wolfssl.com/forums を通じてサポートをお求めいただくか、support@wolfssl.com へ直接ご連絡ください。 +この章では、Linux、un\*x 系(BSD、macOS)、および Windows 環境で wolfSSH をビルドする方法を説明し、非標準環境でのビルドに関するガイダンスも提供します。入門ガイドとサンプルは第 3 章に用意しています。 -この章ではwolfSSHを*nix システム(あるいはその派生システム)やWindows上でビルドする方法を説明します。また、上記以外のシステムにおいてのビルド方法のガイダンスも提供します。次章では「サンプルプログラムを使って始めてみよう」を用意しています。 - -autoconf/automakeシステムを使ってビルドする際にはwolfSSHは単一のMakefileによってすべてのコンポーネントとサンプルプログラムをビルドできます。Makefileを繰り返し使用する場合に比べてシンプルで早いです。 +autotools システムを使ってビルドする際には、wolfSSH は単一の Makefile によってライブラリのすべての部分とサンプルをビルドします。これは Makefile を再帰的に使用する場合に比べてシンプルかつ高速です。 ## ソースコードの入手 -最新バージョンのコードを入手する場合には次のGitHubサイトからダウンロードできます:
- [https://github.com/wolfSSL/wolfSSH](https://github.com/wolfSSL/wolfSSH) +最新の最新版は、次の GitHub サイトからダウンロードできます: [https://github.com/wolfSSL/wolfssh](https://github.com/wolfSSL/wolfssh)。 - “Download ZIP” ボタンをクリックするかターミナルを開いて次のコマンドを実行してください:
- +"Download ZIP" ボタンをクリックするか、ターミナルで次のコマンドを実行してください: ``` $ git clone https://github.com/wolfSSL/wolfssh.git ``` - ## wolfSSH が依存するモジュール -wolfSSHはwolfCryptに依存しているので、wolfSSLのコンフィギュレーションが必要となっています。wolfSSLはここからダウンロードできます:
-https://github.com/wolfSSL/wolfssl - -最も簡潔なwolfSSHの構成のためのwolfSSLのコンフィギュレーションを行うにはwolfSSLのルートフォルダから以下のコマンドを実行します:
- +wolfSSH は wolfCrypt に依存しているため、wolfSSL のコンフィギュレーションが必要です。wolfSSL はここからダウンロードできます: [https://github.com/wolfSSL/wolfssl](https://github.com/wolfSSL/wolfssl)。wolfSSH に必要な最も簡潔な wolfSSL の構成は、既定のビルドです。これは wolfSSL のルートフォルダから次のコマンドでビルドできます: ``` -$ ./autogen.sh (GitHubからクローンした場合にのみ実行が必要) -$ ./configure --enable-ssh +$ ./autogen.sh (GitHub からクローンした場合にのみ実行が必要) +$ ./configure --enable-wolfssh $ make check $ sudo make install ``` +wolfSSH の鍵生成機能を利用するには、wolfSSL を keygen 付きでコンフィギュレーションする必要があります: +``` +--enable-keygen +``` +wolfSSL コードの大部分が不要な場合は、crypto only オプションで wolfSSL をコンフィギュレーションできます: +``` +--enable-cryptonly +``` -wolfSSHの鍵生成機能を利用する場合には `--enable-keygen` を追加してください。 -また、もしwolfSSLのコードが必要ない場合には `--enable-cryptonly` を追加してください。 - -上記により、wolfSSHの実行に必要なwolfSSLライブラリがインストールされます。 +wolfSSH には `--enable-wolfssh`(`WOLFSSL_WOLFSSH` を定義します)付きでビルドした wolfSSL が必要です。このオプションなしでビルドされた wolfSSL に対して wolfSSH をビルドすると、`#error` で停止します。wolfSSH の一部の機能には、さらに次の wolfSSL オプションが必要です: -## *nixシステム上でのwolfSSHのビルド +- X.509 証明書(`--enable-certs`)は wolfSSL の証明書マネージャーを使用するため、wolfSSL は `--enable-cryptonly` ではなく TLS 付きでビルドする必要があります。OCSP による問い合わせを可能にするには `--enable-ocsp` を追加してください。 +- Curve25519 鍵交換には `--enable-curve25519` が必要です。 +- ML-KEM ハイブリッド鍵交換には `--enable-mlkem` が必要です。 +- ML-DSA のホスト鍵とユーザー認証には `--enable-mldsa` と wolfSSL 5.9.2 以降が必要です。 +- TPM サポート(`--enable-tpm`)には `--enable-wolftpm` 付きでビルドした wolfSSL と wolfTPM が必要です。 +- wolfssh クライアントアプリケーション(`--enable-sshclient`)には、スレッド対応の wolfSSL と wolfSSL の Base64 エンコーダー(`--enable-base64encode`、x86_64 でのみデフォルトで有効)が必要です。 -Linux, *BSD, OS X, Solaris *nix類似のシステム上でビルドを行う場合には、autoconfシステムを利用します。wolfSSHのビルドには以下のコマンドを実行します:
+## autotools でのビルド +Linux、BSD、macOS、Solaris、その他の un\*x 系環境でビルドする場合は、autotools システムを使用します。wolfSSH をビルドするには次のコマンドを実行します: ``` -$ ./autogen.sh (GitHubからクローンした場合にのみ実行が必要) +$ ./autogen.sh (GitHub からクローンした場合にのみ実行が必要) $ ./configure $ make $ make install ``` - -configureコマンドにはオプションを追加することができます。追加可能なオプションとその用途は以下のコマンドで参照することができます:
- +configure コマンドにはビルドオプションを追加できます。利用可能な configure オプションとその用途の一覧は、次のコマンドで参照できます: ``` $ ./configure --help ``` - -wolfSSHのビルドには以下を実行してください: - +wolfSSH をビルドするには次を実行します: ``` $ make ``` - -wolfSSHのビルドが正常に終了したことを確認する為に、以下のコマンドを実行して、全てのテストがパスすることを確認してください: - +wolfSSH が正しくビルドされたことを確認するために、次のコマンドで全てのテストがパスしたかどうかを確認してください: ``` $ make check ``` -以下を実行してwolfSSHをインストールします: - +wolfSSH をインストールするには次を実行します: ``` $ make install ``` -インストールにはスーパーユーザー権限が必要なので、場合によっては以下の様に'sudo'コマンドを前置して実行する必要があるかもしれません: - +インストールにはスーパーユーザー権限が必要な場合があり、その場合は sudo を付けてインストールを実行してください: ``` $ sudo make install ``` - -場合によっては、wolfssh/src以下のwolfSSHライブラリだけをビルドし、その他のアイテム(サンプルプログラムやテスト)を除外したいかもしれません。その場合にはwolfSSHのルートフォルダから以下のコマンドを実行してください: - +wolfssh/src/ にある wolfSSH ライブラリのみをビルドし、追加のアイテム(サンプルとテスト)はビルドしたくない場合は、wolfSSH のルートフォルダから次のコマンドを実行できます: ``` $ make src/libwolfssh.la ``` +## ビルドオプション + +`./configure` には次のオプションを指定できます。各機能オプションは、「wolfSSH プリプロセッサガードマクロ」の章でそのオプションに対応して記載されているプリプロセッサマクロも定義します。 + +| オプション | デフォルト | 説明 | +|-------------------------------|-----------|--------------------------------------------| +| `--with-wolfssl=PATH` | /usr/local | wolfSSL のインストールプレフィックス。`PATH/lib` と `PATH/include` が存在している必要があります。 | +| `--enable-debug` | 無効 | デバッグコードとログ出力を追加し、最適化を無効にします。 | +| `--disable-inline` | 有効 | インライン関数を無効にします。 | +| `--disable-examples` | 有効 | サンプルプログラムをビルドしません。 | +| `--disable-server` | 有効 | サーバーのコードを除外します。`--disable-client` と同時には指定できません。 | +| `--disable-client` | 有効 | クライアントのコードを除外します。`--disable-server` と同時には指定できません。 | +| `--enable-keygen` | 無効 | 鍵生成 API。wolfSSL には `--enable-keygen` が必要です。 | +| `--enable-keyboard-interactive` | 無効 | keyboard-interactive ユーザー認証。 | +| `--enable-scp` | 無効 | SCP サポート。 | +| `--enable-sftp` | 無効 | SFTP サポート。 | +| `--disable-sftp-zeroize` | 有効 | SFTP のファイルデータバッファを解放前にゼロクリアしません。 | +| `--enable-fwd` | 無効 | TCP/IP ポートフォワーディング。 | +| `--disable-term` | 有効 | 疑似端末サポートを除外します。 | +| `--enable-shell` | 無効 | echoserver でのシェルサポート。 | +| `--enable-agent` | 無効 | ssh-agent サポート。 | +| `--enable-certs` | 無効 | X.509 証明書サポート。 | +| `--enable-ossh-certs` | 無効 | OpenSSH 証明書によるユーザー認証。 | +| `--enable-windows-cert-store` | 無効 | Windows 証明書ストアから鍵と証明書を読み込みます。`--enable-certs` と mingw の Windows ホストが必要です。`crypt32` と `ncrypt` をリンクします。 | +| `--enable-tpm` | 無効 | wolfTPM による TPM 2.0 サポート。 | +| `--enable-smallstack` | 無効 | 大きなバッファをヒープから確保し、スタック使用量を削減します。 | +| `--enable-none-cipher` | 無効 | 暗号化と完全性保護を無効にする安全でない "none" 暗号および MAC のネゴシエーションを許可します。 | +| `--enable-sshd` | 無効 | wolfSSHd サーバーデーモンをビルドします。`--enable-shell` も有効にします。 | +| `--with-pam=PATH` | なし | wolfSSHd 用の PAM ライブラリのディレクトリ。 | +| `--enable-sshclient` | 無効 | wolfssh クライアントアプリケーションをビルドします。 | +| `--enable-all` | 無効 | keygen、keyboard-interactive、scp、sftp、fwd、shell、agent、sshd、sshclient、certs を有効にします。 | +| `--enable-distro` | 無効 | `--enable-all` に加えて、共有ライブラリとスタティックライブラリの両方をビルドします。 | -## Windows上でのwolfSSHのビルド +wolfssh クライアントアプリケーションはすべてのセッションの I/O をスレッド上で実行するため、スレッド対応の wolfSSL が必要です。シングルスレッドの wolfSSL に対して `--enable-sshclient` を指定すると configure エラーになりますが、`--enable-all` の場合は失敗せずにクライアントを除外します。 -Visual Studioプロジェクトファイルは以下で取得できます: -https://github.com/wolfSSL/wolfssh/blob/master/ide/winvs/wolfssh.sln +`--enable-all` は `--enable-ossh-certs`、`--enable-windows-cert-store`、`--enable-tpm`、`--enable-smallstack`、`--enable-none-cipher` を有効にしません。これらは明示的に追加してください。 +ビルドツリー内の `./apps/wolfssh-options` は、有効になっている各ビルドオプションの名前を 1 行に 1 つずつ出力します。テストスクリプトでの使用を想定したもので、インストールはされません。 -ソリューションファイル'wolfssh.sln'はwolfSSH,そのサンプルプログラムとテストプログラムをビルドするように構成されています。DebugビルドとReleaseビルドの構成をスタティックリンクライブラリとダイナミック(32/64ビット)ライブラリの両形式で提供しています。user_settings.hはwolfSSLのコンフィギュレーションで必要となります。 +## Windows 上でのビルド +Visual Studio のプロジェクトファイルは *ide\\winvs* ディレクトリにあります。 -このプロジェクトファイルではwolfSSHとwolfSSLのソースフォルダ階層が隣同士に配置されていることを前提にしています。また、それらのルートフォルダにはバージョン番号が含まれていないフォルダ名となっていることを前提としています。つまり、次のようなフォルダ構成です: +ソリューションファイル 'wolfssh.sln' により、wolfSSH とそのサンプルおよびテストプログラムをビルドできます。このソリューションは、スタティックおよびダイナミックの 32 ビットまたは 64 ビットライブラリの Debug ビルドと Release ビルドの両方を提供します。wolfSSL のビルドをコンフィギュレーションするには user_settings.h を使用してください。 +このプロジェクトは、wolfSSH と wolfSSL のソースディレクトリが隣り合わせにインストールされ、そのフォルダ名にバージョン番号が含まれていないことを前提としています: ``` Projects\ @@ -104,96 +131,74 @@ wolfssh\ wolfssl\ ``` -`wolfssh\ide\winvs\user_settings.h`ファイルはwolfSSLに対する設定も既に含んだ適切な内容となっています。このファイルを忘れずに`wolfssh\ide\winvs`フォルダから`wolfssl\IDE\WIN`フォルダにコピーしてください。もし、一方の内容を変更した場合には、 -その内容を他方にもコピーして下さい。 - -`WOLFCRYPT_ONLY`マクロ定義はwolfSSLコードをビルド対象から除外し、wolfCryptのアルゴリズム部分のみをビルドするの為に指定してあります。もし、wolfSSLコードもビルドする場合にはこの定義を削除してください。 - +`wolfssh\ide\winvs\user_settings.h` ファイルには、wolfSSL を適切な設定でコンフィギュレーションするための設定が含まれています。このファイルは `wolfssh\ide\winvs` ディレクトリから `wolfssl\IDE\WIN` へコピーする必要があります。一方のコピーを変更した場合は、両方のコピーを変更しなければなりません。`WOLFCRYPT_ONLY` オプションは wolfSSL ファイルのビルドを無効にし、wolfCrypt アルゴリズムのみをビルドします。wolfSSL も残すには、このオプションを削除してください。X.509 証明書サポートには TLS 層が必要なため、このファイルの X.509 ブロックでは `WOLFSSH_CERTS` を定義するとともに `WOLFCRYPT_ONLY` を削除しています。 -### Windows上でのビルドに使用するユーザーマクロ定義 +各プロジェクトは、Windows 証明書ストアのサポート(`WOLFSSH_WINDOWS_CERT_STORE`)のために Windows の `crypt32.lib` および `ncrypt.lib` インポートライブラリとリンクします。これを使用するには、`user_settings.h` のコメントブロックの説明にしたがって、`WOLFSSH_CERTS` とともに `WOLFSSH_WINDOWS_CERT_STORE` を定義してください。 +### Windows 上でのビルドに使用するユーザーマクロ +このソリューションでは、wolfSSL ライブラリとヘッダーの場所を示すためにユーザーマクロを使用します。すべてのパスは wolfssl64 ソリューションの既定のビルド出力先に設定されています。ユーザーマクロ wolfCryptDir は、ライブラリを検索するためのベースパスとして使用されます。初期値は `..\..\..\..\wolfssl` に設定されています。そして、例えば API テストプロジェクトの追加インクルードディレクトリの値は `$(wolfCryptDir)` に設定されています。 -ソリューションではwolfSSLライブラリとヘッダーファイルのロケーションを指定するためにユーザーマクロを利用します。wolfssl64ソリューションでは全てのパスは既定のビルド出力先に設定されます。ユーザーマクロ'wolfCryptDir'はライブラリを検索するためのベースパスとして使用します。初期値として、`..\..\..\..\wolfssl`に設定されています。その後、例えば追加のインクルードファイル検索パスが追加される場合には、`$(wolfCryptDir)`に対して追加を行います。 - -wolfCryptDirパスはプロジェクトファイルからの相対位置で表せなければなりません。 - - +wolfCryptDir パスは、プロジェクトファイルからの相対パスでなければなりません。プロジェクトファイルはすべて 1 つ下のディレクトリにあります。 ``` wolfssh/wolfssh.vcxproj unit-test/unit-test.vcxproj ``` - -そのほかのユーザーマクロは異なるビルドターゲットのためのディレクトリを表すために使用されます。例えば、 `wolfCryptDllRelease64` は次のフォルダを表します: - - +その他のユーザーマクロは、異なるビルド向けの wolfSSL ライブラリが見つかるディレクトリです。したがって、ユーザーマクロ 'wolfCryptDllRelease64' は初期値として次のように設定されています: ``` -$(wolfCryptDir)\x64\DLL Release +$(wolfCryptDir)\DLL Release\x64 ``` - -このパスはechoserverサンプルプログラムのデバッグ環境設定で64-bit DLLリリースビルド版の出力先を表現するのに次の様に使われます: - +この値は、echoserver の 64 ビット DLL Release ビルドのデバッグ環境で次のように設定して使用されます: ``` PATH=$(wolfCryptDllRelease64);%PATH% ``` +デバッガーから echoserver を実行すると、そのディレクトリで wolfSSL DLL が見つかります。 -echoserverプログラムをデバッガーを使って実行する際にはこの設定によってwolfSSL DLLがこのディレクトリから見つかります。 - - -## その他の環境上でのビルド - -公式にはサポートしていませんが、wolfSSHを非標準の環境でビルドしたいお客様、特に組み込み機器向け環境でのビルドをご希望の方々をできるだけお手伝いしようとしています。以下はその際に理解しておいていただきたい点です: - -1. ソースとヘッダーファイルはwolfSSHダウンロードパッケージの階層構造に存在する必要があります。 -2. いくつかのビルドシステムではwolfSSHヘッダーファイルの格納場所を明示的に指定することを求める場合があります。その格納場所は/wolfsshディレクトリなので通常はディレクトリをインクルードファイルパスに追加することで解決します。 -3. wolfSSHはコンフィギュレーションで指定されない限りリトルエンディアンをデフォルトにしています。ユーザーが使用している非標準環境ではconfigureコマンドを使用していない場合で、ビッグエンディアンシステムに指定する場合にはBIG_ENDIAN_ORDERマクロ定義が必要となります。 -4. ライブラリをビルドしてみて何か問題が生じた場合にはwolfSSLにお知らせください。サポートが必要な場合には、support@wolfssl.com 宛てにご連絡ください。 +## 非標準環境でのビルド +公式にはサポートしていませんが、非標準環境、特に組み込みおよびクロスコンパイル環境で wolfSSH をビルドしたいユーザーをできるだけお手伝いしようとしています。以下は、その際に理解しておいていただきたい点です: +1. ソースファイルとヘッダーファイルは、wolfSSH ダウンロードパッケージにある階層構造のまま維持する必要があります。 +2. 一部のビルドシステムでは、wolfSSH ヘッダーファイルの場所を明示的に知る必要があるため、それを指定しなければならない場合があります。それらは /wolfssh ディレクトリにあります。通常、 ディレクトリをインクルードパスに追加することでヘッダーの問題を解決できます。 +3. wolfSSH は、configure プロセスがビッグエンディアンを検出しない限り、リトルエンディアンシステムを既定とします。非標準環境でビルドするユーザーは configure プロセスを使用していないため、ビッグエンディアンシステムを使用する場合は BIG_ENDIAN_ORDER を定義する必要があります。 +4. ライブラリをビルドしてみて、何か問題が生じた場合はお知らせください。サポートが必要な場合は、support@wolfssl.com までご連絡ください。 ## クロスコンパイル +組み込みプラットフォームの多くのユーザーは、自身の環境向けにクロスコンパイルを行います。ライブラリをクロスコンパイルする最も簡単な方法は、configure システムを使用することです。configure システムは Makefile を生成し、それを使って wolfSSH をビルドできます。 -組み込み機器開発環境ではクロスコンパイルを行います。そのための簡単な方法はライブラリをコンフィギュアシステムを使ってクロスコンパイルを行うことです。コンフィギュアシステムはMakefileを一つ生成し、それを使ってwolfSSHをビルドします。 - -クロスコンパイルを行う際には、次の様にコンフィギュアを行うホストを指定する必要があります: - +クロスコンパイルを行う際には、次のようにコンフィギュレーションするホストを指定する必要があります: ``` $ ./configure --host=arm-linux ``` - -さらにコンパイラ、リンカー等も指定する必要があるでしょう: - +また、使用したいコンパイラやリンカーなどを指定する必要がある場合もあります: ``` -$ ./configure --host=arm-linux CC=arm-linux-gcc AR=arm-linux-ar RANLIB=arm-linux +$ ./configure --host=arm-linux CC=arm-linux-gcc AR=arm- +linux-ar +RANLIB=arm-linux ``` - -クロスコンパイル用にwolfSSHを正しくコンフィギュレーションできた後は、標準のautoconf作法にしたがってビルドとライブラリのインストールを行います: +クロスコンパイル用に wolfSSH を正しくコンフィギュレーションできた後は、標準の autoconf の作法にしたがってライブラリのビルドとインストールを行えるはずです: ``` $ make $ sudo make install ``` - -ここでご紹介した以外のTipsをお持ちでしたらぜひ facts@wolfssl.comまで お知らせください。 +wolfSSH のクロスコンパイルに関する追加の Tips やフィードバックがありましたら、facts@wolfssl.com までお知らせください。 ## カスタムディレクトリへのインストール -wolfSSLをカスタムディレクトリへインストールする場合には次のようにしてください: - +wolfSSL のカスタムインストールディレクトリを設定するには、次のようにします: ``` -$ ./configure --prefix=`~`/wolfSSL +$ ./configure --prefix=~/wolfSSL $ make $ make install ``` - -上記コマンドによってライブラリを ”~/wolfSSL/lib” に、インクルードファイルを ”~/wolfssl/include” に配置するように指定します。wolfSSHをカスタムディレクトリに配置する場合には次の様にしてください: - - +これにより、ライブラリは ~/wolfSSL/lib に、インクルードは ~/wolfSSL/include に配置されます。wolfSSH のカスタムインストールディレクトリを設定し、その wolfSSL のインストール先を参照させるには、次のようにします: ``` -$ ./configure --prefix=`~`/wolfssh --libdir=`~`/wolfssl/lib --includedir=`~`/wolfssl/include +$ ./configure --prefix=~/wolfssh --with-wolfssl=~/wolfSSL $ make $ make install ``` +--with-wolfssl オプションには wolfSSL のインストール先プレフィックスを指定します。その配下に lib/ と include/ があることが前提です。wolfSSH に wolfSSL の場所を伝えるのはこのオプションです。--libdir および --includedir オプションは wolfSSH 自身のライブラリとヘッダーのインストール先を設定するものであり、wolfSSL の検索先には影響しません。 -上記パスがご自分の実際のディレクトリとマッチすることを確認して下さい。 +上記のパスが実際の場所と一致していることを確認してください。 diff --git a/wolfSSH/src-ja/chapter03.md b/wolfSSH/src-ja/chapter03.md index f3516a65..b114118e 100644 --- a/wolfSSH/src-ja/chapter03.md +++ b/wolfSSH/src-ja/chapter03.md @@ -1,249 +1,506 @@ # 始めよう -wolfSSHのダウンロードとビルドが終わったら、テストプログラムとサンプルプログラムが自動的に作成されているはずです。 - +wolfSSHのダウンロードとビルドが終わったら、ライブラリの使い方を示す自動テストプログラムとサンプルプログラムが用意されています。 ## テスト ### wolfSSHユニットテスト -wolfSSHのユニットテストはAPIの動作を確認するためのものです。ポジティブ/ネガティブの両テストケースが実行されます。テストはマニュアルで実行することができますが、他の処理の一部(例えばmake check コマンド実行時)として実行される場合もあります。 +wolfSSHのユニットテストはAPIの動作を確認するためのものです。ポジティブ/ネガティブの両テストケースが実行されます。テストはマニュアルで実行することができますが、makeやmake checkコマンドなど他の自動化された処理の一部として実行される場合もあります。`make check`コマンドは、APIテスト(`tests/api.test`)、リグレッションテスト(`tests/regress.test`)、クライアント/サーバーテストスイート(`tests/testsuite.test`)、鍵交換テスト(`tests/kex.test`)も実行します。 -全てのサンプルプログラムとテストはwolfSSHのホームディレクトリから実行されなければなりません。実行時に必要な各種証明書と鍵をプログラムが見つけることができるようにするためです。 +全てのサンプルプログラムとテストはwolfSSHのホームディレクトリから実行されなければなりません。実行時に必要な各種証明書と鍵をテストツールが見つけることができるようにするためです。 ユニットテストをマニュアルで実行するには次のようにします: - ``` $ ./tests/unit.test ``` - あるいは - ``` $ make check (autoconfが使われている場合) ``` ### テストに関する注記事項 -レポジトリをクローンした後、テスト用の秘密鍵はユーザーにとってはリードオンリーになっていることを確認してください。そうなっていない場合はssh_clientサンプルプログラムは警告します。 - +レポジトリをクローンした後、テスト用の秘密鍵はユーザーにとってリードオンリーになっていることを確認してください。そうなっていない場合はsshクライアントがそうするように警告します。 ``` $ chmod 0600 ./keys/gretel-key-rsa.pem ./keys/hansel-key-rsa.pem \ ./keys/gretel-key-ecc.pem ./keys/hansel-key-ecc.pem ``` - サンプルプログラムechoserverに対しての認証はパスワードあるいは公開鍵を使って行うことができます。パスワードを使う場合は次のコマンドを使ってください: - - ``` -$ ssh_client -p 22222 USER@localhost +$ ssh -p 22222 USER@localhost ``` -ここでUSERとしてのユーザーとそのパスワードとして次の2つのペアが使えます: - +ここで_USER_としてのユーザーとそのパスワードとして次の2つのペアが使えます: ``` jill:upthehill jack:fetchapail ``` 公開鍵を使った認証を行う場合には次のコマンドを使います: - ``` -$ ssh_client -i ./keys/USER-key-TYPE.pem -p 22222 USER@localhost +$ ssh -i ./keys/USER-key-TYPE.pem -p 22222 USER@localhost ``` -ここで、USERの部分にはgretelかhanselが指定できて、TYPEにはrsaかeccを指定します。 - -echoserverはそのwsUserAuthコールバック関数に偽のアカウント(jack, jill, hansel, とgretel)を用意してあります。後述するシェルサポートが有効になっている場合には、これらの偽アカウントは機能しません。これらのアカウントを使って認証を試みてもサーバーにはシステムのパスワードファイルにこれらのアカウントのおパスワードは存在していないので認証に失敗します。新たなユーザーとパスワードあるいは公開鍵リストをechoserverに追加することができます。追加されたアカウントでは、echoserverによって起動されたシェルにechoserverを起動したユーザー権限でログインすることができます。 +ここで、_USER_の部分にはgretelかhanselが指定でき、TYPEにはrsaかeccを指定します。echoserverはデフォルトではRSA鍵を受け付けます。代わりにECC鍵を受け付けるには、オプション`-e`を指定してください。 +echoserverはそのwsUserAuthコールバック関数に複数の偽のアカウント(jack, jill, hansel, とgretel)を用意してあります。後述するシェルサポートが有効になっている場合には、これらの偽アカウントは機能しません。これらのアカウントはシステムのパスワードファイルに存在しないためです。ユーザー認証は成功しますが、システム上にこれらのアカウントが存在しないためサーバー側でエラーになります。echoserverのパスワードリストあるいは公開鍵リストに自分自身のユーザー名を追加することができます。追加されたアカウントでは、echoserverによって起動されたシェルにechoserverを起動したユーザーの権限でログインすることができます。 ## サンプルプログラム ### wolfSSH echoserver -echoserverサンプルプログラムはwolfSSHのサンプルプログラム中で最も多くの処理をこなすプログラムです。用意されているアカウントを認証することを許された唯一のユーザーであり、入力された文字を繰り返し出力します。後の章で説明するシェルサポートが有効になっている場合には、ユーザーシェルを起動することができます。echoserverの実行にはマシン上での実際のユーザ名とクレデンシャルを検証する為の更新した認証コールバック関数を必要とします。 - -ターミナルから次のコマンドを事項してください: - +echoserverサンプルプログラムはwolfSSHのサンプルプログラム中で最も多くの処理をこなすプログラムです。もともとは用意されたアカウントのいずれかで認証を行い、入力された文字を繰り返し出力するだけのものでした。後のセクションで説明するシェルサポートを有効にすると、ユーザーシェルを起動することができます。その場合、マシン上の実際のユーザー名と、そのクレデンシャルを検証するために更新されたユーザー認証コールバック関数が必要になります。echoserverはSCPおよびSFTP接続も扱うことができます。ターミナルから次を実行してください: ``` -$ ./examples/echoserver/echoserver -f + $ ./examples/echoserver/echoserver -f ``` - `-f` オプションはエコーバックだけを行うモードを指定します。 - 別のターミナルを開いて次のコマンドを実行してください: +`-f` オプションはエコーバックだけを行うモードを有効にします。別のターミナルから次を実行してください: ``` -$ ssh_client jill@localhost -p 22222 + $ ssh jill@localhost -p 22222 ``` -パスワードの入力を求められたら"upthehill"と入力してください。サーバーは次のバナーを返信してくるはずです: - - +パスワードの入力を求められたら"upthehill"と入力してください。サーバーは次のバナーをクライアントに送信します: ``` wolfSSH Example Echo Server ``` -ssh_clientにタイプした文字はサーバーからエコーバックされて表示されます。入力した文字が2度スクリーンにエコーバックされたとしたらそれはローカルのエコーバックが有効になっているからです。echoserverは正規のターミナルではないので、CR/LF 改行の変換が期待通りに機能しないかもしれません。 +クライアントにタイプした文字はサーバーからスクリーンにエコーバックされます。文字が2度エコーバックされたとしたら、それはクライアントのローカルエコーが有効になっているからです。echoserverは正規のターミナルとして振る舞ってはいないので、CR/LFの変換が期待通りに機能しないことがあります。 以下の制御文字はechoserverで特別な動作を引き起こします: -- CTRL-C: コネクションを切断 -- CTRL-E: セッション状況をプリントアウト -- CTRL-F: 新たな鍵交換をトリガー - -echoserverサンプルプログラムには以下のコマンドラインオプションが指定できます: +- CTRL-C: コネクションを切断します。 +- CTRL-E: いくつかのセッション統計をプリントアウトします。 +- CTRL-F: 新たな鍵交換をトリガーします。 +echoserverサンプルプログラムには以下のコマンドラインオプションが指定できます。一部のオプションは、対応する機能が組み込まれている場合にのみ使用できます。 ``` + -? ヘルプを表示して終了する -1 一回の接続後に終了する -e クライアントからECC公開鍵を受け取る - -E ECC秘密鍵を使う - -f 入力をエコーする - -p 待ち受けポート番号を指定する(デフォルトは22222) + -E ECC秘密鍵を先にロードする + -f 入力をエコーする(シェル対応ビルドのみ) + -A アプリケーションコールバックからチャネルを駆動する + -p 待ち受けポート番号を指定する(デフォルトは22222) -N ノンブロッキングソケットを使う -d SFTPコネクションのホームディレクトリを指定する - -j 接続相手からの公開鍵を受け付ける為にロードする + -D SFTPコネクションをホームディレクトリから開始する + だけでなく、ホームディレクトリ内に制限する + -j 接続相手からのSSH公開鍵を受け付ける為にロードする + (ユーザーはコメントにあるものとみなす) + -I : + 接続相手からのSSH公開鍵を受け付ける為にロードする + -s デフォルトのhansel鍵を置き換えるTPM公開鍵ファイルを + ロードする + -G TPMからECC/RSAホスト鍵blobをロードする(秘密鍵は + TPM内に留まる) + -J : + 接続相手からのX.509 PEM証明書を受け付ける為にロードする + -K : + 接続相手からのX.509 DER証明書を受け付ける為にロードする + -P : + 接続相手から受け付けるパスワードを追加する + -i : + 接続相手からkeyboard-interactiveで受け付ける + パスワードを追加する + -a ルートCA証明書ファイルをロードする + -k 使用する鍵アルゴリズムのカンマ区切りリストを指定する + -x 使用する鍵交換アルゴリズムのカンマ区切りリストを + 指定する + -m 使用するMACアルゴリズムのカンマ区切りリストを指定する + -W Windows証明書ストア: "store:subject[:flags]" + -b ユーザー認証がブロックする場合をテストする + -H テスト用のハイウォーターコールバックを設定する ``` ### wolfSSH Client -このクライアントプログラムははSSHサーバーと接続を確立します。簡単モードでは"Hello, wolfSSH!"をサーバーに送信し、サーバーからの応答を表示して終了します。疑似ターミナルオプションではこのクライアントプログラムは実際のクライアントとして機能します。 - -クライアントサンプルプログラムには以下のコマンドラインオプションが指定できます: +このクライアントはSSHサーバーとの接続を確立します。最も単純なモードでは"Hello, wolfSSH!"という文字列をサーバーに送信し、その応答を表示して終了します。疑似ターミナルオプションを使うと、このクライアントは実際のクライアントとして機能します。 +クライアントサンプルプログラムには以下のコマンドラインオプションが指定できます。一部のオプションは、対応する機能が組み込まれている場合にのみ使用できます。 ``` + -? ヘルプを表示して終了する -h 接続先ホストアドレス(デフォルト 127.0.0.1) -p 接続先ポート(デフォルト 22222) -u 認証の為のユーザー名(指定必須) -P パスワード(省略した場合はプロンプトが表示される) + -K TPM鍵の認証パスワード -e サンプルecc公開鍵を指定 -i ユーザーの秘密鍵ファイル名 -j ユーザーの公開鍵ファイル名 - -x 接続完了後、データ送受信することなく終了 + -x 接続成功後、データの読み書きをせずに終了 -N ノンブロッキングソケットを使う -t 疑似ターミナルを使用 - -c リモートコマンドとpipe stdin/stdout を使用する + -c リモートコマンドを実行し stdin/stdout をパイプする + -R 変換なしの生の出力(Windowsのみ) -a SSH-AGENTの使用を試みる + -J 使用するDER証明書のファイル名 + -A ホストを検証するためのDER CA証明書のファイル名 + -X 接続相手と接続相手の証明書のIPチェックを無視する + -E 使用可能なすべてのアルゴリズムを一覧表示する + -k 鍵アルゴリズムのリストを指定する + -C 暗号化アルゴリズムのリストを指定する + -q デバッグ出力をオフにする ``` ### wolfSSH portfwd -portfwdサンプルプログラムはSSHサーバーと接続を確立し、ローカルポートフォワーディングのための待ち受けポートをリスンするかあるいはリスンしているリスナーに対してリモートポートフォワーディングを要求します。接続確立の後はプログラムは終了します。 +portfwdサンプルプログラムはSSHサーバーとの接続を確立し、ローカルポートフォワーディングのための待ち受けリスナーを設定するか、あるいはオプション`-r`を指定した場合はリモートポートフォワーディングのための待ち受けをサーバーに要求します。プログラムは接続が終了するまで動作し続けます。 portfwd サンプルプログラムには以下のコマンドラインオプションが指定できます: ``` + -? ヘルプを表示して終了する -h 接続先SSHサーバーアドレス(デフォルト 127.0.0.1) -p 接続先SSHサーバーポート(デフォルト 22222) -u ユーザー名(指定必須) -P パスワード(省略した場合はプロンプトが表示される) -F フォーワード元ホストアドレス(デフォルト 0.0.0.0) - -f フォーワード元ホストポート(指定必須) + -f フォーワード元ホストポート(指定必須)。-rと共に0を + 指定すると、リスナーのポートを接続相手が選択する -T フォーワード先ホストアドレス(デフォルト host) -t フォーワード先ホストポート(指定必須) + -r リモート(リバース)フォワード: SSHサーバーに-F/-fで + 待ち受けさせ、接続をローカルの-T/-t宛てにトンネルで + 戻す ``` ### wolfSSH scpclient -scpclientとwolfscpはSSHサーバーと接続を確立し、指定されたファイルをローカルマシンにコピー、あるいはローカルマシンのファイルをサーバーにコピーします。 -wolfSSHのサンプルプログラムを使用する際は、絶対パスを使用する必要があり、ディレクトリは`/`で終わる必要があります。 +scpclient、すなわちwolfscpはSSHサーバーとの接続を確立し、指定されたファイルをサーバーへ、あるいはサーバーからローカルマシンへコピーします。wolfSSHのサンプルプログラムを使用する際は、絶対パスを使用する必要があり、ディレクトリは`/`で終わる必要があります。 scpclientサンプルプログラムには以下のコマンドラインオプションが指定できます: - ``` + -h ヘルプを表示して終了する -H 接続先SSHサーバーアドレス(デフォルト 127.0.0.1) -p 接続先SSHサーバーポート(デフォルト 22222) -u ユーザー名(指定必須) -P パスワード(省略した場合はプロンプトが表示される) - -L : ローカルマシンのfromからサーバーのtoへコピーする - -S : サーバーのfromからローカルマシンのtoへコピーする + -L : ローカルマシンからサーバーへコピーする + -S : サーバーからローカルマシンへコピーする + -i ユーザーの秘密鍵ファイル名 + -j ユーザーの公開鍵ファイル名 + -J 使用するDER証明書のファイル名 + -A ホストを検証するためのDER CA証明書のファイル名 + -X 接続相手と接続相手の証明書のIPチェックを無視する ``` -# wolfSSH sftpclient - -sftpclient, wolfsftpはSSHサーバーと接続を確立し、ディレクトリ移動、ファイル取得、ファイル配置、ディレクトリ追加・削除等を実行します。 - - +### wolfSSH sftpclient -sftpclientサンプルプログラムには以下のコマンドラインオプションが指定できます: +sftpclient、すなわちwolfsftpはSSHサーバーとの接続を確立し、ディレクトリ移動、ファイルの取得と配置、ディレクトリの作成と削除などを実行できるようにします。 +sftpclientサンプルプログラムには以下のコマンドラインオプションが指定できます。一部のオプションは、対応する機能が組み込まれている場合にのみ使用できます。 ``` + -? ヘルプを表示して終了する -h 接続先SSHサーバーアドレス(デフォルト 127.0.0.1) -p 接続先SSHサーバーポート(デフォルト 22222) -u ユーザー名(指定必須) -P パスワード(省略した場合はプロンプトが表示される) - -d ローカルマシンのデフォルトのパスを設定 + -d ローカルマシンのデフォルトのパスを設定する -N ノンブロッキングソケットを使う - -e ECC公開鍵を使ってユーザー認証を行う -l ローカルファイル名 -r リモートファイル名 - -g ローカルファイルをリモートファイルとして送信 - -G リモートファイルをローカルファイルとして受信 + -g ローカルファイルをリモートファイルとして送信する + -G リモートファイルをローカルファイルとして受信する + -i ユーザーの秘密鍵ファイル名 + -j ユーザーの公開鍵ファイル名 + -k 受け付けるサーバーホスト鍵アルゴリズムのカンマ区切り + リストを指定する + -W Windows証明書ストア: "store:subject[:flags]" + -J 使用するDER証明書のファイル名 + -A ホストを検証するためのDER CA証明書のファイル名 + -X 接続相手と接続相手の証明書のIPチェックを無視する ``` -### wolfSSHサーバー +### wolfsshクライアントアプリケーション -serverはプレースホルダーとして存在しています。 +wolfsshクライアントアプリケーションは`--enable-sshclient`を指定してビルドされ、サーバーに接続してターミナルを開くか、あるいは接続先の後に指定されたコマンドを実行します。ユーザー名はデフォルトで現在のユーザーとなり、認証には秘密鍵`$HOME/.ssh/id_ecdsa`を使用します。 +``` + wolfssh [-a] [-E logfile] [-G] [-l login_name] [-p port] [-V] + destination [command] +``` +オプションは次のとおりです: +``` + -a SSH-AGENTの使用を試みる(agent対応ビルドのみ) + -E logfile ログをstderrではなくこのファイルに追記し、ログ出力を + 有効にする + -G 使用される設定を出力する + -l login_name 接続先に含まれるログイン名を上書きする + -p port 接続先のポート番号を上書きする + -V バージョンを出力する +``` -## SCP +接続先は`[user@]hostname`または`ssh://[user@]hostname[:port]`のいずれかです。デフォルトのポートは22です。オプション`-N`は受け付けられなくなりました。 -wolfSSHはscpの為のサーバー側サポート(サーバーへのファイルコピーとサーバーからのファイルのコピーの両方)を含んでいます。単一ファイルのコピーとディレクトリ単位の再帰的コピーの両方をデフォルトの送信コールバックあるいは受信コールバックでサポートしています。 +### wolfSSHd -wolfSSHをscpサポート機能を有効にしてコンパイルするには,`--enable-scp` ビルドオプションを指定するかあるいは`WOLFSSL_SCP`マクロ定義を指定してください: +wolfSSHdは`--enable-sshd`を指定してビルドされるSSHサーバーデーモンで、OpenSSH形式の`sshd_config`ファイルを読み込み、ユーザーをローカルシステムにログインさせます。シェルセッションとexecセッション、およびビルド時に組み込まれていればSCPとSFTPをサポートします。 +wolfSSHdは、実行ユーザー(またはroot)が所有していないホスト鍵ファイルや、グループまたは全ユーザーから読み取り可能なホスト鍵ファイルを拒否します。そのため、wolfSSHdが使用できる鍵のコピーを渡してください。例えば次のようにします: +``` + $ sudo install -m 600 keys/gretel-key-ecc.pem /etc/ssh/wolfsshd_key.pem + $ sudo ./apps/wolfsshd/wolfsshd -D -h /etc/ssh/wolfsshd_key.pem -p 11111 + $ ssh @localhost -p 11111 +``` +システムの`sshd_config`ファイルにwolfSSHdがサポートしていないディレクティブがあって停止する場合は、ファイルをコピーしてその行を削除し、そのコピーを`-f`で指定してください。 + +wolfSSHdには以下のコマンドラインオプションが指定できます: ``` -$ ./configure --enable-scp -$ make + -? ヘルプを表示して終了する + -f 使用する設定ファイル(デフォルトは + /etc/ssh/sshd_config) + -p 待ち受けポート番号 + -d デバッグモードを有効にする + -D フォアグラウンドで実行する(デタッチしない) + -h 使用するホスト秘密鍵ファイル + -E ログファイルに追記する + -t テストモード: 設定を読み込み、待ち受けを行わずに + 終了する ``` -wolfSSHサンプルサーバープログラムは単一のscpリクエストを受け付けるように設定されていてwolfSSHライブラリをビルドする際にデフォルトでビルドされます。サンプルサーバーを起動するには以下を実行してください: +wolfSSHdは次の設定ディレクティブを認識します: + +| ディレクティブ | 備考 | +|--------------------------------|-----------------------------------------------| +| `Port` | 待ち受けポート。デフォルトは22です。 | +| `Protocol` | `2`のみ受け付けます。 | +| `HostKey` | ホスト秘密鍵ファイル。`Match`ブロック内では使用できません。 | +| `HostCertificate` | ホストX.509証明書ファイル。`Match`ブロック内では使用できません。 | +| `PasswordAuthentication` | `yes`(デフォルト)または`no`。 | +| `PubkeyAuthentication` | `yes`(デフォルト)または`no`。 | +| `PermitEmptyPasswords` | `yes`または`no`(デフォルト)。 | +| `PermitRootLogin` | `no`(デフォルト)、`yes`、`prohibit-password`(`without-password`とも記述可能)、`forced-commands-only`。UIDが0のすべてのアカウントに適用されます。 | +| `AuthorizedKeysFile` | 認可済み鍵ファイル。デフォルトはユーザーのホームディレクトリ内の`.ssh/authorized_keys`です。相対パスはホームディレクトリからのパスとみなされます。`%u`はユーザー名に、`%h`はホームディレクトリに、`%%`はパーセント記号に展開されます。それ以外の`%`トークンはエラーになります。 | +| `StrictModes` | `yes`(デフォルト)または`no`。 | +| `TrustedUserCAKeys` | ユーザー証明書用のCAファイル。X.509 CA証明書、またはOpenSSH証明書用のOpenSSH CA公開鍵です。 | +| `AuthorizedUPNDomains` | ユーザーのFPKI証明書のUPNレルムを制限します。 | +| `LoginGraceTime` | 認証に許容される秒数。デフォルトは120です。 | +| `UsePrivilegeSeparation` | `yes`、`no`、または`sandbox`。 | +| `ChrootDirectory` | ユーザーのセッションをchrootするディレクトリ。 | +| `ForceCommand` | クライアントが要求したコマンドの代わりに実行するコマンド。 | +| `Banner` | 認証前にクライアントへ送信するファイル。 | +| `PidFile` | デーモンのプロセスIDを書き込むファイル。 | +| `Include` | 別の設定ファイルを読み込みます。 | +| `Match` | `User`または`Group`に対する設定ブロックを開始します。 | +| `wolfSSH_HostKeyStore`, `wolfSSH_HostKeyStoreSubject`, `wolfSSH_HostKeyStoreFlags` | Windows証明書ストア対応ビルドのみ。証明書ストアからホスト鍵と証明書を読み込みます。 | +| `wolfSSH_TrustedUserCAStore`, `wolfSSH_WinUserStores`, `wolfSSH_WinUserPvPara`, `wolfSSH_WinUserDwFlags` | Windows証明書ストア対応ビルドのみ。Windows証明書ストアからユーザー証明書のCAを読み込みます。 | +| `wolfSSH_TrustedSystemCAKeys` | `yes`または`no`。オペレーティングシステムのトラストストアをユーザー証明書のCAとして読み込みます。 | + +ディレクティブ`Subsystem`、`ChallengeResponseAuthentication`、`UsePAM`、`X11Forwarding`、`PrintMotd`、`AcceptEnv`、`UseDNS`はOpenSSHの設定ファイルとの互換性のために認識されますが、効果はありません。wolfSSHdはそれぞれについて警告をログに出力します。それ以外のディレクティブはエラーになります。ディレクティブとその値は空白で区切る必要があり、OpenSSHの`Keyword=value`形式は拒否されます。 + +`Match`ブロックのキーには`User`または`Group`のみを指定できます。`Match User X Group Y`は両方が一致する必要があります。`wolfSSH_`で始まるストア関連のディレクティブと`wolfSSH_TrustedSystemCAKeys`はグローバルにのみ指定でき、`Match`ブロック内では拒否されます。`TrustedUserCAKeys`は`Match`ブロック内でも設定できます。 + +`StrictModes yes`の場合、認可済み鍵ファイルはシンボリックリンクではない通常ファイルで、ユーザーまたはrootが所有し、パス中にグループまたは全ユーザーが書き込み可能な要素を含んではなりません。`StrictModes no`で緩和されるのは認可済み鍵ファイルのチェックのみです。ホスト鍵ファイルとCAファイルは常にチェックされます。これらはデーモンの実行ユーザーまたはrootが所有している必要があり、ホスト秘密鍵はグループまたは全ユーザーから読み取り可能であってはなりません。 -$ ./examples/server/server +`PermitRootLogin prohibit-password`はrootのパスワードおよびkeyboard-interactiveによるログインを拒否し、公開鍵によるログインを許可します。`forced-commands-only`はさらに、rootの公開鍵ログインに`ForceCommand`を必要とします。認可済み鍵ファイルの`command=`オプションは強制されません。 -標準scpコマンド群はクライアント側で利用されます。以下はその使用例です。ここで、`scp`は使用しているsshクライアントを表します。 +X.509ユーザー証明書(`--enable-certs`)の場合、CAは`TrustedUserCAKeys`で設定します。証明書は、wolfSSLがFPKIをサポートしている場合はそのUPNによって、そうでない場合はサブジェクトCNの大文字小文字を区別しない一致によって、要求されたアカウントに結び付けられます。FPKIがない場合、Windows以外のシステムでは設定で`AuthorizedKeysFile`も指定する必要があり、証明書はユーザーの認可済み鍵ファイルと照合されます。CAのみに依存するログインは失敗します。FPKIがある場合、`AuthorizedUPNDomains`でUPNレルムを制限できます。 -単一ファイルをサーバーに送信する場合で既定のユーザー"jill"を使うとすると: +OpenSSHユーザー証明書(`--enable-ossh-certs`)の場合、署名するCAの公開鍵を`TrustedUserCAKeys`に列挙します。証明書のプリンシパルには要求されたユーザーが含まれている必要があり、証明書が有効期間内である必要があります。また、`source-address`制限がある場合はクライアントと一致する必要があります。証明書の`force-command`は要求されたコマンドを上書きします。OpenSSH証明書によるログインはWindowsではサポートされていません。 + +wolfSSHdのセッションはumask 022(`WOLFSSHD_DEFAULT_UMASK`)で実行されます。 + +## SCP + +wolfSSHはscpの為のサーバー側サポートを含んでおり、サーバーへのファイルコピーとサーバーからのファイルコピーの両方をサポートしています。単一ファイルのコピーとディレクトリ単位の再帰的コピーの両方が、デフォルトの送信・受信コールバックでサポートされています。 + +wolfSSHをscpサポート付きでコンパイルするには、`--enable-scp` ビルドオプションを指定するか、あるいは`WOLFSSH_SCP`を定義してください: ``` -$ scp -P 22222 jill@127.0.0.1: + $ ./configure --enable-scp + $ make ``` -同じ単一ファイルをサーバーに送信する場合で、今度はタイムスタンプを使いバーバスモードを使うとすると: + +wolfSSHのサンプルechoserverは、wolfSSHがSCPサポート付きでビルドされている場合にscpリクエストを受け付けます。サンプルサーバーを起動するには次を実行してください: + + $ ./examples/echoserver/echoserver + +クライアント側では標準のscpコマンドが使用できます。以下はその使用例です。ここで`scp`は使用しているsshクライアントを表します。 + +既定のサンプルユーザー"jill"を使って単一ファイルをサーバーに送信するには: + + $ scp -P 22222 jill@127.0.0.1: + +同じ単一ファイルをサーバーに送信するが、今度はタイムスタンプ付きでバーバスモードを使うには: + + $ scp -v -p -P 22222 jill@127.0.0.1: + +あるディレクトリを再帰的にサーバーへコピーするには: + + $ scp -P 22222 -r jill@127.0.0.1: + +単一ファイルをサーバーからローカルクライアントへコピーするには: + + $ scp -P 22222 jill@127.0.0.1: + +あるディレクトリをサーバーからローカルクライアントへ再帰的にコピーするには: + + $ scp -P 22222 -r jill@127.0.0.1: + +## SFTP + +wolfSSHはSFTPバージョン3のサーバー側およびクライアント側サポートを提供します。これにより、ファイルシステムを管理するための暗号化された接続を設定することができます。 + +wolfSSHをSFTPサポート付きでコンパイルするには、`--enable-sftp` ビルドオプションを指定するか、あるいは`WOLFSSH_SFTP`を定義してください: ``` -$ scp -v -p -P 22222 jill@127.0.0.1: + $ ./configure --enable-sftp + $ make ``` -あるディレクトリを再帰的にサーバーに送信する場合には: +作成されるSFTPクライアントはexamples/sftpclient/ディレクトリに配置され、サーバーはwolfSSHと同じechoserverを使って実行されます。 ``` -$ scp -P 22222 -r jill@127.0.0.1: + src/wolfssh$ ./examples/sftpclient/wolfsftp ``` -単一ファイルをサーバーからローカルマシンにコピーするには: +サポートされているコマンドの完全な一覧は、接続後に"help"と入力することで確認できます。 ``` -$ scp -P 22222 jill@127.0.0.1: -``` + wolfSSH sftp> help -サーバーのあるディレクトリを再帰的に受信する場合には: + Commands : + cd change directory + chmod change mode + creat create file with given permissions + get pulls file(s) from server + lcd change local directory + lls list local directory + ls list current directory + mkdir creates new directory on server + put push file(s) to server + pwd list current path + quit exit + rename renames remote file + reget resume pulling file + reput resume pushing file + interrupt get/put cmd +``` +別のシステムに接続する例は次のようになります: ``` -$ scp -P 22222 -r jill@127.0.0.1: + src/wolfssh$ ./examples/sftpclient/wolfsftp -p 22 -u user -h 192.168.1.111 ``` ## シェルサポート -wolfSSHのechoserverサンプルプログラムはログインを試みるユーザーの為にシェルを起動することができます。この機能はLinuxとmacOSでのみテスト済みです。echoserver.cファイルはユーザー認証コールバック内にユーザーのクレデンシャルを保持するように変更が必要です。あるいはユーザー認証コールバックは提供されたパスワードを検証するように変更する必要があります。 - -wolfSSHをシェルサポート機能付きでビルドする場合には--enable-shellオプションを指定するかあるいはWOLFSSH_SHELLマクロ定義を指定します: +wolfSSHのサンプルechoserverは、ログインを試みるユーザーの為にシェルをforkできるようになりました。この機能は現在のところLinuxとmacOSでのみテストされています。echoserver.cファイルは、ユーザー認証コールバック内にユーザーのクレデンシャルを保持するように変更するか、あるいは提供されたパスワードを検証するようにユーザー認証コールバックを変更する必要があります。 +wolfSSHをシェルサポート付きでコンパイルするには、--enable-shellビルドオプションを指定するか、あるいはWOLFSSH_SHELLを定義してください: ``` $ ./configure --enable-shell $ make ``` -デフォルトでechoserverはシェルを実行しようと試みます。エコーバックの機能をテストしたい場合にはコマンドラインオプションで-fを指定してください: +試すには、現在のユーザーのパスワードを指定してechoserverを起動し、疑似ターミナルを使用するサンプルクライアントで接続します。ここで``は現在ログインしているユーザーの名前です: +``` +$ ./examples/echoserver/echoserver -P :junk +$ ./examples/client/client -t -u -P junk +``` +デフォルトでechoserverはシェルを起動しようとします。エコーテストの動作を使うには、echoserverにコマンドラインオプション-fを指定してください: ``` $ ./examples/echoserver/echoserver -f ``` + +## Post-Quantum + +wolfSSHは、ML-KEM(旧称Kyber)によるポスト量子鍵交換と、ML-DSA(旧称Dilithium)によるポスト量子署名をサポートしています。 + +* **ML-KEM**: ハイブリッド鍵交換`mlkem768x25519-sha256`(ML-KEM-768とCurve25519)、`mlkem768nistp256-sha256`(ML-KEM-768とP-256上のECDH)、`mlkem1024nistp384-sha384`(ML-KEM-1024とP-384上のECDH)。利用可能な場合、これらは従来の鍵交換よりも優先して提示されます。 +* **ML-DSA**: ML-DSA-44、ML-DSA-65、ML-DSA-87のパラメータセット(`ssh-mldsa-44`、`ssh-mldsa-65`、`ssh-mldsa-87`)をサーバーホスト鍵とクライアント公開鍵認証の両方でサポートし、ML-DSAとECDSA、Ed25519、Ed448とのコンポジットもサポートします。証明書サポート付きでビルドした場合は、ML-DSA X.509証明書(`x509v3-ssh-mldsa-44`、`x509v3-ssh-mldsa-65`、`x509v3-ssh-mldsa-87`)もサポートされます。 + +これらのアルゴリズムはwolfCryptによって提供され、liboqsは使用しません。これらをサポートするようにwolfSSLをビルドしてインストールしてください。ML-DSAにはwolfSSL 5.9.2以降が必要です。例えば次のようにします: + +``` + $ ./configure --enable-wolfssh --enable-mlkem --enable-mldsa +``` + +その後、通常どおりwolfSSHをコンフィギュレーションしてビルドします: + +``` + $ ./configure + $ make all +``` + +wolfSSHのクライアントとサーバーは、ML-KEMハイブリッド鍵交換を使うように自動的にネゴシエートします。 + +``` + $ ./examples/echoserver/echoserver -f + + $ ./examples/client/client -u jill -P upthehill +``` + +クライアント側では、次のような出力が表示されます: + +``` +Server said: Hello, wolfSSH! +``` + +これらの鍵交換をサポートする他のSSHクライアント(`mlkem768x25519-sha256`に対するOpenSSHなど)もechoserverに接続できます。 + + +## Certificate Support + +wolfSSHはユーザーを認証する際に、単なる公開鍵の代わりにX.509証明書を受け付けることができます。 + +wolfSSHをX.509サポート付きでコンパイルするには、`--enable-certs`ビルドオプションを指定するか、あるいは`WOLFSSH_CERTS`を定義してください: + +``` + $ ./configure --enable-certs CPPFLAGS=-DWOLFSSH_NO_FPKI + $ make +``` + +この例では、同梱の"fred"の証明書が必要なFPKI拡張を持っていないため、FPKIチェックを無効にしています。`WOLFSSH_NO_FPKI`が定義されていない場合、この証明書は拒否されます。 + +FPKIの有無にかかわらず、接続相手の証明書にはRFC 6187のセクション2.2が適用されます。KeyUsage拡張はdigitalSignatureを示している必要があり、ExtendedKeyUsage拡張はanyExtendedKeyUsageか、検証対象の役割に対応する用途(ユーザー証明書の場合はid-kp-secureShellClientまたはclientAuth、ホスト証明書の場合はid-kp-secureShellServerまたはserverAuth)を指定している必要があります。これらの拡張を持たない証明書は受け付けられます。一致しない場合は`WS_CERT_KEY_USAGE_E`で失敗します。 + +ユーザーの証明書を検証するためのCAルート証明書を提供するには、echoserverにコマンドラインオプション`-a`を指定してください: + +``` + $ ./examples/echoserver/echoserver -a ./keys/ca-cert-ecc.pem +``` + +echoserverとクライアントには"fred"という名前の偽のユーザーが用意されており、その証明書が認証に使用されます。 + +サンプル証明書fred-cert.derを使ったechoserver/client接続の例は次のようになります: + +``` + $ ./examples/echoserver/echoserver -a ./keys/ca-cert-ecc.pem -K fred:./keys/fred-cert.der + + $ ./examples/client/client -u fred -J ./keys/fred-cert.der -i ./keys/fred-key.der +``` + +## OpenSSH証明書サポート + +wolfSSHは、公開鍵によるユーザー認証でOpenSSHユーザー証明書(`*-cert-v01@openssh.com`)を受け付けることができます。wolfSSHをOpenSSH証明書サポート付きでコンパイルするには、`--enable-ossh-certs`ビルドオプションを指定するか、あるいは`WOLFSSH_OSSH_CERTS`を定義してください。証明書のCA鍵、プリンシパル、有効期間、およびforce-commandとsource-addressオプションはユーザー認証コールバックに渡され、コールバックはCAが信頼できることを確認する必要があります。wolfSSHdは`TrustedUserCAKeys`に列挙されたCA鍵を使用します。 + +## Windows証明書ストア + +Windowsでは、ホスト鍵とユーザー鍵をファイルの代わりにWindows証明書ストアから取得できます。これには証明書サポートが必要です。`--enable-windows-cert-store`ビルドオプション(mingwホストのみ)を指定するか、`WOLFSSH_WINDOWS_CERT_STORE`を定義して有効にしてください。RSAのストア証明書は`x509v3-ssh-rsa`として提示され、RFC 6187ではこれをSHA-1で署名するため、`WOLFSSH_NO_SHA1_SOFT_DISABLE`と、`WC_SIG_MIN_HASH_TYPE=WC_HASH_TYPE_SHA`付きでビルドしたwolfSSLも必要です。ECDSAのストア鍵にはどちらも不要です。 + +echoserverとSFTPクライアントは`-W store:subject[:flags]`オプションを受け付けます。このオプションでは、ストア、証明書のサブジェクトCN、および任意でストアの場所を指定します。ストアの場所はCURRENT_USER(デフォルト)、LOCAL_MACHINE、USERS、CURRENT_SERVICE、SERVICES、CURRENT_USER_GROUP_POLICY、LOCAL_MACHINE_GROUP_POLICY、LOCAL_MACHINE_ENTERPRISEのいずれかで、それぞれ`CERT_SYSTEM_STORE_`プレフィックス付きの形式や数値でも指定できます。`-W`は証明書とその秘密鍵の両方を提供します。SFTPクライアントでは`-i`、`-j`、`-J`と組み合わせることはできません。 + +``` + $ ./examples/echoserver/echoserver -W "My:wolfSSH-Server:LOCAL_MACHINE" -a ./keys/ca-cert-ecc.pem + + $ ./examples/sftpclient/wolfsftp -u testuser -W "My:testuser:CURRENT_USER" -A ./keys/ca-cert-ecc.der -X +``` + +## TPMホスト鍵 + +`--enable-tpm`を指定すると、サーバーはECDSAまたはRSAのホスト鍵をTPM 2.0内に保持できるため、ホスト秘密鍵がメモリ上に置かれることはありません。鍵は`wolfSSH_CTX_UseTpmHostKey()`で登録され、交換ハッシュはTPMによって署名されます。`wolfSSH_CTX_UseTpmHostKey()`の後に`wolfSSH_CTX_UseCert_buffer()`を呼び出すことで、X.509ホスト証明書をTPM鍵と組み合わせることができます。echoserverはオプション`-G`でTPMホスト鍵blobをロードします: + +``` + $ ./examples/echoserver/echoserver -G ../wolfTPM/hostkey.bin +``` + +サンプル`examples/tpmcertserver/tpmcertserver`と`tpmcertclient`は、TPMホスト鍵と自己署名X.509ホスト証明書の組み合わせを示しています。 + +## 厳格な鍵交換 + +wolfSSHは、Terrapin攻撃(CVE-2023-48795)への対策である厳格な鍵交換(strict KEX)を実装しています。これは最初のKEXINITで提示され、接続相手も提示した場合には常に使用されるため、通常の場合は設定が不要です。strict KEXが有効な場合、wolfSSHは接続相手のSSH_MSG_NEWKEYSが到着するまで鍵交換メッセージとSSH_MSG_DISCONNECT以外は何も受け付けず、SSH_MSG_NEWKEYSのたびにパケットシーケンス番号をリセットします。順序外で到着したメッセージは接続を終了させます。 + +strict KEXを正しく扱えない接続相手と相互運用する必要があるアプリケーションは、`wolfSSH_CTX_SetStrictKex(ctx, 0)`で以降のセッションに対してこれを無効にできます。`wolfSSH_GetStrictKexNegotiated()`は、セッションがこれを使用しているかどうかを報告します。 diff --git a/wolfSSH/src-ja/chapter04.md b/wolfSSH/src-ja/chapter04.md index f1126d16..2def0580 100644 --- a/wolfSSH/src-ja/chapter04.md +++ b/wolfSSH/src-ja/chapter04.md @@ -27,3 +27,17 @@ wolfSFTPライブラリヘッダファイルもwolfsshディレクトリに含 すべてのメインソースファイルは、ルートディレクトリにある **src** ディレクトリにありま す。 + +**wolfssh** ディレクトリにある他のヘッダーは、オプション機能を宣言しています。SCP用の **wolfssh/wolfscp.h**、ssh-agentサポート用の **wolfssh/agent.h**、X.509証明書用の **wolfssh/certman.h**、鍵生成用の **wolfssh/keygen.h** です。 + +## アルゴリズムのネゴシエーション + +鍵交換の際、クライアントとサーバーはそれぞれアルゴリズムのリストを提示し、クライアントのリストの中でサーバーもサポートしている最初のアルゴリズムが使用されます。このリストは `wolfSSH_CTX_SetAlgoList*()` および `wolfSSH_SetAlgoList*()` 関数で変更できます。これらの関数は入力を検証し、未知のアルゴリズムを含むリストに対しては `WS_INVALID_ALGO_ID` を返します。暗号とMACは接続の方向ごとに個別にネゴシエーションされるため、2つの方向で異なるものが使用される場合があります。 + +SHA-1を使用するアルゴリズムとAES-CBC暗号はコンパイルされますが、デフォルトでは提示されません。これらはアルゴリズムリストに追加し直すことができるほか、`WOLFSSH_NO_SHA1_SOFT_DISABLE` または `WOLFSSH_NO_AES_CBC_SOFT_DISABLE` を指定してビルドすることでデフォルトで提示されるようにもできます。"none" 暗号とMACは、`--enable-none-cipher` を指定したビルドでのみネゴシエーションできます。 + +wolfSSHは厳格な鍵交換(Terrapin攻撃への対策)を実装しており、両方のピアが提示した場合に使用されます。これはデフォルトで有効になっており、`wolfSSH_CTX_SetStrictKex()` で無効にできます。 + +## 鍵の再交換 + +現在の鍵で送受信したバイト数がハイウォーターマーク(`wolfSSH_SetHighwater()`、デフォルトは `DEFAULT_HIGHWATER_MARK`)に達するか、送受信したパケット数がパケット数のハイウォーターマーク(`wolfSSH_SetMsgHighwater()`、デフォルトは `WOLFSSH_DEFAULT_MSG_HIGHWATER_MARK`)に達すると、wolfSSHはハイウォーターコールバックを呼び出します。デフォルトのコールバックは新しい鍵交換を開始します。別のコールバックは `wolfSSH_SetHighwaterCb()` で設定できます。アプリケーションは `wolfSSH_TriggerKeyExchange()` で鍵交換を開始することもできます。`wolfSSH_RekeyPending()` は鍵交換が進行中かどうかを報告します。 diff --git a/wolfSSH/src-ja/chapter05.md b/wolfSSH/src-ja/chapter05.md index 93bd5bc4..77f2adfc 100644 --- a/wolfSSH/src-ja/chapter05.md +++ b/wolfSSH/src-ja/chapter05.md @@ -9,15 +9,14 @@ wolfSSH は、ユーザ認証メッセージで提供されたユーザ名、パ ルバック関数は適切な検索を実行して応答を返します。ユーザはそのためのコールバック を提供する必要があります。 -コールバック関数は失敗を示すエラーコードあるいは成功のいずれかを返さなければなりません。ライブラリは全ての失敗をロギング目的を除いて同一に扱います。すなわち、ユーザー認証失敗メッセージを再試行するクライアントに返信します。 +コールバック関数は失敗を示すエラーコードあるいは成功のいずれかを返さなければなりません。ライブラリは全ての失敗をロギング目的を除いて同一に扱います。すなわち、ユーザー認証失敗メッセージを再試行するクライアントに返信します。例外は `WOLFSSH_USERAUTH_REJECTED` で、これは強制的な拒否を意味します。サーバーは失敗メッセージを送信した後、セッションを終了します。また、サーバーは一定回数(デフォルトは 6 回)認証に失敗したクライアントを切断します。`wolfSSH_CTX_SetMaxAuthAttempts()` を参照してください。 -パスワード検索を行う場合には平文のパスワードがコールバック関数に渡されます。ユーザー名とパスワードは一致するか検査され成功を返します。成功時にはSSHハンドシェークはただちに続行されます。現時点ではパスワードの変更はサポートされません。 +`WOLFSSH_USERAUTH_SUCCESS` の値は 0 で、`WS_SUCCESS` と同じであることに注意してください。デフォルトで 0 を返すコールバックや、ヘルパー関数からの `WS_SUCCESS` をそのまま返すコールバックは、クライアントを認証してしまいます。コールバックが明示的に処理しない認証タイプやコードパスでは `WOLFSSH_USERAUTH_FAILURE` を返してください。 + +パスワード検索を行う場合には平文のパスワードがコールバック関数に渡されます。ユーザー名とパスワードは一致するか検査され成功を返します。成功時にはSSHハンドシェークはただちに続行されます。パスワードの変更はサポートされません。パスワード変更の要求は、コールバックを呼び出すことなく拒否されます。 公開鍵検索では、クライアントからの公開鍵blob(バイナリデータ) がコールバック関数に渡されます。 -公開鍵はサーバーの有効なクライアント公開鍵のリストと照合されます。提供された公開 -鍵がそのユーザーの既知の公開鍵と一致する場合。 wolfSSH ライブラリは -RFC4252§7 に記述されたプロセスに従ってユーザー認証署名の実際の検証を実行しま -す。 +コールバックは、その公開鍵をそのユーザーに対するサーバーの有効な公開鍵のリストと照合する必要があります。チェックしていない鍵に対して成功を返すと、クライアントが提示するあらゆる鍵を許可することになります。wolfSSH ライブラリは RFC 4252 セクション 7 に記述されたプロセスに従ってユーザー認証署名の実際の検証を実行します。2048 ビット(`WOLFSSH_RSA_MIN_KEY_BITS`)未満の RSA 鍵は拒否されます。 一般に公開鍵の場合、サーバーは ssh-keygen ユーティリティによって生成されたユーザ ーの公開鍵を保存するか、または公開鍵のフィンガープリントを保存します。ユーザーに @@ -29,30 +28,18 @@ ID の署名とユーザー認証要求メッセージを提供します。サ ユーザ認証コールバック関数プロトタイプは次の通りです: ``` -int UserAuthCb(byte authType , const WS_UserAuthData* authData , void* ctx ); +int UserAuthCb(byte authType, WS_UserAuthData* authData, void* ctx); ``` この関数プロトタイプのタイプは: ``` WS_CallbackUserAuth ``` -パラメータ `authType` は: - -``` -WOLFSSH_USERAUTH_PASSWORD -``` - -か、あるいは - -``` -WOLFSSH_USERAUTH_PUBLICKEY -``` - -です。 +パラメータ `authType` は、次のセクションに示す認証タイプ定数のいずれかです。 パラメータ authData は認証データへのポインタです。 -WS_UserAuthData の詳細は5.4を参照してください。 +WS_UserAuthData の詳細は5.4を参照してください。 パラメータ **ctx** はアプリケーション定義のコンテキストです。 wolfSSH はコンテキスト 内のデータについては何の知識も持たず何も操作しません。コールバック関数へのコンテキストポイ @@ -64,9 +51,14 @@ WS_UserAuthData の詳細は5.4を参照してください。 ``` WOLFSSH_USERAUTH_PASSWORD +WOLFSSH_USERAUTH_KEYBOARD +WOLFSSH_USERAUTH_KEYBOARD_SETUP WOLFSSH_USERAUTH_PUBLICKEY +WOLFSSH_USERAUTH_NONE ``` +`WOLFSSH_USERAUTH_KEYBOARD_SETUP` は、クライアントに送信する keyboard-interactive のプロンプトをコールバックに要求します。`WOLFSSH_USERAUTH_NONE` は `WOLFSSH_ALLOW_USERAUTH_NONE` を指定したビルドでのみ使用されます。 + ## コールバック関数の戻り値定数 以下は、コールバック関数がライブラリに返すリターンコードです。 失敗コードはコー @@ -79,34 +71,47 @@ invalid username invalid password invalid public key ``` - -ライブラリはクライアントに成功または失敗のみを示し、下記の特定の失敗タイプはロギングに -のみ使用されます。 +サーバーはクライアントに _成功_ または _失敗_ を示し、特定の失敗タイプはロギングに +のみ使用されます。コールバックがライブラリに返せる特別な成功と失敗の応答として +_partial-success_(部分的成功)があります。これは、その認証タイプは成功したが、完 +全に認証するには別の認証タイプがまだ必要であることを意味します。サーバーは partial-success +フラグをセットしたユーザー認証失敗メッセージをクライアントに送信します。 ``` WOLFSSH_USERAUTH_SUCCESS WOLFSSH_USERAUTH_FAILURE +WOLFSSH_USERAUTH_INVALID_AUTHTYPE WOLFSSH_USERAUTH_INVALID_USER WOLFSSH_USERAUTH_INVALID_PASSWORD +WOLFSSH_USERAUTH_REJECTED WOLFSSH_USERAUTH_INVALID_PUBLICKEY +WOLFSSH_USERAUTH_PARTIAL_SUCCESS +WOLFSSH_USERAUTH_SUCCESS_ANOTHER +WOLFSSH_USERAUTH_WOULD_BLOCK ``` +`WOLFSSH_USERAUTH_SUCCESS_ANOTHER` は、keyboard-interactive のラウンドが成功し、さらに別のラウンドを要求することを示します。`WOLFSSH_USERAUTH_WOULD_BLOCK` は、同じリクエストで後からコールバックを再度呼び出すようライブラリに要求します。`WOLFSSH_USERAUTH_REJECTED` はセッションを終了させます。 + ## コールバック関数のデータタイプ クライアントデータは、`WS_UserAuthData` という構造体でコールバック関数に渡され -ます。 メッセージ内のデータへのポインタが含まれています。 このフィールドには共通フィールドとUNIONフィールドをメンバに持っています。メソッド固有のフィールドは、ユーザー認証データ内のUNIONフィールドにあります。 - +ます。 メッセージ内のデータへのポインタが含まれています。 この構造体には共通フィールドを持ちます。メソッド固有のフィールドは、ユーザー認証データ内の構造体の union にあります。 ``` typedef struct WS_UserAuthData { - byte authType ; - byte* username ; - word32 usernameSz ; - byte* serviceName ; - word32 serviceNameSz ; n + byte type; + const byte* username; + word32 usernameSz; + const byte* serviceName; + word32 serviceNameSz; + const byte* authName; + word32 authNameSz; union { - WS_UserAuthData_Password password ; - WS_UserAuthData_PublicKey publicKey ; + WS_UserAuthData_Password password; + WS_UserAuthData_PublicKey publicKey; +#ifdef WOLFSSH_KEYBOARD_INTERACTIVE + WS_UserAuthData_Keyboard keyboard; +#endif } sf; } WS_UserAuthData; ``` @@ -115,21 +120,68 @@ typedef struct WS_UserAuthData { username および usernameSz パラメータは、クライアントによって提供されるユーザ名とオクテット単位のサイズです。 -password フィールドと passwordSz フィールドは、クライアントのパスワードとそのオクテット単位のサイズです。 - -クライアントから提供された場合は設定されますが、パラメータ hasNewPassword、newPassword、および newPasswordSz は使用されません。 現時点でクライアントにパスワードを変更するように指示するメカニズムはありません。 +`password` フィールドと `passwordSz` フィールドは、クライアントのパスワードとそのオクテット単位のサイズです。 +フィールド `hasNewPassword`、`newPassword`、`newPasswordSz` は将来の使用のために用意されています。新しいパスワードを含むリクエストは、コールバックを呼び出すことなく拒否されます。 ``` typedef struct WS_UserAuthData_Password { - uint8_t* password ; - uint32_t passwordSz ; - uint8_t hasNewPasword ; - uint8_t* newPassword ; - uint32_t newPasswordSz ; + const byte* password; + word32 passwordSz; + /* The following are present for future use. */ + byte hasNewPassword; + const byte* newPassword; + word32 newPasswordSz; } WS_UserAuthData_Password; ``` +### Keyboard-Interactive + +Keyboard-Interactive モードでは、サーバーからクライアントへ任意の数のプロンプトと +レスポンスをやり取りできます。情報を格納する構造体は次の通りです: + +```c +typedef struct WS_UserAuthData_Keyboard { + word32 promptCount; + word32 responseCount; + word32 promptNameSz; + word32 promptInstructionSz; + word32 promptLanguageSz; + byte* promptName; + byte* promptInstruction; + byte* promptLanguage; + word32* promptLengths; + word32* responseLengths; + byte* promptEcho; + byte** responses; + byte** prompts; +} WS_UserAuthData_Keyboard; +``` + +クライアント側では、認証中に `promptName` と `promptInstruction` が認証に関する情 +報をユーザーに示します。 `promptLanguage` フィールドは API の非推奨部分であり、無 +視されます。 + +`promptCount` はプロンプトがいくつあるかを示します。 `prompts` はプロンプトの配列 +を保持し、`promptLengths` は `prompts` 内の各プロンプトの長さを保持する配列です。 +`promptEcho` は、各プロンプトのレスポンスをユーザーが入力する際にエコー表示するか +どうかを示すブール値の配列です。 + +逆に、`responseCount` は与えられるレスポンスの数を設定します。 `responses` と +`responseLengths` はプロンプトに対するレスポンスデータを保持します。 + +サーバーは、`authType` に `WOLFSSH_USERAUTH_KEYBOARD_SETUP` を指定してユーザー認証 +コールバックを呼び出すことでプロンプトを取得します。コールバックは `promptCount`、 +`prompts`、`promptLengths`、`promptEcho` を設定し、`WOLFSSH_USERAUTH_SUCCESS` を返す +必要があります。その他の `prompt*` 項目はオプションです。指定できるプロンプトは最大 +`WOLFSSH_MAX_PROMPTS`(64)個です。セットアップの呼び出しから +`WOLFSSH_USERAUTH_REJECTED` を返すとセッションが終了し、それ以外の失敗を返すとその +認証試行が失敗します。 + +サーバーは、後続のリクエスト/レスポンスのラウンドを実行するために、 +`WS_CallbackUserAuth` コールバックから `WOLFSSH_USERAUTH_SUCCESS_ANOTHER` を返す必 +要があります。 + ### 公開鍵 wolfSSH は複数の公開鍵アルゴリズムをサポートします。 publicKeyType メンバは、使用されているアルゴリズム名を指します。 @@ -148,12 +200,34 @@ hasSignature フィールドが設定され、signature フィールドがクラ ``` typedef struct WS_UserAuthData_PublicKey { - byte* publicKeyType; + const byte* dataToSign; + const byte* publicKeyType; word32 publicKeyTypeSz; - byte* publicKey; + const byte* publicKey; word32 publicKeySz; + const byte* privateKey; + word32 privateKeySz; byte hasSignature; - byte* signature; + const byte* signature; word32 signatureSz; + byte isCert:1; + word32 dataToSignSz; +#ifdef WOLFSSH_OSSH_CERTS + byte isOsshCert:1; + const byte* caKey; + word32 caKeySz; + const byte* principals; + word32 principalsSz; + word64 validAfter; + word64 validBefore; + const byte* forceCommand; + word32 forceCommandSz; + const byte* sourceAddress; + word32 sourceAddressSz; +#endif } WS_UserAuthData_PublicKey; ``` + +`isCert` フィールドは、クライアントが X.509 証明書を提示した場合に設定され、その場合 `publicKey` は証明書を保持します。ライブラリは `wolfSSH_CTX_AddRootCert_buffer()` でロードされたルート証明書に対してその証明書を検証済みです。`WOLFSSH_OSSH_CERTS` を指定したビルドでは、クライアントが OpenSSH 証明書を提示した場合に `isOsshCert` フィールドが設定されます。ライブラリは証明書の署名を検証してフィールドを解析しますが、コールバックは `caKey` が信頼できる CA 鍵であることを確認する必要があります。また、`principals`(名前のリスト)、有効期間(エポックからの秒数で表す `validAfter` と `validBefore`)、および `forceCommand` と `sourceAddress`(カンマ区切りの CIDR リスト)オプションも確認すべきです。これらは存在しない場合は NULL になります。 + +`privateKey` と `privateKeySz` フィールドは、クライアントのユーザー認証コールバックが自身の鍵を提供するために使用します。 diff --git a/wolfSSH/src-ja/chapter06.md b/wolfSSH/src-ja/chapter06.md index 7670286d..b253a94e 100644 --- a/wolfSSH/src-ja/chapter06.md +++ b/wolfSSH/src-ja/chapter06.md @@ -2,68 +2,74 @@ 以下の関数を使って、ユーザー認証コールバック関数の設定を行います。 - ## ユーザ認証コールバック関数の設定 ``` -void wolfSSH_SetUserAuth(WOLFSSH_CTX* ctx , WS_CallbackUserAuthcb); +void wolfSSH_SetUserAuth(WOLFSSH_CTX* ctx , WS_CallbackUserAuth +cb ); ``` +コールバック関数は、wolfSSH セッションオブジェクトを作成するために使用される WOLFSSH_CTX オブジェクトに設定されます。この CTX を使用するすべてのセッションは同じコールバック関数を使用します。このコンテキストは、コールバック関数のコンテキストと混同しないでください。 -コールバック関数は、wolfSSH セッションオブジェクトを作成するために使用される -WOLFSSH_CTX オブジェクトに設定されます。 この CTX を使用するすべてのセッション -は同じコールバック関数を使用します。 このコンテキストは、コールバック関数のコン -テキストと混同しないでください。 +## ユーザ認証コールバックコンテキストデータの設定 +``` +void wolfSSH_SetUserAuthCtx(WOLFSSH* ssh , void* ctx ); +``` +それぞれの wolfSSH セッションはそれ自身のユーザ認証コンテキストデータを持っているか、あるいはいくつかを共有することもできます。wolfSSH ライブラリはこのコンテキストデータの内容について何も感知しません。データの作成、解放、および必要に応じた排他制御の提供は、アプリケーションの責任です。コールバックはライブラリからこのコンテキストデータを受け取ります。 -## ユーザ認証コールバックコンテクストデータの設定 +## ユーザ認証コールバックコンテキストデータの取得 ``` -void wolfSSH_SetUserAuthCtx(WOLFSSH* ssh , void* ctx); +void* wolfSSH_GetUserAuthCtx(WOLFSSH* ssh ); ``` -それぞれの wolfSSH セッションはそれ自身のユーザ認証コンテキストデータを持ってい -るか、あるいはいくつかを共有することもできます。 wolfSSH ライブラリはこのコンテ -キストデータの内容について何も感知しません。 データの作成、解放、および必要に応 -じた排他制御の提供は、アプリケーションの責任です。 コールバックはライブラリから -このコンテキストデータを受け取ります。 +提供された wolfSSH セッションに保存されたユーザ認証コンテキストデータへのポインターを返します。これはセッションを作成するために使用される wolfSSH のコンテキストデータと混同しないよう注意してください。 -## ユーザ認証コールバックコンテクストデータの取得 +## Keyboard-Interactive プロンプトの設定 + +Keyboard-Interactive のプロンプト専用のコールバックはありません。前章で説明したとおり、サーバーは `authType` に `WOLFSSH_USERAUTH_KEYBOARD_SETUP` を指定してユーザ認証コールバックを呼び出し、クライアントに送信するプロンプトを取得します。Keyboard-Interactive 認証には `--enable-keyboard-interactive`(`WOLFSSH_KEYBOARD_INTERACTIVE`)を指定したビルドが必要です。 + +## 許可する認証タイプのコールバック関数の設定 ``` -void* wolfSSH_GetUserAuthCtx(WOLFSSH* ssh); +void wolfSSH_SetUserAuthTypes(WOLFSSH_CTX* ctx, WS_CallbackUserAuthTypes cb); ``` -提供された wolfSSH セッションに保存されたユーザ認証コンテキストデータへのポイン -タを返します。 これはセッションを作成するために使用される wolfSSH のコンテキスト -データと混同しないよう注意してください。 -## Echoserver サンプルプログラムのユーザ認証 +このオプションのコールバックは、サーバーが継続可能な認証タイプとしてクライアントに提示する認証タイプのセットを、`WOLFSSH_USERAUTH_*` タイプ定数のビットマスクとして返します。このコールバックがない場合、サーバーはパスワード、公開鍵、および組み込まれている場合は keyboard-interactive を提示します。 -サンプルの echoserver は、パスワードと公開鍵を使用してサンプルユーザーとの認証コ -ールバックを実装しています。 コールバックの例と wsUserAuth は、wolfSSH コンテキ -ストに設定されています: +## ユーザ認証結果コールバック関数の設定 +``` +void wolfSSH_SetUserAuthResult(WOLFSSH_CTX* ctx, WS_CallbackUserAuthResult cb); +void wolfSSH_SetUserAuthResultCtx(WOLFSSH* ssh, void* userAuthResultCtx); +``` + +このオプションのコールバックには、ライブラリによる公開鍵ユーザ認証署名のチェック結果が通知されます。成功が通知された際に `WS_SUCCESS` 以外の値を返すと、その認証試行は失敗になります。 +## 最大認証試行回数の設定 ``` -wolfSSH_SetUserAuth(ctx, wsUserAuth); +int wolfSSH_CTX_SetMaxAuthAttempts(WOLFSSH_CTX* ctx, int value); +int wolfSSH_SetMaxAuthAttempts(WOLFSSH* ssh, int value); ``` -パスワードファイルの例(passwd.txt)は、コロンで区切られたユーザー名とパスワー -ドの単純なリストです。 このファイル内に存在するデフォルトは次のとおりです: +サーバーは、ユーザ認証にこの回数失敗したクライアントを切断します。デフォルトは `DEFAULT_MAX_AUTH_ATTEMPTS`(6)です。0 以下の値を指定するとデフォルトに戻ります。 + +## Echoserver サンプルプログラムのユーザ認証 + +サンプルの echoserver は、パスワードと公開鍵を使用してサンプルユーザーとの認証コールバックを実装しています。コールバックの例である wsUserAuth は、wolfSSH コンテキストに設定されています: +``` +wolfSSH_SetUserAuth(ctx, wsUserAuth); +``` +パスワードファイルの例(passwd.txt)は、それぞれコロンで区切られたユーザー名とパスワードの単純なリストです。このファイル内に存在するデフォルトは次のとおりです。 ``` jill:upthehill jack:fetchapail ``` - -公開鍵ファイルは、ssh-keygen を実行して得た公開鍵出力を 2 つ連結したものです。 - +公開鍵ファイルは、ssh-keygen を 2 回実行して得た公開鍵出力を連結したものです。 ``` ssh-rsa AAAAB3NzaC1yc...d+JI8wrAhfE4x hansel ssh-rsa AAAAB3NzaC1yc...UoGCPIKuqcFMf gretel ``` +すべてのユーザー認証データは、ユーザー名と、パスワードまたは公開鍵 blob の SHA-256 ハッシュのペアをリンクリスト形式で格納されています。 -すべてのユーザー認証データは、ユーザー名と、パスワードまたは公開鍵blob のSHA-256 ハッシュのペアをリンクリスト形式で格納されています。 - -設定ファイル内の公開鍵blob は Base64エンコードされており、ハッシュ前にデコードされます。 ユーザ名 - ハッシュペアのリストへのポインタは新しい wolfSSH セッションに保存されます。 - +設定ファイル内の公開鍵 blob は Base64 エンコードされており、ハッシュ前にデコードされます。ユーザ名 - ハッシュペアのリストへのポインターは新しい wolfSSH セッションに保存されます: ``` wolfSSH_SetUserAuthCtx(ssh, &pwMapList); ``` - -コールバック関数は、最初に authType が公開鍵かパスワードかを調べ、そうでない場合は一般ユーザー認証失敗エラーコードを返します。次に、authData を介して渡された公開鍵またはパスワードをハッシュします。ユーザー名をリスト中から検索し見つけられない場合は無効ユーザーエラーコードを返します。ユーザー名が見つかった場合には、渡された公開鍵またはパスワードの計算ハッシュとペアに格納されているハッシュを比較します。一致した場合、関数は成功を返します。それ以外の場合、無効なパスワードまたは公開鍵 -のエラーコードを返します。 +コールバック関数は、最初に authType が公開鍵かパスワードかを調べ、そうでない場合は一般ユーザー認証失敗エラーコードを返します。次に、authData を介して渡された公開鍵またはパスワードをハッシュします。ユーザー名をリスト中から検索し、見つけられない場合は無効ユーザーエラーコードを返します。ユーザー名が見つかった場合には、渡された公開鍵またはパスワードの計算ハッシュとペアに格納されているハッシュを比較します。一致した場合、関数は成功を返します。それ以外の場合、無効なパスワードまたは公開鍵のエラーコードを返します。 diff --git a/wolfSSH/src-ja/chapter07.md b/wolfSSH/src-ja/chapter07.md index f35e3864..b8b55665 100644 --- a/wolfSSH/src-ja/chapter07.md +++ b/wolfSSH/src-ja/chapter07.md @@ -4,49 +4,45 @@ wolfSSLは既にwolfSSHの使用のためにビルドが済んでいると仮定しています。wolfSSLのビルド方法については2章を参照してください。 -SFTPサポート機能を有効にしてwolfSSHをビルドする場合には、autotoolsを使ったビルドのビルドでは--enable-sftpオプションを指定します。autotoolsを使わない場合にはWOLFSSH_SFTPマクロ定義を指定します。コマンドラインは次のようになります: - - +SFTPサポート機能を有効にしてwolfSSHをビルドする場合には、autotoolsを使ったビルドでは--enable-sftpオプションを指定します。autotoolsを使わない場合にはWOLFSSH_SFTPマクロ定義を指定します。コマンドラインは次のようになります: ``` -$ ./configure --enable-sftp && make +./configure --enable-sftp && make ``` - -リード・ライトをハンドリングするためのバッファサイズはデフォルトで1024バイトです。この値はアプリケーションがより少ないリソース消費に抑えたい場合やより大きなバッファが必要な場合には変更することができます。サイズ変更は`WOLFSSH_MAX_SFTP_RW`マクロを定義して行います。設定例は: +リード・ライトをハンドリングするためのバッファサイズはデフォルトで32768バイトです。この値はアプリケーションがより少ないリソース消費に抑えたい場合やより大きなバッファが必要な場合には変更することができます。デフォルトサイズの変更は、コンパイル時に`WOLFSSH_MAX_SFTP_RW`マクロを定義して行います。設定例は次のとおりです: ``` -$ ./configure --enable-sftp C_EXTRA_FLAGS="WOLFSSH_MAX_SFTP_RW=2048" +./configure --enable-sftp CPPFLAGS="-DWOLFSSH_MAX_SFTP_RW=2048" ``` +サーバーは各セッションに対して、最大`WOLFSSH_MAX_SFTP_HANDLES`(64)個のファイルハンドルおよびディレクトリハンドルのオープンを許可します。ファイルデータバッファは解放前にゼロクリアされます。configureオプション`--disable-sftp-zeroize`(`WOLFSSH_NO_SFTP_BUFFER_ZERO`)を指定するとこれを無効にできます。 + ## wolfSSH SFTP アプリケーションの使用 -SFTPサーバーとクライアントアプリケーションはwoflSSHにバンドルされています。両アプリケーションともautotoolsを使ってwolfSSHライブラリをSFTPサポートを有効にしてビルドする際に同時にビルドされて生成されます。クライアントアプリケーションはwolfsftp/clientフォルダに存在しておりwolfsftpと呼ばれます。 +SFTPサーバーとクライアントアプリケーションはwolfSSHにバンドルされています。両アプリケーションともautotoolsを使ってwolfSSHライブラリをSFTPサポートを有効にしてビルドする際に同時にビルドされて生成されます。サーバーアプリケーションはexamples/echoserverフォルダに存在しておりechoserverと呼ばれます。クライアントアプリケーションはexamples/sftpclientフォルダに存在しておりwolfsftpと呼ばれます。 サーバーの起動例を示します。起動するとSFTPクライアントからの接続を待ち受けます: - ``` -$ ./examples/echoserver/echoserver +./examples/echoserver/echoserver ``` - -ここで、コマンドはルートwolfSSHディレクトリから実行します。サーバーはSSHとSFTPコマンドの両方を処理することができます。 +ここで、コマンドはルートwolfSSHディレクトリから実行します。サーバーはSSHとSFTPの両方の接続を処理することができます。 一方、クライアントを起動するには特定のユーザー名を与えて起動します: - ``` -$ ./wolfsftp/client/wolfsftp -u +$ ./examples/sftpclient/wolfsftp -u ``` +テストを実行するためのデフォルトの"username:password"は"jack:fetchapail" または "jill:upthehill"です。デフォルトのポートは22222です。 -デフォルトの“username:password”は“jack:fetchapail” または “jill:upthehill”を与えます。デフォルトのポートは22222です。 - -サポートしているコマンドの全リストは接続後に、"help"と入力すると得られます。 - - +サポートしているコマンドの全リストは、接続後に"help"と入力すると得られます。 ``` wolfSSH sftp> help Commands : cd change directory chmod change mode + creat create file with given permissions get pulls file(s) from server + lcd change local directory + lls list local directory ls list current directory mkdir creates new directory on server put push file(s) to server @@ -58,9 +54,23 @@ Commands : interrupt get/put cmd ``` -他のシステムへの接続例は: - +他のシステムへの接続例は次のとおりです: ``` src/wolfssh$ ./examples/sftpclient/wolfsftp -p 22 -u user -h 192.168.1.111 ``` +## SFTPサーバーの開始ディレクトリと制限 + +SFTPサーバーのセッションには、互いに独立した2つのパス設定があります: + +- 開始パスは、セッションが開始するディレクトリで、相対パスはこのディレクトリを基準に解決されます。これはアクセスの許可も拒否も行いません。`wolfSSH_SFTP_SetDefaultPath()`で設定します。 +- 制限ルートは、セッションのアクセスが制限されるディレクトリです。このディレクトリの外側に解決されるパスへのリクエストは`WS_PERMISSIONS`で失敗します。ルートが設定されていないか、ルートが"/"の場合、セッションは制限されません。`wolfSSH_SFTP_SetConfinePath()`で設定します。 + +開始パスを設定してもセッションは制限されません。2つを分けておくことで、サーバーは制限ルートの深い階層でセッションを開始したり、開始位置を変えずにセッションを制限したり、あるいはどちらも行わずにオペレーティングシステムにアクセスを制限させたりできます(wolfSSHdは、認証されたユーザーとしてセッションを実行することで最後の方法をとっています)。 + +パスは字句的に解決されるため、シンボリックリンクがルート内に留まることを証明できません。そのため、制限されたセッションでは、ルート配下のすべてのシンボリックリンクを拒否します。これにはルート内を指すリンクも含まれます。シンボリックリンクを含まないツリーを提供するか、あるいは`WOLFSSH_NO_SYMLINK_CHECK`を指定してビルドし、このチェックとそれによる保護を外してください。ルート自体はチェックされないため、ルートはサーバーが管理し、パス中にシンボリックリンクを含まないディレクトリにすべきです。チェックは操作がパスを使用する前に行われるため、同じユーザーとして実行されているプロセスがその間にパスの要素をリンクに差し替えることは依然として可能です。悪意のあるユーザーが存在しうるマルチユーザー環境では、オペレーティングシステムのjailも併用してください。 + +サンプルのechoserverは、オプション`-d`で開始パスを設定し、オプション`-D`を指定するとセッションをそのパスに制限します: +``` +./examples/echoserver/echoserver -d /srv/sftp -D +``` diff --git a/wolfSSH/src-ja/chapter08.md b/wolfSSH/src-ja/chapter08.md index 4b2a019d..e04e0950 100644 --- a/wolfSSH/src-ja/chapter08.md +++ b/wolfSSH/src-ja/chapter08.md @@ -38,3 +38,20 @@ src/wolfssl$ ./examples/client/client -p 12345 上記実行により、wolfSSLクライアントとサーバーサンプルプログラム間でportfwdサンプルプログラムと同様のポートフォワーディングを行います。 +portfwdサンプルプログラムは、オプション`-r`を指定してリモート(リバース)フォワーディングを設定することもできます。この場合、SSHサーバーに`-F`/`-f`のアドレスとポートで待ち受けるよう要求し、サーバーはそこに対して行われた各接続をportfwdへトンネルで戻し、portfwdはそれをローカルの`-T`/`-t`宛てに接続します。`-r`を指定した場合、`-f`のポートに0を指定するとサーバーがポートを選択します。 + +``` +src/wolfssl$ ./examples/server/server +src/wolfssh$ ./examples/portfwd/portfwd -p 22 -u -r \ + -f 12345 -t 11111 +src/wolfssl$ ./examples/client/client -p 12345 +``` + +## ポートフォワーディングAPI + +アプリケーションは、`wolfSSH_CTX_SetFwdCb()`で設定するフォワーディングコールバックと、`wolfSSH_SetFwdCbCtx()`で設定するそのコンテキストによってフォワーディングを制御します。コールバックはすべてのフォワーディングチャネルについて参照されます。受信した"direct-tcpip"または"forwarded-tcpip"チャネルのオープンは、フォワーディングコールバックが設定されていて、その`WOLFSSH_FWD_LOCAL_SETUP`呼び出しが成功しない限り拒否されます。成功した各`WOLFSSH_FWD_LOCAL_SETUP`には後で1回の`WOLFSSH_FWD_LOCAL_CLEANUP`が対応するため、コールバックはその状態を二重に解放してはなりません。サーバーでは、クライアントからの"tcpip-forward"リクエストによって`WOLFSSH_FWD_REMOTE_SETUP`でフォワーディングコールバックが呼び出されます。ポート0に対するリクエストの場合、コールバックは`WS_FWD_SUCCESS`ではなく割り当てたポートを返します。 + +クライアントは`wolfSSH_FwdRemoteSetup()`でリモートフォワーディングを設定します。この関数は、サーバーにアドレスとポートで待ち受け、そこに対して行われた接続を"forwarded-tcpip"チャネルとして返送するよう要求します。停止するには`wolfSSH_FwdRemoteCancel()`を使用します。クライアントは、`wolfSSH_FwdRemoteSetup()`で登録したフォワードと一致しない"forwarded-tcpip"チャネルのオープンを拒否するため、何も登録していないクライアントはすべて拒否します。登録したバインドアドレスが""、"*"、"0.0.0.0"、またはIPv6の任意アドレスの場合はポートのみで照合され、それ以外のアドレスはサーバーが報告するアドレスと等しくなければなりません。アドレスを異なる表記で報告するサーバーに対しては、`wolfSSH_SetFwdRemoteMatch()`で照合をポートのみに緩和する(`WOLFSSH_FWD_MATCH_PORT`)か、照合を無効にする(`WOLFSSH_FWD_MATCH_OFF`)ことができます。クライアントは、自身に送られた"tcpip-forward"および"cancel-tcpip-forward"リクエストを拒否します。 + +宣言されていたものの定義されていなかった関数`wolfSSH_CTX_SetFwdEnable()`および`wolfSSH_SetFwdEnable()`は削除されました。フォワーディングは、`WOLFSSH_FWD`を指定してビルドし、フォワーディングコールバックを設定することで有効になります。 + diff --git a/wolfSSH/src-ja/chapter09.md b/wolfSSH/src-ja/chapter09.md index 99c7aafd..110116b9 100644 --- a/wolfSSH/src-ja/chapter09.md +++ b/wolfSSH/src-ja/chapter09.md @@ -1,3 +1,12 @@ # メモと制限事項 -実装ファイル属性の一部は考慮されておらず、デフォルトの属性またはモード値が使用されます。特に`wolfSSH_SFTP_Open`では、ファイルからタイムスタンプを取得し、すべての拡張ファイル属性を取得します。 +- SFTPはプロトコルバージョン3で実装されています。拡張ファイル属性は扱われず、送信も適用もされません。SFTPの`SETSTAT`または`FSETSTAT`リクエストは、含まれる属性を適用するか、`SSH_FX_OP_UNSUPPORTED`で応答されます。 +- パスワード変更リクエストはサポートされておらず、拒否されます。 +- 圧縮はサポートされていません。"none"のみが提示されます。 +- wolfSSHは`chacha20-poly1305@openssh.com`暗号も`*-etm@openssh.com` MACも提示しません。 +- SHA-1を使用するアルゴリズムとAES-CBCはコンパイルされますが、デフォルトでは提示されません。 +- "none"暗号とMACは、`--enable-none-cipher`(`WOLFSSH_ALLOW_NONE_CIPHER`)を指定したビルドでのみネゴシエーションできます。 +- RSAのユーザー認証鍵は2048ビット(`WOLFSSH_RSA_MIN_KEY_BITS`)以上でなければなりません。 +- DHグループ交換は2048ビット(`WOLFSSH_DEFAULT_GEXDH_MIN`)以上のグループを使用するため、1024ビットのグループしか提示しないサーバーとは失敗します。 +- アプリケーションは、接続相手が送信するstderr(拡張)データを読み取る必要があります。読み取られないデータはチャネルウィンドウを埋め、チャネルを停止させます。 +- wolfSSHdは、ディレクティブ`Subsystem`、`ChallengeResponseAuthentication`、`UsePAM`、`X11Forwarding`、`PrintMotd`、`AcceptEnv`、`UseDNS`を認識しますが、実装はしていません。認可済み鍵ファイルの`command=`オプションは強制されず、WindowsでのOpenSSH証明書によるログインはサポートされていません。 diff --git a/wolfSSH/src-ja/chapter11.md b/wolfSSH/src-ja/chapter11.md index 6594e27c..f7e6f019 100644 --- a/wolfSSH/src-ja/chapter11.md +++ b/wolfSSH/src-ja/chapter11.md @@ -2,49 +2,52 @@ ## サポートを得るには -一般的な製品サポートのために、wolfSSL(旧Cyassl)は、wolfSSL製品ファミリーのオンラインフォーラムを維持しています。フォーラムに投稿するか、弊社までご連絡ください。 - - -**wolfssl(yassl)フォーラム:** https://www.wolfssl.com/forumshoremail
-**サポート:** support@wolfssl.com +一般的な製品サポートのために、wolfSSLは、wolfSSL製品ファミリーのオンラインフォーラムを維持しています。ご質問がありましたら、フォーラムに投稿するか、wolfSSLまで直接ご連絡ください。 +- wolfSSLフォーラム: [https://www.wolfssl.com/forums](https://www.wolfssl.com/forums) +- メールサポート: support@wolfssl.com wolfSSL製品、ライセンスに関する質問、または一般的なコメントに関する情報については、**facts@wolfssl.com** 宛にメールしてください。 - ### バグレポートと障害のサポート -バグレポートを提出したり、問題についてお尋ねになる場合は、次の情報もあわせてお知らせください:
- -1. wolfSSLバージョン番号
- -2. オペレーティングシステムバージョン
- -3. コンパイラバージョン
- -4. 表示されている正確なエラー番号
- -5. 障害の再現方法
+バグレポートを提出したり、問題についてお尋ねになる場合は、次の情報もあわせてお知らせください: +1. wolfSSHおよびwolfSSLのバージョン番号 +2. オペレーティングシステムバージョン +3. コンパイラバージョン +4. 表示されている正確なエラー +5. 障害を再現または再試行する方法の説明 上記の情報が提供いただけると障害解決に向けて最善を尽くすことができますが、情報のご提供がなければ、問題の原因を特定することは非常に困難となります。wolfSSLはお寄せいただいたフィードバックを大切にし、できるだけ早くご回答することを最優先事項にします。 ## コンサルティング -wolfSSLは、機能の追加、移植、競争力のあるアップグレードプログラム、およびデザインコンサルティングを提供します。 +wolfSSLは、機能の追加、移植、競争力のあるアップグレードプログラム(Competitive Upgrade Program)、およびデザインコンサルティングを含む、オンサイトおよびオフサイトの両方のコンサルティングを提供します。 詳細は info@wolfssl.jp 宛にお問い合わせください。 - ### 機能追加と移植 現時点で、ご要望いただいているのに弊社製品で提供されていない機能を、契約または共同開発ベースで追加することができます。また、当社の製品を新しいホスト言語または新しい操作環境に移植するサービスも提供しています。 詳細は info@wolfssl.jp 宛にお問い合わせください。 +### 競争力のあるアップグレードプログラム(Competitive Upgrade Program) + +古くなった、あるいは高価なSSL/TLSライブラリから、低コストかつコードベースへの影響を最小限に抑えて wolfSSL への移行をお手伝いします。 + +プログラム概要: + +1. 現在、wolfSSLの商用競合製品を使用している必要があります。 +2. 古いSSLライブラリをwolfSSLに置き換えるために、最大1週間のオンサイトコンサルティングを受けられます。旅費は含まれません。 +3. 通常、お客様のコードでの置き換えと初期テストを行うには、最大1週間が適切な期間です。置き換えに関する追加のコンサルティングも必要に応じてご利用いただけます。 +4. お客様の製品に同梱するための標準的なwolfSSLのロイヤリティフリーライセンスを受けられます。 + +このプログラムの目的は、現在組み込みSSL実装に多くの費用をかけているユーザーが、容易にwolfSSLへ移行できるようにすることです。詳しくお知りになりたい場合は、facts@wolfssl.com 宛にお問い合わせください。 + ### デザインコンサルティング アプリケーションまたはフレームワークをSSL/TLSで保護する必要があるが、安全なシステムの最適な設計がどのように構造化されるべきかについて不確かな場合は、お手伝いできます! -wolfSSLを使用して、SSL/TLSセキュリティをデバイスにビルドするためのデザインコンサルティングを提供しています。 - +wolfSSLを使用して、SSL/TLSセキュリティをデバイスにビルドするためのデザインコンサルティングを提供しています。当社のコンサルタントは、以下のサービスを提供できます: diff --git a/wolfSSH/src-ja/chapter12.md b/wolfSSH/src-ja/chapter12.md index 9d63fce1..8bd75f6c 100644 --- a/wolfSSH/src-ja/chapter12.md +++ b/wolfSSH/src-ja/chapter12.md @@ -2,10 +2,14 @@ ## 製品のリリース情報 +現在のリリースは2026年10月6日にリリースされたwolfSSH v1.6.0です。各リリースの変更点は、wolfSSHソース内のChangeLog.mdファイルとGitHubのリリースページに記載されています。 + 更新情報をTwitterに定期的に投稿しています。追加のリリース情報については、GitHubでプロジェクトを追跡したり、Facebookでフォローしたり、毎日のブログをフォローしたりできます。 GitHubでのwolfSSH [https://www.github.com/wolfssl/wolfssh](https://www.github.com/wolfssl/wolfssh)
+wolfSSHのリリース [https://github.com/wolfSSL/wolfssh/releases](https://github.com/wolfSSL/wolfssh/releases)
+ TwitterでのwolfSSL [http://twitter.com/wolfSSL](http://twitter.com/wolfSSL)
FacebookでのwolfSSL [http://www.facebook.com/wolfSSL](http://www.facebook.com/wolfSSL)
diff --git a/wolfSSH/src-ja/chapter13.md b/wolfSSH/src-ja/chapter13.md index 1d5b63c1..8418231a 100644 --- a/wolfSSH/src-ja/chapter13.md +++ b/wolfSSH/src-ja/chapter13.md @@ -1,128 +1,187 @@ -# APIリファレンス +# API リファレンス -このセクションでは、wolfSSH Libraryの公開APIについて説明します。 +このセクションでは、wolfSSH ライブラリの公開アプリケーションプログラムインターフェイスについて説明します。 ## エラーコード + ### WS_ErrorCodes (enum) -以下の戻り値は、wolfssh/wolfssh/error.hで定義されていて、発生する可能性のあるさまざまなタイプのエラーを表します。 - -- WS_SUCCESS (0): 関数は成功 -- WS_FATAL_ERROR (-1): 一般的な失敗 -- WS_BAD_ARGUMENT (-2): 引数が範囲外 -- WS_MEMORY_E (-3): メモリ確保に失敗 -- WS_BUFFER_E (-4): 入/出力バッファのサイズエラー -- WS_PARSE_E (-5): 一般的な解析エラー -- WS_NOT_COMPILED (-6): 機能が組み込まれていない -- WS_OVERFLOW_E (-7): 継続するとオーバーフローする可能性あり -- WS_BAD_USAGE (-8): 使用方法が間違っている -- WS_SOCKET_ERROR_E (-9): ソケットで発生したエラー -- WS_WANT_READ (-10): IOコールバックで読み込みがブロック(再度リードせよ) -- WS_WANT_WRITE (-11): IOコールバックで書き込みがブロック(再度ライトせよ) -- WS_RECV_OVERFLOW_E (-12): 受信バッファがオーバーフローした -- WS_VERSION_E (-13): 相手が異なるSSHバージョンを使っている -- WS_SEND_OOB_READ_E (-14): 帯域外データを読み出そうとした -- WS_INPUT_CASE_E (-15): プロセス入力状態不正あるいはプログラミングエラー -- WS_BAD_FILETYPE_E (-16): ファイルタイプ不正 -- WS_UNIMPLEMENTED_E (-17): 機能が未実装 -- WS_RSA_E (-18): RSAバッファーエラー -- WS_BAD_FILE_E (-19): ファイル不正 -- WS_INVALID_ALGO_ID (-20): 無効なアルゴリズムID -- WS_DECRYPT_E (-21): 復号エラー -- WS_ENCRYPT_E (-22): 暗号化エラー -- WS_VERIFY_MAC_E (-23): mac検証エラー -- WS_CREATE_MAC_E (-24): mac作成エラー -- WS_RESOURCE_E (-25): 新たなチャネル作成にリソース不足 -- WS_INVALID_CHANTYPE (-26): 無効なチャネルタイプ -- WS_INVALID_CHANID(-27): ピアが無効なチャネルIDを要求した -- WS_INVALID_USERNAME(-28): 無効なユーザー名 -- WS_CRYPTO_FAILED(-29): 暗号アクションが失敗 -- WS_INVALID_STATE_E(-30): 無効な状態 -- WC_EOF(-31): ファイルの終了 -- WS_INVALID_PRIME_CURVE(-32): 無効なECCプライムカーブ -- WS_ECC_E(-33): ECDSAバッファーエラー -- WS_CHANOPEN_FAILED(-34): ピアがチャネルオープン失敗を返した -- WS_REKEYING(-35): ピアとリキーイング -- WS_CHANNEL_CLOSED(-36): チャネルがクローンした + +以下の API 応答コードは wolfssh/error.h で定義されており、発生し得るさまざまな種類のエラーを表す。`WS_SUCCESS` は 0 であり、すべてのエラーコードは負の値である。`WS_FATAL_ERROR` は `WS_ERROR` の非推奨エイリアスであり、`WS_LAST_E` は常に最後に定義されたエラーコード(v1.6.0 時点では `WS_CERT_KEY_USAGE_E`)を指す。値 -1059 は未割り当てである。 + +- WS_SUCCESS (0): 関数成功 +- WS_ERROR (-1001): 一般的な関数失敗 +- WS_FATAL_ERROR (-1001): WS_ERROR の非推奨エイリアス +- WS_BAD_ARGUMENT (-1002): 不正な関数引数 +- WS_MEMORY_E (-1003): メモリ割り当て失敗 +- WS_BUFFER_E (-1004): 入出力バッファサイズエラー +- WS_PARSE_E (-1005): 一般的な解析エラー +- WS_NOT_COMPILED (-1006): 機能がコンパイルに含まれていない +- WS_OVERFLOW_E (-1007): 続行するとオーバーフローする +- WS_BAD_USAGE (-1008): 不正な使用例 +- WS_SOCKET_ERROR_E (-1009): ソケットエラー +- WS_WANT_READ (-1010): ノンブロッキング読み込みがブロックする、再度呼び出すこと +- WS_WANT_WRITE (-1011): ノンブロッキング書き込みがブロックする、再度呼び出すこと +- WS_RECV_OVERFLOW_E (-1012): 受信バッファオーバーフロー +- WS_VERSION_E (-1013): ピアが誤ったバージョンの SSH を使用している +- WS_SEND_OOB_READ_E (-1014): バッファの範囲外読み込みを試みた +- WS_INPUT_CASE_E (-1015): 不正な処理入力状態、プログラミングエラー +- WS_BAD_FILETYPE_E (-1016): 不正なファイルタイプ +- WS_UNIMPLEMENTED_E (-1017): 機能が実装されていない +- WS_RSA_E (-1018): RSA バッファエラー +- WS_BAD_FILE_E (-1019): 不正なファイル +- WS_INVALID_ALGO_ID (-1020): 無効なアルゴリズム ID +- WS_DECRYPT_E (-1021): 復号エラー +- WS_ENCRYPT_E (-1022): 暗号化エラー +- WS_VERIFY_MAC_E (-1023): MAC 検証エラー +- WS_CREATE_MAC_E (-1024): MAC 生成エラー +- WS_RESOURCE_E (-1025): 新しいチャネルのためのリソース不足 +- WS_INVALID_CHANTYPE (-1026): 無効なチャネルタイプ +- WS_INVALID_CHANID (-1027): ピアが無効なチャネル ID を要求した +- WS_INVALID_USERNAME (-1028): 無効なユーザー名 +- WS_CRYPTO_FAILED (-1029): 暗号処理が失敗した +- WS_INVALID_STATE_E (-1030): 無効な状態 +- WS_EOF (-1031): ファイルの終端 +- WS_INVALID_PRIME_CURVE (-1032): ECC における無効な素数曲線 +- WS_ECC_E (-1033): ECDSA バッファエラー +- WS_CHANOPEN_FAILED (-1034): ピアがチャネルオープン失敗を返した +- WS_REKEYING (-1035): ステータス: 再鍵交換が進行中 +- WS_CHANNEL_CLOSED (-1036): ステータス: チャネルがクローズされた +- WS_INVALID_PATH_E (-1037): 無効なパス +- WS_SCP_CMD_E (-1038): SCP コマンドエラー +- WS_SCP_BAD_MSG_E (-1039): SCP 不正メッセージ +- WS_SCP_PATH_LEN_E (-1040): SCP パスが長すぎる +- WS_SCP_TIMESTAMP_E (-1041): SCP タイムスタンプエラー +- WS_SCP_DIR_STACK_EMPTY_E (-1042): SCP ディレクトリスタックが空 +- WS_SCP_CONTINUE (-1043): ステータス: SCP 継続 +- WS_SCP_ABORT (-1044): ステータス: SCP 中断 +- WS_SCP_ENTER_DIR (-1045): ステータス: SCP ディレクトリに入る +- WS_SCP_EXIT_DIR (-1046): ステータス: SCP ディレクトリから出る +- WS_SCP_EXIT_DIR_FINAL (-1047): ステータス: SCP 最終ディレクトリから出る +- WS_SCP_COMPLETE (-1048): ステータス: SCP 転送完了 +- WS_SCP_INIT (-1049): ステータス: SCP 転送が検証された +- WS_MATCH_KEX_ALGO_E (-1050): ピアと KEX アルゴリズムが一致しない +- WS_MATCH_KEY_ALGO_E (-1051): ピアと鍵アルゴリズムが一致しない +- WS_MATCH_ENC_ALGO_E (-1052): ピアと暗号化アルゴリズムが一致しない +- WS_MATCH_MAC_ALGO_E (-1053): ピアと MAC アルゴリズムが一致しない +- WS_PERMISSIONS (-1054): 権限エラー +- WS_SFTP_COMPLETE (-1055): ステータス: SFTP 接続確立 +- WS_NEXT_ERROR (-1056): 次の値/状態の取得がエラー +- WS_CHAN_RXD (-1057): ステータス: チャネルデータを受信した +- WS_INVALID_EXTDATA (-1058): 無効なチャネル拡張データタイプ +- WS_SFTP_BAD_REQ_ID (-1060): SFTP 不正リクエスト ID +- WS_SFTP_BAD_REQ_TYPE (-1061): SFTP 不正リクエストタイプ +- WS_SFTP_STATUS_NOT_OK (-1062): SFTP ステータスが OK ではない +- WS_SFTP_FILE_DNE (-1063): SFTP ファイルが存在しない +- WS_SIZE_ONLY (-1064): 必要なバッファのサイズのみ取得している +- WS_CLOSE_FILE_E (-1065): ローカルファイルをクローズできない +- WS_PUBKEY_REJECTED_E (-1066): サーバーの公開鍵が拒否された +- WS_EXTDATA (-1067): 読み取り可能な拡張データがある +- WS_USER_AUTH_E (-1068): ユーザー認証エラー +- WS_SSH_NULL_E (-1069): SSH オブジェクトが NULL だった +- WS_SSH_CTX_NULL_E (-1070): SSH_CTX オブジェクトが NULL だった +- WS_CHANNEL_NOT_CONF (-1071): チャネルオープンが確認されていない +- WS_CHANGE_AUTH_E (-1072): 認証タイプの変更が試みられた +- WS_WINDOW_FULL (-1073): チャネルウィンドウが満杯 +- WS_MISSING_CALLBACK (-1074): コールバックが不足している +- WS_DH_SIZE_E (-1075): DH 素数が想定より大きい +- WS_PUBKEY_SIG_MIN_E (-1076): 署名が小さすぎる +- WS_AGENT_NULL_E (-1077): エージェントオブジェクトが NULL だった +- WS_AGENT_NO_KEY_E (-1078): エージェントが要求された鍵を保持していない +- WS_AGENT_CXN_FAIL (-1079): エージェントに接続できなかった +- WS_SFTP_BAD_HEADER (-1080): SFTP 不正ヘッダー +- WS_CERT_NO_SIGNER_E (-1081): 署名者証明書が利用できない +- WS_CERT_EXPIRED_E (-1082): 証明書が期限切れ +- WS_CERT_REVOKED_E (-1083): ユーザー証明書が失効していると報告された +- WS_CERT_SIG_CONFIRM_E (-1084): ルート証明書の署名検証失敗 +- WS_CERT_OTHER_E (-1085): その他の証明書に関する問題 +- WS_CERT_PROFILE_E (-1086): 証明書がプロファイル要件を満たしていない +- WS_CERT_KEY_SIZE_E (-1087): 鍵サイズエラー +- WS_CTX_KEY_COUNT_E (-1088): 秘密鍵の追加が多すぎる +- WS_MATCH_UA_KEY_ID_E (-1089): ユーザー認証鍵の照合失敗 +- WS_KEY_AUTH_MAGIC_E (-1090): OpenSSH 鍵の認証マジックチェック失敗 +- WS_KEY_CHECK_VAL_E (-1091): OpenSSH 鍵のチェック値失敗 +- WS_KEY_FORMAT_E (-1092): OpenSSH 鍵形式失敗 +- WS_SFTP_NOT_FILE_E (-1093): 通常のファイルではない +- WS_MSGID_NOT_ALLOWED_E (-1094): プロトコルのこの時点では許可されないメッセージ ID +- WS_ED25519_E (-1095): Ed25519 失敗 +- WS_AUTH_PENDING (-1096): ユーザー認証がまだ保留中 +- WS_KDF_E (-1097): KDF エラー +- WS_DISCONNECT (-1098): ピアが切断を送信した +- WS_MLDSA_E (-1099): ML-DSA 失敗 +- WS_ED448_E (-1100): Ed448 失敗 +- WS_CERT_KEY_USAGE_E (-1101): 証明書の KeyUsage または ExtendedKeyUsage が SSH での使用を許可していない ### WS_IOerrors (enum) -以下は、ライブラリがユーザー提供のI/Oコールバックから受け取ることを期待しているリターンコードです。それ以外の場合、ライブラリは、I/Oアクションから読み取られたバイト数を期待しています。 +これらは、ユーザー提供の I/O コールバックからライブラリが受け取ることを想定している戻りコードである。それ以外の場合、ライブラリは I/O 動作によって読み書きされたバイト数を期待する。 + - WS_CBIO_ERR_GENERAL (-1): 一般的な予期しないエラー -- WS_CBIO_ERR_WANT_READ (-2): ソケットの読み取りブロック(再度リードせよ) -- WS_CBIO_ERR_WANT_WRITE (-2): ソケットの書き込みブロック(再度ライトせよ) -- WS_CBIO_ERR_CONN_RST (-3): コネクションがリセットされた -- WS_CBIO_ERR_ISR (-4): 割り込み発生 -- WS_CBIO_ERR_CONN_CLOSE (-5): コネクションがクローンした +- WS_CBIO_ERR_WANT_READ (-2): ソケットの読み込みがブロックする、再度呼び出すこと +- WS_CBIO_ERR_WANT_WRITE (-2): ソケットの書き込みがブロックする、再度呼び出すこと +- WS_CBIO_ERR_CONN_RST (-3): 接続がリセットされた +- WS_CBIO_ERR_ISR (-4): 割り込み +- WS_CBIO_ERR_CONN_CLOSE (-5): 接続がクローズされた、または EPIPE - WS_CBIO_ERR_TIMEOUT (-6): ソケットタイムアウト -## 初期化 /シャットダウン +## 初期化 / シャットダウン ### wolfSSH_Init() +```c +#include - -**用法** +int wolfSSH_Init(void); +``` **説明** -wolfSSHライブラリを初期化します。アプリケーションごとに1回、ライブラリへの他の呼び出しの前に呼び出される必要があります。 - -**戻り値** - -WS_SUCCESS
- -WS_CRYPTO_FAILED +使用に先立って wolfSSH ライブラリを初期化する。ライブラリへの他のいかなる呼び出しよりも前に、アプリケーションごとに一度だけ呼び出す必要がある。 **引数** なし -``` -#include -int wolfSSH_Init(void); -``` -**関連項目** +**戻り値** + +- `WS_SUCCESS` +- `WS_CRYPTO_FAILED` -wolfSSH_Cleanup() +**関連項目** +- `wolfSSH_Cleanup()` ### wolfSSH_Cleanup() +```c +#include - -**用法** +int wolfSSH_Cleanup(void); +``` **説明** -wolfSSHライブラリをクリーンアップします。アプリケーションの終了前に呼び出す必要があります。本関数呼び出し後は、ライブラリAPIの呼び出しはできません。 - -**戻り値** - -**WS_SUCCESS** - -**WS_CRYPTO_FAILED** +使用を終えた際に wolfSSH ライブラリをクリーンアップする。アプリケーションの終了前に呼び出すべきである。呼び出した後は、それ以上ライブラリを呼び出してはならない。 **引数** なし +**戻り値** -``` -#include -int wolfSSH_Cleanup(void); -``` +- `WS_SUCCESS` +- `WS_CRYPTO_FAILED` **関連項目** -wolfSSH_Init() +- `wolfSSH_Init()` ## デバッグ出力関数 @@ -130,61 +189,51 @@ wolfSSH_Init() ### wolfSSH_Debugging_ON() +```c +#include - -**用法** +void wolfSSH_Debugging_ON(void); +``` **説明** -実行中にデバッグロギングを有効にします。ビルド時にデバッグが無効になっている場合、何もしません。 +実行時のデバッグログ出力を有効にする。ビルド時にデバッグが無効化されている場合は何も行わない。 - -**戻り値** +**引数** なし -**引数** +**戻り値** なし -``` -#include -void wolfSSH_Debugging_ON(void); -``` - **関連項目** -wolfSSH_Debugging_OFF() - +- `wolfSSH_Debugging_OFF()` ### wolfSSH_Debugging_OFF() +```c +#include - -**用法** +void wolfSSH_Debugging_OFF(void); +``` **説明** -実行時にデバッグロギングを無効にします。ビルド時にデバッグが無効になっている場合、何もしません。 - - -**戻り値** - -なし +実行時のデバッグログ出力を無効にする。ビルド時にデバッグが無効化されている場合は何も行わない。 **引数** なし +**戻り値** -``` -#include -void wolfSSH_Debugging_OFF(void); -``` +なし **関連項目** -wolfSSH_Debugging_ON() +- `wolfSSH_Debugging_ON()` ## コンテキスト関数 @@ -192,1394 +241,4858 @@ wolfSSH_Debugging_ON() ### wolfSSH_CTX_new() +```c +#include - -**用法** +WOLFSSH_CTX* wolfSSH_CTX_new(byte side, void* heap); +``` **説明** -wolfSSHコンテキストオブジェクトを作成します。このオブジェクトはwolfSSHセッションオブジェクトのファクトリとして使用されます。 - -**戻り値** - -**WOLFSSH_CTX** – 割り当てられたWOLFSSH_CTXオブジェクトへのポインターあるいはNULL +wolfSSH コンテキストオブジェクトを作成する。このオブジェクトは設定した上で、wolfSSH セッションオブジェクトのファクトリとして使用できる。 **引数** -**side** – クライアントサイド(実装なし)またはサーバーサイドを示します
+- `side` - エンドポイントの役割: `WOLFSSH_ENDPOINT_SERVER` または `WOLFSSH_ENDPOINT_CLIENT` +- `heap` - メモリ割り当てに使用するヒープへのポインター、または `NULL` -**heap** – メモリ割り当てに使用するヒープへのポインター +**戻り値** -``` -#include -WOLFSSH_CTX* wolfSSH_CTX_new(byte side , void* heap ); -``` +- `WOLFSSH_CTX*` - 新しく割り当てられたコンテキストオブジェクトへのポインター +- `NULL` - 失敗時 **関連項目** -wolfSSH_CTX_free() - +- `wolfSSH_CTX_free()` ### wolfSSH_CTX_free() +```c +#include - -**用法** +void wolfSSH_CTX_free(WOLFSSH_CTX* ctx); +``` **説明** -WOLFSSH_CTXオブジェクトを解放します - -**戻り値** - -なし +wolfSSH コンテキストオブジェクトを解放する。 **引数** -**ctx** – WOLFSSH_CTXオブジェクト +- `ctx` - 解放する wolfSSH コンテキスト -``` -#include -void wolfSSH_CTX_free(WOLFSSH_CTX* ctx ); -``` +**戻り値** + +なし **関連項目** -wolfSSH_CTX_new() +- `wolfSSH_CTX_new()` ### wolfSSH_CTX_SetBanner() +```c +#include -**用法** +int wolfSSH_CTX_SetBanner(WOLFSSH_CTX* ctx, const char* newBanner); +``` **説明** -バナーメッセージをセットします +認証前にピアへ提示されるバナーメッセージを設定する。 -**戻り値** +**引数** -WS_BAD_ARGUMENT
+- `ctx` - wolfSSH コンテキストへのポインター +- `newBanner` - バナーメッセージのテキスト -WS_SUCCESS +**戻り値** -**引数** +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` -**ssh** - wolfSSHオブジェクト
+**関連項目** -**newBanner** - バナーメッセージ文字列 +- `wolfSSH_CTX_UsePrivateKey_buffer()` -``` +### wolfSSH_CTX_UsePrivateKey_buffer() + +```c #include -int wolfSSH_CTX_SetBanner(WOLFSSH_CTX* ctx , const char* newBanner ); + +int wolfSSH_CTX_UsePrivateKey_buffer(WOLFSSH_CTX* ctx, + const byte* in, word32 inSz, int format); ``` -### wolfSSH_CTX_UsePrivateKey_buffer() +**説明** +ファイルではなくバッファから秘密鍵を SSH コンテキストに読み込む。鍵は `in` 引数によって渡され、サイズは `inSz` である。`format` 引数はバッファのエンコーディングを指定する: `WOLFSSH_FORMAT_ASN1` または `WOLFSSH_FORMAT_PEM`(PEM は現時点では未実装)。 -**用法** +**引数** -**説明**
-この関数は、秘密鍵バッファをSSHコンテキストにロードします。ファイルの代わりにバッファーを入力として呼び出されます。バッファは、**insz** の **in** 引数によって提供されます。
+- `ctx` - wolfSSH コンテキストへのポインター +- `in` - 読み込む秘密鍵を含むバッファ +- `inSz` - 入力バッファのサイズ +- `format` - 入力バッファ内の秘密鍵の形式 -**引数** +**戻り値** -**format** バッファのタイプを指定します:**wolfssh_format_asn1** または **wolfssl_format_pem** (現時点では未実装)。 +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_BAD_FILETYPE_E` +- `WS_UNIMPLEMENTED_E` +- `WS_MEMORY_E` +- `WS_RSA_E` +- `WS_BAD_FILE_E` +**関連項目** -**戻り値** +- `wolfSSH_CTX_UseCert_buffer()` -**WS_SUCCESS**
+### wolfSSH_CTX_UseCert_buffer() -**WS_BAD_ARGUMENT** – 少なくとも一つの引数が不正
+**利用可能性** -**WS_BAD_FILETYPE_E** – フォーマットが不正
+`WOLFSSH_CERTS` が必要。 -**WS_UNIMPLEMENTED_E** – PEMフォーマットは未対応
+```c +#include -**WS_MEMORY_E** – メモリ確保エラー
+int wolfSSH_CTX_UseCert_buffer(WOLFSSH_CTX* ctx, + const byte* cert, word32 certSz, int format); +``` -**WS_RSA_E** – RSA鍵をデコードできない
+**説明** -**WS_BAD_FILE_E** – バッファを解析できない
+証明書ベースのホスト認証のために、サーバーの X.509 証明書をバッファからコンテキストに読み込む。`format` は `WOLFSSH_FORMAT_ASN1` または `WOLFSSH_FORMAT_PEM` である。バッファにはリーフ証明書を格納すること。PEM バッファに複数の証明書が含まれている場合は、最初の 1 つだけが読み込まれる。"TRUSTED CERTIFICATE" 形式の PEM はルート CA 用であり、ここでは受け付けない。 **引数** -**ctx** – wolfSSH_CTXオブジェクトへのポインター
+- `ctx` - wolfSSH コンテキストへのポインター +- `cert` - 証明書を含むバッファ +- `certSz` - 証明書バッファのサイズ +- `format` - 証明書のエンコーディング + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` + +**関連項目** -**in** – 秘密鍵を含むバッファへのポインター
+- `wolfSSH_CTX_AddRootCert_buffer()` -**inSz** – 入力バッファのサイズ
+### wolfSSH_CTX_AddRootCert_buffer() -**format** – 秘密鍵のフォーマット
+**利用可能性** -``` +`WOLFSSH_CERTS` が必要。 + +```c #include -int wolfSSH_CTX_UsePrivateKey_buffer(WOLFSSH_CTX* ctx , const byte* in , word32 inSz , int format); + +int wolfSSH_CTX_AddRootCert_buffer(WOLFSSH_CTX* ctx, + const byte* cert, word32 certSz, int format); ``` -**関連項目** +**説明** -wolfSSH_UseCert_buffer()
+ピアから提示された証明書を検証するために使用する、信頼されたルート CA 証明書をコンテキストに追加する。`format` は `WOLFSSH_FORMAT_ASN1` または `WOLFSSH_FORMAT_PEM` である。PEM バッファはバンドルでもよく、含まれるすべての証明書が、通常の形式でも "TRUSTED CERTIFICATE" 形式(後者は wolfSSL 5.8.0 以降が必要)でも読み込まれる。読み込みに失敗したブロックはスキップされ、CA を 1 つも読み込めなかった場合にのみ呼び出しは失敗する。 -wolfSSH_UseCaCert_buffer()
+**引数** +- `ctx` - wolfSSH コンテキストへのポインター +- `cert` - ルート証明書を含むバッファ +- `certSz` - 証明書バッファのサイズ +- `format` - 証明書のエンコーディング -## SSH セッション関数 +**戻り値** +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` -### wolfSSH_new() +**関連項目** +- `wolfSSH_CTX_UseCert_buffer()` +- `wolfSSH_CTX_AddRootCert_file()` +### wolfSSH_CTX_UseCert_file() -**用法** +**利用可能性** -**説明** +`WOLFSSH_CERTS` とファイルシステムのサポートが必要(`NO_FILESYSTEM` または `WOLFSSH_USER_FILESYSTEM` では利用できない)。 -wolfSSHセッションオブジェクトを確保し、与えられたwolfSSH_CTXオブジェクトを使って初期化します。 +```c +#include -**戻り値** +int wolfSSH_CTX_UseCert_file(WOLFSSH_CTX* ctx, const char* name); +``` + +**説明** -**WOLFSSH*** – WOLFSSHオブジェクトへのポインターあるいはNULL +サーバーの X.509 証明書をファイル `name` からコンテキストに読み込む。wolfSSH_CTX_UseCert_buffer() のファイル版である。ファイルが PEM か DER かは内容から判定される。OpenSSH 証明書の行はここでは受け付けない。 **引数** -**ctx** – wolfSSHセッションの初期化に使用されるwolfSSHコンテキスト +- `ctx` - wolfSSH コンテキストへのポインター +- `name` - 証明書ファイルへのパス +**戻り値** -``` -#include -WOLFSSH* wolfSSH_new(WOLFSSH_CTX* ctx ); -``` +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` または `name` が NULL +- `WS_BAD_FILE_E` - ファイルを開けない、読み込めない、空である、または `WOLFSSH_MAX_FILE_SIZE` より大きい +- `WS_BAD_FILETYPE_E` - 内容が PEM または DER の X.509 証明書ではない +- `WS_MEMORY_E` +- 証明書のデコードによるその他のエラー **関連項目** -wolfSSH_free() - -### wolfSSH_free() +- `wolfSSH_CTX_UseCert_buffer()` +- `wolfSSH_CTX_AddRootCert_file()` +### wolfSSH_CTX_AddRootCert_file() +**利用可能性** -**用法** +`WOLFSSH_CERTS` とファイルシステムのサポートが必要(`NO_FILESYSTEM` または `WOLFSSH_USER_FILESYSTEM` では利用できない)。 -**説明** +```c +#include -wolfSSHオブジェクトを解放します +int wolfSSH_CTX_AddRootCert_file(WOLFSSH_CTX* ctx, const char* name); +``` -**戻り値** +**説明** -なし +ファイル `name` に含まれる信頼されたルート CA 証明書をコンテキストに追加する。wolfSSH_CTX_AddRootCert_buffer() のファイル版である。ファイルが PEM か DER かは内容から判定される。PEM バンドルの場合は、含まれるすべての CA が読み込まれる。 **引数** -**ssh** – 解放するWOLFSSHオブジェクトへのポインター +- `ctx` - wolfSSH コンテキストへのポインター +- `name` - CA 証明書ファイルへのパス -``` -#include -void wolfSSH_free(WOLFSSH* ssh ); -``` +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` または `name` が NULL +- `WS_BAD_FILE_E` - ファイルを開けない、読み込めない、空である、または `WOLFSSH_MAX_FILE_SIZE` より大きい +- `WS_BAD_FILETYPE_E` - 内容が PEM または DER の X.509 証明書ではない +- `WS_MEMORY_E` +- 証明書のデコードによるその他のエラー **関連項目** -wolfSSH_new() +- `wolfSSH_CTX_AddRootCert_buffer()` +- `wolfSSH_CTX_UseCert_file()` +### wolfSSH_CTX_UsePrivateKey_fromStore() -### wolfSSH_set_fd() +**利用可能性** +`WOLFSSH_CERTS` と `WOLFSSH_WINDOWS_CERT_STORE` が必要(Windows のみ)。 +```c +#include -**用法** +int wolfSSH_CTX_UsePrivateKey_fromStore(WOLFSSH_CTX* ctx, + const wchar_t* storeName, word32 dwFlags, + const wchar_t* subjectName); +``` **説明** -与えられたファイルディスクリプタをsshオブジェクトに関連付けます。ファイルディスクリプタはネットワークI/Oに使用され、I/Oコールバック関数に渡されます。 - -**戻り値** +Windows システム証明書ストア内の証明書とその秘密鍵を、サーバーのホスト鍵として使用する。証明書はコモンネーム `subjectName` によって検索される。`subjectName` には "CN=" 接頭辞を付けてもよく、大文字と小文字を区別せずに完全一致する必要がある。ストア `storeName`(例: L"My")は読み取り専用で開かれる。`dwFlags` はストアの場所を選択するもので、`CERT_SYSTEM_STORE_CURRENT_USER` などの `CERT_SYSTEM_STORE_*` 場所ビットのみを含めなければならない。`CERT_STORE_DELETE_FLAG` などの制御フラグは拒否される。 -WS_SUCCESS
+鍵はその素の鍵タイプ(`ssh-rsa` または `ecdsa-sha2-nistp*`)で登録され、ビルドがサポートしていれば、対応する RFC 6187 の `x509v3-*` タイプでも登録される。これにより、証明書アルゴリズムをネゴシエートしたピアにストアの証明書そのものを送信できる。秘密鍵はストア内にとどまり、署名は CNG を通じて行われる。 -WS_BAD_ARGUMENT – 引数の少なくともひとつが不正 +有効期間内で、かつ秘密鍵にアクセス可能で署名に使用できる証明書のみが選択される。期限切れまたはまだ有効でない証明書しか一致しない場合、呼び出しは `WS_CERT_EXPIRED_E` で失敗する。代わりにそれらのいずれかを選択させるには `WOLFSSH_CERT_STORE_ALLOW_EXPIRED` を定義する。ストアの鍵は、同じアルゴリズムに対してすでに読み込まれているファイルベースまたは TPM ベースのホスト鍵やホスト証明書と、読み込み順にかかわらず混在させることはできない。以前に読み込んだストアの鍵を置き換えることは許可される。いずれかの失敗が発生した場合、コンテキストは変更されない。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `ctx` - wolfSSH コンテキストへのポインター +- `storeName` - システム証明書ストアの名前 +- `dwFlags` - ストアの場所(`CERT_SYSTEM_STORE_*` の値) +- `subjectName` - 使用する証明書のコモンネーム -**fd** – セッションで使用されるソケットディスクリプター +**戻り値** -``` -#include -int wolfSSH_set_fd(WOLFSSH* ssh , int fd ); -``` +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - NULL 引数、不正な `dwFlags`、サポートされていない鍵タイプ、または鍵構成の混在 +- `WS_BAD_FILE_E` - ストアを開けない +- `WS_CRYPTO_FAILED` - 一致する証明書はあるが、アクセス可能かつ署名用に登録された秘密鍵を持つものがない +- `WS_CERT_EXPIRED_E` - 有効期間外の証明書しか一致しない +- `WS_CTX_KEY_COUNT_E` - 空いている鍵スロットが 2 つない +- `WS_MEMORY_E` +- `WS_FATAL_ERROR` - 一致する証明書がない **関連項目** -wolfSSH_get_fd() - -### wolfSSH_get_fd() - +- `wolfSSH_CTX_GetCertStoreCert()` +- `wolfSSH_CTX_UsePrivateKey_buffer()` +### wolfSSH_CTX_GetCertStoreCert() -**用法** +**利用可能性** -**説明** - -SSHコネクションの入出力機能で使用されるファイルディスクリプタ( **fd** )を返します。一般的にはソケットファイルディスクリプタを返します。 +`WOLFSSH_CERTS` と `WOLFSSH_WINDOWS_CERT_STORE` が必要(Windows のみ)。 +```c +#include -**戻り値** +int wolfSSH_CTX_GetCertStoreCert(WOLFSSH_CTX* ctx, + const byte** cert, word32* certSz, const char** algoName); +``` -**int** – ファイルディスクリプタ
+**説明** -**WS_BAD_ARGUEMENT** +wolfSSH_CTX_UsePrivateKey_fromStore() で読み込んだホスト鍵に結び付けられた証明書を報告する。アプリケーションはこれを証明書によるユーザー認証に提示できる。`cert` と `certSz` には DER 証明書が返される。この証明書はコンテキストが所有し、コンテキストが解放されるか鍵スロットが置き換えられるまで有効である。`algoName` には静的な `x509v3-*` アルゴリズム名が返される。出力ポインターはいずれも NULL にしてその出力を省略できる。複数のストア資格情報が読み込まれている場合は、読み込み順で最初の `x509v3-*` スロットが返される。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `ctx` - wolfSSH コンテキストへのポインター +- `cert` - DER 証明書へのポインターの出力先 +- `certSz` - 証明書サイズの出力先 +- `algoName` - SSH アルゴリズム名の出力先 +**戻り値** -``` -#include -int wolfSSH_get_fd(const WOLFSSH* ssh ); -``` +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` が NULL +- `WS_FATAL_ERROR` - 証明書ストアに基づく `x509v3-*` 鍵スロットが存在しない **関連項目** -wolfSSH_set_fd() +- `wolfSSH_CTX_UsePrivateKey_fromStore()` -## ハイウォーターマーク機能 +## SSH セッション関数 -### wolfSSH_SetHighwater() +### wolfSSH_new() +```c +#include -**用法** +WOLFSSH* wolfSSH_new(WOLFSSH_CTX* ctx); +``` **説明** -SSHセッションで使用するハイウォーターマークをセットします。 +提供された wolfSSH コンテキストで初期化された wolfSSH セッションオブジェクトを作成する。 -**戻り値** +**引数** + +- `ctx` - セッションの初期化に使用する wolfSSH コンテキスト -WS_SUCCESS
+**戻り値** -WS_BAD_ARGUMENT +- `WOLFSSH*` - 新しく割り当てられたセッションオブジェクトへのポインター +- `NULL` - 失敗時 -**引数** +**関連項目** -**ssh** - WOLFSSHオブジェクトへのポインター
+- `wolfSSH_free()` -**highwater** - ハイウォーターマークを示すデータ +### wolfSSH_free() -``` +```c #include -int wolfSSH_SetHighwater(WOLFSSH* ssh , word32 highwater ); -``` -### wolfSSH_GetHighwater() +void wolfSSH_free(WOLFSSH* ssh); +``` +**説明** -**用法** +wolfSSH セッションオブジェクトを解放する。 -**説明** +**引数** -ハイウォーターマークを返します。 +- `ssh` - 解放するセッション **戻り値** -**word32** - ハイウォーターマーク - -**引数** +なし -**ssh** - WOLFSSHオブジェクトへのポインター
+**関連項目** -``` -#include -word32 wolfSSH_GetHighwater(WOLFSSH* ssh ); -``` +- `wolfSSH_new()` -### wolfSSH_SetHighwaterCb() +### wolfSSH_worker() +```c +#include -**用法** +int wolfSSH_worker(WOLFSSH* ssh, word32* channelId); +``` **説明** -SSHセッションにハイウォーターマークとハイウォーターコールバック関数を設定します。 +SSH 接続を処理する。保留中の受信データを受け取り、保留中の送信パケットをフラッシュする。これは実行中のセッションに対する主要なドライバー呼び出しである。`WS_SUCCESS` 以外にも、呼び出し側がエラーとして扱ってはならない致命的でないステータスをいくつか返す。 +- `WS_CHAN_RXD` - チャネルデータが到着した。wolfSSH_stream_read() または wolfSSH_ChannelIdRead() で読み取る +- `WS_EXTDATA` - 拡張(stderr)データが到着した。wolfSSH_ChannelIdReadExt()(最初のチャネルの場合は wolfSSH_extended_data_read())で読み出す +- `WS_EOF` - ピアがチャネルをハーフクローズした。ピアはこれ以上データを送信しないが、チャネルは送信用にまだ開いている。これは到着時に一度だけ報告される。見逃してはならないアプリケーションは、wolfSSH_ChannelGetEof() を確認するか、チャネル EOF コールバックを登録すること。ライブラリは自ら EOF を返さない。プロトコルが必要とする場合は、wolfSSH_ChannelSendEof() で応答すること。 +- `WS_CHANNEL_CLOSED` - ピアがチャネルをクローズし、そのチャネルは破棄された +- `WS_WANT_READ`、`WS_WANT_WRITE`、`WS_REKEYING` - 一時的な状態。再度呼び出すこと -**戻り値** +イベントは wolfSSH_get_error() からではなく、戻り値から取得すること。戻り値は何が到着したかを示し、wolfSSH_get_error() はトランスポートが何をしたかを示す。どの呼び出しにおいても両者は独立しており、戻り値がイベントを示している一方で、wolfSSH_get_error() がまだ完了していない書き込みや失敗した書き込みを報告することがある。`WS_WANT_READ` しか許容しない呼び出し側は、キューに入った書き込みが `WS_WANT_WRITE` を報告するため、稼働中のセッションを切断してしまう。それ以外のコードはエラーであり、戻り値そのものとして返されるか、`WS_FATAL_ERROR` として返されてその原因が wolfSSH_get_error() に入る。ピアの切断の場合は `WS_DISCONNECT` であり、ほとんどのセッションはこれで終了する。セッションが切断された後は、以降のすべての呼び出しが `WS_FATAL_ERROR` を返し、`WS_DISCONNECT` が保持される。 -なし +書き込みがまだ残っているかを確認するには wolfSSH_OutputPending() を、鍵交換が進行中かを確認するには wolfSSH_RekeyPending() を呼び出す。 + +`WS_CHAN_RXD`、`WS_EXTDATA`、`WS_EOF`、`WS_SUCCESS`、および `WS_SUCCESS` または `WS_CHAN_RXD` に代わって返された `WS_REKEYING` の場合は、`channelId` が NULL でなければ、そのイベントが属するチャネルの ID が書き込まれる。`WS_CHANNEL_CLOSED` を含むその他のすべてのステータスでは変更されない。その場合は wolfSSH_GetLastRxId() を使用すること。 **引数** -**ctx** – wolfSSHコンテキスト
+- `ssh` - wolfSSH セッションへのポインター +- `channelId` - イベントが属するチャネルの ID の出力先(任意、NULL でもよい) -**highwater** - ハイウォーターマーク
+**戻り値** -**cb** - ハイウォーターコールバック関数
+- `WS_SUCCESS` +- `WS_CHAN_RXD` +- `WS_EXTDATA` +- `WS_EOF` +- `WS_CHANNEL_CLOSED` +- `WS_REKEYING` +- `WS_WANT_READ` +- `WS_WANT_WRITE` +- `WS_BAD_ARGUMENT` +- `WS_FATAL_ERROR` - 原因は wolfSSH_get_error() で確認する +**関連項目** -``` -#include -void wolfSSH_SetHighwaterCb(WOLFSSH_CTX* ctx , word32 highwater , -WS_CallbackHighwater cb ); -``` +- `wolfSSH_GetLastRxId()` +- `wolfSSH_OutputPending()` +- `wolfSSH_RekeyPending()` -### wolfSSH_SetHighwaterCtx() +### wolfSSH_GetLastRxId() +```c +#include -**用法** +int wolfSSH_GetLastRxId(WOLFSSH* ssh, word32* channelId); +``` **説明** -ハイウォーターコールバック関数に渡されるコンテキストを設定します。 +最も直近にデータを受信したチャネルの ID を `channelId` に書き込む。 + +**引数** +- `ssh` - wolfSSH セッションへのポインター +- `channelId` - 最後に受信したチャネル ID の出力先 **戻り値** -なし +- `WS_SUCCESS` +- `WS_ERROR` -**引数** +**関連項目** -**ssh** - WOLFSSHオブジェクトへのポインター
+- `wolfSSH_worker()` -**ctx** - ハイウォーターコールバック関数に渡されるコンテキスト +### wolfSSH_OutputPending() -``` +```c #include -void wolfSSH_SetHighwaterCtx(WOLFSSH* ssh, void* ctx); -``` -### wolfSSH_GetHighwaterCtx() +int wolfSSH_OutputPending(const WOLFSSH* ssh); +``` +**説明** -**用法** +短い(ノンブロッキングの)送信で送り残された出力が、セッションのキューにまだ残っているかを報告する。ステータスコードとは異なり、成功を含むどの戻りの後でも正しい答えを返す。キューに入ったデータをフラッシュするには、wolfSSH_worker()(またはそのデータをキューに入れた呼び出し)を再度呼び出す。 -**説明** +**引数** -SSHセッションにセットされたハイウォーターマークを返します。 +- `ssh` - wolfSSH セッションへのポインター **戻り値** -**void*** - ハイウォーターマーク
+- 0 以外 - 書き込みがまだ残っている +- 0 - キューに何もない、または `ssh` が NULL -**NULL** - WOLFSSHオブジェクトにハイウォーターマークがセットされていない場合 +**関連項目** -**引数** +- `wolfSSH_worker()` +- `wolfSSH_RekeyPending()` -**ssh** - WOLFSSHオブジェクトへのポインター +### wolfSSH_RekeyPending() -``` +```c #include -void wolfSSH_GetHighwaterCtx(WOLFSSH* ssh ); + +int wolfSSH_RekeyPending(const WOLFSSH* ssh); ``` -## エラーチェック +**説明** +最初の鍵交換を含め、鍵交換が進行中かどうかを報告する。フラグは双方から SSH_MSG_NEWKEYS を交換した場合にのみクリアされるため、鍵交換が失敗した後もセットされたままになる。サービスループの終了判定には、この呼び出しではなく wolfSSH_worker() の結果を使用すること。 +**引数** -### wolfSSH_get_error() +- `ssh` - wolfSSH セッションへのポインター +**戻り値** + +- 0 以外 - 鍵交換が進行中である +- 0 - 鍵交換は進行中でない、または `ssh` が NULL +**関連項目** -**用法** +- `wolfSSH_worker()` +- `wolfSSH_OutputPending()` +- `wolfSSH_TriggerKeyExchange()` -**説明** +### wolfSSH_set_fd() -wolfSSHセッションオブジェクトにセットされたエラーコードを返します。 +```c +#include -**戻り値** +int wolfSSH_set_fd(WOLFSSH* ssh, WS_SOCKET_T fd); +``` -WS_ErrorCodes (enum) +**説明** + +指定されたファイルディスクリプタをセッションに割り当てる。セッションは、デフォルトの I/O コールバックにおいて、このディスクリプタをネットワーク I/O に使用する。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター +- `ssh` - ディスクリプタを設定するセッション +- `fd` - セッションが使用するソケットのファイルディスクリプタ -``` -#include -int wolfSSH_get_error(const WOLFSSH* ssh ); -``` +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` **関連項目** -wolfSSH_get_error_name() +- `wolfSSH_get_fd()` +### wolfSSH_get_fd() -### wolfSSH_get_error_name() +```c +#include +WS_SOCKET_T wolfSSH_get_fd(const WOLFSSH* ssh); +``` +**説明** -**用法** +SSH 接続の入出力に使用されているファイルディスクリプタを返す。通常はソケットのファイルディスクリプタである。 -**説明** +**引数** -wolfSSHセッションオブジェクトにセットされたエラーの名前を返します。 +- `ssh` - wolfSSH セッションへのポインター **戻り値** -**const char*** – エラー名文字列
+- 成功時はセッションのソケットファイルディスクリプタ +- `ssh` が NULL の場合は -1(Windows では `INVALID_SOCKET`)。これは新しいセッションのディスクリプタが初期化される無効なソケット値と同じである。 -**引数** +**関連項目** -**ssh** – WOLFSSHオブジェクトへのポインター +- `wolfSSH_set_fd()` +### wolfSSH_SetFilesystemHandle() -``` +```c #include -const char* wolfSSH_get_error_name(const WOLFSSH* ssh ); + +int wolfSSH_SetFilesystemHandle(WOLFSSH* ssh, void* handle); ``` -**関連項目** +**説明** -wolfSSH_get_error() +ユーザーが提供するファイルシステムハンドルをセッションに関連付ける。独自のファイルシステム層を提供する移植環境では、セッションに対するファイル操作を行う際にこのハンドルを使用する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `handle` - セッションに関連付ける不透明なファイルシステムハンドル + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +**関連項目** + +- `wolfSSH_GetFilesystemHandle()` + +### wolfSSH_GetFilesystemHandle() + +```c +#include + +void* wolfSSH_GetFilesystemHandle(WOLFSSH* ssh); +``` + +**説明** + +wolfSSH_SetFilesystemHandle() によって以前にセッションへ関連付けられたファイルシステムハンドルを返す。設定されていない場合は NULL を返す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- セッションに関連付けられたファイルシステムハンドル +- `NULL` - `ssh` が NULL の場合、またはハンドルが設定されていない場合 + +**関連項目** + +- `wolfSSH_SetFilesystemHandle()` + +## データ最高水位関数 + + + +### wolfSSH_SetHighwater() + + +```c +#include + +int wolfSSH_SetHighwater(WOLFSSH* ssh, word32 level); +``` + +**説明** + +セッションのデータハイウォーターマークをバイト単位で設定する。転送されたデータ量がこのレベルに達すると、ハイウォーターコールバックが呼び出される(通常はリキーをトリガーするため)。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `level` - ハイウォーターマーク(バイト単位) + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +**関連項目** + +- `wolfSSH_GetHighwater()` + +### wolfSSH_GetHighwater() + + +```c +#include + +word32 wolfSSH_GetHighwater(WOLFSSH* ssh); +``` + +**説明** + +セッションの現在のデータハイウォーターマークをバイト単位で返す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- データハイウォーターマーク(バイト単位) + +**関連項目** + +- `wolfSSH_SetHighwater()` + +### wolfSSH_SetHighwaterCb() + + +```c +#include + +void wolfSSH_SetHighwaterCb(WOLFSSH_CTX* ctx, word32 level, + WS_CallbackHighwater cb); +``` + +**説明** + +コンテキストレベルで、デフォルトのデータハイウォーターマークと、セッションがそれに到達したときに呼び出されるコールバックを設定する。このコンテキストから作成されたセッションは、これらのデフォルト値を継承する。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `level` - デフォルトのデータハイウォーターマーク(バイト単位) +- `cb` - ハイウォーターコールバック関数 + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_SetHighwaterCtx()` + +### wolfSSH_SetHighwaterCtx() + + +```c +#include + +void wolfSSH_SetHighwaterCtx(WOLFSSH* ssh, void* ctx); +``` + +**説明** + +セッションのハイウォーターコールバックが呼び出される際に渡される、ユーザーコンテキストポインターを設定する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - ハイウォーターコールバックに渡すユーザーコンテキストポインター + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_GetHighwaterCtx()` + +### wolfSSH_GetHighwaterCtx() + + +```c +#include + +void* wolfSSH_GetHighwaterCtx(WOLFSSH* ssh); +``` + +**説明** + +wolfSSH_SetHighwaterCtx() によって以前に設定された、ハイウォーターコールバックに渡されるユーザーコンテキストポインターを返す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- ハイウォーターのユーザーコンテキストポインター +- `NULL` - `ssh` が無効な場合、またはコンテキストが設定されていない場合 + +**関連項目** + +- `wolfSSH_SetHighwaterCtx()` + +### wolfSSH_CTX_SetMsgHighwater() + +```c +#include + +void wolfSSH_CTX_SetMsgHighwater(WOLFSSH_CTX* ctx, word32 level); +``` + +**説明** + +コンテキストレベルで、デフォルトのパケット数ハイウォーターマーク(RFC 4344, Section 3.1)を設定する。セッションで送受信されたパケット数がこのレベルに達すると、リキーがトリガーされる。このコンテキストから作成されたセッションは、このデフォルト値を継承する。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `level` - パケット数ハイウォーターマーク + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_SetMsgHighwater()` + +### wolfSSH_SetMsgHighwater() + +```c +#include + +void wolfSSH_SetMsgHighwater(WOLFSSH* ssh, word32 level); +``` + +**説明** + +単一のセッションに対して、パケット数ハイウォーターマーク(RFC 4344, Section 3.1)を設定する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `level` - パケット数ハイウォーターマーク + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_GetMsgHighwater()` + +### wolfSSH_GetMsgHighwater() + +```c +#include + +word32 wolfSSH_GetMsgHighwater(WOLFSSH* ssh); +``` + +**説明** + +セッションの現在のパケット数ハイウォーターマークを返す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- パケット数ハイウォーターマーク + +**関連項目** + +- `wolfSSH_SetMsgHighwater()` + +## エラーチェック + + + +### wolfSSH_get_error() + + + +```c +#include + +int wolfSSH_get_error(const WOLFSSH* ssh); +``` + +**説明** + +wolfSSH セッションオブジェクトに設定された最後のエラーを返します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- `WS_ErrorCodes` の値(エラーコードを参照) + +**関連項目** + +- `wolfSSH_get_error_name()` + +### wolfSSH_get_error_name() + + + +```c +#include + +const char* wolfSSH_get_error_name(const WOLFSSH* ssh); +``` + +**説明** + +wolfSSH セッションオブジェクトに設定された最後のエラーの名前文字列を返します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- エラー名文字列へのポインター + +**関連項目** + +- `wolfSSH_get_error()` ### wolfSSH_ErrorToName() -**用法** +```c +#include + +const char* wolfSSH_ErrorToName(int err); +``` + +**説明** + +指定した wolfSSH エラーコードの名前文字列を返します。 + +**引数** + +- `err` - エラーコードの値(`WS_ErrorCodes` の値) + +**戻り値** + +- エラー名文字列へのポインター + +**関連項目** + +- `wolfSSH_get_error_name()` + +## I/O コールバック + + + +### wolfSSH_SetIORecv() + + +```c +#include + +void wolfSSH_SetIORecv(WOLFSSH_CTX* ctx, WS_CallbackIORecv cb); +``` + +**説明** + +wolfSSH が入力データを読み取る際に使用する受信コールバックを登録します。コールバックのシグネチャは `WS_CallbackIORecv` 型で示されます。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - コンテキストの受信コールバックとして登録する関数 + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_SetIOSend()` + +### wolfSSH_SetIOSend() + + +```c +#include + +void wolfSSH_SetIOSend(WOLFSSH_CTX* ctx, WS_CallbackIOSend cb); +``` + +**説明** + +wolfSSH が出力データを書き込む際に使用する送信コールバックを登録します。コールバックのシグネチャは `WS_CallbackIOSend` 型で示されます。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - コンテキストの送信コールバックとして登録する関数 + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_SetIORecv()` + +### wolfSSH_SetIOReadCtx() + + +```c +#include + +void wolfSSH_SetIOReadCtx(WOLFSSH* ssh, void* ctx); +``` + +**説明** + +セッションの受信(I/O 読み取り)コールバックに渡されるコンテキストを登録します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - セッションの受信コールバックに登録するコンテキスト + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_GetIOReadCtx()` + +### wolfSSH_SetIOWriteCtx() + + +```c +#include + +void wolfSSH_SetIOWriteCtx(WOLFSSH* ssh, void* ctx); +``` + +**説明** + +セッションの送信(I/O 書き込み)コールバックに渡されるコンテキストを登録します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - セッションの送信コールバックに登録するコンテキスト + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_GetIOWriteCtx()` + +### wolfSSH_GetIOReadCtx() + + +```c +#include + +void* wolfSSH_GetIOReadCtx(WOLFSSH* ssh); +``` + +**説明** + +セッションの受信(I/O 読み取り)コールバックに以前登録されたコンテキストを返します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- 登録された読み取りコンテキストへのポインター。登録されていない場合は `NULL` + +**関連項目** + +- `wolfSSH_SetIOReadCtx()` + +### wolfSSH_GetIOWriteCtx() + + +```c +#include + +void* wolfSSH_GetIOWriteCtx(WOLFSSH* ssh); +``` + +**説明** + +セッションの送信(I/O 書き込み)コールバックに以前登録されたコンテキストを返します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- 登録された書き込みコンテキストへのポインター。登録されていない場合は `NULL` + +**関連項目** + +- `wolfSSH_SetIOWriteCtx()` + +## ユーザー認証 + + + +### wolfSSH_SetUserAuth() + + +```c +#include + +void wolfSSH_SetUserAuth(WOLFSSH_CTX* ctx, WS_CallbackUserAuth cb); +``` + +**説明** + +wolfSSH コンテキストにユーザー認証コールバックを登録します。このコールバックは、サーバー上でハンドシェイク中にクライアントを認証するかどうかを判断するために呼び出されます。 + +コールバックは、認証を肯定する判断の場合にのみ `WOLFSSH_USERAUTH_SUCCESS` を返します。`WOLFSSH_USERAUTH_PARTIAL_SUCCESS` は複数方式の認証のうち 1 つの要素が通過したことを、`WOLFSSH_USERAUTH_SUCCESS_ANOTHER` は keyboard-interactive の 1 ラウンドが通過したことを報告して次のラウンドを要求し、`WOLFSSH_USERAUTH_WOULD_BLOCK` は要求の再試行を求めます。`WOLFSSH_USERAUTH_REJECTED` は強い拒否であり、サーバーは USERAUTH_FAILURE で応答した後にセッションを終了します。その他の値は通常の失敗として扱われます。 + +注意: `WOLFSSH_USERAUTH_SUCCESS` の値は `WS_SUCCESS` と同じ 0 です。単なる `return 0;`、ヘルパーから転送された `WS_SUCCESS`、あるいはデフォルトで 0 にフォールスルーするコードは、何の警告もなくクライアントを認証してしまいます。コールバックが明示的に処理しない認証タイプやコードパスでは、`WOLFSSH_USERAUTH_FAILURE` を返してください。`WOLFSSH_USERAUTH_PUBLICKEY` の場合、コールバックは提示された公開鍵をユーザーの認可済み鍵と照合する必要があります。ライブラリが検証するのは署名であり、鍵が認可されているかどうかではありません。 + +完全な認証に至らない要求はすべて、セッションの認証失敗回数の上限に加算されます(wolfSSH_CTX_SetMaxAuthAttempts() を参照)。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - ユーザー認証コールバック関数 + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_SetUserAuthCtx()` +- `wolfSSH_CTX_SetMaxAuthAttempts()` + +### wolfSSH_SetUserAuthCtx() + + +```c +#include + +void wolfSSH_SetUserAuthCtx(WOLFSSH* ssh, void* userAuthCtx); +``` + +**説明** + +ユーザー認証コールバックに渡されるユーザーコンテキストポインターを設定します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `userAuthCtx` - 認証コールバックに渡すユーザーコンテキストポインター + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_GetUserAuthCtx()` + +### wolfSSH_GetUserAuthCtx() + + +```c +#include + +void* wolfSSH_GetUserAuthCtx(WOLFSSH* ssh); +``` + +**説明** + +wolfSSH_SetUserAuthCtx() によって以前設定されたユーザーコンテキストポインターを返します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- ユーザー認証コンテキストポインター +- `NULL` - `ssh` が NULL の場合 + +**関連項目** + +- `wolfSSH_SetUserAuthCtx()` + +### wolfSSH_SetUserAuthTypes() + +```c +#include + +void wolfSSH_SetUserAuthTypes(WOLFSSH_CTX* ctx, WS_CallbackUserAuthTypes cb); +``` + +**説明** + +サーバーが提供するユーザー認証タイプを報告するコールバックを登録します。このコールバックは `WOLFSSH_USERAUTH_*` の値(例えば `WOLFSSH_USERAUTH_PASSWORD` や `WOLFSSH_USERAUTH_PUBLICKEY`)のビットマスクを返します。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - ユーザー認証タイプコールバック + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_SetUserAuth()` + +### wolfSSH_SetUserAuthResult() + +```c +#include + +void wolfSSH_SetUserAuthResult(WOLFSSH_CTX* ctx, WS_CallbackUserAuthResult cb); +``` + +**説明** + +ユーザー認証試行の結果とともに呼び出されるコールバックを登録します。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - ユーザー認証結果コールバック + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_SetUserAuthResultCtx()` + +### wolfSSH_SetUserAuthResultCtx() + +```c +#include + +void wolfSSH_SetUserAuthResultCtx(WOLFSSH* ssh, void* userAuthResultCtx); +``` + +**説明** + +ユーザー認証結果コールバックに渡されるユーザーコンテキストポインターを設定します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `userAuthResultCtx` - 結果コールバックに渡すユーザーコンテキストポインター + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_GetUserAuthResultCtx()` + +### wolfSSH_GetUserAuthResultCtx() + +```c +#include + +void* wolfSSH_GetUserAuthResultCtx(WOLFSSH* ssh); +``` + +**説明** + +wolfSSH_SetUserAuthResultCtx() によって以前設定されたユーザーコンテキストポインターを返します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- ユーザー認証結果コンテキストポインター +- `NULL` - `ssh` が NULL の場合 + +**関連項目** + +- `wolfSSH_SetUserAuthResultCtx()` + +### wolfSSH_CTX_SetPublicKeyCheck() + +```c +#include + +void wolfSSH_CTX_SetPublicKeyCheck(WOLFSSH_CTX* ctx, + WS_CallbackPublicKeyCheck cb); +``` + +**説明** + +クライアント側で、ハンドシェイクを続行する前にサーバーの公開鍵(ホスト鍵)を確認するために使用されるコールバックを登録します。これは中間者攻撃に対するクライアントの唯一の防御です。コールバックは、鍵を受け入れる場合は 0 を、拒否して鍵交換を失敗させる場合は 0 以外を返します。 + +注意: 0 が受け入れを意味するため、デフォルトで `return 0;` するスタブはあらゆるサーバーホスト鍵を受け入れ、中間者攻撃に対する保護を無効にしてしまいます。コールバックは、known-hosts リストなどの信頼ストアと鍵を照合する必要があります。コールバックが登録されていない場合、ホスト鍵は拒否されます(`WS_PUBKEY_REJECTED_E`)。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - 公開鍵確認コールバック + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_SetPublicKeyCheckCtx()` + +### wolfSSH_SetPublicKeyCheckCtx() + +```c +#include + +void wolfSSH_SetPublicKeyCheckCtx(WOLFSSH* ssh, void* publicKeyCheckCtx); +``` + +**説明** + +公開鍵確認コールバックに渡されるユーザーコンテキストポインターを設定します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `publicKeyCheckCtx` - コールバックに渡すユーザーコンテキストポインター + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_GetPublicKeyCheckCtx()` + +### wolfSSH_GetPublicKeyCheckCtx() + +```c +#include + +void* wolfSSH_GetPublicKeyCheckCtx(WOLFSSH* ssh); +``` + +**説明** + +wolfSSH_SetPublicKeyCheckCtx() によって以前設定されたユーザーコンテキストポインターを返します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- 公開鍵確認コンテキストポインター +- `NULL` - `ssh` が NULL の場合 + +**関連項目** + +- `wolfSSH_SetPublicKeyCheckCtx()` + +### wolfSSH_CTX_SetMaxAuthAttempts() + +```c +#include + +int wolfSSH_CTX_SetMaxAuthAttempts(WOLFSSH_CTX* ctx, int value); +``` + +**説明** + +このコンテキストから作成されるセッションについて、接続ごとのユーザー認証失敗回数のサーバー側上限を設定します。デフォルトは `DEFAULT_MAX_AUTH_ATTEMPTS`(6)で、OpenSSH の `MaxAuthTries` のデフォルトと同じ値です。上限に達すると、サーバーは SSH_MSG_DISCONNECT を送信して接続を切断します。`value` が 0 以下の場合は組み込みのデフォルトに戻ります。「無制限」の設定はありません。完全な認証に至らない要求は、部分的な成功も含めてすべて加算されます。加算されないのは、クライアントが方式リストを知るために最初に送る "none" 要求だけです。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `value` - 認証失敗回数の上限、またはデフォルトを使う場合は 0 以下 + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` が NULL + +**関連項目** + +- `wolfSSH_CTX_GetMaxAuthAttempts()` +- `wolfSSH_SetMaxAuthAttempts()` + +### wolfSSH_CTX_GetMaxAuthAttempts() + +```c +#include + +int wolfSSH_CTX_GetMaxAuthAttempts(WOLFSSH_CTX* ctx); +``` + +**説明** + +コンテキストのユーザー認証失敗回数の上限を返します。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター + +**戻り値** + +- 現在の上限値 +- `WS_BAD_ARGUMENT` - `ctx` が NULL + +**関連項目** + +- `wolfSSH_CTX_SetMaxAuthAttempts()` + +### wolfSSH_SetMaxAuthAttempts() + +```c +#include + +int wolfSSH_SetMaxAuthAttempts(WOLFSSH* ssh, int value); +``` + +**説明** + +セッションがコンテキストから継承したユーザー認証失敗回数の上限を、そのセッションについてのみ上書きします。`value` の意味は wolfSSH_CTX_SetMaxAuthAttempts() と同じです。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `value` - 認証失敗回数の上限、またはデフォルトを使う場合は 0 以下 + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` が NULL + +**関連項目** + +- `wolfSSH_GetMaxAuthAttempts()` +- `wolfSSH_CTX_SetMaxAuthAttempts()` + +### wolfSSH_GetMaxAuthAttempts() + +```c +#include + +int wolfSSH_GetMaxAuthAttempts(WOLFSSH* ssh); +``` + +**説明** + +セッションのユーザー認証失敗回数の上限を返します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- 現在の上限値 +- `WS_BAD_ARGUMENT` - `ssh` が NULL + +**関連項目** + +- `wolfSSH_SetMaxAuthAttempts()` + +## ユーザー名の設定 + + + +### wolfSSH_SetUsername() + + +```c +#include + +int wolfSSH_SetUsername(WOLFSSH* ssh, const char* username); +``` + +**説明** + +SSH 接続に使用するユーザー名を NULL 終端の文字列として設定します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `username` - SSH 接続に使用するユーザー名 + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` + +**関連項目** + +- `wolfSSH_GetUsername()` + +### wolfSSH_SetUsernameRaw() + +```c +#include + +int wolfSSH_SetUsernameRaw(WOLFSSH* ssh, const byte* username, + word32 usernameSz); +``` + +**説明** + +SSH 接続に使用するユーザー名を、NULL 終端の文字列ではなくバッファと長さから設定します。ユーザー名が NULL 終端でない場合や任意のバイト列を含む場合に有用です。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `username` - ユーザー名を含むバッファ +- `usernameSz` - ユーザー名バッファの長さ + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` + +**関連項目** + +- `wolfSSH_SetUsername()` + +### wolfSSH_GetUsername() + +```c +#include + +char* wolfSSH_GetUsername(WOLFSSH* ssh); +``` + +**説明** + +セッションに関連付けられたユーザー名を返します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- セッションのユーザー名文字列へのポインター +- `NULL` - `ssh` が NULL の場合、またはユーザー名が設定されていない場合 + +**関連項目** + +- `wolfSSH_SetUsername()` + +## 接続関数 + +### wolfSSH_accept() + + + +```c +#include + +int wolfSSH_accept(WOLFSSH* ssh); +``` + +**説明** + +サーバー側で呼び出す。SSH クライアントが SSH ハンドシェイクを開始するのを待ち、それを完了させる。 + +wolfSSH_accept() はブロッキング I/O・ノンブロッキング I/O のいずれとも併用できる。基盤となる I/O がノンブロッキングの場合、wolfSSH_accept() はハンドシェイクをまだ満たせない時点で戻り、続けて wolfSSH_get_error() を呼び出すと `WS_WANT_READ` または `WS_WANT_WRITE` が得られる。呼び出し側はデータが利用可能になった時点で再度呼び出すことで、wolfSSH は中断した箇所から処理を再開する。 + +基盤となる I/O がブロッキングの場合、wolfSSH_accept() はハンドシェイクが完了するかエラーが発生するまで戻らない。 + +デフォルトでは、wolfSSH_accept() は最初のチャネルが開かれてセッションが確立されるまで処理を進める。wolfSSH_CTX_SetAppChannels() または wolfSSH_SetAppChannels() でアプリケーション駆動のチャネルを有効にしている場合は、ユーザーが認証された時点で `WS_SUCCESS` を返し、以降はアプリケーションが wolfSSH_worker() とチャネルコールバックを使ってセッションを駆動する。デフォルトモードでは、SCP コマンドが許可されると wolfSSH_accept() は `WS_SCP_INIT` を返し、"sftp" サブシステム要求が許可されると wolfSSH_SFTP_accept() に処理を引き渡す。 + +セッションが切断された後(切断を送信または受信した後)は、この呼び出しは `WS_FATAL_ERROR` を返し、wolfSSH_get_error() は `WS_DISCONNECT` を報告する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- `WS_SUCCESS` +- `WS_SCP_INIT` - SCP 転送が要求された(`WOLFSSH_SCP` ビルドの場合) +- `WS_BAD_ARGUMENT` +- `WS_FATAL_ERROR` + +**関連項目** + +- `wolfSSH_connect()` +- `wolfSSH_stream_read()` +- `wolfSSH_CTX_SetAppChannels()` + +### wolfSSH_connect() + + +```c +#include + +int wolfSSH_connect(WOLFSSH* ssh); +``` + +**説明** + +クライアント側で呼び出す。サーバーとの SSH ハンドシェイクを開始する。この呼び出しの前に、基盤となる通信チャネルがセットアップ済みである必要がある。 + +wolfSSH_connect() はブロッキング I/O・ノンブロッキング I/O のいずれとも併用できる。基盤となる I/O がノンブロッキングの場合、wolfSSH_connect() はハンドシェイクをまだ満たせない時点で戻り、続けて wolfSSH_get_error() を呼び出すと `WS_WANT_READ` または `WS_WANT_WRITE` が得られる。呼び出し側は I/O が準備できた時点で再度呼び出すことで、wolfSSH は中断した箇所から処理を再開する。 + +基盤となる I/O がブロッキングの場合、wolfSSH_connect() はハンドシェイクが完了するかエラーが発生するまで戻らない。 + +セッションが切断された後(切断を送信または受信した後)は、この呼び出しは `WS_FATAL_ERROR` を返し、wolfSSH_get_error() は `WS_DISCONNECT` を報告する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_FATAL_ERROR` + +**関連項目** + +- `wolfSSH_accept()` + +### wolfSSH_shutdown() + + +```c +#include + +int wolfSSH_shutdown(WOLFSSH* ssh); +``` + +**説明** + +セッションのチャネルリストにある最初のチャネルを終了させる。SSH_MSG_CHANNEL_EOF、終了ステータス、SSH_MSG_CHANNEL_CLOSE を送信した後、ピアからのクローズ応答を読み取る。SSH_MSG_DISCONNECT は送信しない。それには wolfSSH_SendDisconnect() を使用する。 + +wolfSSH_shutdown() は、終了させるチャネルの有無にかかわらず、短いノンブロッキング送信によってキューに残されたもの(拒否された認証の USERAUTH_FAILURE や、こちら側自身の切断など)もフラッシュする。このフラッシュも短く終わることがあるため、`WS_WANT_WRITE` はチャネル終了のメッセージではなくこのフラッシュによるものである場合がある。いずれの場合も、別の結果が報告されるまで wolfSSH_shutdown() を再度呼び出すこと。ピアが切断した後は新たに何も送信されない。キューに残っているこちら側自身の切断だけが送出され、wolfSSH_get_error() は `WS_DISCONNECT` を報告する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- `WS_SUCCESS` +- `WS_CHANNEL_CLOSED` - チャネルリストが空になった +- `WS_WANT_WRITE` - 出力がまだキューに残っている。再度呼び出すこと +- `WS_WANT_READ` +- `WS_BAD_ARGUMENT` - `ssh` が NULL、または終了させるチャネルがない +- 送信または受信の処理によるその他の負のエラーコード + +**関連項目** + +- `wolfSSH_SendDisconnect()` +- `wolfSSH_ChannelExit()` +- `wolfSSH_OutputPending()` + +### wolfSSH_stream_read() + + + +```c +#include + +int wolfSSH_stream_read(WOLFSSH* ssh, byte* buf, word32 bufSz); +``` + +**説明** + +セッションのチャネルリストにある最初のチャネルから、復号化済みデータを最大 `bufSz` バイト読み取る。読み取られたバイトは内部バッファから取り除かれ、その分がチャネルウィンドウに加算される。 + +wolfSSH_stream_read() はブロッキング I/O・ノンブロッキング I/O のいずれとも併用できる。基盤となる I/O がノンブロッキングで読み取りを満たせない場合、この呼び出しは負の値を返し、wolfSSH_get_error() を呼び出すと `WS_WANT_READ` または `WS_WANT_WRITE` が得られる。呼び出し側はデータが利用可能になった時点で再度呼び出す。基盤となる I/O がブロッキングの場合、データが利用可能になるかエラーが発生するまで戻らない。リキーが進行中の場合、この呼び出しは失敗し、wolfSSH_get_error() は `WS_REKEYING` を返す。wolfSSH_worker() を呼び出してそれを完了させる。 + +読み取りが成功すると、ピアにウィンドウ調整が送信される。ノンブロッキングソケットではこの送信が短く終わることがある。その場合もバイト数は返されるが、ウィンドウ調整がキューに入っていることを示すために wolfSSH_get_error() は `WS_WANT_WRITE` のままになる。ウィンドウ調整は次の送信または次の wolfSSH_worker() 呼び出しで送出される。 + +この呼び出しは最初のチャネルのみを扱う。それ以外のチャネルに通常データまたは拡張データが到着すると、この呼び出しは `WS_ERROR` で失敗する。それらのチャネルは wolfSSH_ChannelIdRead() と wolfSSH_ChannelIdReadExt() で読み取ること。最初のチャネルに拡張(stderr)データが到着すると、この呼び出しは `WS_EXTDATA` を返す。wolfSSH_extended_data_read() が 0 を返すまで読み出すこと。ピアからの EOF は、バッファ済みのデータがすべて読み取られた後にのみ報告される。切断後も、切断前に到着したデータは読み取ることができる。バッファが空になると、この呼び出しは失敗し、wolfSSH_get_error() は `WS_DISCONNECT` を返す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `buf` - データを格納するバッファ +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 より大きい値 - 成功時に読み取ったバイト数 +- `WS_BAD_ARGUMENT` +- `WS_EXTDATA` - 最初のチャネルで拡張データが待機している +- `WS_EOF` - ピアがチャネルで EOF を送信した +- `WS_ERROR` - 別のチャネルにデータが到着した、またはピアが EOF を送信した(wolfSSH_get_error() は `WS_EOF` を報告する) +- `WS_BUFFER_E` +- `WS_FATAL_ERROR` - wolfSSH_get_error() を確認する。`WS_REKEYING`、`WS_DISCONNECT`、`WS_WANT_READ`、`WS_WANT_WRITE`、またはその他のエラーが報告される + +**関連項目** + +- `wolfSSH_stream_send()` +- `wolfSSH_extended_data_read()` +- `wolfSSH_ChannelIdRead()` +- `wolfSSH_accept()` + +### wolfSSH_stream_send() + + + +```c +#include + +int wolfSSH_stream_send(WOLFSSH* ssh, byte* buf, word32 bufSz); +``` + +**説明** + +`buf` から `bufSz` バイトを SSH ストリームデータバッファに書き込む。 + +wolfSSH_stream_send() はブロッキング I/O・ノンブロッキング I/O のいずれとも併用できる。基盤となる I/O がノンブロッキングで保留中のデータすべてを送信できない場合、wolfSSH_get_error() を呼び出すと `WS_WANT_READ` または `WS_WANT_WRITE` が得られ、呼び出し側はソケットが送信可能になった時点で再度呼び出す。基盤となる I/O がブロッキングの場合、データの送信が完了するかエラーが発生するまで戻らない。エラーが want-read/want-write でない場合(例えば `WS_REKEYING`)は、内部の SSH 処理が完了するまで wolfSSH_worker() を呼び出す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `buf` - 送信するバッファ +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 より大きい値 - 成功時に書き込んだバイト数 +- `WS_BAD_ARGUMENT` +- `WS_EOF` - こちら側がすでにチャネルで EOF を送信している +- `WS_WINDOW_FULL` - ピアのチャネルウィンドウがいっぱいである +- `WS_FATAL_ERROR` - wolfSSH_get_error() を確認する。鍵交換中であれば `WS_REKEYING` が、セッションが切断された後であれば `WS_DISCONNECT` が報告される + +**関連項目** + +- `wolfSSH_stream_read()` +- `wolfSSH_stream_send_eof()` +- `wolfSSH_accept()` + + +### wolfSSH_stream_send_eof() + +```c +#include + +int wolfSSH_stream_send_eof(WOLFSSH* ssh); +``` + +**説明** + +SSH_MSG_CHANNEL_EOF を送信して、セッションのチャネルリストにある最初のチャネルをハーフクローズする。wolfSSH_ChannelSendEof() が指定したチャネルに対して行うのと同じ処理である。以降、そのチャネルでのデータ送信は `WS_EOF` で失敗する。読み取りは、ピアが自身の EOF を送信するかチャネルをクローズするまで引き続き可能である。2 回目の呼び出しで 2 つ目の EOF が送出されることはない。原因を保持したうえで `WS_FATAL_ERROR` を返す wolfSSH_stream_send() とは異なり、この呼び出しは鍵交換中であれば `WS_REKEYING` そのものを返す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` が NULL、またはチャネルがない +- `WS_CHANNEL_NOT_CONF` - ピアがまだチャネルのオープンを確認していない +- `WS_REKEYING` - 鍵交換が進行中である。完了後に再試行すること +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) +- `WS_WANT_WRITE` などの送信処理のステータス + +**関連項目** + +- `wolfSSH_ChannelSendEof()` +- `wolfSSH_stream_send()` +- `wolfSSH_ChannelGetEof()` + +### wolfSSH_stream_exit() + + +```c +#include + +int wolfSSH_stream_exit(WOLFSSH* ssh, int status); +``` + +**説明** + +SSH ストリームを終了し、指定した終了ステータスをピアに送信してチャネルを閉じる。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `status` - ピアに報告する終了ステータス + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` が NULL、またはチャネルがない +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) + +**関連項目** + +- `wolfSSH_stream_send()` + +### wolfSSH_TriggerKeyExchange() + + +```c +#include + +int wolfSSH_TriggerKeyExchange(WOLFSSH* ssh); +``` + +**説明** + +SSH_MSG_KEXINIT を準備・送信することで、鍵交換(リキー)プロセスを開始する。開始に成功した場合、セッションのエラー状態は変更されない。失敗した場合にのみ、そのコードが wolfSSH_get_error() 用に記録される。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) +- KEXINIT の送信によるその他の負のエラーコード(`WS_WANT_WRITE` を含む) + +**関連項目** + +- `wolfSSH_worker()` +- `wolfSSH_RekeyPending()` + +### wolfSSH_stream_peek() + +```c +#include + +int wolfSSH_stream_peek(WOLFSSH* ssh, byte* buf, word32 bufSz); +``` + +**説明** + +内部バッファから取り除くことなく、最初のチャネルの保留中の復号化済みデータを最大 `bufSz` バイトまで `buf` にコピーする。その後 wolfSSH_stream_read() を呼び出すと同じデータが返される。`buf` が NULL の場合は、利用可能なバイト数(上限は `bufSz`)のみが返される。ピアからの EOF は、バッファ済みのデータがすべて読み取られた後にのみ報告される。切断後も、バッファ済みのデータは覗き見できる。バッファが空になると、この呼び出しは失敗し、wolfSSH_get_error() は `WS_DISCONNECT` を返す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `buf` - 覗き見したデータを格納するバッファ、または NULL +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 以上の値 - コピーされたバイト数(`buf` が NULL の場合は利用可能なバイト数) +- `WS_BAD_ARGUMENT` - `ssh` が NULL、またはチャネルがない +- `WS_REKEYING` - 鍵交換が進行中である +- `WS_ERROR` - バッファが空で、ピアが EOF を送信した(wolfSSH_get_error() は `WS_EOF` を報告する) +- `WS_FATAL_ERROR` - バッファが空で、セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) + +**関連項目** + +- `wolfSSH_stream_read()` +- `wolfSSH_ChannelIdPeek()` + +### wolfSSH_extended_data_send() + +```c +#include + +int wolfSSH_extended_data_send(WOLFSSH* ssh, byte* buf, word32 bufSz); +``` + +**説明** + +セッションのチャネルリストにある最初のチャネルで、`bufSz` バイトを拡張チャネルデータ(stderr データ型)として送信する。別のチャネルで送信するには wolfSSH_ChannelIdSendExt() を使用する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `buf` - 送信するバッファ +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 より大きい値 - 成功時に送信したバイト数 +- `WS_BAD_ARGUMENT` +- `WS_EOF` - こちら側がすでにチャネルで EOF を送信している +- `WS_REKEYING` - 鍵交換が進行中である +- `WS_WINDOW_FULL` - ピアのチャネルウィンドウがいっぱいである +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) + +**関連項目** + +- `wolfSSH_extended_data_read()` + +### wolfSSH_extended_data_read() + +```c +#include + +int wolfSSH_extended_data_read(WOLFSSH* ssh, byte* out, word32 outSz); +``` + +**説明** + +セッションのチャネルリストにある最初のチャネルから、バッファ済みの拡張データ(stderr)を最大 `outSz` バイトまで `out` に読み取る。これは wolfSSH_stream_read() の stderr 版であり、同じチャネルを読み取る。 + +アプリケーションは stderr を読み出さなければならない。stderr は通常データとチャネルの受信ウィンドウを共有しており(RFC 4254 セクション 5.2)、ウィンドウはデータが読み取られた分だけ補充されるため、読み取られない stderr はいずれチャネルを停止させる。wolfSSH_stream_read() が `WS_EXTDATA` を返した後、この関数が 0 を返すまで呼び出すこと。その他のチャネルには wolfSSH_ChannelIdReadExt() を使用する。wolfSSH_worker() は `WS_EXTDATA` を返す際に、拡張データが到着したチャネルを示す。 + +読み出しによってピアにウィンドウ調整が送信される。ノンブロッキングソケットではこの送信が短く終わることがある。その場合もバイト数は返されるが、フラッシュが必要であることを示すために wolfSSH_get_error() は `WS_WANT_WRITE` のままになる。読み取りしか行わないアプリケーションは、その後 wolfSSH_worker() でフラッシュしなければならない。そうしないと、ピアのウィンドウは補充されない。バッファはチャネルに属しているため、チャネルが削除された時点で読み取られていないデータはチャネルとともに破棄される。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `out` - データを格納するバッファ +- `outSz` - バッファのサイズ + +**戻り値** + +- 0 以上の値 - 読み取ったバイト数 +- `WS_BAD_ARGUMENT` - `ssh` または `out` が NULL、`outSz` が 0、またはチャネルがない +- `WS_INVALID_STATE_E` + +**関連項目** + +- `wolfSSH_extended_data_send()` +- `wolfSSH_ChannelIdReadExt()` +- `wolfSSH_ChannelReadExt()` + +### wolfSSH_SendIgnore() + +```c +#include + +int wolfSSH_SendIgnore(WOLFSSH* ssh, const byte* buf, word32 bufSz); +``` + +**説明** + +SSH_MSG_IGNORE メッセージをピアに送信する。ピアはその内容を破棄する。キープアライブやトラフィック解析対策として使用できる。引数 `buf` と `bufSz` は現在使用されておらず、メッセージには常に 128 バイトのゼロが含まれる。 + +厳格な鍵交換(strict KEX)を提示している場合、最初の鍵交換が完了する前に IGNORE を送信すると、strict KEX を使うピアは接続を終了してしまう。そのため、それまでの間この呼び出しは `WS_INVALID_STATE_E` で拒否される。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `buf` - ペイロード(現在は未使用) +- `bufSz` - ペイロードのサイズ(現在は未使用) + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_INVALID_STATE_E` - strict KEX を提示しており、最初の鍵交換がまだ完了していない +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) + +### wolfSSH_SendDisconnect() + +```c +#include + +int wolfSSH_SendDisconnect(WOLFSSH* ssh, word32 reason); +``` + +**説明** + +指定した理由コード(`WS_DisconnectReasonCodes` の値を参照)を伴う SSH_MSG_DISCONNECT メッセージをピアに送信する。 + +切断は、送信したものでも受信したものでも、セッションを終了させる(RFC 4253 セクション 11.1)。以降、wolfSSH_shutdown()、各送信呼び出し、wolfSSH_accept()、wolfSSH_connect()、wolfSSH_worker() は `WS_DISCONNECT` を報告し、切断以外の受信メッセージは破棄され、チャネルコールバックは呼び出されなくなる。切断前に到着したチャネルデータは引き続き読み取ることができる。 + +1 回の切断でセッションは終了するため、2 回目の呼び出しは `WS_DISCONNECT` で失敗する。例外は、短いノンブロッキング送信によってこちら側自身の切断がキューに残された場合で、それがキューに残っている間は、再度呼び出すとフラッシュが再試行される。wolfSSH_shutdown() もこれを再試行する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `reason` - 切断理由コード + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_WANT_WRITE` - メッセージがキューに入った。再度呼び出してフラッシュすること +- `WS_FATAL_ERROR` - セッションはすでに切断されている(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) + +**関連項目** + +- `wolfSSH_shutdown()` + +### wolfSSH_global_request() + +```c +#include + +int wolfSSH_global_request(WOLFSSH* ssh, const unsigned char* data, + word32 dataSz, int reply); +``` + +**説明** + +`data` をリクエスト名として、グローバルリクエスト(SSH_MSG_GLOBAL_REQUEST)をピアに送信する。`reply` が 1 の場合、ピアに成功または失敗の応答を要求する。RFC 4254 セクション 7.1 で want-reply ブール値の後に置かれるリクエスト固有のデータはこの呼び出しでは運べないため、それを必要とするリクエストには wolfSSH_FwdRemoteSetup() などの専用の呼び出しがある。応答にはリクエスト ID が含まれないため、`WOLFSSH_FWD` ビルドでは、`reply` を設定して送信したリクエストは wolfSSH_FwdRemoteSetup() が使用するのと同じ送信順のキューに並ぶ。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `data` - リクエスト名 +- `dataSz` - リクエスト名のサイズ +- `reply` - ピアからの応答を要求する場合は 1、それ以外は 0 + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` または `data` が NULL、または `reply` が 0 でも 1 でもない +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) +- 送信処理によるその他の負のエラーコード + +### wolfSSH_ChannelIdRead() + +```c +#include + +int wolfSSH_ChannelIdRead(WOLFSSH* ssh, word32 channelId, + byte* buf, word32 bufSz); +``` + +**説明** + +`channelId` で識別されるチャネルから、バッファ済みのデータを最大 `bufSz` バイトまで読み取る。wolfSSH_ChannelRead() と同じ規約に従い、すでにバッファにあるデータを読み出し、バッファが空の場合は 0 を返す。トランスポートから受信することも、EOF を報告することもない。wolfSSH_ChannelRead() とは異なり、鍵交換中も読み取りを行う。さらにデータを受信するには wolfSSH_worker() を呼び出す。 + +読み取りによってチャネルウィンドウが加算され、ピアにウィンドウ調整が送信される。ウィンドウ調整を送出できない場合でもバイト数は返される。呼び出し後に wolfSSH_get_error() を確認し、`WS_WANT_WRITE` であればウィンドウ調整がキューに入っていることを意味する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `channelId` - 読み取り対象のチャネル +- `buf` - データを格納するバッファ +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 以上の値 - 読み取ったバイト数 +- `WS_BAD_ARGUMENT` +- `WS_INVALID_CHANID` - その ID を持つチャネルがない +- `WS_INVALID_STATE_E` + +**関連項目** + +- `wolfSSH_ChannelIdSend()` +- `wolfSSH_ChannelIdPeek()` +- `wolfSSH_ChannelIdReadExt()` + +### wolfSSH_ChannelIdPeek() + +```c +#include + +int wolfSSH_ChannelIdPeek(WOLFSSH* ssh, word32 channelId, + byte* buf, word32 bufSz); +``` + +**説明** + +`channelId` で識別されるチャネルから、バッファ済みのデータを消費することなく最大 `bufSz` バイトまで `buf` にコピーする。wolfSSH_stream_peek() と同じ規約に従うが、鍵交換中も覗き見を行う点が異なる。`buf` が NULL の場合は、利用可能なバイト数(上限は `bufSz`)のみが返される。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `channelId` - 覗き見するチャネル +- `buf` - 覗き見したデータを格納するバッファ、または NULL +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 以上の値 - コピーされたバイト数(`buf` が NULL の場合は利用可能なバイト数) +- `WS_BAD_ARGUMENT` - `ssh` が NULL +- `WS_INVALID_CHANID` - その ID を持つチャネルがない +- `WS_ERROR` - バッファが空で、ピアが EOF を送信した(wolfSSH_get_error() は `WS_EOF` を報告する) +- `WS_FATAL_ERROR` - バッファが空で、セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) + +**関連項目** + +- `wolfSSH_ChannelIdRead()` +- `wolfSSH_stream_peek()` + +### wolfSSH_ChannelIdSend() + +```c +#include + +int wolfSSH_ChannelIdSend(WOLFSSH* ssh, word32 channelId, + byte* buf, word32 bufSz); +``` + +**説明** + +`channelId` で識別されるチャネル上で `bufSz` バイトを送信する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `channelId` - 送信対象のチャネル +- `buf` - 送信するバッファ +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 より大きい値 - 成功時に送信したバイト数 +- `WS_BAD_ARGUMENT` +- `WS_INVALID_CHANID` - その ID を持つチャネルがない +- `WS_CHANNEL_NOT_CONF` - ピアがまだチャネルのオープンを確認していない +- `WS_EOF` - こちら側がすでにチャネルで EOF を送信している +- `WS_REKEYING` - 鍵交換が進行中である +- `WS_WINDOW_FULL` - ピアのチャネルウィンドウがいっぱいである +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) + +**関連項目** + +- `wolfSSH_ChannelIdRead()` +- `wolfSSH_ChannelIdSendExt()` + +### wolfSSH_ChannelIdReadExt() + +```c +#include + +int wolfSSH_ChannelIdReadExt(WOLFSSH* ssh, word32 channelId, + byte* buf, word32 bufSz); +``` + +**説明** + +`channelId` で識別されるチャネルから、バッファ済みの拡張データ(stderr)を最大 `bufSz` バイトまで読み取る。wolfSSH_extended_data_read() と同じ読み出しの規約に従うが、チャネルリストの最初のチャネルではなく、指定したチャネルを読み取る。stderr は通常データとチャネルの受信ウィンドウを共有しているため、各チャネルの stderr を読み出さなければならない。wolfSSH_worker() は `WS_EXTDATA` を返す際にそのチャネルを示す。ウィンドウ調整を送出できない場合でもバイト数は返され、その場合 wolfSSH_get_error() は `WS_WANT_WRITE` などのウィンドウ調整のステータスを報告する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `channelId` - 読み取り対象のチャネル +- `buf` - データを格納するバッファ +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 以上の値 - 読み取ったバイト数 +- `WS_BAD_ARGUMENT` - `ssh` または `buf` が NULL、または `bufSz` が 0 +- `WS_INVALID_CHANID` - その ID を持つチャネルがない +- `WS_INVALID_STATE_E` + +**関連項目** + +- `wolfSSH_ChannelIdSendExt()` +- `wolfSSH_extended_data_read()` +- `wolfSSH_ChannelReadExt()` + +### wolfSSH_ChannelIdSendExt() + +```c +#include + +int wolfSSH_ChannelIdSendExt(WOLFSSH* ssh, word32 channelId, + byte* buf, word32 bufSz); +``` + +**説明** + +`channelId` で識別されるチャネル上で、`bufSz` バイトを拡張データ(stderr データ型)として送信する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `channelId` - 送信対象のチャネル +- `buf` - 送信するバッファ +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 より大きい値 - 成功時に送信したバイト数 +- `WS_BAD_ARGUMENT` +- `WS_INVALID_CHANID` - その ID を持つチャネルがない +- `WS_CHANNEL_NOT_CONF` - ピアがまだチャネルのオープンを確認していない +- `WS_EOF` - こちら側がすでにチャネルで EOF を送信している +- `WS_REKEYING` - 鍵交換が進行中である +- `WS_WINDOW_FULL` - ピアのチャネルウィンドウがいっぱいである +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) + +**関連項目** + +- `wolfSSH_ChannelIdReadExt()` +- `wolfSSH_extended_data_send()` +- `wolfSSH_ChannelSendExt()` + +### wolfSSH_CTX_SetSshProtoIdStr() + +```c +#include + +int wolfSSH_CTX_SetSshProtoIdStr(WOLFSSH_CTX* ctx, const char* protoIdStr); +``` + +**説明** + +接続開始時のバージョン交換でピアに送信される SSH プロトコル識別文字列を上書きする。文字列は検証され、次の条件をすべて満たさない場合は `WS_BAD_ARGUMENT` で拒否される(その場合、コンテキストは変更されない)。 + +- "SSH-2.0-" で始まる +- 長さが、"SSH-2.0-" 接頭辞と末尾の CR LF を含めて 11 から 255 バイトである +- CR LF (`"\r\n"`) で終わる +- 本体には印字可能な US-ASCII(0x20 から 0x7e)のみを含む。したがって、CR や LF を途中に含めることはできない +- 本体の先頭が空白でない(RFC 4253 セクション 4.2 では本体を softwareversion とそれに続く任意のコメントとして解釈するため、先頭に空白があると softwareversion が空になる。本体の途中にある空白はコメントの開始となる) + +文字列はコピーされずに参照として保持されるため、コンテキストの存続期間中は有効かつ変更されない状態を保つ必要がある。検証は設定時にのみ行われる。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `protoIdStr` - 送信するプロトコル識別文字列(末尾の CR LF を含む) + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_CTX_SetWindowPacketSize() + +```c +#include + +int wolfSSH_CTX_SetWindowPacketSize(WOLFSSH_CTX* ctx, + word32 windowSz, word32 maxPacketSz); +``` + +**説明** + +このコンテキストから作成されるセッションに対する、デフォルトのチャネルウィンドウサイズと最大パケットサイズを設定する。`windowSz` が 0 の場合はデフォルト(`DEFAULT_WINDOW_SZ`、128 KB)が選択され、ウィンドウは 256 KB(`WINDOW_SZ_UPPER_BOUND`)を超えてはならない。`maxPacketSz` が 0 の場合はデフォルト(`DEFAULT_MAX_PACKET_SZ`、32768)が選択され、パケットサイズは `MAX_PACKET_SZ` からチャネルデータパケットのオーバーヘッドを差し引いた値を超えてはならない。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `windowSz` - チャネルウィンドウサイズ(バイト単位)、またはデフォルトを使う場合は 0 +- `maxPacketSz` - 最大パケットサイズ(バイト単位)、またはデフォルトを使う場合は 0 + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` が NULL、またはサイズが上限を超えている + +## チャネルコールバック + +wolfSSH ライブラリへのインターフェースは単一の int 値を返す。ピアがチャネルを開くといった非同期な情報の状態を伝えるには、このインターフェースでは不十分である。wolfSSH は、チャネルの状態変化を呼び出し元アプリケーションに通知するためにコールバック関数を使用する。 + +以下の SSHv2 プロトコルメッセージの受信に対応するコールバック関数が存在する。 + +* SSH_MSG_CHANNEL_OPEN +* SSH_MSG_CHANNEL_OPEN_CONFIRMATION +* SSH_MSG_CHANNEL_OPEN_FAILURE +* SSH_MSG_CHANNEL_REQUEST + - "shell" + - "subsystem" + - "exec" + - 任意のリクエストタイプ(wolfSSH_CTX_SetChannelReqAnyCb() で設定する + リクエストポリシーコールバックを通じて) +* SSH_MSG_CHANNEL_EOF +* SSH_MSG_CHANNEL_CLOSE + +### コールバック関数のプロトタイプ + +チャネルコールバック関数はいずれも、**WOLFSSH_CHANNEL** オブジェクトへのポインター _channel_ と、アプリケーションが定義したデータ構造へのポインター _ctx_ を引数に取る。チャネルに関するプロパティは API 関数を使って取得できる。 + +``` +typedef int (*WS_CallbackChannelOpen)(WOLFSSH_CHANNEL* channel, void* ctx); +typedef int (*WS_CallbackChannelReq)(WOLFSSH_CHANNEL* channel, void* ctx); +typedef int (*WS_CallbackChannelEof)(WOLFSSH_CHANNEL* channel, void* ctx); +typedef int (*WS_CallbackChannelClose)(WOLFSSH_CHANNEL* channel, void* ctx); +``` + +リクエストポリシーコールバックは独自のプロトタイプを持ち、リクエストタイプとそのタイプ固有のデータも受け取り、`WS_ReqCbResult` の値のいずれかを返す。グローバルリクエストポリシーコールバック(wolfSSH_CTX_SetGlobalReqAnyCb() を参照)も同じ結果値を使用する。 + +``` +typedef enum WS_ReqCbResult { + WOLFSSH_REQ_UNHANDLED = 0, + WOLFSSH_REQ_ACCEPT, + WOLFSSH_REQ_REJECT +} WS_ReqCbResult; + +typedef int (*WS_CallbackChannelReqAny)(WOLFSSH_CHANNEL* channel, + const byte* type, word32 typeSz, const byte* data, word32 dataSz, + int wantReply, void* ctx); +``` + +ここでは 0 が `WOLFSSH_REQ_UNHANDLED` であることに注意すること。shell、subsystem、exec のリクエストコールバックでは、戻り値 0 は受け入れと解釈される。このファミリーのコールバックは、`WS_SUCCESS` ではなく、3 つの `WS_ReqCbResult` 値のいずれかを返す。 + +### wolfSSH_CTX_SetChannelOpenCb() + +```c +#include + +int wolfSSH_CTX_SetChannelOpenCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelOpen cb); +``` + +**説明** + +ピアからチャネルオープン(SSH_MSG_CHANNEL_OPEN)メッセージを受信した際に呼び出されるコールバックを設定する。これはピアによるチャネルオープンに対するポリシーコールバックである。コールバックが登録されていない場合、ピアからのチャネルオープンはデフォルトですべて受け入れられる。ただし、フォワーディングのチャネルタイプは、フォワーディングコールバックがなければ拒否される(wolfSSH_CTX_SetFwdCb() を参照)。クライアントは、サーバーからの "session" チャネルオープンを、このコールバックより先に無条件で拒否する。チャネルのポリシーを適用するにはコールバックを登録する。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - チャネルオープンコールバック + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**関連項目** + +- `wolfSSH_SetChannelOpenCtx()` + + +### wolfSSH_CTX_SetChannelOpenRespCb() + +```c +#include + +int wolfSSH_CTX_SetChannelOpenRespCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelOpen confCb, WS_CallbackChannelOpen failCb); +``` + +**説明** + +ピアからチャネルオープン確認(SSH_MSG_CHANNEL_OPEN_CONFIRMATION)またはチャネルオープン失敗(SSH_MSG_CHANNEL_OPEN_FAILURE)メッセージを受信した際に呼び出されるコールバックを設定する。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `confCb` - チャネルオープン確認のコールバック +- `failCb` - チャネルオープン失敗のコールバック + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**関連項目** + +- `wolfSSH_CTX_SetChannelOpenCb()` + + +### wolfSSH_CTX_SetChannelReqShellCb() + +```c +#include + +int wolfSSH_CTX_SetChannelReqShellCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelReq cb); +``` + +**説明** + +ピアから _shell_ に対するチャネルリクエスト(SSH_MSG_CHANNEL_REQUEST)メッセージを受信した際に呼び出されるコールバックを設定する。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - チャネルリクエストコールバック + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**関連項目** + +- `wolfSSH_CTX_SetChannelReqExecCb()` + + +### wolfSSH_CTX_SetChannelReqSubsysCb() + +```c +#include + +int wolfSSH_CTX_SetChannelReqSubsysCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelReq cb); +``` + +**説明** + +ピアから _subsystem_ に対するチャネルリクエスト(SSH_MSG_CHANNEL_REQUEST)メッセージを受信した際に呼び出されるコールバックを設定する。サブシステムの一般的な例としては SFTP がある。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - チャネルリクエストコールバック + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**関連項目** + +- `wolfSSH_CTX_SetChannelReqShellCb()` + + +### wolfSSH_CTX_SetChannelReqExecCb() + +```c +#include + +int wolfSSH_CTX_SetChannelReqExecCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelReq cb); +``` + +**説明** + +ピアから _exec_ するコマンドに対するチャネルリクエスト(SSH_MSG_CHANNEL_REQUEST)メッセージを受信した際に呼び出されるコールバックを設定する。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - チャネルリクエストコールバック + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**関連項目** + +- `wolfSSH_CTX_SetChannelReqShellCb()` + + +### wolfSSH_CTX_SetChannelReqAnyCb() + +```c +#include + +int wolfSSH_CTX_SetChannelReqAnyCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelReqAny cb); +``` + +**説明** + +ピアからのすべてのチャネルリクエスト(SSH_MSG_CHANNEL_REQUEST)に対して、shell、exec、subsystem の各コールバックや組み込みの処理よりも先に参照されるポリシーコールバックを設定する。専用のコールバックを持たないリクエスト(env、pty-req、window-change、exit-status、auth-agent-req、またはライブラリが認識しないタイプ)も、これによりポリシーに基づいて許可または拒否できる。 + +`type` は到着したままのリクエスト名で長さは `typeSz` バイト、`data` はリクエストのタイプ固有の部分で長さは `dataSz` バイトであり、コールバックが解析する。どちらも NUL 終端されておらず、名前には任意のバイトが含まれ得るため、文字列関数ではなく `typeSz` バイトで照合すること。`wantReply` はピアが要求した値である。コールバックは、wolfSSH_SetChannelReqCtx() で設定したチャネルリクエストコンテキストを共有する。 + +コールバックは `WS_ReqCbResult` を返す。`WOLFSSH_REQ_UNHANDLED`(0 であり、コールバックがない場合の応答でもある)は、リクエストを他のコールバックと組み込みの処理に委ねる。`WOLFSSH_REQ_ACCEPT` と `WOLFSSH_REQ_REJECT` はリクエストの扱いを確定させ、shell、exec、subsystem の各コールバックは参照されない。ライブラリは、認識できるリクエストについては必要な情報を引き続き解析・記録する。そのため、受け入れられた session リクエストはチャネルのセッションタイプを設定し、受け入れられた pty-req のモードは保持される。タイプに適合しないリクエストは、コールバックの結果にかかわらず拒否される。ライブラリが認識しないタイプは、`WOLFSSH_REQ_ACCEPT` の場合は CHANNEL_SUCCESS で応答され、それ以外の場合は拒否される。 + +コールバックは、渡されたチャネルを wolfSSH_ChannelFree() で解放してもよい。その場合リクエストはそこで終了し、応答を求めるリクエストは `WS_INVALID_CHANID` で失敗する。`type` と `data` はセッションの入力バッファ内を指しており、呼び出しの間のみ有効であるため、いずれかを保持するコールバックはコピーしなければならない。コールバックは、このセッションに対してライブラリの受信側(wolfSSH_worker()、wolfSSH_stream_read()、wolfSSH_accept()、または SFTP の呼び出し)を再入してはならない。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - チャネルリクエストポリシーコールバック + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**関連項目** + +- `wolfSSH_SetChannelReqCtx()` +- `wolfSSH_CTX_SetChannelReqShellCb()` +- `wolfSSH_CTX_SetGlobalReqAnyCb()` + + +### wolfSSH_CTX_SetAppChannels() + +```c +#include + +int wolfSSH_CTX_SetAppChannels(WOLFSSH_CTX* ctx, byte enable); +``` + +**説明** + +このコンテキストから作成されるセッションについて、サーバー側でのアプリケーション駆動のチャネル処理を有効または無効にする。デフォルトでは無効である。 + +無効の場合、wolfSSH_accept() は最初のチャネルが開かれてセッションが確立されるまでセッションのステートマシンを進め、コールバックが登録されていない shell、exec、subsystem のリクエストは受け入れられる。 + +有効の場合、wolfSSH_accept() はユーザーが認証された時点で `WS_SUCCESS` を返し、以降はアプリケーションがすべてのチャネルを管理し、wolfSSH_worker() とチャネルコールバックを使ってセッションを駆動する。このとき、コールバックが登録されていない shell、exec、subsystem のリクエストは拒否される。このモードでは wolfSSH_accept() は組み込みの SCP エントリーポイントに到達しないため、`WS_SCP_INIT` を返さない。wolfSSH_SFTP_accept() は引き続き機能するが、"sftp" サブシステムリクエストがサブシステムコールバックによって許可されたセッションチャネル上に限られる。それより前に呼び出すと `WS_INVALID_STATE_E` を返す。 + +これは wolfSSH_new() の前にコンテキストに設定するか、最初の wolfSSH_accept() 呼び出しの前に wolfSSH_SetAppChannels() でセッションに設定する。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `enable` - アプリケーション駆動のチャネルを有効にする場合は 0 以外、無効にする場合は 0 + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**関連項目** + +- `wolfSSH_SetAppChannels()` +- `wolfSSH_accept()` +- `wolfSSH_ChannelGetSessionGranted()` + + +### wolfSSH_SetAppChannels() + +```c +#include + +int wolfSSH_SetAppChannels(WOLFSSH* ssh, byte enable); +``` + +**説明** + +1 つのセッションについて、コンテキストから継承した設定を上書きして、アプリケーション駆動のチャネル処理を有効または無効にする。wolfSSH_CTX_SetAppChannels() を参照。最初の wolfSSH_accept() 呼び出しの前に設定すること。後から有効にしても以降のチャネルリクエストには適用されるが、すでにユーザー認証を通過したセッションでは、wolfSSH_accept() が戻る位置を変えることはできない。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `enable` - アプリケーション駆動のチャネルを有効にする場合は 0 以外、無効にする場合は 0 + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` + +**関連項目** + +- `wolfSSH_CTX_SetAppChannels()` + +### wolfSSH_CTX_SetChannelEofCb() + +```c +#include + +int wolfSSH_CTX_SetChannelEofCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelEof cb); +``` + +**説明** + +ピアからチャネル EOF(SSH_MSG_CHANNEL_EOF)メッセージを受信した際に呼び出されるコールバックを設定する。これはピアがこのチャネル上でこれ以上データを送信しないことを示す。チャネルは送信用に開いたままである。ライブラリは受信した EOF に対して自ら EOF を返すことはない。応答するかどうかはアプリケーションが判断し、応答する場合は wolfSSH_ChannelSendEof() または wolfSSH_stream_send_eof() を使用する。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - チャネル EOF コールバック + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**関連項目** + +- `wolfSSH_CTX_SetChannelCloseCb()` + + +### wolfSSH_CTX_SetChannelCloseCb() + +```c +#include + +int wolfSSH_CTX_SetChannelCloseCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelClose cb); +``` + +**説明** + +ピアからチャネルクローズ(SSH_MSG_CHANNEL_CLOSE)メッセージを受信した際に呼び出されるコールバックを設定する。これはピアがこのチャネルを終了させたいことを示す。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - チャネルクローズコールバック + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**関連項目** + +- `wolfSSH_CTX_SetChannelEofCb()` + + +### wolfSSH_SetChannelOpenCtx() + +```c +#include + +int wolfSSH_SetChannelOpenCtx(WOLFSSH* ssh, void* ctx); +``` + +**説明** + +チャネルオープン、チャネルオープン確認、およびチャネルオープン失敗の各コールバックに渡されるユーザーコンテキストを設定する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - チャネルオープンコールバックに渡すユーザーコンテキスト + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` + +**関連項目** + +- `wolfSSH_GetChannelOpenCtx()` + + +### wolfSSH_SetChannelReqCtx() + +```c +#include + +int wolfSSH_SetChannelReqCtx(WOLFSSH* ssh, void* ctx); +``` + +**説明** + +チャネルリクエスト(shell/exec/subsystem)コールバックに渡されるユーザーコンテキストを設定する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - チャネルリクエストコールバックに渡すユーザーコンテキスト + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` + +**関連項目** + +- `wolfSSH_GetChannelReqCtx()` + + +### wolfSSH_SetChannelEofCtx() + +```c +#include + +int wolfSSH_SetChannelEofCtx(WOLFSSH* ssh, void* ctx); +``` + +**説明** + +チャネル EOF コールバックに渡されるユーザーコンテキストを設定する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - チャネル EOF コールバックに渡すユーザーコンテキスト + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` + +**関連項目** + +- `wolfSSH_GetChannelEofCtx()` + + +### wolfSSH_SetChannelCloseCtx() + +```c +#include + +int wolfSSH_SetChannelCloseCtx(WOLFSSH* ssh, void* ctx); +``` + +**説明** + +チャネルクローズコールバックに渡されるユーザーコンテキストを設定する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - チャネルクローズコールバックに渡すユーザーコンテキスト + +**戻り値** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` + +**関連項目** + +- `wolfSSH_GetChannelCloseCtx()` + + +### wolfSSH_GetChannelOpenCtx() + +```c +#include + +void* wolfSSH_GetChannelOpenCtx(WOLFSSH* ssh); +``` + +**説明** + +wolfSSH_SetChannelOpenCtx() によって以前に設定された、チャネルオープンコールバック用のユーザーコンテキストを返す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- チャネルオープンコンテキストへのポインター。設定されていない場合は `NULL` + +**関連項目** + +- `wolfSSH_SetChannelOpenCtx()` + + +### wolfSSH_GetChannelReqCtx() + +```c +#include + +void* wolfSSH_GetChannelReqCtx(WOLFSSH* ssh); +``` + +**説明** + +wolfSSH_SetChannelReqCtx() によって以前に設定された、チャネルリクエストコールバック用のユーザーコンテキストを返す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- チャネルリクエストコンテキストへのポインター。設定されていない場合は `NULL` + +**関連項目** + +- `wolfSSH_SetChannelReqCtx()` + + +### wolfSSH_GetChannelEofCtx() + +```c +#include + +void* wolfSSH_GetChannelEofCtx(WOLFSSH* ssh); +``` + +**説明** + +wolfSSH_SetChannelEofCtx() によって以前に設定された、チャネル EOF コールバック用のユーザーコンテキストを返す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- チャネル EOF コンテキストへのポインター。設定されていない場合は `NULL` + +**関連項目** + +- `wolfSSH_SetChannelEofCtx()` + + +### wolfSSH_GetChannelCloseCtx() + +```c +#include + +void* wolfSSH_GetChannelCloseCtx(WOLFSSH* ssh); +``` + +**説明** + +wolfSSH_SetChannelCloseCtx() によって以前に設定された、チャネルクローズコールバック用のユーザーコンテキストを返す。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- チャネルクローズコンテキストへのポインター。設定されていない場合は `NULL` + +**関連項目** + +- `wolfSSH_SetChannelCloseCtx()` + + +## チャネル関数 + +これらの関数は、SSH セッション上で多重化される個々のチャネルを表す `WOLFSSH_CHANNEL` オブジェクトに対して直接操作を行う。 + +### wolfSSH_ChannelGetSessionType() + +```c +#include + +WS_SessionType wolfSSH_ChannelGetSessionType(const WOLFSSH_CHANNEL* channel); +``` + +**説明** + +指定したチャネルの `WS_SessionType`(shell、exec、subsystem、terminal、または unknown)を返す。 + +**引数** + +- `channel` - チャネルへのポインター + +**戻り値** + +- チャネルの `WS_SessionType` + +**関連項目** + +- `wolfSSH_ChannelGetSessionCommand()` + + +### wolfSSH_ChannelGetSessionCommand() + +```c +#include + +const char* wolfSSH_ChannelGetSessionCommand(const WOLFSSH_CHANNEL* channel); +``` + +**説明** + +指定したチャネル上でピアが実行を要求したコマンド("exec" リクエストの場合)、またはサブシステム名("subsystem" リクエストの場合)を返す。記録された長さを得るには wolfSSH_ChannelGetSessionCommandSz() を使用する。 + +**引数** + +- `channel` - チャネルへのポインター + +**戻り値** + +- コマンド文字列へのポインター。存在しない場合は `NULL` + +**関連項目** + +- `wolfSSH_ChannelGetSessionType()` +- `wolfSSH_ChannelGetSessionCommandSz()` + +### wolfSSH_ChannelGetSessionCommandSz() + +```c +#include + +word32 wolfSSH_ChannelGetSessionCommandSz(const WOLFSSH_CHANNEL* channel); +``` + +**説明** + +wolfSSH_ChannelGetSessionCommand() が返すコマンドまたはサブシステム名の、記録された長さ(バイト単位)を返す。ピアが指定したコマンドには NUL バイトが含まれている可能性があるため、その違いが重要な場合は、この長さと文字列長を比較すること。 + +**引数** + +- `channel` - チャネルへのポインター + +**戻り値** + +- セッションコマンドの長さ。存在しない場合、または `channel` が NULL の場合は 0 + +**関連項目** + +- `wolfSSH_ChannelGetSessionCommand()` + +### wolfSSH_ChannelGetSessionGranted() + +```c +#include + +int wolfSSH_ChannelGetSessionGranted(const WOLFSSH_CHANNEL* channel); +``` + +**説明** + +チャネル上の shell、exec、subsystem のいずれかのリクエストに CHANNEL_SUCCESS で応答済みかどうかを報告する。セッションリクエストのコールバックからは、応答中のリクエストについてはこのフラグはまだクリアされて見えるため、そこでフラグがセットされていれば、それ以前のリクエストが許可されたことを意味する。 + +**引数** + +- `channel` - チャネルへのポインター + +**戻り値** + +- 1 - チャネル上のセッションリクエストが許可済み +- 0 - 許可されたものはない +- `WS_BAD_ARGUMENT` - `channel` が NULL + +**関連項目** + +- `wolfSSH_ChannelGetSessionType()` +- `wolfSSH_CTX_SetAppChannels()` +- `wolfSSH_ChannelCommandIsScp()` + +### wolfSSH_ChannelFree() + +```c +#include + +int wolfSSH_ChannelFree(WOLFSSH_CHANNEL* channel); +``` + +**説明** + +チャネルオブジェクトを解放し、そのセッションから削除する。 + +**引数** + +- `channel` - 解放するチャネルへのポインター + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_ChannelGetId() + +```c +#include + +int wolfSSH_ChannelGetId(WOLFSSH_CHANNEL* channel, word32* id, byte peer); +``` + +**説明** + +指定したチャネルの数値チャネル ID を取得する。`peer` に `WS_CHANNEL_ID_SELF` を指定すると自分側の ID、`WS_CHANNEL_ID_PEER` を指定するとピア側の ID が取得される。 + +**引数** + +- `channel` - チャネルへのポインター +- `id` - チャネル ID の出力先 +- `peer` - `WS_CHANNEL_ID_SELF` または `WS_CHANNEL_ID_PEER` + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +**関連項目** + +- `wolfSSH_ChannelFind()` + +### wolfSSH_ChannelFind() + +```c +#include + +WOLFSSH_CHANNEL* wolfSSH_ChannelFind(WOLFSSH* ssh, word32 id, byte peer); +``` + +**説明** + +指定した ID に一致するセッション上のチャネルを検索する。`peer` に `WS_CHANNEL_ID_SELF` を指定すると自分側の ID に、`WS_CHANNEL_ID_PEER` を指定するとピア側の ID に一致するものが検索される。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `id` - 検索するチャネル ID +- `peer` - `WS_CHANNEL_ID_SELF` または `WS_CHANNEL_ID_PEER` + +**戻り値** + +- 一致したチャネルへのポインター。見つからない場合は `NULL` + +**関連項目** + +- `wolfSSH_ChannelNext()` + +### wolfSSH_ChannelNext() + +```c +#include + +WOLFSSH_CHANNEL* wolfSSH_ChannelNext(WOLFSSH* ssh, WOLFSSH_CHANNEL* channel); +``` + +**説明** + +セッション上のチャネルを反復処理する。`channel` に `NULL` を渡すと最初のチャネルが取得され、あるチャネルを渡すとその次のチャネルが取得される。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `channel` - 現在のチャネル。反復を開始する場合は `NULL` + +**戻り値** + +- 次のチャネルへのポインター。リストの末尾に達した場合は `NULL` + +**関連項目** + +- `wolfSSH_ChannelFind()` + +### wolfSSH_ChannelRead() + +```c +#include + +int wolfSSH_ChannelRead(WOLFSSH_CHANNEL* channel, byte* buf, word32 bufSz); +``` + +**説明** + +指定したチャネルからバッファ済みのデータを最大 `bufSz` バイト読み込む。すでにバッファにあるデータのみを読み出し、バッファが空の場合は 0 を返す。トランスポートから受信することはなく、EOF を報告することもない。さらにデータを受信するには wolfSSH_worker() を呼び出す。 + +読み込みによって、wolfSSH_stream_read() と同様にチャネルウィンドウが加算され、ピアにウィンドウ調整が送信される。この関数は呼び出し時にセッションのエラー状態をクリアしないため、呼び出し後に wolfSSH_get_error() を確認すること。そこで `WS_WANT_WRITE` であればウィンドウ調整がキューに入っていることを意味し、その場合もバイト数は返される。 + +**引数** + +- `channel` - チャネルへのポインター +- `buf` - データを格納するバッファ +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 以上 - 読み込まれたバイト数 +- `WS_BAD_ARGUMENT` +- `WS_REKEYING` - 鍵交換が進行中である(wolfSSH_ChannelIdRead() は鍵交換中も読み込みを行う) +- `WS_INVALID_STATE_E` + +**関連項目** + +- `wolfSSH_ChannelSend()` +- `wolfSSH_ChannelReadExt()` +- `wolfSSH_ChannelIdRead()` + +### wolfSSH_ChannelReadExt() + +```c +#include + +int wolfSSH_ChannelReadExt(WOLFSSH_CHANNEL* channel, byte* buf, + word32 bufSz); +``` + +**説明** + +指定したチャネルからバッファ済みの拡張データ(stderr)を最大 `bufSz` バイト読み込む。wolfSSH_extended_data_read() と同じ読み出しの規約に従うが、指定したチャネルを読み込む。wolfSSH_ChannelRead() とは異なり、鍵交換中に `WS_REKEYING` で失敗することはない。データはすでにバッファにあり、読み込みによって生じるウィンドウの加算は鍵交換が完了するまで保留される。 + +**引数** + +- `channel` - チャネルへのポインター +- `buf` - データを格納するバッファ +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 以上 - 読み込まれたバイト数 +- `WS_BAD_ARGUMENT` - `channel` または `buf` が NULL、または `bufSz` が 0 +- `WS_INVALID_STATE_E` + +**関連項目** + +- `wolfSSH_ChannelSendExt()` +- `wolfSSH_ChannelIdReadExt()` +- `wolfSSH_extended_data_read()` + +### wolfSSH_ChannelSend() + +```c +#include + +int wolfSSH_ChannelSend(WOLFSSH_CHANNEL* channel, const byte* buf, + word32 bufSz); +``` + +**説明** + +指定したチャネル上で `bufSz` バイトを送信する。 + +**引数** + +- `channel` - チャネルへのポインター +- `buf` - 送信するバッファ +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 より大きい値 - 成功時に送信されたバイト数 +- `WS_BAD_ARGUMENT` +- `WS_CHANNEL_NOT_CONF` - ピアがまだチャネルのオープンを確認していない +- `WS_EOF` - こちら側がすでにチャネルで EOF を送信している +- `WS_REKEYING` - 鍵交換が進行中である +- `WS_WINDOW_FULL` - ピアのチャネルウィンドウがいっぱいである +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) + +**関連項目** + +- `wolfSSH_ChannelRead()` +- `wolfSSH_ChannelSendExt()` + +### wolfSSH_ChannelSendExt() + +```c +#include + +int wolfSSH_ChannelSendExt(WOLFSSH_CHANNEL* channel, + const byte* buf, word32 bufSz); +``` + +**説明** + +指定したチャネル上で、`bufSz` バイトを拡張データ(stderr データ型)として送信する。 + +**引数** + +- `channel` - チャネルへのポインター +- `buf` - 送信するバッファ +- `bufSz` - バッファのサイズ + +**戻り値** + +- 0 より大きい値 - 成功時に送信されたバイト数 +- `WS_BAD_ARGUMENT` +- `WS_CHANNEL_NOT_CONF` - ピアがまだチャネルのオープンを確認していない +- `WS_EOF` - こちら側がすでにチャネルで EOF を送信している +- `WS_REKEYING` - 鍵交換が進行中である +- `WS_WINDOW_FULL` - ピアのチャネルウィンドウがいっぱいである +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) + +**関連項目** + +- `wolfSSH_ChannelReadExt()` +- `wolfSSH_ChannelIdSendExt()` + +### wolfSSH_ChannelExit() + +```c +#include + +int wolfSSH_ChannelExit(WOLFSSH_CHANNEL* channel); +``` + +**説明** + +指定したチャネルを閉じ、SSH_MSG_CHANNEL_EOF に続いて SSH_MSG_CHANNEL_CLOSE をピアへ送信する。ピアのクローズが到着して wolfSSH_worker() が `WS_CHANNEL_CLOSED` を報告するまで、チャネルはセッションのチャネルリストに残り、チャネルポインターも有効なままである。wolfSSH_ChannelNext() でリストをたどる処理では、終了させたチャネルを読み飛ばして先に進む必要があり、リストの先頭を読み直してはならない。 + +`WS_WANT_WRITE` はチャネルの終了処理が完了していないことを意味する。クローズは EOF が送信された後にのみ作成されるため、結果が別のものになるまで再度呼び出すこと。再試行しても 2 つ目の EOF は送信されない。`WS_SUCCESS` は両方のメッセージがキューに入ったことを意味し、ピアに届いたことを意味するものではない。ピアが応答しない場合、チャネルはセッションの存続期間中リストに残る。 + +**引数** + +- `channel` - チャネルへのポインター + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_CHANNEL_NOT_CONF` - ピアがチャネルのオープンを確認していないため、宛先となるピアのチャネル ID がない +- `WS_WANT_WRITE` - 再度呼び出して終了処理を完了させること +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) + +**関連項目** + +- `wolfSSH_ChannelSendEof()` +- `wolfSSH_worker()` + +### wolfSSH_ChannelSendEof() + +```c +#include + +int wolfSSH_ChannelSendEof(WOLFSSH_CHANNEL* channel); +``` + +**説明** + +指定したチャネルで SSH_MSG_CHANNEL_EOF を送信し、送信方向を閉じて受信方向は開いたままにする(RFC 4254 セクション 5.3 のハーフクローズ)。以降、そのチャネルでのデータ送信(wolfSSH_ChannelSend()、wolfSSH_stream_send()、および拡張データ用の各関数)は `WS_EOF` で失敗するが、リクエスト、終了ステータス、終了処理のメッセージは引き続き送出される。読み込みは、ピアが自身の EOF を送信するかチャネルをクローズするまで可能である。この呼び出しはべき等であり、2 回目の呼び出しで 2 つ目の EOF が送出されることはない。 + +ライブラリは受信した EOF に対して自ら EOF を返すことはない。受信した EOF は `WS_EOF` として、またチャネル EOF コールバックを通じて報告され、この呼び出しまたは wolfSSH_stream_send_eof() で応答するかどうかはアプリケーションが判断する。wolfSSH_ChannelExit() と wolfSSH_shutdown() は、チャネルを終了させる際に自ら EOF を送信する。 + +**引数** + +- `channel` - チャネルへのポインター + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `channel` が NULL +- `WS_CHANNEL_NOT_CONF` - ピアがまだチャネルのオープンを確認していない +- `WS_REKEYING` - 鍵交換が進行中である +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) +- `WS_WANT_WRITE` などの送信処理のステータス + +**関連項目** + +- `wolfSSH_stream_send_eof()` +- `wolfSSH_ChannelGetEof()` +- `wolfSSH_ChannelExit()` + +### wolfSSH_ChannelGetEof() + +```c +#include + +int wolfSSH_ChannelGetEof(WOLFSSH_CHANNEL* channel); +``` + +**説明** + +指定したチャネル上でピアが EOF を送信済みかどうかを報告する。wolfSSH_worker() は受信した EOF を到着時に一度だけ `WS_EOF` として報告する。この呼び出しは永続的に確認できる手段である。 + +**引数** + +- `channel` - チャネルへのポインター + +**戻り値** + +- 1 - チャネルが EOF を受信済み +- 0 - チャネルが EOF を受信していない + +### wolfSSH_ChannelGetType() + +```c +#include + +const char* wolfSSH_ChannelGetType(const WOLFSSH_CHANNEL* channel); +``` + +**説明** + +指定したチャネルのチャネルタイプ文字列(例: "session")を返す。 + +**引数** + +- `channel` - チャネルへのポインター + +**戻り値** + +- チャネルタイプ文字列へのポインター。存在しない場合は `NULL` + +### wolfSSH_ChannelIsPty() + +```c +#include + +int wolfSSH_ChannelIsPty(const WOLFSSH_CHANNEL* channel); +``` + +**説明** + +指定したチャネルに疑似端末(PTY)が関連付けられているかどうかを報告する。 + +**引数** + +- `channel` - チャネルへのポインター + +**戻り値** + +- 1 - チャネルに PTY がある +- 0 - チャネルに PTY がない + + +## テスト関数 + + +### wolfSSH_GetStats() + + +```c +#include + +void wolfSSH_GetStats(WOLFSSH* ssh, word32* txCount, word32* rxCount, + word32* seq, word32* peerSeq); +``` + +**説明** + +セッションの転送統計情報を、指定した出力先ポインターに書き込む。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `txCount` - セッションで送信された総バイト数の出力先 +- `rxCount` - セッションで受信された総バイト数の出力先 +- `seq` - 送信パケットのシーケンス番号の出力先 +- `peerSeq` - ピアのパケットシーケンス番号の出力先 + +**戻り値** + +なし + +### wolfSSH_KDF() + + +```c +#include + +int wolfSSH_KDF(byte hashId, byte keyId, byte* key, word32 keySz, + const byte* k, word32 kSz, const byte* h, word32 hSz, + const byte* sessionId, word32 sessionIdSz); +``` + +**説明** + +SSH 鍵導出関数を実行する。この関数は、鍵材料の元となる `k`(ディフィー・ヘルマン共有秘密)と `h`(鍵交換時に生成される交換ハッシュ)から対称鍵を導出する。生成される鍵の種類は `keyId` によって選択される。この関数は主に、テストスイートが鍵導出に対して既知の解答によるテストを実行できるように公開されている。 + +`keyId` の値は以下の通り。 + +``` +A - initial IV, client to server +B - initial IV, server to client +C - encryption key, client to server +D - encryption key, server to client +E - integrity key, client to server +F - integrity key, server to client +``` + +**引数** + +- `hashId` - 鍵材料の導出に使用するハッシュタイプ(例: `WC_HASH_TYPE_SHA` や `WC_HASH_TYPE_SHA256`) +- `keyId` - どの鍵を導出するか(上記の A〜F) +- `key` - 導出された鍵の出力バッファ +- `keySz` - 出力鍵バッファのサイズ +- `k` - ディフィー・ヘルマン共有秘密 +- `kSz` - `k` のサイズ +- `h` - 交換ハッシュ +- `hSz` - `h` のサイズ +- `sessionId` - セッション識別子 +- `sessionIdSz` - セッション識別子のサイズ + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_CRYPTO_FAILED` + +### wolfSSH_ShowSizes() + +```c +#include + +void wolfSSH_ShowSizes(void); +``` + +**説明** + +wolfSSH の内部データ構造体のサイズを表示する。これは診断用の補助機能であり、リソースに制約のあるターゲットでのメモリ使用量の調整に役立つ。 + +**引数** + +なし + +**戻り値** + +なし + + +## セッション関数 + + + +### wolfSSH_GetSessionType() + + +```c +#include + +WS_SessionType wolfSSH_GetSessionType(const WOLFSSH* ssh); +``` **説明** -引数で指定されたエラーコードに対応するエラーの名前を返します。 +セッションのチャネルにおけるセッションタイプを返す。`WOLFSSH_SESSION_UNKNOWN`、`WOLFSSH_SESSION_SHELL`、`WOLFSSH_SESSION_EXEC`、`WOLFSSH_SESSION_SUBSYSTEM`、`WOLFSSH_SESSION_TERMINAL` のいずれか。 + +**引数** +- `ssh` - wolfSSH セッションへのポインター **戻り値** -**const char*** – エラー名文字列
+- セッションの `WS_SessionType` -**引数** +**関連項目** -**err** - エラーコード +- `wolfSSH_GetSessionCommand()` -``` +### wolfSSH_GetSessionCommand() + + +```c #include -const char* wolfSSH_ErrorToName(int err ); + +const char* wolfSSH_GetSessionCommand(const WOLFSSH* ssh); ``` -## I/O コールバック関数 +**説明** + +このセッションについてピアが実行を要求したコマンド("exec" リクエストの場合)、またはサブシステム名を、セッションのチャネルリストにある最初のチャネルから取得して返す。記録された長さを得るには wolfSSH_GetSessionCommandSz() を使用する。 +**引数** +- `ssh` - wolfSSH セッションへのポインター -### wolfSSH_SetIORecv() +**戻り値** + +- コマンド文字列へのポインター、存在しない場合は `NULL` + +**関連項目** + +- `wolfSSH_GetSessionType()` +- `wolfSSH_GetSessionCommandSz()` +### wolfSSH_GetSessionCommandSz() -**用法** +```c +#include + +word32 wolfSSH_GetSessionCommandSz(const WOLFSSH* ssh); +``` **説明** -入力データを受信する為の受信コールバック関数を登録します。 +wolfSSH_GetSessionCommand() が返すコマンドの記録された長さ(バイト単位)を、セッションのチャネルリストにある最初のチャネルから取得して返す。 + +**引数** +- `ssh` - wolfSSH セッションへのポインター **戻り値** -なし +- セッションコマンドの長さ。存在しない場合、または `ssh` が NULL の場合は 0 -**引数** +**関連項目** -**ctx** – wolfSSHコンテキスト
+- `wolfSSH_GetSessionCommand()` +- `wolfSSH_ChannelGetSessionCommandSz()` -**cb** – wolfSSHコンテキストに関連つけられる、受信コールバック関数 +### wolfSSH_SetChannelType() -``` +```c #include -void wolfSSH_SetIORecv(WOLFSSH_CTX* ctx , WS_CallbackIORecv cb ); -``` -### wolfSSH_SetIOSend() +int wolfSSH_SetChannelType(WOLFSSH* ssh, byte type, byte* name, + word32 nameSz); +``` +**説明** -**用法** +セッションのチャネルに対して、チャネルリクエストタイプ(shell、exec、subsystem など)と、それに関連付ける任意の名前を設定する。exec と subsystem はピアが必要とする名前文字列を伴うため、名前が利用可能でなければならない。名前を渡さない場合は以前の呼び出しで保存された名前が保持され、何も保存されていない場合は呼び出しが拒否される。shell と terminal は名前を取らず、保存されている名前を破棄する。拒否された呼び出しは、選択されたタイプを含め何も変更しない。 -**説明** +**引数** -送信データを送信するための送信コールバック関数を登録します。 +- `ssh` - wolfSSH セッションへのポインター +- `type` - チャネルリクエストタイプ +- `name` - exec または subsystem の場合のコマンド名またはサブシステム名、あるいは保存済みの名前を保持する場合は NULL +- `nameSz` - `name` の長さ **戻り値** -なし +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` が NULL、`type` が不明、サーバー側で exec が要求された、`name` が `WOLFSSH_MAX_CHN_NAMESZ` バイト以上、`name` なしで `nameSz` が指定された、または exec か subsystem で名前が指定されず保存もされていない +- `WS_MEMORY_E` - 名前を割り当てられない + +### wolfSSH_ChangeTerminalSize() + +```c +#include + +int wolfSSH_ChangeTerminalSize(WOLFSSH* ssh, word32 columns, + word32 rows, word32 widthPixels, word32 heightPixels); +``` + +**説明** + +ターミナル(ウィンドウ)サイズが変更されたことをピアに通知し、新しい寸法を送信する。 **引数** -**ctx** – wolfSSHコンテキスト
+- `ssh` - wolfSSH セッションへのポインター +- `columns` - 新しい幅(文字カラム数) +- `rows` - 新しい高さ(文字行数) +- `widthPixels` - 新しい幅(ピクセル数) +- `heightPixels` - 新しい高さ(ピクセル数) -**cb** – wolfSSHコンテキストに関連つけられる、送信コールバック関数。 +**戻り値** -``` -#include -void wolfSSH_SetIOSend(WOLFSSH_CTX* ctx , WS_CallbackIOSend cb ); -``` +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) -### wolfSSH_SetIOReadCtx() +**関連項目** + +- `wolfSSH_SetTerminalResizeCb()` + +### wolfSSH_SetTerminalResizeCb() +```c +#include -**用法** +void wolfSSH_SetTerminalResizeCb(WOLFSSH* ssh, WS_CallbackTerminalSize cb); +``` **説明** -受信コールバック関数に渡されるコンテキストを設定します +ピアがターミナルサイズの変更を報告した際に呼び出されるコールバックを登録する。 + +**引数** +- `ssh` - wolfSSH セッションへのポインター +- `cb` - ターミナルリサイズコールバック **戻り値** なし -**引数** +**関連項目** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `wolfSSH_SetTerminalResizeCtx()` -**ctx** – コンテキストへのポインター。受信コールバック関数に渡される +### wolfSSH_SetTerminalResizeCtx() -``` +```c #include -void wolfSSH_SetIOReadCtx(WOLFSSH* ssh , void* ctx ); -``` -### wolfSSH_SetIOWriteCtx() +void wolfSSH_SetTerminalResizeCtx(WOLFSSH* ssh, void* usrCtx); +``` +**説明** -**用法** +ターミナルリサイズコールバックに渡すユーザーコンテキストポインターを設定する。 -**説明** +**引数** -送信コールバック関数に渡されるコンテキストを設定します +- `ssh` - wolfSSH セッションへのポインター +- `usrCtx` - コールバックに渡すユーザーコンテキストポインター **戻り値** なし +### wolfSSH_GetExitStatus() + +```c +#include + +int wolfSSH_GetExitStatus(WOLFSSH* ssh); +``` + +**説明** + +セッションのコマンドについてピアが報告した終了ステータスを返す。 + **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `ssh` - wolfSSH セッションへのポインター + +**戻り値** -**ctx** – コンテキストへのポインター。送信コールバック関数に渡される +- ピアが報告した終了ステータス -``` +**関連項目** + +- `wolfSSH_SetExitStatus()` + +### wolfSSH_SetExitStatus() + +```c #include -void wolfSSH_SetIOWriteCtx(WOLFSSH* ssh , void* ctx ); + +int wolfSSH_SetExitStatus(WOLFSSH* ssh, word32 exitStatus); ``` -### wolfSSH_GetIOReadCtx() +**説明** + +セッションのコマンドについてピアに報告する終了ステータスを設定する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `exitStatus` - 報告する終了ステータス + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +**関連項目** +- `wolfSSH_GetExitStatus()` -**用法** +### wolfSSH_DoModes() + +```c +#include + +int wolfSSH_DoModes(const byte* modes, word32 modesSz, int fd); +``` **説明** -WOLFSSHオブジェクトのioReadCtxメンバーを返します。 +`modes` に含まれる SSH エンコード済みのターミナルモードを、ファイルディスクリプタ `fd` が参照するターミナルに適用する。 +**引数** + +- `modes` - SSH エンコード済みターミナルモードのバッファ +- `modesSz` - modes バッファの長さ +- `fd` - 設定対象ターミナルのファイルディスクリプタ **戻り値** -**void*** - WOLFSSHオブジェクトのioReadCtxメンバーへのポインター +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` -**引数** +### wolfSSH_ConvertConsole() -**ssh** – WOLFSSHオブジェクトへのポインター +**利用可能性** -``` +Windows ビルド(`USE_WINDOWS_API`)でのみ利用可能。 + +```c #include -void* wolfSSH_GetIOReadCtx(WOLFSSH* ssh ); + +int wolfSSH_ConvertConsole(WOLFSSH* ssh, WOLFSSH_HANDLE handle, + byte* buf, word32 bufSz); ``` -### wolfSSH_GetIOWriteCtx() +**説明** + +Windows コンソールハンドルから読み取ったコンソールデータを処理し、SSH ストリーム用に変換する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `handle` - Windows コンソールハンドル +- `buf` - 変換対象のコンソールデータバッファ +- `bufSz` - バッファの長さ +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_SetKeyingCompletionCb() + +```c +#include -**用法** +void wolfSSH_SetKeyingCompletionCb(WOLFSSH_CTX* ctx, + WS_CallbackKeyingCompletion cb); +``` **説明** -WOLFSSHオブジェクトのioWriteCtxメンバーを返します。 +鍵交換(初回またはリキー)が完了した際に呼び出されるコールバックを登録する。 + +**引数** +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - キーイング完了コールバック **戻り値** -**void*** – WOLFSSHオブジェクトのioWriteCtxメンバーへのポインター +なし -**引数** +**関連項目** -**ssh** – WOLFSSHオブジェクトへのポインター +- `wolfSSH_SetKeyingCompletionCbCtx()` -``` +### wolfSSH_SetKeyingCompletionCbCtx() + +```c #include -void* wolfSSH_GetIOWriteCtx(WOLFSSH* ssh); + +void wolfSSH_SetKeyingCompletionCbCtx(WOLFSSH* ssh, void* ctx); ``` -## ユーザー認証 +**説明** + +キーイング完了コールバックに渡すユーザーコンテキストポインターを設定する。 +**引数** +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - コールバックに渡すユーザーコンテキストポインター -### wolfSSH_SetUserAuth() +**戻り値** + +なし + +### wolfSSH_RealPath() +```c +#include -**用法** +int wolfSSH_RealPath(const char* defaultPath, char* in, + char* out, word32 outSz); +``` **説明** +`defaultPath` を基準として、パス `in` を解決し、正規化された絶対パスを `out` に書き込む。 -現在のWOLFSSL_CTXオブジェクトに対してユーザー認証コールバック関数を登録します。 +**引数** +- `defaultPath` - 相対パスの `in` を解決する際の基準パス +- `in` - 解決対象のパス +- `out` - 解決されたパスを書き込むバッファ +- `outSz` - 出力バッファのサイズ **戻り値** -なし +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` -**引数** +## ポートフォワーディング関数 -**ctx** – WOLFSSH_CTXオブジェクトへのポインター
-**cb** – ユーザー認証コールバック関数 -``` +本セクションのすべての関数は、wolfSSH がポートフォワーディングサポート(`WOLFSSH_FWD`、`./configure --enable-fwd`)付きでビルドされていることを必要とする。 + +### wolfSSH_ChannelFwdNewLocal() + +```c #include -void wolfSSH_SetUserAuth(WOLFSSH_CTX* ctx, WS_CallbackUserAuth cb) + +WOLFSSH_CHANNEL* wolfSSH_ChannelFwdNewLocal(WOLFSSH* ssh, + const char* host, word32 hostPort, + const char* origin, word32 originPort); ``` -### wolfSSH_SetUserAuthCtx() +**説明** + +セッション上にローカル TCP/IP フォワーディングチャネルを設定する。セッションが接続および認証されると、接続は `hostPort` ポートの `host` へフォワードされ、送信元アドレス `origin` とポート `originPort` がタグ付けされる。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `host` - 転送先ホストアドレス +- `hostPort` - 転送先ポート +- `origin` - 送信元接続アドレス +- `originPort` - 送信元接続ポート +**戻り値** + +- 新しいチャネルへのポインター、エラー時は `NULL` + +**関連項目** + +- `wolfSSH_ChannelFwdNewRemote()` + +### wolfSSH_ChannelFwdNewRemote() + +```c +#include -**用法** +WOLFSSH_CHANNEL* wolfSSH_ChannelFwdNewRemote(WOLFSSH* ssh, + const char* host, word32 hostPort, + const char* origin, word32 originPort); +``` **説明** -ユーザー認証コールバック関数に渡されるコンテキストを登録します。 +セッション上にリモート TCP/IP フォワーディングチャネルを設定し、ピアに対して `hostPort` ポートの `host` へ接続をフォワードするよう要求する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `host` - 転送先ホストアドレス +- `hostPort` - 転送先ポート +- `origin` - 送信元接続アドレス +- `originPort` - 送信元接続ポート **戻り値** -なし +- 新しいチャネルへのポインター、エラー時は `NULL` -**引数** +**関連項目** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `wolfSSH_ChannelFwdNewLocal()` -**userAuthCtx** – ユーザー認証コールバック関数へ渡すコンテキスト +### wolfSSH_CTX_SetFwdCb() -``` +```c #include -void wolfSSH_SetUserAuthCtx(WOLFSSH* ssh , void* userAuthCtx) + +int wolfSSH_CTX_SetFwdCb(WOLFSSH_CTX* ctx, + WS_CallbackFwd fwdCb, WS_CallbackFwdIO fwdIoCb); ``` -### wolfSSH_GetUserAuthCtx() +**説明** + +コンテキストに対して、ポートフォワーディングのセットアップ/クリーンアップコールバック(`fwdCb`)を登録する。`fwdCb` が登録されていない場合、ピアからのフォワーディングチャネルのオープン("direct-tcpip" と "forwarded-tcpip")は拒否される。コールバックが受け取る各 `WOLFSSH_FWD_LOCAL_SETUP` には、後で対応する `WOLFSSH_FWD_LOCAL_CLEANUP` が続く。 +```c +typedef int (*WS_CallbackFwd)(WS_FwdCbAction action, void* fwdCbCtx, + const char* address, word32 port); +``` -**用法** +コールバックの戻り値のうち `WS_FWD_PORT_CHECK`(1024)未満のものは `WS_FwdCbError` ステータスであり、`WS_FWD_SUCCESS` が成功を意味する。ポート 0 を指定した `WOLFSSH_FWD_REMOTE_SETUP` 要求の場合、コールバックは代わりに割り当てた非特権ポート(`WS_FWD_PORT_CHECK` 以上)を返し、サーバーはそれをピアに報告する。拒否されたポート 0 のセットアップには、セットアップが成功を返していても `WOLFSSH_FWD_REMOTE_CLEANUP` が送られる。クライアントは、コールバックがどう処理するかにかかわらず、"tcpip-forward" と "cancel-tcpip-forward" の要求に失敗で応答する。 -**説明** +フォワーディング I/O コールバック `fwdIoCb` は予約済みである。保存はされるが、フォワーディングされたデータはチャネル API を通じて転送されるため、ライブラリ内でこれを呼び出す箇所はない。既存のコードが引き続きコンパイルできるようにこの引数は残されている。NULL を渡すこと。 + +**引数** -ユーザー認証コールバック関数に渡されるコンテキストを返します。 +- `ctx` - wolfSSH コンテキストへのポインター +- `fwdCb` - フォワーディングのセットアップ/クリーンアップコールバック +- `fwdIoCb` - 予約済みのフォワーディング I/O コールバック(未使用) **戻り値** -**void*** – ユーザー認証コールバック関数へ渡すコンテキスト
+- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` -**NULL** – ssh引数がNULLの場合 +**関連項目** -**引数** +- `wolfSSH_SetFwdCbCtx()` -**ssh** – pointer to WOLFSSH object +### wolfSSH_SetFwdCbCtx() -``` +```c #include -void* wolfSSH_GetUserAuthCtx(WOLFSSH* ssh ) + +int wolfSSH_SetFwdCbCtx(WOLFSSH* ssh, void* ctx); ``` -## ユーザー名設定機能 +**説明** + +ポートフォワーディングコールバックに渡すユーザーコンテキストポインターを設定する。 +**引数** +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - フォワーディングコールバックに渡すユーザーコンテキストポインター -### wolfSSH_SetUsername() +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_ChannelFwdNew() +```c +#include -**用法** +WOLFSSH_CHANNEL* wolfSSH_ChannelFwdNew(WOLFSSH* ssh, + const char* host, word32 hostPort, + const char* origin, word32 originPort); +``` **説明** -SSHコネクションに必要なユーザー名を設定します。 +非推奨。`wolfSSH_ChannelFwdNewLocal()` を使用すること。この関数は後方互換性のために維持されており、内部でそちらへ処理を転送する。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `host` - 転送先ホストアドレス +- `hostPort` - 転送先ポート +- `origin` - 送信元接続アドレス +- `originPort` - 送信元接続ポート **戻り値** -WS_BAD_ARGUMENT
+- 新しいチャネルへのポインター、エラー時は `NULL` + +**関連項目** + +- `wolfSSH_ChannelFwdNewLocal()` + +### wolfSSH_ChannelSetFwdFd() + +```c +#include + +int wolfSSH_ChannelSetFwdFd(WOLFSSH_CHANNEL* channel, int fwdFd); +``` -WS_SUCCESS
+**説明** -WS_MEMORY_E
+非推奨。フォワーディングチャネルにフォワーディング用ファイルディスクリプタを関連付ける。 **引数** -**ssh** - WOLFSSHオブジェクトへのポインター
+- `channel` - フォワーディングチャネルへのポインター +- `fwdFd` - フォワーディング用ファイルディスクリプタ -**username** - ユーザー名文字列 +**戻り値** -``` +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_ChannelGetFwdFd() + +```c #include -int wolfSSH_setUsername(WOLFSSH* ssh , const char* username); + +int wolfSSH_ChannelGetFwdFd(const WOLFSSH_CHANNEL* channel); ``` -## 接続機能 +**説明** + +非推奨。フォワーディングチャネルに関連付けられたフォワーディング用ファイルディスクリプタを返す。 -### wolfSSH_accept() +**引数** + +- `channel` - フォワーディングチャネルへのポインター +**戻り値** +- フォワーディング用ファイルディスクリプタ、または負のエラーコード -**用法** +### wolfSSH_FwdRemoteSetup() -**説明** +```c +#include + +int wolfSSH_FwdRemoteSetup(WOLFSSH* ssh, const char* bindAddr, + word32 bindPort, int wantReply); +``` -wolfssh_acceptはサーバー側で呼び出され、SSHクライアントがSSHハンドシェイクを開始するのを待ちます。 +**説明** -wolfssl_accept()は、ブロッキングI/OノンブロッキングI/Oの両方で機能します。使用しているI/Oが非ブロッキングである場合、wolfSSH_accept()は、ハンドシェークが完了できなかった場合は即戻ります。この場合、wolfssh_get_error()を呼び出すと、**WS_WANT_READ** または**WS_WANT_WRITE**のいずれかが返されます。 +クライアント専用。"tcpip-forward" グローバルリクエスト(RFC 4254 セクション 7.1)を送信して、サーバーに `bindAddr`:`bindPort` で待ち受けを行い、受け付けた接続を "forwarded-tcpip" チャネルとしてトンネルで戻すよう要求し、そのフォワードをセッションに登録する。`bindPort` が 0 の場合はサーバーにポートの選択を求める。バインドされたポートが示されるのは応答の中だけであるため、この場合は `wantReply` が必要である。 +クライアントは、セッションの開始時点から、登録していないバインドを指定した "forwarded-tcpip" チャネルのオープンをすべて拒否する(RFC 4254 セクション 7.2)。何も登録していないセッションはそれらをすべて拒否する。`bindAddr` が ""、"*"、"0.0.0.0"、または IPv6 の任意アドレスの場合はポートのみで照合する。それ以外のアドレスは、サーバーがオープン時に報告するものと一致しなければならない。サーバーが返してくる表記か、ワイルドカードを登録するか、wolfSSH_SetFwdRemoteMatch() で照合を緩和すること。 -この場合呼び出し元は、読み取るべきデータを受信してwolfSSHが中断されたところからピックアップできるように、wolfSSH_acceptへの呼び出しを繰り返す必要があります。非ブロッキングソケットを使用する場合、何も実行する必要はありませんが、select()を使用して必要な条件を確認できます。 +1 つの `bindAddr`:`bindPort` は、何度要求されても 1 つの登録であり、1 回のキャンセルで取り消される。複数の要求が 1 つのバインドを指定した場合は、最後に送信されたものが適用される。 +`WS_WANT_WRITE` は、要求がキューに入って次のフラッシュで送出され、フォワードが登録されたことを意味する。要求がピアに届いた後に報告されたエラーの場合も同様であり、その場合の再試行は無害な繰り返しとなる。要求が送出されなかったエラーの場合にのみ、何も登録されない。 -使用しているI/Oがブロッキングの場合、wolfSSH_accept()は、ハンドシェークが終了したか、エラーが発生した場合にのみ戻ります。 +**引数** +- `ssh` - wolfSSH セッションへのポインター +- `bindAddr` - サーバーが待ち受けるアドレス +- `bindPort` - サーバーが待ち受けるポート、またはサーバーに選択させる場合は 0 +- `wantReply` - サーバーに応答を求める場合は 1、それ以外は 0 **戻り値** -**WS_SUCCESS** - 成功
+- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` または `bindAddr` が NULL、`bindPort` が 65535 を超える、`wantReply` が 0 でも 1 でもない、`wantReply` なしで `bindPort` が 0、またはセッションがクライアントでない +- `WS_REKEYING` - 鍵交換が進行中である +- `WS_RESOURCE_E` - 応答待ちの要求が多すぎる +- `WS_MEMORY_E` +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) +- `WS_WANT_WRITE` などの送信処理のステータス -**WS_BAD_ARGUMENT** - 引数がNULL
+**関連項目** -**WS_FATAL_ERROR** – エラーが発生した。wolfSSH_get_error()を呼び出して詳細を取得すべき +- `wolfSSH_FwdRemoteCancel()` +- `wolfSSH_SetFwdRemoteMatch()` +- `wolfSSH_CTX_SetFwdCb()` -**引数** +### wolfSSH_FwdRemoteCancel() -**ssh** – WOLFSSHオブジェクトへのポインター
+```c +#include +int wolfSSH_FwdRemoteCancel(WOLFSSH* ssh, const char* bindAddr, + word32 bindPort, int wantReply); ``` + +**説明** + +クライアント専用。"cancel-tcpip-forward" グローバルリクエストを送信し、wolfSSH_FwdRemoteSetup() で設定したフォワードを解除する。`bindPort` はサーバーがバインドしたポートであり、ポート 0 で要求した後は 0 ではなくサーバーが報告したポートである。そのようなフォワードは、その応答が到着する前にはキャンセルできない。 + +キャンセルが送出されると同時に、フォワードは受信する "forwarded-tcpip" のオープンと照合されなくなるため、それと競合するオープンは拒否される。`wantReply` がない場合はそれで完了する。`wantReply` がある場合、登録はサーバーが応答するまで保持される。拒否された場合はリスナーが残ったままとなってフォワードは元に戻り、確認された場合は破棄される。複数のキャンセルが未処理の場合、フォワードが元に戻るにはそのすべてが拒否される必要がある。キャンセルが未処理の間に再度登録すると、新しい要求が送出された時点でフォワードが元に戻る。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `bindAddr` - フォワードを登録したときのアドレス +- `bindPort` - サーバーがバインドしたポート +- `wantReply` - サーバーに応答を求める場合は 1、それ以外は 0 + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` または `bindAddr` が NULL、`bindPort` が 0 または 65535 を超える、`wantReply` が 0 でも 1 でもない、またはセッションがクライアントでない +- `WS_REKEYING` - 鍵交換が進行中である +- `WS_RESOURCE_E` - 応答待ちの要求が多すぎる +- `WS_MEMORY_E` +- `WS_FATAL_ERROR` - セッションが切断された(wolfSSH_get_error() は `WS_DISCONNECT` を報告する) +- `WS_WANT_WRITE` などの送信処理のステータス + +**関連項目** + +- `wolfSSH_FwdRemoteSetup()` + +### wolfSSH_SetFwdRemoteMatch() + +```c #include -int wolfSSH_accept(WOLFSSH* ssh); + +int wolfSSH_SetFwdRemoteMatch(WOLFSSH* ssh, byte match); ``` -**関連項目** +**説明** + +受信する "forwarded-tcpip" チャネルのオープンが、wolfSSH_FwdRemoteSetup() で登録したフォワードとどの程度厳密に一致しなければならないかを設定する。クライアントはセッションの開始時点からこれらのオープンを確認するため、ピアがオープンを送信できるようになる前に設定すること。 -wolfSSH_stream_read() +```c +enum WS_FwdRemoteMatch { + WOLFSSH_FWD_MATCH_STRICT = 0, /* bind and port, the default */ + WOLFSSH_FWD_MATCH_PORT = 1, /* port alone, the bind is not compared */ + WOLFSSH_FWD_MATCH_OFF = 2 /* accept any open, matching nothing */ +}; +``` +`WOLFSSH_FWD_MATCH_STRICT` はデフォルトであり、RFC 4254 セクション 7.2 が求める動作である。`WOLFSSH_FWD_MATCH_PORT` は、返してくるバインドアドレスを書き換えるがポートは保持するピア向けである。`WOLFSSH_FWD_MATCH_OFF` は、このチェックが導入される前の wolfSSH と同様に、あらゆる "forwarded-tcpip" のオープンを受け入れ、チャネルオープンコールバックだけがポリシーチェックとなる。 -### wolfSSH_connect() +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `match` - `WS_FwdRemoteMatch` の値 +**戻り値** -**用法** +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` が NULL、または `match` が既知の設定ではない -**説明** +**関連項目** + +- `wolfSSH_FwdRemoteSetup()` +- `wolfSSH_CTX_SetChannelOpenCb()` + + +## 鍵ロード関数 -この関数はクライアント側で呼び出されSSHハンドシェークをサーバーに対して開始します。 -この関数が呼び出される時点では下層の通信チャネルは接続が完了している必要があります。 -wolfSSH_connect()関数はブロッキングとノンブロッキングI/Oの両方で動作できます。ノンブロッキングI/Oの場合にはハンドシェークが完了できなかった場合は即戻ります。この場合、wolfssh_get_error()を呼び出すと、**WS_WANT_READ** または**WS_WANT_WRITE**のいずれかが返されます。 +### wolfSSH_ReadKey_buffer() + +```c +#include + +int wolfSSH_ReadKey_buffer(const byte* in, word32 inSz, + int format, byte** out, word32* outSz, + const byte** outType, word32* outTypeSz, + void* heap); +``` -この場合呼び出し元は、読み取るべきデータを受信してwolfSSHが中断されたところからピックアップできるように、wolfSSH_connectへの呼び出しを繰り返す必要があります。非ブロッキングソケットを使用する場合、何も実行する必要はありませんが、select()を使用して必要な条件を確認できます。 +**説明** +サイズ `inSz` のバッファ `in` から鍵を読み込み、`format` 型の鍵としてデコードする。`format` には `WOLFSSH_FORMAT_ASN1`、`WOLFSSH_FORMAT_PEM`、`WOLFSSH_FORMAT_SSH`、または `WOLFSSH_FORMAT_OPENSSH` を指定できる。デコードされた鍵は、`wolfSSH_CTX_UsePrivateKey_buffer()` で利用できる形式で、`out` が指すバッファに格納され、そのサイズが `outSz` に格納される。`out` が NULL の場合、`heap` を使って鍵用のバッファが確保される。鍵種別文字列は `outType` に格納され、その長さが `outTypeSz` に格納される。 -使用しているI/Oがブロッキングの場合、wolfSSH_accept()は、ハンドシェークが終了したか、エラーが発生した場合にのみ戻ります。 +**引数** +- `in` - エンコードされた鍵を含むバッファ +- `inSz` - 入力バッファのサイズ +- `format` - 入力鍵のエンコーディング +- `out` - デコードされた鍵の出力バッファ(NULL の場合は `heap` から確保) +- `outSz` - デコードされた鍵サイズの出力先 +- `outType` - 鍵種別文字列の出力先 +- `outTypeSz` - 鍵種別文字列の長さの出力先 +- `heap` - `out` が NULL の場合に確保で使用されるヒープ **戻り値** -**WS_SUCCESS** - 接続に成功
-**WS_BAD_ARGUMENT** - 引数がNULL
- -**WS_FATAL_ERROR** - エラーが発生した。wolfSSH_get_error()を呼び出して詳細を取得すべき +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` +- `WS_BUFFER_E` +- `WS_PARSE_E` +- `WS_UNIMPLEMENTED_E` +- `WS_RSA_E` +- `WS_ECC_E` +- `WS_KEY_AUTH_MAGIC_E` +- `WS_KEY_FORMAT_E` +- `WS_KEY_CHECK_VAL_E` +**関連項目** -**引数** +- `wolfSSH_ReadKey_file()` -**ssh** - WOLFSSHオブジェクトへのポインター
+### wolfSSH_ReadKey_buffer_ex() -``` +```c #include -int wolfSSH_connect(WOLFSSH* ssh); -``` -### wolfSSH_shutdown() +int wolfSSH_ReadKey_buffer_ex(const byte* in, word32 inSz, int format, + byte** out, word32* outSz, const byte** outType, word32* outTypeSz, + int isPrivate, void* heap); +``` +**説明** -**用法** +wolfSSH_ReadKey_buffer() と同様だが、バッファが秘密鍵か公開鍵かを推測するのではなく、明示的な `isPrivate` フラグで指定する。 -**説明** +**引数** -SSHチャネルの接続を終了してクローズします +- `in` - エンコードされた鍵を含むバッファ +- `inSz` - 入力バッファのサイズ +- `format` - 入力鍵のエンコーディング +- `out` - デコードされた鍵の出力バッファ(NULL の場合は `heap` から確保) +- `outSz` - デコードされた鍵サイズの出力先 +- `outType` - 鍵種別文字列の出力先 +- `outTypeSz` - 鍵種別文字列の長さの出力先 +- `isPrivate` - 鍵が秘密鍵の場合は非ゼロ、公開鍵の場合は 0 +- `heap` - `out` が NULL の場合に確保で使用されるヒープ **戻り値** -**WS_BAD_ARGUMENT** - 引数がNULL
+- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` +- `WS_BUFFER_E` +- `WS_PARSE_E` +- `WS_UNIMPLEMENTED_E` -**WS_SUCCES** - 正常にシャットダウンが成功した +**関連項目** -**引数** +- `wolfSSH_ReadKey_buffer()` -**ssh** - WOLFSSHオブジェクトへのポインター
+### wolfSSH_ReadPublicKey_buffer() -``` +```c #include -int wolfSSH_shutdown(WOLFSSH* ssh); + +int wolfSSH_ReadPublicKey_buffer(const byte* in, word32 inSz, int format, + byte** out, word32* outSz, const byte** outType, word32* outTypeSz, + void* heap); ``` -### wolfSSH_stream_read() +**説明** +バッファ `in` から公開鍵を読み込みデコードする。wolfSSH_ReadKey_buffer() と同様に動作するが、公開鍵専用である。 +**引数** -**用法** +- `in` - エンコードされた公開鍵を含むバッファ +- `inSz` - 入力バッファのサイズ +- `format` - 入力鍵のエンコーディング +- `out` - デコードされた鍵の出力バッファ(NULL の場合は `heap` から確保) +- `outSz` - デコードされた鍵サイズの出力先 +- `outType` - 鍵種別文字列の出力先 +- `outTypeSz` - 鍵種別文字列の長さの出力先 +- `heap` - `out` が NULL の場合に確保で使用されるヒープ -**説明** +**戻り値** -wolfSSH_stream_read()は内部のバッファから復号済みデータを**bufSz**で指定されたバイト数まで読みだします。読み込まれたデータはバッファから取り除かれます。 +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` +- `WS_BUFFER_E` +- `WS_PARSE_E` +- `WS_UNIMPLEMENTED_E` -wolfSSH_stream_read()はブロッキングとノンブロッキングI/Oの両方で動作できます。ノンブロッキングI/Oの場合にはハンドシェークが完了できなかった場合は即戻ります。この場合、wolfssh_get_error()を呼び出すと、**WS_WANT_READ** または**WS_WANT_WRITE**のいずれかが返されます。 +**関連項目** -この場合呼び出し元は、読み取るべきデータを受信してwolfSSHが中断されたところからピックアップできるように、wolfSSH_stream_read()の呼び出しを繰り返す必要があります。非ブロッキングI/Oが使用されている場合、何も実行する必要はありませんが、select()を使用して必要な条件を確認できます。 +- `wolfSSH_ReadKey_buffer()` -ブロッキングI/Oが使用されている場合は、wolfSSH_stream_read()は、データがIsAbaibleまたはエラーが発生した場合にのみ戻ります。 -**戻り値** +### wolfSSH_ReadKey_file() -**>0** – 読み取りに成功したバイト数
+```c +#include -**0** – クリーンコネクションシャットダウンかソケットエラー
+int wolfSSH_ReadKey_file(const char* name, + byte** out, word32* outSz, + const byte** outType, word32* outTypeSz, + byte* isPrivate, void* heap); +``` -**WS_BAD_ARGUMENT** – 引数の一つがNULL
+**説明** -**WS_EOF** – ストリームの終端に到達
+ファイル `name` から鍵を読み込む。フォーマットはファイル内容から推測される。鍵バッファ `out`、鍵種別 `outType`、およびそれぞれのサイズは wolfSSH_ReadKey_buffer() と同様に生成される。`isPrivate` フラグは、鍵が秘密鍵であるかどうかを示すよう設定される。確保処理には指定された `heap` が使用される。 -**WS_FATAL_ERROR** – エラーが発生。**wolfSSH_get_error()** を呼び出して詳細を取得すべき
+**引数** -**WS_REKEYING** - リキーイング処理中。 wolfSSH_worker()を呼び出して完了させること +- `name` - 鍵ファイルへのパス +- `out` - デコードされた鍵の出力バッファ(NULL の場合は `heap` から確保) +- `outSz` - デコードされた鍵サイズの出力先 +- `outType` - 鍵種別文字列の出力先 +- `outTypeSz` - 鍵種別文字列の長さの出力先 +- `isPrivate` - 鍵が秘密鍵の場合に非ゼロが設定される出力 +- `heap` - `out` が NULL の場合に確保で使用されるヒープ -**引数** +**戻り値** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_BAD_FILE_E` +- `WS_MEMORY_E` +- `WS_BUFFER_E` +- `WS_PARSE_E` +- `WS_UNIMPLEMENTED_E` +- `WS_RSA_E` +- `WS_ECC_E` +- `WS_KEY_AUTH_MAGIC_E` +- `WS_KEY_FORMAT_E` +- `WS_KEY_CHECK_VAL_E` -**buf** – wolfSSH_stream_read()が読みだしたデータを格納するバッファへのポインター
+**関連項目** -**bufSz** – バッファサイズ +- `wolfSSH_ReadKey_buffer()` -``` -#include -int wolfSSH_stream_read(WOLFSSH* ssh, byte* buf, word32 bufSz); -``` +### wolfSSH_ReadCert_buffer() -**関連項目** +**利用可能性** -wolfSSH_accept()
+`WOLFSSH_CERTS`(X.509 証明書)または `WOLFSSH_OSSH_CERTS`(OpenSSH 証明書)が必要。 -wolfSSH_stream_send() +```c +#include +int wolfSSH_ReadCert_buffer(const byte* in, word32 inSz, + byte** out, word32* outSz, + const byte** outType, word32* outTypeSz, + byte* flavor, void* heap); +``` -### wolfSSH_stream_send() +**説明** +バッファ `in` から証明書をデコードする。形式は内容から判定され、DER または PEM の X.509 証明書(`WOLFSSH_CERTS` ビルドの場合)、あるいは OpenSSH 証明書の行(`WOLFSSH_OSSH_CERTS` ビルドの場合)を扱う。PEM 証明書が複数ある場合は、最初の 1 つだけが読み込まれる。成功時、`out` には `heap` から新たに割り当てられたバッファが返され、DER 証明書または OpenSSH 証明書の blob が格納される。このバッファは呼び出し側が解放する。`outType` には証明書の SSH アルゴリズム名が返され、`flavor` には見つかった証明書の種類が返される。 +```c +enum WS_CertFlavors { + WOLFSSH_CERT_FLAVOR_UNKNOWN, + WOLFSSH_CERT_FLAVOR_X509, + WOLFSSH_CERT_FLAVOR_OSSH +}; +``` -**用法** +X.509 証明書は wolfSSH_CTX_UseCert_buffer() と wolfSSH_CTX_AddRootCert_buffer() が受け付ける形式である。失敗時には、すべての出力引数がクリアされる。 -**説明** +**引数** -wolfSSH_stream_send()はバッファで与えたデータを**bufSz**で指定されたバイト数までSSHストリームデータバッファに書き込みます。 +- `in` - 証明書を含むバッファ +- `inSz` - 入力バッファのサイズ +- `out` - 新たに割り当てられたデコード済み証明書の出力先 +- `outSz` - デコード済み証明書のサイズの出力先 +- `outType` - アルゴリズム名文字列の出力先 +- `outTypeSz` - アルゴリズム名文字列の長さの出力先 +- `flavor` - `WS_CertFlavors` 値の出力先 +- `heap` - 割り当てに使用するヒープ -wolfSSH_stream_send()はブロッキングとノンブロッキングI/Oの両方で動作できます。ノンブロッキングI/Oの場合にはハンドシェークが完了できなかった場合は即戻ります。この場合、wolfssh_get_error()を呼び出すと、**WS_WANT_READ** または**WS_WANT_WRITE**のいずれかが返されます。 +**戻り値** -この場合呼び出し元は、データの書き込みがペンディングされ、wolfSSHが中断されたところから書き込みを再開できるように、wolfSSH_stream_send()の呼び出しを繰り返す必要があります。非ブロッキングソケットを使用する場合、何も実行する必要はありませんが、select()を使用して必要な条件を確認できます。 +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `in` または出力ポインターが NULL、または `inSz` が 0 +- `WS_BAD_FILETYPE_E` - 内容が認識できる証明書の形式ではない +- `WS_PARSE_E` - 証明書の本体をデコードできない +- `WS_MEMORY_E` +- 証明書の識別によるその他のエラー -ブロッキングI/Oが使用されている場合は、wolfSSH_stream_send()は、データが送信されたときかエラーが発生した時のみ戻ります。 +**関連項目** -WS_WANT_READ またはWS_WANT_WRITEのいずれもかえされていない場合(すなわち**WS_REKEYING**が返された場合)は、内部処理が終了するまでwolfSSH_worker()を呼び出し続ける必要があります。 +- `wolfSSH_ReadCert_file()` +- `wolfSSH_ReadKey_buffer()` +### wolfSSH_ReadCert_file() -**戻り値** +**利用可能性** -**>0** – SSHストリームバッファに書き込んだバイト数
+`WOLFSSH_CERTS` または `WOLFSSH_OSSH_CERTS`、およびファイルシステムのサポートが必要(`NO_FILESYSTEM` または `WOLFSSH_USER_FILESYSTEM` では利用できない)。 -**0** – クリーンコネクションシャットダウンかソケットエラー。 **wolfSSH_get_error()** を呼び出して詳細を取得すること
+```c +#include -**WS_FATAL_ERROR** – エラーが発生。**wolfSSH_get_error()** を呼び出して詳細を取得すること
+int wolfSSH_ReadCert_file(const char* name, + byte** out, word32* outSz, + const byte** outType, word32* outTypeSz, + byte* flavor, void* heap); +``` -**WS_BAD_ARGUMENT** - 引数の一つがNULL
+**説明** -**WS_REKEYING** - リキーイング処理中。 wolfSSH_worker()を呼び出して完了させること +ファイル `name` を読み込み、wolfSSH_ReadCert_buffer() と同様にその中の証明書をデコードする。失敗時には、すべての出力引数がクリアされる。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `name` - 証明書ファイルへのパス +- `out` - 新たに割り当てられたデコード済み証明書の出力先 +- `outSz` - デコード済み証明書のサイズの出力先 +- `outType` - アルゴリズム名文字列の出力先 +- `outTypeSz` - アルゴリズム名文字列の長さの出力先 +- `flavor` - `WS_CertFlavors` 値の出力先 +- `heap` - 割り当てに使用するヒープ -**buf** – wolfSSH_stream_send()が送信するデータを格納するバッファへのポインター
+**戻り値** -**bufSz** – size of the buffer
+- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - 出力ポインターが NULL +- `WS_BAD_FILE_E` - `name` が NULL、またはファイルを開けない、読み込めない、空である、または `WOLFSSH_MAX_FILE_SIZE` より大きい +- `WS_BAD_FILETYPE_E` +- `WS_PARSE_E` +- `WS_MEMORY_E` -``` -#include -int wolfSSH_stream_send(WOLFSSH* ssh , byte* buf , word32 bufSz); -``` +**関連項目** +- `wolfSSH_ReadCert_buffer()` +- `wolfSSH_ReadKey_file()` +## 鍵交換アルゴリズムの設定 -**関連項目** +wolfSSH は、使用している wolfCrypt ライブラリでのアルゴリズムの利用可否に基づいて、 +鍵交換 (KEX) 時に使用するアルゴリズムリストの集合をセットアップする。 -wolfSSH_accept()
+利用可能なアルゴリズムを確認するためのアクセサ関数と、KEX で使用されるアルゴリズムリストを +確認するためのアクセサ関数が用意されている。アクセサ関数は 4 つ 1 組で提供される。すなわち、 +CTX オブジェクトからの設定・取得、および SSH オブジェクトからの設定・取得である。CTX を使って +作成された SSH オブジェクトはすべて CTX のアルゴリズムリストを継承するが、独自のリストを +与えることもできる。 -wolfSSH_stream_read() +デフォルトでは、SHA-1 を使用するアルゴリズムはすべて無効化されているが、以下のいずれかの +関数を使って再度有効化できる。wolfCrypt 側で SHA-1 が無効化されている場合、SHA-1 は使用できない。 -### wolfSSH_stream_exit() +### wolfSSH アルゴリズムリストの設定 +```c +#include -**用法** +int wolfSSH_CTX_SetAlgoListKex(WOLFSSH_CTX* ctx, const char* list); +int wolfSSH_CTX_SetAlgoListKey(WOLFSSH_CTX* ctx, const char* list); +int wolfSSH_CTX_SetAlgoListCipher(WOLFSSH_CTX* ctx, const char* list); +int wolfSSH_CTX_SetAlgoListMac(WOLFSSH_CTX* ctx, const char* list); +int wolfSSH_CTX_SetAlgoListKeyAccepted(WOLFSSH_CTX* ctx, const char* list); + +int wolfSSH_SetAlgoListKex(WOLFSSH* ssh, const char* list); +int wolfSSH_SetAlgoListKey(WOLFSSH* ssh, const char* list); +int wolfSSH_SetAlgoListCipher(WOLFSSH* ssh, const char* list); +int wolfSSH_SetAlgoListMac(WOLFSSH* ssh, const char* list); +int wolfSSH_SetAlgoListKeyAccepted(WOLFSSH* ssh, const char* list); +``` **説明** -SSHストリームを終了させます。 +これらの関数は、wolfSSH の _ctx_ または _ssh_ オブジェクトに設定される各種アルゴリズムリストの +セッターとして機能する。これらの文字列は KEX 初期化時にピアへ送信され、ピアが KEX 初期化 +メッセージを送ってきた際の比較に使用される。KeyAccepted リストはユーザー認証に使用される。 +CTX 版の関数は、指定された WOLFSSH_CTX オブジェクト _ctx_ に対してアルゴリズムリストを設定する。 +これらはコンパイル時にデフォルト値が設定されている。指定した値がその代わりに使用される。 +なお、このライブラリは文字列をコピーしないため、その所有権はアプリケーション側にあり、 +アプリケーションが CTX を解放する際に文字列を解放するのはアプリケーションの責任である。 +CTX を使って SSH オブジェクトを作成すると、SSH オブジェクトは CTX の文字列を継承する。 +SSH オブジェクトのアルゴリズムリストは上書きすることができる。 -**戻り値** +`Kex` は鍵交換アルゴリズムリストを指定する。`Key` はサーバー公開鍵アルゴリズムリストを指定する。 +`Cipher` はバルク暗号化アルゴリズムリストを指定する。`Mac` はメッセージ認証コードアルゴリズム +リストを指定する。`KeyAccepted` はユーザー認証で許可される公開鍵アルゴリズムを指定する。 -**WS_BAD_ARGUMENT** - 引数の一つがNULL
+セッターはリストを検証し、拒否した場合は現在のリストをそのまま残す。`Kex`、`Cipher`、`Mac` の +セッターは NULL を拒否する。`Key` のセッターはサーバー上でのみ NULL を受け付け、その場合は +読み込まれた秘密鍵からホスト鍵リストを導出するデフォルトの動作に戻る。クライアントにはこのような +フォールバックはない。`KeyAccepted` のセッターはどちら側でも NULL を受け付けるが、これは +デフォルトに戻すのではなくリストを空にする。その場合サーバーは空の RFC 8308 "server-sig-algs" を +通知し、どの署名アルゴリズムも受け付けないことをクライアントに伝えることになる。 -**WS_SUCCESS** - 成功 +**戻り値** -**引数** +- `WS_SUCCESS` +- `WS_INVALID_ALGO_ID` - リストが有効でない +- `WS_SSH_CTX_NULL_E` - `ctx` が NULL +- `WS_SSH_NULL_E` - `ssh` が NULL -**ssh** – WOLFSSHオブジェクトへのポインター
-**status** – SSHコネクションの状態 +### wolfSSH アルゴリズムリストの取得 -``` +```c #include -int wolfSSH_stream_exit(WOLFSSH* ssh, int status); -``` - -### wolfSSH_TriggerKeyExchange() - -**用法** +const char* wolfSSH_CTX_GetAlgoListKex(WOLFSSH_CTX* ctx); +const char* wolfSSH_CTX_GetAlgoListKey(WOLFSSH_CTX* ctx); +const char* wolfSSH_CTX_GetAlgoListCipher(WOLFSSH_CTX* ctx); +const char* wolfSSH_CTX_GetAlgoListMac(WOLFSSH_CTX* ctx); +const char* wolfSSH_CTX_GetAlgoListKeyAccepted(WOLFSSH_CTX* ctx); + +const char* wolfSSH_GetAlgoListKex(WOLFSSH* ssh); +const char* wolfSSH_GetAlgoListKey(WOLFSSH* ssh); +const char* wolfSSH_GetAlgoListCipher(WOLFSSH* ssh); +const char* wolfSSH_GetAlgoListMac(WOLFSSH* ssh); +const char* wolfSSH_GetAlgoListKeyAccepted(WOLFSSH* ssh); +``` **説明** -鍵交換処理を開始します。ハンドシェークに必要なパケットを用意して送信します。 +これらの関数は、wolfSSH の _ctx_ または _ssh_ オブジェクトに設定される各種アルゴリズムリストの +ゲッターとして機能する。 +`Kex` は鍵交換アルゴリズムリストを指定する。`Key` はサーバー公開鍵アルゴリズムリストを指定する。 +`Cipher` はバルク暗号化アルゴリズムリストを指定する。`Mac` はメッセージ認証コードアルゴリズム +リストを指定する。`KeyAccepted` はユーザー認証で許可される公開鍵アルゴリズムを指定する。 **戻り値** -**WS_BAD_ARGUEMENT** – 引数がNULL
- -**WS_SUCCESS** - 成功 +これらの関数は、コンパイル時に設定されたデフォルト値、またはセッター関数で実行時に設定された +値へのポインターを返す。`ctx` または `ssh` パラメーターが NULL の場合、関数は NULL を返す。 -**引数** -**ssh** – WOLFSSHオブジェクトへのポインター
+### wolfSSH_CheckAlgoName() -``` +```c #include -int wolfSSH_TriggerKeyExchange(WOLFSSH* ssh ); + +int wolfSSH_CheckAlgoName(const char* name); ``` -## テスト機能 +**説明** +指定した単一のアルゴリズム名 `name` が有効かつサポートされているかどうかを確認する。 +**引数** -### wolfSSH_GetStats() +- `name` - 確認するアルゴリズム名 +**戻り値** -**用法** +- `WS_SUCCESS` +- `WS_INVALID_ALGO_ID` -**説明** -**ssh**セッションに関連した、**txCount** , **rxCount** , **seq** , と **peerSeq** を更新します。 +### wolfSSH_CTX_SetStrictKex() +```c +#include -**戻り値** +int wolfSSH_CTX_SetStrictKex(WOLFSSH_CTX* ctx, byte enable); +``` -なし +**説明** + +このコンテキストから作成されるセッションについて、Terrapin(CVE-2023-48795)の緩和策である厳格な鍵交換(strict KEX)を提示するかどうかを有効または無効にする。strict KEX はデフォルトで有効である。双方が提示した場合、最初の鍵交換中に KEX 以外のメッセージを受け取ると接続が終了し、シーケンス番号は鍵交換のたびにリセットされる。wolfSSH_new() はコンテキストの設定をコピーするため、変更はその後に作成されたセッションにのみ影響する。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `ctx` - wolfSSH コンテキストへのポインター +- `enable` - strict KEX を提示する場合は 0 以外、提示しない場合は 0 -**txCount** – 総送信済みデータ数を返却する為の変数のアドレス
+**戻り値** -**rxCount** – 総受信済みデータ数を返却する為の変数のアドレス
+- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` が NULL -**seq** – パケットシーケンス番号を返却する為の変数のアドレス。パケットシーケンス番号は0から始まりパケット毎にインクリメントされる
+**関連項目** -**peerSeq** – 相手パケットシーケンス番号を返却する為の変数のアドレス。パケットシーケンス番号は0から始まりパケット毎にインクリメントされる
+- `wolfSSH_CTX_GetStrictKex()` +- `wolfSSH_GetStrictKexNegotiated()` +### wolfSSH_CTX_GetStrictKex() -``` +```c #include -void wolfSSH_GetStats(WOLFSSH* ssh , word32* txCount , word32* rxCount , -word32* seq , word32* peerSeq ) -``` -### wolfSSH_KDF() - - -**用法** +int wolfSSH_CTX_GetStrictKex(WOLFSSH_CTX* ctx); +``` **説明** -APIテストが鍵派生の既知の回答テストを行うことができるように使用されます。 -鍵派生関数は鍵マテリアル**k** と **h**を元に対称鍵を生成します。ここで、**k**はデフィーヘルマンのシェアードシークレットであり、**h**は初期の鍵交換中に生成されたハンドシェークのハッシュ値です。**keyid**および**hashid**によって指定される複数のタイプの鍵が導出される可能性があります。 +コンテキストが strict KEX を提示するかどうかを報告する。 +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター -``` -Initial IV client to server: keyId = A -Initial IV server to client: keyId = B -Encryption key client to server: keyId = C -Encryption key server to client: keyId = D -Integrity key client to server: keyId = E -Integrity key server to client : keyId = F -``` **戻り値** -**WS_SUCCESS**
+- 1 - strict KEX を提示する +- 0 - strict KEX を提示しない +- `WS_BAD_ARGUMENT` - `ctx` が NULL -**WS_CRYPTO_FAILED** +**関連項目** -**引数** +- `wolfSSH_CTX_SetStrictKex()` -**hashId** – キーイングマテリアルを生成させる為のハッシュのタイプ(WC_HASH_TYPE_SHA あるいは WC_HASH_TYPE_SHA256)
+### wolfSSH_GetStrictKexNegotiated() + +```c +#include -**keyId** – 生成する鍵を示す文字A から F
+int wolfSSH_GetStrictKexNegotiated(WOLFSSH* ssh); +``` -**key** – 期待されている鍵との比較に使用される生成済みの鍵
+**説明** -**keySz** – 鍵**key**の生成に必要なサイズ
+セッションで strict KEX がネゴシエートされたかどうか、すなわち双方がそれを提示したかどうかを報告する。 -**k** – デフィーヘルマン鍵交換で得たシェアードシークレット
+**引数** -**kSz** – シェアードシークレット**k**のサイズ
+- `ssh` - wolfSSH セッションへのポインター -**h** – 鍵交換中に生成されたハンドシェークのハッシュ値
+**戻り値** -**hSz** – ハッシュ**h**のサイズ
+- 1 - strict KEX がネゴシエートされた +- 0 - strict KEX はネゴシエートされなかった +- `WS_SSH_NULL_E` - `ssh` が NULL -**sessionId** – 最初のハッシュ**h**のユニークなID
+**関連項目** -**sessionIdSz** – **sessionId**のサイズ +- `wolfSSH_CTX_SetStrictKex()` +### wolfSSH アルゴリズムの照会 -``` +```c #include -int wolfSSH_KDF(byte hashId , byte keyId , byte* key , word32 keySz , -const byte* k , word32 kSz , const byte* h , word32 hSz , -const byte* sessionId , word32 sessionIdSz ); + +const char* wolfSSH_QueryKex(word32* index); +const char* wolfSSH_QueryKey(word32* index); +const char* wolfSSH_QueryCipher(word32* index); +const char* wolfSSH_QueryMac(word32* index); ``` +**説明** + +指定された種別(Kex、Key、Cipher、または Mac)の有効なアルゴリズムの名前文字列を返す。Key +種別は、ユーザー認証で受理される鍵種別としても使用される。`index` を 0 に初期化し、呼び出す +たびに同じポインターを渡すことで反復処理を行う。関数はこのポインターを進める。戻り値が NULL +の場合、リストの末尾に達したことを意味する。 +**引数** -## セッション機能 +- `index` - イテレーター。0 に初期化し、呼び出しごとに渡す +**戻り値** +- アルゴリズム名文字列へのポインター、またはリストの末尾に達した場合は `NULL` -### wolfSSH_GetSessionType() +### wolfSSH_GetText() +```c +#include -**用法** +size_t wolfSSH_GetText(WOLFSSH* ssh, WS_Text id, char* str, size_t strSz); +``` **説明** -wolfSSH_GetSessionType()はセッションの種類を返します。 +`id`(KEX アルゴリズム、KEX 曲線、KEX ハッシュ、入出力暗号、入出力 MAC などの `WS_Text` 値) +で識別されるネゴシエーション済み項目のテキスト表現を `str` に書き込む。終端 NULL を含めて +`strSz` バイトを超えて書き込むことはない。 -**戻り値** +**引数** -WOLFSSH_SESSION_UNKNOWN
+- `ssh` - wolfSSH セッションへのポインター +- `id` - 取得する `WS_Text` 項目 +- `str` - テキストの出力バッファ +- `strSz` - 出力バッファのサイズ -WOLFSSH_SESSION_SHELL
+**戻り値** -WOLFSSH_SESSION_EXEC
+- 書き込まれた文字数(終端 NULL を除く)。値が `strSz` 以上の場合、出力が切り詰められたことを + 意味する -WOLFSSH_SESSION_SUBSYSTEM
+## グローバルリクエストコールバック -**引数** +これらのコールバックは、SSH グローバルリクエストメッセージおよびその成功/失敗応答を処理する。 -**ssh** - WOLFSSHオブジェクトへのポインター
+### wolfSSH_SetGlobalReq() -``` +```c #include -WS_SessionType wolfSSH_GetSessionType(const WOLFSSH* ssh ); -``` -### wolfSSH_GetSessionCommand() +void wolfSSH_SetGlobalReq(WOLFSSH_CTX* ctx, WS_CallbackGlobalReq cb); +``` +**説明** -**用法** +ピアからグローバルリクエストメッセージを受信した際に呼び出されるコールバックを登録する。 -**説明** +**引数** -セッションの現在のコマンドを返します +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - グローバルリクエストコールバック **戻り値** -**const char*** - コマンドへのポインター +なし -**引数** +**関連項目** -**ssh** - WOLFSSHオブジェクトへのポインター
+- `wolfSSH_SetGlobalReqCtx()` -``` +### wolfSSH_SetGlobalReqCtx() + +```c #include -const char* wolfSSH_GetSessionCommand(const WOLFSSH* ssh ); + +void wolfSSH_SetGlobalReqCtx(WOLFSSH* ssh, void* ctx); ``` -## ポートフォワーディング関数 +**説明** +グローバルリクエストコールバックに渡されるユーザーコンテキストポインターを設定する。 +**引数** -### wolfSSH_ChannelFwdNew() +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - コールバックに渡すユーザーコンテキストポインター +**戻り値** -**用法** +なし -**説明** +### wolfSSH_GetGlobalReqCtx() -wolfSSHセッションにTCP/IP転送チャネルを設定します。SSHセッションが接続され、認証された場合、ポート_hostport_のaddress_host_のインターフェイスにローカルリスナーが作成されます。そのリスナーの新しい接続があれば、SSHサーバーへの新しいChannelRequestをトリガーして、ポート_hostport_で_host_への接続を確立します。 +```c +#include +void* wolfSSH_GetGlobalReqCtx(WOLFSSH* ssh); +``` -**戻り値** +**説明** -**WOLFSSH_CHAN*** – エラーの場合はNULL、成功の場合は新たな新しいチャンネルレコード +wolfSSH_SetGlobalReqCtx() で以前に設定されたユーザーコンテキストポインターを返す。 **引数** -**ssh** - WOLFSSHオブジェクトへのポインター
+- `ssh` - wolfSSH セッションへのポインター -**host** – バインドリスナーのホストアドレス
+**戻り値** -**hostPort** – バインドリスナーのポート
+- グローバルリクエストコンテキストポインター。存在しない場合は `NULL` -**origin** – 接続元のIPアドレス
+### wolfSSH_CTX_SetGlobalReqAnyCb() -**originPort** – 接続元のポート
+```c +#include +int wolfSSH_CTX_SetGlobalReqAnyCb(WOLFSSH_CTX* ctx, + WS_CallbackGlobalReqAny cb); ``` -#include -WOLFSSH_CHANNEL* wolfSSH_ChannelFwdNew(WOLFSSH* ssh , -const char* host , word32 hostPort , -const char* origin , word32 originPort ); + +**説明** + +ピアからのグローバルリクエストに対して最初に参照されるポリシーコールバックを設定する。これは、"tcpip-forward" と "cancel-tcpip-forward" に応答するフォワーディングコールバックや、それ以外に応答する wolfSSH_SetGlobalReq() で設定したグローバルリクエストコールバックよりも先に参照される。 + +```c +typedef int (*WS_CallbackGlobalReqAny)(WOLFSSH* ssh, const byte* name, + word32 nameSz, const byte* data, word32 dataSz, int wantReply, + void* ctx); ``` -### wolfSSH_ChannelFree() +`name` は到着したままのリクエスト名で長さは `nameSz` バイト、`data` はリクエストのタイプ固有の部分で長さは `dataSz` バイトであり、コールバックが解析する。したがって、ポートを指定した "tcpip-forward" は、フォワーディングコールバックなしにここからセットアップできる。どちらも NUL 終端されておらず、名前には任意のバイトが含まれ得るため、文字列関数ではなく `nameSz` バイトで照合すること。コールバックは、wolfSSH_SetGlobalReqCtx() で設定したグローバルリクエストコンテキストを共有する。 +コールバックは `WS_ReqCbResult` を返す(「チャネルコールバック」セクションを参照)。`WOLFSSH_REQ_UNHANDLED`(0)は、リクエストを他のコールバックに委ねる。`WOLFSSH_REQ_ACCEPT` と `WOLFSSH_REQ_REJECT` はリクエストの扱いを確定させ、他のコールバックは参照されない。応答が求められている場合、その応答は SSH_MSG_REQUEST_SUCCESS または SSH_MSG_REQUEST_FAILURE となる。 -**用法** +2 種類のリクエストはこのコールバックに到達しない。ポート 0 を要求する "tcpip-forward"、または本体を解析できない "tcpip-forward" は、ポートをバインドして報告できるフォワーディングコールバックに委ねられる。また、クライアントは、ポリシーがどうであれ "tcpip-forward" と "cancel-tcpip-forward" に失敗で応答する。 -**説明** +`name` と `data` はセッションの入力バッファ内を指しており、呼び出しの間のみ有効であるため、いずれかを保持するコールバックはコピーしなければならない。コールバックは、このセッションに対してライブラリの受信側(wolfSSH_worker()、wolfSSH_stream_read()、wolfSSH_accept()、または SFTP の呼び出し)を再入してはならない。 -チャネル _channel_のメモリを解放します。チャネルはセッションのチャネルリストから削除されます。 +**引数** +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - グローバルリクエストポリシーコールバック **戻り値** -**int** – エラーコード +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` -**引数** +**関連項目** -**channel** – 解放されるwolfSSHチャネル +- `wolfSSH_SetGlobalReq()` +- `wolfSSH_SetGlobalReqCtx()` +- `wolfSSH_CTX_SetChannelReqAnyCb()` -``` +### wolfSSH_SetReqSuccess() + +```c #include -int wolfSSH_ChannelFree(WOLFSSH_CHANNEL* channel ); + +void wolfSSH_SetReqSuccess(WOLFSSH_CTX* ctx, WS_CallbackReqSuccess cb); ``` -### wolfSSH_worker() +**説明** +ピアからリクエスト成功応答を受信した際に呼び出されるコールバックを登録する。 -**用法** +**引数** -**説明** +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - リクエスト成功コールバック -wolfSSH Worker機能は接続を見守り、データが受信されると処理します。SSHセッションにはセッションの多くの管理すべきメッセージがあり、これにより自動的にケアがあります。特定のチャネルのデータが受信されると、ワーカーはデータをチャネルに配置します。(function wolfssh_stream_read()dosmuchも同じですが、単一のチャネルの受信データも返します。)wolfssh_worker()は次のアクションを実行します: +**戻り値** -1. _outputbuffer_ 内に保留中のデータを送信しようとします。 -2. セッションのソケットに対して _DoReceive()_ を呼び出します。 -3. 特定のチャネルのデータが受信された場合、データを返して通知を受け取り、チャネルIDを指定して通知します。 +なし +**関連項目** -**戻り値** +- `wolfSSH_SetReqSuccessCtx()` -**int** – エラーコードあるいはステータス
+### wolfSSH_SetReqSuccessCtx() -**WS_CHANNEL_RXD** – チャネルに受信済みのデータとチャネルIDがセットされている +```c +#include -**引数** +void wolfSSH_SetReqSuccessCtx(WOLFSSH* ssh, void* ctx); +``` -**ssh** - WOLFSSHオブジェクトへのポインター
+**説明** -**id** – IDを格納する変数へのポインター +リクエスト成功コールバックに渡されるユーザーコンテキストポインターを設定する。 +**引数** -``` -#include -int wolfSSH_worker(WOLFSSH* ssh , word32* channelId ); -``` +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - コールバックに渡すユーザーコンテキストポインター -### wolfSSH_ChannelGetId() +**戻り値** +なし -**用法** +### wolfSSH_GetReqSuccessCtx() -**説明** +```c +#include -引数で与えられたチャネルに対してIDあるいは相手のIDを返します。 +void* wolfSSH_GetReqSuccessCtx(WOLFSSH* ssh); +``` -**戻り値** +**説明** -**int** – エラーコード
+wolfSSH_SetReqSuccessCtx() で以前に設定されたユーザーコンテキストポインターを返す。 **引数** -**channel** – チャネルへのポインター
- -**id** – IDを格納する変数へのポインター
+- `ssh` - wolfSSH セッションへのポインター -**peer** – 自チャネルIDか相手チャネルID +**戻り値** -``` -#include -int wolfSSH_ChannelGetId(WOLFSSH_CHANNEL* channel , word32* id , byte peer); -``` +- リクエスト成功コンテキストポインター。存在しない場合は `NULL` -### wolfSSH_ChannelFind() +### wolfSSH_SetReqFailure() +```c +#include -**用法** +void wolfSSH_SetReqFailure(WOLFSSH_CTX* ctx, WS_CallbackReqSuccess cb); +``` **説明** -Given a session _ssh_ , find the channel associated with _id_. +ピアからリクエスト失敗応答を受信した際に呼び出されるコールバックを登録する。 -**戻り値** +**引数** -**WOLFSSH_CHANNEL*** – チャネルへのポインター,IDがリストになければNULL +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - リクエスト失敗コールバック -**引数** +**戻り値** -**ssh** - WOLFSSHオブジェクトへのポインター
+なし -**id** – 検索したいチャネルID
+**関連項目** -**peer** – どちらの側(自channel ID か相手channel ID) +- `wolfSSH_SetReqFailureCtx()` +### wolfSSH_SetReqFailureCtx() -``` +```c #include -WOLFSSH_CHANNEL* wolfSSH_ChannelFind(WOLFSSH* ssh , -word32 id , byte peer ); + +void wolfSSH_SetReqFailureCtx(WOLFSSH* ssh, void* ctx); ``` -### wolfSSH_ChannelRead() +**説明** +リクエスト失敗コールバックに渡されるユーザーコンテキストポインターを設定する。 -**用法** +**引数** -**説明** +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - コールバックに渡すユーザーコンテキストポインター -チャネルオブジェクトからデータをコピーします +**戻り値** +なし -**戻り値** +### wolfSSH_GetReqFailureCtx() -**int** – 読みだしたバイト数
+```c +#include -**>0** – 成功時には読みだしたバイト数を返します +void* wolfSSH_GetReqFailureCtx(WOLFSSH* ssh); +``` -**0** – クリーンコネクションシャットダウンかソケットエラーが発生している。 エラー詳細を取得するためにwolfSSH_get_error()を呼び出すこと。
+**説明** -**WS_FATAL_ERROR** – そのほかのエラーが発生。エラー詳細を取得するためにwolfSSH_get_error()を呼び出すこと。
+wolfSSH_SetReqFailureCtx() で以前に設定されたユーザーコンテキストポインターを返す。 **引数** -**channel** – wolfSSH channelへのポインター
+- `ssh` - wolfSSH セッションへのポインター + +**戻り値** -**buf** – wolfSSH_ChannelReadが読みだしたデータを格納するバッファアドレス
+- リクエスト失敗コンテキストポインター。存在しない場合は `NULL` -**bufSz** – バッファのサイズ
+## TPM 2.0 連携 -``` -#include -int wolfSSH_ChannelRead(WOLFSSH_CHANNEL* channel, byte* buf, word32 bufSz ); -``` +これらの関数は、ホスト鍵操作のために wolfTPM 2.0 デバイスおよび鍵を統合する。使用するには、 +wolfSSH を `WOLFSSH_TPM` を有効にしてビルドし、wolfTPM がインストールされている必要がある。 -### wolfSSH_ChannelSend() +### wolfSSH_SetTpmDev() +```c +#include -**用法** +void wolfSSH_SetTpmDev(WOLFSSH* ssh, WOLFTPM2_DEV* dev); +``` **説明** -指定したチャネル経由でデータを相手に送信します。データはチャネルデータメッセージにパッキングされて送られます。さらに送信すべきデータがある場合には、 _wolfSSH_worker()_ を呼び出すと相手へのデータ送信を継続します。 +TPM を利用したホスト鍵操作のために、wolfTPM 2.0 デバイスをセッションに関連付ける。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `dev` - wolfTPM 2.0 デバイスへのポインター **戻り値** -**int** – 送信したバイト数
+なし + +**関連項目** + +- `wolfSSH_SetTpmKey()` -**>0** – 成功時には送信したバイト数を返す
+### wolfSSH_SetTpmKey() + +```c +#include -**0** – クリーンコネクションシャットダウンかソケットエラーが発生している。 エラー詳細を取得するためにwolfSSH_get_error()を呼び出すこと。
+void wolfSSH_SetTpmKey(WOLFSSH* ssh, WOLFTPM2_KEY* key); +``` -**WS_FATAL_ERROR** – そのほかのエラーが発生。エラー詳細を取得するためにwolfSSH_get_error()を呼び出すこと。
+**説明** +TPM を利用したホスト鍵操作のために、wolfTPM 2.0 鍵をセッションに関連付ける。 **引数** -**channel** – wolfSSH channelへのポインター
+- `ssh` - wolfSSH セッションへのポインター +- `key` - wolfTPM 2.0 鍵へのポインター -**buf** – wolfSSH_ChannelSend()が送信のために読みだすバッファへのポインター
+**戻り値** -**bufSz** – バッファのサイズ
+なし +### wolfSSH_GetTpmDev() -``` +```c #include -int* wolfSSH_ChannelSend(WOLFSSH_CHANNEL* channel, const byte* buf, word32 bufSz); -``` -### wolfSSH_ChannelExit() +void* wolfSSH_GetTpmDev(WOLFSSH* ssh); +``` +**説明** -**用法** +以前にセッションに関連付けられた wolfTPM 2.0 デバイスを返す。 -**説明** +**引数** -チャネルを終了し、相手へのメッセージ送信を停止し、チャネルがクローズしたとマークします。この関数はチャネルと残ったデータを解放しませんし、チャネルはリストに残ります。クローズ後は未送信データはそのままですが、受信は可能です。(現時点ではEOFとcloseを送りチャネルを削除します) +- `ssh` - wolfSSH セッションへのポインター **戻り値** -**int** – エラーコード - -**引数** +- wolfTPM 2.0 デバイスへのポインター。存在しない場合は `NULL` -**channel** – wolfSSH channelへのポインター
+### wolfSSH_GetTpmKey() -``` +```c #include -int wolfSSH_ChannelExit(WOLFSSH_CHANNEL* channel ); + +void* wolfSSH_GetTpmKey(WOLFSSH* ssh); ``` -### wolfSSH_ChannelNext() +**説明** +以前にセッションに関連付けられた wolfTPM 2.0 鍵を返す。 -**用法** +**引数** -**説明** +- `ssh` - wolfSSH セッションへのポインター -_ssh_ の _channel_ の次のチャネルを返します。_channel_ がNULLの場合には、チャネルリスト内の最初のチャネルを返します。 +**戻り値** +- wolfTPM 2.0 鍵へのポインター。存在しない場合は `NULL` -**戻り値** +### wolfSSH_CTX_UseTpmHostKey() -**WOLFSSH_CHANNEL** – 最初のチャネルあるいは次のチャネルへのポインターあるいはNULL +```c +#include -**引数** +int wolfSSH_CTX_UseTpmHostKey(WOLFSSH_CTX* ctx, + WOLFTPM2_DEV* dev, WOLFTPM2_KEY* key); +``` -**ssh** - WOLFSSHオブジェクトへのポインター
+**説明** -**channel** – wolfSSH channelへのポインター
+指定された wolfTPM 2.0 デバイスおよび鍵をサーバーホスト鍵として使用するようコンテキストを +設定する。 -``` -#include -WOLFSSH_CHANNEL* wolfSSH_ChannelFwdNew(WOLFSSH* ssh , WOLFSSH_CHANNEL* channel ); -``` +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `dev` - wolfTPM 2.0 デバイスへのポインター +- `key` - wolfTPM 2.0 鍵へのポインター + +**戻り値** +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` diff --git a/wolfSSH/src-ja/chapter14.md b/wolfSSH/src-ja/chapter14.md index f2f34ff3..034a94b1 100644 --- a/wolfSSH/src-ja/chapter14.md +++ b/wolfSSH/src-ja/chapter14.md @@ -1,6 +1,6 @@ -# wolfSSL SFTP API リファレンス +# wolfSSH SFTP API リファレンス -## 接続機能 +## 接続関数 @@ -8,837 +8,662 @@ -**用法** +```c +#include -**説明** +int wolfSSH_SFTP_accept(WOLFSSH* ssh); +``` -クライアントからの接続要求を処理します +**説明** -**戻り値** +クライアントからの受信 SFTP 接続要求を処理します。SSH セッションが確立された後、 +サーバー側で呼び出します。 -**WS_SFTP_COMPLETE** - 成功 +アプリケーション駆動チャネルが有効な場合(wolfSSH_CTX_SetAppChannels() または +wolfSSH_SetAppChannels())、この関数は、アプリケーションのサブシステムコールバックが +"sftp" サブシステムを許可したセッションチャネルのみを処理します。サブシステム名は +"sftp" と完全に一致する必要があります。その許可より前に呼び出された場合は、セッションに +エラーを記録せずに `WS_INVALID_STATE_E` を返します。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
- +- `ssh` - 接続に使用する wolfSSH セッションへのポインター -``` -#include -int wolfSSH_SFTP_accept(WOLFSSH* ssh ); -``` -**使用例** - -``` -WOLFSSH* ssh; - -//create new WOLFSSH structure -... +**戻り値** -if (wolfSSH_SFTP_accept(ssh) != WS_SUCCESS) { -//handle error case -} -``` +- 成功時は `WS_SFTP_COMPLETE` +- `ssh` が `NULL` の場合は `WS_BAD_ARGUMENT` +- アプリケーション駆動チャネルモードで sftp サブシステムが許可されていない場合は + `WS_INVALID_STATE_E` +- 失敗時は負のエラーコード **関連項目** -wolfSSH_SFTP_free()
- -wolfSSH_new()
- -wolfSSH_SFTP_connect()
- +- `wolfSSH_SFTP_connect()` +- `wolfSSH_SFTP_negotiate()` ### wolfSSH_SFTP_connect() -**用法** -**説明** +```c +#include -SFTPサーバーへの接続を開始します。 +int wolfSSH_SFTP_connect(WOLFSSH* ssh); +``` -**戻り値** +**説明** -**WS_SFTP_COMPLETE** - 成功
+サーバーへの SFTP 接続を開始します。SSH セッションが確立された後、クライアント側で +呼び出します。 **引数** -**ssh** - – WOLFSSHオブジェクトへのポインター
- - -``` -#include -int wolfSSH_SFTP_connect(WOLFSSH* ssh ); -``` - - -**使用例** - -``` -WOLFSSH* ssh; +- `ssh` - 接続に使用する wolfSSH セッションへのポインター -//after creating a new WOLFSSH structure +**戻り値** -wolfSSH_SFTP_connect(ssh); -``` +- 成功時は `WS_SFTP_COMPLETE` +- 失敗時は負のエラーコード **関連項目** -wolfSSH_SFTP_accept()
- -wolfSSH_new()
- -wolfSSH_free()
- +- `wolfSSH_SFTP_accept()` +- `wolfSSH_SFTP_negotiate()` ### wolfSSH_SFTP_negotiate() -**用法** - -**説明** - -本関数はクライアントからの接続要求かサーバーへの接続要求のいずれかを処理します。いずれを処理するかはwolfSSHオブジェクトにセットされているアクションに依存します。 - - -**戻り値** - -**WS_SUCCESS** - 成功 - -**引数** - -**ssh** - – WOLFSSHオブジェクトへのポインター
- - -``` +```c #include -int wolfSSH_SFTP_negotiate(WOLFSSH* ssh) -``` - -**使用例** +int wolfSSH_SFTP_negotiate(WOLFSSH* ssh); ``` -WOLFSSH* ssh; -//create new WOLFSSH structure with side of connection -set -.... - -if (wolfSSH_SFTP_negotiate(ssh) != WS_SUCCESS) { -//handle error case -} -``` - -**関連項目** - -wolfSSH_SFTP_free()
- -wolfSSH_new()
+**説明** -wolfSSH_SFTP_connect()
+SFTP プロトコルのネゴシエーションを実行します。セッションがどちら側のために作成 +されたかに応じて、クライアントからの受信接続を処理するか、サーバーへ接続要求を +送信します。 -wolfSSH_SFTP_accept()
+**引数** +- `ssh` - 接続に使用する wolfSSH セッションへのポインター +**戻り値** -## プロトコル関係 +- 成功時は `WS_SUCCESS` +- 失敗時は負のエラーコード +**関連項目** +- `wolfSSH_SFTP_accept()` +- `wolfSSH_SFTP_connect()` -### wolfSSH_SFTP_RealPath() +### wolfSSH_SFTP_SetDefaultPath() +```c +#include -**用法** +int wolfSSH_SFTP_SetDefaultPath(WOLFSSH* ssh, const char* path); +``` **説明** -REALPATHパケットを相手に送信し、相手から取得したファイル名を返します。 +SFTP セッションの開始パスを設定します。開始パスは、セッションが開始するディレクトリ +であり、サーバーが相対的な要求パスを解決する際の基準となります。開始パスはセッションが +どこで開始するかを設定するだけで、アクセスの許可や拒否は一切行いません。セッションが +到達できるパスを制限するには wolfSSH_SFTP_SetConfinePath() を使用します。これは +この設定とは独立しています。 +パスは保存される前に正規化されます。相対的な `path` は、プロセスの現在の作業 +ディレクトリを基準に解決されます。この関数を再度呼び出すと、以前の開始パスが置き換え +られます。置き換え用のメモリを確保できない場合、既存の開始パスはそのまま残ります。 +`NULL` のパスを渡すと現在の設定は変更されず、`WS_SUCCESS` を返します。 -**戻り値** - -成功時にはWS_SFTPNAME構造体へのポインターを返します。エラー発生時にはNULLを返します。 +クライアントから最初の REALPATH 要求を受信した時点で開始パスが設定されていない場合、 +サーバーは開始パスを自身の現在の作業ディレクトリに設定します。これによってセッションが +制限されることはありません。 +**注意:** wolfSSH v1.6.0 以降、開始パスはセッションを制限しなくなりました。以前の +リリースでは、デフォルトパスの外側に解決される要求は拒否されていました。その動作に +依存していたアプリケーションは、wolfSSH_SFTP_SetConfinePath() も呼び出す必要が +あります。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
- -**dir** - 実際のパスを取得するためのディレクトリ/ファイル名 - - - -``` -#include -WS_SFTPNAME* wolfSSH_SFTP_RealPath(WOLFSSH* ssh , char* dir); -``` -**使用例** - -``` -WOLFSSH* ssh ; +- `ssh` - wolfSSH セッションへのポインター +- `path` - NULL 終端の開始パス。または現在の設定を変更しない場合は `NULL` -//set up ssh and do sftp connections -... +**戻り値** -if (wolfSSH_SFTP_read( ssh ) != WS_SUCCESS) { -//handle error case -} -``` +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` が `NULL` +- `WS_BUFFER_E` - パス、またはその解決の基準となる作業ディレクトリが + `WOLFSSH_MAX_FILENAME` に収まらない +- `WS_INVALID_PATH_E` - 現在の作業ディレクトリを読み取れなかった、またはパスを正規化 + できなかった +- `WS_FATAL_ERROR` - メモリ確保に失敗した(`ssh->error` は `WS_MEMORY_E` に設定 + されます) **関連項目** -wolfSSH_SFTP_accept()
+- `wolfSSH_SFTP_SetConfinePath()` -wolfSSH_SFTP_connect()
+### wolfSSH_SFTP_SetConfinePath() +```c +#include +int wolfSSH_SFTP_SetConfinePath(WOLFSSH* ssh, const char* path); +``` -### wolfSSH_SFTP_Close() +**説明** +SFTP セッションのサーバー側を、`path` をルートとするディレクトリツリーに制限します。 +各要求パスは開始パス(wolfSSH_SFTP_SetDefaultPath() を参照)を基準に解決され、 +正規化されます。その結果がルート自体でもルート配下のパスでもない場合、要求は +`WS_PERMISSIONS` で拒否されます。制限ルートが設定されていない場合、またはルートが "/" +の場合、セッションは制限されません。ルートが "/" の場合は、解決結果が絶対パスである +要求のみが受け付けられます。Windows では、プレフィックスの比較は大文字と小文字を区別 +しません。 + +制限と開始パスは互いに独立しています。サーバーは、ジェイルの深い位置でセッションを +開始する(例えば /srv/data/user7 で開始し、/srv/data に制限する)ことも、セッションが +開始する場所を変えずに制限することも、どちらも行わずにオペレーティングシステムの +パーミッションに任せることもできます。wolfSSHd は最後の方法を採用しており、制限ルートを +設定せず、認証されたユーザーに権限を降格します。開始パスは制限ルートの内側に設定して +ください。開始パスがルートの外側にあると、相対的な要求がルートの外側に解決され、 +それらの要求は拒否されます。 + +パスは保存される前に正規化されます。相対的な `path` は、プロセスの現在の作業 +ディレクトリを基準に解決されます。この関数を再度呼び出すと、以前のルートが置き換え +られます。`NULL` のパスを渡すと現在の設定は変更されず、`WS_SUCCESS` を返します。 + +パスは字句的に解決されるため、ジェイル内のシンボリックリンクがジェイル内にとどまる +ことを保証できません。そのため、シンボリックリンクをサポートするビルド +(`WOLFSSH_HAVE_SYMLINK`)では、制限されたセッションは、ルート配下のパスに既存の +シンボリックリンクの構成要素を含むすべての要求を拒否します。リンク先がジェイル内に +とどまるリンクも例外ではありません。まだ存在しない末端要素は許可されるため、作成操作は +引き続き機能します。`WOLFSSH_NO_SYMLINK_CHECK` を定義するとこのチェックが削除され、 +それによる脱出防止も失われます。ルート自体は信頼され、チェックされることはないため、 +シンボリックリンクを経由して到達するルートは、そのリンク先と同じ範囲になります。 +サーバーが管理し、シンボリックリンクの構成要素を含まないルートを使用してください。 + +シンボリックリンクのチェックは多層防御の一つであり、セキュリティ境界ではありません。 +これはチェック時と使用時の間の競合(TOCTOU)の影響を受けるチェックです。ジェイル内で +並行して書き込みを行う者が、操作の実行前にチェック済みの構成要素をリンクに置き換える +可能性があります。悪意のあるテナントが混在するデプロイメントでは、OS レベルのジェイル +(chroot と権限の降格)を使用してください。 +**引数** -**用法** +- `ssh` - wolfSSH セッションへのポインター +- `path` - NULL 終端の制限ルート。または現在の設定を変更しない場合は `NULL` -**説明** +**戻り値** -相手にクローズパケットを送信します。 +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` が `NULL` +- `WS_BUFFER_E` - パス、またはその解決の基準となる作業ディレクトリが + `WOLFSSH_MAX_FILENAME` に収まらない +- `WS_INVALID_PATH_E` - 現在の作業ディレクトリを読み取れなかった、またはパスを正規化 + できなかった +- `WS_FATAL_ERROR` - メモリ確保に失敗した(`ssh->error` は `WS_MEMORY_E` に設定 + されます) +**関連項目** -**戻り値** +- `wolfSSH_SFTP_SetDefaultPath()` -**WS_SUCCESS** - 成功 +## プロトコルレベル関数 -**引数** -**ssh** – WOLFSSHオブジェクトへのポインター
-**handle** - 閉じようとするハンドル
+### wolfSSH_SFTP_RealPath() -**handleSz** - ハンドルバッファーのサイズ -``` +```c #include -int wolfSSH_SFTP_Close(WOLFSSH* ssh , byte* handle , word32 handleSz ); -``` -**使用例** +WS_SFTPNAME* wolfSSH_SFTP_RealPath(WOLFSSH* ssh, char* dir); ``` -WOLFSSH* ssh; -byte handle[HANDLE_SIZE]; -word32 handleSz = HANDLE_SIZE; -//set up ssh and do sftp connections -... - -if (wolfSSH_SFTP_Close(ssh, handle, handleSz) != WS_SUCCESS) { -//handle error case -} -``` - -**関連項目** - -wolfSSH_SFTP_accept()
- -wolfSSH_SFTP_connect()
+**説明** +ピアに REALPATH 要求を送信し、ファイルまたはディレクトリの正規名を返します。返された +`WS_SFTPNAME` は wolfSSH_SFTPNAME_free() で解放する必要があります。 -### wolfSSH_SFTP_Open() +**引数** +- `ssh` - wolfSSH セッションへのポインター +- `dir` - 解決するファイル名またはディレクトリ名 +**戻り値** -**用法** +- 成功時は `WS_SFTPNAME` 構造体へのポインター +- エラー時は `NULL` -**説明** +**関連項目** -Openパケットを相手に送信します。結果を受け取るバッファサイズのをhandleSzで指定し、相手から受け取ったハンドルをバッファに格納します。 +- `wolfSSH_SFTPNAME_free()` +### wolfSSH_SFTP_Close() -openの理由として取り得る値は:
-WOLFSSH_FXF_READ
-WOLFSSH_FXF_WRITE
+```c +#include -WOLFSSH_FXF_APPEND
+int wolfSSH_SFTP_Close(WOLFSSH* ssh, byte* handle, word32 handleSz); +``` -WOLFSSH_FXF_CREAT
+**説明** -WOLFSSH_FXF_TRUNC
+指定されたファイルハンドルについて、ピアにクローズ要求を送信します。このハンドルは、 +以前の wolfSSH_SFTP_Open() の呼び出しから取得したものです。 -WOLFSSH_FXF_EXCL
+**引数** +- `ssh` - wolfSSH セッションへのポインター +- `handle` - クローズするファイルハンドル +- `handleSz` - ハンドルバッファのサイズ **戻り値** -**WS_SUCCESS** - 成功 - -**引数** - -**ssh** – WOLFSSHオブジェクトへのポインター
- -**dir** - 開くファイルの名前
+- `WS_SUCCESS` +- 失敗時は負のエラーコード -**reason** - ファイルを開く理由
+**関連項目** -**atr** - ファイルの初期属性
+- `wolfSSH_SFTP_Open()` -**handle** - 結果として得られるハンドル
+### wolfSSH_SFTP_Open() -**handleSz** - ハンドル用バッファのサイズ
-``` +```c #include -int wolfSSH_SFTP_Open(WOLFSSH* ssh , char* dir , word32 reason, WS_SFTP_FILEATRB* atr , byte* handle , word32* handleSz); -``` - -**使用例** - - -``` -WOLFSSH* ssh ; -char name[NAME_SIZE]; -byte handle[HANDLE_SIZE]; -word32 handleSz = HANDLE_SIZE; -WS_SFTP_FILEATRB atr; - -//set up ssh and do sftp connections -... - -if (wolfSSH_SFTP_Open( ssh , name , WOLFSSH_FXF_WRITE | WOLFSSH_FXF_APPEND | WOLFSSH_FXF_CREAT , &atr , handle , &handleSz ) != WS_SUCCESS) { -//handle error case -} +int wolfSSH_SFTP_Open(WOLFSSH* ssh, char* dir, word32 reason, + WS_SFTP_FILEATRB* atr, byte* handle, word32* handleSz); ``` -**関連項目** - -wolfSSH_SFTP_accept()
- -wolfSSH_SFTP_connect()
- - -### wolfSSH_SFTP_SendReadPacket() - -**用法** - **説明** -readパケットを相手に送信します。ハンドル用のバッファは直前のwolfSSH_SFTP_Openで得られたハンドルを格納していなければなりません。読みだすことができたデータはoutバッファに格納されます。 - - -**戻り値** - -成功時には読みだしたデータ数を返します。エラー発生時には、負の値を返します。 +`dir` で指定された名前のファイルについて、ピアにオープン要求を送信します。成功時、 +得られたファイルハンドルが `handle` に格納され、そのサイズが `handleSz` に書き込ま +れます。`reason` 引数はオープンフラグのビットマスクで、`WOLFSSH_FXF_READ`、 +`WOLFSSH_FXF_WRITE`、`WOLFSSH_FXF_APPEND`、`WOLFSSH_FXF_CREAT`、`WOLFSSH_FXF_TRUNC`、 +`WOLFSSH_FXF_EXCL` のいずれかです。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
- -**handle** - 読みだそうとするハンドル
+- `ssh` - wolfSSH セッションへのポインター +- `dir` - オープンするファイルの名前 +- `reason` - オープンフラグのビットマスク(上記を参照) +- `atr` - 初期ファイル属性 +- `handle` - 得られたファイルハンドルの出力バッファ +- `handleSz` - 入力時はバッファのサイズ、出力時はハンドルのサイズが設定される -**handleSz** - ハンドルバッファのサイズ
+**戻り値** -**ofst** - 読み出しを開始するオフセット
+- `WS_SUCCESS` +- 失敗時は負のエラーコード -**out** - 読み出した結果を格納するバッファ
+**関連項目** -**outSz** - バッファサイズ +- `wolfSSH_SFTP_Close()` +- `wolfSSH_SFTP_SendReadPacket()` +- `wolfSSH_SFTP_SendWritePacket()` +### wolfSSH_SFTP_SendReadPacket() -``` +```c #include -int wolfSSH_SFTP_SendReadPacket(WOLFSSH* ssh , byte* handle , word32 handleSz , word64 ofst , byte* out , word32 outSz ); -``` - - -**使用例** - -``` -WOLFSSH* ssh; -byte handle[HANDLE_SIZE]; -word32 handleSz = HANDLE_SIZE; -byte out[OUT_SIZE]; -word32 outSz = OUT_SIZE; -word32 ofst = 0; -int ret; - -//set up ssh and do sftp connections -... -//get handle with wolfSSH_SFTP_Open() - -if ((ret = wolfSSH_SFTP_SendReadPacket(ssh, handle, handleSz, ofst, out, outSz)) < 0) { -//handle error case -} -//ret holds the number of bytes placed into out buffer +int wolfSSH_SFTP_SendReadPacket(WOLFSSH* ssh, byte* handle, + word32 handleSz, const word32* ofst, byte* out, word32 outSz); ``` -**関連項目** - -wolfSSH_SFTP_SendWritePacket()
- -wolfSSH_SFTP_Open()
- - -### wolfSSH_SFTP_SendWritePacket() - - - -**用法** - **説明** -writeパケットを相手に送信します。ハンドル用のバッファは直前のwolfSSH_SFTP_Openで得られたハンドルを格納していなければなりません。 - -**戻り値** - -成功時には書き込んだサイズを返します。エラー発生時には負の値を返します。 +`handle`(wolfSSH_SFTP_Open() から取得)が参照するファイルについて、ピアに読み取り +要求を送信します。読み取られたバイトは `out` バッファに格納されます。`ofst` 引数は、 +読み取りを開始するファイルオフセットを指します。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
- -**handle** - 書き込もうとするハンドル
- -**handleSz** - ハンドルバッファのサイズ
- -**ofst** - 書き込みを開始するオフセット
- -**out** - 書き込むデータを保持するバッファ
- -**outSz** - バッファサイズ
- - -``` -#include -int wolfSSH_SFTP_SendWritePacket(WOLFSSH* ssh, byte* handle, word32 handleSz, word64 ofst, byte* out, word32 outSz); -``` - -**使用例** +- `ssh` - wolfSSH セッションへのポインター +- `handle` - 読み取り元のファイルハンドル +- `handleSz` - ハンドルバッファのサイズ +- `ofst` - 読み取りを開始するファイルオフセットへのポインター +- `out` - 読み取ったデータを保持するバッファ +- `outSz` - 出力バッファのサイズ +**戻り値** -``` -WOLFSSH* ssh; -byte handle[HANDLE_SIZE]; -word32 handleSz = HANDLE_SIZE; -byte out[OUT_SIZE]; -word32 outSz = OUT_SIZE; -word32 ofst = 0; -int ret; - -//set up ssh and do sftp connections -... -//get handle with wolfSSH_SFTP_Open() - -if ((ret = wolfSSH_SFTP_SendWritePacket(ssh, handle, handleSz, ofst, out, outSz)) < 0) { -//handle error case -} -//ret holds the number of bytes written -``` +- 0 以上 - 成功時に読み取ったバイト数 +- 失敗時は負のエラーコード **関連項目** -wolfSSH_SFTP_SendReadPacket()
- -wolfSSH_SFTP_Open()
+- `wolfSSH_SFTP_SendWritePacket()` +- `wolfSSH_SFTP_Open()` +### wolfSSH_SFTP_SendWritePacket() -### wolfSSH_SFTP_STAT() +```c +#include -**用法** +int wolfSSH_SFTP_SendWritePacket(WOLFSSH* ssh, byte* handle, + word32 handleSz, const word32* ofst, byte* out, word32 outSz); +``` **説明** -STATパケットを相手に送信します。ファイルあるいはディレクトリの属性を取得します。ファイルが存在しないかあるいは属性が存在しない場合は相手はエラーを返します。 +`handle`(wolfSSH_SFTP_Open() から取得)が参照するファイルについて、ピアに書き込み +要求を送信し、`out` バッファの内容を書き込みます。`ofst` 引数は、書き込みを行う +ファイルオフセットを指します。 +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `handle` - 書き込み先のファイルハンドル +- `handleSz` - ハンドルバッファのサイズ +- `ofst` - 書き込みを開始するファイルオフセットへのポインター +- `out` - ピアに送信するデータのバッファ +- `outSz` - バッファのサイズ **戻り値** -**WS_SUCCESS** - 成功 +- 0 以上 - 成功時に書き込んだバイト数 +- 失敗時は負のエラーコード -**引数** +**関連項目** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `wolfSSH_SFTP_SendReadPacket()` +- `wolfSSH_SFTP_Open()` -**dir** - NULLターミネートされたファイルあるいはディレクトリ名
+### wolfSSH_SFTP_STAT() -**atr** - 属性値がこの構造体に返却されます -``` +```c #include -int wolfSSH_SFTP_STAT(WOLFSSH* ssh , char* dir, WS_SFTP_FILEATRB* atr); -``` -**使用例** +int wolfSSH_SFTP_STAT(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr); ``` -WOLFSSH* ssh; -byte name[NAME_SIZE]; -int ret; -WS_SFTP_FILEATRB atr; -//set up ssh and do sftp connections -... +**説明** -if ((ret = wolfSSH_SFTP_STAT(ssh, name, &atr)) < 0) { -//handle error case -} -``` +ファイルまたはディレクトリの属性を取得するために、ピアに STAT 要求を送信します。 +シンボリックリンクをたどります。対象が存在しない場合、ピアはエラーを返し、この関数は +エラー値を返します。 -**関連項目** +**引数** -wolfSSH_SFTP_LSTAT()
+- `ssh` - wolfSSH セッションへのポインター +- `dir` - ファイルまたはディレクトリの NULL 終端の名前 +- `atr` - 得られた属性を受け取る構造体 -wolfSSH_SFTP_connect()
+**戻り値** +- `WS_SUCCESS` +- 失敗時は負のエラーコード -### wolfSSH_SFTP_LSTAT() +**関連項目** -**用法** +- `wolfSSH_SFTP_LSTAT()` +- `wolfSSH_SFTP_SetSTAT()` -**説明** +### wolfSSH_SFTP_LSTAT() -LSTATパケットを相手に送信します。ファイルあるいはディレクトリの属性値を取得します。STATパケットがシンボリックリンクをたどりませんがLSTATパケットはシンボリックリンクをたどって処理します。ファイルが存在しないかあるいは属性が存在しない場合は相手はエラーを返します。 +```c +#include +int wolfSSH_SFTP_LSTAT(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr); +``` -**戻り値** +**説明** -**WS_SUCCESS** - 成功 +ファイルまたはディレクトリの属性を取得するために、ピアに LSTAT 要求を送信します。 +wolfSSH_SFTP_STAT() とは異なり、LSTAT はシンボリックリンクをたどらず、リンク自体の +属性を返します。対象が存在しない場合、ピアはエラーを返し、この関数はエラー値を +返します。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
- -**dir** - NULLターミネートされたファイルあるいはディレクトリ名
+- `ssh` - wolfSSH セッションへのポインター +- `dir` - ファイルまたはディレクトリの NULL 終端の名前 +- `atr` - 得られた属性を受け取る構造体 -**atr** - 属性値がこの構造体に返却されます - - -``` -#include -int wolfSSH_SFTP_LSTAT(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr); -``` -**使用例** -``` -WOLFSSH* ssh; -byte name[NAME_SIZE]; -int ret; -WS_SFTP_FILEATRB atr; - -//set up ssh and do sftp connections -... +**戻り値** -if ((ret = wolfSSH_SFTP_LSTAT(ssh, name, &atr)) < 0) { -//handle error case -} -``` +- `WS_SUCCESS` +- 失敗時は負のエラーコード **関連項目** -wolfSSH_SFTP_STAT()
+- `wolfSSH_SFTP_STAT()` +- `wolfSSH_SFTP_SetSTAT()` -wolfSSH_SFTP_connect()
+### wolfSSH_SFTP_SetSTAT() +```c +#include -### wolfSSH_SFTPNAME_free() - -**用法** +int wolfSSH_SFTP_SetSTAT(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr); +``` **説明** -単一のWS_SFTPNAMEノードを解放します。指定したノードがノードリストの途中のものであった場合には、リストは壊れます。 - -**戻り値** - -なし +`atr` の属性(例えばパーミッション、サイズ、タイムスタンプ)を指定されたファイル +またはディレクトリに適用するために、ピアに SETSTAT 要求を送信します。`atr->flags` で +フラグが設定されている属性のみが送信されます。wolfSSH v1.6.0 以降のサーバーは属性を +適用するか、`SSH_FX_OP_UNSUPPORTED` で応答します。それより前のサーバーは常に +`SSH_FX_OK` で応答していました。 **引数** -**name** - 解放されるノード - +- `ssh` - wolfSSH セッションへのポインター +- `dir` - ファイルまたはディレクトリの NULL 終端の名前 +- `atr` - 適用する属性 +**戻り値** - -``` -#include -void wolfSSH_SFTPNAME_free(WS_SFTPNAME* name ); -``` -**使用例** - -``` -WOLFSSH* ssh; -WS_SFTPNAME* name; - -//set up ssh and do sftp connections -... -name = wolfSSH_SFTP_RealPath(ssh, path); -if (name != NULL) { -wolfSSH_SFTPNAME_free(name); -} -``` +- `WS_SUCCESS` +- 失敗時は負のエラーコード **関連項目** -wolfSSH_SFTPNAME_list_free() - - -### wolfSSH_SFTPNAME_list_free() +- `wolfSSH_SFTP_STAT()` +### wolfSSH_SFTPNAME_free() +```c +#include -**用法** +void wolfSSH_SFTPNAME_free(WS_SFTPNAME* n); +``` **説明** -リスト中の全WS_SFTPNAMEノードを解放します。 +単一の `WS_SFTPNAME` ノードを解放します。ノードがリストの途中にある場合、それを解放 +するとリストが壊れます。リスト全体を解放するには wolfSSH_SFTPNAME_list_free() を使用 +してください。 +**引数** + +- `n` - 解放する `WS_SFTPNAME` ノード **戻り値** なし -**引数** - -**name** - 解放するリストの先頭 +**関連項目** +- `wolfSSH_SFTPNAME_list_free()` +### wolfSSH_SFTPNAME_list_free() -``` +```c #include -void wolfSSH_SFTPNAME_list_free(WS_SFTPNMAE* name ); -``` - -**使用例** - -``` -WOLFSSH* ssh; -WS_SFTPNAME* name; -//set up ssh and do sftp connections -... - -name = wolfSSH_SFTP_LS(ssh, path); -if (name != NULL) { -wolfSSH_SFTPNAME_list_free(name); -} +void wolfSSH_SFTPNAME_list_free(WS_SFTPNAME* n); ``` -**関連項目** - -wolfSSH_SFTPNAME_free() - - -## Reget/Reput 機能 - -### wolfSSH_SFTP_SaveOfst() - - - -**用法** - **説明** -get あるいはputコマンドが中断された場合のオフセットを保存します。オフセットはwolfSSH_SFTP_GetOfstで復元できます。 - -**戻り値** - -**WS_SUCCESS** - 成功 +wolfSSH_SFTP_LS() が返すリストのような、`WS_SFTPNAME` ノードのリスト全体を解放し +ます。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
- -**from** - NULL終端されたソースパスを示す文字列
+- `n` - 解放する `WS_SFTPNAME` リストの先頭 -**to** - NULL終端されたデスティネーションパスを示す文字列
- -**ofst** - 記憶されるべきファイルのオフセット - - - -``` -#include -int wolfSSH_SFTP_SaveOfst(WOLFSSH* ssh , char* from , char* -to , -word64 ofst ); -``` - -**使用例** - -``` -WOLFSSH* ssh; -char from[NAME_SZ]; -char to[NAME_SZ]; -word64 ofst; - -//set up ssh and do sftp connections -... +**戻り値** -if (wolfSSH_SFTP_SaveOfst(ssh, from, to, ofst) != WS_SUCCESS) { -//handle error case -} -``` +なし **関連項目** -wolfSSH_SFTP_GetOfst()
+- `wolfSSH_SFTPNAME_free()` -wolfSSH_SFTP_Interrupt()
+## Reget / Reput 関数 +### wolfSSH_SFTP_SaveOfst() -### wolfSSH_SFTP_GetOfst() +```c +#include -**用法** +int wolfSSH_SFTP_SaveOfst(WOLFSSH* ssh, char* frm, char* to, + const word32* ofst); +``` **説明** -get あるいはputコマンドが中断された場合のオフセットを取得します。 +中断された get または put の転送オフセットを、ソース(`frm`)と宛先(`to`)のパスを +キーとして保存します。保存されたオフセットは、後で wolfSSH_SFTP_GetOfst() により +取得できます。各パスは `WOLFSSH_MAX_FILENAME` バイトより短くなければなりません。 +そうでない場合は `WS_BUFFER_E` を返します。 + +**引数** +- `ssh` - wolfSSH セッションへのポインター +- `frm` - NULL 終端のソースパス +- `to` - NULL 終端の宛先パス +- `ofst` - 保存するオフセットへのポインター **戻り値** -成功時にはオフセット値を返します。オフセットが保存されていない場合には0が返されます。 - +- `WS_SUCCESS` +- 失敗時は負のエラーコード -**引数** +**関連項目** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `wolfSSH_SFTP_GetOfst()` +- `wolfSSH_SFTP_Interrupt()` -**from** - NULL終端されたソースパスを示す文字列
+### wolfSSH_SFTP_GetOfst() -**to** - NULL終端されたデスティネーションパスを示す文字列
-``` +```c #include -word64 wolfSSH_SFTP_GetOfst(WOLFSSH* ssh, char* from, char* to); -``` - -**使用例** +int wolfSSH_SFTP_GetOfst(WOLFSSH* ssh, char* frm, char* to, + word32* ofst); ``` -WOLFSSH* ssh; -char from[NAME_SZ]; -char to[NAME_SZ]; -word64 ofst; -//set up ssh and do sftp connections -... - -ofst = wolfSSH_SFTP_GetOfst(ssh, from, to); -//start reading/writing from ofst -``` +**説明** -**関連項目** +中断された get または put について、ソース(`frm`)と宛先(`to`)のパスをキーとして +保存された転送オフセットを取得し、`ofst` に書き込みます。保存されたオフセットが +見つからない場合、`ofst` は 0 に設定されます。 -wolfSSH_SFTP_SaveOfst()
+**引数** -wolfSSH_SFTP_Interrup()
+- `ssh` - wolfSSH セッションへのポインター +- `frm` - NULL 終端のソースパス +- `to` - NULL 終端の宛先パス +- `ofst` - 保存されたオフセットの出力 +**戻り値** +- `WS_SUCCESS` +- 失敗時は負のエラーコード -### wolfSSH_SFTP_ClearOfst() +**関連項目** +- `wolfSSH_SFTP_SaveOfst()` +- `wolfSSH_SFTP_Interrupt()` +### wolfSSH_SFTP_ClearOfst() -**用法** -**説明** -保存されている全オフセット値をクリアします。 +```c +#include +int wolfSSH_SFTP_ClearOfst(WOLFSSH* ssh); +``` -**戻り値** +**説明** -**WS_SUCCESS** - 成功 +セッションについて保存されているすべての転送オフセットをクリアします。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `ssh` - wolfSSH セッションへのポインター +**戻り値** -``` -#include -int wolfSSH_SFTP_ClearOfst(WOLFSSH* ssh); -``` -**使用例** +- `WS_SUCCESS` +- 失敗時は負のエラーコード **関連項目** -wolfSSH_SFTP_SaveOfst()
- -wolfSSH_SFTP_GetOfst()
- +- `wolfSSH_SFTP_SaveOfst()` +- `wolfSSH_SFTP_GetOfst()` ### wolfSSH_SFTP_Interrupt() -**用法** - -**説明** - -中断フラグをセットし、get/putコマンドを停止します。 - - -**戻り値** - -なし - -**引数** - -**ssh** – WOLFSSHオブジェクトへのポインター
- - -``` +```c #include + void wolfSSH_SFTP_Interrupt(WOLFSSH* ssh); ``` -**使用例** - -``` -WOLFSSH* ssh; +**説明** -//set up ssh and do sftp connections -... - -if (wolfSSH_SFTP_ClearOfst(ssh) != WS_SUCCESS) { -//handle error -} -``` +進行中の get または put の転送を停止するために、セッションに割り込みフラグを設定 +します。転送を後で再開できるように、現在のオフセットを wolfSSH_SFTP_SaveOfst() で +保存できます。 +**引数** -``` -WOLFSSH* ssh; -char from[NAME_SZ]; -char to[NAME_SZ]; -word64 ofst; +- `ssh` - wolfSSH セッションへのポインター -//set up ssh and do sftp connections -... +**戻り値** -wolfSSH_SFTP_Interrupt(ssh); -wolfSSH_SFTP_SaveOfst(ssh, from, to, ofst); -``` +なし **関連項目** -wolfSSH_SFTP_SaveOfst()
- -wolfSSH_SFTP_GetOfst()
+- `wolfSSH_SFTP_SaveOfst()` +- `wolfSSH_SFTP_GetOfst()` - -## コマンド機能 +## コマンド関数 @@ -846,428 +671,318 @@ wolfSSH_SFTP_GetOfst()
-**用法** - -**説明** +```c +#include -"remove"パケットをチャネルを通じて送信します。削除するファイル名"f"は相手に渡されます。 +int wolfSSH_SFTP_Remove(WOLFSSH* ssh, char* f); +``` -**戻り値** +**説明** -**WS_SUCCESS** - 成功 +`f` で指定された名前のファイルを削除するために、ピアに remove 要求を送信します。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
-**f** - 削除したいファイル名 - - -``` -#include -int wolfSSH_SFTP_Remove(WOLFSSH* ssh , char* f ); -``` - -**使用例** - -``` -WOLFSSH* ssh; -int ret; -char* name[NAME_SZ]; +- `ssh` - wolfSSH セッションへのポインター +- `f` - 削除するファイルの NULL 終端の名前 -//set up ssh and do sftp connections -... +**戻り値** -ret = wolfSSH_SFTP_Remove(ssh, name); -``` +- `WS_SUCCESS` +- 失敗時は負のエラーコード **関連項目** -wolfSSH_SFTP_accept()
- -wolfSSH_SFTP_connect()
- +- `wolfSSH_SFTP_RMDIR()` ### wolfSSH_SFTP_MKDIR() -**用法** - -**説明** - -チャネルを通して“mkdir”パケットを送信します。相手に作成するディレクトリ名が"dir"として渡されます。現時点では、属性は使用されず、既定の属性が使用されます。 +```c +#include +int wolfSSH_SFTP_MKDIR(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr); +``` -**戻り値** +**説明** -**WS_SUCCESS** - 成功 +`dir` で指定された名前のディレクトリを作成するために、ピアに mkdir 要求を送信します。 +`atr` 属性は現在使用されておらず、代わりにデフォルトの属性が適用されます。 **引数** -ssh – WOLFSSHオブジェクトへのポインター
- -dir - NULL終端された作成するディレクトリ名を示す文字列
+- `ssh` - wolfSSH セッションへのポインター +- `dir` - 作成するディレクトリの NULL 終端の名前 +- `atr` - 新しいディレクトリの属性(現在は未使用) -atr - ディレクトリ作成に使う属性値 - - -``` -#include -int wolfSSH_SFTP_MKDIR(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr); -``` - -**使用例** - -``` -WOLFSSH* ssh; -int ret; -char* dir[DIR_SZ]; - -//set up ssh and do sftp connections -... +**戻り値** -ret = wolfSSH_SFTP_MKDIR(ssh, dir, DIR_SZ); -``` +- `WS_SUCCESS` +- 失敗時は負のエラーコード **関連項目** -wolfSSH_SFTP_accept()
- -wolfSSH_SFTP_connect()
+- `wolfSSH_SFTP_RMDIR()` ### wolfSSH_SFTP_RMDIR() -**用法** - -**説明** +```c +#include -“rmdir”パケットをチャネルを通じて送信します。削除するディレクトリ名は"dir"として相手に送られます。 +int wolfSSH_SFTP_RMDIR(WOLFSSH* ssh, char* dir); +``` -**戻り値** +**説明** -**WS_SUCCESS** - 成功 +`dir` で指定された名前のディレクトリを削除するために、ピアに rmdir 要求を送信します。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `ssh` - wolfSSH セッションへのポインター +- `dir` - 削除するディレクトリの NULL 終端の名前 -**dir** - NULL終端された削除するディレクトリ名を示す文字列
- - -``` -#include -int wolfSSH_SFTP_RMDIR(WOLFSSH* ssh , char* dir ); -``` -**使用例** - -``` -WOLFSSH* ssh; -int ret; -char* dir[DIR_SZ]; - -//set up ssh and do sftp connections -... +**戻り値** -ret = wolfSSH_SFTP_RMDIR(ssh, dir); -``` +- `WS_SUCCESS` +- 失敗時は負のエラーコード **関連項目** -wolfSSH_SFTP_accept()
- -wolfSSH_SFTP_connect()
+- `wolfSSH_SFTP_MKDIR()` ### wolfSSH_SFTP_Rename() -**用法** - -**説明** - -“rename”パケットをチャネルを通じて送信します。相手側のファイル名を“old” から “nw”に変更しようとします。 +```c +#include +int wolfSSH_SFTP_Rename(WOLFSSH* ssh, const char* old, const char* nw); +``` -**戻り値** +**説明** -**WS_SUCCESS** - 成功 +ピアに rename 要求を送信し、ファイル `old` を `nw` に名前変更します。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `ssh` - wolfSSH セッションへのポインター +- `old` - 現在のファイル名 +- `nw` - 新しいファイル名 -**old** - 旧ファイル名
+**戻り値** -**nw** - 新ファイル名 +- `WS_SUCCESS` +- 失敗時は負のエラーコード +**関連項目** -``` -#include -int wolfSSH_SFTP_Rename(WOLFSSH* ssh , const char* old , const char* nw); -``` +- `wolfSSH_SFTP_Remove()` -**使用例** +### wolfSSH_SFTP_LS() -``` -WOLFSSH* ssh; -int ret; -char* old[NAME_SZ]; -char* nw[NAME_SZ]; //new file name -//set up ssh and do sftp connections -... +```c +#include -ret = wolfSSH_SFTP_Rename(ssh, old, nw); +WS_SFTPNAME* wolfSSH_SFTP_LS(WOLFSSH* ssh, char* dir); ``` -**関連項目** - -wolfSSH_SFTP_accept()
- -wolfSSH_SFTP_connect() - - -### wolfSSH_SFTP_LS() - - +**説明** -**用法** +`dir` 内のファイルとディレクトリを一覧表示します。これは REALPATH、OPENDIR、READDIR、 +CLOSE の各操作を実行する高レベルのヘルパーです。返されたリストは +wolfSSH_SFTPNAME_list_free() で解放する必要があります。 -**説明** +**引数** -LS操作(全ファイルとディレクトリのリストを取得する)を現在のワーキングディレクトリで実行します。 -この関数はREALPATH, OPENDIR, READDIR と CLOSE操作を実行する高水準関数です。 +- `ssh` - wolfSSH セッションへのポインター +- `dir` - 一覧表示するディレクトリ **戻り値** -成功時にはWS_SFTPNAME構造体のリストを返します。失敗時にはNULLを返します。 +- 成功時は `WS_SFTPNAME` 構造体のリストへのポインター +- 失敗時は `NULL` -**引数** - -**ssh** – WOLFSSHオブジェクトへのポインター
+**関連項目** -**dir** - リストを作成するディレクトリ名 +- `wolfSSH_SFTPNAME_list_free()` +- `wolfSSH_SFTP_RealPath()` +### wolfSSH_SFTP_CHMOD() -``` +```c #include -WS_SFTPNAME* wolfSSH_SFTP_LS(WOLFSSH* ssh , char* dir ); -``` +int wolfSSH_SFTP_CHMOD(WOLFSSH* ssh, char* n, char* oct); +``` +**説明** -**使用例** +ファイルまたはディレクトリ `n` のパーミッションビットを、8 進文字列 `oct`(例えば +"644")で指定されたモードに変更します。STAT 要求に続いて、新しいパーミッション +(`WOLFSSH_FILEATRB_PERM`)のみを含む SETSTAT 要求を送信することで実装されています。 +ファイルのその他の属性は再送信されません。 -``` -WOLFSSH* ssh; -int ret; -char* dir[DIR_SZ]; -WS_SFTPNAME* name; -WS_SFTPNAME* tmp; - -//set up ssh and do sftp connections -... - -name = wolfSSH_SFTP_LS(ssh, dir); -tmp = name; -while (tmp != NULL) { -printf("%s\n", tmp->fName); -tmp = tmp->next; -} -wolfSSH_SFTPNAME_list_free(name); -``` +**引数** -**関連項目** +- `ssh` - wolfSSH セッションへのポインター +- `n` - ファイルまたはディレクトリの NULL 終端の名前 +- `oct` - 8 進のパーミッション文字列(例えば "755") -wolfSSH_SFTP_accept()
+**戻り値** -wolfSSH_SFTP_connect()
+- `WS_SUCCESS` +- 失敗時は負のエラーコード -wolfSSH_SFTPNAME_list_free()
+**関連項目** +- `wolfSSH_SFTP_SetSTAT()` ### wolfSSH_SFTP_Get() -**用法** - -**説明** +```c +#include -相手からファイルを取得するget操作を実行し、ローカルディレクトリに配置します。この関数は高水準関数であり、LSTAT, OPEN, READ, とCLOSEを実行します。関数の実行を中断したい場合には、wolfSSH_SFTP_Interruptを呼び出すことができます。 +int wolfSSH_SFTP_Get(WOLFSSH* ssh, char* from, char* to, + byte resume, WS_STATUS_CB* statusCb); +``` +**説明** -**戻り値** +ピアからローカルパスへファイルをダウンロードします。これは STAT、OPEN、READ、CLOSE +の各操作を実行する高レベルのヘルパーです。進行中の転送は wolfSSH_SFTP_Interrupt() で +中断できます。 -**WS_SUCCESS** - 成功 -その他の値はすべてエラーとみなすべきです。 +`resume` が非ゼロの場合、`from` と `to` の組に対して保存されたオフセット +(wolfSSH_SFTP_SaveOfst() を参照)は、リモートファイルにそのオフセットより先の +バイトがまだあり、かつローカルファイルの長さがちょうどそのバイト数である場合にのみ +使用されます。それ以外の場合、転送は最初からやり直されます。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
+- `ssh` - wolfSSH セッションへのポインター +- `from` - 取得するリモートファイルの名前 +- `to` - ファイルを書き込むローカルパス +- `resume` - 以前に中断した転送を再開するには非ゼロ、それ以外は 0 +- `statusCb` - 転送の進捗とともに呼び出されるコールバック。または `NULL` -**from** - 取得するファイルの名前
+**戻り値** -**to** - 配置する際のファイルの名前
+- `WS_SUCCESS` +- 失敗時は負のエラーコード -**resume** - 操作を再開するか(1は再開する、0はしない)
+**関連項目** -**statusCb** - ステータスを取得するコールバック関数 +- `wolfSSH_SFTP_Put()` +- `wolfSSH_SFTP_Interrupt()` +### wolfSSH_SFTP_Put() -``` -#include -int wolfSSH_SFTP_Get(WOLFSSH* ssh , char* from , char* to , byte resume , WS_STATUS_CB* statusCb ); -``` -**使用例** +```c +#include +int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, + byte resume, WS_STATUS_CB* statusCb); ``` -static void myStatusCb(WOLFSSH* sshIn, long bytes, char* name) -{ -char buf[80]; -WSNPRINTF(buf, sizeof(buf), "Processed %8ld\t bytes -\r", bytes); -WFPUTS(buf, fout); -(void)name; -(void)sshIn; -} -... -WOLFSSH* ssh; -char* from[NAME_SZ]; -char* to[NAME_SZ]; - -//set up ssh and do sftp connections -... - -if (wolfSSH_SFTP_Get( ssh , from , to , 0 , & myStatusCb ) != WS_SUCCESS) { -//handle error case -} -``` - -**関連項目** - -wolfSSH_SFTP_accept()
- -wolfSSH_SFTP_connect()
- - -### wolfSSH_SFTP_Put() - +**説明** -**用法** +ローカルファイルをピアへアップロードします。これは OPEN、WRITE、CLOSE の各操作を +実行する高レベルのヘルパーです。進行中の転送は wolfSSH_SFTP_Interrupt() で中断でき +ます。 -**説明** +`resume` が非ゼロで、`from` と `to` の組に対してオフセットが保存されている場合、この +関数はまずリモートファイルに対して STAT 要求を送信します。保存されたオフセットは、 +ローカルファイルにそのオフセットより先のバイトがまだあり、かつリモートファイルの長さが +ちょうどそのバイト数である場合にのみ使用されます。それ以外の場合、転送は最初から +やり直されます。リモートファイルは、転送がオフセット 0 から開始する場合にのみ +`WOLFSSH_FXF_TRUNC` 付きでオープンされるため、再開された put が宛先を切り詰めることは +ありません。書き込みが拒否された場合、転送は成功を報告せずにエラーで終了します。 -ローカルのファイルを相手のディレクトリに配置するput操作を実行します。この関数は高水準関数であり、OPEN, WRITE, と CLOSE操作を実行します。操作を中断する場合にはwolfSSH_SFTP_Interruptを呼び出してください。 +**引数** +- `ssh` - wolfSSH セッションへのポインター +- `from` - 送信するローカルファイルの名前 +- `to` - ファイルを書き込むリモートパス +- `resume` - 以前に中断した転送を再開するには非ゼロ、それ以外は 0 +- `statusCb` - 転送の進捗とともに呼び出されるコールバック。または `NULL` **戻り値** -**WS_SUCCESS** - 成功
+- `WS_SUCCESS` +- 失敗時は負のエラーコード -その他の値はすべてエラーとみなすべきです。 +**関連項目** -**引数** +- `wolfSSH_SFTP_Get()` +- `wolfSSH_SFTP_Interrupt()` -**ssh** – WOLFSSHオブジェクトへのポインター
+## SFTP サーバー関数 -**from** - 配置したい対象ファイルの名前
-**to** - 配置先でのファイルの名前
-**resume** - 操作を再開するかのフラグ(1は再開、0は再開しない)
+### wolfSSH_SFTP_read() -**statusCb** - ステータスを取得するコールバック関数 -``` +```c #include -int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume, WS_STATUS_CB* statusCb); -``` -**使用例** -``` -static void myStatusCb(WOLFSSH* sshIn, long bytes, char* name) -{ -char buf[80]; -WSNPRINTF(buf, sizeof(buf), "Processed %8ld\t bytes -\r", bytes); -WFPUTS(buf, fout); -(void)name; -(void)sshIn; -} -... - -WOLFSSH* ssh; -char* from[NAME_SZ]; -char* to[NAME_SZ]; - -//set up ssh and do sftp connections -... - -if (wolfSSH_SFTP_Put(ssh, from, to, 0, &myStatusCb) != -WS_SUCCESS) { -//handle error case -} +int wolfSSH_SFTP_read(WOLFSSH* ssh); ``` -**関連項目** +**説明** -wolfSSH_SFTP_accept()
+サーバー側 SFTP のメインエントリポイントです。I/O バッファから読み取り、受信した +SFTP パケットの種類に基づいて適切な内部ハンドラーへディスパッチします。SFTP 要求を +処理するために、サーバーループからこれを呼び出します。 -wolfSSH_SFTP_connect()
+**引数** +- `ssh` - wolfSSH セッションへのポインター -## SFTPサーバー機能 +**戻り値** +- `WS_SUCCESS` +- 失敗時は負のエラーコード +**関連項目** -### wolfSSH_SFTP_read() +- `wolfSSH_SFTP_accept()` +- `wolfSSH_SFTP_PendingSend()` +### wolfSSH_SFTP_PendingSend() +```c +#include -**用法** +int wolfSSH_SFTP_PendingSend(WOLFSSH* ssh); +``` **説明** -メインのSFTPサーバー機能を提供する関数です。到着するパケットを処理し、I/O バッファからデータを読み出しSFTPパケットのタイプに応じて内部の関数を呼び出します。 - - -**戻り値** - -**WS_SUCCESS** - 成功 +SFTP レイヤーに、送信待ちのバッファされた送出データがあるかどうかを報告します。これ +は、非ブロッキング I/O を駆動する際に、もう一度送信を試みる必要があることを知るのに +役立ちます。 **引数** -**ssh** – WOLFSSHオブジェクトへのポインター
- - -``` -#include -int wolfSSH_SFTP_read(WOLFSSH* ssh ); -``` - +- `ssh` - wolfSSH セッションへのポインター -**使用例** - -``` -WOLFSSH* ssh; +**戻り値** -//set up ssh and do sftp connections -... -if (wolfSSH_SFTP_read(ssh) != WS_SUCCESS) { -//handle error case -} -``` +- 送信待ちのデータがある場合は非ゼロ +- 送信待ちのデータがない場合は 0 **関連項目** -wolfSSH_SFTP_accept()
- -wolfSSH_SFTP_connect()
+- `wolfSSH_SFTP_read()` diff --git a/wolfSSH/src-ja/chapter15.md b/wolfSSH/src-ja/chapter15.md new file mode 100644 index 00000000..1dc223d0 --- /dev/null +++ b/wolfSSH/src-ja/chapter15.md @@ -0,0 +1,383 @@ +# wolfSSH SCP API リファレンス + +この章では、wolfSSH における SCP(Secure Copy)ファイル転送のパブリック +アプリケーションプログラミングインターフェイスについて説明します。 + +この章のすべての関数を使用するには、wolfSSH を SCP サポート付き +(`WOLFSSH_SCP`、`./configure --enable-scp` により有効化)でビルドする必要が +あります。クライアント側の転送関数 wolfSSH_SCP_connect()、wolfSSH_SCP_to()、 +wolfSSH_SCP_from() は、クライアントがコンパイル対象から除外されている場合 +(`NO_WOLFSSH_CLIENT`)には利用できません。SCP はクライアントのみのビルドでも +利用できます。 + +## SCP 転送関数 + +### wolfSSH_SCP_connect() + +```c +#include + +int wolfSSH_SCP_connect(WOLFSSH* ssh, byte* cmd); +``` + +**説明** + +確立済みの SSH 接続上で、SCP コマンド `cmd` をサーバーに送信して SCP セッション +を開始します。ファイルを転送する前に、クライアント側で呼び出します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `cmd` - サーバーに送信する SCP コマンド + +**戻り値** + +- `WS_SUCCESS` +- 失敗時は負のエラーコード + +**関連項目** + +- `wolfSSH_SCP_to()` +- `wolfSSH_SCP_from()` + +### wolfSSH_SCP_to() + +```c +#include + +int wolfSSH_SCP_to(WOLFSSH* ssh, const char* src, const char* dst); +``` + +**説明** + +ローカルのファイルまたはディレクトリ `src` を、SSH 接続を通じてリモートの宛先 +`dst` に送信(アップロード)します。クライアント側で呼び出します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `src` - ローカルのソースファイルまたはディレクトリのパス +- `dst` - リモートピア上の宛先パス + +**戻り値** + +- `WS_SUCCESS` +- 失敗時は負のエラーコード + +**関連項目** + +- `wolfSSH_SCP_from()` +- `wolfSSH_SCP_connect()` + +### wolfSSH_SCP_from() + +```c +#include + +int wolfSSH_SCP_from(WOLFSSH* ssh, const char* src, const char* dst); +``` + +**説明** + +リモートのファイルまたはディレクトリ `src` をピアから取得(ダウンロード)し、 +SSH 接続を通じてローカルの宛先 `dst` に書き込みます。クライアント側で呼び出し +ます。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `src` - リモートピア上のソースファイルまたはディレクトリのパス +- `dst` - ローカルシステム上の宛先パス + +**戻り値** + +- `WS_SUCCESS` +- 失敗時は負のエラーコード + +**関連項目** + +- `wolfSSH_SCP_to()` +- `wolfSSH_SCP_connect()` + +### wolfSSH_SCP_accept() + +```c +#include + +int wolfSSH_SCP_accept(WOLFSSH* ssh); +``` + +**説明** + +サーバー側の関数です。"exec scp ..." コマンドがすでにバインドされたチャネルを持つ +セッション上で SCP 転送を実行します。これは、wolfSSH_accept() が `WS_SCP_INIT` を +返した後に再度呼び出されたときに行う処理と同じです。この関数は、アプリケーション駆動 +チャネルを使用するアプリケーションなど、`scp` コマンドを自身でチャネルにバインドする +アプリケーションが転送を開始できるように公開されています。1 つの転送に対しては、 +この関数か wolfSSH_accept() の経路のどちらか一方のみを使用し、両方を使用しないで +ください。 + +wolfSSH_accept() が戻り、exec チャネル要求コールバックが SCP コマンドを報告した後に +呼び出してください。そのコールバックの内部からは呼び出さないでください。 +wolfSSH_SFTP_accept() と同様に、セッションのチャネルリストの最初のチャネルに対して +動作します。SCP 受信コールバックが設定されている必要があります。 +`WOLFSSH_SCP_USER_CALLBACKS` が定義されていない限り、新しいコンテキストには +デフォルトのコールバックがインストールされます。 + +ノンブロッキングソケットでは、転送が途中の状態で `WS_WANT_READ` または +`WS_WANT_WRITE` を返します。`WS_SCP_COMPLETE` を返すまで、同じセッションに対して +再度呼び出してください。セッションに記録された保留中の `WS_WANT_READ` または +`WS_WANT_WRITE` は、各呼び出しの開始時にクリアされます。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- 転送が完了した場合は `WS_SCP_COMPLETE` +- 転送を再開する必要がある場合は `WS_WANT_READ` または `WS_WANT_WRITE` +- `ssh` が `NULL` の場合、または SCP 受信コールバックが設定されていない場合は + `WS_BAD_ARGUMENT` +- 失敗時は負のエラーコード + +**関連項目** + +- `wolfSSH_ChannelCommandIsScp()` +- `wolfSSH_SetScpRecv()` +- `wolfSSH_SetScpSend()` + +### wolfSSH_ChannelCommandIsScp() + +```c +#include + +int wolfSSH_ChannelCommandIsScp(const WOLFSSH_CHANNEL* channel); +``` + +**説明** + +`channel` に記録されたセッションコマンドが SCP 転送を開始するものかどうかを報告 +します。exec チャネル要求コールバックから使用することを想定しています。 +wolfSSH_accept() も同じ判定を使用するため、何が転送を開始するかについて +アプリケーションとライブラリの判断が食い違うことはありません。 + +コマンドは、独立したトークンとしての "scp" で始まる必要があります。つまり、コマンド +全体が "scp" であるか、"scp" の後に空白が続く必要があります。"scpbackup" のような +単純なプレフィックス一致は SCP コマンドではありません。判定は文字列長ではなく記録 +されたコマンドサイズを対象とし、そのサイズ内のどこかに NUL バイトを含むコマンドは +SCP コマンドとして扱われません。転送を処理するパーサーは C 文字列を読み取るため、 +残りの部分を黙って切り捨ててしまうからです。 + +**引数** + +- `channel` - セッションコマンドを判定するチャネル + +**戻り値** + +- コマンドが SCP 転送を開始する場合は 1 +- 開始しない場合は 0(チャネルにコマンドがない場合を含む) +- `channel` が `NULL` の場合は `WS_BAD_ARGUMENT` + +**関連項目** + +- `wolfSSH_SCP_accept()` + +### wolfSSH_SetScpErrorMsg() + +```c +#include + +int wolfSSH_SetScpErrorMsg(WOLFSSH* ssh, const char* message); +``` + +**説明** + +セッションにカスタムのエラーメッセージ文字列を設定します。この文字列は、SCP 転送 +が失敗したときにピアへ報告されます。SCP コールバックの内部から呼び出すことを想定 +しています。メッセージはコピーされるため、`message` の所有権は呼び出し元が保持します。 +後の呼び出しは以前のメッセージを置き換えます。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `message` - 報告する NULL 終端のエラーメッセージ + +**戻り値** + +- `WS_SUCCESS` +- `ssh` または `message` が `NULL` の場合は `WS_BAD_ARGUMENT` +- コピーのためのメモリを確保できない場合は `WS_MEMORY_E` + +## SCP コールバック + +アプリケーションが管理するストレージで SCP を使用する場合(例えばファイルシステム +のないシステム上や、転送をフィルタリングする場合)、アプリケーションは送信および +受信のコールバックを登録します。各コールバックにはユーザーコンテキストポインター +を渡すことができます。 + +### wolfSSH_SetScpRecv() + +```c +#include + +void wolfSSH_SetScpRecv(WOLFSSH_CTX* ctx, WS_CallbackScpRecv cb); +``` + +**説明** + +コンテキストに SCP 受信コールバックを登録します。このコールバックは受信ファイル +が受け取られる際に呼び出され、アプリケーション自身がデータを保存できるようにし +ます。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - SCP 受信コールバック + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_SetScpRecvCtx()` +- `wolfSSH_SetScpSend()` + +### wolfSSH_SetScpSend() + +```c +#include + +void wolfSSH_SetScpSend(WOLFSSH_CTX* ctx, WS_CallbackScpSend cb); +``` + +**説明** + +コンテキストに SCP 送信コールバックを登録します。このコールバックはピアがファイル +を要求した際に呼び出され、アプリケーション自身がデータを供給できるようにします。 + +コールバックは、`buf` に格納したバイト数、`WS_SCP_*` ステータスコードのいずれか、 +または転送を中止するための負のエラーを返します。引数 `fileNameSz` は `fileName` +バッファの容量であり、すでに格納されている名前の長さではありません。0 を返すことが +有効なのは、データの準備が整う前にファイルのメタデータ(名前、モード、時刻、 +`totalFileSz`)を設定する呼び出しの場合のみです。その場合、ライブラリはファイル +ヘッダーを送信し、`WOLFSSH_SCP_CONTINUE_FILE_TRANSFER` を指定してコールバックを再度 +呼び出します。`fileOffset` が `totalFileSz` に達していない状態で 2 回続けて 0 が +返されると、コールバックが停止したものとみなされ、転送は中止されます。API には +"現時点ではデータなし" を表すステータスがないためです。データを待つ必要がある +コールバックは、0 を返すのではなくブロックしてください。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cb` - SCP 送信コールバック + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_SetScpSendCtx()` +- `wolfSSH_SetScpRecv()` + +### wolfSSH_SetScpRecvCtx() + +```c +#include + +void wolfSSH_SetScpRecvCtx(WOLFSSH* ssh, void* ctx); +``` + +**説明** + +SCP 受信コールバックに渡されるユーザーコンテキストポインターを設定します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - 受信コールバックに渡すユーザーコンテキストポインター + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_GetScpRecvCtx()` + +### wolfSSH_SetScpSendCtx() + +```c +#include + +void wolfSSH_SetScpSendCtx(WOLFSSH* ssh, void* ctx); +``` + +**説明** + +SCP 送信コールバックに渡されるユーザーコンテキストポインターを設定します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - 送信コールバックに渡すユーザーコンテキストポインター + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_GetScpSendCtx()` + +### wolfSSH_GetScpRecvCtx() + +```c +#include + +void* wolfSSH_GetScpRecvCtx(WOLFSSH* ssh); +``` + +**説明** + +wolfSSH_SetScpRecvCtx() で以前に設定されたユーザーコンテキストポインターを返し +ます。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- SCP 受信コンテキストポインター。設定されていない場合は `NULL` + +**関連項目** + +- `wolfSSH_SetScpRecvCtx()` + +### wolfSSH_GetScpSendCtx() + +```c +#include + +void* wolfSSH_GetScpSendCtx(WOLFSSH* ssh); +``` + +**説明** + +wolfSSH_SetScpSendCtx() で以前に設定されたユーザーコンテキストポインターを返し +ます。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- SCP 送信コンテキストポインター。設定されていない場合は `NULL` + +**関連項目** + +- `wolfSSH_SetScpSendCtx()` diff --git a/wolfSSH/src-ja/chapter16.md b/wolfSSH/src-ja/chapter16.md new file mode 100644 index 00000000..04a97de9 --- /dev/null +++ b/wolfSSH/src-ja/chapter16.md @@ -0,0 +1,1177 @@ +# wolfSSH 追加 API リファレンス + +この章では、wolfSSH の残りのパブリックインターフェイス、すなわち ssh-agent +フォワーディング、鍵生成、ロギング、証明書マネージャー(Windows 証明書ストアの +ヘルパーを含む)、およびプラットフォーム移植レイヤーについて説明します。 + +## SSH エージェント関数 + +これらの関数は ssh-agent フォワーディングをサポートします。使用するには、wolfSSH +をエージェントサポート付き(`WOLFSSH_AGENT`、`./configure --enable-agent` により +有効化)でビルドする必要があります。 + +### wolfSSH_AGENT_new() + +```c +#include + +WOLFSSH_AGENT_CTX* wolfSSH_AGENT_new(void* heap); +``` + +**説明** + +新しい ssh-agent コンテキストを割り当て、その乱数生成器を含めて初期化します。 + +**引数** + +- `heap` - メモリ割り当てに使用するヒープへのポインター。または `NULL` + +**戻り値** + +- 新しいエージェントコンテキストへのポインター。割り当てまたは乱数生成器の初期化に + 失敗した場合は `NULL` + +**関連項目** + +- `wolfSSH_AGENT_free()` + +### wolfSSH_AGENT_free() + +```c +#include + +void wolfSSH_AGENT_free(WOLFSSH_AGENT_CTX* agent); +``` + +**説明** + +wolfSSH_AGENT_new() で以前に割り当てられた ssh-agent コンテキストを解放します。 + +**引数** + +- `agent` - 解放するエージェントコンテキスト + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_AGENT_new()` + +### wolfSSH_CTX_set_agent_cb() + +```c +#include + +int wolfSSH_CTX_set_agent_cb(WOLFSSH_CTX* ctx, + WS_CallbackAgent agentCb, WS_CallbackAgentIO agentIoCb); +``` + +**説明** + +コンテキストにエージェントコールバックとエージェント I/O コールバックを登録し +ます。これらのコールバックにより、アプリケーションはエージェント要求を処理し、 +エージェント I/O を実行できます。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `agentCb` - エージェントコールバック +- `agentIoCb` - エージェント I/O コールバック + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +**関連項目** + +- `wolfSSH_set_agent_cb_ctx()` + +### wolfSSH_set_agent_cb_ctx() + +```c +#include + +int wolfSSH_set_agent_cb_ctx(WOLFSSH* ssh, void* ctx); +``` + +**説明** + +エージェントコールバックに渡されるユーザーコンテキストポインターを設定します。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `ctx` - エージェントコールバックに渡すユーザーコンテキストポインター + +**戻り値** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_CTX_AGENT_enable() + +```c +#include + +int wolfSSH_CTX_AGENT_enable(WOLFSSH_CTX* ctx, byte isEnabled); +``` + +**説明** + +コンテキストから作成されるセッションについて、ssh-agent フォワーディングを有効 +または無効にします。各セッションは、作成時にこの設定をコピーします。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `isEnabled` - エージェントフォワーディングを有効にするには非ゼロ、無効にする + には 0 + +**戻り値** + +- `WS_SUCCESS` +- `ctx` が `NULL` の場合は `WS_SSH_CTX_NULL_E` + +**関連項目** + +- `wolfSSH_AGENT_enable()` + +### wolfSSH_AGENT_enable() + +```c +#include + +int wolfSSH_AGENT_enable(WOLFSSH* ssh, byte isEnabled); +``` + +**説明** + +単一のセッションについて、ssh-agent フォワーディングを有効または無効にします。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `isEnabled` - エージェントフォワーディングを有効にするには非ゼロ、無効にする + には 0 + +**戻り値** + +- `WS_SUCCESS` +- `ssh` が `NULL` の場合は `WS_SSH_NULL_E` + +**関連項目** + +- `wolfSSH_CTX_AGENT_enable()` + +### wolfSSH_AGENT_ChannelOpen() + +```c +#include + +int wolfSSH_AGENT_ChannelOpen(WOLFSSH* ssh); +``` + +**説明** + +サーバー側の関数です。クライアントの "auth-agent-req@openssh.com" チャネル要求で +エージェントフォワーディングが要求された後、クライアントへの +"auth-agent@openssh.com" チャネルをオープンします。サーバーがその要求を受け付けるのは、 +wolfSSH_CTX_set_agent_cb() でエージェントコールバックが設定されている場合のみです。 +デフォルトの経路では、wolfSSH_accept() 自身がチャネルをオープンします。自身でチャネルを +駆動するアプリケーション(wolfSSH_CTX_SetAppChannels() を参照)は、代わりにこの関数を +ポーリングします。 + +この関数はセッションごとに最大 1 つのチャネルをオープンします。チャネルがオープンされた +後の呼び出しは、キューに残っている出力をフラッシュするだけです。成功時には、 +`WOLFSSH_AGENT_LOCAL_SETUP` を指定してエージェントコールバックを呼び出します。 +`WS_SUCCESS` はオープン要求が送信されたことを意味し、ピアがそれを受け入れたことを +意味するものではありません。拒否はチャネルオープン失敗コールバックに報告されます。 +オープン要求の送信後に(例えばハイウォーターコールバックの失敗によって)エラーが発生 +した場合でも、チャネルはオープンされたままとなり、次の呼び出しは `WS_SUCCESS` を +返します。 + +結果を `ssh->error` に記録するのは送信経路のみです。ピアがフォワーディングを要求する +前に呼び出された場合は、エラーを記録せずに `WS_BAD_ARGUMENT` を返すため、そのセッション +を引き続き wolfSSH_accept() に渡すことができます。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター + +**戻り値** + +- チャネルオープンが送信された場合は `WS_SUCCESS` +- 出力がまだキューに残っている間は `WS_WANT_READ` または `WS_WANT_WRITE`。再度 + 呼び出してください +- クライアントセッションの場合、またはピアがエージェントフォワーディングを要求する + 前の場合は `WS_BAD_ARGUMENT` +- セッションが切断された後は `WS_FATAL_ERROR`(`ssh->error` は `WS_DISCONNECT` を + 保持します) +- `ssh` が `NULL` の場合は `WS_SSH_NULL_E` +- エージェントコンテキストまたはチャネルを割り当てられない場合は `WS_MEMORY_E` +- 送信によって報告されたその他の負のエラーコード + +**関連項目** + +- `wolfSSH_AGENT_RelayChannel()` +- `wolfSSH_CTX_set_agent_cb()` + +### wolfSSH_AGENT_Relay() + +```c +#include + +int wolfSSH_AGENT_Relay(WOLFSSH* ssh, + const byte* msg, word32* msgSz, byte* rsp, word32* rspSz); +``` + +**説明** + +1 つのエージェントプロトコルメッセージをローカルエージェントへ中継し、エージェントの +応答を返します。`msg` 内のメッセージは、エージェント I/O コールバックを通じてそのまま +エージェントに書き込まれるため、4 バイトの長さプレフィックスを含む完全なエージェント +メッセージである必要があります。何も書き込めなかった場合、この関数は再接続のために +`WOLFSSH_AGENT_LOCAL_SETUP` を指定してエージェントコールバックを呼び出し、もう一度だけ +試みます。その後、4 バイトの長さプレフィックスを含むエージェントの応答全体を 1 つ +読み取り、`rsp` にコピーします。入力時 `rspSz` は `rsp` バッファのサイズを保持し、 +出力時には書き込まれた応答のサイズを保持します。長さが 0、または +`WOLFSSH_AGENT_MAX_MSG_SZ`(デフォルトでは 262144 バイト)を超えると宣言された応答は +拒否されます。 + +セッションはエージェントコンテキストを持っている必要があります。クライアント側では、 +エージェントフォワーディングが有効な場合に wolfSSH_connect() がこれを作成します。 +データが分割されて到着するエージェントチャネルには、代わりに +wolfSSH_AGENT_RelayChannel() を使用してください。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `msg` - 中継するエージェントメッセージ +- `msgSz` - メッセージのサイズへのポインター +- `rsp` - エージェントの応答を受け取るバッファ +- `rspSz` - 入力時は応答バッファのサイズ、出力時は応答のサイズが設定される + +**戻り値** + +- `WS_SUCCESS` +- 何らかの失敗時は `WS_ERROR`。`ssh` が `NULL` でない場合、具体的なエラーはセッション + に保存され、wolfSSH_get_error() で取得できます。考えられるエラーには + `WS_AGENT_NULL_E`(エージェントコンテキストがない)、`WS_BAD_ARGUMENT`、 + `WS_AGENT_CXN_FAIL`(エージェント I/O が失敗した)、`WS_BUFFER_E`(応答が範囲外、 + または `rsp` に収まらない)があります。 + +**関連項目** + +- `wolfSSH_AGENT_RelayChannel()` + +### wolfSSH_AGENT_RelayChannel() + +```c +#include + +int wolfSSH_AGENT_RelayChannel(WOLFSSH* ssh, word32 channelId); +``` + +**説明** + +フォワードされたエージェントチャネル `channelId` とローカルエージェントとの間で、 +完全なエージェントメッセージを受け渡します。各呼び出しでは、すでにバッファリング +されているチャネルデータを読み取り、それを完全なエージェントメッセージに区切り、各 +メッセージをエージェント I/O コールバックを通じてエージェントに書き込み、各応答を +チャネル上で送り返します。不完全な要求や未完了の応答は呼び出し間で保持されるため、 +いずれかを完了するには同じ `channelId` を再度渡す必要があります。異なる `channelId` +が渡された場合、以前のチャネル用に保持されていたバイトは破棄されます。エージェント +コンテキストがまだ初期状態の場合、この関数はまず `WOLFSSH_AGENT_LOCAL_SETUP` を指定 +してエージェントコールバックを呼び出します。 + +一般的なクライアントは、読み取りがエージェントチャネルについて `WS_CHAN_RXD` を報告 +したとき(チャネル ID は wolfSSH_GetLastRxId() から取得できます)にこの関数を呼び +出し、応答がまだ未送信である間は再度呼び出します。 + +応答が未送信の間、戻り値はそれを妨げているものを示します。`WS_WANT_WRITE` は +トランスポートを、`WS_WINDOW_FULL` または `WS_REKEYING` はピアを意味します。 +`WS_SUCCESS` を返すまで、この関数を再度呼び出してください。それ以外の成功以外の +コードが返された場合、チャネルは使用できなくなります。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `channelId` - エージェントチャネルのローカル ID + +**戻り値** + +- バッファリングされたすべての要求が中継され、その応答が送信された場合は + `WS_SUCCESS` +- 応答がまだ未送信である間は `WS_WANT_WRITE`、`WS_WINDOW_FULL`、または + `WS_REKEYING`。再度呼び出してください +- `ssh` が `NULL` の場合は `WS_SSH_NULL_E` +- セッションにエージェントコンテキストがない場合は `WS_AGENT_NULL_E` +- エージェントへの接続またはエージェント I/O が失敗した場合は `WS_AGENT_CXN_FAIL` +- メッセージが宣言する長さが 0、または `WOLFSSH_AGENT_MAX_MSG_SZ` を超える場合は + `WS_BUFFER_E` +- 指定された ID のチャネルがない場合は `WS_INVALID_CHANID` +- 失敗時はその他の負のエラーコード + +**関連項目** + +- `wolfSSH_AGENT_Relay()` +- `wolfSSH_AGENT_ChannelOpen()` + +### wolfSSH_AGENT_SignRequest() + +```c +#include + +int wolfSSH_AGENT_SignRequest(WOLFSSH* ssh, + const byte* digest, word32 digestSz, + byte* sig, word32* sigSz, + const byte* keyBlob, word32 keyBlobSz, word32 flags); +``` + +**説明** + +`keyBlob` で識別される鍵を使用して、指定された `digest` に署名するようエージェント +に要求します。生成された署名は `sig` に書き込まれます。この関数は、要求の前に +`WOLFSSH_AGENT_LOCAL_SETUP` を、要求の後に `WOLFSSH_AGENT_LOCAL_CLEANUP` を指定して +エージェントコールバックを呼び出し、エージェント I/O コールバックを使用して要求と +応答をやり取りします。失敗時には `*sigSz` は 0 に設定されます。 + +**引数** + +- `ssh` - wolfSSH セッションへのポインター +- `digest` - 署名するダイジェスト +- `digestSz` - ダイジェストのサイズ +- `sig` - 署名を受け取るバッファ +- `sigSz` - 入力時は署名バッファのサイズ、出力時は署名のサイズが設定される +- `keyBlob` - どの鍵で署名するかを識別する公開鍵ブロブ +- `keyBlobSz` - 鍵ブロブのサイズ +- `flags` - 署名要求のフラグ + +**戻り値** + +- `WS_SUCCESS` +- `ssh` が `NULL` の場合は `WS_SSH_NULL_E` +- セッションにエージェントコンテキストがない場合は `WS_AGENT_NULL_E` +- `sigSz` が `NULL` の場合は `WS_BAD_ARGUMENT` +- 応答バッファを割り当てられない場合は `WS_MEMORY_E` +- 要求をエージェントに書き込めなかった場合は `WS_AGENT_CXN_FAIL` +- エージェントが応答を返さない場合、署名ではない応答を返した場合、または失敗を + 返した場合は `WS_AGENT_NO_KEY_E` +- 署名が `sig` に収まらない場合は `WS_BUFFER_E` +- 失敗時はその他の負のエラーコード + +## 鍵生成関数 + +これらの関数は SSH 鍵ペアを生成します。使用するには、wolfSSH を鍵生成サポート付き +(`WOLFSSH_KEYGEN`、`./configure --enable-keygen` により有効化)でビルドし、 +wolfSSL を鍵生成付き(`WOLFSSL_KEY_GEN`)でビルドする必要があります。対応する +アルゴリズムも有効になっている必要があり、有効でない場合、関数は `WS_NOT_COMPILED` +を返します。wolfCrypt 内部での失敗は `WS_CRYPTO_FAILED` として報告されます。 + +ML-DSA 関数を使用するには、ML-DSA サポート付きでビルドされた wolfSSL 5.9.2 以降が +必要です。 + +### wolfSSH_MakeRsaKey() + +```c +#include + +int wolfSSH_MakeRsaKey(byte* out, word32 outSz, word32 size, word32 e); +``` + +**説明** + +公開指数 `e` を使用して `size` ビットの RSA 鍵ペアを生成し、DER エンコードされた +秘密鍵を `out` に書き込みます。 + +**引数** + +- `out` - 生成された鍵を受け取るバッファ +- `outSz` - 出力バッファのサイズ +- `size` - RSA 鍵のサイズ(ビット単位、例えば 2048) +- `e` - RSA 公開指数(例えば 65537) + +**戻り値** + +- 成功時は書き込まれたバイト数 +- RSA が無効な場合は `WS_NOT_COMPILED` +- 鍵の生成またはエンコードに失敗した場合は `WS_CRYPTO_FAILED` + +**関連項目** + +- `wolfSSH_MakeEcdsaKey()` + +### wolfSSH_MakeEcdsaKey() + +```c +#include + +int wolfSSH_MakeEcdsaKey(byte* out, word32 outSz, word32 size); +``` + +**説明** + +指定された `size`(ビット単位、例えば NIST P-256 の場合 256)の曲線に対する ECDSA +鍵ペアを生成し、DER エンコードされた秘密鍵を `out` に書き込みます。 + +**引数** + +- `out` - 生成された鍵を受け取るバッファ +- `outSz` - 出力バッファのサイズ +- `size` - ECC 曲線のサイズ(ビット単位、例えば 256、384、または 521) + +**戻り値** + +- 成功時は書き込まれたバイト数 +- ECDSA が無効な場合は `WS_NOT_COMPILED` +- 鍵の生成またはエンコードに失敗した場合は `WS_CRYPTO_FAILED` + +**関連項目** + +- `wolfSSH_MakeRsaKey()` +- `wolfSSH_MakeEd25519Key()` + +### wolfSSH_MakeEd25519Key() + +```c +#include + +int wolfSSH_MakeEd25519Key(byte* out, word32 outSz, word32 size); +``` + +**説明** + +Ed25519 鍵ペアを生成し、DER エンコードされた秘密鍵を `out` に書き込みます。 + +**引数** + +- `out` - 生成された鍵を受け取るバッファ +- `outSz` - 出力バッファのサイズ +- `size` - 鍵のサイズ(ビット単位、Ed25519 の場合 256) + +**戻り値** + +- 成功時は書き込まれたバイト数 +- Ed25519 の鍵生成が利用できない場合は `WS_NOT_COMPILED` +- 鍵の生成またはエンコードに失敗した場合は `WS_CRYPTO_FAILED` + +**関連項目** + +- `wolfSSH_MakeEcdsaKey()` + +### wolfSSH_MakeMlDsaKey() + +```c +#include + +int wolfSSH_MakeMlDsaKey(byte* out, word32 outSz, word32 level); +``` + +**説明** + +指定されたセキュリティレベルで ML-DSA(FIPS 204)鍵ペアを生成し、DER エンコード +された秘密鍵を `out` に書き込みます。 + +**引数** + +- `out` - 生成された鍵を受け取るバッファ +- `outSz` - 出力バッファのサイズ +- `level` - ML-DSA パラメーターセット: `WOLFSSH_MLDSAKEY_44`、 + `WOLFSSH_MLDSAKEY_65`、または `WOLFSSH_MLDSAKEY_87` + +**戻り値** + +- 成功時は書き込まれたバイト数 +- `level` が上記の値のいずれでもない場合は `WS_BAD_ARGUMENT` +- ML-DSA が利用できない場合は `WS_NOT_COMPILED` +- スモールスタック用のメモリ割り当てに失敗した場合は `WS_MEMORY_E` +- 鍵の生成またはエンコードに失敗した場合は `WS_CRYPTO_FAILED` + +**関連項目** + +- `wolfSSH_MakeMlDsaCompositeKey()` + +### wolfSSH_MakeMlDsaCompositeKey() + +```c +#include + +int wolfSSH_MakeMlDsaCompositeKey(byte* out, word32 outSz, + word32 level, word32 tradType); +``` + +**説明** + +ML-DSA 鍵と従来型の署名鍵を組み合わせたコンポジット鍵ペアを生成します。結果は、 +NUL 終端された暗号化なしの PEM 形式の OpenSSH 秘密鍵 +("-----BEGIN OPENSSH PRIVATE KEY-----")として、空のコメント付きで `out` に書き込ま +れます。ML-DSA 側はシードとして格納されます。 + +`level` と `tradType` の組み合わせとして受け付けられるのは、次のもののみです。 + +- `WOLFSSH_MLDSAKEY_44` と `WOLFSSH_COMPOSITE_TRAD_ED25519` または + `WOLFSSH_COMPOSITE_TRAD_ECDSA`(NIST P-256) +- `WOLFSSH_MLDSAKEY_65` と `WOLFSSH_COMPOSITE_TRAD_ED25519` または + `WOLFSSH_COMPOSITE_TRAD_ECDSA`(NIST P-256) +- `WOLFSSH_MLDSAKEY_87` と `WOLFSSH_COMPOSITE_TRAD_ED448` または + `WOLFSSH_COMPOSITE_TRAD_ECDSA`(NIST P-384) + +必要なバッファサイズを問い合わせるには、`out` に `NULL` を渡します。 + +**引数** + +- `out` - PEM エンコードされた鍵を受け取るバッファ。またはサイズを問い合わせる場合は + `NULL` +- `outSz` - 出力バッファのサイズ +- `level` - ML-DSA パラメーターセット: `WOLFSSH_MLDSAKEY_44`、 + `WOLFSSH_MLDSAKEY_65`、または `WOLFSSH_MLDSAKEY_87` +- `tradType` - 従来型アルゴリズム: `WOLFSSH_COMPOSITE_TRAD_ECDSA`、 + `WOLFSSH_COMPOSITE_TRAD_ED25519`、または `WOLFSSH_COMPOSITE_TRAD_ED448` + +**戻り値** + +- 成功時は、終端の NUL を含む書き込まれたバイト数 +- `out` が `NULL` の場合は、終端の NUL を含む必要なバッファサイズ +- `level` と `tradType` の組み合わせがサポートされていない場合は `WS_BAD_ARGUMENT` +- ML-DSA または要求されたコンポジットアルゴリズムがコンパイルされていない場合は + `WS_NOT_COMPILED` +- `outSz` が小さすぎる場合は `WS_BUFFER_E` +- メモリ割り当てに失敗した場合は `WS_MEMORY_E` +- 鍵の生成またはエンコードに失敗した場合は `WS_CRYPTO_FAILED` + +**関連項目** + +- `wolfSSH_MakeMlDsaKey()` + +## ロギング関数 + +これらの関数は wolfSSH のデバッグロギングを制御します。ロギングのコードは、wolfSSH +を `DEBUG_WOLFSSH`(`./configure --enable-debug` により有効化)または `WOLFSSH_SSHD` +付きでビルドした場合にコンパイルされます。 + +### wolfSSH_SetLoggingCb() + +```c +#include + +void wolfSSH_SetLoggingCb(wolfSSH_LoggingCb logF); +``` + +**説明** + +デフォルトのロギング出力の代わりに、ログメッセージをそのログレベルおよびメッセージ +テキストとともに受け取るコールバックを登録します。`NULL` を渡すと、現在の +コールバックがそのまま維持されます。`WOLFSSH_NO_DEFAULT_LOGGING_CB` 付きのビルドには +デフォルトのコールバックがないため、コールバックが登録されるまで何も出力されません。 + +**引数** + +- `logF` - ロギングコールバック + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_LogEnabled()` + +### wolfSSH_LogEnabled() + +```c +#include + +int wolfSSH_LogEnabled(void); +``` + +**説明** + +現在ロギングが有効かどうかを報告します。ロギングはデフォルトでは無効であり、 +wolfSSH_Debugging_ON() で有効になります。ロギングサポートなしのビルドでは常に 0 を +返します。 + +**引数** + +なし + +**戻り値** + +- ロギングが有効な場合は非ゼロ +- ロギングが無効な場合は 0 + +### wolfSSH_Log() + +```c +#include + +void wolfSSH_Log(enum wolfSSH_LogLevel level, const char* const fmt, ...); +``` + +**説明** + +指定されたレベルで printf 形式のフォーマット済みログメッセージを書き込みます。 +ログレベルは、低いものから高いものへ順に `WS_LOG_DEBUG`、`WS_LOG_INFO`、 +`WS_LOG_WARN`、`WS_LOG_ERROR`、`WS_LOG_USER`、およびサブシステムごとのレベル +`WS_LOG_SFTP`、`WS_LOG_SCP`、`WS_LOG_AGENT`、`WS_LOG_CERTMAN` です。 + +フォーマットされたメッセージは `WOLFSSH_DEFAULT_LOG_WIDTH` バイト(デフォルトでは +終端の NUL を含めて 120)に切り詰められます。メッセージがロギングコールバックに渡さ +れる前に、タブ以外の制御文字および DEL は `?` に置き換えられます。そのため、`%s` で +ログに出力される信頼できない文字列によって、ログに改行や端末エスケープシーケンスが +挿入されることはありません。 + +**引数** + +- `level` - メッセージの `wolfSSH_LogLevel` +- `fmt` - printf 形式のフォーマット文字列 +- `...` - フォーマット文字列に対する引数 + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_SetLoggingCb()` + +## 証明書マネージャー関数 + +証明書マネージャーは、証明書ベースの認証のために X.509 証明書を検証します。これ +らの関数を使用するには、wolfSSH を証明書サポート付き(`WOLFSSH_CERTS`、 +`./configure --enable-certs` により有効化)でビルドする必要があります。 + +### wolfSSH_SetCertManager() + +```c +#include + +int wolfSSH_SetCertManager(WOLFSSH_CTX* ctx, struct WOLFSSL_CERT_MANAGER* cm); +``` + +**説明** + +コンテキストが使用する wolfSSL 証明書マネージャーを `cm` に置き換えます。この関数は +`cm` への参照を取得し、以前のマネージャーへの参照を解放します。呼び出し元は自身の +参照を保持し、引き続きその解放に責任を持ちます。 + +wolfSSH は共有されたマネージャーを変更します。OCSP サポート付き(`HAVE_OCSP`)の +ビルドでは、`cm` に対して `WOLFSSL_OCSP_CHECKALL` を有効にするため、そのマネージャーを +TLS にも使用する呼び出し元では、すべてのチェーンで OCSP 応答が必要になります。証明書 +認証の際、wolfSSH は検証済みのピアの中間 CA を、信頼されたルートとしてマネージャーに +永続的に追加します。稼働中の TLS スタックと共有するマネージャーではなく、wolfSSH 専用 +のマネージャーを使用してください。 + +すでに使用中のマネージャーを渡すと、OCSP ポリシーが再度適用されるだけで、それ以外は +何も変わりません。`WS_FATAL_ERROR` の場合は何も変更されていません。コンテキストは +以前のマネージャーを保持し、`cm` にはポリシーが適用されていません。 + +**利用可能性** + +wolfSSH を証明書サポート付き(`WOLFSSH_CERTS`)でビルドする必要があります。 +wolfSSL 4.6.0 以降が必要です。それより古いバージョンでは、この関数は引数にかかわらず +`WS_NOT_COMPILED` を返します。 + +**引数** + +- `ctx` - wolfSSH コンテキストへのポインター +- `cm` - 使用する wolfSSL 証明書マネージャー + +**戻り値** + +- `WS_SUCCESS` +- `ctx` または `cm` が `NULL` の場合、あるいはコンテキストが証明書マネージャーを + 持たない場合は `WS_BAD_ARGUMENT` +- 参照を取得できない場合、または `cm` で OCSP を有効にできない場合は + `WS_FATAL_ERROR` +- wolfSSL が 4.6.0 より古い場合は `WS_NOT_COMPILED` + +**関連項目** + +- `wolfSSH_CERTMAN_VerifyCerts_buffer()` + +### wolfSSH_CERTMAN_new() + +```c +#include + +WOLFSSH_CERTMAN* wolfSSH_CERTMAN_new(void* heap); +``` + +**説明** + +新しい wolfSSL 証明書マネージャーを基盤とする、新しい証明書マネージャーを割り当てて +初期化します。OCSP サポート付き(`HAVE_OCSP`)のビルドでは、チェーン内のすべての +証明書に対する OCSP チェック(`WOLFSSL_OCSP_CHECKALL`)がそのマネージャーで有効に +なります。 + +**引数** + +- `heap` - メモリ割り当てに使用するヒープへのポインター。または `NULL` + +**戻り値** + +- 新しい証明書マネージャーへのポインター。OCSP を有効にできない場合を含め、失敗時は + `NULL` + +**関連項目** + +- `wolfSSH_CERTMAN_free()` + +### wolfSSH_CERTMAN_free() + +```c +#include + +void wolfSSH_CERTMAN_free(WOLFSSH_CERTMAN* cm); +``` + +**説明** + +wolfSSH_CERTMAN_new() で以前に割り当てられた証明書マネージャーを解放します。 + +**引数** + +- `cm` - 解放する証明書マネージャー + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_CERTMAN_new()` + +### wolfSSH_CERTMAN_LoadRootCA_buffer() + +```c +#include + +int wolfSSH_CERTMAN_LoadRootCA_buffer(WOLFSSH_CERTMAN* cm, + const unsigned char* rootCa, word32 rootCaSz); +``` + +**説明** + +信頼されたルート CA 証明書をバッファから証明書マネージャーに読み込みます。読み込ま +れたルートは、ピアから提示された証明書を検証するために使用されます。証明書は DER +エンコードされている必要があります。 + +**引数** + +- `cm` - 証明書マネージャー +- `rootCa` - DER エンコードされたルート CA 証明書を含むバッファ +- `rootCaSz` - ルート CA バッファのサイズ + +**戻り値** + +- `WS_SUCCESS` +- `cm` または `rootCa` が `NULL` の場合、あるいは `rootCaSz` が 0 の場合は + `WS_BAD_ARGUMENT` +- 証明書を読み込めない場合は wolfSSL のエラーコード + +**関連項目** + +- `wolfSSH_CERTMAN_VerifyCerts_buffer()` + +### wolfSSH_CERTMAN_VerifyCerts_buffer() + +```c +#include + +int wolfSSH_CERTMAN_VerifyCerts_buffer(WOLFSSH_CERTMAN* cm, + const unsigned char* cert, word32 certSz, word32 certCount); +``` + +**説明** + +バッファに含まれる `certCount` 個の証明書のチェーンを、証明書マネージャーに読み +込まれたルート CA に対して検証します。バッファには、4 バイトのビッグエンディアンの +長さが前置された DER エンコードの各証明書が、リーフを先頭に、続いて中間証明書の順で +格納されます。ルート CA は省略できます。チェーンに含めることができる証明書は最大 +`MAX_CHAIN_DEPTH` 個(wolfSSL が定義していない場合は 9)です。 + +証明書はチェーンの末尾からリーフに向かって検証されます。OCSP サポート付きのビルドでは、 +各証明書は OCSP でもチェックされます。デフォルトのレスポンダーが設定されていない場合、 +OCSP レスポンダーの URL を持たない証明書は失効していないものとして扱われます。検証 +された中間証明書のうち CA であるものは、次の証明書が署名者を持てるように、信頼された +ルートとして証明書マネージャーに追加されます。この追加は永続的です。CA ではない中間 +証明書があると、チェーンの検証は失敗します。 + +リーフは CA ではなく、エンドエンティティ証明書である必要があります。その後、この関数は +すべてのビルドで RFC 6187 セクション 2.2 のリーフチェックを適用します。KeyUsage 拡張 +が存在する場合は digitalSignature を表明している必要があり、ExtendedKeyUsage 拡張が +存在する場合は anyExtendedKeyUsage、または検証対象の SSH の役割に使用できる用途を +含んでいる必要があります。ユーザー証明書(サーバーが検証)の場合、その用途は +id-kp-secureShellClient または TLS clientAuth であり、ホスト証明書(クライアントが +検証)の場合は id-kp-secureShellServer または TLS serverAuth です。役割は証明書 +マネージャーを所有するコンテキストから決まり、wolfSSH_CERTMAN_new() で作成された +単独のマネージャーはどちらも受け付けます。FPKI プロファイル照合付きのビルド(つまり +`WOLFSSH_NO_FPKI` なしのビルド)では、リーフがサポートされている FPKI プロファイルの +いずれかに一致することも必要です。 + +**引数** + +- `cm` - 証明書マネージャー +- `cert` - 長さが前置された証明書チェーンを含むバッファ +- `certSz` - 証明書バッファのサイズ +- `certCount` - チェーン内の証明書の数 + +**戻り値** + +- `WS_SUCCESS` +- `cm` または `cert` が `NULL` の場合、`certCount` が 0 の場合、または `certCount` + が `MAX_CHAIN_DEPTH` を超える場合は `WS_BAD_ARGUMENT` +- メモリ割り当てに失敗した場合は `WS_MEMORY_E` +- 証明書の長さがバッファの末尾を超える場合は `ASN_PARSE_E` +- 証明書に信頼された署名者がない場合、または中間証明書が CA ではない場合は + `WS_CERT_NO_SIGNER_E` +- 証明書の有効期限が切れている場合は `WS_CERT_EXPIRED_E` +- 証明書の署名を検証できない場合は `WS_CERT_SIG_CONFIRM_E` +- OCSP が証明書を失効済みと報告した場合は `WS_CERT_REVOKED_E` +- リーフの KeyUsage または ExtendedKeyUsage がその役割での SSH 使用を許可しない場合 + は `WS_CERT_KEY_USAGE_E` +- リーフが CA である場合、または FPKI プロファイルに一致しない場合は + `WS_CERT_PROFILE_E` +- その他の検証または OCSP の失敗の場合は `WS_CERT_OTHER_E` + +**関連項目** + +- `wolfSSH_CERTMAN_LoadRootCA_buffer()` + +### wolfSSH_CertStoreLocationFromName() + +**利用可能性** + +wolfSSH を証明書サポートおよび Windows 証明書ストアサポート付き(`WOLFSSH_CERTS` +および `WOLFSSH_WINDOWS_CERT_STORE`、 +`./configure --enable-certs --enable-windows-cert-store` により有効化)でビルドした +場合に利用可能です。 + +```c +#include + +int wolfSSH_CertStoreLocationFromName(const char* in, word32* out); +``` + +**説明** + +Windows システム証明書ストアの場所の名前を解析し、対応する `CERT_SYSTEM_STORE_*` の +値に変換します。受け付けられる名前は `CURRENT_USER`、`LOCAL_MACHINE`、`USERS`、 +`CURRENT_SERVICE`、`SERVICES`、`CURRENT_USER_GROUP_POLICY`、 +`LOCAL_MACHINE_GROUP_POLICY`、`LOCAL_MACHINE_ENTERPRISE`、およびこれらに +`CERT_SYSTEM_STORE_` プレフィックスを付けた名前です。場所は 10 進数、または 0x +プレフィックス付きの 16 進数で指定することもできます。数値は数字で始まり、全体が +数値として解釈される必要があります。先頭の符号や空白は拒否され、先頭の 0 は 8 進数 +ではなく 10 進数として読み取られます。受け付けられるのは割り当て済みのストアの場所 +のみであり、制御フラグは受け付けられません。 + +**引数** + +- `in` - NUL 終端の場所の名前または数値 +- `out` - `CERT_SYSTEM_STORE_*` の値を受け取る + +**戻り値** + +- `WS_SUCCESS` +- `in` または `out` が `NULL` の場合、`in` が空の場合、または `in` が有効な場所で + ない場合は `WS_BAD_ARGUMENT` + +**関連項目** + +- `wolfSSH_ParseCertStoreSpec()` + +### wolfSSH_ParseCertStoreSpec() + +**利用可能性** + +wolfSSH を証明書サポートおよび Windows 証明書ストアサポート付き(`WOLFSSH_CERTS` +および `WOLFSSH_WINDOWS_CERT_STORE`)でビルドした場合に利用可能です。 + +```c +#include + +int wolfSSH_ParseCertStoreSpec(const char* spec, + wchar_t** wStoreName, wchar_t** wSubjectName, + word32* dwFlags, void* heap); +``` + +**説明** + +`store:subject[:flags]` 形式の証明書ストア指定を、ストア名、サブジェクト名、ストアの +場所に分割します。指定は最初の 2 つのコロンで分割されるため、ストア名とサブジェクトの +どちらにもコロンを含めることはできず、3 つ目のコロンは拒否されます。例えば +"My:CN=host:65536" は、ストア "My"、サブジェクト "CN=host"、フラグ 65536 となります。 +省略可能な `flags` フィールドには、wolfSSH_CertStoreLocationFromName() が受け付ける +任意の表記を指定でき、デフォルトは `CURRENT_USER` です。ストア名とサブジェクトは +UTF-8 から、新たに割り当てられたワイド文字列に変換されます。不正な UTF-8 は拒否され +ます。 + +成功時には、呼び出し元が 2 つのワイド文字列を所有し、同じ `heap` を指定して +wolfSSH_FreeCertStoreSpec() で解放する必要があります。失敗時には、`NULL` でない +`wStoreName` および `wSubjectName` の出力ポインターは `NULL` に設定され、`dwFlags` +は変更されません。 + +**引数** + +- `spec` - NUL 終端の指定文字列 +- `wStoreName` - 割り当てられたストア名を受け取る +- `wSubjectName` - 割り当てられたサブジェクト名を受け取る +- `dwFlags` - ストアの場所の値を受け取る +- `heap` - 割り当てに使用するヒープ + +**戻り値** + +- `WS_SUCCESS` +- 引数が `NULL` の場合、または指定の形式が不正な場合は `WS_BAD_ARGUMENT` +- メモリ割り当てに失敗した場合は `WS_MEMORY_E` +- UTF-8 からワイド文字列への変換に失敗した場合は `WS_FATAL_ERROR` + +**関連項目** + +- `wolfSSH_FreeCertStoreSpec()` +- `wolfSSH_CertStoreLocationFromName()` + +### wolfSSH_FreeCertStoreSpec() + +**利用可能性** + +wolfSSH を証明書サポートおよび Windows 証明書ストアサポート付き(`WOLFSSH_CERTS` +および `WOLFSSH_WINDOWS_CERT_STORE`)でビルドした場合に利用可能です。 + +```c +#include + +void wolfSSH_FreeCertStoreSpec(wchar_t* wStoreName, wchar_t* wSubjectName, + void* heap); +``` + +**説明** + +wolfSSH_ParseCertStoreSpec() が返した文字列を解放します。どちらのポインターも `NULL` +で構いません。`heap` は wolfSSH_ParseCertStoreSpec() に渡したものと同じである必要が +あります。 + +**引数** + +- `wStoreName` - 解放するストア名。または `NULL` +- `wSubjectName` - 解放するサブジェクト名。または `NULL` +- `heap` - 割り当てに使用したヒープ + +**戻り値** + +なし + +**関連項目** + +- `wolfSSH_ParseCertStoreSpec()` + +## 移植性関数 + +これらの関数は wolfSSH のプラットフォーム移植レイヤーの一部を構成し、サポートされる +ターゲット間でファイルシステム操作および文字列操作を抽象化します。主に内部的に、 +また wolfSSH を新しいプラットフォームに移植する際に使用されます。利用可能な関数の +正確なセットは、ターゲットのビルド構成によって異なります。 + +### wfopen() + +```c +#include + +int wfopen(WFILE** f, const char* filename, const char* mode); +``` + +**説明** + +移植可能なファイルオープンラッパーです。アクセスモード `mode` を使用して +`filename` を開き、得られたファイルハンドルを `f` に格納します。 + +**引数** + +- `f` - 開かれたファイルハンドルを受け取る +- `filename` - 開くファイルのパス +- `mode` - アクセスモード文字列(C ライブラリの `fopen` と同様) + +**戻り値** + +- 成功時は 0 +- 失敗時は非ゼロ + +### wstrnstr() + +```c +#include + +char* wstrnstr(const char* s1, const char* s2, unsigned int n); +``` + +**説明** + +`s1` の先頭 `n` バイト以内で、部分文字列 `s2` が最初に出現する位置を見つけます。 + +**引数** + +- `s1` - 検索対象の文字列 +- `s2` - 見つける部分文字列 +- `n` - `s1` を検索する最大バイト数 + +**戻り値** + +- `s1` 内で `s2` が最初に出現する位置へのポインター。見つからない場合は `NULL` + +### wstrncat() + +```c +#include + +char* wstrncat(char* s1, const char* s2, size_t n); +``` + +**説明** + +文字列 `s2` を `s1` 内の文字列の末尾に追加します。`n` は `s1` を保持するバッファ全体 +のサイズです。追加は全部行われるか、まったく行われないかのどちらかです。`s2` が終端の +NUL を含めて残りの領域に収まらない場合、何も追加されません。`s1` の先頭 `n` バイト +以内に NUL 終端が見つからない場合、この関数は何も書き込まずに失敗します。 + +**引数** + +- `s1` - 追加先の文字列。その場で追加される +- `s2` - 追加するソース文字列 +- `n` - `s1` バッファ全体のサイズ(バイト単位) + +**戻り値** + +- 成功時は追加先の文字列 `s1` へのポインター +- `s2` が収まらない場合、または `s1` が `n` バイト以内で終端されていない場合は + `NULL` + +### wstrdup() + +```c +#include + +char* wstrdup(const char* s1, void* heap, int type); +``` + +**説明** + +文字列 `s1` を複製します。複製は指定された `heap` から割り当てられます。`s1` が +`NULL` の場合は `NULL` を返します。 + +**引数** + +- `s1` - 複製する文字列 +- `heap` - 割り当てに使用するヒープ +- `type` - 割り当てタイプのヒント + +**戻り値** + +- 複製された文字列へのポインター。失敗時は `NULL` + +### WS_FindFirstFileA() + +**利用可能性** + +SCP または SFTP サポート付きの Windows ビルド(`USE_WINDOWS_API`)で利用可能です。 +ただし、`WOLFSSH_SCP_USER_CALLBACKS` が定義されている場合を除きます。 + +```c +#include + +void* WS_FindFirstFileA(const char* fileName, + char* realFileName, size_t realFileNameSz, int* isDir, void* heap); +``` + +**説明** + +`fileName` に対するディレクトリ列挙を開始し、検索ハンドルと最初に一致したエントリ +を返します。`isDir` には、そのエントリがディレクトリかどうかを示す値が設定され +ます。ドライブ文字の前にある先頭のパス区切り文字("/C:/dir" のような SFTP パスの +場合)は、検索の前に取り除かれます。ハンドルは Windows の検索ハンドルです。 + +**引数** + +- `fileName` - 列挙するディレクトリまたは検索パターン +- `realFileName` - 一致したファイル名を受け取るバッファ +- `realFileNameSz` - `realFileName` バッファのサイズ +- `isDir` - エントリがディレクトリの場合に非ゼロが設定される出力。または `NULL` +- `heap` - 割り当てに使用するヒープ + +**戻り値** + +- 成功時は不透明な検索ハンドル +- 失敗時は `INVALID_HANDLE_VALUE` + +**関連項目** + +- `WS_FindNextFileA()` + +### WS_FindNextFileA() + +**利用可能性** + +SCP または SFTP サポート付きの Windows ビルド(`USE_WINDOWS_API`)で利用可能です。 +ただし、`WOLFSSH_SCP_USER_CALLBACKS` が定義されている場合を除きます。 + +```c +#include + +int WS_FindNextFileA(void* findHandle, + char* realFileName, size_t realFileNameSz); +``` + +**説明** + +WS_FindFirstFileA() で開始したディレクトリ列挙を継続し、次に一致したエントリを +返します。 + +**引数** + +- `findHandle` - WS_FindFirstFileA() が返した検索ハンドル +- `realFileName` - 一致したファイル名を受け取るバッファ +- `realFileNameSz` - `realFileName` バッファのサイズ + +**戻り値** + +- 別のエントリが返された場合は非ゼロ +- これ以上エントリがない場合、またはエントリ名を `realFileName` に収まるマルチバイト + 文字列に変換できなかった場合は 0 + +**関連項目** + +- `WS_FindFirstFileA()` + +### wstrsep() + +**利用可能性** + +Windows ビルド(`USE_WINDOWS_API`)で利用可能です。その他のプラットフォームでは、 +`WSTRSEP()` マクロを通じて C ライブラリの `strsep()` を使用します。 + +```c +#include + +char* wstrsep(char** s1, const char* delim); +``` + +**説明** + +Microsoft C ランタイムおよび MinGW が提供していない BSD の `strsep()` 関数の代替 +です。`*s1` 内で `delim` に含まれる最初の文字を見つけ、それを NUL に置き換えてその場 +でトークンを終端し、`*s1` をその次の位置に進めます。区切り文字が残っていない場合、 +`*s1` は `NULL` に設定されます。移植性のあるコードでは `WSTRSEP()` マクロを呼び出す +べきです。このマクロは、必要に応じて `strsep()` またはこの関数に対応付けられます。 + +**引数** + +- `s1` - 分割する文字列ポインターへのポインター。トークンの次の位置を指すように + 更新される +- `delim` - NUL 終端の区切り文字の集合 + +**戻り値** + +- トークンの先頭へのポインター +- `*s1` がすでに `NULL` だった場合は `NULL` diff --git a/wolfSSH/src-ja/chapter17.md b/wolfSSH/src-ja/chapter17.md new file mode 100644 index 00000000..40b020e1 --- /dev/null +++ b/wolfSSH/src-ja/chapter17.md @@ -0,0 +1,142 @@ +# wolfSSH プリプロセッサガードマクロ + +wolfSSH の多くの機能、アルゴリズム、関数は、ビルド時のプリプロセッサマクロによって +制御されます。この章は、アプリケーションが設定することを意図したマクロのリファレンス +です。これらはビルド時にコンパイラのコマンドライン(例えば `CPPFLAGS`/`CFLAGS`)を +通じて、または「wolfSSH のビルド」の章で説明した `./configure` オプションによって +定義されます。 + +## アルゴリズム無効化マクロ + +以下の各 `WOLFSSH_NO_*` マクロは、1 つのアルゴリズム(またはアルゴリズムファミリー) +を無効にします。autotools ビルドでは、これらは通常、wolfCrypt でどのアルゴリズムが +有効になっているかに基づいて自動的に設定されます。wolfSSH からアルゴリズムを削除する +ために手動で定義することもできます。 + +2 つのアルゴリズムファミリーはデフォルトで「ソフト無効化」されています。これらは +コンパイルされており動作もしますが、再度有効化しない限り鍵交換時にアドバタイズ +されません。 + +| マクロ | 効果 | +|--------------------------------------|------------------------------------| +| `WOLFSSH_NO_SHA1_SOFT_DISABLE` | SHA-1 アルゴリズムはコンパイルされますが、デフォルトでは KEX 時にアドバタイズされません。デフォルトで SHA-1 アルゴリズムをアドバタイズするには、これを定義します。 | +| `WOLFSSH_NO_AES_CBC_SOFT_DISABLE` | AES-CBC アルゴリズムはコンパイルされますが、デフォルトでは KEX 時にアドバタイズされません。デフォルトで AES-CBC アルゴリズムをアドバタイズするには、これを定義します。 | +| `WOLFSSH_NO_SHA1` | HMAC およびデジタル署名における SHA-1 を無効にします。 | +| `WOLFSSH_NO_HMAC_SHA1` | HMAC-SHA1 を無効にします。 | +| `WOLFSSH_NO_HMAC_SHA1_96` | HMAC-SHA1-96 を無効にします。 | +| `WOLFSSH_NO_HMAC_SHA2_256` | HMAC-SHA2-256 を無効にします。 | +| `WOLFSSH_NO_HMAC_SHA2_512` | HMAC-SHA2-512 を無効にします。 | +| `WOLFSSH_NO_DH_GROUP1_SHA1` | SHA-1 を用いた DH グループ 1(Oakley 1)を無効にします。 | +| `WOLFSSH_NO_DH_GROUP14_SHA1` | SHA-1 を用いた DH グループ 14(Oakley 14)を無効にします。 | +| `WOLFSSH_NO_DH_GROUP14_SHA256` | SHA-256 を用いた DH グループ 14 を無効にします。 | +| `WOLFSSH_NO_DH_GROUP16_SHA512` | SHA-512 を用いた DH グループ 16 を無効にします。 | +| `WOLFSSH_NO_DH_GEX_SHA256` | SHA-256 を用いた DH グループ交換を無効にします。 | +| `WOLFSSH_NO_DH` | すべての DH 鍵合意を無効にします。 | +| `WOLFSSH_NO_ECDH_SHA2_NISTP256` | NIST P-256 を用いた ECDH 鍵交換を無効にします。 | +| `WOLFSSH_NO_ECDH_SHA2_NISTP384` | NIST P-384 を用いた ECDH 鍵交換を無効にします。 | +| `WOLFSSH_NO_ECDH_SHA2_NISTP521` | NIST P-521 を用いた ECDH 鍵交換を無効にします。 | +| `WOLFSSH_NO_ECDH` | すべての ECDH 鍵合意を無効にします。 | +| `WOLFSSH_NO_CURVE25519_SHA256` | Curve25519 鍵交換を無効にします。 | +| `WOLFSSH_NO_NISTP256_MLKEM768_SHA256` | NIST P-256 と ML-KEM-768 を組み合わせたポスト量子ハイブリッド鍵交換を無効にします。 | +| `WOLFSSH_NO_NISTP384_MLKEM1024_SHA384` | NIST P-384 と ML-KEM-1024 を組み合わせたポスト量子ハイブリッド鍵交換を無効にします。 | +| `WOLFSSH_NO_CURVE25519_MLKEM768_SHA256` | Curve25519 と ML-KEM-768 を組み合わせたポスト量子ハイブリッド鍵交換を無効にします。 | +| `WOLFSSH_NO_RSA` | RSA サーバー認証およびユーザー認証を無効にします。 | +| `WOLFSSH_NO_SSH_RSA_SHA1` | `ssh-rsa`(SHA-1 を用いた RSA)および `x509v3-ssh-rsa` を無効にします。 | +| `WOLFSSH_NO_RSA_SHA2_256` | `rsa-sha2-256` を無効にします。 | +| `WOLFSSH_NO_RSA_SHA2_512` | `rsa-sha2-512` を無効にします。 | +| `WOLFSSH_NO_ECDSA` | ECDSA サーバー認証およびユーザー認証を無効にします。 | +| `WOLFSSH_NO_ECDSA_SHA2_NISTP256` | NIST P-256 を用いた ECDSA 認証を無効にします。 | +| `WOLFSSH_NO_ECDSA_SHA2_NISTP384` | NIST P-384 を用いた ECDSA 認証を無効にします。 | +| `WOLFSSH_NO_ECDSA_SHA2_NISTP521` | NIST P-521 を用いた ECDSA 認証を無効にします。 | +| `WOLFSSH_NO_ED25519` | Ed25519 サーバー認証およびユーザー認証と、Ed25519 を用いた ML-DSA コンポジットを無効にします。wolfCrypt が署名、検証、ストリーミング検証、鍵のインポートとエクスポートを備えた Ed25519 を持たない場合に設定されます。 | +| `WOLFSSH_NO_MLDSA` | すべての ML-DSA サーバー認証およびユーザー認証を無効にします。wolfCrypt が ML-DSA を持たないか、バージョン 5.9.2 より前の場合に設定されます。 | +| `WOLFSSH_NO_MLDSA44` | ML-DSA-44 を無効にします。 | +| `WOLFSSH_NO_MLDSA65` | ML-DSA-65 を無効にします。 | +| `WOLFSSH_NO_MLDSA87` | ML-DSA-87 を無効にします。 | +| `WOLFSSH_NO_MLDSA44_ES256`, `WOLFSSH_NO_MLDSA65_ES256`, `WOLFSSH_NO_MLDSA87_ES384`, `WOLFSSH_NO_MLDSA44_ED25519`, `WOLFSSH_NO_MLDSA65_ED25519`, `WOLFSSH_NO_MLDSA87_ED448` | それぞれ 1 つの ML-DSA コンポジットを無効にします。ML-DSA のレベル、または組み合わせるアルゴリズムが無効になっている場合に設定されます。 | +| `WOLFSSH_NO_MLDSA_COMPOSITES` | すべての ML-DSA コンポジットを無効にします。 | +| `WOLFSSH_NO_OSSH_CERT_RSA` | RSA の OpenSSH 証明書を無効にします。RSA が無効になっている場合、または `rsa-sha2-256` と `rsa-sha2-512` の両方が無効になっている場合に設定されます。 | +| `WOLFSSH_NO_AES_CBC` | AES-CBC 暗号化を無効にします。 | +| `WOLFSSH_NO_AES_CTR` | AES-CTR 暗号化を無効にします。 | +| `WOLFSSH_NO_AES_GCM` | AES-GCM 暗号化を無効にします。 | +| `WOLFSSH_NO_AEAD` | すべての AEAD 暗号を無効にします。 | + +また、RSA、ECDSA、Ed25519、ML-DSA がすべて無効になっている場合、ライブラリは +`WOLFSSH_NO_PUBKEY_AUTH` を設定し、公開鍵によるユーザー認証を除外します。 + +## 機能有効化マクロ + +これらのマクロはサブシステム全体を有効にします。autotools ビルドでは、各マクロは +以下に示す対応する `./configure` オプションによって定義されます。これらの機能の +ほとんどに関連する API は、API リファレンスの各章で説明されています。 + +| マクロ | 有効化する機能 | Configure オプション | +|--------------------------------|---------------------|------------------------------| +| `WOLFSSH_SFTP` | SFTP サポート | `--enable-sftp` | +| `WOLFSSH_SCP` | SCP サポート | `--enable-scp` | +| `WOLFSSH_FWD` | TCP/IP ポートフォワーディング | `--enable-fwd` | +| `WOLFSSH_AGENT` | ssh-agent フォワーディング | `--enable-agent` | +| `WOLFSSH_CERTS` | X.509 証明書サポート | `--enable-certs` | +| `WOLFSSH_OSSH_CERTS` | OpenSSH 証明書によるユーザー認証 | `--enable-ossh-certs` | +| `WOLFSSH_WINDOWS_CERT_STORE` | Windows 証明書ストアからの鍵と証明書。`WOLFSSH_CERTS` と Windows ターゲットが必要 | `--enable-windows-cert-store` | +| `WOLFSSH_TPM` | ホスト鍵とユーザー鍵の TPM 2.0 サポート | `--enable-tpm` | +| `WOLFSSH_SSHD` | wolfsshd デーモン | `--enable-sshd` | +| `WOLFSSH_USE_PAM` | wolfsshd 用の PAM | `--with-pam` | +| `WOLFSSH_SHELL` | echoserver のシェルサポート | `--enable-shell` | +| `WOLFSSH_KEYGEN` | 鍵生成 API | `--enable-keygen` | +| `WOLFSSH_KEYBOARD_INTERACTIVE` | キーボードインタラクティブ認証 | `--enable-keyboard-interactive` | +| `WOLFSSH_SSHCLIENT` | wolfSSH クライアントアプリケーション | `--enable-sshclient` | +| `WOLFSSH_TERM` | PTY / 端末処理 | デフォルトで有効(削除するには `--disable-term`) | +| `WOLFSSH_SMALL_STACK` | リソース制約のあるターゲット向けのスタック使用量削減 | `--enable-smallstack` | +| `WOLFSSH_ALLOW_NONE_CIPHER` | 安全でない "none" 暗号および MAC のネゴシエーション | `--enable-none-cipher` | +| `NO_WOLFSSH_SERVER` | サーバーのコードを除外 | `--disable-server` | +| `NO_WOLFSSH_CLIENT` | クライアントのコードを除外 | `--disable-client` | + +次のマクロは、サブシステムを有効にするのではなく、動作を調整します。 + +| マクロ | 効果 | +|--------------------------------------|--------------------------------------------------| +| `WOLFSSH_NO_DEFAULT_LOGGING_CB` | 組み込みのデフォルトロギングコールバックを省略します。 | +| `WOLFSSH_NO_TIMESTAMP` | ログ出力からタイムスタンプを省略します。 | +| `WOLFSSH_NO_SYMLINK_CHECK` | SFTP の制限ルート配下のシンボリックリンクを拒否するチェックと、それによるルート外へのアクセス防止を無効にします。 | +| `WOLFSSH_NO_SFTP_BUFFER_ZERO` | SFTP のファイルデータバッファを解放前にゼロクリアする処理をスキップします。`--disable-sftp-zeroize` によって設定されます。 | +| `WOLFSSH_NO_FPKI` | X.509 証明書に対する Federal PKI(FPKI)プロファイルのチェックをスキップします。 | +| `WOLFSSH_ALLOW_USERAUTH_NONE` | サーバーが "none" ユーザー認証方式を受け付けるようにし、それを `WOLFSSH_USERAUTH_NONE` としてユーザー認証コールバックに渡します。 | +| `WOLFSSH_SCP_USER_CALLBACKS` | デフォルトの SCP 送信・受信コールバックを省略します。アプリケーションは独自のコールバックを設定する必要があります。 | +| `WOLFSSH_USER_IO` | デフォルトのソケット I/O コールバックを省略します。アプリケーションは独自のコールバックを設定する必要があります。 | +| `WOLFSSH_CERT_STORE_ALLOW_EXPIRED` | 有効期間内の証明書が一致しない場合に、Windows 証明書ストアの検索で期限切れまたはまだ有効でない証明書を使用できるようにします。 | +| `WOLFSSH_IGNORE_UNKNOWN_CONFIG` | wolfSSHd は、未知またはサポートされていない設定行に対して起動に失敗する代わりに、警告をログに出力してその行を無視します。 | +| `WOLFSSH_NO_HOSTKEY_PERMS` | QNX において、wolfSSHd はホスト鍵ファイルの所有者とモードのチェックをスキップします。 | + +## チューニングおよび値マクロ + +これらのマクロは、オン/オフのスイッチとして機能するのではなく、数値を取ります。 +デフォルトを上書きするには、ビルド時に定義します。 + +| マクロ | 意味 | デフォルト | +|-------------------------------------|-----------------------------------|--------------| +| `DEFAULT_WINDOW_SZ` | 初期のチャネルウィンドウサイズ(バイト単位)。 | 131072(128 KB) | +| `DEFAULT_MAX_PACKET_SZ` | チャネルの最大パケットサイズ(バイト単位)。 | 32768 | +| `MAX_PACKET_SZ` | 送信または受け付ける SSH パケットの最大サイズ(バイト単位)。 | 35000 | +| `DEFAULT_MAX_AUTH_ATTEMPTS` | サーバーが切断するまでに許容するユーザー認証の失敗回数。 | 6 | +| `WOLFSSH_RSA_MIN_KEY_BITS` | RSA ユーザー認証鍵の最小サイズ(ビット単位)。 | 2048 | +| `WOLFSSH_DEFAULT_GEXDH_MIN` | クライアントが要求する DH グループ交換のグループの最小サイズ(ビット単位)。 | 2048 | +| `WOLFSSH_DEFAULT_GEXDH_PREFERRED` | クライアントが要求する DH グループ交換のグループの推奨サイズ(ビット単位)。 | 3072 | +| `WOLFSSH_DEFAULT_GEXDH_MAX` | クライアントが要求する DH グループ交換のグループの最大サイズ(ビット単位)。 | 8192 | +| `WOLFSSH_DH_GEX_MIN_BITS` | 双方が受け付ける DH グループ交換のグループの最小サイズ(ビット単位)。 | 2048 | +| `WOLFSSH_MAX_NAMELIST_SZ` | 接続相手から受け付ける name-list の最大サイズ(バイト単位)。 | 4096 | +| `WOLFSSH_MAX_NAMELIST_CNT` | 接続相手から受け付ける name-list 内の名前の最大数。 | 64 | +| `WOLFSSH_MAX_PVT_KEYS` | 1 つのコンテキストが保持できる秘密鍵の最大数。 | 16 | +| `WOLFSSH_MAX_PROMPTS` | keyboard-interactive プロンプトの最大数。 | 64 | +| `WOLFSSH_MAX_PROMPT_SZ` | keyboard-interactive プロンプトの最大サイズ(バイト単位)。 | 1024 | +| `DEFAULT_HIGHWATER_MARK` | 再鍵交換がトリガーされるまでのデフォルトのデータ最高水位(バイト単位)。 | 約 1 GB | +| `WOLFSSH_DEFAULT_MSG_HIGHWATER_MARK` | 再鍵交換がトリガーされるまでのデフォルトのパケット数最高水位。 | 0x80000000 | +| `WOLFSSH_MR_ROUNDS` | クライアントがサーバーの DH グループ交換素数を検査する際に使用する Miller-Rabin のラウンド数。 | 8 | +| `WOLFSSH_KEY_QUANTITY_REQ` | OpenSSH 形式の鍵ラッパーで必要な鍵の数。 | 1 | +| `WOLFSSH_MAX_FILENAME` | 最大ファイル名長(バイト単位)。 | 256 | +| `WOLFSSH_MAX_SFTP_RW` | SFTP の読み書きチャンクの最大サイズ(バイト単位)。 | 32768 | +| `WOLFSSH_MAX_SFTP_RECV` | SFTP の最大受信サイズ(バイト単位)。 | 32768 | +| `WOLFSSH_MAX_SFTP_NAME` | SFTP 名前リストの最大サイズ(バイト単位)。 | 1048576(1 MB) | +| `WOLFSSH_MAX_SFTP_PACKET` | サーバーが受け付ける SFTP リクエストの最大サイズ(バイト単位)。 | `WOLFSSH_MAX_SFTP_RW` + `WOLFSSH_MAX_SFTP_RECV` | +| `WOLFSSH_MAX_SFTP_HANDLES` | サーバーのセッションあたりにオープンできる SFTP ハンドルの最大数。 | 64 | +| `WOLFSSHD_DEFAULT_UMASK` | wolfSSHd のセッションが実行される umask。 | 022 | diff --git a/wolfSSH/src/chapter01.md b/wolfSSH/src/chapter01.md index 79a43dce..ce9ad7fb 100644 --- a/wolfSSH/src/chapter01.md +++ b/wolfSSH/src/chapter01.md @@ -2,7 +2,7 @@ This manual is written as a technical guide to the wolfSSH embedded library. It will explain how to build and get started with wolfSSH, provide an overview of build options, features, support, and much more. -wolfSSH is an implementation of the SSH (Secure Shell) server written in C and uses the wolfCrypt library which is also available from wolfSSL. Furthermore, wolfSSH has been built from the ground up in order for it to have multi-platform use. This implementation is based off of the SSH v2 specification. +wolfSSH is an implementation of the SSH (Secure Shell) server and client written in C and uses the wolfCrypt library which is also available from wolfSSL. Furthermore, wolfSSH has been built from the ground up in order for it to have multi-platform use. This implementation is based off of the SSH v2 specification. ## Protocol Overview @@ -10,7 +10,7 @@ SSH is a layered set of protocols that provide multiplexed streams of data betwe ## Why Choose wolfSSH? -The wolfSSH library is a lightweight SSHv2 server library written in ANSI C and targeted for embedded, RTOS, and resource-constrained environments - primarily because of its small size, speed, and feature set. It is commonly used in standard operating environments as well because of its royalty-free pricing and excellent cross platform support. wolfSSH supports the industry standard SSH v2. wolfSSH is powered by the wolfCrypt library. A version of the wolfCrypt cryptography library has been FIPS 140-3 validated (Certificate #4718) and FIPS 140-2 validated (Certificate #3389). For additional information, visit the wolfCrypt FIPS FAQ or contact fips@wolfssl.com. +The wolfSSH library is a lightweight SSHv2 server and client library written in ANSI C and targeted for embedded, RTOS, and resource-constrained environments - primarily because of its small size, speed, and feature set. It is commonly used in standard operating environments as well because of its royalty-free pricing and excellent cross platform support. wolfSSH supports the industry standard SSH v2. wolfSSH is powered by the wolfCrypt library. A version of the wolfCrypt cryptography library has been FIPS 140-3 validated (Certificate #4718) and FIPS 140-2 validated (Certificate #3389). For additional information, visit the wolfCrypt FIPS FAQ or contact fips@wolfssl.com. ### Features @@ -23,20 +23,38 @@ The wolfSSH library is a lightweight SSHv2 server library written in ANSI C and - Multiple hashing functions: SHA-1, SHA-2 (SHA-256, SHA-384, SHA-512) -- Block and authenticated ciphers: AES-CBC, AES-CTR, AES-GCM +- Block and authenticated ciphers: AES-CBC, AES-CTR, AES-GCM (128-, 192- and 256-bit keys) -- Key exchange options: DHE and ECDHE (with curves NISTP256, NISTP384, NISTP521) +- Message authentication: HMAC-SHA1, HMAC-SHA1-96, HMAC-SHA2-256, HMAC-SHA2-512 -- Public key authentication options: RSA and ECDSA (with curves NISTP256, NISTP384, NISTP521) +- Cipher and MAC negotiated independently for each direction of the connection + +- Key exchange options: DH (groups 1, 14 and 16, and group exchange), ECDH (with curves NISTP256, NISTP384, NISTP521), and Curve25519 + +- Post-quantum hybrid key exchange: ML-KEM-768 with Curve25519 or NIST P-256, and ML-KEM-1024 with NIST P-384 + +- Public key authentication options: RSA (ssh-rsa, rsa-sha2-256, rsa-sha2-512), ECDSA (with curves NISTP256, NISTP384, NISTP521), Ed25519, and the post-quantum ML-DSA-44, ML-DSA-65 and ML-DSA-87, alone or as composites with ECDSA, Ed25519 or Ed448, for both host keys and user authentication + +- Builds with neither RSA nor ECDSA, such as an Ed25519-only build + +- SHA-1 and AES-CBC algorithms compiled in but not offered by default + +- Strict key exchange, the mitigation for the Terrapin attack (CVE-2023-48795), on by default + +- Rekeying triggered by the amount of data or by the number of packets sent - User authentication support (password, keyboard-interactive and public key authentication) - Simple API -- PEM and DER X.509 certificate support +- PEM and DER X.509 certificate support for host keys and user authentication (RFC 6187), including ML-DSA certificates + +- OpenSSH certificate user authentication in wolfSSHd + +- TPM 2.0 resident host keys and user keys, and host keys from the Windows certificate store - Hardware Cryptography Support: Intel AES-NI support, Intel AVX1/2, RDRAND, RDSEED, Cavium NITROX support, STM32F2/F4 hardware crypto support, Freescale CAU / mmCAU / SEC, Microchip PIC32MZ -- Post quantum hybrid key exchange with Hybrid ECDH-P256 Kyber-Level1 +- Support for SFTP, SCP, SSH-AGENT, local and remote port forwarding (client and server) -- Support for SFTP, SCP, SSH-AGENT, local and remote port forwarding +- wolfSSHd, an SSH server daemon, and wolfssh, an SSH client application diff --git a/wolfSSH/src/chapter02.md b/wolfSSH/src/chapter02.md index 654629ff..411fbf81 100644 --- a/wolfSSH/src/chapter02.md +++ b/wolfSSH/src/chapter02.md @@ -1,6 +1,6 @@ # Building wolfSSH -wolfSSH is written with portability in mind and should generally be easy to build on most systems. If you have difficulty building, please don’t hesitate to seek support through our support forums, https://www.wolfssl.com/forums, or contact us directly at support@wolfssl.com. +wolfSSH is written with portability in mind and should generally be easy to build on most systems. If you have difficulty building, please don't hesitate to seek support through our support forums, https://www.wolfssl.com/forums, or contact us directly at support@wolfssl.com. This section explains how to build wolfSSH on Linux, un\*x-like (BSD, macOS) and Windows environments, and provides guidance for building in a non-standard environment. You will find a getting started guide and example in section 3. @@ -10,7 +10,7 @@ When using the autotools system to build, wolfSSH uses a single Makefile to buil The most recent, up to date version can be downloaded from the GitHub website here: [https://github.com/wolfSSL/wolfssh](https://github.com/wolfSSL/wolfssh). -Either click the “Download ZIP” button or use the following command in your terminal: +Either click the "Download ZIP" button or use the following command in your terminal: ``` $ git clone https://github.com/wolfSSL/wolfssh.git ``` @@ -33,6 +33,15 @@ If the bulk of wolfSSL code isn't desired, wolfSSL can be configured with the cr --enable-cryptonly ``` +wolfSSH requires wolfSSL built with `--enable-wolfssh` (which defines `WOLFSSL_WOLFSSH`); building wolfSSH against a wolfSSL without it stops with an `#error`. Some wolfSSH features need further wolfSSL options: + +- X.509 certificates (`--enable-certs`) use wolfSSL's certificate manager, so wolfSSL must be built with TLS, not `--enable-cryptonly`. Add `--enable-ocsp` to allow OCSP lookups. +- Curve25519 key exchange needs `--enable-curve25519`. +- The ML-KEM hybrid key exchanges need `--enable-mlkem`. +- ML-DSA host keys and user authentication need `--enable-mldsa` and wolfSSL 5.9.2 or later. +- TPM support (`--enable-tpm`) needs wolfSSL built with `--enable-wolftpm`, and wolfTPM. +- The wolfssh client application (`--enable-sshclient`) needs a threaded wolfSSL, and wolfSSL's Base64 encoder (`--enable-base64encode`, on by default only on x86_64). + ## Building with autotools When building on Linux, BSD, macOS, Solaris, or other un\*x-like environments, use the autotools system. To build wolfSSH run the following commands: @@ -71,6 +80,53 @@ wolfSSH root directory: ``` $ make src/libwolfssh.la ``` +## Build Options + +The following options may be given to `./configure`. Each feature option also +defines the preprocessor macro listed for it in the "wolfSSH Preprocessor Guard +Macros" chapter. + +| Option | Default | Description | +|-------------------------------|-----------|--------------------------------------------| +| `--with-wolfssl=PATH` | /usr/local | Install prefix of wolfSSL; `PATH/lib` and `PATH/include` must exist. | +| `--enable-debug` | disabled | Add debug code and logging, and turn off optimizations. | +| `--disable-inline` | enabled | Disable inline functions. | +| `--disable-examples` | enabled | Do not build the example programs. | +| `--disable-server` | enabled | Leave out the server code. Cannot be combined with `--disable-client`. | +| `--disable-client` | enabled | Leave out the client code. Cannot be combined with `--disable-server`. | +| `--enable-keygen` | disabled | Key generation API. wolfSSL needs `--enable-keygen`. | +| `--enable-keyboard-interactive` | disabled | Keyboard-interactive user authentication. | +| `--enable-scp` | disabled | SCP support. | +| `--enable-sftp` | disabled | SFTP support. | +| `--disable-sftp-zeroize` | enabled | Do not zero SFTP file data buffers before they are freed. | +| `--enable-fwd` | disabled | TCP/IP port forwarding. | +| `--disable-term` | enabled | Leave out pseudo-terminal support. | +| `--enable-shell` | disabled | Shell support in the echoserver. | +| `--enable-agent` | disabled | ssh-agent support. | +| `--enable-certs` | disabled | X.509 certificate support. | +| `--enable-ossh-certs` | disabled | OpenSSH certificate user authentication. | +| `--enable-windows-cert-store` | disabled | Load keys and certificates from the Windows certificate store. Requires `--enable-certs` and a mingw Windows host; links `crypt32` and `ncrypt`. | +| `--enable-tpm` | disabled | TPM 2.0 support through wolfTPM. | +| `--enable-smallstack` | disabled | Reduce stack usage, allocating large buffers from the heap. | +| `--enable-none-cipher` | disabled | Allow negotiating the insecure "none" cipher and MAC, which turn off encryption and integrity protection. | +| `--enable-sshd` | disabled | Build the wolfSSHd server daemon. Also turns on `--enable-shell`. | +| `--with-pam=PATH` | none | Directory of the PAM library for wolfSSHd. | +| `--enable-sshclient` | disabled | Build the wolfssh client application. | +| `--enable-all` | disabled | Turn on keygen, keyboard-interactive, scp, sftp, fwd, shell, agent, sshd, sshclient and certs. | +| `--enable-distro` | disabled | `--enable-all` plus both shared and static libraries. | + +The wolfssh client application runs every session's I/O on threads, so it needs +a threaded wolfSSL. Giving `--enable-sshclient` against a single-threaded +wolfSSL is a configure error, while `--enable-all` leaves the client out instead +of failing. + +`--enable-all` does not turn on `--enable-ossh-certs`, +`--enable-windows-cert-store`, `--enable-tpm`, `--enable-smallstack` or +`--enable-none-cipher`; add those explicitly. + +In the build tree, `./apps/wolfssh-options` prints the name of each enabled +build option, one per line, for use by test scripts. It is not installed. + ## Building on Windows The Visual Studio project file can be found in the directory *ide\\winvs*. @@ -90,7 +146,15 @@ configure wolfSSL with the appropriate settings. This file must be copied from the directory `wolfssh\ide\winvs` to `wolfssl\IDE\WIN`. If you change one copy you must change both copies. The option `WOLFCRYPT_ONLY` disables the build of the wolfSSL files and only builds the wolfCrypt algorithms. To -also keep wolfSSL, delete that option. +also keep wolfSSL, delete that option. X.509 certificate support needs the +TLS layer, so the X.509 block in that file removes `WOLFCRYPT_ONLY` along with +defining `WOLFSSH_CERTS`. + +The projects link against the Windows `crypt32.lib` and `ncrypt.lib` import +libraries for the Windows certificate store support +(`WOLFSSH_WINDOWS_CERT_STORE`). To use it, define `WOLFSSH_WINDOWS_CERT_STORE` +as described in the comment block in `user_settings.h`, along with +`WOLFSSH_CERTS`. ### User Macros for Building on Windows @@ -104,7 +168,7 @@ unit-test/unit-test.vcxproj ``` The other user macros are the directories where the wolfSSL libraries for the different builds may be found. So the user macro 'wolfCryptDllRelease64' is initially set to: ``` -$(wolfCryptDir)\x64\DLL Release +$(wolfCryptDir)\DLL Release\x64 ``` This value is used in the debugging environment for the echoserver's 64-bit DLL Release build is set to: ``` @@ -118,13 +182,13 @@ While not officially supported, we try to help users wishing to build wolfSSH in 1. The source and header files need to remain in the same directory structure as they are in the wolfSSH download package. 2. Some build systems will want to explicitly know where the wolfSSH header files are located, so you may need to specify that. They are located in the /wolfssh directory. Typically, you can add the directory to your include path to resolve header problems. -3. wolfSSH defaults to a little endian system unless the configure process detects big endian. Since users building in a non-standard environment aren’t using the configure process, BIG_ENDIAN_ORDER will need to be defined if using a big endian system. +3. wolfSSH defaults to a little endian system unless the configure process detects big endian. Since users building in a non-standard environment aren't using the configure process, BIG_ENDIAN_ORDER will need to be defined if using a big endian system. 4. Try to build the library and let us know if you run into any problems. If you need help, contact us at support@wolfssl.com. ## Cross Compiling Many users on embedded platforms cross compile for their environment. The easiest way to cross compile the library is to use the configure system. It will generate a Makefile which can then be used to build wolfSSH. -When cross compiling, you’ll need to specify the host to configure, such as: +When cross compiling, you'll need to specify the host to configure, such as: ``` $ ./configure --host=arm-linux ``` @@ -150,11 +214,13 @@ $ ./configure --prefix=~/wolfSSL $ make $ make install ``` -This will place the library in ~/wolfSSL/lib and the includes in ~/wolfssl/include. To set up a custom install directory for wolfSSH and specify the custom wolfSSL library and include directories use the following: +This will place the library in ~/wolfSSL/lib and the includes in ~/wolfSSL/include. To set up a custom install directory for wolfSSH and point it at that wolfSSL install use the following: ``` -$ ./configure --prefix=~/wolfssh --libdir=~/wolfssl/lib --includedir=~/wolfssl/include +$ ./configure --prefix=~/wolfssh --with-wolfssl=~/wolfSSL $ make $ make install ``` +The --with-wolfssl option takes the wolfSSL install prefix and expects to find lib/ and include/ under it. It is what tells wolfSSH where to find wolfSSL. The --libdir and --includedir options set where wolfSSH's own library and headers are installed, they do not affect where wolfSSL is found. + Make sure the paths above match your actual locations. diff --git a/wolfSSH/src/chapter03.md b/wolfSSH/src/chapter03.md index c2601865..c8a7045b 100644 --- a/wolfSSH/src/chapter03.md +++ b/wolfSSH/src/chapter03.md @@ -6,7 +6,7 @@ After downloading and building wolfSSH, there are some automated test and exampl ### wolfSSH Unit Test -The wolfSSH unit test is used to verify the API. Both positive and negative test cases are performed. This test can be run manually and it additionally runs as part of other automated processes such as the make and make check commands. +The wolfSSH unit test is used to verify the API. Both positive and negative test cases are performed. This test can be run manually and it additionally runs as part of other automated processes such as the make and make check commands. The command `make check` also runs the API test (`tests/api.test`), the regression test (`tests/regress.test`), the client/server test suite (`tests/testsuite.test`), and the key exchange test (`tests/kex.test`). All examples and tests must be run from the wolfSSH home directory so the test tools can find their certificates and keys. @@ -21,7 +21,7 @@ $ make check (when using autoconf) ### Testing Notes -After cloning the repository, be sure to make the testing private keys read- only for the user, otherwise ssh_client will tell you to do it. +After cloning the repository, be sure to make the testing private keys read-only for the user, otherwise ssh will tell you to do it. ``` $ chmod 0600 ./keys/gretel-key-rsa.pem ./keys/hansel-key-rsa.pem \ ./keys/gretel-key-ecc.pem ./keys/hansel-key-ecc.pem @@ -43,7 +43,7 @@ To use public key authentication use the command line: $ ssh -i ./keys/USER-key-TYPE.pem -p 22222 USER@localhost ``` -Where the _USER_ can be gretel or hansel, and TYPE is rsa or ecc. +Where the _USER_ can be gretel or hansel, and TYPE is rsa or ecc. The echoserver accepts the RSA keys by default; give it the option `-e` to accept the ECC keys instead. Keep in mind, the echoserver has several fake accounts in its wsUserAuth callback function. (jack, jill, hansel, and gretel) When the shell support is enabled, those fake accounts will not work. They don't exist in the system's passwd file. The users will authenticate, but the server will err out because they don't exist in the system. You can add your own username to the password or public key list in the echoserver. That account will be logged into a shell started by the echoserver with the privileges of the user running echoserver. @@ -79,16 +79,45 @@ echoserver: - CTRL-E: Print out some session statistics. - CTRL-F: Trigger a new key exchange. -The echoserver tool accepts the following command line options: +The echoserver tool accepts the following command line options. Some options +are only available when the matching feature is built in. ``` + -? display this help and exit -1 exit after a single (one) connection -e expect ECC public key from client - -E use ECC private key - -f echo input + -E load ECC private key first + -f echo input (shell builds only) + -A drive channels from the application callbacks -p port to accept on, default 22222 -N use non-blocking sockets -d set the home directory for SFTP connections - -j load in a public key to accept from peer + -D confine SFTP connections to the home directory, + rather than only starting them there + -j load in a SSH public key to accept from peer + (user assumed in comment) + -I : + load in a SSH public key to accept from peer + -s load in a TPM public key file to replace default + hansel key + -G load ECC/RSA host key blob from TPM (private key + stays in TPM) + -J : + load in an X.509 PEM cert to accept from peer + -K : + load in an X.509 DER cert to accept from peer + -P : + add password to accept from peer + -i : + add password to accept via keyboard-interactive + from peer + -a load in a root CA certificate file + -k set the comma separated list of key algos to use + -x set the comma separated list of key exchange algos + to use + -m set the comma separated list of mac algos to use + -W Windows cert store: "store:subject[:flags]" + -b test user auth would block + -H set test highwater callback ``` ### wolfSSH Client @@ -98,39 +127,55 @@ it sends the string "Hello, wolfSSH!" to the server, prints the response, and then exits. With the pseudo terminal option, the client will be a real client. -The client tool accepts the following command line options: +The client tool accepts the following command line options. Some options +are only available when the matching feature is built in. ``` + -? display this help and exit -h host to connect to, default 127.0.0.1 -p port to connect on, default 22222 -u username to authenticate as (REQUIRED) -P password for username, prompted if omitted + -K TPM key authentication password -e use sample ecc key for user -i filename for the user's private key -j filename for the user's public key -x exit after successful connection without doing read/write -N use non-blocking sockets - -t use psuedo terminal + -t use pseudo terminal -c executes remote command and pipe stdin/stdout + -R raw untranslated output (Windows only) -a Attempt to use SSH-AGENT + -J filename for DER certificate to use + -A filename for DER CA certificate to verify host + -X Ignore IP checks on peer vs peer certificate + -E List all possible algos + -k set the list of key algos + -C set the list of encrypt algos + -q turn off debugging output ``` ### wolfSSH portfwd The portfwd tool establishes a connection to an SSH server and sets up a -listener for local port forwarding or requests a listener for remote port -forwarding. After a connection, the tool terminates. +listener for local port forwarding, or with the option `-r` asks the server +to listen for remote port forwarding. It runs until the connection ends. The portfwd tool accepts the following command line options: ``` + -? display this help and exit -h host to connect to, default 127.0.0.1 -p port to connect on, default 22222 -u username to authenticate as (REQUIRED) -P password for username, prompted if omitted -F host to forward from, default 0.0.0.0 - -f host port to forward from (REQUIRED) + -f host port to forward from (REQUIRED), 0 with -r + lets the peer pick the listener port -T host to forward to, default to host -t port to forward to (REQUIRED) + -r remote (reverse) forward: ask the SSH server to + listen on -F/-f and tunnel connections back to + the local -T/-t target ``` ### wolfSSH scpclient @@ -141,12 +186,18 @@ example, absolute paths must be used, and directories must end with a `/`. The scpclient tool accepts the following command line options: ``` + -h display this help and exit -H host to connect to, default 127.0.0.1 -p port to connect on, default 22222 -u username to authenticate as (REQUIRED) -P password for username, prompted if omitted -L : copy from local to server -S : copy from server to local + -i filename for the user's private key + -j filename for the user's public key + -J filename for DER certificate to use + -A filename for DER CA certificate to verify host + -X Ignore IP checks on peer vs peer certificate ``` ### wolfSSH sftpclient @@ -155,25 +206,155 @@ The sftpclient, wolfsftp, establishes a connection to an SSH server and allows directory navigation, getting and putting files, making and removing directories, etc. -The sftpclient tool accepts the following command line options: +The sftpclient tool accepts the following command line options. Some options +are only available when the matching feature is built in. ``` + -? display this help and exit -h host to connect to, default 127.0.0.1 -p port to connect on, default 22222 -u username to authenticate as (REQUIRED) -P password for username, prompted if omitted -d set the default local path -N use non blocking sockets - -e use ECC user authentication -l local filename -r remote filename -g put local filename as remote filename -G get remote filename as local filename -``` - -### wolfSSH server - -This tool is a place holder. - + -i filename for the user's private key + -j filename for the user's public key + -k set the comma separated list of server host key + algos to accept + -W Windows cert store: "store:subject[:flags]" + -J filename for DER certificate to use + -A filename for DER CA certificate to verify host + -X Ignore IP checks on peer vs peer certificate +``` + +### wolfssh Client Application + +The wolfssh client application, built with `--enable-sshclient`, connects to a +server and opens a terminal, or runs a command given after the destination. +It defaults the user name to the current user and uses the private key +`$HOME/.ssh/id_ecdsa` to authenticate. +``` + wolfssh [-a] [-E logfile] [-G] [-l login_name] [-p port] [-V] + destination [command] +``` + +The options are: +``` + -a attempt to use SSH-AGENT (agent builds only) + -E logfile append the log to this file instead of stderr, and + turn logging on + -G print out the configuration as used + -l login_name overrides the login name in the destination + -p port overrides the destination port number + -V print out the version +``` + +The destination is either `[user@]hostname` or `ssh://[user@]hostname[:port]`. +The default port is 22. The option `-N` is no longer accepted. + +### wolfSSHd + +wolfSSHd is an SSH server daemon, built with `--enable-sshd`, that reads an +OpenSSH style `sshd_config` file and logs users in to the local system. It +supports shell and exec sessions, and SCP and SFTP when built with them. + +wolfSSHd refuses a host key file that is not owned by the user it runs as (or +root), or that is group or world readable, so give it a copy of the key it can +use. For example: +``` + $ sudo install -m 600 keys/gretel-key-ecc.pem /etc/ssh/wolfsshd_key.pem + $ sudo ./apps/wolfsshd/wolfsshd -D -h /etc/ssh/wolfsshd_key.pem -p 11111 + $ ssh @localhost -p 11111 +``` + +If wolfSSHd stops on a directive in the system `sshd_config` file it does not +support, copy the file, remove that line, and give the copy with `-f`. + +wolfSSHd accepts the following command line options: +``` + -? display this help and exit + -f configuration file to use, default is + /etc/ssh/sshd_config + -p port number to listen on + -d turn on debug mode + -D run in foreground (do not detach) + -h host private key file to use + -E append to log file + -t test mode: load the configuration and exit + without listening +``` + +wolfSSHd recognizes the following configuration directives: + +| Directive | Notes | +|--------------------------------|-----------------------------------------------| +| `Port` | Port to listen on, default 22. | +| `Protocol` | Only `2` is accepted. | +| `HostKey` | Host private key file. Not allowed inside a `Match` block. | +| `HostCertificate` | Host X.509 certificate file. Not allowed inside a `Match` block. | +| `PasswordAuthentication` | `yes` (default) or `no`. | +| `PubkeyAuthentication` | `yes` (default) or `no`. | +| `PermitEmptyPasswords` | `yes` or `no` (default). | +| `PermitRootLogin` | `no` (default), `yes`, `prohibit-password` (also spelled `without-password`), or `forced-commands-only`. Applies to every account with UID 0. | +| `AuthorizedKeysFile` | Authorized keys file, default `.ssh/authorized_keys` in the user's home directory. A relative path is taken from the home directory. `%u` expands to the user name, `%h` to the home directory, and `%%` to a percent sign; any other `%` token is an error. | +| `StrictModes` | `yes` (default) or `no`. | +| `TrustedUserCAKeys` | CA file for user certificates: X.509 CA certificates, or OpenSSH CA public keys for OpenSSH certificates. | +| `AuthorizedUPNDomains` | Restricts the UPN realm of a user's FPKI certificate. | +| `LoginGraceTime` | Seconds allowed to authenticate, default 120. | +| `UsePrivilegeSeparation` | `yes`, `no`, or `sandbox`. | +| `ChrootDirectory` | Directory to chroot the user's session into. | +| `ForceCommand` | Command run in place of the one the client asks for. | +| `Banner` | File sent to the client before authentication. | +| `PidFile` | File the daemon's process ID is written to. | +| `Include` | Reads another configuration file. | +| `Match` | Starts a block of settings for a `User` or `Group`. | +| `wolfSSH_HostKeyStore`, `wolfSSH_HostKeyStoreSubject`, `wolfSSH_HostKeyStoreFlags` | Windows certificate store builds only. Load the host key and certificate from a certificate store. | +| `wolfSSH_TrustedUserCAStore`, `wolfSSH_WinUserStores`, `wolfSSH_WinUserPvPara`, `wolfSSH_WinUserDwFlags` | Windows certificate store builds only. Load user certificate CAs from a Windows certificate store. | +| `wolfSSH_TrustedSystemCAKeys` | `yes` or `no`. Load the operating system's trust store as the user certificate CAs. | + +The directives `Subsystem`, `ChallengeResponseAuthentication`, `UsePAM`, +`X11Forwarding`, `PrintMotd`, `AcceptEnv` and `UseDNS` are recognized for +compatibility with OpenSSH configuration files, but have no effect; wolfSSHd +logs a warning for each. Any other directive is an error. A directive and its +value must be separated by whitespace; the OpenSSH `Keyword=value` form is +rejected. + +A `Match` block may only be keyed on `User` or `Group`; `Match User X Group Y` +requires both to match. The `wolfSSH_` store directives and +`wolfSSH_TrustedSystemCAKeys` are global only and are rejected inside a `Match` +block. `TrustedUserCAKeys` may be set inside one. + +With `StrictModes yes`, an authorized keys file must be a regular file, not a +symbolic link, owned by the user or root, with no group or world writable +component in its path. `StrictModes no` relaxes only the check of authorized +keys files. Host key files and CA files are always checked: they must be owned +by the daemon's user or root, and a host private key must not be group or world +readable. + +`PermitRootLogin prohibit-password` refuses password and keyboard-interactive +logins for root, allowing public key logins. `forced-commands-only` also +requires a `ForceCommand` for a root public key login; the `command=` option in +authorized keys files is not enforced. + +For X.509 user certificates (`--enable-certs`), the CA is set with +`TrustedUserCAKeys`. A certificate is bound to the requested account by its +UPN when wolfSSL has FPKI support, and by a case-insensitive match of its +subject CN otherwise. Without FPKI, on systems other than Windows, the +configuration must also set `AuthorizedKeysFile`, and the certificate is +checked against the user's authorized keys file; a login relying on the CA +alone fails. With FPKI, `AuthorizedUPNDomains` restricts the UPN realm. + +For OpenSSH user certificates (`--enable-ossh-certs`), list the signing CA +public keys in `TrustedUserCAKeys`. The certificate's principals must include +the requested user, it must be within its validity period, and its +`source-address` restriction, if any, must match the client. A certificate's +`force-command` overrides the requested command. OpenSSH certificate logins +are not supported on Windows. + +wolfSSHd sessions run with a umask of 022 (`WOLFSSHD_DEFAULT_UMASK`). ## SCP @@ -182,18 +363,17 @@ single file and recursive directory copy are supported with the default send and receive callbacks. To compile wolfSSH with scp support, use the `--enable-scp` build option -or define `WOLFSSL_SCP`: +or define `WOLFSSH_SCP`: ``` $ ./configure --enable-scp $ make ``` -The wolfSSL example server has been set up to accept a single scp request, -and is compiled by default when compiling the wolfSSH library. To start the -example server, run: +The wolfSSH example echoserver accepts scp requests when wolfSSH is built +with SCP support. To start the example server, run: - $ ./examples/server/server + $ ./examples/echoserver/echoserver Standard scp commands can be used on the client side. The following are a few examples, where `scp` represents the ssh client you are using. @@ -232,9 +412,6 @@ define `WOLFSSH_SFTP`: $ make ``` -For full API usage and implementation details, please see the wolfSSH User -Manual. - The SFTP client created is located in the directory examples/sftpclient/ and the server is ran using the same echoserver as with wolfSSH. @@ -242,7 +419,7 @@ server is ran using the same echoserver as with wolfSSH. src/wolfssh$ ./examples/sftpclient/wolfsftp ``` -A full list of supported commands can be seen with typeing "help" after a +A full list of supported commands can be seen with typing "help" after a connection. ``` @@ -251,7 +428,10 @@ connection. Commands : cd change directory chmod change mode + creat create file with given permissions get pulls file(s) from server + lcd change local directory + lls list local directory ls list current directory mkdir creates new directory on server put push file(s) to server @@ -278,6 +458,12 @@ $ ./configure --enable-shell $ make ``` +To try it, start the echoserver with a password for the current user, and connect with the example client using a pseudo terminal, where `` is the name of the user currently logged in: +``` +$ ./examples/echoserver/echoserver -P :junk +$ ./examples/client/client -t -u -P junk +``` + By default, the echoserver will try to start a shell. To use the echo testing behavior, give the echoserver the command line option -f. ``` $ ./examples/echoserver/echoserver -f @@ -285,39 +471,37 @@ $ ./examples/echoserver/echoserver -f ## Post-Quantum -wolfSSH now supports the post-quantum algorithm Kyber. It uses the NIST -submission's Level 1 parameter set implemented by liboqs via an integration -with wolfSSH. It is hybridized with ECDHE over the P-256 ECC curve. +wolfSSH supports post-quantum key exchange with ML-KEM (formerly known as +Kyber) and post-quantum signatures with ML-DSA (formerly known as Dilithium). -In order be able to use liboqs, you must have it built and installed on your -system. We support the 0.7.0 release of liboqs. You can download it from the -following link: +* **ML-KEM**: the hybrid key exchanges `mlkem768x25519-sha256` (ML-KEM-768 + with Curve25519), `mlkem768nistp256-sha256` (ML-KEM-768 with ECDH over + P-256), and `mlkem1024nistp384-sha384` (ML-KEM-1024 with ECDH over P-384). + When available they are offered ahead of the classical key exchanges. +* **ML-DSA**: the ML-DSA-44, ML-DSA-65, and ML-DSA-87 parameter sets + (`ssh-mldsa-44`, `ssh-mldsa-65`, `ssh-mldsa-87`) for both server host keys + and client public key authentication, and composites of ML-DSA with ECDSA, + Ed25519, or Ed448. When built with certificate support, ML-DSA X.509 + certificates (`x509v3-ssh-mldsa-44`, `x509v3-ssh-mldsa-65`, and + `x509v3-ssh-mldsa-87`) are also supported. -``` - https://github.com/open-quantum-safe/liboqs/archive/refs/tags/0.7.0.tar.gz -``` - -Once unpacked, this would be sufficient: +These algorithms are provided by wolfCrypt; liboqs is not used. Build and +install wolfSSL with support for them. ML-DSA needs wolfSSL 5.9.2 or later. +For example: ``` - $ cd liboqs-0.7.0 - $ mkdir build - $ cd build - $ cmake -DOQS_USE_OPENSSL=0 .. - $ make all - $ sudo make install + $ ./configure --enable-wolfssh --enable-mlkem --enable-mldsa ``` - -In order to enable support for Kyber Level1 hybridized with ECDHE over the P-256 -ECC curve in wolfSSH, use the `--with-liboqs` build option during configuration: +After that, configure and build wolfSSH as usual: ``` - $ ./configure --with-liboqs + $ ./configure + $ make all ``` -The wolfSSH client and server will automatically negotiate using Kyber Level1 -hybridized with ECDHE over the P-256 ECC curve if this feature is enabled. +The wolfSSH client and server will automatically negotiate an ML-KEM hybrid +key exchange. ``` $ ./examples/echoserver/echoserver -f @@ -331,31 +515,8 @@ On the client side, you will see the following output: Server said: Hello, wolfSSH! ``` -If you want to see inter-operability with OpenQauntumSafe's fork of OpenSSH, you -can build and execute the fork while the echoserver is running. Download the -release from here: - -``` - https://github.com/open-quantum-safe/openssh/archive/refs/tags/OQS-OpenSSH-snapshot-2021-08.tar.gz -``` - -The following is sufficient for build and execution: - -``` - $ tar xmvf openssh-OQS-OpenSSH-snapshot-2021-08.tar.gz - $ cd openssh-OQS-OpenSSH-snapshot-2021-08/ - $ ./configure --with-liboqs-dir=/usr/local - $ make all - $ ./ssh -o"KexAlgorithms +ecdh-nistp256-kyber-512-sha256" \ - -o"PubkeyAcceptedAlgorithms +ssh-rsa" \ - -o"HostkeyAlgorithms +ssh-rsa" \ - jill@localhost -p 22222 -``` - -NOTE: when prompted, enter the password which is "upthehill". - -You can type a line of text and when you press enter, the line will be echoed -back. Use CTRL-C to terminate the connection. +Other SSH clients that support these key exchanges, such as OpenSSH for +`mlkem768x25519-sha256`, can also connect to the echoserver. ## Certificate Support @@ -367,10 +528,22 @@ To compile wolfSSH with X.509 support, use the `--enable-certs` build option or define `WOLFSSH_CERTS`: ``` - $ ./configure --enable-certs + $ ./configure --enable-certs CPPFLAGS=-DWOLFSSH_NO_FPKI $ make ``` +For this example, FPKI checking is turned off because the included certificate +for "fred" does not have the required FPKI extensions. If `WOLFSSH_NO_FPKI` is +not defined, the certificate is rejected. + +With or without FPKI, a peer certificate is held to RFC 6187 section 2.2: a +KeyUsage extension must assert digitalSignature, and an ExtendedKeyUsage +extension must name anyExtendedKeyUsage or a purpose for the role being +verified (id-kp-secureShellClient or clientAuth for a user certificate, +id-kp-secureShellServer or serverAuth for a host certificate). A certificate +without those extensions is accepted. A mismatch fails with +`WS_CERT_KEY_USAGE_E`. + To provide a CA root certificate to validate a user's certificate, give the echoserver the command line option `-a`. @@ -378,14 +551,78 @@ echoserver the command line option `-a`. $ ./examples/echoserver/echoserver -a ./keys/ca-cert-ecc.pem ``` -The echoserver and client have a fake user named "john" whose certificate +The echoserver and client have a fake user named "fred" whose certificate will be used for authentication. An example echoserver/client connection using the example certificate -john-cert.der would be: +fred-cert.der would be: + +``` + $ ./examples/echoserver/echoserver -a ./keys/ca-cert-ecc.pem -K fred:./keys/fred-cert.der + + $ ./examples/client/client -u fred -J ./keys/fred-cert.der -i ./keys/fred-key.der +``` + +## OpenSSH Certificate Support + +wolfSSH can accept OpenSSH user certificates (`*-cert-v01@openssh.com`) for +public key user authentication. To compile wolfSSH with OpenSSH certificate +support, use the `--enable-ossh-certs` build option or define +`WOLFSSH_OSSH_CERTS`. The certificate's CA key, principals, validity period, +and its force-command and source-address options are passed to the user +authentication callback, which must check that the CA is trusted. wolfSSHd +uses the CA keys listed in `TrustedUserCAKeys`. + +## Windows Certificate Store + +On Windows, host and user keys can come from the Windows certificate store +instead of files. This requires certificate support; enable it with the +`--enable-windows-cert-store` build option (mingw hosts only) or by defining +`WOLFSSH_WINDOWS_CERT_STORE`. An RSA store certificate is offered as +`x509v3-ssh-rsa`, which RFC 6187 signs with SHA-1, so it also needs +`WOLFSSH_NO_SHA1_SOFT_DISABLE`, and wolfSSL built with +`WC_SIG_MIN_HASH_TYPE=WC_HASH_TYPE_SHA`. ECDSA store keys need neither. + +The echoserver and the SFTP client take a `-W store:subject[:flags]` option +naming the store, the certificate's subject CN, and optionally the store +location: CURRENT_USER (the default), LOCAL_MACHINE, USERS, CURRENT_SERVICE, +SERVICES, CURRENT_USER_GROUP_POLICY, LOCAL_MACHINE_GROUP_POLICY, or +LOCAL_MACHINE_ENTERPRISE, each also accepted with a `CERT_SYSTEM_STORE_` +prefix or as a number. `-W` supplies both the certificate and its private key; +in the SFTP client it cannot be combined with `-i`, `-j`, or `-J`. ``` - $ ./examples/echoserver/echoserver -a ./keys/ca-cert-ecc.pem -K john:./keys/john-cert.der + $ ./examples/echoserver/echoserver -W "My:wolfSSH-Server:LOCAL_MACHINE" -a ./keys/ca-cert-ecc.pem + + $ ./examples/sftpclient/wolfsftp -u testuser -W "My:testuser:CURRENT_USER" -A ./keys/ca-cert-ecc.der -X +``` + +## TPM Host Keys - $ ./examples/client/client -u john -J ./keys/john-cert.der -i ./keys/john-key.der +With `--enable-tpm`, the server can keep its ECDSA or RSA host key inside a +TPM 2.0 so the host private key is never in memory. The key is registered with +`wolfSSH_CTX_UseTpmHostKey()`, and the exchange hash is signed by the TPM. An +X.509 host certificate can be paired with the TPM key by calling +`wolfSSH_CTX_UseCert_buffer()` after `wolfSSH_CTX_UseTpmHostKey()`. The +echoserver loads a TPM host key blob with the option `-G`: + +``` + $ ./examples/echoserver/echoserver -G ../wolfTPM/hostkey.bin ``` + +The examples `examples/tpmcertserver/tpmcertserver` and `tpmcertclient` show a +TPM host key with a self-signed X.509 host certificate. + +## Strict Key Exchange + +wolfSSH implements strict key exchange, the mitigation for the Terrapin attack +(CVE-2023-48795). It is offered in the initial KEXINIT and used whenever the +peer offers it too, so no configuration is needed for the usual case. With +strict KEX in force, wolfSSH accepts nothing but the key exchange messages and +SSH_MSG_DISCONNECT until the peer's SSH_MSG_NEWKEYS arrives, and it resets the +packet sequence numbers at every SSH_MSG_NEWKEYS. A message that arrives out of +turn ends the connection. + +An application that has to interoperate with a peer that mishandles strict KEX +can turn it off for later sessions with `wolfSSH_CTX_SetStrictKex(ctx, 0)`. +`wolfSSH_GetStrictKexNegotiated()` reports whether a session is using it. diff --git a/wolfSSH/src/chapter04.md b/wolfSSH/src/chapter04.md index 7ed99345..132d8cbe 100644 --- a/wolfSSH/src/chapter04.md +++ b/wolfSSH/src/chapter04.md @@ -13,3 +13,17 @@ The wolfSFTP library header file is also included in the wolfssh directory. To c #include ``` All main source files are located in the **src** directory that resides in the root directory. + +Other headers in the **wolfssh** directory declare the optional features: **wolfssh/wolfscp.h** for SCP, **wolfssh/agent.h** for ssh-agent support, **wolfssh/certman.h** for X.509 certificates, and **wolfssh/keygen.h** for key generation. + +## Algorithm Negotiation + +During key exchange the client and server each offer lists of algorithms, and the first algorithm in the client's list that the server also supports is used. The lists can be changed with the `wolfSSH_CTX_SetAlgoList*()` and `wolfSSH_SetAlgoList*()` functions. Those functions validate their input, and return `WS_INVALID_ALGO_ID` for a list naming an unknown algorithm. The cipher and the MAC are negotiated separately for each direction of the connection, so the two directions may use different ones. + +Algorithms using SHA-1, and the AES-CBC ciphers, are compiled in but not offered by default. They can be added back to an algorithm list, or offered by default by building with `WOLFSSH_NO_SHA1_SOFT_DISABLE` or `WOLFSSH_NO_AES_CBC_SOFT_DISABLE`. The "none" cipher and MAC can only be negotiated in a build with `--enable-none-cipher`. + +wolfSSH implements strict key exchange (the Terrapin mitigation), which is used when both peers offer it. It is on by default and can be turned off with `wolfSSH_CTX_SetStrictKex()`. + +## Rekeying + +When the number of bytes sent or received under the current keys reaches the highwater mark (`wolfSSH_SetHighwater()`, default `DEFAULT_HIGHWATER_MARK`), or the number of packets sent or received reaches the packet-count highwater mark (`wolfSSH_SetMsgHighwater()`, default `WOLFSSH_DEFAULT_MSG_HIGHWATER_MARK`), wolfSSH calls the highwater callback. The default callback starts a new key exchange; another may be set with `wolfSSH_SetHighwaterCb()`. The application can also start one with `wolfSSH_TriggerKeyExchange()`. `wolfSSH_RekeyPending()` reports whether a key exchange is in progress. diff --git a/wolfSSH/src/chapter05.md b/wolfSSH/src/chapter05.md index 6b4e2d1a..a6ba116d 100644 --- a/wolfSSH/src/chapter05.md +++ b/wolfSSH/src/chapter05.md @@ -4,34 +4,27 @@ wolfSSH needs to be able to authenticate users connecting to the server no matte wolfSSH provides a callback hook that receives the username, either the password or public key provided in the user authentication message and the requested authentication type. The callback function then performs the appropriate lookups and gives a reply. Providing a callback is required. -The callback should return one of several failures or a success. The library will treat all the failures the same except for logging purposes, i.e. return the User Authorization Failure message to the client who will try again. +The callback should return one of several failures or a success. The library will treat all the failures the same except for logging purposes, i.e. return the User Authorization Failure message to the client who will try again. The exception is `WOLFSSH_USERAUTH_REJECTED`, a hard rejection: the server sends the failure message and then ends the session. The server also disconnects a client after a number of failed attempts, 6 by default; see `wolfSSH_CTX_SetMaxAuthAttempts()`. -For password lookups, the plaintext password is given to the callback function. The username and password should be checked and if they match, a success returned. On success, the SSH handshake continues immediately. Password changing is not supported at this time. +Note that `WOLFSSH_USERAUTH_SUCCESS` has the value 0, the same as `WS_SUCCESS`. A callback that returns 0 by default, or forwards a `WS_SUCCESS` from a helper function, authenticates the client. Return `WOLFSSH_USERAUTH_FAILURE` for any authentication type or code path the callback does not explicitly handle. -For public key lookups, the public key blob from the client is given to the callback function. The public key is checked against the server’s list of valid client public keys. If the public key provided matches the known public key for that user. The wolfSSH library performs the actual validation of the user authentication signature following the process described in RFC 4252 §7. +For password lookups, the plaintext password is given to the callback function. The username and password should be checked and if they match, a success returned. On success, the SSH handshake continues immediately. Password changing is not supported: a request to change the password is refused without calling the callback. -Commonly for public keys, the server stores either the users’ public keys as generated by the ssh-keygen utility or stores a fingerprint of the public key. This value for a user is what is compared. The client will provide a signature of the session ID and the user authentication request message using its private key; the server verifies this signature using the public key. +For public key lookups, the public key blob from the client is given to the callback function. The callback must check the public key against the server's list of valid public keys for that user; returning success for a key that was not checked authorizes any key the client offers. The wolfSSH library performs the actual validation of the user authentication signature following the process described in RFC 4252 section 7. RSA keys shorter than 2048 bits (`WOLFSSH_RSA_MIN_KEY_BITS`) are rejected. + +Commonly for public keys, the server stores either the users' public keys as generated by the ssh-keygen utility or stores a fingerprint of the public key. This value for a user is what is compared. The client will provide a signature of the session ID and the user authentication request message using its private key; the server verifies this signature using the public key. ## Callback Function Prototype The prototype for the user authentication callback function is: ``` -int UserAuthCb(byte authType , const WS_UserAuthData* -authData , void* ctx ); +int UserAuthCb(byte authType, WS_UserAuthData* authData, void* ctx); ``` This function prototype is of the type: ``` WS_CallbackUserAuth ``` -The parameter `authType` is either: - -``` -WOLFSSH_USERAUTH_PASSWORD -``` -or -``` -WOLFSSH_USERAUTH_PUBLICKEY -``` +The parameter `authType` is one of the authentication type constants listed in the next section. The parameter, authData, is a pointer to the authentication data. See section 5.4 for a description of WS_UserAuthData @@ -45,12 +38,16 @@ The following are values passed to the user authentication callback function in ``` WOLFSSH_USERAUTH_PASSWORD WOLFSSH_USERAUTH_KEYBOARD +WOLFSSH_USERAUTH_KEYBOARD_SETUP WOLFSSH_USERAUTH_PUBLICKEY +WOLFSSH_USERAUTH_NONE ``` +`WOLFSSH_USERAUTH_KEYBOARD_SETUP` asks the callback for the keyboard-interactive prompts to send to the client. `WOLFSSH_USERAUTH_NONE` is only used in builds with `WOLFSSH_ALLOW_USERAUTH_NONE`. + ## Callback Function Return Code Constants -The following are the return codes the callback function shall return to the library. The failure code indicates that nothing was done and the callback couldn’t do any checking. +The following are the return codes the callback function shall return to the library. The failure code indicates that nothing was done and the callback couldn't do any checking. The invalid codes indicate why the user authentication is being rejected: @@ -69,28 +66,37 @@ authentication failure message with the partial-success flag set to client. ``` WOLFSSH_USERAUTH_SUCCESS WOLFSSH_USERAUTH_FAILURE +WOLFSSH_USERAUTH_INVALID_AUTHTYPE WOLFSSH_USERAUTH_INVALID_USER WOLFSSH_USERAUTH_INVALID_PASSWORD +WOLFSSH_USERAUTH_REJECTED WOLFSSH_USERAUTH_INVALID_PUBLICKEY WOLFSSH_USERAUTH_PARTIAL_SUCCESS WOLFSSH_USERAUTH_SUCCESS_ANOTHER +WOLFSSH_USERAUTH_WOULD_BLOCK ``` +`WOLFSSH_USERAUTH_SUCCESS_ANOTHER` reports that a keyboard-interactive round passed and asks for another round. `WOLFSSH_USERAUTH_WOULD_BLOCK` asks the library to call the callback again later with the same request. `WOLFSSH_USERAUTH_REJECTED` ends the session. + ## Callback Function Data Types The client data is passed to the callback function in a structure called `WS_UserAuthData`. It contains pointers to the data in the message. Common fields are in this structure. Method specific fields are in a union of structures in the user authentication data. ``` typedef struct WS_UserAuthData { - byte authType ; - byte* username ; - word32 usernameSz ; - byte* serviceName ; - word32 serviceNameSz ; + byte type; + const byte* username; + word32 usernameSz; + const byte* serviceName; + word32 serviceNameSz; + const byte* authName; + word32 authNameSz; union { - WS_UserAuthData_Password password ; - WS_UserAuthData_PublicKey publicKey ; - WS_UserAuthData_Keyboard keyboard ; + WS_UserAuthData_Password password; + WS_UserAuthData_PublicKey publicKey; +#ifdef WOLFSSH_KEYBOARD_INTERACTIVE + WS_UserAuthData_Keyboard keyboard; +#endif } sf; } WS_UserAuthData; ``` @@ -99,17 +105,18 @@ typedef struct WS_UserAuthData { The `username` and `usernameSz` parameters are the username provided by the client and its size in octets. -The `password`and `passwordSz` fields are the client’s password and its size in octets. +The `password` and `passwordSz` fields are the client's password and its size in octets. -While set if provided by the client, the parameters `hasNewPassword`, `newPassword`, and `newPasswordSz` are not used. There is no mechanism to tell the client to change its password at this time. +The fields `hasNewPassword`, `newPassword`, and `newPasswordSz` are present for future use. A request carrying a new password is refused without calling the callback. ``` typedef struct WS_UserAuthData_Password { - uint8_t* password ; - uint32_t passwordSz ; - uint8_t hasNewPasword ; - uint8_t* newPassword ; - uint32_t newPasswordSz ; + const byte* password; + word32 passwordSz; + /* The following are present for future use. */ + byte hasNewPassword; + const byte* newPassword; + word32 newPasswordSz; } WS_UserAuthData_Password; ``` @@ -150,17 +157,20 @@ each prompt response should be echoed to the user as they are typing. Conversely there is `responseCount` to set the number of responses given. `responses` and `responseLengths` contain the response data for the prompts. -The server can set the prompts using the `wolfSSH_SetKeyboardAuthPrompts()` -callback. The `WS_CallbackKeyboardAuthPrompts` callback should set the -`promptCount`, `prompts`, `promptLengths` and `promptEcho`. The other `prompt*` -items are optional. +The server gets the prompts by calling the user authentication callback with +the `authType` `WOLFSSH_USERAUTH_KEYBOARD_SETUP`. The callback should set the +`promptCount`, `prompts`, `promptLengths` and `promptEcho`, and return +`WOLFSSH_USERAUTH_SUCCESS`. The other `prompt*` items are optional. At most +`WOLFSSH_MAX_PROMPTS` (64) prompts may be given. Returning +`WOLFSSH_USERAUTH_REJECTED` from the setup call ends the session; any other +failure fails the attempt. The server should return `WOLFSSH_USERAUTH_SUCCESS_ANOTHER` from the `WS_CallbackUserAuth` callback to execute subsequent request / response rounds. ### Public Key -wolfSSH will support multiple public key algorithms. The publicKeyType member points to the algorithm name used. +wolfSSH supports multiple public key algorithms. The publicKeyType member points to the algorithm name used. The publicKey field points at the public key blob provided by the client. @@ -170,12 +180,34 @@ Each of the fields has a size value in octets. ``` typedef struct WS_UserAuthData_PublicKey { - byte* publicKeyType; + const byte* dataToSign; + const byte* publicKeyType; word32 publicKeyTypeSz; - byte* publicKey; + const byte* publicKey; word32 publicKeySz; + const byte* privateKey; + word32 privateKeySz; byte hasSignature; - byte* signature; + const byte* signature; word32 signatureSz; + byte isCert:1; + word32 dataToSignSz; +#ifdef WOLFSSH_OSSH_CERTS + byte isOsshCert:1; + const byte* caKey; + word32 caKeySz; + const byte* principals; + word32 principalsSz; + word64 validAfter; + word64 validBefore; + const byte* forceCommand; + word32 forceCommandSz; + const byte* sourceAddress; + word32 sourceAddressSz; +#endif } WS_UserAuthData_PublicKey; ``` + +The `isCert` field is set when the client offered an X.509 certificate, which `publicKey` then holds; the library has verified it against the root certificates loaded with `wolfSSH_CTX_AddRootCert_buffer()`. In builds with `WOLFSSH_OSSH_CERTS`, the `isOsshCert` field is set when the client offered an OpenSSH certificate. The library verifies the certificate's signature and parses its fields, but the callback must check that `caKey` is a trusted CA key, and should check the `principals` (a list of names), the validity period (`validAfter` and `validBefore`, in seconds since the epoch), and the `forceCommand` and `sourceAddress` (a comma-separated CIDR list) options, which are NULL when absent. + +The `privateKey` and `privateKeySz` fields are used by a client's user authentication callback to supply its key. diff --git a/wolfSSH/src/chapter06.md b/wolfSSH/src/chapter06.md index 67598fbe..21529194 100644 --- a/wolfSSH/src/chapter06.md +++ b/wolfSSH/src/chapter06.md @@ -7,8 +7,8 @@ The following functions are used to set up the user authentication callback func void wolfSSH_SetUserAuth(WOLFSSH_CTX* ctx , WS_CallbackUserAuth cb ); ``` -The callback function is set on the wolfSSL CTX object that is used to create the wolfSSH session objects. All sessions using this CTX will use the same callback -function. This context is not to be confused with the callback function’s context. +The callback function is set on the wolfSSH CTX object that is used to create the wolfSSH session objects. All sessions using this CTX will use the same callback +function. This context is not to be confused with the callback function's context. ## Setting the User Authentication Callback Context Data ``` @@ -20,19 +20,45 @@ Each wolfSSH session may have its own user authentication context data or share ``` void* wolfSSH_GetUserAuthCtx(WOLFSSH* ssh ); ``` -This returns the pointer to the user authentication context data stored in the provided wolfSSH session. This is not to be confused with the wolfSSH’s context data used to create the session. +This returns the pointer to the user authentication context data stored in the provided wolfSSH session. This is not to be confused with the wolfSSH's context data used to create the session. -## Setting the Keyboard Authentication Prompts Callback Function +## Setting the Keyboard-Interactive Prompts + +There is no separate callback for the keyboard-interactive prompts. The server +calls the user authentication callback with the `authType` +`WOLFSSH_USERAUTH_KEYBOARD_SETUP` to get the prompts to send to the client, as +described in the previous chapter. Keyboard-interactive authentication requires +a build with `--enable-keyboard-interactive` (`WOLFSSH_KEYBOARD_INTERACTIVE`). + +## Setting the Allowed Authentication Types Callback Function ``` -void wolfSSH_SetKeyboardAuthPrompts(WOLFSSH_CTX* ctx, WS_CallbackKeyboardAuthPrompts cb); +void wolfSSH_SetUserAuthTypes(WOLFSSH_CTX* ctx, WS_CallbackUserAuthTypes cb); ``` -The server needs to specify the prompts that are to be given to the client so -that it can authenticate in Keyboard-Interactive mode. This callback allows the -server to set the prompts ready to send to the client. +The optional callback returns the set of authentication types, as a bit mask of +the `WOLFSSH_USERAUTH_*` type constants, that the server lists to the client as +able to continue. Without it, the server lists password, public key, and, when +built in, keyboard-interactive. + +## Setting the User Authentication Result Callback Function +``` +void wolfSSH_SetUserAuthResult(WOLFSSH_CTX* ctx, WS_CallbackUserAuthResult cb); +void wolfSSH_SetUserAuthResultCtx(WOLFSSH* ssh, void* userAuthResultCtx); +``` + +The optional callback is told the result of the library's check of a public +key user authentication signature. When it is told of a success, returning a +value other than `WS_SUCCESS` turns the attempt into a failure. + +## Setting the Maximum Authentication Attempts +``` +int wolfSSH_CTX_SetMaxAuthAttempts(WOLFSSH_CTX* ctx, int value); +int wolfSSH_SetMaxAuthAttempts(WOLFSSH* ssh, int value); +``` -Without this set, Keyboard-Interactive mode will be disabled on the server, even -if attempts are made to explicitly enable it. +The server disconnects a client after this many failed user authentication +attempts. The default is `DEFAULT_MAX_AUTH_ATTEMPTS` (6). A value of 0 or less +restores the default. ## Example Echo Server User Authentication diff --git a/wolfSSH/src/chapter07.md b/wolfSSH/src/chapter07.md index 75b00baa..fe788701 100644 --- a/wolfSSH/src/chapter07.md +++ b/wolfSSH/src/chapter07.md @@ -8,16 +8,17 @@ To build wolfSSH with support for SFTP use --enable-sftp, in the case of buildin ``` ./configure --enable-sftp && make ``` -By default the internal buffer size for handling reads and writes for get and put commands is set to 1024 bytes. This value can be overwritten in the case that the application needs to consume less resources or in the case that a larger buffer is desired. To override the default size define the macro `WOLFSSH_MAX_SFTP_RW` at compile time. An example of setting it would be as follows: +By default the internal buffer size for handling reads and writes for get and put commands is set to 32768 bytes. This value can be overwritten in the case that the application needs to consume less resources or in the case that a larger buffer is desired. To override the default size define the macro `WOLFSSH_MAX_SFTP_RW` at compile time. An example of setting it would be as follows: ``` -./configure --enable-sftp -C_EXTRA_FLAGS=’WOLFSSH_MAX_SFTP_RW=2048 +./configure --enable-sftp CPPFLAGS="-DWOLFSSH_MAX_SFTP_RW=2048" ``` +A server allows each session at most `WOLFSSH_MAX_SFTP_HANDLES` (64) open file and directory handles. File data buffers are zeroed before they are freed; the configure option `--disable-sftp-zeroize` (`WOLFSSH_NO_SFTP_BUFFER_ZERO`) turns that off. + ## Using wolfSSH SFTP Apps -A SFTP server and client application are bundled with wolfSSH. Both applications get built by autotools when building the wolfSSH library with SFTP support. The server application is located in examples/echoserver/ and is called echoserver. The client application is located in wolfsftp/client/ and is called wolfsftp. +A SFTP server and client application are bundled with wolfSSH. Both applications get built by autotools when building the wolfSSH library with SFTP support. The server application is located in examples/echoserver/ and is called echoserver. The client application is located in examples/sftpclient/ and is called wolfsftp. An example of starting up a server that would handle incoming SFTP client connections would be as follow: ``` @@ -27,18 +28,21 @@ Where the command is being ran from the root wolfSSH directory. This starts up a Starting the client with specific username: ``` -$ ./wolfsftp/client/wolfsftp -u +$ ./examples/sftpclient/wolfsftp -u ``` -The default “username:password” to run the test is either: “jack:fetchapail” or “jill:upthehill”. The default port is 22222. +The default "username:password" to run the test is either: "jack:fetchapail" or "jill:upthehill". The default port is 22222. -A full list of supported commands can be seen with typeing "help" after a connection. +A full list of supported commands can be seen with typing "help" after a connection. ``` wolfSSH sftp> help Commands : cd change directory chmod change mode + creat create file with given permissions get pulls file(s) from server + lcd change local directory + lls list local directory ls list current directory mkdir creates new directory on server put push file(s) to server @@ -55,3 +59,18 @@ An example of connecting to another system would be src/wolfssh$ ./examples/sftpclient/wolfsftp -p 22 -u user -h 192.168.1.111 ``` +## SFTP Server Start Directory and Confinement + +An SFTP server session has two independent path settings: + +- The start path is the directory the session begins in, which relative paths are resolved against. It grants and denies nothing. Set it with `wolfSSH_SFTP_SetDefaultPath()`. +- The confinement root is the directory the session is restricted to. A request for a path that resolves outside it fails with `WS_PERMISSIONS`. With no root, or a root of "/", the session is not confined. Set it with `wolfSSH_SFTP_SetConfinePath()`. + +Setting the start path does not confine the session. Keeping the two separate lets a server start a session deep inside the confinement root, confine a session without changing where it starts, or do neither and let the operating system limit access, as wolfSSHd does by running the session as the authenticated user. + +Paths are resolved lexically, which cannot prove that a symbolic link stays inside the root, so a confined session rejects every symbolic link below the root, including ones that point back inside it. Serve trees without symbolic links, or build with `WOLFSSH_NO_SYMLINK_CHECK` to drop the check along with the protection it gives. The root itself is not checked, so it should be a directory the server controls with no symbolic links in its path. The check is made before the operation uses the path, so a process running as the same user could still swap a path component for a link in between; for hostile multi-user deployments, also use an operating system jail. + +The example echoserver sets the start path with the option `-d`, and with the option `-D` also confines the session to it: +``` +./examples/echoserver/echoserver -d /srv/sftp -D +``` diff --git a/wolfSSH/src/chapter08.md b/wolfSSH/src/chapter08.md index 1d9e6c3f..ef8b77e2 100644 --- a/wolfSSH/src/chapter08.md +++ b/wolfSSH/src/chapter08.md @@ -34,3 +34,20 @@ src/wolfssl$ ./examples/client/client -p 12345 ``` This will allow port forwarding between the wolfSSL client and server like in the previous example. + +The portfwd example can also set up remote (reverse) forwarding with the option `-r`. It asks the SSH server to listen on the `-F`/`-f` address and port, and the server tunnels each connection made there back to portfwd, which connects it to the local `-T`/`-t` target. With `-r`, a `-f` port of 0 lets the server pick the port. + +``` +src/wolfssl$ ./examples/server/server +src/wolfssh$ ./examples/portfwd/portfwd -p 22 -u -r \ + -f 12345 -t 11111 +src/wolfssl$ ./examples/client/client -p 12345 +``` + +## Port Forwarding API + +The application controls forwarding with a forwarding callback set with `wolfSSH_CTX_SetFwdCb()`, and its context set with `wolfSSH_SetFwdCbCtx()`. The callback is consulted for every forwarding channel: an incoming "direct-tcpip" or "forwarded-tcpip" channel open is refused unless a forwarding callback is set and its `WOLFSSH_FWD_LOCAL_SETUP` call succeeds. Each successful `WOLFSSH_FWD_LOCAL_SETUP` is later matched by one `WOLFSSH_FWD_LOCAL_CLEANUP`, so the callback must not free that state twice. On a server, a "tcpip-forward" request from the client calls the forwarding callback with `WOLFSSH_FWD_REMOTE_SETUP`; for a request for port 0, the callback returns the port it allocated rather than `WS_FWD_SUCCESS`. + +A client sets up remote forwarding with `wolfSSH_FwdRemoteSetup()`, which asks the server to listen on an address and port and to send connections made there back as "forwarded-tcpip" channels, and stops it with `wolfSSH_FwdRemoteCancel()`. A client refuses a "forwarded-tcpip" channel open that does not match a forward it registered with `wolfSSH_FwdRemoteSetup()`, so a client that registered none refuses them all. A registered bind address of "", "*", "0.0.0.0", or an IPv6 any-address matches on the port alone; any other address must equal the address the server reports. For a server that reports a different spelling of the address, `wolfSSH_SetFwdRemoteMatch()` can relax the match to the port alone (`WOLFSSH_FWD_MATCH_PORT`) or turn it off (`WOLFSSH_FWD_MATCH_OFF`). A client refuses "tcpip-forward" and "cancel-tcpip-forward" requests sent to it. + +The functions `wolfSSH_CTX_SetFwdEnable()` and `wolfSSH_SetFwdEnable()`, which were declared but never defined, have been removed. Forwarding is enabled by building with `WOLFSSH_FWD` and setting a forwarding callback. diff --git a/wolfSSH/src/chapter09.md b/wolfSSH/src/chapter09.md index ecf164de..f40536ac 100644 --- a/wolfSSH/src/chapter09.md +++ b/wolfSSH/src/chapter09.md @@ -1,3 +1,12 @@ # Notes and Limitations -In portions of the implementation file attributes are not being considered and default attributes or mode values are used. Specifically in `wolfSSH_SFTP_Open`, getting timestamps from files, and all extended file attributes. +- SFTP is implemented at protocol version 3. Extended file attributes are not handled: they are neither sent nor applied. An SFTP `SETSTAT` or `FSETSTAT` request applies the attributes it carries or is answered with `SSH_FX_OP_UNSUPPORTED`. +- Password change requests are not supported and are refused. +- Compression is not supported; only "none" is offered. +- wolfSSH offers neither the `chacha20-poly1305@openssh.com` cipher nor the `*-etm@openssh.com` MACs. +- Algorithms using SHA-1, and AES-CBC, are compiled in but not offered by default. +- The "none" cipher and MAC can only be negotiated in a build with `--enable-none-cipher` (`WOLFSSH_ALLOW_NONE_CIPHER`). +- RSA user authentication keys must be at least 2048 bits (`WOLFSSH_RSA_MIN_KEY_BITS`). +- DH group exchange uses groups of at least 2048 bits (`WOLFSSH_DEFAULT_GEXDH_MIN`), so it fails with a server that only offers 1024-bit groups. +- Applications must read the stderr (extended) data a peer sends. Data left unread fills the channel window and stalls the channel. +- wolfSSHd recognizes, but does not implement, the directives `Subsystem`, `ChallengeResponseAuthentication`, `UsePAM`, `X11Forwarding`, `PrintMotd`, `AcceptEnv` and `UseDNS`. It does not enforce the `command=` option in authorized keys files, and does not support OpenSSH certificate logins on Windows. diff --git a/wolfSSH/src/chapter11.md b/wolfSSH/src/chapter11.md index f6fdd7ba..4134da25 100644 --- a/wolfSSH/src/chapter11.md +++ b/wolfSSH/src/chapter11.md @@ -13,7 +13,7 @@ For information regarding wolfSSL products, questions regarding licensing, or ge If you are submitting a bug report or asking about a problem, please include the following information with your submission: -1. wolfSSL version number +1. wolfSSH and wolfSSL version numbers 2. Operating System version 3. Compiler version 4. The exact error you are seeing diff --git a/wolfSSH/src/chapter12.md b/wolfSSH/src/chapter12.md index 823e4a79..6bba1b1a 100644 --- a/wolfSSH/src/chapter12.md +++ b/wolfSSH/src/chapter12.md @@ -2,11 +2,14 @@ ## Product Release Information +The current release is wolfSSH v1.6.0, released October 6, 2026. The changes in each release are listed in the file ChangeLog.md in the wolfSSH source, and on the GitHub releases page. + We regularly post update information on Twitter. For additional release information, you can keep track of our projects on GitHub, follow us on Facebook, or follow our daily blog. - wolfSSH on GitHub [https://www.github.com/wolfssl/wolfssh](https://www.github.com/wolfssl/wolfssh) +- wolfSSH releases [https://github.com/wolfSSL/wolfssh/releases](https://github.com/wolfSSL/wolfssh/releases) - wolfSSL on Twitter [https://twitter.com/wolfSSL](https://twitter.com/wolfSSL) - wolfSSL on Facebook [https://www.facebook.com/wolfSSL](https://www.facebook.com/wolfSSL) - wolfSSL on Reddit [https://www.reddit.com/r/wolfssl/](https://www.reddit.com/r/wolfssl/) -- Daily Blog [https://wolfssl.com/wolfSSL/Blog/Blog.html](https://wolfssl.com/wolfSSL/Blog/Blog.html) +- Daily Blog [https://www.wolfssl.com/blog](https://www.wolfssl.com/blog) diff --git a/wolfSSH/src/chapter13.md b/wolfSSH/src/chapter13.md index ba9107d8..bdfdbc08 100644 --- a/wolfSSH/src/chapter13.md +++ b/wolfSSH/src/chapter13.md @@ -10,45 +10,110 @@ This section describes the public application program interfaces for the wolfSSH -The following API response codes are defined in: wolfssh/wolfssh/error.h and describe the different types of errors that can occur. +The following API response codes are defined in wolfssh/error.h and describe the different types of errors that can occur. `WS_SUCCESS` is 0; all error codes are negative. `WS_FATAL_ERROR` is a deprecated alias for `WS_ERROR`, and `WS_LAST_E` always tracks the last defined error code (`WS_CERT_KEY_USAGE_E` as of v1.6.0). Value -1059 is unassigned. - WS_SUCCESS (0): Function success -- WS_FATAL_ERROR (-1): General function failure -- WS_BAD_ARGUMENT (-2): Function argument out of bounds -- WS_MEMORY_E (-3): Memory allocation error -- WS_BUFFER_E (-4): Input/output buffer size error -- WS_PARSE_E (-5): General parsing error -- WS_NOT_COMPILED (-6): Feature not compiled in -- WS_OVERFLOW_E (-7): Would overflow if continued -- WS_BAD_USAGE (-8): Bad example usage -- WS_SOCKET_ERROR_E (-9): Socket error -- WS_WANT_READ (-10): IO callback would read block error -- WS_WANT_WRITE (-11): IO callback would write block error -- WS_RECV_OVERFLOW_E (-12): Received buffer overflow -- WS_VERSION_E (-13): Peer using wrong version of SSH -- WS_SEND_OOB_READ_E (-14): Attempted to read buffer out of bounds -- WS_INPUT_CASE_E (-15): Bad process input state, programming error -- WS_BAD_FILETYPE_E (-16): Bad filetype -- WS_UNIMPLEMENTED_E (-17): Feature not implemented -- WS_RSA_E (-18): RSA buffer error -- WS_BAD_FILE_E (-19): Bad file -- WS_INVALID_ALGO_ID (-20): invalid algorithm ID -- WS_DECRYPT_E (-21): Decrypt error -- WS_ENCRYPT_E (-22): Encrypt error -- WS_VERIFY_MAC_E (-23): verify mac error -- WS_CREATE_MAC_E (-24): Create mac error -- WS_RESOURCE_E (-25): Insufficient resources for new channel -- WS_INVALID_CHANTYPE (-26): Invalid channel type -- WS_INVALID_CHANID(-27): Peer requested invalid channel ID -- WS_INVALID_USERNAME(-28): Invalid user name -- WS_CRYPTO_FAILED(-29): Crypto action failed -- WS_INVALID_STATE_E(-30): Invalid State -- WC_EOF(-31): End of File -- WS_INVALID_PRIME_CURVE(-32): Invalid prime curve in ECC -- WS_ECC_E(-33): ECDSA buffer error -- WS_CHANOPEN_FAILED(-34): Peer returned channel open failure -- WS_REKEYING(-35): Rekeying with peer -- WS_CHANNEL_CLOSED(-36): Channel closed +- WS_ERROR (-1001): General function failure +- WS_FATAL_ERROR (-1001): Deprecated alias for WS_ERROR +- WS_BAD_ARGUMENT (-1002): Bad function argument +- WS_MEMORY_E (-1003): Memory allocation failure +- WS_BUFFER_E (-1004): Input/output buffer size error +- WS_PARSE_E (-1005): General parsing error +- WS_NOT_COMPILED (-1006): Feature not compiled in +- WS_OVERFLOW_E (-1007): Would overflow if continued +- WS_BAD_USAGE (-1008): Bad example usage +- WS_SOCKET_ERROR_E (-1009): Socket error +- WS_WANT_READ (-1010): Nonblocking read would block, call again +- WS_WANT_WRITE (-1011): Nonblocking write would block, call again +- WS_RECV_OVERFLOW_E (-1012): Received buffer overflow +- WS_VERSION_E (-1013): Peer using wrong version of SSH +- WS_SEND_OOB_READ_E (-1014): Attempted to read buffer out of bounds +- WS_INPUT_CASE_E (-1015): Bad process input state, programming error +- WS_BAD_FILETYPE_E (-1016): Bad file type +- WS_UNIMPLEMENTED_E (-1017): Feature not implemented +- WS_RSA_E (-1018): RSA buffer error +- WS_BAD_FILE_E (-1019): Bad file +- WS_INVALID_ALGO_ID (-1020): Invalid algorithm ID +- WS_DECRYPT_E (-1021): Decrypt error +- WS_ENCRYPT_E (-1022): Encrypt error +- WS_VERIFY_MAC_E (-1023): Verify MAC error +- WS_CREATE_MAC_E (-1024): Create MAC error +- WS_RESOURCE_E (-1025): Insufficient resources for new channel +- WS_INVALID_CHANTYPE (-1026): Invalid channel type +- WS_INVALID_CHANID (-1027): Peer requested invalid channel ID +- WS_INVALID_USERNAME (-1028): Invalid user name +- WS_CRYPTO_FAILED (-1029): Crypto action failed +- WS_INVALID_STATE_E (-1030): Invalid state +- WS_EOF (-1031): End of file +- WS_INVALID_PRIME_CURVE (-1032): Invalid prime curve in ECC +- WS_ECC_E (-1033): ECDSA buffer error +- WS_CHANOPEN_FAILED (-1034): Peer returned channel open failure +- WS_REKEYING (-1035): Status: rekey in progress +- WS_CHANNEL_CLOSED (-1036): Status: channel closed +- WS_INVALID_PATH_E (-1037): Invalid path +- WS_SCP_CMD_E (-1038): SCP command error +- WS_SCP_BAD_MSG_E (-1039): SCP bad message +- WS_SCP_PATH_LEN_E (-1040): SCP path too long +- WS_SCP_TIMESTAMP_E (-1041): SCP timestamp error +- WS_SCP_DIR_STACK_EMPTY_E (-1042): SCP directory stack empty +- WS_SCP_CONTINUE (-1043): Status: SCP continue +- WS_SCP_ABORT (-1044): Status: SCP abort +- WS_SCP_ENTER_DIR (-1045): Status: SCP enter directory +- WS_SCP_EXIT_DIR (-1046): Status: SCP exit directory +- WS_SCP_EXIT_DIR_FINAL (-1047): Status: SCP exit final directory +- WS_SCP_COMPLETE (-1048): Status: SCP transfer complete +- WS_SCP_INIT (-1049): Status: SCP transfer verified +- WS_MATCH_KEX_ALGO_E (-1050): Cannot match KEX algorithm with peer +- WS_MATCH_KEY_ALGO_E (-1051): Cannot match key algorithm with peer +- WS_MATCH_ENC_ALGO_E (-1052): Cannot match encryption algorithm with peer +- WS_MATCH_MAC_ALGO_E (-1053): Cannot match MAC algorithm with peer +- WS_PERMISSIONS (-1054): Permissions error +- WS_SFTP_COMPLETE (-1055): Status: SFTP connection established +- WS_NEXT_ERROR (-1056): Getting next value/state is error +- WS_CHAN_RXD (-1057): Status: channel data received +- WS_INVALID_EXTDATA (-1058): Invalid channel extended data type +- WS_SFTP_BAD_REQ_ID (-1060): SFTP bad request ID +- WS_SFTP_BAD_REQ_TYPE (-1061): SFTP bad request type +- WS_SFTP_STATUS_NOT_OK (-1062): SFTP status not OK +- WS_SFTP_FILE_DNE (-1063): SFTP file does not exist +- WS_SIZE_ONLY (-1064): Only getting size of buffer needed +- WS_CLOSE_FILE_E (-1065): Unable to close local file +- WS_PUBKEY_REJECTED_E (-1066): Server public key rejected +- WS_EXTDATA (-1067): Extended data available to be read +- WS_USER_AUTH_E (-1068): User authentication error +- WS_SSH_NULL_E (-1069): SSH object was null +- WS_SSH_CTX_NULL_E (-1070): SSH_CTX object was null +- WS_CHANNEL_NOT_CONF (-1071): Channel open not confirmed +- WS_CHANGE_AUTH_E (-1072): Changing auth type attempt +- WS_WINDOW_FULL (-1073): Channel window full +- WS_MISSING_CALLBACK (-1074): Callback is missing +- WS_DH_SIZE_E (-1075): DH prime larger than expected +- WS_PUBKEY_SIG_MIN_E (-1076): Signature too small +- WS_AGENT_NULL_E (-1077): Agent object was null +- WS_AGENT_NO_KEY_E (-1078): Agent does not have requested key +- WS_AGENT_CXN_FAIL (-1079): Could not connect to agent +- WS_SFTP_BAD_HEADER (-1080): SFTP bad header +- WS_CERT_NO_SIGNER_E (-1081): No signer certificate available +- WS_CERT_EXPIRED_E (-1082): Certificate expired +- WS_CERT_REVOKED_E (-1083): User certificate reported revoked +- WS_CERT_SIG_CONFIRM_E (-1084): Root certificate signature verify failure +- WS_CERT_OTHER_E (-1085): Other certificate issue +- WS_CERT_PROFILE_E (-1086): Certificate does not meet profile requirements +- WS_CERT_KEY_SIZE_E (-1087): Key size error +- WS_CTX_KEY_COUNT_E (-1088): Adding too many private keys +- WS_MATCH_UA_KEY_ID_E (-1089): Match user auth key failure +- WS_KEY_AUTH_MAGIC_E (-1090): OpenSSH key auth magic check failure +- WS_KEY_CHECK_VAL_E (-1091): OpenSSH key check value failure +- WS_KEY_FORMAT_E (-1092): OpenSSH key format failure +- WS_SFTP_NOT_FILE_E (-1093): Not a regular file +- WS_MSGID_NOT_ALLOWED_E (-1094): Message ID not allowed at this point in the protocol +- WS_ED25519_E (-1095): Ed25519 failure +- WS_AUTH_PENDING (-1096): User authentication still pending +- WS_KDF_E (-1097): KDF error +- WS_DISCONNECT (-1098): Peer sent disconnect +- WS_MLDSA_E (-1099): ML-DSA failure +- WS_ED448_E (-1100): Ed448 failure +- WS_CERT_KEY_USAGE_E (-1101): Certificate KeyUsage or ExtendedKeyUsage does not permit SSH use ### WS_IOerrors (enum) @@ -62,7 +127,7 @@ These are the return codes the library expects to receive from a user-provided I - WS_CBIO_ERR_CONN_RST (-3): Connection reset - WS_CBIO_ERR_ISR (-4): Interrupt - WS_CBIO_ERR_CONN_CLOSE (-5): Connection closed or EPIPE -- WS_CBIO_ERR_TIMEOUT (-6): Socket timeout" +- WS_CBIO_ERR_TIMEOUT (-6): Socket timeout ## Initialization / Shutdown @@ -70,60 +135,53 @@ These are the return codes the library expects to receive from a user-provided I ### wolfSSH_Init() +```c +#include - -**Synopsis** +int wolfSSH_Init(void); +``` **Description** -Initializes the wolfSSH library for use. Must be called once per application and before any other calls to the library. - -**Return Values** - -WS_SUCCESS -WS_CRYPTO_FAILED +Initializes the wolfSSH library for use. Must be called once per application before any other call into the library. **Parameters** None -**See Also** +**Return Values** -wolfSSH_Cleanup() +- `WS_SUCCESS` +- `WS_CRYPTO_FAILED` -``` -#include -int wolfSSH_Init(void); -``` +**See Also** -### wolfSSH_Cleanup() +- `wolfSSH_Cleanup()` +### wolfSSH_Cleanup() +```c +#include -**Synopsis** +int wolfSSH_Cleanup(void); +``` **Description** -Cleans up the wolfSSH library when done. Should be called at before termination of the application. After calling, do not make any more calls to the library. - -**Return Values** - -**WS_SUCCESS** - -**WS_CRYPTO_FAILED** +Cleans up the wolfSSH library when done. Should be called before termination of the application. After calling, do not make any more calls to the library. **Parameters** None -**See Also** +**Return Values** -wolfSSH_Init() +- `WS_SUCCESS` +- `WS_CRYPTO_FAILED` -``` -#include -int wolfSSH_Cleanup(void); -``` +**See Also** + +- `wolfSSH_Init()` ## Debugging output functions @@ -131,57 +189,51 @@ int wolfSSH_Cleanup(void); ### wolfSSH_Debugging_ON() +```c +#include - -**Synopsis** +void wolfSSH_Debugging_ON(void); +``` **Description** Enables debug logging during runtime. Does nothing when debugging is disabled at build time. -**Return Values** +**Parameters** None -**Parameters** +**Return Values** None **See Also** -wolfSSH_Debugging_OFF() - -``` -#include -void wolfSSH_Debugging_ON(void); -``` +- `wolfSSH_Debugging_OFF()` ### wolfSSH_Debugging_OFF() +```c +#include - -**Synopsis** +void wolfSSH_Debugging_OFF(void); +``` **Description** Disables debug logging during runtime. Does nothing when debugging is disabled at build time. -**Return Values** +**Parameters** None -**Parameters** +**Return Values** None **See Also** -wolfSSH_Debugging_ON() - -``` -#include -void wolfSSH_Debugging_OFF(void); -``` +- `wolfSSH_Debugging_ON()` ## Context Functions @@ -189,1995 +241,4871 @@ void wolfSSH_Debugging_OFF(void); ### wolfSSH_CTX_new() +```c +#include - -**Synopsis** +WOLFSSH_CTX* wolfSSH_CTX_new(byte side, void* heap); +``` **Description** Creates a wolfSSH context object. This object can be configured and then used as a factory for wolfSSH session objects. -**Return Values** +**Parameters** -**WOLFSSH_CTX*** – returns pointer to allocated WOLFSSH_CTX object or NULL +- `side` - the endpoint role: `WOLFSSH_ENDPOINT_SERVER` or `WOLFSSH_ENDPOINT_CLIENT` +- `heap` - pointer to a heap to use for memory allocations, or `NULL` -**Parameters** +**Return Values** -**side** – indicate client side (unimplemented) or server side -**heap** – pointer to a heap to use for memory allocations +- `WOLFSSH_CTX*` - pointer to the newly allocated context object +- `NULL` - on failure **See Also** -wolfSSH_wolfSSH_CTX_free() - -``` -#include -WOLFSSH_CTX* wolfSSH_CTX_new(byte side , void* heap ); -``` +- `wolfSSH_CTX_free()` ### wolfSSH_CTX_free() +```c +#include - -**Synopsis** +void wolfSSH_CTX_free(WOLFSSH_CTX* ctx); +``` **Description** Deallocates a wolfSSH context object. -**Return Values** +**Parameters** -None +- `ctx` - the wolfSSH context to free -**Parameters** +**Return Values** -**ctx** – the wolfSSH context used to initialize the wolfSSH session +None **See Also** -wolfSSH_wolfSSH_CTX_new() - -``` -#include -void wolfSSH_CTX_free(WOLFSSH_CTX* ctx ); -``` +- `wolfSSH_CTX_new()` ### wolfSSH_CTX_SetBanner() +```c +#include -**Synopsis** +int wolfSSH_CTX_SetBanner(WOLFSSH_CTX* ctx, const char* newBanner); +``` **Description** -Sets a banner message that a user can see. +Sets a banner message presented to the peer before authentication. -**Return Values** +**Parameters** -WS_BAD_ARGUMENT -WS_SUCCESS +- `ctx` - pointer to the wolfSSH context +- `newBanner` - the banner message text -**Parameters** +**Return Values** -**ssh -** Pointer to wolfSSH session -**newBanner** - The banner message text. +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` -``` -#include -int wolfSSH_CTX_SetBanner(WOLFSSH_CTX* ctx , const char* -newBanner ); -``` +**See Also** -### wolfSSH_CTX_UsePrivateKey_buffer() +- `wolfSSH_CTX_UsePrivateKey_buffer()` +### wolfSSH_CTX_UsePrivateKey_buffer() +```c +#include -**Synopsis** +int wolfSSH_CTX_UsePrivateKey_buffer(WOLFSSH_CTX* ctx, + const byte* in, word32 inSz, int format); +``` **Description** -This function loads a private key buffer into the SSH context. It is called with a buffer as input instead of a file. The buffer is provided by the **in** argument of size **inSz**. The argument **format** specifies the type of buffer: **WOLFSSH_FORMAT_ASN1** or **WOLFSSL_FORMAT_PEM** (unimplemented at this time). +Loads a private key from a buffer into the SSH context instead of from a file. The key is provided by the `in` argument of size `inSz`. The `format` argument specifies the buffer encoding: `WOLFSSH_FORMAT_ASN1` or `WOLFSSH_FORMAT_PEM` (PEM is unimplemented at this time). -**Return Values** +**Parameters** -**WS_SUCCESS -WS_BAD_ARGUMENT** – at least one of the parameters is invalid -**WS_BAD_FILETYPE_E** – wrong format -**WS_UNIMPLEMENTED_E** – support for PEM format not implemented -**WS_MEMORY_E** – out of memory condition -**WS_RSA_E** – cannot decode RSA key -**WS_BAD_FILE_E** – cannot parse buffer +- `ctx` - pointer to the wolfSSH context +- `in` - buffer containing the private key to be loaded +- `inSz` - size of the input buffer +- `format` - format of the private key in the input buffer -**Parameters** +**Return Values** -**ctx** – pointer to the wolfSSH context -**in** – buffer containing the private key to be loaded -**inSz** – size of the input buffer -**format** – format of the private key located in the input buffer +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_BAD_FILETYPE_E` +- `WS_UNIMPLEMENTED_E` +- `WS_MEMORY_E` +- `WS_RSA_E` +- `WS_BAD_FILE_E` **See Also** -wolfSSH_UseCert_buffer() -wolfSSH_UseCaCert_buffer() +- `wolfSSH_CTX_UseCert_buffer()` -``` +### wolfSSH_CTX_UseCert_buffer() + +**Availability** + +Requires `WOLFSSH_CERTS`. + +```c #include -int wolfSSH_CTX_UsePrivateKey_buffer(WOLFSSH_CTX* ctx , -const byte* in , word32 inSz , int format ); + +int wolfSSH_CTX_UseCert_buffer(WOLFSSH_CTX* ctx, + const byte* cert, word32 certSz, int format); ``` -## SSH Session Functions +**Description** +Loads the server's X.509 certificate from a buffer into the context, for certificate-based host authentication. The `format` is `WOLFSSH_FORMAT_ASN1` or `WOLFSSH_FORMAT_PEM`. The buffer should hold the leaf certificate; when a PEM buffer holds several certificates, only the first is read. The "TRUSTED CERTIFICATE" PEM form is meant for root CAs and is declined here. +**Parameters** -### wolfSSH_new() +- `ctx` - pointer to the wolfSSH context +- `cert` - buffer containing the certificate +- `certSz` - size of the certificate buffer +- `format` - encoding of the certificate +**Return Values** +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` -**Synopsis** +**See Also** -**Description** +- `wolfSSH_CTX_AddRootCert_buffer()` -Creates a wolfSSH session object. It is initialized with the provided wolfSSH context. +### wolfSSH_CTX_AddRootCert_buffer() -**Return Values** +**Availability** -**WOLFSSH*** – returns pointer to allocated WOLFSSH object or NULL +Requires `WOLFSSH_CERTS`. + +```c +#include + +int wolfSSH_CTX_AddRootCert_buffer(WOLFSSH_CTX* ctx, + const byte* cert, word32 certSz, int format); +``` + +**Description** + +Adds a trusted root CA certificate to the context, used to verify certificates presented by the peer. The `format` is `WOLFSSH_FORMAT_ASN1` or `WOLFSSH_FORMAT_PEM`. A PEM buffer may be a bundle: every certificate in it is loaded, in either the plain or the "TRUSTED CERTIFICATE" form (the latter with wolfSSL 5.8.0 or later). A block that fails to load is skipped; the call fails only when no CA could be loaded at all. **Parameters** -**ctx** – the wolfSSH context used to initialize the wolfSSH session +- `ctx` - pointer to the wolfSSH context +- `cert` - buffer containing the root certificate +- `certSz` - size of the certificate buffer +- `format` - encoding of the certificate + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` **See Also** -wolfSSH_free() +- `wolfSSH_CTX_UseCert_buffer()` +- `wolfSSH_CTX_AddRootCert_file()` -``` -#include -WOLFSSH* wolfSSH_new(WOLFSSH_CTX* ctx ); -``` +### wolfSSH_CTX_UseCert_file() -### wolfSSH_free() +**Availability** +Requires `WOLFSSH_CERTS` and filesystem support (not available with `NO_FILESYSTEM` or `WOLFSSH_USER_FILESYSTEM`). +```c +#include -**Synopsis** +int wolfSSH_CTX_UseCert_file(WOLFSSH_CTX* ctx, const char* name); +``` **Description** -Deallocates a wolfSSH session object. +Loads the server's X.509 certificate from the file `name` into the context, the file counterpart of wolfSSH_CTX_UseCert_buffer(). Whether the file holds PEM or DER is detected from its content. An OpenSSH certificate line is not accepted here. -**Return Values** +**Parameters** -None +- `ctx` - pointer to the wolfSSH context +- `name` - path to the certificate file -**Parameters** +**Return Values** -**ssh** – session to deallocate +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` or `name` is NULL +- `WS_BAD_FILE_E` - the file cannot be opened or read, is empty, or is larger than `WOLFSSH_MAX_FILE_SIZE` +- `WS_BAD_FILETYPE_E` - the content is not a PEM or DER X.509 certificate +- `WS_MEMORY_E` +- other errors from decoding the certificate **See Also** -wolfSSH_new() +- `wolfSSH_CTX_UseCert_buffer()` +- `wolfSSH_CTX_AddRootCert_file()` -``` -#include -void wolfSSH_free(WOLFSSH* ssh ); -``` +### wolfSSH_CTX_AddRootCert_file() -### wolfSSH_set_fd() +**Availability** +Requires `WOLFSSH_CERTS` and filesystem support (not available with `NO_FILESYSTEM` or `WOLFSSH_USER_FILESYSTEM`). +```c +#include -**Synopsis** +int wolfSSH_CTX_AddRootCert_file(WOLFSSH_CTX* ctx, const char* name); +``` **Description** -Assigns the provided file descriptor to the ssh object. The ssh session will use the file descriptor for network I/O in the default I/O callbacks. +Adds the trusted root CA certificate(s) in the file `name` to the context, the file counterpart of wolfSSH_CTX_AddRootCert_buffer(). Whether the file holds PEM or DER is detected from its content; a PEM bundle loads every CA it contains. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `name` - path to the CA certificate file **Return Values** -#### WS_SUCCESS +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` or `name` is NULL +- `WS_BAD_FILE_E` - the file cannot be opened or read, is empty, or is larger than `WOLFSSH_MAX_FILE_SIZE` +- `WS_BAD_FILETYPE_E` - the content is not a PEM or DER X.509 certificate +- `WS_MEMORY_E` +- other errors from decoding the certificate -WS_BAD_ARGUMENT – one of the parameters is invalid +**See Also** -**Parameters** +- `wolfSSH_CTX_AddRootCert_buffer()` +- `wolfSSH_CTX_UseCert_file()` -**ssh** – session to set the fd -**fd** – file descriptor for the socket used by the session +### wolfSSH_CTX_UsePrivateKey_fromStore() -**See Also** +**Availability** -wolfSSH_get_fd() +Requires `WOLFSSH_CERTS` and `WOLFSSH_WINDOWS_CERT_STORE` (Windows only). -``` +```c #include -int wolfSSH_set_fd(WOLFSSH* ssh , int fd ); + +int wolfSSH_CTX_UsePrivateKey_fromStore(WOLFSSH_CTX* ctx, + const wchar_t* storeName, word32 dwFlags, + const wchar_t* subjectName); ``` -### wolfSSH_get_fd() +**Description** +Uses a certificate and its private key from a Windows system certificate store as the server host key. The certificate is located by its Common Name, `subjectName`, which may carry a "CN=" prefix and must match in full, case insensitively. The store `storeName` (for example, L"My") is opened read-only. `dwFlags` selects the store location and must hold only `CERT_SYSTEM_STORE_*` location bits, such as `CERT_SYSTEM_STORE_CURRENT_USER`; control flags such as `CERT_STORE_DELETE_FLAG` are rejected. +The key is registered under its plain key type (`ssh-rsa` or `ecdsa-sha2-nistp*`) and, where the build supports it, under the matching RFC 6187 `x509v3-*` type, so the store certificate itself can be sent to peers that negotiate certificate algorithms. The private key stays in the store; signing is done through CNG. -**Synopsis** +Only a time-valid certificate whose private key is accessible and usable for signing is selected. When only expired or not-yet-valid certificates match, the call fails with `WS_CERT_EXPIRED_E`; define `WOLFSSH_CERT_STORE_ALLOW_EXPIRED` to select one of them instead. A store key cannot be mixed with a file- or TPM-based host key or host certificate already loaded for the same algorithm, in either load order; replacing a previously loaded store key is allowed. On any failure the context is left unchanged. -**Description** +**Parameters** -This function returns the file descriptor ( **fd** ) used as the input/output facility for the SSH connection. Typically this will be a socket file descriptor. +- `ctx` - pointer to the wolfSSH context +- `storeName` - name of the system certificate store +- `dwFlags` - the store location, a `CERT_SYSTEM_STORE_*` value +- `subjectName` - Common Name of the certificate to use **Return Values** -**int** – file descriptor -**WS_BAD_ARGUEMENT** +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - a NULL argument, bad `dwFlags`, an unsupported key type, or a mixed key configuration +- `WS_BAD_FILE_E` - the store cannot be opened +- `WS_CRYPTO_FAILED` - certificates match, but none has a private key that is both accessible and enrolled for signing +- `WS_CERT_EXPIRED_E` - only certificates outside their validity period match +- `WS_CTX_KEY_COUNT_E` - two free key slots are not available +- `WS_MEMORY_E` +- `WS_FATAL_ERROR` - no certificate matches -**Parameters** +**See Also** -**ssh** – pointer to the SSL session. +- `wolfSSH_CTX_GetCertStoreCert()` +- `wolfSSH_CTX_UsePrivateKey_buffer()` -**See Also** +### wolfSSH_CTX_GetCertStoreCert() -wolfSSH_set_fd() +**Availability** -``` +Requires `WOLFSSH_CERTS` and `WOLFSSH_WINDOWS_CERT_STORE` (Windows only). + +```c #include -int wolfSSH_get_fd(const WOLFSSH* ssh ); + +int wolfSSH_CTX_GetCertStoreCert(WOLFSSH_CTX* ctx, + const byte** cert, word32* certSz, const char** algoName); ``` -## Data High Water Mark Functions +**Description** +Reports the certificate that a host key loaded with wolfSSH_CTX_UsePrivateKey_fromStore() is bound to, so an application can offer it for certificate user authentication. `cert` and `certSz` receive the DER certificate, which is owned by the context and remains valid until the context is freed or the key slot is replaced. `algoName` receives the static `x509v3-*` algorithm name. Any of the output pointers may be NULL to skip it. When several store credentials are loaded, the first `x509v3-*` slot in load order is returned. +**Parameters** -### wolfSSH_SetHighwater() +- `ctx` - pointer to the wolfSSH context +- `cert` - output for a pointer to the DER certificate +- `certSz` - output for the certificate size +- `algoName` - output for the SSH algorithm name +**Return Values** -**Synopsis** +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` is NULL +- `WS_FATAL_ERROR` - no certificate-store-backed `x509v3-*` key slot exists -**Description** +**See Also** -Sets the highwater mark for the ssh session. +- `wolfSSH_CTX_UsePrivateKey_fromStore()` -**Return Values** +## SSH Session Functions -WS_SUCCESS -WS_BAD_ARGUMENT -**Parameters** -**ssh -** Pointer to wolfSSH session -**highwater** - data indicating the highwater security mark +### wolfSSH_new() -``` +```c #include -int wolfSSH_SetHighwater(WOLFSSH* ssh , word32 highwater ); -``` -### wolfSSH_GetHighwater() +WOLFSSH* wolfSSH_new(WOLFSSH_CTX* ctx); +``` +**Description** -**Synopsis** +Creates a wolfSSH session object, initialized with the provided wolfSSH context. -**Description** +**Parameters** -Returns the highwater security mark +- `ctx` - the wolfSSH context used to initialize the session **Return Values** -**word32** - The highwater security mark. +- `WOLFSSH*` - pointer to the newly allocated session object +- `NULL` - on failure -**Parameters** +**See Also** -**ssh -** Pointer to wolfSSH session +- `wolfSSH_free()` -``` +### wolfSSH_free() + +```c #include -word32 wolfSSH_GetHighwater(WOLFSSH* ssh ); -``` -### wolfSSH_SetHighwaterCb() +void wolfSSH_free(WOLFSSH* ssh); +``` +**Description** -**Synopsis** +Deallocates a wolfSSH session object. -**Description** +**Parameters** -The wolfSSH_SetHighwaterCb function sets the highwater security mark for the SSH session as well as the high water call back. +- `ssh` - session to deallocate **Return Values** -none +None -**Parameters** +**See Also** -**ctx** – The wolfSSH context used to initialize the wolfSSH session. -**highwater** - The highwater security mark. -**cb** - The call back highwater function. +- `wolfSSH_new()` -``` +### wolfSSH_worker() + +```c #include -void wolfSSH_SetHighwaterCb(WOLFSSH_CTX* ctx , word32 highwater , -WS_CallbackHighwater cb ); + +int wolfSSH_worker(WOLFSSH* ssh, word32* channelId); ``` -### wolfSSH_SetHighwaterCtx() +**Description** +Services the SSH connection: receives any pending inbound data and flushes pending outbound packets. This is the main driver call for a running session. Besides `WS_SUCCESS`, it returns several non-fatal statuses that callers must not treat as errors: -**Synopsis** +- `WS_CHAN_RXD` - channel data arrived; read it with wolfSSH_stream_read() or wolfSSH_ChannelIdRead() +- `WS_EXTDATA` - extended (stderr) data arrived; drain it with wolfSSH_ChannelIdReadExt() (or wolfSSH_extended_data_read() for the first channel) +- `WS_EOF` - the peer half-closed a channel. It sends no more data, but the channel is still open for sending. This is reported once, on arrival; an application that must not miss it tests wolfSSH_ChannelGetEof() or registers the channel EOF callback. The library does not answer with an EOF of its own; reply, if the protocol wants one, with wolfSSH_ChannelSendEof(). +- `WS_CHANNEL_CLOSED` - the peer closed a channel, which has been retired +- `WS_WANT_READ`, `WS_WANT_WRITE`, `WS_REKEYING` - transient; call again -**Description** +Take the event from the return value, not from wolfSSH_get_error(). The return names what arrived; wolfSSH_get_error() names what the transport did, and on any pass the two are independent: the return can carry an event while wolfSSH_get_error() reports a write that is still owed or that failed. A caller that tolerates only `WS_WANT_READ` drops live sessions, since a queued write reports `WS_WANT_WRITE`. Any other code is an error, either in the return itself or as `WS_FATAL_ERROR` with the cause in wolfSSH_get_error() -- `WS_DISCONNECT` for the peer's disconnect, which is how most sessions end. Once the session has disconnected, every further call returns `WS_FATAL_ERROR` with `WS_DISCONNECT` latched. + +To ask whether a write is still owed, call wolfSSH_OutputPending(); to ask whether a key exchange is in flight, call wolfSSH_RekeyPending(). + +For `WS_CHAN_RXD`, `WS_EXTDATA`, `WS_EOF`, `WS_SUCCESS`, and a `WS_REKEYING` that displaced `WS_SUCCESS` or `WS_CHAN_RXD`, the ID of the channel the event belongs to is written to `channelId` when it is not NULL. It is left alone for every other status, `WS_CHANNEL_CLOSED` included; use wolfSSH_GetLastRxId() there. -The wolfSSH_SetHighwaterCTX function sets the highwater security mark for the given context. +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `channelId` - optional output for the ID of the channel the event belongs to; may be NULL **Return Values** -none +- `WS_SUCCESS` +- `WS_CHAN_RXD` +- `WS_EXTDATA` +- `WS_EOF` +- `WS_CHANNEL_CLOSED` +- `WS_REKEYING` +- `WS_WANT_READ` +- `WS_WANT_WRITE` +- `WS_BAD_ARGUMENT` +- `WS_FATAL_ERROR` - check wolfSSH_get_error() for the cause -**Parameters** +**See Also** -**ssh -** pointer to wolfSSH session -**ctx** - pointer to highwater security mark in the wolfSSH context. +- `wolfSSH_GetLastRxId()` +- `wolfSSH_OutputPending()` +- `wolfSSH_RekeyPending()` -``` +### wolfSSH_GetLastRxId() + +```c #include -void wolfSSH_SetHighwaterCtx(WOLFSSH* ssh, void* ctx); -``` -### wolfSSH_GetHighwaterCtx() +int wolfSSH_GetLastRxId(WOLFSSH* ssh, word32* channelId); +``` +**Description** -**Synopsis** +Writes the channel ID of the channel that most recently received data into `channelId`. -**Description** +**Parameters** -The wolfSSH_GetHighwaterCtx() returns the highwaterCtx security mark from the SSH session. +- `ssh` - pointer to the wolfSSH session +- `channelId` - output for the last received channel ID **Return Values** -**void*** - the highwater security mark -**NULL** - if there is an error with the WOLFSSH object. +- `WS_SUCCESS` +- `WS_ERROR` -**Parameters** +**See Also** -**ssh -** pointer to WOLFSSH object +- `wolfSSH_worker()` -``` +### wolfSSH_OutputPending() + +```c #include -void wolfSSH_GetHighwaterCtx(WOLFSSH* ssh ); + +int wolfSSH_OutputPending(const WOLFSSH* ssh); ``` -## Error Checking +**Description** +Reports whether the session still has queued output that a short (non-blocking) send left unsent. Unlike a status code, it gives a correct answer after any return, including a success. Flush the queued data by calling wolfSSH_worker() (or the call that queued it) again. +**Parameters** -### wolfSSH_get_error() +- `ssh` - pointer to the wolfSSH session + +**Return Values** +- non-zero - a write is still owed +- 0 - nothing is queued, or `ssh` is NULL +**See Also** -**Synopsis** +- `wolfSSH_worker()` +- `wolfSSH_RekeyPending()` -**Description** +### wolfSSH_RekeyPending() -Returns the error set in the wolfSSH session object. +```c +#include -**Return Values** +int wolfSSH_RekeyPending(const WOLFSSH* ssh); +``` + +**Description** -WS_ErrorCodes (enum) +Reports whether a key exchange is in flight, the first one included. Only the exchange of SSH_MSG_NEWKEYS from both sides clears the flag, so it stays set after a failed exchange; end a service loop on the result of wolfSSH_worker(), not on this call. **Parameters** -**ssh** – pointer to WOLFSSH object +- `ssh` - pointer to the wolfSSH session -**See Also** +**Return Values** -wolfSSH_get_error_name() +- non-zero - a key exchange is in progress +- 0 - no key exchange is in progress, or `ssh` is NULL -``` -#include -int wolfSSH_get_error(const WOLFSSH* ssh ); -``` +**See Also** -### wolfSSH_get_error_name() +- `wolfSSH_worker()` +- `wolfSSH_OutputPending()` +- `wolfSSH_TriggerKeyExchange()` +### wolfSSH_set_fd() +```c +#include -**Synopsis** +int wolfSSH_set_fd(WOLFSSH* ssh, WS_SOCKET_T fd); +``` **Description** -Returns the name of the error set in the wolfSSH session object. +Assigns the provided file descriptor to the session. The session uses this descriptor for network I/O in the default I/O callbacks. -**Return Values** +**Parameters** -**const char*** – error name string +- `ssh` - session to set the descriptor on +- `fd` - file descriptor for the socket used by the session -**Parameters** +**Return Values** -**ssh** – pointer to WOLFSSH object +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` **See Also** -wolfSSH_get_error() +- `wolfSSH_get_fd()` -``` +### wolfSSH_get_fd() + +```c #include -const char* wolfSSH_get_error_name(const WOLFSSH* ssh ); -``` -### wolfSSH_ErrorToName() +WS_SOCKET_T wolfSSH_get_fd(const WOLFSSH* ssh); +``` +**Description** -**Synopsis** +Returns the file descriptor used as the input/output facility for the SSH connection. Typically this is a socket file descriptor. -**Description** +**Parameters** -Returns the name of an error when called with an error number in the parameter. +- `ssh` - pointer to the wolfSSH session **Return Values** -**const char*** – name of error string +- the session's socket file descriptor on success +- -1 (`INVALID_SOCKET` on Windows) if `ssh` is NULL. This is the same invalid-socket value a new session's descriptor is initialized to. -**Parameters** +**See Also** -**err** - the int value of the error - -``` -#include -const char* wolfSSH_ErrorToName(int err ); -``` - -## I/O Callbacks +- `wolfSSH_set_fd()` +### wolfSSH_SetFilesystemHandle() +```c +#include -### wolfSSH_SetIORecv() +int wolfSSH_SetFilesystemHandle(WOLFSSH* ssh, void* handle); +``` +**Description** -**Synopsis** +Associates a user-provided filesystem handle with the session. Ports that supply their own filesystem layer use this handle when performing file operations for the session. -**Description** +**Parameters** -This function registers a receive callback for wolfSSL to get input data. +- `ssh` - pointer to the wolfSSH session +- `handle` - opaque filesystem handle to associate with the session **Return Values** -None - -**Parameters** +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` -**ctx** – pointer to the SSH context -**cb** – function to be registered as the receive callback for the wolfSSH context, **ctx**. The signature of this function must follow that as shown above in the Synopsis section. +**See Also** -``` -#include -void wolfSSH_SetIORecv(WOLFSSH_CTX* ctx , WS_CallbackIORecv cb ); -``` +- `wolfSSH_GetFilesystemHandle()` -### wolfSSH_SetIOSend() +### wolfSSH_GetFilesystemHandle() +```c +#include -**Synopsis** +void* wolfSSH_GetFilesystemHandle(WOLFSSH* ssh); +``` **Description** -This function registers a send callback for wolfSSL to write output data. - -**Return Values** - -None +Returns the filesystem handle previously associated with the session by wolfSSH_SetFilesystemHandle(), or NULL if none was set. **Parameters** -**ctx** – pointer to the wolfSSH context -**cb** – function to be registered as the send callback for the wolfSSH context, **ctx**. The signature of this function must follow that as shown above in the Synopsis section. - -``` -#include -void wolfSSH_SetIOSend(WOLFSSH_CTX* ctx , WS_CallbackIOSend cb ); -``` +- `ssh` - pointer to the wolfSSH session -### wolfSSH_SetIOReadCtx() +**Return Values** +- the filesystem handle associated with the session +- `NULL` - if `ssh` is NULL or no handle was set -**Synopsis** +**See Also** -**Description** +- `wolfSSH_SetFilesystemHandle()` -This function registers a context for the SSH session receive callback function. +## Data High Water Mark Functions -**Return Values** -None -**Parameters** +### wolfSSH_SetHighwater() -**ssh** – pointer to WOLFSSH object -**ctx** – pointer to the context to be registered with the SSH session ( **ssh** ) receive callback -function. -``` +```c #include -void wolfSSH_SetIOReadCtx(WOLFSSH* ssh , void* ctx ); -``` -### wolfSSH_SetIOWriteCtx() +int wolfSSH_SetHighwater(WOLFSSH* ssh, word32 level); +``` +**Description** -**Synopsis** +Sets the data highwater mark, in bytes, for the session. When the amount of data transferred reaches this level, the highwater callback is invoked (typically to trigger a rekey). -**Description** +**Parameters** -This function registers a context for the SSH session’s send callback function. +- `ssh` - pointer to the wolfSSH session +- `level` - the highwater mark, in bytes **Return Values** -None +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` -**Parameters** +**See Also** -**ssh** – pointer to WOLFSSH session. -**ctx** – pointer to be registered with the SSH session’s ( **ssh** ) send callback function. +- `wolfSSH_GetHighwater()` -``` -#include -void wolfSSH_SetIOWriteCtx(WOLFSSH* ssh , void* ctx ); -``` +### wolfSSH_GetHighwater() -### wolfSSH_GetIOReadCtx() +```c +#include -**Synopsis** +word32 wolfSSH_GetHighwater(WOLFSSH* ssh); +``` **Description** -This function return the ioReadCtx member of the WOLFSSH structure. +Returns the current data highwater mark, in bytes, for the session. -**Return Values** +**Parameters** -**Void*** - pointer to the ioReadCtx member of the WOLFSSH structure. +- `ssh` - pointer to the wolfSSH session -**Parameters** +**Return Values** -**ssh** – pointer to WOLFSSH object +- the data highwater mark, in bytes -``` -#include -void* wolfSSH_GetIOReadCtx(WOLFSSH* ssh ); -``` +**See Also** -### wolfSSH_GetIOWriteCtx() +- `wolfSSH_SetHighwater()` +### wolfSSH_SetHighwaterCb() -**Synopsis** -**Description** +```c +#include -This function returns the ioWriteCtx member of the WOLFSSH structure. +void wolfSSH_SetHighwaterCb(WOLFSSH_CTX* ctx, word32 level, + WS_CallbackHighwater cb); +``` -**Return Values** +**Description** -**Void*** – pointer to the ioWriteCtx member of the WOLFSSH structure. +Sets, at the context level, the default data highwater mark and the callback that is invoked when a session reaches it. Sessions created from this context inherit these defaults. **Parameters** -**ssh** – pointer to WOLFSSH object +- `ctx` - pointer to the wolfSSH context +- `level` - the default data highwater mark, in bytes +- `cb` - the highwater callback function -``` -#include -void* wolfSSH_GetIOWriteCtx(WOLFSSH* ssh ); -``` +**Return Values** -## User Authentication +None +**See Also** +- `wolfSSH_SetHighwaterCtx()` -### wolfSSH_SetUserAuth() +### wolfSSH_SetHighwaterCtx() -**Synopsis** +```c +#include + +void wolfSSH_SetHighwaterCtx(WOLFSSH* ssh, void* ctx); +``` **Description** -The wolfSSH_SetUserAuth() function is used to set the user authentication for the -current wolfSSH context if the context does not equal NULL. +Sets the user context pointer that is passed to the session's highwater callback when it is invoked. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context pointer to pass to the highwater callback **Return Values** None -**Parameters** +**See Also** -**ctx** – pointer to the wolfSSH context -**cb** – call back function for the user authentication +- `wolfSSH_GetHighwaterCtx()` -``` -#include -void wolfSSH_SetUserAuth(WOLFSSH_CTX* ctx , -WS_CallbackUserAuth cb ) -``` +### wolfSSH_GetHighwaterCtx() -### wolfSSH_SetUserAuthCtx() +```c +#include -**Synopsis** +void* wolfSSH_GetHighwaterCtx(WOLFSSH* ssh); +``` **Description** -The wolfSSH_SetUserAuthCtx() function is used to set the value of the user -authentication context in the SSH session. +Returns the user context pointer previously set with wolfSSH_SetHighwaterCtx() that is passed to the highwater callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session **Return Values** -None +- the highwater user context pointer +- `NULL` - if `ssh` is invalid or no context was set -**Parameters** +**See Also** -**ssh** – pointer to WOLFSSH object -**userAuthCtx** – pointer to the user authentication context +- `wolfSSH_SetHighwaterCtx()` -``` +### wolfSSH_CTX_SetMsgHighwater() + +```c #include -void wolfSSH_SetUserAuthCtx(WOLFSSH* ssh , void* -userAuthCtx ) -``` -### wolfSSH_GetUserAuthCtx() +void wolfSSH_CTX_SetMsgHighwater(WOLFSSH_CTX* ctx, word32 level); +``` +**Description** -**Synopsis** +Sets, at the context level, the default packet-count highwater mark (RFC 4344, Section 3.1). When the number of packets sent or received on a session reaches this level, a rekey is triggered. Sessions created from this context inherit the default. -**Description** +**Parameters** -The wolfSSH_GetUserAuthCtx() function is used to return the pointer to the user -authentication context. +- `ctx` - pointer to the wolfSSH context +- `level` - the packet-count highwater mark **Return Values** -**Void*** – pointer to the user authentication context -**Null** – returns if ssh is equal to NULL +None -**Parameters** +**See Also** -**ssh** – pointer to WOLFSSH object +- `wolfSSH_SetMsgHighwater()` -``` +### wolfSSH_SetMsgHighwater() + +```c #include -void* wolfSSH_GetUserAuthCtx(WOLFSSH* ssh ) -``` -### wolfSSH_SetKeyboardAuthPrompts() +void wolfSSH_SetMsgHighwater(WOLFSSH* ssh, word32 level); +``` +**Description** -**Synopsis** +Sets the packet-count highwater mark (RFC 4344, Section 3.1) for a single session. -**Description** +**Parameters** -The wolfSSH_SetKeyboardAuthPrompts() function is used to setup the callback -which will provide the server with the prompts to send to the client. +- `ssh` - pointer to the wolfSSH session +- `level` - the packet-count highwater mark **Return Values** None -**Parameters** +**See Also** -**ctx** - pointer to the wolfSSH context -**cb** - callback function to provide the keyboard prompts +- `wolfSSH_GetMsgHighwater()` -``` +### wolfSSH_GetMsgHighwater() + +```c #include -void wolfSSH_SetKeyboardAuthPrompts(WOLFSSH_CTX* ctx, - WS_CallbackKeyboardAuthPrompts cb) -``` -### wolfSSH_SetKeyboardAuthCtx() +word32 wolfSSH_GetMsgHighwater(WOLFSSH* ssh); +``` +**Description** -**Synopsis** +Returns the current packet-count highwater mark for the session. -**Description** +**Parameters** -The wolfSSH_SetKeyboardAuthCtx() function is used to setup the user context -for the wolfSSH_SetKeyboardAuthPrompts() function. +- `ssh` - pointer to the wolfSSH session **Return Values** -None +- the packet-count highwater mark -**Parameters** +**See Also** -**ssh** - pointer to the WOLFSSH object -**keyboardAuthCtx* - pointer to the user context data +- `wolfSSH_SetMsgHighwater()` + +## Error Checking -``` -#include -void wolfSSH_SetKeyboardAuthCtx(WOLFSSH* ssh, void* keyboardAuthCtx) -``` -## Set Username +### wolfSSH_get_error() -### wolfSSH_SetUsername() +```c +#include -**Synopsis** +int wolfSSH_get_error(const WOLFSSH* ssh); +``` **Description** -Sets the username required for the SSH connection. +Returns the last error set on the wolfSSH session object. -**Return Values** +**Parameters** -WS_BAD_ARGUMENT -WS_SUCCESS -WS_MEMORY_E +- `ssh` - pointer to the wolfSSH session -**Parameters** +**Return Values** -**ssh -** Pointer to wolfSSH session -**username** - The input username for the SSH connection. +- a `WS_ErrorCodes` value (see Error Codes) -``` -#include -int wolfSSH_setUsername(WOLFSSH* ssh , const char* username ); -``` +**See Also** -## Connection Functions +- `wolfSSH_get_error_name()` + +### wolfSSH_get_error_name() -### wolfSSH_accept() +```c +#include -**Synopsis** +const char* wolfSSH_get_error_name(const WOLFSSH* ssh); +``` **Description** -wolfSSH_accept is called on the server side and waits for an SSH client to initiate the -SSH handshake. +Returns the name string of the last error set on the wolfSSH session object. -wolfSSL_accept() works with both blocking and non-blocking I/O. When the underlying -I/O is non-blocking, wolfSSH_accept() will return when the underlying I/O could not -satisfy the needs of wolfSSH_accept to continue the handshake. In this case, a call to -wolfSSH_get_error() will yield either **WS_WANT_READ** or **WS_WANT_WRITE**. The -calling process must then repeat the call to wolfSSH_accept when data is available to -read and wolfSSH will pick up where it left off. When using a non-blocking socket, -nothing needs to be done, but select() can be used to check for the required condition. +**Parameters** -If the underlying I/O is blocking, wolfSSH_accept() will only return once the handshake -has been finished or an error occurred. +- `ssh` - pointer to the wolfSSH session **Return Values** -**WS_SUCCESS** - The function succeeded. -**WS_BAD_ARGUMENT** - A parameter value was null. -**WS_FATAL_ERROR** – There was an error, call wolfSSH_get_error() for more detail +- pointer to the error name string -**Parameters** +**See Also** -**ssh** – pointer to the wolfSSH session +- `wolfSSH_get_error()` -**See Also** +### wolfSSH_ErrorToName() -wolfSSH_stream_read() -``` +```c #include -int wolfSSH_accept(WOLFSSH* ssh); + +const char* wolfSSH_ErrorToName(int err); ``` -### wolfSSH_connect() +**Description** +Returns the name string for the given wolfSSH error code. -**Synopsis** +**Parameters** -**Description** +- `err` - the error code value (a `WS_ErrorCodes` value) -This function is called on the client side and initiates an SSH handshake with a server. -When this function is called, the underlying communication channel has already been -set up. +**Return Values** -wolfSSH_connect() works with both blocking and non-blocking I/O. When the -underlying I/O is non-blocking, wolfSSH_connect() will return when the underlying I/O -could not satisfy the needs of wolfSSH_connect to continue the handshake. In this -case, a call to wolfSSH_get_error() will yield either **WS_WANT_READ** or -**WS_WANT_WRITE**. The calling process must then repeat the call to -wolfSSH_connect() when the underlying I/O is ready and wolfSSH will pick up where it -left off. When using a non-blocking socket, nothing needs to be done, but select() can -be used to check for the required condition. +- pointer to the error name string -If the underlying I/O is blocking, wolfSSH_connect() will only return once the handshake -has been finished or an error occurred. +**See Also** -**Return Values** +- `wolfSSH_get_error_name()` -**WS_BAD_ARGUMENT -WS_FATAL_ERROR -WS_SUCCESS** - This will return if the call is successful. +## I/O Callbacks -**Parameters** -**ssh** - Pointer to wolfSSH session -``` -#include -int wolfSSH_connect(WOLFSSH* ssh); -``` +### wolfSSH_SetIORecv() -### wolfSSH_shutdown() +```c +#include -**Synopsis** +void wolfSSH_SetIORecv(WOLFSSH_CTX* ctx, WS_CallbackIORecv cb); +``` **Description** -Closes and disconnects the SSH channel. +Registers a receive callback used by wolfSSH to read input data. The callback signature is shown by the `WS_CallbackIORecv` type. -**Return Values** +**Parameters** -**WS_BAD_ARGUMENT** - returned if the parameter is NULL -**WS_SUCCES** - returns when everything has been correctly shutdown +- `ctx` - pointer to the wolfSSH context +- `cb` - function to register as the receive callback for the context -**Parameters** +**Return Values** -**ssh -** Pointer to wolfSSH session +None -``` -#include -int wolfSSH_shutdown(WOLFSSH* ssh); -``` +**See Also** -### wolfSSH_stream_read() +- `wolfSSH_SetIOSend()` + +### wolfSSH_SetIOSend() +```c +#include -**Synopsis** +void wolfSSH_SetIOSend(WOLFSSH_CTX* ctx, WS_CallbackIOSend cb); +``` **Description** -wolfSSH_stream_read reads up to **bufSz** bytes from the internal decrypted data stream -buffer. The bytes are removed from the internal buffer. +Registers a send callback used by wolfSSH to write output data. The callback signature is shown by the `WS_CallbackIOSend` type. -wolfSSH_stream_read() works with both blocking and non-blocking I/O. When the -underlying I/O is non-blocking, wolfSSH_stream_read() will return when the underlying -I/O could not satisfy the needs of wolfSSH_stream_read to continue the read. In this -case, a call to wolfSSH_get_error() will yield either **WS_WANT_READ** or -**WS_WANT_WRITE**. The calling process must then repeat the call to -wolfSSH_stream_read when data is available to read and wolfSSH will pick up where it -left off. When using a non-blocking socket, nothing needs to be done, but select() can -be used to check for the required condition. +**Parameters** -If the underlying I/O is blocking, wolfSSH_stream_read() will only return when data is -available or an error occurred. +- `ctx` - pointer to the wolfSSH context +- `cb` - function to register as the send callback for the context **Return Values** -**>0** – number of bytes read upon success -**0** – returned on socket failure caused by either a clean connection shutdown or a -socket. -**WS_BAD_ARGUMENT** – returns if one or more parameters is equal to NULL -**WS_EOF** – returns when end of stream is reached -**WS_FATAL_ERROR** – there was an error, call **wolfSSH_get_error()** for more detail -**WS_REKEYING** if currently a rekey is in process, use wolfSSH_worker() to complete +None -**Parameters** +**See Also** -**ssh** – pointer to the wolfSSH session +- `wolfSSH_SetIORecv()` -``` +### wolfSSH_SetIOReadCtx() + + +```c #include -int wolfSSH_stream_read(WOLFSSH* ssh , -byte* buf , word32 bufSz ); + +void wolfSSH_SetIOReadCtx(WOLFSSH* ssh, void* ctx); ``` -**buf** – buffer where wolfSSH_stream_read() will place the data -**bufSz** – size of the buffer +**Description** + +Registers a context passed to the session's receive (I/O read) callback. -**See Also** +**Parameters** -wolfSSH_accept() -wolfSSH_stream_send() +- `ssh` - pointer to the wolfSSH session +- `ctx` - context to register with the session's receive callback +**Return Values** -### wolfSSH_stream_send() +None +**See Also** + +- `wolfSSH_GetIOReadCtx()` +### wolfSSH_SetIOWriteCtx() -**Synopsis** -**Description** +```c +#include -wolfSSH_stream_send writes **bufSz** bytes from buf to the SSH stream data buffer. -wolfSSH_stream_send() works with both blocking and non-blocking I/O. When the -underlying I/O is non-blocking, wolfSSH_stream_send() will return a want write -error when the underlying I/O could not satisfy the needs of wolfSSH_stream_send -and there is still pending data in the SSH stream data buffer to be sent. In this -case, a call to wolfSSH_get_error() will yield either **WS_WANT_READ** or -**WS_WANT_WRITE**. The calling process must then repeat the call to -wolfSSH_stream_send when the socket is ready to send and wolfSSH will send out -any pending data left in the SSH stream data buffer then pull data from the input -**buf**. When using a non-blocking socket, nothing needs to be done, but select() -can be used to check for the required condition. - -If the underlying I/O is blocking, wolfSSH_stream_send() will only return when the data -has been sent or an error occurred. - -In cases where I/O want write/read is not the error encountered (i.e. WS_REKEYING) -then wolfSSH_worker() should be called until the internal SSH processes are completed. +void wolfSSH_SetIOWriteCtx(WOLFSSH* ssh, void* ctx); +``` -**Return Values** +**Description** -**>0** – number of bytes written to SSH stream data buffer upon success -**0** – returned on socket failure caused by either a clean connection shutdown or a socket -error, call **wolfSSH_get_error()** for more detail -**WS_FATAL_ERROR** – there was an error, call wolfSSH_get_error() for more detail -**WS_BAD_ARGUMENT** if any of the parameters is null -**WS_REKEYING** if currently a rekey is in process, use wolfSSH_worker() to complete +Registers a context passed to the session's send (I/O write) callback. **Parameters** -**ssh** – pointer to the wolfSSH session -**buf** – buffer wolfSSH_stream_send() will send +- `ssh` - pointer to the wolfSSH session +- `ctx` - context to register with the session's send callback -``` -#include -int wolfSSH_stream_send(WOLFSSH* ssh , byte* buf , word32 -bufSz ); -``` +**Return Values** -**bufSz** – size of the buffer +None **See Also** -wolfSSH_accept() -wolfSSH_stream_read() +- `wolfSSH_GetIOWriteCtx()` +### wolfSSH_GetIOReadCtx() -### wolfSSH_stream_exit() +```c +#include -**Synopsis** +void* wolfSSH_GetIOReadCtx(WOLFSSH* ssh); +``` **Description** -This function is used to exit the SSH stream. +Returns the context previously registered for the session's receive (I/O read) callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session **Return Values** -**WS_BAD_ARGUMENT** - returned if a parameter value is NULL -**WS_SUCCESS** - returns if function was a success +- the registered read context pointer, or `NULL` if none -**Parameters** +**See Also** -**ssh** – Pointer to wolfSSH session -**status** – the status of the SSH connection +- `wolfSSH_SetIOReadCtx()` -``` -#include -int wolfSSH_stream_exit(WOLFSSH* ssh, int status); -``` +### wolfSSH_GetIOWriteCtx() -### wolfSSH_TriggerKeyExchange() +```c +#include -**Synopsis** +void* wolfSSH_GetIOWriteCtx(WOLFSSH* ssh); +``` **Description** -Triggers key exchange process. Prepares and sends packet of allocated handshake -info. +Returns the context previously registered for the session's send (I/O write) callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session **Return Values** -**WS_BAD_ARGUEMENT** – if **ssh** is NULL -**WS_SUCCESS** +- the registered write context pointer, or `NULL` if none -**Parameters** +**See Also** -**ssh** – pointer to the wolfSSH session +- `wolfSSH_SetIOWriteCtx()` -``` -#include -int wolfSSH_TriggerKeyExchange(WOLFSSH* ssh ); -``` +## User Authentication -## Channel Callbacks -Interfaces to the wolfSSH library return single int values. Communicating -status of asynchronous information, like the peer opening a channel, isn't -easy with that interface. wolfSSH uses callback functions to notify the -calling application of changes in state of a channel. -There are callback functions for receipt of the following SSHv2 protocol -messages: - -* SSH_MSG_CHANNEL_OPEN -* SSH_MSG_CHANNEL_OPEN_CONFIRMATION -* SSH_MSG_CHANNEL_OPEN_FAILURE -* SSH_MSG_CHANNEL_REQUEST - - "shell" - - "subsystem" - - "exec" -* SSH_MSG_CHANNEL_EOF -* SSH_MSG_CHANNEL_CLOSE +### wolfSSH_SetUserAuth() -### Callback Function Prototypes -The channel callback functions all take a pointer to a **WOLFSSH_CHANNEL** -object, _channel_, and a pointer to the application defined data structure, -_ctx_. Properties about the channel may be queried using API functions. +```c +#include +void wolfSSH_SetUserAuth(WOLFSSH_CTX* ctx, WS_CallbackUserAuth cb); ``` -typedef int (*WS_CallbackChannelOpen)(WOLFSSH_CHANNEL* channel, void* ctx); -typedef int (*WS_CallbackChannelReq)(WOLFSSH_CHANNEL* channel, void* ctx); -typedef int (*WS_CallbackChannelEof)(WOLFSSH_CHANNEL* channel, void* ctx); -typedef int (*WS_CallbackChannelClose)(WOLFSSH_CHANNEL* channel, void* ctx); -``` -### wolfSSH_CTX_SetChannelOpenCb +**Description** + +Registers the user authentication callback on the wolfSSH context. The callback is invoked on the server during the handshake to decide whether to authenticate the client. -**Synopsis** +The callback returns `WOLFSSH_USERAUTH_SUCCESS` only on a positive authentication decision. `WOLFSSH_USERAUTH_PARTIAL_SUCCESS` reports that one factor of a multi-method authentication passed, `WOLFSSH_USERAUTH_SUCCESS_ANOTHER` reports that a keyboard-interactive round passed and asks for the next round, `WOLFSSH_USERAUTH_WOULD_BLOCK` asks for the request to be retried, and `WOLFSSH_USERAUTH_REJECTED` is a hard rejection: the server answers with USERAUTH_FAILURE and then ends the session. Any other value is treated as an ordinary failure. -``` -#include -int wolfSSH_CTX_SetChannelOpenCb(WOLFSSH_CTX* ctx, - WS_CallbackChannelOpen cb); -``` +Note: `WOLFSSH_USERAUTH_SUCCESS` has the value 0, the same as `WS_SUCCESS`. A bare `return 0;`, a forwarded `WS_SUCCESS` from a helper, or a fall-through default of 0 silently authenticates the client. Return `WOLFSSH_USERAUTH_FAILURE` for any auth type or code path the callback does not explicitly handle. For `WOLFSSH_USERAUTH_PUBLICKEY`, the callback must check the offered public key against the user's authorized keys: the library verifies the signature, not the key's authorization. -**Description** +Every request that does not fully authenticate counts against the session's limit on failed attempts (see wolfSSH_CTX_SetMaxAuthAttempts()). + +**Parameters** -Sets the callback function, _cb_, into the wolfSSH _ctx_ used when a Channel -Open (**SSH_MSG_CHANNEL_OPEN**) message is received from the peer. +- `ctx` - pointer to the wolfSSH context +- `cb` - the user authentication callback function **Return Values** -* **WS_SUCCESS** - Setting callback in _ctx_ was successful -* **WS_SSH_CTX_NULL_E** - _ctx_ is **NULL** +None + +**See Also** +- `wolfSSH_SetUserAuthCtx()` +- `wolfSSH_CTX_SetMaxAuthAttempts()` -### wolfSSH_CTX_SetChannelOpenRespCb +### wolfSSH_SetUserAuthCtx() -**Synopsis** -``` +```c #include -int wolfSSH_CTX_SetChannelOpenRespCb(WOLFSSH_CTX* ctx, - WS_CallbackChannelOpen confCb, - WS_CallbackChannelOpen failCb); + +void wolfSSH_SetUserAuthCtx(WOLFSSH* ssh, void* userAuthCtx); ``` **Description** -Sets the callback functions, _confCb_ and _failCb_, into the wolfSSH _ctx_ -used when a Channel Open Confirmation (**SSH_MSG_CHANNEL_OPEN_CONFIRMATION**) -or a Channel Open Failure (**SSH_MSG_CHANNEL_OPEN_FAILURE**) message is -received from the peer. +Sets the user context pointer passed to the user authentication callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `userAuthCtx` - user context pointer to pass to the authentication callback **Return Values** -* **WS_SUCCESS** - Setting callbacks in _ctx_ was successful -* **WS_SSH_CTX_NULL_E** - _ctx_ is **NULL** +None + +**See Also** +- `wolfSSH_GetUserAuthCtx()` -### wolfSSH_CTX_SetChannelReqShellCb +### wolfSSH_GetUserAuthCtx() -**Synopsis** -``` +```c #include -int wolfSSH_CTX_SetChannelReqShellCb(WOLFSSH_CTX* ctx, - WS_CallbackChannelReq cb); + +void* wolfSSH_GetUserAuthCtx(WOLFSSH* ssh); ``` **Description** -Sets the callback function, _cb_, into the wolfSSH _ctx_ used when a Channel -Request (**SSH_MSG_CHANNEL_REQUEST**) message is received from the peer for -a _shell_. +Returns the user context pointer previously set with wolfSSH_SetUserAuthCtx(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session **Return Values** -* **WS_SUCCESS** - Setting callback in _ctx_ was successful -* **WS_SSH_CTX_NULL_E** - _ctx_ is **NULL** +- the user authentication context pointer +- `NULL` - if `ssh` is NULL +**See Also** -### wolfSSH_CTX_SetChannelReqSubsysCb +- `wolfSSH_SetUserAuthCtx()` -**Synopsis** +### wolfSSH_SetUserAuthTypes() -``` +```c #include -int wolfSSH_CTX_SetChannelReqSubsysCb(WOLFSSH_CTX* ctx, - WS_CallbackChannelReq cb); + +void wolfSSH_SetUserAuthTypes(WOLFSSH_CTX* ctx, WS_CallbackUserAuthTypes cb); ``` **Description** -Sets the callback function, _cb_, into the wolfSSH _ctx_ used when a Channel -Request (**SSH_MSG_CHANNEL_REQUEST**) message is received from the peer for -a _subsystem_. A common example of a subsystem is SFTP. +Registers a callback that reports which user authentication types the server offers. The callback returns a bitmask of the `WOLFSSH_USERAUTH_*` values (for example, `WOLFSSH_USERAUTH_PASSWORD` or `WOLFSSH_USERAUTH_PUBLICKEY`). + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the user authentication types callback **Return Values** -* **WS_SUCCESS** - Setting callback in _ctx_ was successful -* **WS_SSH_CTX_NULL_E** - _ctx_ is **NULL** +None +**See Also** -### wolfSSH_CTX_SetChannelReqExecCb +- `wolfSSH_SetUserAuth()` -**Synopsis** +### wolfSSH_SetUserAuthResult() -``` +```c #include -int wolfSSH_CTX_SetChannelReqExecCb(WOLFSSH_CTX* ctx, - WS_CallbackChannelReq cb); + +void wolfSSH_SetUserAuthResult(WOLFSSH_CTX* ctx, WS_CallbackUserAuthResult cb); ``` **Description** -Sets the callback function, _cb_, into the wolfSSH _ctx_ used when a Channel -Request (**SSH_MSG_CHANNEL_REQUEST**) message is received from the peer for -a command to _exec_. +Registers a callback that is invoked with the result of a user authentication attempt. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the user authentication result callback **Return Values** -* **WS_SUCCESS** - Setting callback in _ctx_ was successful -* **WS_SSH_CTX_NULL_E** - _ctx_ is **NULL** +None +**See Also** -### wolfSSH_CTX_SetChannelEofCb +- `wolfSSH_SetUserAuthResultCtx()` -**Synopsis** +### wolfSSH_SetUserAuthResultCtx() -``` +```c #include -int wolfSSH_CTX_SetChannelEof(WOLFSSH_CTX* ctx, - WS_CallbackChannelEof cb); + +void wolfSSH_SetUserAuthResultCtx(WOLFSSH* ssh, void* userAuthResultCtx); ``` **Description** -Sets the callback function, _cb_, into the wolfSSH _ctx_ used when a Channel -EOF (**SSH_MSG_CHANNEL_EOF**) message is received from the peer. This -message indicates that the peer isn't going to transmit any more data on this -channel. +Sets the user context pointer passed to the user authentication result callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `userAuthResultCtx` - user context pointer to pass to the result callback **Return Values** -* **WS_SUCCESS** - Setting callback in _ctx_ was successful -* **WS_SSH_CTX_NULL_E** - _ctx_ is **NULL** +None +**See Also** -### wolfSSH_CTX_SetChannelCloseCb +- `wolfSSH_GetUserAuthResultCtx()` -**Synopsis** +### wolfSSH_GetUserAuthResultCtx() -``` +```c #include -int wolfSSH_CTX_SetChannelClose(WOLFSSH_CTX* ctx, - WS_CallbackChannelClose cb); + +void* wolfSSH_GetUserAuthResultCtx(WOLFSSH* ssh); ``` **Description** -Sets the callback function, _cb_, into the wolfSSH _ctx_ used when a Channel -Close (**SSH_MSG_CHANNEL_CLOSE**) message is received from the peer. This -message indicates that the peer is interested in terminating this channel. +Returns the user context pointer previously set with wolfSSH_SetUserAuthResultCtx(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session **Return Values** -* **WS_SUCCESS** - Setting callback in _ctx_ was successful -* **WS_SSH_CTX_NULL_E** - _ctx_ is **NULL** +- the user authentication result context pointer +- `NULL` - if `ssh` is NULL +**See Also** -### wolfSSH_SetChannelOpenCtx +- `wolfSSH_SetUserAuthResultCtx()` -**Synopsis** +### wolfSSH_CTX_SetPublicKeyCheck() -``` +```c #include -int wolfSSH_SetChannelOpenCtx(WOLFSSH* ssh, void* ctx); + +void wolfSSH_CTX_SetPublicKeyCheck(WOLFSSH_CTX* ctx, + WS_CallbackPublicKeyCheck cb); ``` **Description** -Sets the context, _ctx_, into the wolfSSH _ssh_ object used when the callback -for the Channel Open (**SSH_MSG_CHANNEL_OPEN**) message, Channel Open -Confirmation (**SSH_MSG_CHANNEL_CONFIRMATION**) message, or Channel Open -Failure (**SSH_MSG_CHANNEL_FAILURE**) is received from the peer. +Registers a callback, used on the client side, to check the server's public (host) key before continuing the handshake. This is the client's only defense against a man-in-the-middle. The callback returns 0 to accept the key, or non-zero to reject it and fail the key exchange. + +Note: because 0 accepts, a stub that defaults to `return 0;` accepts any server host key and defeats man-in-the-middle protection. The callback must match the key against a trust store, such as a known-hosts list. If no callback is registered, the host key is rejected (`WS_PUBKEY_REJECTED_E`). + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the public key check callback **Return Values** -* **WS_SUCCESS** - Setting context in _ssh_ was successful -* **WS_SSH_NULL_E** - _ssh_ is **NULL** +None +**See Also** -### wolfSSH_SetChannelReqCtx +- `wolfSSH_SetPublicKeyCheckCtx()` -**Synopsis** +### wolfSSH_SetPublicKeyCheckCtx() -``` +```c #include -int wolfSSH_SetChannelReqCtx(WOLFSSH* ssh, void* ctx); + +void wolfSSH_SetPublicKeyCheckCtx(WOLFSSH* ssh, void* publicKeyCheckCtx); ``` **Description** -Sets the context, _ctx_, into the wolfSSH _ssh_ object used when the callback -for the Channel Request (**SSH_MSG_CHANNEL_REQUEST**) message is received from -the peer. +Sets the user context pointer passed to the public key check callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `publicKeyCheckCtx` - user context pointer to pass to the callback **Return Values** -* **WS_SUCCESS** - Setting context in _ssh_ was successful -* **WS_SSH_NULL_E** - _ssh_ is **NULL** +None +**See Also** -### wolfSSH_SetChannelEofCtx +- `wolfSSH_GetPublicKeyCheckCtx()` -**Synopsis** +### wolfSSH_GetPublicKeyCheckCtx() -``` +```c #include -int wolfSSH_SetChannelEofCtx(WOLFSSH* ssh, void* ctx); + +void* wolfSSH_GetPublicKeyCheckCtx(WOLFSSH* ssh); ``` **Description** -Sets the context, _ctx_, into the wolfSSH _ssh_ object used when the callback -for the Channel EOF (**SSH_MSG_CHANNEL_EOF**) message is received from -the peer. +Returns the user context pointer previously set with wolfSSH_SetPublicKeyCheckCtx(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session **Return Values** -* **WS_SUCCESS** - Setting context in _ssh_ was successful -* **WS_SSH_NULL_E** - _ssh_ is **NULL** +- the public key check context pointer +- `NULL` - if `ssh` is NULL +**See Also** -### wolfSSH_SetChannelCloseCtx +- `wolfSSH_SetPublicKeyCheckCtx()` -**Synopsis** +### wolfSSH_CTX_SetMaxAuthAttempts() -``` +```c #include -int wolfSSH_SetChannelCloseCtx(WOLFSSH* ssh, void* ctx); + +int wolfSSH_CTX_SetMaxAuthAttempts(WOLFSSH_CTX* ctx, int value); ``` **Description** -Sets the context, _ctx_, into the wolfSSH _ssh_ object used when the callback -for the Channel Close (**SSH_MSG_CHANNEL_CLOSE**) message is received from -the peer. +Sets the server-side limit on failed user authentication attempts per connection for sessions created from this context. The default is `DEFAULT_MAX_AUTH_ATTEMPTS` (6), the same value as the OpenSSH `MaxAuthTries` default. When the limit is reached the server sends an SSH_MSG_DISCONNECT and drops the connection. A `value` less than or equal to 0 restores the built-in default; there is no "unlimited" setting. Every request that does not fully authenticate is charged, including a partial success; only the opening "none" request that clients use to learn the method list is exempt. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `value` - the maximum number of failed attempts, or 0 or less for the default **Return Values** -* **WS_SUCCESS** - Setting context in _ssh_ was successful -* **WS_SSH_NULL_E** - _ssh_ is **NULL** +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` is NULL +**See Also** -### wolfSSH_GetChannelOpenCtx +- `wolfSSH_CTX_GetMaxAuthAttempts()` +- `wolfSSH_SetMaxAuthAttempts()` -**Synopsis** +### wolfSSH_CTX_GetMaxAuthAttempts() -``` +```c #include -void* wolfSSH_GetChannelOpenCtx(WOLFSSH* ssh); + +int wolfSSH_CTX_GetMaxAuthAttempts(WOLFSSH_CTX* ctx); ``` **Description** -Gets the context from the wolfSSH _ssh_ object used when the callback for the -Channel Open (**SSH_MSG_CHANNEL_OPEN**) message. +Returns the context's limit on failed user authentication attempts. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context **Return Values** -* pointer to the context data +- the current limit +- `WS_BAD_ARGUMENT` - `ctx` is NULL +**See Also** -### wolfSSH_GetChannelReqCtx +- `wolfSSH_CTX_SetMaxAuthAttempts()` -**Synopsis** +### wolfSSH_SetMaxAuthAttempts() -``` +```c #include -void* wolfSSH_GetChannelReqCtx(WOLFSSH* ssh); + +int wolfSSH_SetMaxAuthAttempts(WOLFSSH* ssh, int value); ``` **Description** -Gets the context from the wolfSSH _ssh_ object used when the callback for the -Channel Request (**SSH_MSG_CHANNEL_REQUEST**) message. +Overrides, for one session, the limit on failed user authentication attempts that the session inherited from its context. The semantics of `value` are those of wolfSSH_CTX_SetMaxAuthAttempts(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `value` - the maximum number of failed attempts, or 0 or less for the default **Return Values** -* pointer to the context data +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` is NULL +**See Also** -### wolfSSH_GetChannelEofCtx +- `wolfSSH_GetMaxAuthAttempts()` +- `wolfSSH_CTX_SetMaxAuthAttempts()` -**Synopsis** +### wolfSSH_GetMaxAuthAttempts() -``` +```c #include -void* wolfSSH_GetChannelEofCtx(WOLFSSH* ssh); + +int wolfSSH_GetMaxAuthAttempts(WOLFSSH* ssh); ``` **Description** -Gets the context from the wolfSSH _ssh_ object used when the callback for the -Channel EOF (**SSH_MSG_CHANNEL_EOF**) message. +Returns the session's limit on failed user authentication attempts. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session **Return Values** -* pointer to the context data +- the current limit +- `WS_BAD_ARGUMENT` - `ssh` is NULL + +**See Also** + +- `wolfSSH_SetMaxAuthAttempts()` +## Set Username -### wolfSSH_GetChannelCloseCtx -**Synopsis** -``` +### wolfSSH_SetUsername() + + +```c #include -void* wolfSSH_GetChannelCloseCtx(WOLFSSH* ssh); + +int wolfSSH_SetUsername(WOLFSSH* ssh, const char* username); ``` **Description** -Gets the context from the wolfSSH _ssh_ object used when the callback for the -Channel Close (**SSH_MSG_CHANNEL_CLOSE**) message. +Sets the username used for the SSH connection, provided as a null-terminated string. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `username` - the username for the SSH connection **Return Values** -* pointer to the context data +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` +**See Also** -### wolfSSH_ChannelGetSessionType +- `wolfSSH_GetUsername()` -**Synopsis** +### wolfSSH_SetUsernameRaw() -``` +```c #include -WS_SessionType wolfSSH_ChannelGetSessionType(const WOLFSSH_CHANNEL* channel); + +int wolfSSH_SetUsernameRaw(WOLFSSH* ssh, const byte* username, + word32 usernameSz); ``` **Description** -Returns the **WS_SessionType** for the specified _channel_. +Sets the username used for the SSH connection from a buffer and length, rather than a null-terminated string. Useful when the username is not null-terminated or may contain arbitrary bytes. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `username` - buffer containing the username +- `usernameSz` - length of the username buffer **Return Values** -* **WS_SessionType** - type for the session +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` +**See Also** -### wolfSSH_ChannelGetSessionCommand +- `wolfSSH_SetUsername()` -**Synopsis** +### wolfSSH_GetUsername() -``` +```c #include -const char* wolfSSH_ChannelGetSessionCommand(const WOLFSSH_CHANNEL* channel); + +char* wolfSSH_GetUsername(WOLFSSH* ssh); ``` **Description** -Returns a pointer to the command the user wishes to execute over the specified -_channel_. - -**Return Values** +Returns the username associated with the session. -* **const char*** - pointer to the string holding the command sent by the user +**Parameters** +- `ssh` - pointer to the wolfSSH session -## Testing Functions +**Return Values** +- pointer to the session's username string +- `NULL` - if `ssh` is NULL or no username is set -### wolfSSH_GetStats() +**See Also** +- `wolfSSH_SetUsername()` -**Synopsis** +## Connection Functions -**Description** +### wolfSSH_accept() -Updates **txCount** , **rxCount** , **seq** , and **peerSeq** with their respective **ssh** session -statistics. -**Return Values** -none +```c +#include -**Parameters** +int wolfSSH_accept(WOLFSSH* ssh); +``` -**ssh** – pointer to the wolfSSH session -**txCount** – address where total transferred bytes in **ssh** session are stored. -**rxCount** – address where total received bytes in **ssh** session are stored. -**seq** – packet sequence number is initially 0 and is incremented after every packet -**peerSeq** – peer packet sequence number is initially 0 and is incremented after every -packet +**Description** -``` -#include -void wolfSSH_GetStats(WOLFSSH* ssh , word32* txCount , word32* -rxCount , -word32* seq , word32* peerSeq ) -``` +Called on the server side; waits for an SSH client to initiate the SSH handshake and completes it. -### wolfSSH_KDF() +wolfSSH_accept() works with both blocking and non-blocking I/O. When the underlying I/O is non-blocking, wolfSSH_accept() returns when the I/O cannot yet satisfy the handshake; a call to wolfSSH_get_error() then yields either `WS_WANT_READ` or `WS_WANT_WRITE`. The caller repeats the call when data is available and wolfSSH resumes where it left off. +If the underlying I/O is blocking, wolfSSH_accept() returns only once the handshake has finished or an error occurred. -**Synopsis** +By default wolfSSH_accept() runs through to an established session with the first channel open. When application-driven channels are enabled with wolfSSH_CTX_SetAppChannels() or wolfSSH_SetAppChannels(), it instead returns `WS_SUCCESS` as soon as the user has authenticated, and the application drives the session from there with wolfSSH_worker() and the channel callbacks. In the default mode, a granted SCP command makes wolfSSH_accept() return `WS_SCP_INIT`, and a granted "sftp" subsystem request hands off to wolfSSH_SFTP_accept(). -**Description** +Once the session has disconnected (a disconnect sent or received), this call returns `WS_FATAL_ERROR` and wolfSSH_get_error() reports `WS_DISCONNECT`. -This is used so that the API test can do known answer tests for the key derivation. +**Parameters** -The Key Derivation Function derives a symmetric **key** based on source keying material, -**k** and **h**. Where **k** is the Diffie-Hellman shared secret and **h** is the hash of the -handshake that was produced during initial key exchange. Multiple types of keys could -be derived which are specified by the **keyId** and **hashId**. +- `ssh` - pointer to the wolfSSH session -``` -Initial IV client to server: keyId = A -Initial IV server to client: keyId = B -Encryption key client to server: keyId = C -Encryption key server to client: keyId = D -Integrity key client to server: keyId = E -Integrity key server to client : keyId = F -``` **Return Values** -WS_SUCCESS -WS_CRYPTO_FAILED +- `WS_SUCCESS` +- `WS_SCP_INIT` - an SCP transfer was requested (`WOLFSSH_SCP` builds) +- `WS_BAD_ARGUMENT` +- `WS_FATAL_ERROR` -**Parameters** +**See Also** -**hashId** – type of hash to generate keying material. -e.g. ( WC_HASH_TYPE_SHA and WC_HASH_TYPE_SHA256 ) -**keyId** – letter A - F to indicate which key to make -**key** – generated key used for comparisons to expected key +- `wolfSSH_connect()` +- `wolfSSH_stream_read()` +- `wolfSSH_CTX_SetAppChannels()` -``` -#include -int wolfSSH_KDF(byte hashId , byte keyId , byte* key , word32 -keySz , -const byte* k , word32 kSz , const byte* h , word32 -hSz , -const byte* sessionId , word32 sessionIdSz ); -``` +### wolfSSH_connect() -**keySz** – needed size of **key -k** – shared secret from the Diffie-Hellman key exchange -**kSz** – size of the shared secret ( **k** ) -**h** – hash of the handshake that was produced during key exchange -**hSz** – size of the hash ( **h** ) -**sessionId** – unique identifier from first **h** calculated. -**sessionIdSz** – size of the **sessionId** +```c +#include -## Session Functions +int wolfSSH_connect(WOLFSSH* ssh); +``` +**Description** +Called on the client side; initiates an SSH handshake with a server. The underlying communication channel must already be set up before this call. -### wolfSSH_GetSessionType() +wolfSSH_connect() works with both blocking and non-blocking I/O. When the underlying I/O is non-blocking, wolfSSH_connect() returns when the I/O cannot yet satisfy the handshake; a call to wolfSSH_get_error() then yields either `WS_WANT_READ` or `WS_WANT_WRITE`. The caller repeats the call when the I/O is ready and wolfSSH resumes where it left off. +If the underlying I/O is blocking, wolfSSH_connect() returns only once the handshake has finished or an error occurred. -**Synopsis** +Once the session has disconnected (a disconnect sent or received), this call returns `WS_FATAL_ERROR` and wolfSSH_get_error() reports `WS_DISCONNECT`. -**Description** +**Parameters** -The wolfSSH_GetSessionType() is used to return the type of session +- `ssh` - pointer to the wolfSSH session **Return Values** -WOLFSSH_SESSION_UNKNOWN -WOLFSSH_SESSION_SHELL -WOLFSSH_SESSION_EXEC -WOLFSSH_SESSION_SUBSYSTEM +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_FATAL_ERROR` -**Parameters** +**See Also** -**ssh -** pointer to wolfSSH session +- `wolfSSH_accept()` -``` -#include -WS_SessionType wolfSSH_GetSessionType(const WOLFSSH* ssh ); -``` +### wolfSSH_shutdown() -### wolfSSH_GetSessionCommand() +```c +#include -**Synopsis** +int wolfSSH_shutdown(WOLFSSH* ssh); +``` **Description** -This function is used to return the current command in the session. - -**Return Values** +Tears down the first channel in the session's channel list, sending SSH_MSG_CHANNEL_EOF, the exit status, and SSH_MSG_CHANNEL_CLOSE, and then reads the peer's close reply. It does not send SSH_MSG_DISCONNECT; use wolfSSH_SendDisconnect() for that. -**const char*** - Pointer to command +wolfSSH_shutdown() also flushes anything a short non-blocking send left queued, with or without a channel to tear down, such as a rejected authentication's USERAUTH_FAILURE or a disconnect of this side's own. That flush can be short too, so `WS_WANT_WRITE` may be owed to it rather than to the teardown messages; either way, call wolfSSH_shutdown() again until it reports something else. Once the peer has disconnected, nothing new is sent: only a disconnect of this side's own that is still queued goes out, and wolfSSH_get_error() reports `WS_DISCONNECT`. **Parameters** -**ssh -** pointer to wolfSSH session +- `ssh` - pointer to the wolfSSH session -``` -#include -const char* wolfSSH_GetSessionCommand(const WOLFSSH* ssh ); -``` +**Return Values** -## Port Forwarding Functions +- `WS_SUCCESS` +- `WS_CHANNEL_CLOSED` - the channel list is now empty +- `WS_WANT_WRITE` - output is still queued; call again +- `WS_WANT_READ` +- `WS_BAD_ARGUMENT` - `ssh` is NULL, or there is no channel to tear down +- other negative error codes from the send or receive path +**See Also** +- `wolfSSH_SendDisconnect()` +- `wolfSSH_ChannelExit()` +- `wolfSSH_OutputPending()` -### wolfSSH_ChannelFwdNew() +### wolfSSH_stream_read() -**Synopsis** -**Description** +```c +#include -Sets up a TCP/IP forwarding channel on a WOLFSSH session. When the SSH session -is connected and authenticated, a local listener is created on the interface for address -_host_ on port _hostPort_. Any new connections on that listener will trigger a new channel -request to the SSH server to establish a connection to _host_ on port _hostPort_. +int wolfSSH_stream_read(WOLFSSH* ssh, byte* buf, word32 bufSz); +``` -**Return Values** +**Description** -**WOLFSSH_CHAN*** – NULL on error or new channel record +Reads up to `bufSz` bytes of decrypted data from the first channel in the session's channel list. The bytes read are removed from the internal buffer, and the channel window is credited for them. -**Parameters** +wolfSSH_stream_read() works with both blocking and non-blocking I/O. When the underlying I/O is non-blocking and cannot satisfy the read, the call returns a negative value and wolfSSH_get_error() yields `WS_WANT_READ` or `WS_WANT_WRITE`; the caller repeats the call when data is available. If the underlying I/O is blocking, the call returns only when data is available or an error occurred. If a rekey is in progress, the call fails and wolfSSH_get_error() yields `WS_REKEYING`; call wolfSSH_worker() to complete it. -**ssh** – wolfSSH session -**host** – host address to bind listener -**hostPort** – host port to bind listener -**origin** – IP address of the originating connection -**originPort** – port number of the originating connection +A successful read sends the peer a window adjust. On a non-blocking socket that send can be short: the byte count is still returned, but wolfSSH_get_error() is left at `WS_WANT_WRITE` to show the adjust is queued; it goes out on the next send or the next wolfSSH_worker() call. -``` -#include -WOLFSSH_CHANNEL* wolfSSH_ChannelFwdNew(WOLFSSH* ssh , -const char* host , word32 hostPort , -const char* origin , word32 originPort ); -``` +This call serves only the first channel. Data, normal or extended, arriving for any other channel makes it fail with `WS_ERROR`; read those channels with wolfSSH_ChannelIdRead() and wolfSSH_ChannelIdReadExt(). When extended (stderr) data arrives on the first channel the call returns `WS_EXTDATA`; drain it with wolfSSH_extended_data_read() until that returns 0. An EOF from the peer is reported only once the buffered data has been read. After a disconnect, data that arrived before it can still be read; once the buffer is empty the call fails with `WS_DISCONNECT` in wolfSSH_get_error(). -### wolfSSH_ChannelFree() +**Parameters** +- `ssh` - pointer to the wolfSSH session +- `buf` - buffer where the data is placed +- `bufSz` - size of the buffer -**Synopsis** +**Return Values** -**Description** +- greater than 0 - number of bytes read on success +- `WS_BAD_ARGUMENT` +- `WS_EXTDATA` - extended data is waiting on the first channel +- `WS_EOF` - the peer sent EOF on the channel +- `WS_ERROR` - data arrived for another channel, or the peer sent EOF (wolfSSH_get_error() reports `WS_EOF`) +- `WS_BUFFER_E` +- `WS_FATAL_ERROR` - check wolfSSH_get_error(), which reports `WS_REKEYING`, `WS_DISCONNECT`, `WS_WANT_READ`, `WS_WANT_WRITE`, or another error -Releases the memory allocated for the channel _channel_. The channel is removed from -its session’s channel list. +**See Also** -**Return Values** +- `wolfSSH_stream_send()` +- `wolfSSH_extended_data_read()` +- `wolfSSH_ChannelIdRead()` +- `wolfSSH_accept()` -**int** – error code +### wolfSSH_stream_send() -**Parameters** -**channel** – wolfSSH channel to free -``` +```c #include -int wolfSSH_ChannelFree(WOLFSSH_CHANNEL* channel ); -``` -### wolfSSH_worker() +int wolfSSH_stream_send(WOLFSSH* ssh, byte* buf, word32 bufSz); +``` +**Description** -**Synopsis** +Writes `bufSz` bytes from `buf` to the SSH stream data buffer. -**Description** +wolfSSH_stream_send() works with both blocking and non-blocking I/O. When the underlying I/O is non-blocking and cannot send all pending data, a call to wolfSSH_get_error() yields `WS_WANT_READ` or `WS_WANT_WRITE`, and the caller repeats the call when the socket is ready to send. If the underlying I/O is blocking, the call returns only once the data has been sent or an error occurred. If the error is not want-read/want-write (for example `WS_REKEYING`), call wolfSSH_worker() until the internal SSH processing completes. -The wolfSSH worker function babysits the connection and as data is received -processes it. SSH sessions have many bookkeeping messages for the session and this -takes care of them automatically. When data for a particular channel is received, the -worker places the data into the channel. (The function wolfSSH_stream_read() does -much the same but also returns the receive data for a single channel.) -wolfSSH_worker() will perform the following actions: +**Parameters** -1. Attempt to send any pending data in the _outputBuffer_. -2. Call _DoReceive()_ on the session’s socket. -3. If data is received for a particular channel, return data received notice and set the - channel ID. +- `ssh` - pointer to the wolfSSH session +- `buf` - buffer to send +- `bufSz` - size of the buffer **Return Values** -**int** – error or status -**WS_CHANNEL_RXD** – data has been received on a channel and the ID is set +- greater than 0 - number of bytes written on success +- `WS_BAD_ARGUMENT` +- `WS_EOF` - this side already sent EOF on the channel +- `WS_WINDOW_FULL` - the peer's channel window is full +- `WS_FATAL_ERROR` - check wolfSSH_get_error(), which reports `WS_REKEYING` during a key exchange or `WS_DISCONNECT` once the session has disconnected -**Parameters** +**See Also** -**ssh** – pointer to the wolfSSH session -**id** – pointer to the location to save the ID value +- `wolfSSH_stream_read()` +- `wolfSSH_stream_send_eof()` +- `wolfSSH_accept()` -``` -#include -int wolfSSH_worker(WOLFSSH* ssh , word32* channelId ); -``` -### wolfSSH_ChannelGetId() +### wolfSSH_stream_send_eof() +```c +#include -**Synopsis** +int wolfSSH_stream_send_eof(WOLFSSH* ssh); +``` **Description** -Given a channel, returns the ID or peer’s ID for the channel. - -**Return Values** - -**int** – error code +Half-closes the first channel in the session's channel list by sending SSH_MSG_CHANNEL_EOF, as wolfSSH_ChannelSendEof() does for a named channel. Data sends on the channel then fail with `WS_EOF`; reads keep working until the peer sends its own EOF or closes the channel. A second call puts no second EOF on the wire. Unlike wolfSSH_stream_send(), which returns `WS_FATAL_ERROR` with the cause latched, this call reports `WS_REKEYING` itself during a key exchange. **Parameters** -**channel** – pointer to channel -**id** – pointer to location to save the ID value -**peer** – either self (my channel ID) or peer (my peer’s channel ID) +- `ssh` - pointer to the wolfSSH session +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` is NULL, or there is no channel +- `WS_CHANNEL_NOT_CONF` - the peer has not confirmed the channel open yet +- `WS_REKEYING` - a key exchange is in progress; try again after it completes +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) +- a send-path status such as `WS_WANT_WRITE` + +**See Also** + +- `wolfSSH_ChannelSendEof()` +- `wolfSSH_stream_send()` +- `wolfSSH_ChannelGetEof()` + +### wolfSSH_stream_exit() + + +```c +#include + +int wolfSSH_stream_exit(WOLFSSH* ssh, int status); +``` + +**Description** + +Exits the SSH stream, sending the given exit status to the peer and closing the channel. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `status` - the exit status to report to the peer + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` is NULL, or there is no channel +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +**See Also** + +- `wolfSSH_stream_send()` + +### wolfSSH_TriggerKeyExchange() + + +```c +#include + +int wolfSSH_TriggerKeyExchange(WOLFSSH* ssh); +``` + +**Description** + +Triggers the key exchange (rekey) process by preparing and sending an SSH_MSG_KEXINIT. A successful start leaves the session's error state alone; only a failure records its code there for wolfSSH_get_error(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) +- other negative error codes, including `WS_WANT_WRITE`, from sending the KEXINIT + +**See Also** + +- `wolfSSH_worker()` +- `wolfSSH_RekeyPending()` + +### wolfSSH_stream_peek() + +```c +#include + +int wolfSSH_stream_peek(WOLFSSH* ssh, byte* buf, word32 bufSz); +``` + +**Description** + +Copies up to `bufSz` bytes of pending decrypted data from the first channel into `buf` without removing them from the internal buffer. A subsequent wolfSSH_stream_read() will return the same data. If `buf` is NULL, only the count of available bytes (capped at `bufSz`) is returned. An EOF from the peer is reported only once the buffered data has been read. After a disconnect, buffered data can still be peeked; once the buffer is empty the call fails with `WS_DISCONNECT` in wolfSSH_get_error(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `buf` - buffer where the peeked data is placed, or NULL +- `bufSz` - size of the buffer + +**Return Values** + +- greater than or equal to 0 - number of bytes copied (or available, if `buf` is NULL) +- `WS_BAD_ARGUMENT` - `ssh` is NULL, or there is no channel +- `WS_REKEYING` - a key exchange is in progress +- `WS_ERROR` - the buffer is empty and the peer sent EOF (wolfSSH_get_error() reports `WS_EOF`) +- `WS_FATAL_ERROR` - the buffer is empty and the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +**See Also** + +- `wolfSSH_stream_read()` +- `wolfSSH_ChannelIdPeek()` + +### wolfSSH_extended_data_send() + +```c +#include + +int wolfSSH_extended_data_send(WOLFSSH* ssh, byte* buf, word32 bufSz); +``` + +**Description** + +Sends `bufSz` bytes as extended channel data (the stderr data type) on the first channel in the session's channel list. To send on another channel, use wolfSSH_ChannelIdSendExt(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `buf` - buffer to send +- `bufSz` - size of the buffer + +**Return Values** + +- greater than 0 - number of bytes sent on success +- `WS_BAD_ARGUMENT` +- `WS_EOF` - this side already sent EOF on the channel +- `WS_REKEYING` - a key exchange is in progress +- `WS_WINDOW_FULL` - the peer's channel window is full +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +**See Also** + +- `wolfSSH_extended_data_read()` + +### wolfSSH_extended_data_read() + +```c +#include + +int wolfSSH_extended_data_read(WOLFSSH* ssh, byte* out, word32 outSz); +``` + +**Description** + +Reads up to `outSz` bytes of buffered extended data (stderr) from the first channel in the session's channel list into `out`. This is the stderr counterpart of wolfSSH_stream_read(), and reads the same channel. + +Applications must drain stderr: it shares the channel receive window with normal data (RFC 4254 section 5.2), and the window is only replenished as the data is read, so unread stderr eventually stalls the channel. Call this after wolfSSH_stream_read() returns `WS_EXTDATA`, until it returns 0. For other channels, use wolfSSH_ChannelIdReadExt(); wolfSSH_worker() names the channel the extended data arrived on when it returns `WS_EXTDATA`. + +Draining sends the peer a window adjust. On a non-blocking socket that send can be short: the byte count is still returned, but wolfSSH_get_error() is left at `WS_WANT_WRITE` to show a flush is owed. An application that only reads must then flush with wolfSSH_worker(), or the peer's window is never replenished. The buffer belongs to the channel, so anything unread when the channel is removed is discarded with it. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `out` - buffer where the data is placed +- `outSz` - size of the buffer + +**Return Values** + +- greater than or equal to 0 - number of bytes read +- `WS_BAD_ARGUMENT` - `ssh` or `out` is NULL, `outSz` is 0, or there is no channel +- `WS_INVALID_STATE_E` + +**See Also** + +- `wolfSSH_extended_data_send()` +- `wolfSSH_ChannelIdReadExt()` +- `wolfSSH_ChannelReadExt()` + +### wolfSSH_SendIgnore() + +```c +#include + +int wolfSSH_SendIgnore(WOLFSSH* ssh, const byte* buf, word32 bufSz); +``` + +**Description** + +Sends an SSH_MSG_IGNORE message to the peer. The peer discards the contents; this can be used as a keepalive or for traffic-analysis resistance. The `buf` and `bufSz` arguments are currently unused: the message always carries 128 zero bytes. + +When strict key exchange is offered, an IGNORE sent before the initial key exchange completes would make a strict peer end the connection, so the call is refused with `WS_INVALID_STATE_E` until then. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `buf` - payload (currently unused) +- `bufSz` - size of the payload (currently unused) + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_INVALID_STATE_E` - strict KEX is offered and the initial key exchange has not completed +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +### wolfSSH_SendDisconnect() + +```c +#include + +int wolfSSH_SendDisconnect(WOLFSSH* ssh, word32 reason); +``` + +**Description** + +Sends an SSH_MSG_DISCONNECT message to the peer with the given reason code (see the `WS_DisconnectReasonCodes` values). + +A disconnect, sent or received, ends the session (RFC 4253 section 11.1). From then on wolfSSH_shutdown(), the send calls, wolfSSH_accept(), wolfSSH_connect() and wolfSSH_worker() report `WS_DISCONNECT`, inbound messages other than a disconnect are dropped, and the channel callbacks stop firing. Channel data that arrived before the disconnect can still be read. + +One disconnect ends the session, so a second call fails with `WS_DISCONNECT`. The exception is a disconnect of this side's own left queued by a short non-blocking send: while it is still queued, calling again retries the flush. wolfSSH_shutdown() retries it too. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `reason` - disconnect reason code + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_WANT_WRITE` - the message is queued; call again to flush it +- `WS_FATAL_ERROR` - the session already disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +**See Also** + +- `wolfSSH_shutdown()` + +### wolfSSH_global_request() + +```c +#include + +int wolfSSH_global_request(WOLFSSH* ssh, const unsigned char* data, + word32 dataSz, int reply); +``` + +**Description** + +Sends a global request (SSH_MSG_GLOBAL_REQUEST) to the peer, using `data` as the request name. If `reply` is 1, the peer is asked to reply with success or failure. The request-specific data that RFC 4254 section 7.1 places after the want-reply boolean cannot be carried by this call, so requests that need it have their own calls, such as wolfSSH_FwdRemoteSetup(). Replies carry no request ID, so in a `WOLFSSH_FWD` build a request sent with `reply` set takes its place in the same send-order queue that wolfSSH_FwdRemoteSetup() uses. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `data` - request name +- `dataSz` - size of the request name +- `reply` - 1 to request a reply from the peer, 0 otherwise + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` or `data` is NULL, or `reply` is not 0 or 1 +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) +- other negative error codes from the send path + +### wolfSSH_ChannelIdRead() + +```c +#include + +int wolfSSH_ChannelIdRead(WOLFSSH* ssh, word32 channelId, + byte* buf, word32 bufSz); +``` + +**Description** + +Reads up to `bufSz` bytes of buffered data from the channel identified by `channelId`, with the contract of wolfSSH_ChannelRead(): it drains what is already buffered, returning 0 when the buffer is empty, and never receives from the transport or reports EOF. Unlike wolfSSH_ChannelRead(), it also reads during a key exchange. Call wolfSSH_worker() to receive more data. + +The read credits the channel window and sends the peer a window adjust. The byte count is returned even when that adjust cannot go out; check wolfSSH_get_error() after the call, where `WS_WANT_WRITE` means the adjust is queued. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `channelId` - the channel to read from +- `buf` - buffer where the data is placed +- `bufSz` - size of the buffer + +**Return Values** + +- greater than or equal to 0 - number of bytes read +- `WS_BAD_ARGUMENT` +- `WS_INVALID_CHANID` - no channel has that ID +- `WS_INVALID_STATE_E` + +**See Also** + +- `wolfSSH_ChannelIdSend()` +- `wolfSSH_ChannelIdPeek()` +- `wolfSSH_ChannelIdReadExt()` + +### wolfSSH_ChannelIdPeek() + +```c +#include + +int wolfSSH_ChannelIdPeek(WOLFSSH* ssh, word32 channelId, + byte* buf, word32 bufSz); +``` + +**Description** + +Copies up to `bufSz` bytes of buffered data from the channel identified by `channelId` into `buf` without consuming them, with the contract of wolfSSH_stream_peek(), except that it also peeks during a key exchange. If `buf` is NULL, only the count of available bytes (capped at `bufSz`) is returned. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `channelId` - the channel to peek +- `buf` - buffer where the peeked data is placed, or NULL +- `bufSz` - size of the buffer + +**Return Values** + +- greater than or equal to 0 - number of bytes copied (or available, if `buf` is NULL) +- `WS_BAD_ARGUMENT` - `ssh` is NULL +- `WS_INVALID_CHANID` - no channel has that ID +- `WS_ERROR` - the buffer is empty and the peer sent EOF (wolfSSH_get_error() reports `WS_EOF`) +- `WS_FATAL_ERROR` - the buffer is empty and the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +**See Also** + +- `wolfSSH_ChannelIdRead()` +- `wolfSSH_stream_peek()` + +### wolfSSH_ChannelIdSend() + +```c +#include + +int wolfSSH_ChannelIdSend(WOLFSSH* ssh, word32 channelId, + byte* buf, word32 bufSz); +``` + +**Description** + +Sends `bufSz` bytes on the channel identified by `channelId`. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `channelId` - the channel to send on +- `buf` - buffer to send +- `bufSz` - size of the buffer + +**Return Values** + +- greater than 0 - number of bytes sent on success +- `WS_BAD_ARGUMENT` +- `WS_INVALID_CHANID` - no channel has that ID +- `WS_CHANNEL_NOT_CONF` - the peer has not confirmed the channel open yet +- `WS_EOF` - this side already sent EOF on the channel +- `WS_REKEYING` - a key exchange is in progress +- `WS_WINDOW_FULL` - the peer's channel window is full +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +**See Also** + +- `wolfSSH_ChannelIdRead()` +- `wolfSSH_ChannelIdSendExt()` + +### wolfSSH_ChannelIdReadExt() + +```c +#include + +int wolfSSH_ChannelIdReadExt(WOLFSSH* ssh, word32 channelId, + byte* buf, word32 bufSz); +``` + +**Description** + +Reads up to `bufSz` bytes of buffered extended data (stderr) from the channel identified by `channelId`. This has the drain contract of wolfSSH_extended_data_read(), but reads the named channel instead of the first one in the channel list. Each channel's stderr must be drained, since it shares the channel receive window with normal data; wolfSSH_worker() names the channel when it returns `WS_EXTDATA`. The byte count is returned even when the window adjust cannot go out; wolfSSH_get_error() then reports the adjust's status, such as `WS_WANT_WRITE`. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `channelId` - the channel to read from +- `buf` - buffer where the data is placed +- `bufSz` - size of the buffer + +**Return Values** + +- greater than or equal to 0 - number of bytes read +- `WS_BAD_ARGUMENT` - `ssh` or `buf` is NULL, or `bufSz` is 0 +- `WS_INVALID_CHANID` - no channel has that ID +- `WS_INVALID_STATE_E` + +**See Also** + +- `wolfSSH_ChannelIdSendExt()` +- `wolfSSH_extended_data_read()` +- `wolfSSH_ChannelReadExt()` + +### wolfSSH_ChannelIdSendExt() + +```c +#include + +int wolfSSH_ChannelIdSendExt(WOLFSSH* ssh, word32 channelId, + byte* buf, word32 bufSz); +``` + +**Description** + +Sends `bufSz` bytes as extended data (the stderr data type) on the channel identified by `channelId`. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `channelId` - the channel to send on +- `buf` - buffer to send +- `bufSz` - size of the buffer + +**Return Values** + +- greater than 0 - number of bytes sent on success +- `WS_BAD_ARGUMENT` +- `WS_INVALID_CHANID` - no channel has that ID +- `WS_CHANNEL_NOT_CONF` - the peer has not confirmed the channel open yet +- `WS_EOF` - this side already sent EOF on the channel +- `WS_REKEYING` - a key exchange is in progress +- `WS_WINDOW_FULL` - the peer's channel window is full +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +**See Also** + +- `wolfSSH_ChannelIdReadExt()` +- `wolfSSH_extended_data_send()` +- `wolfSSH_ChannelSendExt()` + +### wolfSSH_CTX_SetSshProtoIdStr() + +```c +#include + +int wolfSSH_CTX_SetSshProtoIdStr(WOLFSSH_CTX* ctx, const char* protoIdStr); +``` + +**Description** + +Overrides the SSH protocol identification string that is sent to the peer during the version exchange at the start of the connection. The string is validated and rejected with `WS_BAD_ARGUMENT`, leaving the context unchanged, unless it: + +- begins with "SSH-2.0-" +- is between 11 and 255 bytes long, counting the "SSH-2.0-" prefix and the trailing CR LF +- ends with CR LF (`"\r\n"`) +- carries only printable US-ASCII (0x20 to 0x7e) in the body, which rules out an embedded CR or LF +- does not begin the body with a space (RFC 4253 section 4.2 reads the body as softwareversion followed by optional comments, so a leading space would make softwareversion empty; a space later in the body starts the comments) + +The string is stored by reference, not copied, so it must remain valid and unmodified for the lifetime of the context. It is validated only when set. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `protoIdStr` - the protocol identification string to send, including the trailing CR LF + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_CTX_SetWindowPacketSize() + +```c +#include + +int wolfSSH_CTX_SetWindowPacketSize(WOLFSSH_CTX* ctx, + word32 windowSz, word32 maxPacketSz); +``` + +**Description** + +Sets the default channel window size and maximum packet size for sessions created from this context. A `windowSz` of 0 selects the default (`DEFAULT_WINDOW_SZ`, 128 KB), and the window may not exceed 256 KB (`WINDOW_SZ_UPPER_BOUND`). A `maxPacketSz` of 0 selects the default (`DEFAULT_MAX_PACKET_SZ`, 32768), and the packet size may not exceed `MAX_PACKET_SZ` less the channel data packet overhead. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `windowSz` - the channel window size, in bytes, or 0 for the default +- `maxPacketSz` - the maximum packet size, in bytes, or 0 for the default + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` is NULL, or a size is over its limit + +## Channel Callbacks + +Interfaces to the wolfSSH library return single int values. Communicating +status of asynchronous information, like the peer opening a channel, isn't +easy with that interface. wolfSSH uses callback functions to notify the +calling application of changes in state of a channel. + +There are callback functions for receipt of the following SSHv2 protocol +messages: + +* SSH_MSG_CHANNEL_OPEN +* SSH_MSG_CHANNEL_OPEN_CONFIRMATION +* SSH_MSG_CHANNEL_OPEN_FAILURE +* SSH_MSG_CHANNEL_REQUEST + - "shell" + - "subsystem" + - "exec" + - any request type, through the request policy callback set with + wolfSSH_CTX_SetChannelReqAnyCb() +* SSH_MSG_CHANNEL_EOF +* SSH_MSG_CHANNEL_CLOSE + +### Callback Function Prototypes + +The channel callback functions all take a pointer to a **WOLFSSH_CHANNEL** +object, _channel_, and a pointer to the application defined data structure, +_ctx_. Properties about the channel may be queried using API functions. + +``` +typedef int (*WS_CallbackChannelOpen)(WOLFSSH_CHANNEL* channel, void* ctx); +typedef int (*WS_CallbackChannelReq)(WOLFSSH_CHANNEL* channel, void* ctx); +typedef int (*WS_CallbackChannelEof)(WOLFSSH_CHANNEL* channel, void* ctx); +typedef int (*WS_CallbackChannelClose)(WOLFSSH_CHANNEL* channel, void* ctx); +``` + +The request policy callback has its own prototype, which also receives the +request type and its type-specific data, and returns one of the +`WS_ReqCbResult` values. The global request policy callback (see +wolfSSH_CTX_SetGlobalReqAnyCb()) uses the same result values. + +``` +typedef enum WS_ReqCbResult { + WOLFSSH_REQ_UNHANDLED = 0, + WOLFSSH_REQ_ACCEPT, + WOLFSSH_REQ_REJECT +} WS_ReqCbResult; + +typedef int (*WS_CallbackChannelReqAny)(WOLFSSH_CHANNEL* channel, + const byte* type, word32 typeSz, const byte* data, word32 dataSz, + int wantReply, void* ctx); +``` + +Note that 0 is `WOLFSSH_REQ_UNHANDLED` here, where the shell, subsystem and +exec request callbacks read a 0 return as acceptance. A callback of this +family returns one of the three `WS_ReqCbResult` values, not `WS_SUCCESS`. + +### wolfSSH_CTX_SetChannelOpenCb() + +```c +#include + +int wolfSSH_CTX_SetChannelOpenCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelOpen cb); +``` + +**Description** + +Sets the callback invoked when a Channel Open (SSH_MSG_CHANNEL_OPEN) message is received from the peer. This is the policy callback for peer channel opens: when no callback is registered, every channel open from the peer is accepted by default, except the forwarding channel types, which are refused without a forwarding callback (see wolfSSH_CTX_SetFwdCb()). A client refuses a "session" channel open from a server outright, ahead of this callback. Register a callback to enforce a channel policy. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the channel open callback + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**See Also** + +- `wolfSSH_SetChannelOpenCtx()` + + +### wolfSSH_CTX_SetChannelOpenRespCb() + +```c +#include + +int wolfSSH_CTX_SetChannelOpenRespCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelOpen confCb, WS_CallbackChannelOpen failCb); +``` + +**Description** + +Sets the callbacks invoked when a Channel Open Confirmation (SSH_MSG_CHANNEL_OPEN_CONFIRMATION) or a Channel Open Failure (SSH_MSG_CHANNEL_OPEN_FAILURE) message is received from the peer. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `confCb` - callback for a channel open confirmation +- `failCb` - callback for a channel open failure + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**See Also** + +- `wolfSSH_CTX_SetChannelOpenCb()` + + +### wolfSSH_CTX_SetChannelReqShellCb() + +```c +#include + +int wolfSSH_CTX_SetChannelReqShellCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelReq cb); +``` + +**Description** + +Sets the callback invoked when a Channel Request (SSH_MSG_CHANNEL_REQUEST) message is received from the peer for a _shell_. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the channel request callback + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**See Also** + +- `wolfSSH_CTX_SetChannelReqExecCb()` + + +### wolfSSH_CTX_SetChannelReqSubsysCb() + +```c +#include + +int wolfSSH_CTX_SetChannelReqSubsysCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelReq cb); +``` + +**Description** + +Sets the callback invoked when a Channel Request (SSH_MSG_CHANNEL_REQUEST) message is received from the peer for a _subsystem_. A common example of a subsystem is SFTP. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the channel request callback + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**See Also** + +- `wolfSSH_CTX_SetChannelReqShellCb()` + + +### wolfSSH_CTX_SetChannelReqExecCb() + +```c +#include + +int wolfSSH_CTX_SetChannelReqExecCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelReq cb); +``` + +**Description** + +Sets the callback invoked when a Channel Request (SSH_MSG_CHANNEL_REQUEST) message is received from the peer for a command to _exec_. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the channel request callback + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**See Also** + +- `wolfSSH_CTX_SetChannelReqShellCb()` + + +### wolfSSH_CTX_SetChannelReqAnyCb() + +```c +#include + +int wolfSSH_CTX_SetChannelReqAnyCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelReqAny cb); +``` + +**Description** + +Sets a policy callback consulted first for every Channel Request (SSH_MSG_CHANNEL_REQUEST) from the peer, ahead of the shell, exec and subsystem callbacks and of the built-in handling. A request with no callback of its own -- env, pty-req, window-change, exit-status, auth-agent-req, or a type the library does not know -- can then be granted or refused by policy. + +`type` is the request name as it arrived, `typeSz` bytes, and `data` is the request's type-specific part, `dataSz` bytes, for the callback to parse. Neither is NUL terminated, and a name may hold any byte, so match on `typeSz` bytes rather than with the string functions. `wantReply` is what the peer asked for. The callback shares the channel request context set with wolfSSH_SetChannelReqCtx(). + +The callback returns a `WS_ReqCbResult`. `WOLFSSH_REQ_UNHANDLED` (0, and what a missing callback answers) leaves the request to the other callbacks and the built-in handling. `WOLFSSH_REQ_ACCEPT` and `WOLFSSH_REQ_REJECT` settle the request, and the shell, exec and subsystem callbacks are not consulted. The library still parses and records what it needs from a request it knows, so an accepted session request sets the channel's session type and the modes of an accepted pty-req are kept; a request that does not fit its type is refused whatever the callback says. A type the library does not know is answered with CHANNEL_SUCCESS on `WOLFSSH_REQ_ACCEPT`, where it is otherwise refused. + +The callback may free the channel it was handed with wolfSSH_ChannelFree(); the request ends there, and one wanting a reply fails with `WS_INVALID_CHANID`. `type` and `data` point into the session's input buffer and are valid only for the length of the call, so a callback keeping either must copy it. The callback must not re-enter the receive side of the library on this session (wolfSSH_worker(), wolfSSH_stream_read(), wolfSSH_accept(), or the SFTP calls). + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the channel request policy callback + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**See Also** + +- `wolfSSH_SetChannelReqCtx()` +- `wolfSSH_CTX_SetChannelReqShellCb()` +- `wolfSSH_CTX_SetGlobalReqAnyCb()` + + +### wolfSSH_CTX_SetAppChannels() + +```c +#include + +int wolfSSH_CTX_SetAppChannels(WOLFSSH_CTX* ctx, byte enable); +``` + +**Description** + +Enables or disables application-driven channel handling on the server side for sessions created from this context. It is off by default. + +When off, wolfSSH_accept() runs the session state machine through to an established session with the first channel open, and a shell, exec, or subsystem request with no callback registered for it is accepted. + +When on, wolfSSH_accept() returns `WS_SUCCESS` as soon as the user has authenticated, and the application owns every channel from there, driving the session with wolfSSH_worker() and the channel callbacks. A shell, exec, or subsystem request with no callback registered is then rejected. wolfSSH_accept() never reaches the built-in SCP entry point in this mode, so it does not return `WS_SCP_INIT`. wolfSSH_SFTP_accept() still serves, but only on a session channel whose "sftp" subsystem request the subsystem callback granted; called ahead of that, it returns `WS_INVALID_STATE_E`. + +Set this on the context before wolfSSH_new(), or on a session with wolfSSH_SetAppChannels() before the first wolfSSH_accept() call. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `enable` - non-zero to enable application-driven channels, 0 to disable + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**See Also** + +- `wolfSSH_SetAppChannels()` +- `wolfSSH_accept()` +- `wolfSSH_ChannelGetSessionGranted()` + + +### wolfSSH_SetAppChannels() + +```c +#include + +int wolfSSH_SetAppChannels(WOLFSSH* ssh, byte enable); +``` + +**Description** + +Enables or disables application-driven channel handling for one session, overriding the setting inherited from its context. See wolfSSH_CTX_SetAppChannels(). Set it before the first wolfSSH_accept() call. Turning it on later still applies to the channel requests that follow, but cannot move where wolfSSH_accept() returns on a session that has already gone past user authentication. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `enable` - non-zero to enable application-driven channels, 0 to disable + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` + +**See Also** + +- `wolfSSH_CTX_SetAppChannels()` + +### wolfSSH_CTX_SetChannelEofCb() + +```c +#include + +int wolfSSH_CTX_SetChannelEofCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelEof cb); +``` + +**Description** + +Sets the callback invoked when a Channel EOF (SSH_MSG_CHANNEL_EOF) message is received from the peer, indicating the peer will not transmit any more data on this channel. The channel stays open for sending. The library never answers a received EOF with one of its own; the application decides whether to reply, with wolfSSH_ChannelSendEof() or wolfSSH_stream_send_eof(). + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the channel EOF callback + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**See Also** + +- `wolfSSH_CTX_SetChannelCloseCb()` + + +### wolfSSH_CTX_SetChannelCloseCb() + +```c +#include + +int wolfSSH_CTX_SetChannelCloseCb(WOLFSSH_CTX* ctx, + WS_CallbackChannelClose cb); +``` + +**Description** + +Sets the callback invoked when a Channel Close (SSH_MSG_CHANNEL_CLOSE) message is received from the peer, indicating the peer wants to terminate this channel. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the channel close callback + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` + +**See Also** + +- `wolfSSH_CTX_SetChannelEofCb()` + + +### wolfSSH_SetChannelOpenCtx() + +```c +#include + +int wolfSSH_SetChannelOpenCtx(WOLFSSH* ssh, void* ctx); +``` + +**Description** + +Sets the user context passed to the channel open, channel open confirmation, and channel open failure callbacks. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context to pass to the channel open callbacks + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` + +**See Also** + +- `wolfSSH_GetChannelOpenCtx()` + + +### wolfSSH_SetChannelReqCtx() + +```c +#include + +int wolfSSH_SetChannelReqCtx(WOLFSSH* ssh, void* ctx); +``` + +**Description** + +Sets the user context passed to the channel request (shell/exec/subsystem) callbacks. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context to pass to the channel request callbacks + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` + +**See Also** + +- `wolfSSH_GetChannelReqCtx()` + + +### wolfSSH_SetChannelEofCtx() + +```c +#include + +int wolfSSH_SetChannelEofCtx(WOLFSSH* ssh, void* ctx); +``` + +**Description** + +Sets the user context passed to the channel EOF callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context to pass to the channel EOF callback + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` + +**See Also** + +- `wolfSSH_GetChannelEofCtx()` + + +### wolfSSH_SetChannelCloseCtx() + +```c +#include + +int wolfSSH_SetChannelCloseCtx(WOLFSSH* ssh, void* ctx); +``` + +**Description** + +Sets the user context passed to the channel close callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context to pass to the channel close callback + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` + +**See Also** + +- `wolfSSH_GetChannelCloseCtx()` + + +### wolfSSH_GetChannelOpenCtx() + +```c +#include + +void* wolfSSH_GetChannelOpenCtx(WOLFSSH* ssh); +``` + +**Description** + +Returns the user context previously set with wolfSSH_SetChannelOpenCtx() for the channel open callbacks. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- the channel open context pointer, or `NULL` if none + +**See Also** + +- `wolfSSH_SetChannelOpenCtx()` + + +### wolfSSH_GetChannelReqCtx() + +```c +#include + +void* wolfSSH_GetChannelReqCtx(WOLFSSH* ssh); +``` + +**Description** + +Returns the user context previously set with wolfSSH_SetChannelReqCtx() for the channel request callbacks. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- the channel request context pointer, or `NULL` if none + +**See Also** + +- `wolfSSH_SetChannelReqCtx()` + + +### wolfSSH_GetChannelEofCtx() + +```c +#include + +void* wolfSSH_GetChannelEofCtx(WOLFSSH* ssh); +``` + +**Description** + +Returns the user context previously set with wolfSSH_SetChannelEofCtx() for the channel EOF callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- the channel EOF context pointer, or `NULL` if none + +**See Also** + +- `wolfSSH_SetChannelEofCtx()` + + +### wolfSSH_GetChannelCloseCtx() + +```c +#include + +void* wolfSSH_GetChannelCloseCtx(WOLFSSH* ssh); +``` + +**Description** + +Returns the user context previously set with wolfSSH_SetChannelCloseCtx() for the channel close callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- the channel close context pointer, or `NULL` if none + +**See Also** + +- `wolfSSH_SetChannelCloseCtx()` + + +## Channel Functions + +These functions operate directly on `WOLFSSH_CHANNEL` objects, which represent the individual channels multiplexed over an SSH session. + +### wolfSSH_ChannelGetSessionType() + +```c +#include + +WS_SessionType wolfSSH_ChannelGetSessionType(const WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Returns the `WS_SessionType` (shell, exec, subsystem, terminal, or unknown) for the specified channel. + +**Parameters** + +- `channel` - pointer to the channel + +**Return Values** + +- the channel's `WS_SessionType` + +**See Also** + +- `wolfSSH_ChannelGetSessionCommand()` + + +### wolfSSH_ChannelGetSessionCommand() + +```c +#include + +const char* wolfSSH_ChannelGetSessionCommand(const WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Returns the command the peer requested to execute over the specified channel (for an "exec" request), or the subsystem name (for a "subsystem" request). Use wolfSSH_ChannelGetSessionCommandSz() for its recorded length. + +**Parameters** + +- `channel` - pointer to the channel + +**Return Values** + +- pointer to the command string, or `NULL` if none + +**See Also** + +- `wolfSSH_ChannelGetSessionType()` +- `wolfSSH_ChannelGetSessionCommandSz()` + +### wolfSSH_ChannelGetSessionCommandSz() + +```c +#include + +word32 wolfSSH_ChannelGetSessionCommandSz(const WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Returns the recorded length, in bytes, of the command or subsystem name returned by wolfSSH_ChannelGetSessionCommand(). A peer-supplied command may contain a NUL byte, so compare this length against the string length when the distinction matters. + +**Parameters** + +- `channel` - pointer to the channel + +**Return Values** + +- the length of the session command, or 0 if there is none or `channel` is NULL + +**See Also** + +- `wolfSSH_ChannelGetSessionCommand()` + +### wolfSSH_ChannelGetSessionGranted() + +```c +#include + +int wolfSSH_ChannelGetSessionGranted(const WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Reports whether a shell, exec, or subsystem request on the channel has been answered with CHANNEL_SUCCESS. A session request callback sees this still clear for the request it is answering, so a set flag there means an earlier request was granted. + +**Parameters** + +- `channel` - pointer to the channel + +**Return Values** + +- 1 - a session request on the channel has been granted +- 0 - none has been granted +- `WS_BAD_ARGUMENT` - `channel` is NULL + +**See Also** + +- `wolfSSH_ChannelGetSessionType()` +- `wolfSSH_CTX_SetAppChannels()` +- `wolfSSH_ChannelCommandIsScp()` + +### wolfSSH_ChannelFree() + +```c +#include + +int wolfSSH_ChannelFree(WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Frees a channel object and removes it from its session. + +**Parameters** + +- `channel` - pointer to the channel to free + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_ChannelGetId() + +```c +#include + +int wolfSSH_ChannelGetId(WOLFSSH_CHANNEL* channel, word32* id, byte peer); +``` + +**Description** + +Retrieves the numeric channel ID for the given channel. Set `peer` to `WS_CHANNEL_ID_SELF` for this side's ID or `WS_CHANNEL_ID_PEER` for the peer's ID. + +**Parameters** + +- `channel` - pointer to the channel +- `id` - output for the channel ID +- `peer` - `WS_CHANNEL_ID_SELF` or `WS_CHANNEL_ID_PEER` + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +**See Also** + +- `wolfSSH_ChannelFind()` + +### wolfSSH_ChannelFind() + +```c +#include + +WOLFSSH_CHANNEL* wolfSSH_ChannelFind(WOLFSSH* ssh, word32 id, byte peer); +``` + +**Description** + +Finds the channel on the session matching the given ID. Set `peer` to `WS_CHANNEL_ID_SELF` to match this side's ID or `WS_CHANNEL_ID_PEER` to match the peer's ID. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `id` - the channel ID to find +- `peer` - `WS_CHANNEL_ID_SELF` or `WS_CHANNEL_ID_PEER` + +**Return Values** + +- pointer to the matching channel, or `NULL` if not found + +**See Also** + +- `wolfSSH_ChannelNext()` + +### wolfSSH_ChannelNext() + +```c +#include + +WOLFSSH_CHANNEL* wolfSSH_ChannelNext(WOLFSSH* ssh, WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Iterates the channels on a session. Pass `NULL` for `channel` to get the first channel; pass a channel to get the one after it. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `channel` - the current channel, or `NULL` to start iteration + +**Return Values** + +- pointer to the next channel, or `NULL` at the end of the list + +**See Also** + +- `wolfSSH_ChannelFind()` + +### wolfSSH_ChannelRead() + +```c +#include + +int wolfSSH_ChannelRead(WOLFSSH_CHANNEL* channel, byte* buf, word32 bufSz); +``` + +**Description** + +Reads up to `bufSz` bytes of buffered data from the given channel. It drains only what is already buffered, returning 0 when the buffer is empty; it never receives from the transport and never reports EOF. Call wolfSSH_worker() to receive more data. + +The read credits the channel window and sends the peer a window adjust, as wolfSSH_stream_read() does. It does not clear the session's error state on entry, so check wolfSSH_get_error() after the call: `WS_WANT_WRITE` there means the adjust is queued, while the byte count is still returned. + +**Parameters** + +- `channel` - pointer to the channel +- `buf` - buffer where the data is placed +- `bufSz` - size of the buffer + +**Return Values** + +- greater than or equal to 0 - number of bytes read +- `WS_BAD_ARGUMENT` +- `WS_REKEYING` - a key exchange is in progress (wolfSSH_ChannelIdRead() reads during one) +- `WS_INVALID_STATE_E` + +**See Also** + +- `wolfSSH_ChannelSend()` +- `wolfSSH_ChannelReadExt()` +- `wolfSSH_ChannelIdRead()` + +### wolfSSH_ChannelReadExt() + +```c +#include + +int wolfSSH_ChannelReadExt(WOLFSSH_CHANNEL* channel, byte* buf, + word32 bufSz); +``` + +**Description** + +Reads up to `bufSz` bytes of buffered extended data (stderr) from the given channel. This has the drain contract of wolfSSH_extended_data_read(), but reads the named channel. Unlike wolfSSH_ChannelRead(), it does not fail with `WS_REKEYING` during a key exchange: the data is already buffered, and the window credit the read owes is held until the key exchange completes. + +**Parameters** + +- `channel` - pointer to the channel +- `buf` - buffer where the data is placed +- `bufSz` - size of the buffer + +**Return Values** + +- greater than or equal to 0 - number of bytes read +- `WS_BAD_ARGUMENT` - `channel` or `buf` is NULL, or `bufSz` is 0 +- `WS_INVALID_STATE_E` + +**See Also** + +- `wolfSSH_ChannelSendExt()` +- `wolfSSH_ChannelIdReadExt()` +- `wolfSSH_extended_data_read()` + +### wolfSSH_ChannelSend() + +```c +#include + +int wolfSSH_ChannelSend(WOLFSSH_CHANNEL* channel, const byte* buf, + word32 bufSz); +``` + +**Description** + +Sends `bufSz` bytes on the given channel. + +**Parameters** + +- `channel` - pointer to the channel +- `buf` - buffer to send +- `bufSz` - size of the buffer + +**Return Values** + +- greater than 0 - number of bytes sent on success +- `WS_BAD_ARGUMENT` +- `WS_CHANNEL_NOT_CONF` - the peer has not confirmed the channel open yet +- `WS_EOF` - this side already sent EOF on the channel +- `WS_REKEYING` - a key exchange is in progress +- `WS_WINDOW_FULL` - the peer's channel window is full +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +**See Also** + +- `wolfSSH_ChannelRead()` +- `wolfSSH_ChannelSendExt()` + +### wolfSSH_ChannelSendExt() + +```c +#include + +int wolfSSH_ChannelSendExt(WOLFSSH_CHANNEL* channel, + const byte* buf, word32 bufSz); +``` + +**Description** + +Sends `bufSz` bytes as extended data (the stderr data type) on the given channel. + +**Parameters** + +- `channel` - pointer to the channel +- `buf` - buffer to send +- `bufSz` - size of the buffer + +**Return Values** + +- greater than 0 - number of bytes sent on success +- `WS_BAD_ARGUMENT` +- `WS_CHANNEL_NOT_CONF` - the peer has not confirmed the channel open yet +- `WS_EOF` - this side already sent EOF on the channel +- `WS_REKEYING` - a key exchange is in progress +- `WS_WINDOW_FULL` - the peer's channel window is full +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +**See Also** + +- `wolfSSH_ChannelReadExt()` +- `wolfSSH_ChannelIdSendExt()` + +### wolfSSH_ChannelExit() + +```c +#include + +int wolfSSH_ChannelExit(WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Closes the given channel, sending SSH_MSG_CHANNEL_EOF and then SSH_MSG_CHANNEL_CLOSE to the peer. The channel stays on the session's channel list, and the channel pointer stays valid, until the peer's close arrives and wolfSSH_worker() reports `WS_CHANNEL_CLOSED`. A walk with wolfSSH_ChannelNext() has to step past a channel it has exited rather than re-read the head of the list. + +`WS_WANT_WRITE` means the teardown is incomplete: the close is built only once the EOF is sent, so call again until the result is something else. Retrying does not send a second EOF. `WS_SUCCESS` means both messages are queued, not that they reached the peer. A peer that never answers leaves the channel on the list for the life of the session. + +**Parameters** + +- `channel` - pointer to the channel + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_CHANNEL_NOT_CONF` - the peer has not confirmed the channel open, so there is no peer channel ID to address +- `WS_WANT_WRITE` - call again to complete the teardown +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +**See Also** + +- `wolfSSH_ChannelSendEof()` +- `wolfSSH_worker()` + +### wolfSSH_ChannelSendEof() + +```c +#include + +int wolfSSH_ChannelSendEof(WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Sends SSH_MSG_CHANNEL_EOF on the given channel, closing the sending direction and leaving the receiving direction open (the half-close of RFC 4254 section 5.3). Data sends on the channel then fail with `WS_EOF` -- wolfSSH_ChannelSend(), wolfSSH_stream_send() and the extended data variants -- while requests, the exit status and the teardown messages still go out. Reads work until the peer sends its own EOF or closes the channel. The call is idempotent: a second call puts no second EOF on the wire. + +The library never answers a received EOF with one of its own. It reports it as `WS_EOF` and through the channel EOF callback, and the application decides whether to reply with this call or wolfSSH_stream_send_eof(). wolfSSH_ChannelExit() and wolfSSH_shutdown() send an EOF themselves while tearing the channel down. + +**Parameters** + +- `channel` - pointer to the channel + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `channel` is NULL +- `WS_CHANNEL_NOT_CONF` - the peer has not confirmed the channel open yet +- `WS_REKEYING` - a key exchange is in progress +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) +- a send-path status such as `WS_WANT_WRITE` + +**See Also** + +- `wolfSSH_stream_send_eof()` +- `wolfSSH_ChannelGetEof()` +- `wolfSSH_ChannelExit()` + +### wolfSSH_ChannelGetEof() + +```c +#include + +int wolfSSH_ChannelGetEof(WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Reports whether the peer has sent EOF on the given channel. wolfSSH_worker() reports a received EOF as `WS_EOF` only once, on arrival; this call is the durable check. + +**Parameters** + +- `channel` - pointer to the channel + +**Return Values** + +- 1 - the channel has received EOF +- 0 - the channel has not received EOF + +### wolfSSH_ChannelGetType() + +```c +#include + +const char* wolfSSH_ChannelGetType(const WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Returns the channel type string (for example, "session") for the given channel. + +**Parameters** + +- `channel` - pointer to the channel + +**Return Values** + +- pointer to the channel type string, or `NULL` if none + +### wolfSSH_ChannelIsPty() + +```c +#include + +int wolfSSH_ChannelIsPty(const WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Reports whether the given channel has an associated pseudo-terminal (PTY). + +**Parameters** + +- `channel` - pointer to the channel + +**Return Values** + +- 1 - the channel has a PTY +- 0 - the channel does not have a PTY + + +## Testing Functions + + +### wolfSSH_GetStats() + + +```c +#include + +void wolfSSH_GetStats(WOLFSSH* ssh, word32* txCount, word32* rxCount, + word32* seq, word32* peerSeq); +``` + +**Description** + +Writes the session's transfer statistics into the provided output pointers. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `txCount` - output for the total bytes transmitted on the session +- `rxCount` - output for the total bytes received on the session +- `seq` - output for the outgoing packet sequence number +- `peerSeq` - output for the peer's packet sequence number + +**Return Values** + +None + +### wolfSSH_KDF() + + +```c +#include + +int wolfSSH_KDF(byte hashId, byte keyId, byte* key, word32 keySz, + const byte* k, word32 kSz, const byte* h, word32 hSz, + const byte* sessionId, word32 sessionIdSz); +``` + +**Description** + +Runs the SSH key derivation function. It derives a symmetric key from the source keying material `k` (the Diffie-Hellman shared secret) and `h` (the exchange hash produced during key exchange). The particular key produced is selected by `keyId`. This function is primarily exposed so the test suite can run known-answer tests against the key derivation. + +The `keyId` values are: + +``` +A - initial IV, client to server +B - initial IV, server to client +C - encryption key, client to server +D - encryption key, server to client +E - integrity key, client to server +F - integrity key, server to client +``` + +**Parameters** + +- `hashId` - the hash type used to derive keying material (for example, `WC_HASH_TYPE_SHA` or `WC_HASH_TYPE_SHA256`) +- `keyId` - which key to derive (A through F, as above) +- `key` - output buffer for the derived key +- `keySz` - size of the output key buffer +- `k` - the Diffie-Hellman shared secret +- `kSz` - size of `k` +- `h` - the exchange hash +- `hSz` - size of `h` +- `sessionId` - the session identifier +- `sessionIdSz` - size of the session identifier + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_CRYPTO_FAILED` + +### wolfSSH_ShowSizes() + +```c +#include + +void wolfSSH_ShowSizes(void); +``` + +**Description** + +Prints the sizes of wolfSSH's internal data structures. This is a diagnostic aid, useful for tuning memory use on constrained targets. + +**Parameters** + +None + +**Return Values** + +None + + +## Session Functions + + + +### wolfSSH_GetSessionType() + + +```c +#include + +WS_SessionType wolfSSH_GetSessionType(const WOLFSSH* ssh); +``` + +**Description** + +Returns the session type for the session's channel: one of `WOLFSSH_SESSION_UNKNOWN`, `WOLFSSH_SESSION_SHELL`, `WOLFSSH_SESSION_EXEC`, `WOLFSSH_SESSION_SUBSYSTEM`, or `WOLFSSH_SESSION_TERMINAL`. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- the session's `WS_SessionType` + +**See Also** + +- `wolfSSH_GetSessionCommand()` + +### wolfSSH_GetSessionCommand() + + +```c +#include + +const char* wolfSSH_GetSessionCommand(const WOLFSSH* ssh); +``` + +**Description** + +Returns the command the peer requested to run for this session (for an "exec" request), or the subsystem name, taken from the first channel in the session's channel list. Use wolfSSH_GetSessionCommandSz() for its recorded length. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- pointer to the command string, or `NULL` if none + +**See Also** + +- `wolfSSH_GetSessionType()` +- `wolfSSH_GetSessionCommandSz()` + +### wolfSSH_GetSessionCommandSz() + +```c +#include + +word32 wolfSSH_GetSessionCommandSz(const WOLFSSH* ssh); +``` + +**Description** + +Returns the recorded length, in bytes, of the command returned by wolfSSH_GetSessionCommand(), taken from the first channel in the session's channel list. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- the length of the session command, or 0 if there is none or `ssh` is NULL + +**See Also** + +- `wolfSSH_GetSessionCommand()` +- `wolfSSH_ChannelGetSessionCommandSz()` + +### wolfSSH_SetChannelType() + +```c +#include + +int wolfSSH_SetChannelType(WOLFSSH* ssh, byte type, byte* name, + word32 nameSz); +``` + +**Description** + +Sets the channel request type (for example, shell, exec, or subsystem) and optional name for the session's channel. Exec and subsystem carry a name string the peer requires, so one must be available: passing no name keeps the name an earlier call stored, and with nothing stored the call is refused. Shell and terminal take no name and drop any stored one. A refused call changes nothing, the selected type included. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `type` - the channel request type +- `name` - the command or subsystem name for exec or subsystem, or NULL to keep a stored one +- `nameSz` - length of `name` + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` is NULL, `type` is unknown, exec is requested on the server side, `name` is `WOLFSSH_MAX_CHN_NAMESZ` bytes or longer, `nameSz` is given with no `name`, or exec or subsystem has no name given and none stored +- `WS_MEMORY_E` - the name cannot be allocated + +### wolfSSH_ChangeTerminalSize() + +```c +#include + +int wolfSSH_ChangeTerminalSize(WOLFSSH* ssh, word32 columns, + word32 rows, word32 widthPixels, word32 heightPixels); +``` + +**Description** + +Notifies the peer that the terminal (window) size has changed, sending the new dimensions. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `columns` - the new width in character columns +- `rows` - the new height in character rows +- `widthPixels` - the new width in pixels +- `heightPixels` - the new height in pixels + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) + +**See Also** + +- `wolfSSH_SetTerminalResizeCb()` + +### wolfSSH_SetTerminalResizeCb() + +```c +#include + +void wolfSSH_SetTerminalResizeCb(WOLFSSH* ssh, WS_CallbackTerminalSize cb); +``` + +**Description** + +Registers a callback that is invoked when the peer reports a terminal size change. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `cb` - the terminal resize callback + +**Return Values** + +None + +**See Also** + +- `wolfSSH_SetTerminalResizeCtx()` + +### wolfSSH_SetTerminalResizeCtx() + +```c +#include + +void wolfSSH_SetTerminalResizeCtx(WOLFSSH* ssh, void* usrCtx); +``` + +**Description** + +Sets the user context pointer passed to the terminal resize callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `usrCtx` - user context pointer to pass to the callback + +**Return Values** + +None + +### wolfSSH_GetExitStatus() + +```c +#include + +int wolfSSH_GetExitStatus(WOLFSSH* ssh); +``` + +**Description** + +Returns the exit status the peer reported for the session's command. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- the exit status reported by the peer + +**See Also** + +- `wolfSSH_SetExitStatus()` + +### wolfSSH_SetExitStatus() + +```c +#include + +int wolfSSH_SetExitStatus(WOLFSSH* ssh, word32 exitStatus); +``` + +**Description** + +Sets the exit status to report to the peer for the session's command. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `exitStatus` - the exit status to report + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +**See Also** + +- `wolfSSH_GetExitStatus()` + +### wolfSSH_DoModes() + +```c +#include + +int wolfSSH_DoModes(const byte* modes, word32 modesSz, int fd); +``` + +**Description** + +Applies the SSH-encoded terminal modes in `modes` to the terminal referenced by the file descriptor `fd`. + +**Parameters** + +- `modes` - buffer of SSH-encoded terminal modes +- `modesSz` - length of the modes buffer +- `fd` - file descriptor of the terminal to configure + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_ConvertConsole() + +**Availability** + +Available only on Windows builds (`USE_WINDOWS_API`). + +```c +#include + +int wolfSSH_ConvertConsole(WOLFSSH* ssh, WOLFSSH_HANDLE handle, + byte* buf, word32 bufSz); +``` + +**Description** + +Processes console data read from the Windows console handle, translating it for the SSH stream. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `handle` - the Windows console handle +- `buf` - buffer of console data to convert +- `bufSz` - length of the buffer + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_SetKeyingCompletionCb() + +```c +#include + +void wolfSSH_SetKeyingCompletionCb(WOLFSSH_CTX* ctx, + WS_CallbackKeyingCompletion cb); +``` + +**Description** + +Registers a callback that is invoked when a key exchange (initial or rekey) completes. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the keying completion callback + +**Return Values** + +None + +**See Also** + +- `wolfSSH_SetKeyingCompletionCbCtx()` + +### wolfSSH_SetKeyingCompletionCbCtx() + +```c +#include + +void wolfSSH_SetKeyingCompletionCbCtx(WOLFSSH* ssh, void* ctx); +``` + +**Description** + +Sets the user context pointer passed to the keying completion callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context pointer to pass to the callback + +**Return Values** + +None + +### wolfSSH_RealPath() + +```c +#include + +int wolfSSH_RealPath(const char* defaultPath, char* in, + char* out, word32 outSz); +``` + +**Description** + +Resolves the path `in`, relative to `defaultPath`, into a canonical absolute path written to `out`. + +**Parameters** + +- `defaultPath` - the base path used to resolve a relative `in` +- `in` - the path to resolve +- `out` - buffer where the resolved path is written +- `outSz` - size of the output buffer + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +## Port Forwarding Functions + + + +All functions in this section require wolfSSH to be built with port forwarding support (`WOLFSSH_FWD`, from `./configure --enable-fwd`). + +### wolfSSH_ChannelFwdNewLocal() + +```c +#include + +WOLFSSH_CHANNEL* wolfSSH_ChannelFwdNewLocal(WOLFSSH* ssh, + const char* host, word32 hostPort, + const char* origin, word32 originPort); +``` + +**Description** + +Sets up a local TCP/IP forwarding channel on the session. Once the session is connected and authenticated, connections are forwarded to `host` on port `hostPort`, tagged with the originating address `origin` and port `originPort`. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `host` - destination host address +- `hostPort` - destination port +- `origin` - originating connection address +- `originPort` - originating connection port + +**Return Values** + +- pointer to the new channel, or `NULL` on error + +**See Also** + +- `wolfSSH_ChannelFwdNewRemote()` + +### wolfSSH_ChannelFwdNewRemote() + +```c +#include + +WOLFSSH_CHANNEL* wolfSSH_ChannelFwdNewRemote(WOLFSSH* ssh, + const char* host, word32 hostPort, + const char* origin, word32 originPort); +``` + +**Description** + +Sets up a remote TCP/IP forwarding channel on the session, requesting that the peer forward connections back to `host` on port `hostPort`. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `host` - destination host address +- `hostPort` - destination port +- `origin` - originating connection address +- `originPort` - originating connection port + +**Return Values** + +- pointer to the new channel, or `NULL` on error + +**See Also** + +- `wolfSSH_ChannelFwdNewLocal()` + +### wolfSSH_CTX_SetFwdCb() + +```c +#include + +int wolfSSH_CTX_SetFwdCb(WOLFSSH_CTX* ctx, + WS_CallbackFwd fwdCb, WS_CallbackFwdIO fwdIoCb); +``` + +**Description** + +Registers the port forwarding setup/cleanup callback (`fwdCb`) on the context. Forwarding channel opens from the peer ("direct-tcpip" and "forwarded-tcpip") are refused when no `fwdCb` is registered. Each `WOLFSSH_FWD_LOCAL_SETUP` the callback receives is later matched by a `WOLFSSH_FWD_LOCAL_CLEANUP`. + +```c +typedef int (*WS_CallbackFwd)(WS_FwdCbAction action, void* fwdCbCtx, + const char* address, word32 port); +``` + +The callback's return value below `WS_FWD_PORT_CHECK` (1024) is a `WS_FwdCbError` status, with `WS_FWD_SUCCESS` meaning success. For a `WOLFSSH_FWD_REMOTE_SETUP` request with port 0, the callback instead returns the unprivileged port (at or above `WS_FWD_PORT_CHECK`) it allocated, which the server reports to the peer. A rejected port-0 setup gets a `WOLFSSH_FWD_REMOTE_CLEANUP` even though the setup returned success. A client answers "tcpip-forward" and "cancel-tcpip-forward" requests with a failure, whatever the callback would do. + +The forwarding I/O callback, `fwdIoCb`, is reserved: it is stored, but nothing in the library calls it, since forwarded data moves through the channel API. The parameter is kept so existing code still compiles; pass NULL. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `fwdCb` - forwarding setup/cleanup callback +- `fwdIoCb` - reserved forwarding I/O callback; unused + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +**See Also** + +- `wolfSSH_SetFwdCbCtx()` + +### wolfSSH_SetFwdCbCtx() + +```c +#include + +int wolfSSH_SetFwdCbCtx(WOLFSSH* ssh, void* ctx); +``` + +**Description** + +Sets the user context pointer passed to the port forwarding callbacks. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context pointer to pass to the forwarding callbacks + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_ChannelFwdNew() + +```c +#include + +WOLFSSH_CHANNEL* wolfSSH_ChannelFwdNew(WOLFSSH* ssh, + const char* host, word32 hostPort, + const char* origin, word32 originPort); +``` + +**Description** + +Deprecated. Use wolfSSH_ChannelFwdNewLocal(); this function is retained for backward compatibility and forwards to it. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `host` - destination host address +- `hostPort` - destination port +- `origin` - originating connection address +- `originPort` - originating connection port + +**Return Values** + +- pointer to the new channel, or `NULL` on error + +**See Also** + +- `wolfSSH_ChannelFwdNewLocal()` + +### wolfSSH_ChannelSetFwdFd() + +```c +#include + +int wolfSSH_ChannelSetFwdFd(WOLFSSH_CHANNEL* channel, int fwdFd); +``` + +**Description** + +Deprecated. Associates a forwarding file descriptor with a forwarding channel. + +**Parameters** + +- `channel` - pointer to the forwarding channel +- `fwdFd` - the forwarding file descriptor + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_ChannelGetFwdFd() + +```c +#include + +int wolfSSH_ChannelGetFwdFd(const WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Deprecated. Returns the forwarding file descriptor associated with a forwarding channel. + +**Parameters** + +- `channel` - pointer to the forwarding channel + +**Return Values** + +- the forwarding file descriptor, or a negative error code + +### wolfSSH_FwdRemoteSetup() + +```c +#include + +int wolfSSH_FwdRemoteSetup(WOLFSSH* ssh, const char* bindAddr, + word32 bindPort, int wantReply); +``` + +**Description** + +Client only. Sends a "tcpip-forward" global request (RFC 4254 section 7.1) asking the server to listen on `bindAddr`:`bindPort` and tunnel the connections it accepts back as "forwarded-tcpip" channels, and registers the forward on the session. A `bindPort` of 0 asks the server to choose the port, and requires `wantReply`, since the reply is the only place the bound port is named. + +A client refuses any "forwarded-tcpip" channel open naming a bind it has not registered (RFC 4254 section 7.2), from the start of the session; a session that registers nothing refuses them all. A `bindAddr` of "", "*", "0.0.0.0", or an IPv6 any-address matches on port alone; any other address must equal the one the server reports in the open. Register the spelling the server will echo back, or a wildcard, or relax the match with wolfSSH_SetFwdRemoteMatch(). + +One `bindAddr`:`bindPort` is one registration however often it is requested, so one cancel undoes it. When several requests name one bind, the last one sent governs. + +`WS_WANT_WRITE` means the request is queued and goes out on the next flush, with the forward registered. So does an error reported after the request reached the peer; retrying then is a harmless repeat. Only an error that kept the request off the wire leaves nothing registered. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `bindAddr` - the address for the server to listen on +- `bindPort` - the port for the server to listen on, or 0 for the server to choose +- `wantReply` - 1 to ask the server for a reply, 0 otherwise + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` or `bindAddr` is NULL, `bindPort` is over 65535, `wantReply` is not 0 or 1, `bindPort` is 0 without `wantReply`, or the session is not a client +- `WS_REKEYING` - a key exchange is in progress +- `WS_RESOURCE_E` - too many requests are awaiting a reply +- `WS_MEMORY_E` +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) +- a send-path status such as `WS_WANT_WRITE` + +**See Also** + +- `wolfSSH_FwdRemoteCancel()` +- `wolfSSH_SetFwdRemoteMatch()` +- `wolfSSH_CTX_SetFwdCb()` + +### wolfSSH_FwdRemoteCancel() + +```c +#include + +int wolfSSH_FwdRemoteCancel(WOLFSSH* ssh, const char* bindAddr, + word32 bindPort, int wantReply); +``` + +**Description** + +Client only. Sends a "cancel-tcpip-forward" global request, tearing down a forward set up with wolfSSH_FwdRemoteSetup(). `bindPort` is the port the server bound, which after a port-0 request is the one it reported, not 0; such a forward cannot be cancelled before that reply arrives. + +The forward stops matching inbound "forwarded-tcpip" opens as soon as the cancel goes out, so an open racing it is refused. Without `wantReply`, that is the end of it. With `wantReply`, the registration is held until the server answers: a refusal leaves the listener up and puts the forward back, and a confirmation drops it. With several cancels outstanding, all of them have to be refused for the forward to come back. Registering again while a cancel is outstanding brings the forward back as the new request goes out. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `bindAddr` - the address the forward was registered with +- `bindPort` - the port the server bound +- `wantReply` - 1 to ask the server for a reply, 0 otherwise + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` or `bindAddr` is NULL, `bindPort` is 0 or over 65535, `wantReply` is not 0 or 1, or the session is not a client +- `WS_REKEYING` - a key exchange is in progress +- `WS_RESOURCE_E` - too many requests are awaiting a reply +- `WS_MEMORY_E` +- `WS_FATAL_ERROR` - the session has disconnected (wolfSSH_get_error() reports `WS_DISCONNECT`) +- a send-path status such as `WS_WANT_WRITE` + +**See Also** + +- `wolfSSH_FwdRemoteSetup()` + +### wolfSSH_SetFwdRemoteMatch() + +```c +#include + +int wolfSSH_SetFwdRemoteMatch(WOLFSSH* ssh, byte match); +``` + +**Description** + +Sets how strictly an inbound "forwarded-tcpip" channel open must match a forward registered with wolfSSH_FwdRemoteSetup(). A client checks these opens from the start of the session, so set this before the peer can send one. + +```c +enum WS_FwdRemoteMatch { + WOLFSSH_FWD_MATCH_STRICT = 0, /* bind and port, the default */ + WOLFSSH_FWD_MATCH_PORT = 1, /* port alone, the bind is not compared */ + WOLFSSH_FWD_MATCH_OFF = 2 /* accept any open, matching nothing */ +}; +``` + +`WOLFSSH_FWD_MATCH_STRICT` is the default and is what RFC 4254 section 7.2 asks for. `WOLFSSH_FWD_MATCH_PORT` is for a peer that rewrites the bind address it echoes back but keeps the port. `WOLFSSH_FWD_MATCH_OFF` accepts any "forwarded-tcpip" open, as wolfSSH did before this check existed, leaving the channel open callback as the only policy check. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `match` - a `WS_FwdRemoteMatch` value + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` is NULL or `match` is not a known setting + +**See Also** + +- `wolfSSH_FwdRemoteSetup()` +- `wolfSSH_CTX_SetChannelOpenCb()` + + +## Key Load Functions + + +### wolfSSH_ReadKey_buffer() + +```c +#include + +int wolfSSH_ReadKey_buffer(const byte* in, word32 inSz, + int format, byte** out, word32* outSz, + const byte** outType, word32* outTypeSz, + void* heap); +``` + +**Description** + +Reads a key from the buffer `in` of size `inSz` and decodes it as a `format` type key. The `format` can be `WOLFSSH_FORMAT_ASN1`, `WOLFSSH_FORMAT_PEM`, `WOLFSSH_FORMAT_SSH`, or `WOLFSSH_FORMAT_OPENSSH`. The decoded key, ready for use by `wolfSSH_CTX_UsePrivateKey_buffer()`, is stored in the buffer pointed to by `out` of size `outSz`. If `out` is NULL, `heap` is used to allocate a buffer for the key. The key type string is stored in `outType`, with its length in `outTypeSz`. + +**Parameters** + +- `in` - buffer containing the encoded key +- `inSz` - size of the input buffer +- `format` - the encoding of the input key +- `out` - output buffer for the decoded key (allocated from `heap` if NULL) +- `outSz` - output for the decoded key size +- `outType` - output for the key type string +- `outTypeSz` - output for the key type string length +- `heap` - heap used for allocation when `out` is NULL + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` +- `WS_BUFFER_E` +- `WS_PARSE_E` +- `WS_UNIMPLEMENTED_E` +- `WS_RSA_E` +- `WS_ECC_E` +- `WS_KEY_AUTH_MAGIC_E` +- `WS_KEY_FORMAT_E` +- `WS_KEY_CHECK_VAL_E` + +**See Also** + +- `wolfSSH_ReadKey_file()` + +### wolfSSH_ReadKey_buffer_ex() + +```c +#include + +int wolfSSH_ReadKey_buffer_ex(const byte* in, word32 inSz, int format, + byte** out, word32* outSz, const byte** outType, word32* outTypeSz, + int isPrivate, void* heap); +``` + +**Description** + +Like wolfSSH_ReadKey_buffer(), but takes an explicit `isPrivate` flag indicating whether the buffer holds a private or public key rather than inferring it. + +**Parameters** + +- `in` - buffer containing the encoded key +- `inSz` - size of the input buffer +- `format` - the encoding of the input key +- `out` - output buffer for the decoded key (allocated from `heap` if NULL) +- `outSz` - output for the decoded key size +- `outType` - output for the key type string +- `outTypeSz` - output for the key type string length +- `isPrivate` - non-zero if the key is a private key, 0 if public +- `heap` - heap used for allocation when `out` is NULL + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` +- `WS_BUFFER_E` +- `WS_PARSE_E` +- `WS_UNIMPLEMENTED_E` + +**See Also** + +- `wolfSSH_ReadKey_buffer()` + +### wolfSSH_ReadPublicKey_buffer() + +```c +#include + +int wolfSSH_ReadPublicKey_buffer(const byte* in, word32 inSz, int format, + byte** out, word32* outSz, const byte** outType, word32* outTypeSz, + void* heap); +``` + +**Description** + +Reads and decodes a public key from the buffer `in`. Behaves like wolfSSH_ReadKey_buffer() but is specialized for public keys. + +**Parameters** + +- `in` - buffer containing the encoded public key +- `inSz` - size of the input buffer +- `format` - the encoding of the input key +- `out` - output buffer for the decoded key (allocated from `heap` if NULL) +- `outSz` - output for the decoded key size +- `outType` - output for the key type string +- `outTypeSz` - output for the key type string length +- `heap` - heap used for allocation when `out` is NULL + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_MEMORY_E` +- `WS_BUFFER_E` +- `WS_PARSE_E` +- `WS_UNIMPLEMENTED_E` + +**See Also** + +- `wolfSSH_ReadKey_buffer()` + + +### wolfSSH_ReadKey_file() + +```c +#include + +int wolfSSH_ReadKey_file(const char* name, + byte** out, word32* outSz, + const byte** outType, word32* outTypeSz, + byte* isPrivate, void* heap); +``` + +**Description** + +Reads the key from the file `name`. The format is guessed from the file contents. The key buffer `out`, the key type `outType`, and their sizes are produced as by wolfSSH_ReadKey_buffer(). The `isPrivate` flag is set to indicate whether the key is private. Any allocations use the specified `heap`. + +**Parameters** + +- `name` - path to the key file +- `out` - output buffer for the decoded key (allocated from `heap` if NULL) +- `outSz` - output for the decoded key size +- `outType` - output for the key type string +- `outTypeSz` - output for the key type string length +- `isPrivate` - output set non-zero if the key is private +- `heap` - heap used for allocation when `out` is NULL + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` +- `WS_BAD_FILE_E` +- `WS_MEMORY_E` +- `WS_BUFFER_E` +- `WS_PARSE_E` +- `WS_UNIMPLEMENTED_E` +- `WS_RSA_E` +- `WS_ECC_E` +- `WS_KEY_AUTH_MAGIC_E` +- `WS_KEY_FORMAT_E` +- `WS_KEY_CHECK_VAL_E` + +**See Also** + +- `wolfSSH_ReadKey_buffer()` + + +### wolfSSH_ReadCert_buffer() + +**Availability** + +Requires `WOLFSSH_CERTS` (X.509 certificates) or `WOLFSSH_OSSH_CERTS` (OpenSSH certificates). + +```c +#include + +int wolfSSH_ReadCert_buffer(const byte* in, word32 inSz, + byte** out, word32* outSz, + const byte** outType, word32* outTypeSz, + byte* flavor, void* heap); +``` + +**Description** + +Decodes a certificate from the buffer `in`, detecting its form from the content: a DER or PEM X.509 certificate (`WOLFSSH_CERTS` builds), or an OpenSSH certificate line (`WOLFSSH_OSSH_CERTS` builds). Of several PEM certificates, only the first is read. On success, `out` receives a newly allocated buffer, from `heap`, holding the DER certificate or the OpenSSH certificate blob, which the caller frees; `outType` receives the SSH algorithm name for the certificate, and `flavor` receives the kind of certificate found: + +```c +enum WS_CertFlavors { + WOLFSSH_CERT_FLAVOR_UNKNOWN, + WOLFSSH_CERT_FLAVOR_X509, + WOLFSSH_CERT_FLAVOR_OSSH +}; +``` + +X.509 certificates are what wolfSSH_CTX_UseCert_buffer() and wolfSSH_CTX_AddRootCert_buffer() consume. On failure, all output parameters are cleared. + +**Parameters** + +- `in` - buffer containing the certificate +- `inSz` - size of the input buffer +- `out` - output for the newly allocated decoded certificate +- `outSz` - output for the decoded certificate size +- `outType` - output for the algorithm name string +- `outTypeSz` - output for the algorithm name string length +- `flavor` - output for the `WS_CertFlavors` value +- `heap` - heap used for the allocation + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `in` or an output pointer is NULL, or `inSz` is 0 +- `WS_BAD_FILETYPE_E` - the content is not a recognized certificate form +- `WS_PARSE_E` - the certificate body does not decode +- `WS_MEMORY_E` +- other errors from identifying the certificate + +**See Also** + +- `wolfSSH_ReadCert_file()` +- `wolfSSH_ReadKey_buffer()` + +### wolfSSH_ReadCert_file() + +**Availability** + +Requires `WOLFSSH_CERTS` or `WOLFSSH_OSSH_CERTS`, and filesystem support (not available with `NO_FILESYSTEM` or `WOLFSSH_USER_FILESYSTEM`). + +```c +#include + +int wolfSSH_ReadCert_file(const char* name, + byte** out, word32* outSz, + const byte** outType, word32* outTypeSz, + byte* flavor, void* heap); +``` + +**Description** + +Reads the file `name` and decodes the certificate in it as wolfSSH_ReadCert_buffer() does. On failure, all output parameters are cleared. + +**Parameters** + +- `name` - path to the certificate file +- `out` - output for the newly allocated decoded certificate +- `outSz` - output for the decoded certificate size +- `outType` - output for the algorithm name string +- `outTypeSz` - output for the algorithm name string length +- `flavor` - output for the `WS_CertFlavors` value +- `heap` - heap used for allocations + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - an output pointer is NULL +- `WS_BAD_FILE_E` - `name` is NULL, or the file cannot be opened or read, is empty, or is larger than `WOLFSSH_MAX_FILE_SIZE` +- `WS_BAD_FILETYPE_E` +- `WS_PARSE_E` +- `WS_MEMORY_E` + +**See Also** + +- `wolfSSH_ReadCert_buffer()` +- `wolfSSH_ReadKey_file()` + +## Key Exchange Algorithm Configuration + +wolfSSH sets up a set of algorithm lists used during the Key Exchange (KEX) +based on the availability of algorithms in the wolfCrypt library used. + +Provided are some accessor functions to see which algorithms are available +to use and to see the algorithm lists used in the KEX. The accessor functions +come in sets of four: set or get from CTX object, and set or get from SSH +object. All SSH objects made with a CTX inherit the CTX's algorithm lists, +and they may be provided their own. + +By default, any algorithms using SHA-1 are disabled but may be re-enabled +using one of the following functions. If SHA-1 is disabled in wolfCrypt, then +SHA-1 cannot be used. + + +### wolfSSH Set Algo Lists + +```c +#include + +int wolfSSH_CTX_SetAlgoListKex(WOLFSSH_CTX* ctx, const char* list); +int wolfSSH_CTX_SetAlgoListKey(WOLFSSH_CTX* ctx, const char* list); +int wolfSSH_CTX_SetAlgoListCipher(WOLFSSH_CTX* ctx, const char* list); +int wolfSSH_CTX_SetAlgoListMac(WOLFSSH_CTX* ctx, const char* list); +int wolfSSH_CTX_SetAlgoListKeyAccepted(WOLFSSH_CTX* ctx, const char* list); + +int wolfSSH_SetAlgoListKex(WOLFSSH* ssh, const char* list); +int wolfSSH_SetAlgoListKey(WOLFSSH* ssh, const char* list); +int wolfSSH_SetAlgoListCipher(WOLFSSH* ssh, const char* list); +int wolfSSH_SetAlgoListMac(WOLFSSH* ssh, const char* list); +int wolfSSH_SetAlgoListKeyAccepted(WOLFSSH* ssh, const char* list); +``` + +**Description** + +These functions act as setters for the various algorithm lists set in the +wolfSSH _ctx_ or _ssh_ objects. The strings are sent to the peer during the +KEX Initialization and are used to compare against when the peer sends its +KEX Initialization message. The KeyAccepted list is used for user +authentication. + +The CTX versions of the functions set the algorithm list for the specified +WOLFSSH_CTX object, _ctx_. They have default values set at compile time. The +specified value is used instead. Note, the library does not copy this string, +it is owned by the application and it is up to the application to free it +when the CTX is deallocated by the application. When creating an SSH object +using a CTX, the SSH object inherits the CTX's strings. The SSH object +algorithm lists may be overridden. + +`Kex` specifies the key exchange algorithm list. `Key` specifies the server +public key algorithm list. `Cipher` specifies the bulk encryption algorithm +list. `Mac` specifies the message authentication code algorithm list. +`KeyAccepted` specifies the public key algorithms allowed for user +authentication. + +The setters validate the list and leave the current list in place when it +is rejected. The `Kex`, `Cipher`, and `Mac` setters reject NULL. The `Key` +setters accept NULL only on a server, where it restores the default of +deriving the host key list from the loaded private keys; a client has no +such fallback. The `KeyAccepted` setters accept NULL on either side, but +that empties the list rather than restoring a default: the server then +advertises an empty RFC 8308 "server-sig-algs", telling clients it accepts +no signature algorithms. + +**Return Values** + +- `WS_SUCCESS` +- `WS_INVALID_ALGO_ID` - the list is not valid +- `WS_SSH_CTX_NULL_E` - `ctx` is NULL +- `WS_SSH_NULL_E` - `ssh` is NULL + + +### wolfSSH Get Algo List + +```c +#include + +const char* wolfSSH_CTX_GetAlgoListKex(WOLFSSH_CTX* ctx); +const char* wolfSSH_CTX_GetAlgoListKey(WOLFSSH_CTX* ctx); +const char* wolfSSH_CTX_GetAlgoListCipher(WOLFSSH_CTX* ctx); +const char* wolfSSH_CTX_GetAlgoListMac(WOLFSSH_CTX* ctx); +const char* wolfSSH_CTX_GetAlgoListKeyAccepted(WOLFSSH_CTX* ctx); + +const char* wolfSSH_GetAlgoListKex(WOLFSSH* ssh); +const char* wolfSSH_GetAlgoListKey(WOLFSSH* ssh); +const char* wolfSSH_GetAlgoListCipher(WOLFSSH* ssh); +const char* wolfSSH_GetAlgoListMac(WOLFSSH* ssh); +const char* wolfSSH_GetAlgoListKeyAccepted(WOLFSSH* ssh); +``` + +**Description** + +These functions act as getters for the various algorithm lists set in the +wolfSSH _ctx_ or _ssh_ objects. + +`Kex` specifies the key exchange algorithm list. `Key` specifies the server +public key algorithm list. `Cipher` specifies the bulk encryption algorithm +list. `Mac` specifies the message authentication code algorithm list. +`KeyAccepted` specifies the public key algorithms allowed for user +authentication. + +**Return Values** + +These functions return a pointer to either the default value set at compile +time or the value set at run time with the setter functions. If the _ctx_ +or `ssh` parameters are NULL the functions return NULL. + + +### wolfSSH_CheckAlgoName() + +```c +#include + +int wolfSSH_CheckAlgoName(const char* name); +``` + +**Description** + +Checks whether the given single algorithm `name` is valid and supported. + +**Parameters** + +- `name` - the algorithm name to check + +**Return Values** + +- `WS_SUCCESS` +- `WS_INVALID_ALGO_ID` + + +### wolfSSH_CTX_SetStrictKex() + +```c +#include + +int wolfSSH_CTX_SetStrictKex(WOLFSSH_CTX* ctx, byte enable); ``` + +**Description** + +Enables or disables offering strict key exchange, the Terrapin (CVE-2023-48795) mitigation, for sessions created from this context. Strict KEX is enabled by default. When both sides offer it, a non-KEX message during the initial key exchange ends the connection, and sequence numbers are reset at each key exchange. wolfSSH_new() copies the context's setting, so a change affects only sessions created afterward. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `enable` - non-zero to offer strict KEX, 0 to opt out + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ctx` is NULL + +**See Also** + +- `wolfSSH_CTX_GetStrictKex()` +- `wolfSSH_GetStrictKexNegotiated()` + +### wolfSSH_CTX_GetStrictKex() + +```c #include -int wolfSSH_ChannelGetId(WOLFSSH_CHANNEL* channel , -word32* id , byte peer ); + +int wolfSSH_CTX_GetStrictKex(WOLFSSH_CTX* ctx); ``` -### wolfSSH_ChannelFind() +**Description** + +Reports whether the context offers strict key exchange. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context + +**Return Values** + +- 1 - strict KEX is offered +- 0 - strict KEX is not offered +- `WS_BAD_ARGUMENT` - `ctx` is NULL + +**See Also** +- `wolfSSH_CTX_SetStrictKex()` -**Synopsis** +### wolfSSH_GetStrictKexNegotiated() + +```c +#include + +int wolfSSH_GetStrictKexNegotiated(WOLFSSH* ssh); +``` **Description** -Given a session _ssh_ , find the channel associated with _id_. +Reports whether the session negotiated strict key exchange, that is, whether both sides offered it. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session **Return Values** -**WOLFSSH_CHANNEL*** – pointer to the channel, NULL if the ID isn’t in the list +- 1 - strict KEX was negotiated +- 0 - strict KEX was not negotiated +- `WS_SSH_NULL_E` - `ssh` is NULL -**Parameters** +**See Also** -**ssh** – wolfSSH session -**id** – channel ID to find -**peer** – either self (my channel ID) or peer (my peer’s channel ID) +- `wolfSSH_CTX_SetStrictKex()` -``` +### wolfSSH Query Algorithms + +```c #include -WOLFSSH_CHANNEL* wolfSSH_ChannelFind(WOLFSSH* ssh , -word32 id , byte peer ); + +const char* wolfSSH_QueryKex(word32* index); +const char* wolfSSH_QueryKey(word32* index); +const char* wolfSSH_QueryCipher(word32* index); +const char* wolfSSH_QueryMac(word32* index); ``` -### wolfSSH_ChannelRead() +**Description** + +Returns the name string for a valid algorithm of the given type (Kex, Key, Cipher, or Mac). Key types are also used for the user-authentication accepted key types. Initialize `index` to 0 and pass the same pointer on each call to iterate; the functions advance it. When the returned value is NULL, the end of the list has been reached. + +**Parameters** + +- `index` - iterator, initialized to 0 and passed on each call + +**Return Values** + +- pointer to an algorithm name string, or `NULL` at the end of the list +### wolfSSH_GetText() + +```c +#include -**Synopsis** +size_t wolfSSH_GetText(WOLFSSH* ssh, WS_Text id, char* str, size_t strSz); +``` **Description** -Copies data out of a channel object. +Writes the text representation of the negotiated item identified by `id` (a `WS_Text` value such as the KEX algorithm, KEX curve, KEX hash, input/output cipher, or input/output MAC) into `str`, writing no more than `strSz` bytes including the terminating null. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `id` - the `WS_Text` item to retrieve +- `str` - output buffer for the text +- `strSz` - size of the output buffer **Return Values** -**int** – bytes read -**>0** – number of bytes read upon success -**0** – returns on socket failure cause by either a clean connection shutdown or a -socket error, call wolfSSH_get_error() for more detail -**WS_FATAL_ERROR** – there was some other error, call wolfSSH_get_error() for -more detail +- the number of characters written (excluding the null terminator); a value of `strSz` or more means the output was truncated -**Parameters** +## Global Request Callbacks -**channel** – pointer to the wolfSSH channel -**buf** – buffer where wolfSSH_ChannelRead will place the data -**bufSz** – size of the buffer +These callbacks handle SSH global request messages and their success/failure replies. -``` +### wolfSSH_SetGlobalReq() + +```c #include -int wolfSSH_ChannelRead(WOLFSSH_CHANNEL* channel , -byte* buf , word32 bufSz ); -``` -### wolfSSH_ChannelSend() +void wolfSSH_SetGlobalReq(WOLFSSH_CTX* ctx, WS_CallbackGlobalReq cb); +``` +**Description** -**Synopsis** +Registers the callback invoked when a global request message is received from the peer. -**Description** +**Parameters** -Sends data to the peer via the specified channel. Data is packaged into a channel data -message. This will send as much data as possible via the peer socket. If there is more -to be sent, calls to _wolfSSH_worker()_ will continue sending more data for the channel to -the peer. +- `ctx` - pointer to the wolfSSH context +- `cb` - the global request callback **Return Values** -**int** – bytes sent -**>0** – number of bytes sent upon success -**0** – returns on socket failure cause by either a clean connection shutdown or a -socket error, call wolfSSH_get_error() for more detail -**WS_FATAL_ERROR** – there was some other error, call wolfSSH_get_error() for -more detail +None -**Parameters** +**See Also** -**channel** – pointer to the wolfSSH channel -**buf** – buffer wolfSSH_ChannelSend() will send -**bufSz** – size of the buffer +- `wolfSSH_SetGlobalReqCtx()` -``` +### wolfSSH_SetGlobalReqCtx() + +```c #include -int* wolfSSH_ChannelSend(WOLFSSH_CHANNEL* channel , -const byte* buf , word32 bufSz ); + +void wolfSSH_SetGlobalReqCtx(WOLFSSH* ssh, void* ctx); ``` -### wolfSSH_ChannelExit() +**Description** + +Sets the user context pointer passed to the global request callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context pointer to pass to the callback + +**Return Values** + +None + +### wolfSSH_GetGlobalReqCtx() +```c +#include -**Synopsis** +void* wolfSSH_GetGlobalReqCtx(WOLFSSH* ssh); +``` **Description** -Terminates a channel, sending the close message to the peer, marks the channel as -closed. This does not free the channel and it remains on the channel list. After closure, -data can not be sent on the channel, but data may still be available to be received. (At -the moment, it sends EOF, close, and deletes the channel.) +Returns the user context pointer previously set with wolfSSH_SetGlobalReqCtx(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session **Return Values** -**int** – error code +- the global request context pointer, or `NULL` if none -**Parameters** +### wolfSSH_CTX_SetGlobalReqAnyCb() -**channel** – wolfSSH session channel +```c +#include +int wolfSSH_CTX_SetGlobalReqAnyCb(WOLFSSH_CTX* ctx, + WS_CallbackGlobalReqAny cb); ``` -#include -int wolfSSH_ChannelExit(WOLFSSH_CHANNEL* channel ); + +**Description** + +Sets a policy callback consulted first for a global request from the peer, ahead of the forwarding callback that answers "tcpip-forward" and "cancel-tcpip-forward" and of the global request callback set with wolfSSH_SetGlobalReq() that answers the rest. + +```c +typedef int (*WS_CallbackGlobalReqAny)(WOLFSSH* ssh, const byte* name, + word32 nameSz, const byte* data, word32 dataSz, int wantReply, + void* ctx); ``` -### wolfSSH_ChannelNext() +`name` is the request name as it arrived, `nameSz` bytes, and `data` is the request's type-specific part, `dataSz` bytes, for the callback to parse; a "tcpip-forward" naming a port can thus be set up from here without a forwarding callback. Neither is NUL terminated, and a name may hold any byte, so match on `nameSz` bytes rather than with the string functions. The callback shares the global request context set with wolfSSH_SetGlobalReqCtx(). +The callback returns a `WS_ReqCbResult` (see the Channel Callbacks section). `WOLFSSH_REQ_UNHANDLED` (0) leaves the request to the other callbacks. `WOLFSSH_REQ_ACCEPT` and `WOLFSSH_REQ_REJECT` settle it, and no other callback is consulted; the reply, when one is wanted, is SSH_MSG_REQUEST_SUCCESS or SSH_MSG_REQUEST_FAILURE. -**Synopsis** +Two kinds of request never reach this callback. A "tcpip-forward" asking for port 0, or one whose body does not parse, is left to the forwarding callback, which can bind and report the port. And a client answers "tcpip-forward" and "cancel-tcpip-forward" with a failure whatever a policy would say. -**Description** +`name` and `data` point into the session's input buffer and are valid only for the length of the call, so a callback keeping either must copy it. The callback must not re-enter the receive side of the library on this session (wolfSSH_worker(), wolfSSH_stream_read(), wolfSSH_accept(), or the SFTP calls). -Returns the next channel after _channel_ in _ssh_ ’s channel list. If _channel_ is NULL, the first -channel from the channel list for _ssh_ is returned. +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the global request policy callback **Return Values** -**WOLFSSH_CHANNEL*** – pointer to either the first channel, next channel, or NULL +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` -**Parameters** +**See Also** -**ssh** – wolfSSH session -**channel** – wolfSSH session channel +- `wolfSSH_SetGlobalReq()` +- `wolfSSH_SetGlobalReqCtx()` +- `wolfSSH_CTX_SetChannelReqAnyCb()` -``` +### wolfSSH_SetReqSuccess() + +```c #include -WOLFSSH_CHANNEL* wolfSSH_ChannelFwdNew(WOLFSSH* ssh , -WOLFSSH_CHANNEL* channel ); + +void wolfSSH_SetReqSuccess(WOLFSSH_CTX* ctx, WS_CallbackReqSuccess cb); ``` +**Description** + +Registers the callback invoked when a request-success reply is received from the peer. -## Key Load Functions +**Parameters** +- `ctx` - pointer to the wolfSSH context +- `cb` - the request-success callback -### wolfSSH_ReadKey_buffer() +**Return Values** -**Synopsis** +None -``` +**See Also** + +- `wolfSSH_SetReqSuccessCtx()` + +### wolfSSH_SetReqSuccessCtx() + +```c #include -int wolfSSH_ReadKey_buffer(const byte* in, word32 inSz, - int format, byte** out, word32* outSz, - const byte** outType, word32* outTypeSz, - void* heap); +void wolfSSH_SetReqSuccessCtx(WOLFSSH* ssh, void* ctx); ``` **Description** -Reads a key file from the buffer _in_ of size _inSz_ and tries to decode it -as a _format_ type key. The _format_ can be **WOLFSSH_FORMAT_ASN1**, -**WOLFSSH_FORMAT_PEM**, **WOLFSSH_FORMAT_SSH**, or **WOLFSSH_FORMAT_OPENSSH**. -The key ready for use by `wolfSSH_UsePrivateKey_buffer()` is stored in the -buffer pointed to by _out_, of size _outSz_. If _out_ is NULL, _heap_ is used -to allocate a buffer for the key. The type string of the key is stored in -_outType_, with its string length in _outTypeSz_. +Sets the user context pointer passed to the request-success callback. -**Return Values** +**Parameters** -* **WS_SUCCESS** - read key is successful -* **WS_BAD_ARGUMENT** - parameter has a bad value -* **WS_MEMORY_E** - failure allocating memory -* **WS_BUFFER_E** - buffer not large enough for indicated size -* **WS_PARSE_E** - problem parsing the key file -* **WS_UNIMPLEMENTED_E** - key type not supported -* **WS_RSA_E** - something wrong with RSA (PKCS1) key -* **WS_ECC_E** - something wrong with ECC (X9.63) key -* **WS_KEY_AUTH_MAGIC_E** - OpenSSH key auth magic value bad -* **WS_KEY_FORMAT_E** - OpenSSH key format incorrect -* **WS_KEY_CHECK_VAL_E** - OpenSSH key check value corrupt +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context pointer to pass to the callback +**Return Values** -### wolfSSH_ReadKey_file() +None -**Synopsis** +### wolfSSH_GetReqSuccessCtx() -``` +```c #include -int wolfSSH_ReadKey_file(const char* name, - byte** out, word32* outSz, - const byte** outType, word32* outTypeSz, - byte* isPrivate, void* heap); +void* wolfSSH_GetReqSuccessCtx(WOLFSSH* ssh); ``` **Description** -Reads the key from the file _name_. The format is guessed based on data in -the file. The key buffer _out_, the key type _outType_, and their sizes -are passed to `wolfSSH_ReadKey_buffer()`. The flag _isPrivate_ is set -as appropriate. Any memory allocations use the specified _heap_. +Returns the user context pointer previously set with wolfSSH_SetReqSuccessCtx(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session **Return Values** -* **WS_SUCCESS** - read key is successful -* **WS_BAD_ARGUMENT** - parameter has a bad value -* **WS_BAD_FILE_E** - problem reading the file -* **WS_MEMORY_E** - failure allocating memory -* **WS_BUFFER_E** - buffer not large enough for indicated size -* **WS_PARSE_E** - problem parsing the key file -* **WS_UNIMPLEMENTED_E** - key type not supported -* **WS_RSA_E** - something wrong with RSA (PKCS1) key -* **WS_ECC_E** - something wrong with ECC (X9.63) key -* **WS_KEY_AUTH_MAGIC_E** - OpenSSH key auth magic value bad -* **WS_KEY_FORMAT_E** - OpenSSH key format incorrect -* **WS_KEY_CHECK_VAL_E** - OpenSSH key check value corrupt +- the request-success context pointer, or `NULL` if none +### wolfSSH_SetReqFailure() -## Key Exchange Algorithm Configuration +```c +#include -wolfSSH sets up a set of algorithm lists used during the Key Exchange (KEX) -based on the availability of algorithms in the wolfCrypt library used. +void wolfSSH_SetReqFailure(WOLFSSH_CTX* ctx, WS_CallbackReqSuccess cb); +``` -Provided are some accessor functions to see which algorithms are available -to use and to see the algorithm lists used in the KEX. The accessor functions -come in sets of four: set or get from CTX object, and set or get from SSH -object. All SSH objects made with a CTX inherit the CTX's algorithm lists, -and they may be provided their own. +**Description** -By default, any algorithms using SHA-1 are disabled but may be re-enabled -using one of the following functions. If SHA-1 is disabled in wolfCrypt, then -SHA-1 cannot be used. +Registers the callback invoked when a request-failure reply is received from the peer. +**Parameters** -### wolfSSH Set Algo Lists +- `ctx` - pointer to the wolfSSH context +- `cb` - the request-failure callback -**Synopsis** +**Return Values** -``` +None + +**See Also** + +- `wolfSSH_SetReqFailureCtx()` + +### wolfSSH_SetReqFailureCtx() + +```c #include -int wolfSSH_CTX_SetAlgoListKex(WOLFSSH_CTX* ctx, const char* list); -int wolfSSH_CTX_SetAlgoListKey(WOLFSSH_CTX* ctx, const char* list); -int wolfSSH_CTX_SetAlgoListCipher(WOLFSSH_CTX* ctx, const char* list); -int wolfSSH_CTX_SetAlgoListMac(WOLFSSH_CTX* ctx, const char* list); -int wolfSSH_CTX_SetAlgoListKeyAccepted(WOLFSSH_CTX* ctx, const char* list); +void wolfSSH_SetReqFailureCtx(WOLFSSH* ssh, void* ctx); +``` -int wolfSSH_SetAlgoListKex(WOLFSSH* ssh, const char* list); -int wolfSSH_SetAlgoListKey(WOLFSSH* ssh, const char* list); -int wolfSSH_SetAlgoListCipher(WOLFSSH* ssh, const char* list); -int wolfSSH_SetAlgoListMac(WOLFSSH* ssh, const char* list); -int wolfSSH_SetAlgoListKeyAccepted(WOLFSSH* ssh, const char* list); +**Description** + +Sets the user context pointer passed to the request-failure callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context pointer to pass to the callback + +**Return Values** + +None + +### wolfSSH_GetReqFailureCtx() + +```c +#include + +void* wolfSSH_GetReqFailureCtx(WOLFSSH* ssh); ``` **Description** -These functions act as setters for the various algorithm lists set in the -wolfSSH _ctx_ or _ssh_ objects. The strings are sent to the peer during the -KEX Initialization and are used to compare against when the peer sends its -KEX Initialization message. The KeyAccepted list is used for user -authentication. +Returns the user context pointer previously set with wolfSSH_SetReqFailureCtx(). -The CTX versions of the functions set the algorithm list for the specified -WOLFSSH_CTX object, _ctx_. They have default values set at compile time. The -specified value is used instead. Note, the library does not copy this string, -it is owned by the application and it is up to the application to free it -when the CTX is deallocated by the application. When creating an SSH object -using a CTX, the SSH object inherits the CTX's strings. The SSH object -algorithm lists may be overridden. +**Parameters** -`Kex` specifies the key exchange algorithm list. `Key` specifies the server -public key algorithm list. `Cipher` specifies the bulk encryption algorithm -list. `Mac` specifies the message authentication code algorithm list. -`KeyAccepted` specifies the public key algorithms allowed for user -authentication. +- `ssh` - pointer to the wolfSSH session **Return Values** -* **WS_SUCCESS** - successful -* **WS_SSH_CTX_NULL_E** - provided CTX was null -* **WS_SSH_NULL_E** - provide SSH was null +- the request-failure context pointer, or `NULL` if none +## TPM 2.0 Integration -### wolfSSH Get Algo List +These functions integrate a wolfTPM 2.0 device and key for host-key operations. They require wolfSSH to be built with `WOLFSSH_TPM` and a wolfTPM installation. -**Synopsis** +### wolfSSH_SetTpmDev() -``` +```c #include -const char* wolfSSH_CTX_GetAlgoListKex(WOLFSSH_CTX* ctx); -const char* wolfSSH_CTX_GetAlgoListKey(WOLFSSH_CTX* ctx); -const char* wolfSSH_CTX_GetAlgoListCipher(WOLFSSH_CTX* ctx); -const char* wolfSSH_CTX_GetAlgoListMac(WOLFSSH_CTX* ctx); -const char* wolfSSH_CTX_GetAlgoListKeyAccepted(WOLFSSH_CTX* ctx); - -const char* wolfSSH_GetAlgoListKex(WOLFSSH* ssh); -const char* wolfSSH_GetAlgoListKey(WOLFSSH* ssh); -const char* wolfSSH_GetAlgoListCipher(WOLFSSH* ssh); -const char* wolfSSH_GetAlgoListMac(WOLFSSH* ssh); -const char* wolfSSH_GetAlgoListKeyAccepted(WOLFSSH* ssh); +void wolfSSH_SetTpmDev(WOLFSSH* ssh, WOLFTPM2_DEV* dev); ``` **Description** -These functions act as getters for the various algorithm lists set in the -wolfSSH _ctx_ or _ssh_ objects. +Associates a wolfTPM 2.0 device with the session for TPM-backed host-key operations. -`Kex` specifies the key exchange algorithm list. `Key` specifies the server -public key algorithm list. `Cipher` specifies the bulk encryption algorithm -list. `Mac` specifies the message authentication code algorithm list. -`KeyAccepted` specifies the public key algorithms allowed for user -authentication. +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `dev` - pointer to the wolfTPM 2.0 device **Return Values** -These functions return a pointer to either the default value set at compile -time or the value set at run time with the setter functions. If the _ctx_ -or `ssh` parameters are NULL the functions return NULL. +None +**See Also** -### wolfSSH_CheckAlgoName +- `wolfSSH_SetTpmKey()` -**Synopsis** +### wolfSSH_SetTpmKey() -``` +```c #include -int wolfSSH_CheckAlgoName(const char* name); +void wolfSSH_SetTpmKey(WOLFSSH* ssh, WOLFTPM2_KEY* key); ``` **Description** -Given a single algorithm _name_ checks to see if it is valid. +Associates a wolfTPM 2.0 key with the session for TPM-backed host-key operations. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `key` - pointer to the wolfTPM 2.0 key **Return Values** -* **WS_SUCCESS** - _name_ is a valid algorithm name -* **WS_INVALID_ALGO_ID** - _name_ is an invalid algorithm name +None +### wolfSSH_GetTpmDev() -### wolfSSH Query Algorithms +```c +#include + +void* wolfSSH_GetTpmDev(WOLFSSH* ssh); +``` + +**Description** + +Returns the wolfTPM 2.0 device previously associated with the session. + +**Parameters** -**Synopsis** +- `ssh` - pointer to the wolfSSH session +**Return Values** + +- pointer to the wolfTPM 2.0 device, or `NULL` if none + +### wolfSSH_GetTpmKey() + +```c +#include + +void* wolfSSH_GetTpmKey(WOLFSSH* ssh); ``` + +**Description** + +Returns the wolfTPM 2.0 key previously associated with the session. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- pointer to the wolfTPM 2.0 key, or `NULL` if none + +### wolfSSH_CTX_UseTpmHostKey() + +```c #include -const char* wolfSSH_QueryKex(word32* index); -const char* wolfSSH_QueryKey(word32* index); -const char* wolfSSH_QueryCipher(word32* index); -const char* wolfSSH_QueryMac(word32* index); +int wolfSSH_CTX_UseTpmHostKey(WOLFSSH_CTX* ctx, + WOLFTPM2_DEV* dev, WOLFTPM2_KEY* key); ``` **Description** -Returns the name string for a valid algorithm of the particular type: Kex, -Key, Cipher, or Mac. Note, Key types are also used for the user authentication -accepted key types. The value passed as _index_ must be initialized to 0, -the passed in on each call to the function. At the end of the list, the -_index_ is invalid. +Configures the context to use the given wolfTPM 2.0 device and key as the server host key. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `dev` - pointer to the wolfTPM 2.0 device +- `key` - pointer to the wolfTPM 2.0 key **Return Values** -Returns a constant string with the name of an algorithm. Null indicates the -end of the list. +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` diff --git a/wolfSSH/src/chapter14.md b/wolfSSH/src/chapter14.md index 7050e5be..4c8f2da7 100644 --- a/wolfSSH/src/chapter14.md +++ b/wolfSSH/src/chapter14.md @@ -1,4 +1,4 @@ -# wolfSSL SFTP API Reference +# wolfSSH SFTP API Reference ## Connection Functions @@ -8,798 +8,578 @@ -**Synopsis:** +```c +#include -**Description:** +int wolfSSH_SFTP_accept(WOLFSSH* ssh); +``` -Function to handle an incoming connection request from a client. +**Description** -**Return Values:** +Handles an incoming SFTP connection request from a client. Called on the server side after the SSH session is established. -Returns WS_SFTP_COMPLETE on success. +When application-driven channels are enabled (wolfSSH_CTX_SetAppChannels() or wolfSSH_SetAppChannels()), this function serves only a session channel on which the application's subsystem callback granted the "sftp" subsystem. The subsystem name must match "sftp" exactly. Called before that grant, it returns `WS_INVALID_STATE_E` without recording an error on the session. -**Parameters:** +**Parameters** -**ssh** - pointer to WOLFSSH structure used for connection +- `ssh` - pointer to the wolfSSH session used for the connection -**Example:** +**Return Values** -``` -#include -int wolfSSH_SFTP_accept(WOLFSSH* ssh ); -``` -``` -WOLFSSH* ssh; -``` -``` -//create new WOLFSSH structure -... -``` -``` -if (wolfSSH_SFTP_accept(ssh) != WS_SUCCESS) { -//handle error case -} -``` +- `WS_SFTP_COMPLETE` on success +- `WS_BAD_ARGUMENT` if `ssh` is `NULL` +- `WS_INVALID_STATE_E` in application-driven channel mode when no sftp subsystem has been granted +- a negative error code on failure -**See Also:** +**See Also** -wolfSSH_SFTP_free() -wolfSSH_new() -wolfSSH_SFTP_connect() +- `wolfSSH_SFTP_connect()` +- `wolfSSH_SFTP_negotiate()` ### wolfSSH_SFTP_connect() -**Synopsis:** - -**Description:** +```c +#include -Function for initiating a connection to a SFTP server. +int wolfSSH_SFTP_connect(WOLFSSH* ssh); +``` -**Return Values:** +**Description** -**WS_SFTP_COMPLETE:** on success. +Initiates an SFTP connection to a server. Called on the client side after the SSH session is established. -**Parameters:** +**Parameters** -**ssh** - pointer to WOLFSSH structure to be used for connection +- `ssh` - pointer to the wolfSSH session used for the connection -**Example:** +**Return Values** -**See Also:** +- `WS_SFTP_COMPLETE` on success +- a negative error code on failure -wolfSSH_SFTP_accept() -wolfSSH_new() -wolfSSH_free() +**See Also** -``` -#include -int wolfSSH_SFTP_connect(WOLFSSH* ssh ); -``` -``` -WOLFSSH* ssh; -``` -``` -//after creating a new WOLFSSH structure -``` -``` -wolfSSH_SFTP_connect(ssh); -``` +- `wolfSSH_SFTP_accept()` +- `wolfSSH_SFTP_negotiate()` ### wolfSSH_SFTP_negotiate() -**Synopsis:** - -**Description:** +```c +#include -Function to handle either an incoming connection from client or to send out a -connection request to a server. It is dependent on which side of the connection the -created WOLFSSH structure is set to for which action is performed. +int wolfSSH_SFTP_negotiate(WOLFSSH* ssh); +``` -**Return Values:** +**Description** -Returns WS_SUCCESS on success. +Performs SFTP protocol negotiation. Depending on which side the session was created for, this either handles an incoming connection from a client or sends a connection request to a server. -**Parameters:** +**Parameters** -**ssh** - pointer to WOLFSSH structure used for connection +- `ssh` - pointer to the wolfSSH session used for the connection -**Example:** +**Return Values** -**See Also:** +- `WS_SUCCESS` on success +- a negative error code on failure -wolfSSH_SFTP_free() +**See Also** -``` -#include -int wolfSSH_SFTP_negotiate(WOLFSSH* ssh) -``` -``` -WOLFSSH* ssh; -``` -``` -//create new WOLFSSH structure with side of connection -set -.... -``` -``` -if (wolfSSH_SFTP_negotiate(ssh) != WS_SUCCESS) { -//handle error case -} -``` +- `wolfSSH_SFTP_accept()` +- `wolfSSH_SFTP_connect()` -wolfSSH_new() -wolfSSH_SFTP_connect() -wolfSSH_SFTP_accept() +### wolfSSH_SFTP_SetDefaultPath() -## Protocol Level Functions +```c +#include +int wolfSSH_SFTP_SetDefaultPath(WOLFSSH* ssh, const char* path); +``` +**Description** -### wolfSSH_SFTP_RealPath() +Sets the start path for the SFTP session: the directory the session begins in and the base against which the server resolves relative request paths. The start path only sets where the session opens; it grants and denies nothing. To restrict which paths a session may reach, use wolfSSH_SFTP_SetConfinePath(), which is independent of this setting. +The path is canonicalized before it is stored. A relative `path` is resolved against the process's current working directory. Calling the function again replaces the previous start path; if the replacement cannot be allocated, the existing start path is left intact. A `NULL` path leaves the current setting unchanged and returns `WS_SUCCESS`. +If no start path is set when the server receives the client's first REALPATH request, the server sets the start path to its current working directory. This does not confine the session. -**Synopsis:** +**Note:** As of wolfSSH v1.6.0 the start path no longer confines the session. In earlier releases, requests that resolved outside the default path were rejected. Applications that relied on that behavior must now also call wolfSSH_SFTP_SetConfinePath(). -**Description:** +**Parameters** -Function to send REALPATH packet to peer. It gets the name of the file returned from -peer. +- `ssh` - pointer to the wolfSSH session +- `path` - NULL-terminated start path, or `NULL` to leave the current setting unchanged -**Return Values:** +**Return Values** -Returns a pointer to a WS_SFTPNAME structure on success and NULL on error. +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` is `NULL` +- `WS_BUFFER_E` - the path, or the working directory it resolves against, does not fit in `WOLFSSH_MAX_FILENAME` +- `WS_INVALID_PATH_E` - the current working directory could not be read, or the path could not be canonicalized +- `WS_FATAL_ERROR` - memory allocation failed (`ssh->error` is set to `WS_MEMORY_E`) -**Parameters:** +**See Also** -**ssh** - pointer to WOLFSSH structure used for connection -**dir** - directory / file name to get real path of +- `wolfSSH_SFTP_SetConfinePath()` -**Example:** +### wolfSSH_SFTP_SetConfinePath() -``` +```c #include -WS_SFTPNAME* wolfSSH_SFTP_RealPath(WOLFSSH* ssh , char* -dir ); + +int wolfSSH_SFTP_SetConfinePath(WOLFSSH* ssh, const char* path); ``` -**See Also:** +**Description** -wolfSSH_SFTP_accept() -wolfSSH_SFTP_connect() +Confines the server side of an SFTP session to the directory tree rooted at `path`. Each request path is resolved against the start path (see wolfSSH_SFTP_SetDefaultPath()) and canonicalized. If the result is not the root itself or a path below it, the request is rejected with `WS_PERMISSIONS`. If no confinement root is set, or the root is "/", the session is unconfined; with a root of "/", only absolute resolved paths are accepted. On Windows the prefix comparison is case-insensitive. -``` -WOLFSSH* ssh ; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -if (wolfSSH_SFTP_read( ssh ) != WS_SUCCESS) { -//handle error case -} -``` +Confinement and the start path are independent. A server can start a session deep inside a jail (for example, start in /srv/data/user7 and confine to /srv/data), confine a session without changing where it opens, or do neither and rely on operating system permissions. wolfSSHd does the last: it sets no confinement root and drops privileges to the authenticated user. Set the start path inside the confinement root; a start path outside the root makes relative requests resolve outside it, and those requests are rejected. -### wolfSSH_SFTP_Close() +The path is canonicalized before it is stored. A relative `path` is resolved against the process's current working directory. Calling the function again replaces the previous root. A `NULL` path leaves the current setting unchanged and returns `WS_SUCCESS`. +Paths are resolved lexically, so a symbolic link inside the jail cannot be proven to stay inside it. On builds with symbolic link support (`WOLFSSH_HAVE_SYMLINK`), a confined session therefore rejects every request whose path has an existing symbolic link component below the root, including links whose targets stay inside the jail. A leaf that does not exist yet is allowed, so create operations still work. Define `WOLFSSH_NO_SYMLINK_CHECK` to remove this check, which also removes its escape protection. The root itself is trusted and is never checked, so a root reached through a symbolic link is as wide as the link's target. Use a root that the server controls and that has no symbolic link components. +The symbolic link check is defense in depth, not a security boundary. It is a time-of-check to time-of-use check: a concurrent writer inside the jail could replace a checked component with a link before the operation runs. For hostile multi-tenant deployments, use an OS-level jail (chroot and dropped privileges). -**Synopsis:** +**Parameters** -**Description:** +- `ssh` - pointer to the wolfSSH session +- `path` - NULL-terminated confinement root, or `NULL` to leave the current setting unchanged -Function to to send a close packet to the peer. +**Return Values** -**Return Values:** +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` - `ssh` is `NULL` +- `WS_BUFFER_E` - the path, or the working directory it resolves against, does not fit in `WOLFSSH_MAX_FILENAME` +- `WS_INVALID_PATH_E` - the current working directory could not be read, or the path could not be canonicalized +- `WS_FATAL_ERROR` - memory allocation failed (`ssh->error` is set to `WS_MEMORY_E`) -**WS_SUCCESS** on success. +**See Also** -**Parameters:** +- `wolfSSH_SFTP_SetDefaultPath()` -**ssh** - pointer to WOLFSSH structure used for connection -**handle** - handle to try and close -**handleSz** - size of handle buffer +## Protocol Level Functions -**Example:** -``` -#include -int wolfSSH_SFTP_Close(WOLFSSH* ssh , byte* handle , word32 -handleSz ); -``` -**See Also:** +### wolfSSH_SFTP_RealPath() -wolfSSH_SFTP_accept() -wolfSSH_SFTP_connect() -``` -WOLFSSH* ssh; -byte handle[HANDLE_SIZE]; -word32 handleSz = HANDLE_SIZE; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -if (wolfSSH_SFTP_Close(ssh, handle, handleSz) != -WS_SUCCESS) { -//handle error case -} + +```c +#include + +WS_SFTPNAME* wolfSSH_SFTP_RealPath(WOLFSSH* ssh, char* dir); ``` -### wolfSSH_SFTP_Open() +**Description** +Sends a REALPATH request to the peer and returns the canonical name of the file or directory. The returned `WS_SFTPNAME` must be freed with wolfSSH_SFTPNAME_free(). +**Parameters** -**Synopsis:** +- `ssh` - pointer to the wolfSSH session +- `dir` - the file or directory name to resolve -**Description:** +**Return Values** -Function to to send an open packet to the peer. This sets handleSz with the size of -resulting buffer and gets the resulting handle from the peer and places it in the buffer -handle. +- pointer to a `WS_SFTPNAME` structure on success +- `NULL` on error -Available reasons for open: -WOLFSSH_FXF_READ -WOLFSSH_FXF_WRITE -WOLFSSH_FXF_APPEND -WOLFSSH_FXF_CREAT -WOLFSSH_FXF_TRUNC -WOLFSSH_FXF_EXCL +**See Also** -**Return Values:** +- `wolfSSH_SFTPNAME_free()` -**WS_SUCCESS** on success. +### wolfSSH_SFTP_Close() -**Parameters:** -**ssh** - pointer to WOLFSSH structure used for connection -**dir** - name of file to open -**reason** - reason for opening the file -**atr** - initial attributes for file -**handle** - resulting handle from open -**handleSz** - gets set to the size of resulting handle -``` +```c #include -int wolfSSH_SFTP_Open(WOLFSSH* ssh , char* dir , word32 -reason , -WS_SFTP_FILEATRB* atr , byte* handle , word32* handleSz ) ; + +int wolfSSH_SFTP_Close(WOLFSSH* ssh, byte* handle, word32 handleSz); ``` -**Example:** +**Description** -**See Also:** +Sends a close request to the peer for the given file handle, which was obtained from a previous call to wolfSSH_SFTP_Open(). -wolfSSH_SFTP_accept() -wolfSSH_SFTP_connect() +**Parameters** -``` -WOLFSSH* ssh ; -char name[NAME_SIZE]; -byte handle[HANDLE_SIZE]; -word32 handleSz = HANDLE_SIZE; -WS_SFTP_FILEATRB atr; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -if (wolfSSH_SFTP_Open( ssh , name , WOLFSSH_FXF_WRITE | -WOLFSSH_FXF_APPEND | WOLFSSH_FXF_CREAT , & atr , handle , -& handleSz ) -!= WS_SUCCESS) { -//handle error case -} -``` - -### wolfSSH_SFTP_SendReadPacket() +- `ssh` - pointer to the wolfSSH session +- `handle` - the file handle to close +- `handleSz` - size of the handle buffer -**Synopsis:** +**Return Values** -**Description:** +- `WS_SUCCESS` +- a negative error code on failure -Function to to send a read packet to the peer. The buffer handle should contain the -result of a previous call to wolfSSH_SFTP_Open. The resulting bytes from a read are -placed into the “out” buffer. +**See Also** -**Return Values:** +- `wolfSSH_SFTP_Open()` -Returns the number of bytes read on success. -A negative value is returned on failure. - -**Parameters:** +### wolfSSH_SFTP_Open() -**ssh** - pointer to WOLFSSH structure used for connection -**handle** - handle to try and read from -**handleSz** - size of handle buffer -**ofst** - offset to start reading from -**out** - buffer to hold result from read -**outSz** - size of out buffer -**Example:** -``` +```c #include -int wolfSSH_SFTP_SendReadPacket(WOLFSSH* ssh , byte* -handle , word32 -handleSz , word64 ofst , byte* out , word32 outSz ); + +int wolfSSH_SFTP_Open(WOLFSSH* ssh, char* dir, word32 reason, + WS_SFTP_FILEATRB* atr, byte* handle, word32* handleSz); ``` -**See Also:** +**Description** -wolfSSH_SFTP_SendWritePacket() -wolfSSH_SFTP_Open() +Sends an open request to the peer for the file named by `dir`. On success the resulting file handle is placed in `handle` and its size is written to `handleSz`. The `reason` argument is a bitmask of the open flags: `WOLFSSH_FXF_READ`, `WOLFSSH_FXF_WRITE`, `WOLFSSH_FXF_APPEND`, `WOLFSSH_FXF_CREAT`, `WOLFSSH_FXF_TRUNC`, or `WOLFSSH_FXF_EXCL`. -``` -WOLFSSH* ssh; -byte handle[HANDLE_SIZE]; -word32 handleSz = HANDLE_SIZE; -byte out[OUT_SIZE]; -word32 outSz = OUT_SIZE; -word32 ofst = 0; -int ret; -``` -``` -//set up ssh and do sftp connections -... -//get handle with wolfSSH_SFTP_Open() -``` -``` -if ((ret = wolfSSH_SFTP_SendReadPacket(ssh, handle, -handleSz, ofst, -out, outSz)) < 0) { -//handle error case -} -//ret holds the number of bytes placed into out buffer -``` +**Parameters** -### wolfSSH_SFTP_SendWritePacket() +- `ssh` - pointer to the wolfSSH session +- `dir` - name of the file to open +- `reason` - bitmask of open flags (see above) +- `atr` - initial file attributes +- `handle` - output buffer for the resulting file handle +- `handleSz` - on input the buffer size, set on output to the handle size +**Return Values** +- `WS_SUCCESS` +- a negative error code on failure -**Synopsis:** +**See Also** -**Description:** +- `wolfSSH_SFTP_Close()` +- `wolfSSH_SFTP_SendReadPacket()` +- `wolfSSH_SFTP_SendWritePacket()` -Function to send a write packet to the peer. -The buffer handle should contain the result of a previous call to -wolfSSH_SFTP_Open(). +### wolfSSH_SFTP_SendReadPacket() -**Return Values:** +```c +#include -Returns the number of bytes written on success. -A negative value is returned on failure. +int wolfSSH_SFTP_SendReadPacket(WOLFSSH* ssh, byte* handle, + word32 handleSz, const word32* ofst, byte* out, word32 outSz); +``` -**Parameters:** +**Description** -**ssh** - pointer to WOLFSSH structure used for connection -**handle** - handle to try and read from -**handleSz** - size of handle buffer -**ofst** - offset to start reading from -**out** - buffer to send to peer for writing -**outSz** - size of out buffer +Sends a read request to the peer for the file referenced by `handle` (obtained from wolfSSH_SFTP_Open()). The bytes read are placed into the `out` buffer. The `ofst` argument points to the file offset to read from. -**Example:** +**Parameters** -``` -#include -int wolfSSH_SFTP_SendWritePacket(WOLFSSH* ssh , byte* -handle , word32 -handleSz , word64 ofst , byte* out , word32 outSz ); -``` +- `ssh` - pointer to the wolfSSH session +- `handle` - the file handle to read from +- `handleSz` - size of the handle buffer +- `ofst` - pointer to the file offset to start reading from +- `out` - buffer to hold the data read +- `outSz` - size of the output buffer -**See Also:** +**Return Values** -wolfSSH_SFTP_SendReadPacket() -wolfSSH_SFTP_Open() +- greater than or equal to 0 - number of bytes read on success +- a negative error code on failure -``` -WOLFSSH* ssh; -byte handle[HANDLE_SIZE]; -word32 handleSz = HANDLE_SIZE; -byte out[OUT_SIZE]; -word32 outSz = OUT_SIZE; -word32 ofst = 0; -int ret; -``` -``` -//set up ssh and do sftp connections -... -//get handle with wolfSSH_SFTP_Open() -``` -``` -if ((ret = wolfSSH_SFTP_SendWritePacket(ssh, handle, -handleSz, ofst, -out,outSz)) < 0) { -//handle error case -} -//ret holds the number of bytes written -``` +**See Also** -### wolfSSH_SFTP_STAT() +- `wolfSSH_SFTP_SendWritePacket()` +- `wolfSSH_SFTP_Open()` +### wolfSSH_SFTP_SendWritePacket() -**Synopsis:** -**Description:** +```c +#include -Function to send a STAT packet to the peer. This will get the attributes of file or -directory. If the file or attribute does not exist the peer will return resulting in this function -returning an error value. +int wolfSSH_SFTP_SendWritePacket(WOLFSSH* ssh, byte* handle, + word32 handleSz, const word32* ofst, byte* out, word32 outSz); +``` -**Return Values:** +**Description** -**WS_SUCCESS** on success. +Sends a write request to the peer for the file referenced by `handle` (obtained from wolfSSH_SFTP_Open()), writing the contents of the `out` buffer. The `ofst` argument points to the file offset to write at. -**Parameters:** +**Parameters** -**ssh** - pointer to WOLFSSH structure used for connection -**dir** - NULL terminated name of file or directory to get attributes of -**atr** - resulting attributes are set into this structure +- `ssh` - pointer to the wolfSSH session +- `handle` - the file handle to write to +- `handleSz` - size of the handle buffer +- `ofst` - pointer to the file offset to start writing at +- `out` - buffer of data to send to the peer +- `outSz` - size of the buffer -**Example:** +**Return Values** -``` -#include -int wolfSSH_SFTP_STAT(WOLFSSH* ssh , char* dir , -WS_SFTP_FILEATRB* atr); -``` +- greater than or equal to 0 - number of bytes written on success +- a negative error code on failure -**See Also:** +**See Also** -wolfSSH_SFTP_LSTAT() -wolfSSH_SFTP_connect() +- `wolfSSH_SFTP_SendReadPacket()` +- `wolfSSH_SFTP_Open()` -``` -WOLFSSH* ssh; -byte name[NAME_SIZE]; -int ret; -WS_SFTP_FILEATRB atr; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -if ((ret = wolfSSH_SFTP_STAT(ssh, name, &atr)) < 0) { -//handle error case -} +### wolfSSH_SFTP_STAT() + + + +```c +#include + +int wolfSSH_SFTP_STAT(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr); ``` -### wolfSSH_SFTP_LSTAT() +**Description** -**Synopsis:** +Sends a STAT request to the peer to retrieve the attributes of a file or directory, following symbolic links. If the target does not exist, the peer returns an error and this function returns an error value. -**Description:** +**Parameters** -Function to send a LSTAT packet to the peer. This will get the attributes of file or -directory. It follows symbolic links where a STAT packet will not follow symbolic links. If -the file or attribute does not exist the peer will return resulting in this function returning -an error value. +- `ssh` - pointer to the wolfSSH session +- `dir` - null-terminated name of the file or directory +- `atr` - structure that receives the resulting attributes -**Return Values:** +**Return Values** -WS_SUCCESS on success. +- `WS_SUCCESS` +- a negative error code on failure -**Parameters:** +**See Also** -**ssh** - pointer to WOLFSSH structure used for connection -**dir** - NULL terminated name of file or directory to get attributes of -**atr** - resulting attributes are set into this structure +- `wolfSSH_SFTP_LSTAT()` +- `wolfSSH_SFTP_SetSTAT()` -Example: +### wolfSSH_SFTP_LSTAT() -``` +```c #include -int wolfSSH_SFTP_LSTAT(WOLFSSH* ssh , char* dir , -WS_SFTP_FILEATRB* atr ); + +int wolfSSH_SFTP_LSTAT(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr); ``` -**See Also:** +**Description** -wolfSSH_SFTP_STAT() -wolfSSH_SFTP_connect() +Sends an LSTAT request to the peer to retrieve the attributes of a file or directory. Unlike wolfSSH_SFTP_STAT(), LSTAT does not follow symbolic links: it returns the attributes of the link itself. If the target does not exist, the peer returns an error and this function returns an error value. -``` -WOLFSSH* ssh; -byte name[NAME_SIZE]; -int ret; -WS_SFTP_FILEATRB atr; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -if ((ret = wolfSSH_SFTP_LSTAT(ssh, name, &atr)) < 0) { -//handle error case -} -``` +**Parameters** -### wolfSSH_SFTPNAME_free() +- `ssh` - pointer to the wolfSSH session +- `dir` - null-terminated name of the file or directory +- `atr` - structure that receives the resulting attributes -**Synopsis:** +**Return Values** -**Description:** +- `WS_SUCCESS` +- a negative error code on failure -Function to free a single WS_SFTPNAME node. Note that if this node is in the middle of a -list of nodes then the list will be broken. +**See Also** -**Return Values:** +- `wolfSSH_SFTP_STAT()` +- `wolfSSH_SFTP_SetSTAT()` -None +### wolfSSH_SFTP_SetSTAT() -**Parameters:** +```c +#include -**name** - structure to be free’d +int wolfSSH_SFTP_SetSTAT(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr); +``` -**Example:** +**Description** -**See Also:** +Sends a SETSTAT request to the peer to apply the attributes in `atr` (for example permissions, size, or timestamps) to the named file or directory. Only the attributes whose flags are set in `atr->flags` are sent. A wolfSSH v1.6.0 or later server applies the attributes or answers `SSH_FX_OP_UNSUPPORTED`; earlier servers always answered `SSH_FX_OK`. -``` -#include -``` -### void wolfSSH_SFTPNAME_free(WS_SFTPNMAE* name ); +**Parameters** -``` -WOLFSSH* ssh; -WS_SFTPNAME* name; -``` -``` -//set up ssh and do sftp connections -... -name = wolfSSH_SFTP_RealPath(ssh, path); -if (name != NULL) { -wolfSSH_SFTPNAME_free(name); -} -``` +- `ssh` - pointer to the wolfSSH session +- `dir` - null-terminated name of the file or directory +- `atr` - the attributes to apply -wolfSSH_SFTPNAME_list_free +**Return Values** -wolfSSH_SFTPNAME_list_free() +- `WS_SUCCESS` +- a negative error code on failure +**See Also** +- `wolfSSH_SFTP_STAT()` -**Synopsis:** +### wolfSSH_SFTPNAME_free() -**Description:** +```c +#include -Function to free a all WS_SFTPNAME nodes in a list. +void wolfSSH_SFTPNAME_free(WS_SFTPNAME* n); +``` -**Return Values:** +**Description** -None +Frees a single `WS_SFTPNAME` node. If the node is in the middle of a list, freeing it breaks the list; use wolfSSH_SFTPNAME_list_free() to free an entire list. -**Parameters:** +**Parameters** -**name** - head of list to be free’d +- `n` - the `WS_SFTPNAME` node to free -**Example:** +**Return Values** -``` -#include -void wolfSSH_SFTPNAME_list_free(WS_SFTPNMAE* name ); -``` +None -**See Also:** +**See Also** -wolfSSH_SFTPNAME_free() +- `wolfSSH_SFTPNAME_list_free()` -``` -WOLFSSH* ssh; -WS_SFTPNAME* name; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -name = wolfSSH_SFTP_LS(ssh, path); -if (name != NULL) { -wolfSSH_SFTPNAME_list_free(name); -} -``` +### wolfSSH_SFTPNAME_list_free() -## Reget / Reput Functions +```c +#include -### wolfSSH_SFTP_SaveOfst() +void wolfSSH_SFTPNAME_list_free(WS_SFTPNAME* n); +``` +**Description** +Frees an entire list of `WS_SFTPNAME` nodes, such as the list returned by wolfSSH_SFTP_LS(). -**Synopsis:** +**Parameters** -**Description:** +- `n` - head of the `WS_SFTPNAME` list to free -Function to save an offset for an interrupted get or put command. The offset can be -recovered by calling wolfSSH_SFTP_GetOfst +**Return Values** -**Return Values:** +None -Returns WS_SUCCESS on success. +**See Also** -**Parameters:** +- `wolfSSH_SFTPNAME_free()` -**ssh** - pointer to WOLFSSH structure for connection -**from** - NULL terminated string of source path -**to** - NULL terminated string with destination path -**ofst** - offset into file to be saved +## Reget / Reput Functions -Example: +### wolfSSH_SFTP_SaveOfst() -``` -#include -int wolfSSH_SFTP_SaveOfst(WOLFSSH* ssh , char* from , char* -to , -word64 ofst ); -``` -**See Also:** -wolfSSH_SFTP_GetOfst() -wolfSSH_SFTP_Interrupt() +```c +#include -``` -WOLFSSH* ssh; -char from[NAME_SZ]; -char to[NAME_SZ]; -word64 ofst; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -if (wolfSSH_SFTP_SaveOfst(ssh, from, to, ofst) != -WS_SUCCESS) { -//handle error case -} +int wolfSSH_SFTP_SaveOfst(WOLFSSH* ssh, char* frm, char* to, + const word32* ofst); ``` -### wolfSSH_SFTP_GetOfst() +**Description** +Saves the transfer offset for an interrupted get or put, keyed by the source (`frm`) and destination (`to`) paths. The saved offset can later be recovered with wolfSSH_SFTP_GetOfst(). Each path must be shorter than `WOLFSSH_MAX_FILENAME` bytes; otherwise `WS_BUFFER_E` is returned. +**Parameters** -**Synopsis:** +- `ssh` - pointer to the wolfSSH session +- `frm` - null-terminated source path +- `to` - null-terminated destination path +- `ofst` - pointer to the offset to save -**Description:** +**Return Values** -Function to retrieve an offset for an interrupted get or put command. +- `WS_SUCCESS` +- a negative error code on failure -**Return Values:** +**See Also** -Returns offset value on success. If not stored offset is found then 0 is returned. +- `wolfSSH_SFTP_GetOfst()` +- `wolfSSH_SFTP_Interrupt()` -**Parameters:** +### wolfSSH_SFTP_GetOfst() -**ssh** - pointer to WOLFSSH structure for connection -**from** - NULL terminated string of source path -**to** - NULL terminated string with destination path -**Example:** -``` +```c #include -word64 wolfSSH_SFTP_GetOfst(WOLFSSH* ssh, char* from, -char* to); -``` -``` -WOLFSSH* ssh; -char from[NAME_SZ]; -char to[NAME_SZ]; -word64 ofst; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -ofst = wolfSSH_SFTP_GetOfst(ssh, from, to); -//start reading/writing from ofst -``` -**See Also:** +int wolfSSH_SFTP_GetOfst(WOLFSSH* ssh, char* frm, char* to, + word32* ofst); +``` -wolfSSH_SFTP_SaveOfst() -wolfSSH_SFTP_Interrup() +**Description** -### wolfSSH_SFTP_ClearOfst() +Retrieves the saved transfer offset for an interrupted get or put, keyed by the source (`frm`) and destination (`to`) paths, writing it to `ofst`. If no saved offset is found, `ofst` is set to 0. +**Parameters** +- `ssh` - pointer to the wolfSSH session +- `frm` - null-terminated source path +- `to` - null-terminated destination path +- `ofst` - output for the saved offset -**Synopsis:** +**Return Values** -**Description:** +- `WS_SUCCESS` +- a negative error code on failure -Function to clear all stored offset values. +**See Also** -**Return Values:** +- `wolfSSH_SFTP_SaveOfst()` +- `wolfSSH_SFTP_Interrupt()` -**WS_SUCCESS** on success - -**Parameters:** +### wolfSSH_SFTP_ClearOfst() -**ssh** - pointer to WOLFSSH structure -**Example:** -``` +```c #include + int wolfSSH_SFTP_ClearOfst(WOLFSSH* ssh); ``` -**See Also:** - -wolfSSH_SFTP_SaveOfst() -wolfSSH_SFTP_GetOfst() - -### wolfSSH_SFTP_Interrupt() +**Description** +Clears all stored transfer offsets for the session. +**Parameters** -**Synopsis:** +- `ssh` - pointer to the wolfSSH session -**Description:** +**Return Values** -Function to set interrupt flag and stop a get/put command. +- `WS_SUCCESS` +- a negative error code on failure -**Return Values:** +**See Also** -None +- `wolfSSH_SFTP_SaveOfst()` +- `wolfSSH_SFTP_GetOfst()` -**Parameters:** +### wolfSSH_SFTP_Interrupt() -**ssh** - pointer to WOLFSSH structure -**Example:** -``` -WOLFSSH* ssh; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -if (wolfSSH_SFTP_ClearOfst(ssh) != WS_SUCCESS) { -//handle error -} -``` -``` +```c #include + void wolfSSH_SFTP_Interrupt(WOLFSSH* ssh); ``` -**See Also:** +**Description** -wolfSSH_SFTP_SaveOfst() -wolfSSH_SFTP_GetOfst() +Sets the interrupt flag on the session to stop an in-progress get or put transfer. The current offset can be saved with wolfSSH_SFTP_SaveOfst() so the transfer can be resumed later. -``` -WOLFSSH* ssh; -char from[NAME_SZ]; -char to[NAME_SZ]; -word64 ofst; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -wolfSSH_SFTP_Interrupt(ssh); -wolfSSH_SFTP_SaveOfst(ssh, from, to, ofst); -``` +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +None + +**See Also** + +- `wolfSSH_SFTP_SaveOfst()` +- `wolfSSH_SFTP_GetOfst()` ## Command Functions @@ -809,380 +589,241 @@ wolfSSH_SFTP_SaveOfst(ssh, from, to, ofst); -**Synopsis:** +```c +#include -**Description:** +int wolfSSH_SFTP_Remove(WOLFSSH* ssh, char* f); +``` -Function for sending a “remove” packet across the channel. -The file name passed in as “f” is sent to the peer for removal. +**Description** -**Return Values:** +Sends a remove request to the peer to delete the file named by `f`. -**WS_SUCCESS** : returns WS_SUCCESS on success. +**Parameters** -**Parameters:** +- `ssh` - pointer to the wolfSSH session +- `f` - null-terminated name of the file to remove -**ssh** - pointer to WOLFSSH structure used for connection -**f** - file name to be removed +**Return Values** -**Example:** +- `WS_SUCCESS` +- a negative error code on failure -``` -#include -int wolfSSH_SFTP_Remove(WOLFSSH* ssh , char* f ); -``` -``` -WOLFSSH* ssh; -int ret; -char* name[NAME_SZ]; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -ret = wolfSSH_SFTP_Remove(ssh, name); -``` - -**See Also:** +**See Also** -wolfSSH_SFTP_accept() -wolfSSH_SFTP_connect() +- `wolfSSH_SFTP_RMDIR()` ### wolfSSH_SFTP_MKDIR() -**Synopsis:** - -**Description:** +```c +#include -Function for sending a “mkdir” packet across the channel. The directory name passed in -as “dir” is sent to the peer for creation. Currently the attributes passed in are not used -and default attributes is set instead. +int wolfSSH_SFTP_MKDIR(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr); +``` -**Return Values:** +**Description** -**WS_SUCCESS** : returns WS_SUCCESS on success. +Sends a mkdir request to the peer to create the directory named by `dir`. The `atr` attributes are currently not used; default attributes are applied instead. -**Parameters:** +**Parameters** -ssh - pointer to WOLFSSH structure used for connection -dir - NULL terminated directory to be created -atr - attributes to be used with directory creation +- `ssh` - pointer to the wolfSSH session +- `dir` - null-terminated name of the directory to create +- `atr` - attributes for the new directory (currently unused) -**Example:** +**Return Values** -``` -#include -int wolfSSH_SFTP_MKDIR(WOLFSSH* ssh , char* dir , -WS_SFTP_FILEATRB* -atr ); -``` +- `WS_SUCCESS` +- a negative error code on failure -**See Also:** +**See Also** -wolfSSH_SFTP_accept() -wolfSSH_SFTP_connect() +- `wolfSSH_SFTP_RMDIR()` ### wolfSSH_SFTP_RMDIR() -**Synopsis:** +```c +#include -**Description:** +int wolfSSH_SFTP_RMDIR(WOLFSSH* ssh, char* dir); +``` -Function for sending a “rmdir” packet across the channel. The directory name passed in -as “dir” is sent to the peer for deletion. +**Description** -**Return Values:** +Sends an rmdir request to the peer to delete the directory named by `dir`. -**WS_SUCCESS** : returns WS_SUCCESS on success. +**Parameters** -**Parameters:** +- `ssh` - pointer to the wolfSSH session +- `dir` - null-terminated name of the directory to remove -**ssh** - pointer to WOLFSSH structure used for connection -**dir** - NULL terminated directory to be remove +**Return Values** -``` -WOLFSSH* ssh; -int ret; -char* dir[DIR_SZ]; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -ret = wolfSSH_SFTP_MKDIR(ssh, dir, DIR_SZ); -``` -``` -#include -int wolfSSH_SFTP_RMDIR(WOLFSSH* ssh , char* dir ); -``` +- `WS_SUCCESS` +- a negative error code on failure -**Example:** +**See Also** -**See Also:** +- `wolfSSH_SFTP_MKDIR()` -wolfSSH_SFTP_accept() -wolfSSH_SFTP_connect() +### wolfSSH_SFTP_Rename() -``` -WOLFSSH* ssh; -int ret; -char* dir[DIR_SZ]; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -ret = wolfSSH_SFTP_RMDIR(ssh, dir); + + +```c +#include + +int wolfSSH_SFTP_Rename(WOLFSSH* ssh, const char* old, const char* nw); ``` -### wolfSSH_SFTP_Rename() +**Description** +Sends a rename request to the peer, renaming the file `old` to `nw`. +**Parameters** -**Synopsis:** +- `ssh` - pointer to the wolfSSH session +- `old` - the current file name +- `nw` - the new file name -**Description:** +**Return Values** -Function for sending a “rename” packet across the channel. This tries to have a peer file -renamed from “old” to “nw”. +- `WS_SUCCESS` +- a negative error code on failure -**Return Values:** +**See Also** -**WS_SUCCESS** : returns WS_SUCCESS on success. +- `wolfSSH_SFTP_Remove()` -**Parameters:** +### wolfSSH_SFTP_LS() -**ssh** - pointer to WOLFSSH structure used for connection -**old** - Old file name -**nw** - New file name -**Example:** -``` +```c #include -int wolfSSH_SFTP_Rename(WOLFSSH* ssh , const char* old , -const char* -nw ); -``` -``` -WOLFSSH* ssh; -int ret; -char* old[NAME_SZ]; -char* nw[NAME_SZ]; //new file name -``` -``` -//set up ssh and do sftp connections -... -``` -``` -ret = wolfSSH_SFTP_Rename(ssh, old, nw); + +WS_SFTPNAME* wolfSSH_SFTP_LS(WOLFSSH* ssh, char* dir); ``` -**See Also:** +**Description** -wolfSSH_SFTP_accept() -wolfSSH_SFTP_connect() +Lists the files and directories in `dir`. This is a high-level helper that performs the REALPATH, OPENDIR, READDIR, and CLOSE operations. The returned list must be freed with wolfSSH_SFTPNAME_list_free(). -### wolfSSH_SFTP_LS() +**Parameters** +- `ssh` - pointer to the wolfSSH session +- `dir` - the directory to list +**Return Values** -**Synopsis:** +- pointer to a list of `WS_SFTPNAME` structures on success +- `NULL` on failure -**Description:** +**See Also** -Function for performing LS operation which gets a list of all files and directories in the -current working directory. This is a high level function that performs REALPATH, -OPENDIR, READDIR, and CLOSE operations. +- `wolfSSH_SFTPNAME_list_free()` +- `wolfSSH_SFTP_RealPath()` -**Return Values:** +### wolfSSH_SFTP_CHMOD() -On Success, returns a pointer to a list of WS_SFTPNAME structures. -NULL on failure. +```c +#include -**Parameters:** +int wolfSSH_SFTP_CHMOD(WOLFSSH* ssh, char* n, char* oct); +``` -**ssh** - pointer to WOLFSSH structure used for connection -**dir** - directory to list +**Description** -**Example:** +Changes the permission bits of the file or directory `n` to the mode given by the octal string `oct` (for example, "644"). Implemented by a STAT request followed by a SETSTAT request that carries only the new permissions (`WOLFSSH_FILEATRB_PERM`); other attributes of the file are not resent. -``` -#include -WS_SFTPNAME* wolfSSH_SFTP_LS(WOLFSSH* ssh , char* dir ); -``` +**Parameters** -**See Also:** +- `ssh` - pointer to the wolfSSH session +- `n` - null-terminated name of the file or directory +- `oct` - octal permission string (for example, "755") -wolfSSH_SFTP_accept() -wolfSSH_SFTP_connect() -wolfSSH_SFTPNAME_list_free() +**Return Values** -``` -WOLFSSH* ssh; -int ret; -char* dir[DIR_SZ]; -WS_SFTPNAME* name; -WS_SFTPNAME* tmp; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -name = wolfSSH_SFTP_LS(ssh, dir); -tmp = name; -while (tmp != NULL) { -printf("%s\n", tmp->fName); -tmp = tmp->next; -} -wolfSSH_SFTPNAME_list_free(name); -``` +- `WS_SUCCESS` +- a negative error code on failure -### wolfSSH_SFTP_Get() +**See Also** +- `wolfSSH_SFTP_SetSTAT()` +### wolfSSH_SFTP_Get() -**Synopsis:** -**Description:** -Function for performing get operation which gets a file from the peer and places it in a -local directory. This is a high level function that performs LSTAT, OPEN, READ, and -CLOSE operations. To interrupt the operation call the function -wolfSSH_SFTP_Interrupt. (See the API documentation of this function for more -information on what it does) +```c +#include -**Return Values:** +int wolfSSH_SFTP_Get(WOLFSSH* ssh, char* from, char* to, + byte resume, WS_STATUS_CB* statusCb); +``` -**WS_SUCCESS** : on success. -All other return values should be considered error cases. +**Description** -**Parameters:** +Downloads a file from the peer to a local path. This is a high-level helper that performs the STAT, OPEN, READ, and CLOSE operations. A transfer in progress can be interrupted with wolfSSH_SFTP_Interrupt(). -**ssh** - pointer to WOLFSSH structure used for connection -**from** - file name to get -**to** - file name to place result at -**resume** - flag to try resume of operation. 1 for yes 0 for no -**statusCb** - callback function to get status +When `resume` is non-zero, the offset saved for the `from` and `to` pair (see wolfSSH_SFTP_SaveOfst()) is used only if the remote file still holds bytes past it and the local file is exactly that many bytes long. Otherwise the transfer starts over from the beginning. -**Example:** +**Parameters** -``` -#include -``` -``` -int wolfSSH_SFTP_Get(WOLFSSH* ssh , char* from , char* to , -byte resume , -WS_STATUS_CB* statusCb ); -``` +- `ssh` - pointer to the wolfSSH session +- `from` - the remote file name to get +- `to` - the local path to write the file to +- `resume` - non-zero to resume a previously interrupted transfer, 0 otherwise +- `statusCb` - callback invoked with transfer progress, or `NULL` -**See Also:** +**Return Values** -wolfSSH_SFTP_accept() -wolfSSH_SFTP_connect() +- `WS_SUCCESS` +- a negative error code on failure -``` -static void myStatusCb(WOLFSSH* sshIn, long bytes, char* -name) -{ -char buf[80]; -WSNPRINTF(buf, sizeof(buf), "Processed %8ld\t bytes -\r", bytes); -WFPUTS(buf, fout); -(void)name; -(void)sshIn; -} -... -WOLFSSH* ssh; -char* from[NAME_SZ]; -char* to[NAME_SZ]; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -if (wolfSSH_SFTP_Get( ssh , from , to , 0 , & myStatusCb ) != -WS_SUCCESS) { -//handle error case -} -``` +**See Also** + +- `wolfSSH_SFTP_Put()` +- `wolfSSH_SFTP_Interrupt()` ### wolfSSH_SFTP_Put() -**Synopsis:** +```c +#include -**Description:** +int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, + byte resume, WS_STATUS_CB* statusCb); +``` -Function for performing put operation which pushes a file local file to a peers directory. -This is a high level function that performs OPEN, WRITE, and CLOSE operations. -To interrupt the operation call the function wolfSSH_SFTP_Interrupt. -(See the API documentation of this function for more information on what it does) +**Description** -**Return Values:** +Uploads a local file to the peer. This is a high-level helper that performs the OPEN, WRITE, and CLOSE operations. A transfer in progress can be interrupted with wolfSSH_SFTP_Interrupt(). -**WS_SUCCESS** on success. -All other return values should be considered error cases. +When `resume` is non-zero and an offset was saved for the `from` and `to` pair, the function first sends a STAT request for the remote file. The saved offset is used only if the local file still holds bytes past it and the remote file is exactly that many bytes long; otherwise the transfer starts over. The remote file is opened with `WOLFSSH_FXF_TRUNC` only when the transfer starts from offset 0, so a resumed put does not truncate the destination. A rejected write ends the transfer with an error rather than reporting success. -**Parameters:** +**Parameters** -**ssh** - pointer to WOLFSSH structure used for connection -**from** - file name to push -**to** - file name to place result at -**resume** - flag to try resume of operation. 1 for yes 0 for no -**statusCb** - callback function to get status +- `ssh` - pointer to the wolfSSH session +- `from` - the local file name to push +- `to` - the remote path to write the file to +- `resume` - non-zero to resume a previously interrupted transfer, 0 otherwise +- `statusCb` - callback invoked with transfer progress, or `NULL` -**Example:** +**Return Values** -``` -#include -int wolfSSH_SFTP_Put(WOLFSSH* ssh , char* from , char* to , -byte resume , WS_STATUS_CB* statusCb ); -``` +- `WS_SUCCESS` +- a negative error code on failure -**See Also:** +**See Also** -wolfSSH_SFTP_accept() -wolfSSH_SFTP_connect() - -``` -static void myStatusCb(WOLFSSH* sshIn, long bytes, char* -name) -{ -char buf[80]; -WSNPRINTF(buf, sizeof(buf), "Processed %8ld\t bytes -\r", bytes); -WFPUTS(buf, fout); -(void)name; -(void)sshIn; -} -... -``` -``` -WOLFSSH* ssh; -char* from[NAME_SZ]; -char* to[NAME_SZ]; -``` -``` -//set up ssh and do sftp connections -... -``` -``` -if (wolfSSH_SFTP_Put(ssh, from, to, 0, &myStatusCb) != -WS_SUCCESS) { -//handle error case -} -``` +- `wolfSSH_SFTP_Get()` +- `wolfSSH_SFTP_Interrupt()` ## SFTP Server Functions @@ -1192,42 +833,52 @@ WS_SUCCESS) { -**Synopsis:** +```c +#include + +int wolfSSH_SFTP_read(WOLFSSH* ssh); +``` + +**Description** -**Description:** +The main server-side SFTP entry point. Reads from the I/O buffer and dispatches to the appropriate internal handler based on the SFTP packet type received. Call this from the server loop to service SFTP requests. -Main SFTP server function that handles incoming packets. This function tries to read -from the I/O buffer and calls internal functions to depending on the SFTP packet type -received. +**Parameters** -**Return Values:** +- `ssh` - pointer to the wolfSSH session -**WS_SUCCESS:** on success. +**Return Values** -**Parameters:** +- `WS_SUCCESS` +- a negative error code on failure -**ssh** - pointer to WOLFSSH structure used for connection +**See Also** -**Example:** +- `wolfSSH_SFTP_accept()` +- `wolfSSH_SFTP_PendingSend()` -``` +### wolfSSH_SFTP_PendingSend() + +```c #include -int wolfSSH_SFTP_read(WOLFSSH* ssh ); + +int wolfSSH_SFTP_PendingSend(WOLFSSH* ssh); ``` -**See Also:** +**Description** -wolfSSH_SFTP_accept() -wolfSSH_SFTP_connect() +Reports whether the SFTP layer has buffered outbound data still waiting to be sent. This is useful when driving non-blocking I/O to know that another send attempt is needed. -``` -WOLFSSH* ssh; -``` -``` -//set up ssh and do sftp connections -... -if (wolfSSH_SFTP_read(ssh) != WS_SUCCESS) { -//handle error case -} -``` +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- non-zero if there is pending data to send +- 0 if there is no pending data + +**See Also** + +- `wolfSSH_SFTP_read()` diff --git a/wolfSSH/src/chapter15.md b/wolfSSH/src/chapter15.md new file mode 100644 index 00000000..bb24fdfe --- /dev/null +++ b/wolfSSH/src/chapter15.md @@ -0,0 +1,376 @@ +# wolfSSH SCP API Reference + +This section describes the public application programming interface for SCP +(Secure Copy) file transfer in wolfSSH. + +All functions in this chapter require wolfSSH to be built with SCP support +(`WOLFSSH_SCP`, from `./configure --enable-scp`). The client-side transfer +functions wolfSSH_SCP_connect(), wolfSSH_SCP_to(), and wolfSSH_SCP_from() are +not available when the client is compiled out (`NO_WOLFSSH_CLIENT`). SCP is +available in a client-only build. + +## SCP Transfer Functions + +### wolfSSH_SCP_connect() + +```c +#include + +int wolfSSH_SCP_connect(WOLFSSH* ssh, byte* cmd); +``` + +**Description** + +Initiates an SCP session over an established SSH connection by sending the SCP +command `cmd` to the server. Called on the client side before transferring +files. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `cmd` - the SCP command to send to the server + +**Return Values** + +- `WS_SUCCESS` +- a negative error code on failure + +**See Also** + +- `wolfSSH_SCP_to()` +- `wolfSSH_SCP_from()` + +### wolfSSH_SCP_to() + +```c +#include + +int wolfSSH_SCP_to(WOLFSSH* ssh, const char* src, const char* dst); +``` + +**Description** + +Sends (uploads) the local file or directory `src` to the remote destination +`dst` over the SSH connection. Called on the client side. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `src` - path to the local source file or directory +- `dst` - destination path on the remote peer + +**Return Values** + +- `WS_SUCCESS` +- a negative error code on failure + +**See Also** + +- `wolfSSH_SCP_from()` +- `wolfSSH_SCP_connect()` + +### wolfSSH_SCP_from() + +```c +#include + +int wolfSSH_SCP_from(WOLFSSH* ssh, const char* src, const char* dst); +``` + +**Description** + +Retrieves (downloads) the remote file or directory `src` from the peer and +writes it to the local destination `dst` over the SSH connection. Called on the +client side. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `src` - path to the source file or directory on the remote peer +- `dst` - destination path on the local system + +**Return Values** + +- `WS_SUCCESS` +- a negative error code on failure + +**See Also** + +- `wolfSSH_SCP_to()` +- `wolfSSH_SCP_connect()` + +### wolfSSH_SCP_accept() + +```c +#include + +int wolfSSH_SCP_accept(WOLFSSH* ssh); +``` + +**Description** + +Server side. Runs an SCP transfer on a session whose channel already carries a +bound "exec scp ..." command. This is the same work wolfSSH_accept() performs +when it returns `WS_SCP_INIT` and is called again. It is exposed so that an +application that binds the `scp` command to a channel itself, such as one using +application-driven channels, can start the transfer. Use either this function or +the wolfSSH_accept() path for a given transfer, not both. + +Call it after wolfSSH_accept() has returned and the exec channel-request +callback has reported an SCP command. Do not call it from inside that callback. +Like wolfSSH_SFTP_accept(), it works on the first channel in the session's +channel list. The SCP receive callback must be set; the default callbacks are +installed on a new context unless `WOLFSSH_SCP_USER_CALLBACKS` is defined. + +On a non-blocking socket the function returns `WS_WANT_READ` or `WS_WANT_WRITE` +with the transfer partly done. Call it again on the same session until it +returns `WS_SCP_COMPLETE`. A pending `WS_WANT_READ` or `WS_WANT_WRITE` recorded +in the session is cleared at the start of each call. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- `WS_SCP_COMPLETE` when the transfer is done +- `WS_WANT_READ` or `WS_WANT_WRITE` when the transfer needs to be resumed +- `WS_BAD_ARGUMENT` if `ssh` is `NULL` or no SCP receive callback is set +- a negative error code on failure + +**See Also** + +- `wolfSSH_ChannelCommandIsScp()` +- `wolfSSH_SetScpRecv()` +- `wolfSSH_SetScpSend()` + +### wolfSSH_ChannelCommandIsScp() + +```c +#include + +int wolfSSH_ChannelCommandIsScp(const WOLFSSH_CHANNEL* channel); +``` + +**Description** + +Reports whether the session command recorded on `channel` starts an SCP +transfer. It is intended for use from an exec channel-request callback, and +wolfSSH_accept() uses the same test, so the application and the library cannot +disagree about what starts a transfer. + +The command must begin with "scp" as a token of its own: either the whole +command is "scp" or "scp" is followed by a space. A plain prefix match such as +"scpbackup" is not an SCP command. The test covers the recorded command size +rather than the string length, and a command containing a NUL byte anywhere +within that size is not treated as an SCP command, because the parser that +serves the transfer reads a C string and would silently drop the rest. + +**Parameters** + +- `channel` - the channel whose session command to test + +**Return Values** + +- 1 if the command starts an SCP transfer +- 0 if it does not, including when the channel has no command +- `WS_BAD_ARGUMENT` if `channel` is `NULL` + +**See Also** + +- `wolfSSH_SCP_accept()` + +### wolfSSH_SetScpErrorMsg() + +```c +#include + +int wolfSSH_SetScpErrorMsg(WOLFSSH* ssh, const char* message); +``` + +**Description** + +Sets a custom error message string on the session, which is reported to the peer +when an SCP transfer fails. Intended to be called from inside the SCP callbacks. +The message is copied, so the caller keeps ownership of `message`. A later call +replaces the previous message. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `message` - null-terminated error message to report + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` if `ssh` or `message` is `NULL` +- `WS_MEMORY_E` if the copy cannot be allocated + +## SCP Callbacks + +When using SCP with application-managed storage (for example, on systems without +a filesystem, or to filter transfers), the application registers send and receive +callbacks. Each callback may be given a user context pointer. + +### wolfSSH_SetScpRecv() + +```c +#include + +void wolfSSH_SetScpRecv(WOLFSSH_CTX* ctx, WS_CallbackScpRecv cb); +``` + +**Description** + +Registers the SCP receive callback on the context. The callback is invoked as +incoming files are received, allowing the application to store the data itself. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the SCP receive callback + +**Return Values** + +None + +**See Also** + +- `wolfSSH_SetScpRecvCtx()` +- `wolfSSH_SetScpSend()` + +### wolfSSH_SetScpSend() + +```c +#include + +void wolfSSH_SetScpSend(WOLFSSH_CTX* ctx, WS_CallbackScpSend cb); +``` + +**Description** + +Registers the SCP send callback on the context. The callback is invoked when the +peer requests files, allowing the application to supply the data itself. + +The callback returns the number of bytes it placed in `buf`, one of the `WS_SCP_*` +status codes, or a negative error to abort the transfer. Its `fileNameSz` +argument is the capacity of the `fileName` buffer, not the length of a name +already in it. Returning 0 is valid only on the call that fills in the file +metadata (name, mode, times, and `totalFileSz`) before any data is ready; the +library then sends the file header and calls back with +`WOLFSSH_SCP_CONTINUE_FILE_TRANSFER`. A second 0 in a row while `fileOffset` is +still short of `totalFileSz` is treated as a stalled callback and aborts the +transfer, because the API has no "no data right now" status. A callback that +must wait for data should block rather than return 0. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cb` - the SCP send callback + +**Return Values** + +None + +**See Also** + +- `wolfSSH_SetScpSendCtx()` +- `wolfSSH_SetScpRecv()` + +### wolfSSH_SetScpRecvCtx() + +```c +#include + +void wolfSSH_SetScpRecvCtx(WOLFSSH* ssh, void* ctx); +``` + +**Description** + +Sets the user context pointer passed to the SCP receive callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context pointer to pass to the receive callback + +**Return Values** + +None + +**See Also** + +- `wolfSSH_GetScpRecvCtx()` + +### wolfSSH_SetScpSendCtx() + +```c +#include + +void wolfSSH_SetScpSendCtx(WOLFSSH* ssh, void* ctx); +``` + +**Description** + +Sets the user context pointer passed to the SCP send callback. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context pointer to pass to the send callback + +**Return Values** + +None + +**See Also** + +- `wolfSSH_GetScpSendCtx()` + +### wolfSSH_GetScpRecvCtx() + +```c +#include + +void* wolfSSH_GetScpRecvCtx(WOLFSSH* ssh); +``` + +**Description** + +Returns the user context pointer previously set with wolfSSH_SetScpRecvCtx(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- the SCP receive context pointer, or `NULL` if none + +**See Also** + +- `wolfSSH_SetScpRecvCtx()` + +### wolfSSH_GetScpSendCtx() + +```c +#include + +void* wolfSSH_GetScpSendCtx(WOLFSSH* ssh); +``` + +**Description** + +Returns the user context pointer previously set with wolfSSH_SetScpSendCtx(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- the SCP send context pointer, or `NULL` if none + +**See Also** + +- `wolfSSH_SetScpSendCtx()` diff --git a/wolfSSH/src/chapter16.md b/wolfSSH/src/chapter16.md new file mode 100644 index 00000000..6d328eb8 --- /dev/null +++ b/wolfSSH/src/chapter16.md @@ -0,0 +1,1165 @@ +# wolfSSH Additional API Reference + +This chapter documents the remaining public wolfSSH interfaces: ssh-agent +forwarding, key generation, logging, the certificate manager (including the +Windows certificate store helpers), and the platform portability layer. + +## SSH Agent Functions + +These functions support ssh-agent forwarding. They require wolfSSH to be built +with agent support (`WOLFSSH_AGENT`, from `./configure --enable-agent`). + +### wolfSSH_AGENT_new() + +```c +#include + +WOLFSSH_AGENT_CTX* wolfSSH_AGENT_new(void* heap); +``` + +**Description** + +Allocates and initializes a new ssh-agent context, including its random number +generator. + +**Parameters** + +- `heap` - pointer to a heap to use for memory allocations, or `NULL` + +**Return Values** + +- pointer to the new agent context, or `NULL` if the allocation or the random + number generator initialization fails + +**See Also** + +- `wolfSSH_AGENT_free()` + +### wolfSSH_AGENT_free() + +```c +#include + +void wolfSSH_AGENT_free(WOLFSSH_AGENT_CTX* agent); +``` + +**Description** + +Frees an ssh-agent context previously allocated with wolfSSH_AGENT_new(). + +**Parameters** + +- `agent` - the agent context to free + +**Return Values** + +None + +**See Also** + +- `wolfSSH_AGENT_new()` + +### wolfSSH_CTX_set_agent_cb() + +```c +#include + +int wolfSSH_CTX_set_agent_cb(WOLFSSH_CTX* ctx, + WS_CallbackAgent agentCb, WS_CallbackAgentIO agentIoCb); +``` + +**Description** + +Registers the agent callback and the agent I/O callback on the context. These +callbacks let the application service agent requests and perform agent I/O. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `agentCb` - the agent callback +- `agentIoCb` - the agent I/O callback + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +**See Also** + +- `wolfSSH_set_agent_cb_ctx()` + +### wolfSSH_set_agent_cb_ctx() + +```c +#include + +int wolfSSH_set_agent_cb_ctx(WOLFSSH* ssh, void* ctx); +``` + +**Description** + +Sets the user context pointer passed to the agent callbacks. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `ctx` - user context pointer to pass to the agent callbacks + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` + +### wolfSSH_CTX_AGENT_enable() + +```c +#include + +int wolfSSH_CTX_AGENT_enable(WOLFSSH_CTX* ctx, byte isEnabled); +``` + +**Description** + +Enables or disables ssh-agent forwarding for sessions created from the context. +Each session copies the setting when it is created. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `isEnabled` - non-zero to enable agent forwarding, 0 to disable + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_CTX_NULL_E` if `ctx` is `NULL` + +**See Also** + +- `wolfSSH_AGENT_enable()` + +### wolfSSH_AGENT_enable() + +```c +#include + +int wolfSSH_AGENT_enable(WOLFSSH* ssh, byte isEnabled); +``` + +**Description** + +Enables or disables ssh-agent forwarding for a single session. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `isEnabled` - non-zero to enable agent forwarding, 0 to disable + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` if `ssh` is `NULL` + +**See Also** + +- `wolfSSH_CTX_AGENT_enable()` + +### wolfSSH_AGENT_ChannelOpen() + +```c +#include + +int wolfSSH_AGENT_ChannelOpen(WOLFSSH* ssh); +``` + +**Description** + +Server side. Opens the "auth-agent@openssh.com" channel to the client after the +client's "auth-agent-req@openssh.com" channel request has asked for agent +forwarding. The server accepts that request only when an agent callback is set +with wolfSSH_CTX_set_agent_cb(). On the default path wolfSSH_accept() opens the +channel itself. An application that drives its own channels (see +wolfSSH_CTX_SetAppChannels()) polls this function instead. + +The function opens at most one channel per session; once the channel has been +opened, later calls only flush any output still queued. On success it invokes the +agent callback with `WOLFSSH_AGENT_LOCAL_SETUP`. `WS_SUCCESS` means the open +request was sent, not that the peer accepted it; a refusal is reported to the +channel-open-fail callback. If an error is raised after the open is on the wire +(for example, by a failing high-water callback), the channel stays open and the +next call returns `WS_SUCCESS`. + +Only the send path records its result in `ssh->error`. A call made before the +peer has asked for forwarding returns `WS_BAD_ARGUMENT` without recording an +error, so the session can still be passed to wolfSSH_accept(). + +**Parameters** + +- `ssh` - pointer to the wolfSSH session + +**Return Values** + +- `WS_SUCCESS` when the channel open has been sent +- `WS_WANT_READ` or `WS_WANT_WRITE` while output is still queued; call again +- `WS_BAD_ARGUMENT` on a client session, or before the peer has asked for agent + forwarding +- `WS_FATAL_ERROR` once the session has been disconnected (`ssh->error` holds + `WS_DISCONNECT`) +- `WS_SSH_NULL_E` if `ssh` is `NULL` +- `WS_MEMORY_E` if the agent context or channel cannot be allocated +- another negative error code reported by the send + +**See Also** + +- `wolfSSH_AGENT_RelayChannel()` +- `wolfSSH_CTX_set_agent_cb()` + +### wolfSSH_AGENT_Relay() + +```c +#include + +int wolfSSH_AGENT_Relay(WOLFSSH* ssh, + const byte* msg, word32* msgSz, byte* rsp, word32* rspSz); +``` + +**Description** + +Relays one agent protocol message to the local agent and returns the agent's +response. The message in `msg` is written to the agent through the agent I/O +callback exactly as given, so it must be a complete agent message, including its +4-byte length prefix. If nothing could be written, the function calls the agent +callback with `WOLFSSH_AGENT_LOCAL_SETUP` to reconnect and tries once more. The +function then reads one whole agent reply, including its 4-byte length prefix, +and copies it to `rsp`. On input `rspSz` holds the size of the `rsp` buffer; on +output it holds the size of the response written. A reply declaring a length of +0 or more than `WOLFSSH_AGENT_MAX_MSG_SZ` (262144 bytes by default) is rejected. + +The session must have an agent context; on the client side, wolfSSH_connect() +creates one when agent forwarding is enabled. For an agent channel whose data arrives in +pieces, use wolfSSH_AGENT_RelayChannel() instead. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `msg` - the agent message to relay +- `msgSz` - pointer to the size of the message +- `rsp` - buffer that receives the agent's response +- `rspSz` - on input the response buffer size, set on output to the response size + +**Return Values** + +- `WS_SUCCESS` +- `WS_ERROR` on any failure. When `ssh` is not `NULL`, the specific error is + stored in the session and can be retrieved with wolfSSH_get_error(). Possible + errors include `WS_AGENT_NULL_E` (no agent context), `WS_BAD_ARGUMENT`, + `WS_AGENT_CXN_FAIL` (agent I/O failed), and `WS_BUFFER_E` (the reply is out of + range or does not fit in `rsp`). + +**See Also** + +- `wolfSSH_AGENT_RelayChannel()` + +### wolfSSH_AGENT_RelayChannel() + +```c +#include + +int wolfSSH_AGENT_RelayChannel(WOLFSSH* ssh, word32 channelId); +``` + +**Description** + +Moves whole agent messages between the forwarded agent channel `channelId` and +the local agent. Each call reads whatever channel data is already buffered, +frames it into complete agent messages, writes each message to the agent through +the agent I/O callback, and sends each reply back on the channel. A partial +request or an unfinished reply is held between calls, so the same `channelId` +must be passed again to finish either. If a different `channelId` is passed, +bytes held for the previous channel are discarded. If the agent context is still +in its initial state, the function first invokes the agent callback with +`WOLFSSH_AGENT_LOCAL_SETUP`. + +A typical client calls this function when a read reports `WS_CHAN_RXD` for the +agent channel (the channel ID is available from wolfSSH_GetLastRxId()), and +calls it again whenever a reply is still owed. + +While a reply is owed, the return value names what is holding it: +`WS_WANT_WRITE` means the transport, and `WS_WINDOW_FULL` or `WS_REKEYING` means +the peer. Call the function again until it returns `WS_SUCCESS`. Any other +non-success code leaves the channel unusable. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `channelId` - the local ID of the agent channel + +**Return Values** + +- `WS_SUCCESS` when all buffered requests have been relayed and their replies sent +- `WS_WANT_WRITE`, `WS_WINDOW_FULL`, or `WS_REKEYING` while a reply is still + owed; call again +- `WS_SSH_NULL_E` if `ssh` is `NULL` +- `WS_AGENT_NULL_E` if the session has no agent context +- `WS_AGENT_CXN_FAIL` if the agent connection or agent I/O fails +- `WS_BUFFER_E` if a message declares a length of 0 or more than + `WOLFSSH_AGENT_MAX_MSG_SZ` +- `WS_INVALID_CHANID` if no channel has the given ID +- another negative error code on failure + +**See Also** + +- `wolfSSH_AGENT_Relay()` +- `wolfSSH_AGENT_ChannelOpen()` + +### wolfSSH_AGENT_SignRequest() + +```c +#include + +int wolfSSH_AGENT_SignRequest(WOLFSSH* ssh, + const byte* digest, word32 digestSz, + byte* sig, word32* sigSz, + const byte* keyBlob, word32 keyBlobSz, word32 flags); +``` + +**Description** + +Requests that the agent sign the given `digest` using the key identified by +`keyBlob`. The resulting signature is written to `sig`. The function invokes the +agent callback with `WOLFSSH_AGENT_LOCAL_SETUP` before the request and with +`WOLFSSH_AGENT_LOCAL_CLEANUP` afterward, and uses the agent I/O callback to +exchange the request and the reply. On failure `*sigSz` is set to 0. + +**Parameters** + +- `ssh` - pointer to the wolfSSH session +- `digest` - the digest to sign +- `digestSz` - size of the digest +- `sig` - buffer that receives the signature +- `sigSz` - on input the signature buffer size, set on output to the signature size +- `keyBlob` - the public key blob identifying which key to sign with +- `keyBlobSz` - size of the key blob +- `flags` - signature request flags + +**Return Values** + +- `WS_SUCCESS` +- `WS_SSH_NULL_E` if `ssh` is `NULL` +- `WS_AGENT_NULL_E` if the session has no agent context +- `WS_BAD_ARGUMENT` if `sigSz` is `NULL` +- `WS_MEMORY_E` if the reply buffer cannot be allocated +- `WS_AGENT_CXN_FAIL` if the request could not be written to the agent +- `WS_AGENT_NO_KEY_E` if the agent returns no reply, a reply that is not a + signature, or a failure +- `WS_BUFFER_E` if the signature does not fit in `sig` +- another negative error code on failure + +## Key Generation Functions + +These functions generate SSH key pairs. They require wolfSSH to be built with +key generation support (`WOLFSSH_KEYGEN`, from `./configure --enable-keygen`), +and wolfSSL must be built with key generation (`WOLFSSL_KEY_GEN`). The +corresponding algorithm must also be enabled; if it is not, the function returns +`WS_NOT_COMPILED`. A failure inside wolfCrypt is reported as `WS_CRYPTO_FAILED`. + +The ML-DSA functions require wolfSSL 5.9.2 or later built with ML-DSA support. + +### wolfSSH_MakeRsaKey() + +```c +#include + +int wolfSSH_MakeRsaKey(byte* out, word32 outSz, word32 size, word32 e); +``` + +**Description** + +Generates an RSA key pair of `size` bits using public exponent `e`, writing the +DER-encoded private key to `out`. + +**Parameters** + +- `out` - buffer that receives the generated key +- `outSz` - size of the output buffer +- `size` - RSA key size in bits (for example, 2048) +- `e` - RSA public exponent (for example, 65537) + +**Return Values** + +- the number of bytes written on success +- `WS_NOT_COMPILED` if RSA is disabled +- `WS_CRYPTO_FAILED` on a key generation or encoding failure + +**See Also** + +- `wolfSSH_MakeEcdsaKey()` + +### wolfSSH_MakeEcdsaKey() + +```c +#include + +int wolfSSH_MakeEcdsaKey(byte* out, word32 outSz, word32 size); +``` + +**Description** + +Generates an ECDSA key pair for the curve of the given `size` in bits (for +example, 256 for NIST P-256), writing the DER-encoded private key to `out`. + +**Parameters** + +- `out` - buffer that receives the generated key +- `outSz` - size of the output buffer +- `size` - ECC curve size in bits (for example, 256, 384, or 521) + +**Return Values** + +- the number of bytes written on success +- `WS_NOT_COMPILED` if ECDSA is disabled +- `WS_CRYPTO_FAILED` on a key generation or encoding failure + +**See Also** + +- `wolfSSH_MakeRsaKey()` +- `wolfSSH_MakeEd25519Key()` + +### wolfSSH_MakeEd25519Key() + +```c +#include + +int wolfSSH_MakeEd25519Key(byte* out, word32 outSz, word32 size); +``` + +**Description** + +Generates an Ed25519 key pair, writing the DER-encoded private key to `out`. + +**Parameters** + +- `out` - buffer that receives the generated key +- `outSz` - size of the output buffer +- `size` - key size in bits (256 for Ed25519) + +**Return Values** + +- the number of bytes written on success +- `WS_NOT_COMPILED` if Ed25519 key generation is not available +- `WS_CRYPTO_FAILED` on a key generation or encoding failure + +**See Also** + +- `wolfSSH_MakeEcdsaKey()` + +### wolfSSH_MakeMlDsaKey() + +```c +#include + +int wolfSSH_MakeMlDsaKey(byte* out, word32 outSz, word32 level); +``` + +**Description** + +Generates an ML-DSA (FIPS 204) key pair at the given security level, writing the +DER-encoded private key to `out`. + +**Parameters** + +- `out` - buffer that receives the generated key +- `outSz` - size of the output buffer +- `level` - ML-DSA parameter set: `WOLFSSH_MLDSAKEY_44`, `WOLFSSH_MLDSAKEY_65`, + or `WOLFSSH_MLDSAKEY_87` + +**Return Values** + +- the number of bytes written on success +- `WS_BAD_ARGUMENT` if `level` is not one of the values above +- `WS_NOT_COMPILED` if ML-DSA is not available +- `WS_MEMORY_E` if a small-stack allocation fails +- `WS_CRYPTO_FAILED` on a key generation or encoding failure + +**See Also** + +- `wolfSSH_MakeMlDsaCompositeKey()` + +### wolfSSH_MakeMlDsaCompositeKey() + +```c +#include + +int wolfSSH_MakeMlDsaCompositeKey(byte* out, word32 outSz, + word32 level, word32 tradType); +``` + +**Description** + +Generates a composite key pair that pairs an ML-DSA key with a traditional +signature key. The result is written to `out` as a NUL-terminated, unencrypted +OpenSSH private key in PEM form ("-----BEGIN OPENSSH PRIVATE KEY-----"), with an +empty comment. The ML-DSA half is stored as its seed. + +Only these combinations of `level` and `tradType` are accepted: + +- `WOLFSSH_MLDSAKEY_44` with `WOLFSSH_COMPOSITE_TRAD_ED25519` or + `WOLFSSH_COMPOSITE_TRAD_ECDSA` (NIST P-256) +- `WOLFSSH_MLDSAKEY_65` with `WOLFSSH_COMPOSITE_TRAD_ED25519` or + `WOLFSSH_COMPOSITE_TRAD_ECDSA` (NIST P-256) +- `WOLFSSH_MLDSAKEY_87` with `WOLFSSH_COMPOSITE_TRAD_ED448` or + `WOLFSSH_COMPOSITE_TRAD_ECDSA` (NIST P-384) + +Pass `NULL` for `out` to query the required buffer size. + +**Parameters** + +- `out` - buffer that receives the PEM-encoded key, or `NULL` to query the size +- `outSz` - size of the output buffer +- `level` - ML-DSA parameter set: `WOLFSSH_MLDSAKEY_44`, `WOLFSSH_MLDSAKEY_65`, + or `WOLFSSH_MLDSAKEY_87` +- `tradType` - traditional algorithm: `WOLFSSH_COMPOSITE_TRAD_ECDSA`, + `WOLFSSH_COMPOSITE_TRAD_ED25519`, or `WOLFSSH_COMPOSITE_TRAD_ED448` + +**Return Values** + +- on success, the number of bytes written, including the terminating NUL +- when `out` is `NULL`, the required buffer size, including the terminating NUL +- `WS_BAD_ARGUMENT` if the `level` and `tradType` combination is not supported +- `WS_NOT_COMPILED` if ML-DSA or the requested composite algorithm is not + compiled in +- `WS_BUFFER_E` if `outSz` is too small +- `WS_MEMORY_E` if an allocation fails +- `WS_CRYPTO_FAILED` on a key generation or encoding failure + +**See Also** + +- `wolfSSH_MakeMlDsaKey()` + +## Logging Functions + +These functions control wolfSSH debug logging. The logging code is compiled in +when wolfSSH is built with `DEBUG_WOLFSSH` (from `./configure --enable-debug`) +or with `WOLFSSH_SSHD`. + +### wolfSSH_SetLoggingCb() + +```c +#include + +void wolfSSH_SetLoggingCb(wolfSSH_LoggingCb logF); +``` + +**Description** + +Registers a callback that receives log messages, each with its log level and +message text, instead of the default logging output. Passing `NULL` leaves the +current callback in place. Builds with `WOLFSSH_NO_DEFAULT_LOGGING_CB` have no +default callback, so nothing is output until one is registered. + +**Parameters** + +- `logF` - the logging callback + +**Return Values** + +None + +**See Also** + +- `wolfSSH_LogEnabled()` + +### wolfSSH_LogEnabled() + +```c +#include + +int wolfSSH_LogEnabled(void); +``` + +**Description** + +Reports whether logging is currently enabled. Logging is off by default and is +turned on with wolfSSH_Debugging_ON(). Builds without logging support always +return 0. + +**Parameters** + +None + +**Return Values** + +- non-zero if logging is enabled +- 0 if logging is disabled + +### wolfSSH_Log() + +```c +#include + +void wolfSSH_Log(enum wolfSSH_LogLevel level, const char* const fmt, ...); +``` + +**Description** + +Writes a printf-style formatted log message at the given level. The log levels, +from lowest to highest, are `WS_LOG_DEBUG`, `WS_LOG_INFO`, `WS_LOG_WARN`, +`WS_LOG_ERROR`, and `WS_LOG_USER`, plus the per-subsystem levels `WS_LOG_SFTP`, +`WS_LOG_SCP`, `WS_LOG_AGENT`, and `WS_LOG_CERTMAN`. + +The formatted message is truncated to `WOLFSSH_DEFAULT_LOG_WIDTH` bytes (120 by +default, including the terminating NUL). Before the message is passed to the +logging callback, control characters other than tab, and DEL, are replaced with +`?`, so untrusted strings logged with `%s` cannot inject newlines or terminal +escape sequences into the log. + +**Parameters** + +- `level` - the `wolfSSH_LogLevel` for the message +- `fmt` - printf-style format string +- `...` - arguments for the format string + +**Return Values** + +None + +**See Also** + +- `wolfSSH_SetLoggingCb()` + +## Certificate Manager Functions + +The certificate manager verifies X.509 certificates for certificate-based +authentication. These functions require wolfSSH to be built with certificate +support (`WOLFSSH_CERTS`, from `./configure --enable-certs`). + +### wolfSSH_SetCertManager() + +```c +#include + +int wolfSSH_SetCertManager(WOLFSSH_CTX* ctx, struct WOLFSSL_CERT_MANAGER* cm); +``` + +**Description** + +Replaces the wolfSSL certificate manager used by the context with `cm`. The +function takes a reference on `cm` and frees its reference to the previous +manager. The caller keeps its own reference and remains responsible for freeing +it. + +wolfSSH modifies the shared manager. In builds with OCSP support (`HAVE_OCSP`) +it enables `WOLFSSL_OCSP_CHECKALL` on `cm`, so a caller that also uses the +manager for TLS finds that every chain requires an OCSP response. During +certificate authentication, wolfSSH permanently adds verified peer intermediate +CAs to the manager as trusted roots. Use a manager dedicated to wolfSSH rather +than one shared with a live TLS stack. + +Passing the manager that is already in use applies the OCSP policy again and +changes nothing else. On `WS_FATAL_ERROR` nothing has changed: the context keeps +its previous manager and no policy has been applied to `cm`. + +**Availability** + +Requires wolfSSH built with certificate support (`WOLFSSH_CERTS`). Requires +wolfSSL 4.6.0 or later; with older versions the function returns +`WS_NOT_COMPILED` for any arguments. + +**Parameters** + +- `ctx` - pointer to the wolfSSH context +- `cm` - the wolfSSL certificate manager to use + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` if `ctx` or `cm` is `NULL`, or the context has no + certificate manager +- `WS_FATAL_ERROR` if the reference cannot be taken or OCSP cannot be enabled + on `cm` +- `WS_NOT_COMPILED` with wolfSSL older than 4.6.0 + +**See Also** + +- `wolfSSH_CERTMAN_VerifyCerts_buffer()` + +### wolfSSH_CERTMAN_new() + +```c +#include + +WOLFSSH_CERTMAN* wolfSSH_CERTMAN_new(void* heap); +``` + +**Description** + +Allocates and initializes a new certificate manager, backed by a new wolfSSL +certificate manager. In builds with OCSP support (`HAVE_OCSP`), OCSP checking of +every certificate in a chain (`WOLFSSL_OCSP_CHECKALL`) is enabled on it. + +**Parameters** + +- `heap` - pointer to a heap to use for memory allocations, or `NULL` + +**Return Values** + +- pointer to the new certificate manager, or `NULL` on failure, including when + OCSP cannot be enabled + +**See Also** + +- `wolfSSH_CERTMAN_free()` + +### wolfSSH_CERTMAN_free() + +```c +#include + +void wolfSSH_CERTMAN_free(WOLFSSH_CERTMAN* cm); +``` + +**Description** + +Frees a certificate manager previously allocated with wolfSSH_CERTMAN_new(). + +**Parameters** + +- `cm` - the certificate manager to free + +**Return Values** + +None + +**See Also** + +- `wolfSSH_CERTMAN_new()` + +### wolfSSH_CERTMAN_LoadRootCA_buffer() + +```c +#include + +int wolfSSH_CERTMAN_LoadRootCA_buffer(WOLFSSH_CERTMAN* cm, + const unsigned char* rootCa, word32 rootCaSz); +``` + +**Description** + +Loads a trusted root CA certificate from a buffer into the certificate manager. +Loaded roots are used to verify certificates presented by a peer. The +certificate must be DER-encoded. + +**Parameters** + +- `cm` - the certificate manager +- `rootCa` - buffer containing the DER-encoded root CA certificate +- `rootCaSz` - size of the root CA buffer + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` if `cm` or `rootCa` is `NULL`, or `rootCaSz` is 0 +- a wolfSSL error code if the certificate cannot be loaded + +**See Also** + +- `wolfSSH_CERTMAN_VerifyCerts_buffer()` + +### wolfSSH_CERTMAN_VerifyCerts_buffer() + +```c +#include + +int wolfSSH_CERTMAN_VerifyCerts_buffer(WOLFSSH_CERTMAN* cm, + const unsigned char* cert, word32 certSz, word32 certCount); +``` + +**Description** + +Verifies a chain of `certCount` certificates contained in the buffer against the +root CAs loaded into the certificate manager. The buffer holds each DER-encoded +certificate preceded by its 4-byte big-endian length, leaf first, followed by +the intermediates; the root CA may be omitted. The chain may hold at most +`MAX_CHAIN_DEPTH` certificates (9 unless wolfSSL defines it). + +The certificates are verified from the end of the chain toward the leaf. In +builds with OCSP support, each certificate is also checked with OCSP; a +certificate with no OCSP responder URL, when no default responder is +configured, is treated as not revoked. Each verified intermediate that is a CA +is added to the certificate manager as a trusted root so the next certificate +has a signer. The addition is permanent. An intermediate that is not a CA fails +the chain. + +The leaf must be an end-entity certificate, not a CA. The function then applies +the RFC 6187 section 2.2 leaf checks in every build: a KeyUsage extension, if +present, must assert digitalSignature; an ExtendedKeyUsage extension, if +present, must name anyExtendedKeyUsage or a purpose usable for the SSH role +being verified. For a user certificate (verified by a server) that purpose is +id-kp-secureShellClient or TLS clientAuth; for a host certificate (verified by a +client) it is id-kp-secureShellServer or TLS serverAuth. The role comes from the +context that owns the certificate manager; a standalone manager created with +wolfSSH_CERTMAN_new() accepts either. Builds with FPKI profile matching (that +is, without `WOLFSSH_NO_FPKI`) also require the leaf to match one of the +supported FPKI profiles. + +**Parameters** + +- `cm` - the certificate manager +- `cert` - buffer containing the length-prefixed certificate chain +- `certSz` - size of the certificate buffer +- `certCount` - number of certificates in the chain + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` if `cm` or `cert` is `NULL`, `certCount` is 0, or + `certCount` exceeds `MAX_CHAIN_DEPTH` +- `WS_MEMORY_E` if an allocation fails +- `ASN_PARSE_E` if a certificate length runs past the end of the buffer +- `WS_CERT_NO_SIGNER_E` if a certificate has no trusted signer, or an + intermediate is not a CA +- `WS_CERT_EXPIRED_E` if a certificate has expired +- `WS_CERT_SIG_CONFIRM_E` if a certificate signature does not verify +- `WS_CERT_REVOKED_E` if OCSP reports a certificate as revoked +- `WS_CERT_KEY_USAGE_E` if the leaf KeyUsage or ExtendedKeyUsage does not + permit SSH use for the role +- `WS_CERT_PROFILE_E` if the leaf is a CA, or does not match an FPKI profile +- `WS_CERT_OTHER_E` for any other verification or OCSP failure + +**See Also** + +- `wolfSSH_CERTMAN_LoadRootCA_buffer()` + +### wolfSSH_CertStoreLocationFromName() + +**Availability** + +Available when wolfSSH is built with certificate support and Windows +certificate store support (`WOLFSSH_CERTS` and `WOLFSSH_WINDOWS_CERT_STORE`, +from `./configure --enable-certs --enable-windows-cert-store`). + +```c +#include + +int wolfSSH_CertStoreLocationFromName(const char* in, word32* out); +``` + +**Description** + +Parses the name of a Windows system certificate store location into its +`CERT_SYSTEM_STORE_*` value. Accepted names are `CURRENT_USER`, +`LOCAL_MACHINE`, `USERS`, `CURRENT_SERVICE`, `SERVICES`, +`CURRENT_USER_GROUP_POLICY`, `LOCAL_MACHINE_GROUP_POLICY`, and +`LOCAL_MACHINE_ENTERPRISE`, and the same names with a `CERT_SYSTEM_STORE_` +prefix. The location may also be given as a decimal number or a 0x-prefixed +hexadecimal number. The number must start with a digit and be consumed whole; a +leading sign or whitespace is rejected, and a leading 0 is read as decimal, not +octal. Only assigned store locations are accepted, never control flags. + +**Parameters** + +- `in` - NUL-terminated location name or number +- `out` - receives the `CERT_SYSTEM_STORE_*` value + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` if `in` or `out` is `NULL`, `in` is empty, or `in` is not + a valid location + +**See Also** + +- `wolfSSH_ParseCertStoreSpec()` + +### wolfSSH_ParseCertStoreSpec() + +**Availability** + +Available when wolfSSH is built with certificate support and Windows +certificate store support (`WOLFSSH_CERTS` and `WOLFSSH_WINDOWS_CERT_STORE`). + +```c +#include + +int wolfSSH_ParseCertStoreSpec(const char* spec, + wchar_t** wStoreName, wchar_t** wSubjectName, + word32* dwFlags, void* heap); +``` + +**Description** + +Splits a certificate store specification of the form `store:subject[:flags]` +into a store name, a subject name, and a store location. The specification is +split at the first two colons, so neither the store name nor the subject may +contain a colon, and a third colon is rejected. For example, "My:CN=host:65536" +is store "My", subject "CN=host", and flags 65536. The optional `flags` field +takes any spelling that wolfSSH_CertStoreLocationFromName() accepts and defaults +to `CURRENT_USER`. The store name and subject are converted from UTF-8 to +newly allocated wide strings; invalid UTF-8 is rejected. + +On success the caller owns the two wide strings and must release them with +wolfSSH_FreeCertStoreSpec() using the same `heap`. On failure any non-NULL +`wStoreName` and `wSubjectName` out-pointer is set to `NULL`, and `dwFlags` is +left unchanged. + +**Parameters** + +- `spec` - NUL-terminated specification string +- `wStoreName` - receives the allocated store name +- `wSubjectName` - receives the allocated subject name +- `dwFlags` - receives the store location value +- `heap` - heap used for the allocations + +**Return Values** + +- `WS_SUCCESS` +- `WS_BAD_ARGUMENT` if an argument is `NULL` or the specification is malformed +- `WS_MEMORY_E` if an allocation fails +- `WS_FATAL_ERROR` if the UTF-8 to wide string conversion fails + +**See Also** + +- `wolfSSH_FreeCertStoreSpec()` +- `wolfSSH_CertStoreLocationFromName()` + +### wolfSSH_FreeCertStoreSpec() + +**Availability** + +Available when wolfSSH is built with certificate support and Windows +certificate store support (`WOLFSSH_CERTS` and `WOLFSSH_WINDOWS_CERT_STORE`). + +```c +#include + +void wolfSSH_FreeCertStoreSpec(wchar_t* wStoreName, wchar_t* wSubjectName, + void* heap); +``` + +**Description** + +Frees the strings returned by wolfSSH_ParseCertStoreSpec(). Either pointer may +be `NULL`. The `heap` must be the one passed to wolfSSH_ParseCertStoreSpec(). + +**Parameters** + +- `wStoreName` - the store name to free, or `NULL` +- `wSubjectName` - the subject name to free, or `NULL` +- `heap` - heap used for the allocations + +**Return Values** + +None + +**See Also** + +- `wolfSSH_ParseCertStoreSpec()` + +## Portability Functions + +These functions form part of the wolfSSH platform portability layer, which +abstracts filesystem and string operations across supported targets. They are +primarily used internally and when porting wolfSSH to a new platform; the exact +set available depends on the target build configuration. + +### wfopen() + +```c +#include + +int wfopen(WFILE** f, const char* filename, const char* mode); +``` + +**Description** + +Portable file-open wrapper. Opens `filename` using the access `mode` and stores +the resulting file handle in `f`. + +**Parameters** + +- `f` - receives the opened file handle +- `filename` - path of the file to open +- `mode` - access mode string (as for the C library `fopen`) + +**Return Values** + +- 0 on success +- non-zero on failure + +### wstrnstr() + +```c +#include + +char* wstrnstr(const char* s1, const char* s2, unsigned int n); +``` + +**Description** + +Finds the first occurrence of the substring `s2` within the first `n` bytes of +`s1`. + +**Parameters** + +- `s1` - the string to search +- `s2` - the substring to find +- `n` - maximum number of bytes of `s1` to search + +**Return Values** + +- pointer to the first occurrence of `s2` in `s1`, or `NULL` if not found + +### wstrncat() + +```c +#include + +char* wstrncat(char* s1, const char* s2, size_t n); +``` + +**Description** + +Appends the string `s2` to the end of the string in `s1`, where `n` is the +total size of the buffer holding `s1`. The append is all or nothing: if `s2` +does not fit in the space left, including the terminating NUL, nothing is +appended. If no NUL terminator is found within the first `n` bytes of `s1`, the +function fails without writing. + +**Parameters** + +- `s1` - destination string, appended to in place +- `s2` - source string to append +- `n` - total size of the `s1` buffer in bytes + +**Return Values** + +- pointer to the destination string `s1` on success +- `NULL` if `s2` does not fit, or `s1` is not terminated within `n` bytes + +### wstrdup() + +```c +#include + +char* wstrdup(const char* s1, void* heap, int type); +``` + +**Description** + +Duplicates the string `s1`, allocating the copy from the given `heap`. A `NULL` +`s1` returns `NULL`. + +**Parameters** + +- `s1` - the string to duplicate +- `heap` - heap used for the allocation +- `type` - allocation type hint + +**Return Values** + +- pointer to the duplicated string, or `NULL` on failure + +### WS_FindFirstFileA() + +**Availability** + +Available on Windows builds (`USE_WINDOWS_API`) with SCP or SFTP support, +unless `WOLFSSH_SCP_USER_CALLBACKS` is defined. + +```c +#include + +void* WS_FindFirstFileA(const char* fileName, + char* realFileName, size_t realFileNameSz, int* isDir, void* heap); +``` + +**Description** + +Begins a directory enumeration for `fileName`, returning a find handle and the +first matching entry. `isDir` is set to indicate whether the entry is a +directory. A leading path separator before a drive letter (as in SFTP paths +such as "/C:/dir") is trimmed before the search. The handle is a Windows find +handle. + +**Parameters** + +- `fileName` - the directory or search pattern to enumerate +- `realFileName` - buffer that receives the matched file name +- `realFileNameSz` - size of the `realFileName` buffer +- `isDir` - output set non-zero if the entry is a directory, or `NULL` +- `heap` - heap used for allocations + +**Return Values** + +- an opaque find handle on success +- `INVALID_HANDLE_VALUE` on failure + +**See Also** + +- `WS_FindNextFileA()` + +### WS_FindNextFileA() + +**Availability** + +Available on Windows builds (`USE_WINDOWS_API`) with SCP or SFTP support, +unless `WOLFSSH_SCP_USER_CALLBACKS` is defined. + +```c +#include + +int WS_FindNextFileA(void* findHandle, + char* realFileName, size_t realFileNameSz); +``` + +**Description** + +Continues a directory enumeration started with WS_FindFirstFileA(), returning the +next matching entry. + +**Parameters** + +- `findHandle` - the find handle returned by WS_FindFirstFileA() +- `realFileName` - buffer that receives the matched file name +- `realFileNameSz` - size of the `realFileName` buffer + +**Return Values** + +- non-zero if another entry was returned +- 0 when there are no more entries, or the entry name could not be converted + to a multibyte string that fits in `realFileName` + +**See Also** + +- `WS_FindFirstFileA()` + +### wstrsep() + +**Availability** + +Available on Windows builds (`USE_WINDOWS_API`). Other platforms use the C +library `strsep()` through the `WSTRSEP()` macro. + +```c +#include + +char* wstrsep(char** s1, const char* delim); +``` + +**Description** + +A replacement for the BSD `strsep()` function, which the Microsoft C runtime +and MinGW do not provide. Finds the first character in `*s1` that appears in +`delim`, replaces it with a NUL to terminate the token in place, and advances +`*s1` past it. If no delimiter remains, `*s1` is set to `NULL`. Portable code +should call the `WSTRSEP()` macro, which maps to `strsep()` or to this +function as appropriate. + +**Parameters** + +- `s1` - pointer to the string pointer to split; updated to point past the token +- `delim` - NUL-terminated set of delimiter characters + +**Return Values** + +- pointer to the start of the token +- `NULL` if `*s1` was already `NULL` diff --git a/wolfSSH/src/chapter17.md b/wolfSSH/src/chapter17.md new file mode 100644 index 00000000..b9a1babd --- /dev/null +++ b/wolfSSH/src/chapter17.md @@ -0,0 +1,141 @@ +# wolfSSH Preprocessor Guard Macros + +Many wolfSSH features, algorithms, and functions are controlled by build-time +preprocessor macros. This chapter is a reference for the macros that are +intended to be set by applications. They are defined at build time through the +compiler command line (for example `CPPFLAGS`/`CFLAGS`), or by the `./configure` +options described in the "Building wolfSSH" chapter. + +## Algorithm-Disable Macros + +Each of the following `WOLFSSH_NO_*` macros disables one algorithm (or a family +of algorithms). In an autotools build these are normally set automatically based +on which algorithms are enabled in wolfCrypt; they may also be defined manually +to remove an algorithm from wolfSSH. + +Two algorithm families are "soft-disabled" by default: they are compiled in and +still work, but are not advertised during key exchange unless re-enabled. + +| Macro | Effect | +|--------------------------------------|------------------------------------| +| `WOLFSSH_NO_SHA1_SOFT_DISABLE` | SHA-1 algorithms are compiled in but not advertised during KEX by default. Define this to advertise SHA-1 algorithms by default. | +| `WOLFSSH_NO_AES_CBC_SOFT_DISABLE` | AES-CBC algorithms are compiled in but not advertised during KEX by default. Define this to advertise AES-CBC algorithms by default. | +| `WOLFSSH_NO_SHA1` | Disables SHA-1 in HMAC and digital signatures. | +| `WOLFSSH_NO_HMAC_SHA1` | Disables HMAC-SHA1. | +| `WOLFSSH_NO_HMAC_SHA1_96` | Disables HMAC-SHA1-96. | +| `WOLFSSH_NO_HMAC_SHA2_256` | Disables HMAC-SHA2-256. | +| `WOLFSSH_NO_HMAC_SHA2_512` | Disables HMAC-SHA2-512. | +| `WOLFSSH_NO_DH_GROUP1_SHA1` | Disables DH group 1 (Oakley 1) with SHA-1. | +| `WOLFSSH_NO_DH_GROUP14_SHA1` | Disables DH group 14 (Oakley 14) with SHA-1. | +| `WOLFSSH_NO_DH_GROUP14_SHA256` | Disables DH group 14 with SHA-256. | +| `WOLFSSH_NO_DH_GROUP16_SHA512` | Disables DH group 16 with SHA-512. | +| `WOLFSSH_NO_DH_GEX_SHA256` | Disables DH group exchange with SHA-256. | +| `WOLFSSH_NO_DH` | Disables all DH key agreement. | +| `WOLFSSH_NO_ECDH_SHA2_NISTP256` | Disables ECDH key exchange with NIST P-256. | +| `WOLFSSH_NO_ECDH_SHA2_NISTP384` | Disables ECDH key exchange with NIST P-384. | +| `WOLFSSH_NO_ECDH_SHA2_NISTP521` | Disables ECDH key exchange with NIST P-521. | +| `WOLFSSH_NO_ECDH` | Disables all ECDH key agreement. | +| `WOLFSSH_NO_CURVE25519_SHA256` | Disables Curve25519 key exchange. | +| `WOLFSSH_NO_NISTP256_MLKEM768_SHA256` | Disables the NIST P-256 with ML-KEM-768 post-quantum hybrid key exchange. | +| `WOLFSSH_NO_NISTP384_MLKEM1024_SHA384` | Disables the NIST P-384 with ML-KEM-1024 post-quantum hybrid key exchange. | +| `WOLFSSH_NO_CURVE25519_MLKEM768_SHA256` | Disables the Curve25519 with ML-KEM-768 post-quantum hybrid key exchange. | +| `WOLFSSH_NO_RSA` | Disables RSA server and user authentication. | +| `WOLFSSH_NO_SSH_RSA_SHA1` | Disables `ssh-rsa` (RSA with SHA-1), and `x509v3-ssh-rsa`. | +| `WOLFSSH_NO_RSA_SHA2_256` | Disables `rsa-sha2-256`. | +| `WOLFSSH_NO_RSA_SHA2_512` | Disables `rsa-sha2-512`. | +| `WOLFSSH_NO_ECDSA` | Disables ECDSA server and user authentication. | +| `WOLFSSH_NO_ECDSA_SHA2_NISTP256` | Disables ECDSA authentication with NIST P-256. | +| `WOLFSSH_NO_ECDSA_SHA2_NISTP384` | Disables ECDSA authentication with NIST P-384. | +| `WOLFSSH_NO_ECDSA_SHA2_NISTP521` | Disables ECDSA authentication with NIST P-521. | +| `WOLFSSH_NO_ED25519` | Disables Ed25519 server and user authentication, and the ML-DSA composites with Ed25519. Set unless wolfCrypt has Ed25519 with signing, verifying, streaming verify, and key import and export. | +| `WOLFSSH_NO_MLDSA` | Disables all ML-DSA server and user authentication. Set unless wolfCrypt has ML-DSA and is version 5.9.2 or later. | +| `WOLFSSH_NO_MLDSA44` | Disables ML-DSA-44. | +| `WOLFSSH_NO_MLDSA65` | Disables ML-DSA-65. | +| `WOLFSSH_NO_MLDSA87` | Disables ML-DSA-87. | +| `WOLFSSH_NO_MLDSA44_ES256`, `WOLFSSH_NO_MLDSA65_ES256`, `WOLFSSH_NO_MLDSA87_ES384`, `WOLFSSH_NO_MLDSA44_ED25519`, `WOLFSSH_NO_MLDSA65_ED25519`, `WOLFSSH_NO_MLDSA87_ED448` | Each disables one ML-DSA composite. Set when the ML-DSA level or the algorithm it pairs with is disabled. | +| `WOLFSSH_NO_MLDSA_COMPOSITES` | Disables all of the ML-DSA composites. | +| `WOLFSSH_NO_OSSH_CERT_RSA` | Disables RSA OpenSSH certificates. Set when RSA, or both `rsa-sha2-256` and `rsa-sha2-512`, are disabled. | +| `WOLFSSH_NO_AES_CBC` | Disables AES-CBC encryption. | +| `WOLFSSH_NO_AES_CTR` | Disables AES-CTR encryption. | +| `WOLFSSH_NO_AES_GCM` | Disables AES-GCM encryption. | +| `WOLFSSH_NO_AEAD` | Disables all AEAD ciphers. | + +The library also sets `WOLFSSH_NO_PUBKEY_AUTH` when RSA, ECDSA, Ed25519, and +ML-DSA are all disabled, which leaves out public key user authentication. + +## Feature-Enable Macros + +These macros turn whole subsystems on. In an autotools build each is defined by +the corresponding `./configure` option shown below. The relevant API for most of +these features is documented in the API reference chapters. + +| Macro | Enables | Configure option | +|--------------------------------|---------------------|------------------------------| +| `WOLFSSH_SFTP` | SFTP support | `--enable-sftp` | +| `WOLFSSH_SCP` | SCP support | `--enable-scp` | +| `WOLFSSH_FWD` | TCP/IP port forwarding | `--enable-fwd` | +| `WOLFSSH_AGENT` | ssh-agent forwarding | `--enable-agent` | +| `WOLFSSH_CERTS` | X.509 certificate support | `--enable-certs` | +| `WOLFSSH_OSSH_CERTS` | OpenSSH certificate user authentication | `--enable-ossh-certs` | +| `WOLFSSH_WINDOWS_CERT_STORE` | keys and certificates from the Windows certificate store; requires `WOLFSSH_CERTS` and a Windows target | `--enable-windows-cert-store` | +| `WOLFSSH_TPM` | TPM 2.0 support for host keys and user keys | `--enable-tpm` | +| `WOLFSSH_SSHD` | wolfsshd daemon | `--enable-sshd` | +| `WOLFSSH_USE_PAM` | PAM for wolfsshd | `--with-pam` | +| `WOLFSSH_SHELL` | echoserver shell support | `--enable-shell` | +| `WOLFSSH_KEYGEN` | key generation API | `--enable-keygen` | +| `WOLFSSH_KEYBOARD_INTERACTIVE` | keyboard-interactive authentication | `--enable-keyboard-interactive` | +| `WOLFSSH_SSHCLIENT` | wolfSSH client application | `--enable-sshclient` | +| `WOLFSSH_TERM` | PTY / terminal handling | on by default (`--disable-term` to remove) | +| `WOLFSSH_SMALL_STACK` | reduced stack usage for constrained targets | `--enable-smallstack` | +| `WOLFSSH_ALLOW_NONE_CIPHER` | negotiating the insecure "none" cipher and MAC | `--enable-none-cipher` | +| `NO_WOLFSSH_SERVER` | leaves out the server code | `--disable-server` | +| `NO_WOLFSSH_CLIENT` | leaves out the client code | `--disable-client` | + +The following macros adjust behavior rather than enabling a subsystem: + +| Macro | Effect | +|--------------------------------------|--------------------------------------------------| +| `WOLFSSH_NO_DEFAULT_LOGGING_CB` | Omits the built-in default logging callback. | +| `WOLFSSH_NO_TIMESTAMP` | Omits timestamps from log output. | +| `WOLFSSH_NO_SYMLINK_CHECK` | Disables the check that rejects symbolic links below an SFTP confinement root, and the escape protection it gives. | +| `WOLFSSH_NO_SFTP_BUFFER_ZERO` | Skips zeroing SFTP file data buffers before they are freed. Set by `--disable-sftp-zeroize`. | +| `WOLFSSH_NO_FPKI` | Skips the Federal PKI (FPKI) profile checks on X.509 certificates. | +| `WOLFSSH_ALLOW_USERAUTH_NONE` | Lets the server accept the "none" user authentication method, passing it to the user authentication callback as `WOLFSSH_USERAUTH_NONE`. | +| `WOLFSSH_SCP_USER_CALLBACKS` | Omits the default SCP send and receive callbacks; the application must set its own. | +| `WOLFSSH_USER_IO` | Omits the default socket I/O callbacks; the application must set its own. | +| `WOLFSSH_CERT_STORE_ALLOW_EXPIRED` | Lets a Windows certificate store lookup use an expired or not yet valid certificate when no time-valid one matches. | +| `WOLFSSH_IGNORE_UNKNOWN_CONFIG` | wolfSSHd logs a warning and ignores an unknown or unsupported configuration line, instead of failing to start. | +| `WOLFSSH_NO_HOSTKEY_PERMS` | On QNX, wolfSSHd skips the owner and mode checks of its host key file. | + +## Tuning and Value Macros + +These macros take a numeric value rather than acting as an on/off switch. Define +them at build time to override the default. + +| Macro | Meaning | Default | +|-------------------------------------|-----------------------------------|--------------| +| `DEFAULT_WINDOW_SZ` | Initial channel window size, in bytes. | 131072 (128 KB) | +| `DEFAULT_MAX_PACKET_SZ` | Maximum channel packet size, in bytes. | 32768 | +| `MAX_PACKET_SZ` | Largest SSH packet sent or accepted, in bytes. | 35000 | +| `DEFAULT_MAX_AUTH_ATTEMPTS` | Failed user authentication attempts the server allows before it disconnects. | 6 | +| `WOLFSSH_RSA_MIN_KEY_BITS` | Minimum RSA user authentication key size, in bits. | 2048 | +| `WOLFSSH_DEFAULT_GEXDH_MIN` | Minimum DH group exchange group size a client requests, in bits. | 2048 | +| `WOLFSSH_DEFAULT_GEXDH_PREFERRED` | Preferred DH group exchange group size a client requests, in bits. | 3072 | +| `WOLFSSH_DEFAULT_GEXDH_MAX` | Maximum DH group exchange group size a client requests, in bits. | 8192 | +| `WOLFSSH_DH_GEX_MIN_BITS` | Smallest DH group exchange group either side accepts, in bits. | 2048 | +| `WOLFSSH_MAX_NAMELIST_SZ` | Largest name-list accepted from the peer, in bytes. | 4096 | +| `WOLFSSH_MAX_NAMELIST_CNT` | Most names accepted in a name-list from the peer. | 64 | +| `WOLFSSH_MAX_PVT_KEYS` | Most private keys a context can hold. | 16 | +| `WOLFSSH_MAX_PROMPTS` | Most keyboard-interactive prompts. | 64 | +| `WOLFSSH_MAX_PROMPT_SZ` | Largest keyboard-interactive prompt, in bytes. | 1024 | +| `DEFAULT_HIGHWATER_MARK` | Default data highwater mark, in bytes, before a rekey is triggered. | about 1 GB | +| `WOLFSSH_DEFAULT_MSG_HIGHWATER_MARK` | Default packet-count highwater mark before a rekey is triggered. | 0x80000000 | +| `WOLFSSH_MR_ROUNDS` | Miller-Rabin rounds used when the client checks the server's DH group-exchange prime. | 8 | +| `WOLFSSH_KEY_QUANTITY_REQ` | Number of keys required in an OpenSSH-style key wrapper. | 1 | +| `WOLFSSH_MAX_FILENAME` | Maximum filename length, in bytes. | 256 | +| `WOLFSSH_MAX_SFTP_RW` | Maximum SFTP read/write chunk size, in bytes. | 32768 | +| `WOLFSSH_MAX_SFTP_RECV` | Maximum SFTP receive size, in bytes. | 32768 | +| `WOLFSSH_MAX_SFTP_NAME` | Maximum size of an SFTP name list, in bytes. | 1048576 (1 MB) | +| `WOLFSSH_MAX_SFTP_PACKET` | Largest SFTP request a server accepts, in bytes. | `WOLFSSH_MAX_SFTP_RW` + `WOLFSSH_MAX_SFTP_RECV` | +| `WOLFSSH_MAX_SFTP_HANDLES` | Most open SFTP handles per server session. | 64 | +| `WOLFSSHD_DEFAULT_UMASK` | umask wolfSSHd sessions run with. | 022 |