gpt4 book ai didi

ssl - 如何在 Powershell 中使用客户端证书创建 TCP 客户端连接

转载 作者:太空宇宙 更新时间:2023-11-03 13:13:18 27 4
gpt4 key购买 nike

使用以下代码我可以建立 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 可以解决 Assync Calls 吗 ;-)也许我为此需要一些 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)

我最终想要实现的是列出并稍后指定客户端连接到的 CipherSuites。 (我可以使用我知道的 Wireshark ;-))

最佳答案

终于让它工作了,不是参数 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

关于ssl - 如何在 Powershell 中使用客户端证书创建 TCP 客户端连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9018338/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com