1

次のコードを使用して、SSL接続を確立できます。

   $cert = dir cert:\CurrentUser\My | where {$_.Subject -like "*Alice*"}

   $computerName = "google.com"
   $port = "443"

   $socket = New-Object Net.Sockets.TcpClient($computerName, $port)
   $stream = $socket.GetStream()

   $sslStream = New-Object System.Net.Security.SslStream $stream,$false
   $sslStream.AuthenticateAsClient($computerName)


    $sslStream

これは問題なく動作します。しかし、今は認証用のクライアント証明書を追加したくありません。私はただ置き換える必要があると思います

$sslStream.AuthenticateAsClient($computerName)

$sslStream.BeginAuthenticateAsClient($computerName,$cert,"SslProtocols",$false,"Foo" ,"Bar")

しかし、私は議論を正しくすることができなかった。SombodyはAssyncCallsを解決できますか;-)多分私はこれのためにいくつかのC#コードが必要ですか?!?

引数は次のとおりです。

System.IAsyncResult BeginAuthenticateAsClient(

string targetHost, 
System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, 
System.Security.Authentication.SslProtocols enabledSslProtocols,
bool checkCertificateRevocation, 
System.AsyncCallback asyncCallback, 
System.Object asyncState)

私が最終的に達成したいのは、クライアントが接続されている暗号スイートをリストし、後で指定することです。(私が知っているWiresharkを使用できます;-))

4

2 に答える 2

4

最終的に機能するようになりました。引数 4 ではなく、コレクションではない $Cert でした。

   $cert = dir cert:\CurrentUser\My | where {$_.Subject -like "*alice*"}

   $computerName = "google.com"
   $port = "443"

    [System.Security.Authentication.SslProtocols]$protocol = "ssl3"

   $certcol = New-object System.Security.Cryptography.X509Certificates.X509CertificateCollection
   $certcol.Add($cert)




   $socket = New-Object Net.Sockets.TcpClient($computerName, $port)
   $stream = $socket.GetStream()

   $sslStream = New-Object System.Net.Security.SslStream $stream,$false
   #$sslStream.AuthenticateAsClient($computerName)
   $sslStream.AuthenticateAsClient($computerName,$certcol,$protocol,$false) 


    $sslStream
于 2012-01-26T14:30:15.980 に答える
0

AuthenticateAsClientドキュメントによると、との違いBeginAuthenticateAsClientは、後者が非同期で使用されることです。

を試してみAuthenticateAsClient(String, X509CertificateCollection, SslProtocols, Boolean)てください。2番目の引数は、使用できるクライアント証明書のコレクションです(X509Certificate2認証に使用するには、証明書に関連付けられた秘密鍵が必要になるためです)。

于 2012-01-26T13:04:04.180 に答える