简体   繁体   English

powershell使用ServerCertificateValidationCallback接受自签名证书

[英]powershell Accepting self-signed certificates using ServerCertificateValidationCallback

I cannot seem to get this to work using Powershell 5.1. 我似乎无法使用Powershell 5.1使它正常工作。 The device is a Cisco MX800 CE9.3. 设备是Cisco MX800 CE9.3。

$url = "https://10.1.135.20/getxml?location=/Status"
[Net.ServicePointManager]::ServerCertificateValidationCallback={$true} 
$webclient = New-Object System.Net.Webclient
$credCache = New-Object System.Net.CredentialCache
$creds = New-Object System.Net.NetworkCredential($user,$pwd)
$credCache.Add($url, "Basic", $creds)
$webclient.Credentials = $credCache
$webpage = $webclient.DownloadString($url)

Running this script using http returns XML as expected, but using https returns the error below 使用http运行此脚本将按预期返回XML,但使用https将返回以下错误

Exception calling "DownloadString" with "1" argument(s): "The underlying connection was closed: An unexpected error occurred on a send." “使用” 1“参数调用” DownloadString“的异常:”基础连接已关闭:发送时发生意外错误。“ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException + CategoryInfo:未指定:(:) [],MethodInvocationException + FullyQualifiedErrorId:WebException

In the case above, after searching for answers, I dug in and did packet captures. 在上述情况下,在寻找答案之后,我挖了一下并进行了数据包捕获。 One packet capture with powershell talking to the server and one packet capture with a web browser talking to the server. 使用Powershell与服务器对话时捕获一个数据包,通过Web浏览器与服务器对话时捕获一个数据包。

The PS Client Hello was using TLS1.0 PS Client Hello使用的是TLS1.0

The Web browsers Client Hello was using TLS1.2 Web浏览器Client Hello使用的是TLS1.2

So, in PS I added this to the code and I was able to use https against the server. 因此,在PS中,我将其添加到了代码中,从而能够对服务器使用https。 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 [Net.ServicePointManager] :: SecurityProtocol = [Net.SecurityProtocolType] :: Tls12

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 忽略自签名证书 - Ignore Self-Signed Certificates 使用PowerShell创建自签名证书 - Using PowerShell to Create Self-Signed Certificate 自签名证书仅限于主机? - Self-signed certificates limited to a host? 使用自签名证书签署PowerShell脚本(并且不使用makecert.exe) - Signing a PowerShell script with self-signed certificates (and without makecert.exe) 使用PowerShell创建2048位长的自签名证书 - Using PowerShell to Create Self-Signed Certificate of 2048 bits length 从Powershell Invoke-RestMethod忽略自签名证书不起作用(已再次更改…) - Ignoring Self-Signed Certificates from Powershell Invoke-RestMethod doesn't work (it's changed again…) 创建自签名的PowerShell脚本开始完成 - Creating self-signed PowerShell scripts start to finish PowerShell - 尝试在没有自签名证书问题的情况下进行 REST 调用的添加类型问题 - PowerShell - Add-Type Issue trying to do REST call without self-signed cert issue 使用Powershell Invoke-AddCertToKeyVault命令创建Azure自签名证书 - Creating Azure self-signed sertificate with powershell Invoke-AddCertToKeyVault command 无法使用 Powershell 生成自签名证书 - Unable to generate self signed certificate using Powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM