TsgcWebSocketClient | 証明書 SChannel

サーバーがクライアントにSSL証明書を使用して接続することを要求する場合、 TsgcWebSocketClientのTLSOptionsプロパティを使用して証明書 ファイルを設定してください。

 

SChannel を通じた接続には TLSOptions.IOHandler = iohSChannel が必要です。

 

SChannel は 2 種類の証明書認証をサポートしています:

 

1. PFX証明書を使用する

2. Windows システムにすでにインストールされている証明書のハッシュ証明書を設定します。

 

PFX 証明書

PFX 証明書は証明書と秘密鍵を含むファイルです。PEM 形式の証明書がある場合は、使用する前に PFX に変換する必要があります。

以下の openssl コマンドを使用して PEM 証明書を PFX に変換します。

 


openssl pkcs12 -inkey certificate-pem.key -in certificate-pem.crt -export -out certificate.pfx

証明書が PFX 形式になったら、証明書をデプロイして TLSOptions.CertFile プロパティにそのパスを設定するだけです。

 


TLSOptions.IOHandler = iohSChannel
TLSOptions.CertFile = <certificate path>
TLSOptions.Password = <certificate optional password>

 

ハッシュ証明書

証明書がすでに Windows 証明書ストアにインストールされている場合、証明書のサムプリントを知り、TLSOptions.SChannel_Options プロパティに設定するだけです。

 

証明書のハッシュを見つけることは、powershell で証明書コンテナーに対して dir コマンドを実行するのと同じくらい簡単です。

dir cert:\localmachine\my

ハッシュは 16 進数の Thumbprint 値です。


Directory: Microsoft.PowerShell.Security\Certificate::localmachine\my
Thumbprint                                Subject
----------                                -------
C12A8FC8AE668F866B48F23E753C93D357E9BE10  CN=*.mydomain.com

サムプリント値を取得したら、TLSOptions.SChannel_Options プロパティにハッシュと証明書の場所を設定する必要があります。


TLSOptions.IOHandler = iohSChannel
TLSOptions.SChannel_Options.CertHash = <certificate thumbprint>
TLSOptions.SChannel_Options.CertStoreName = <certificate store name>
TLSOptions.SChannel_Options.CertStorePath = <certificate store path>
TLSOptions.Password = <certificate optional password>