Powershell:由于 TLS 导致的连接问题
Powershell: Connection problem due to TLS
我正在为 PS 使用名为 Qlik-Cli 的模块,
这是连接和启动任务的代码,
> [Net.ServicePointManager]::SecurityProtocol = "Tls12"
> $logpath = "E:\Tools\Scripts\log.txt"
> Import-Module -Name Qlik-Cli
> $cert = gci cert:localmachine\my | where { $_.Thumbprint -eq '1fcad2353817a88b785b11fd543d8c3507fc8bf3'}
> Connect-Qlik -Computername server1 -Certificate $cert -Username ad\qsadmin
> Start-QlikTask -id df9dfa2f-32ca-4db4-bdce-15ad923fd59g
但我遇到了问题,Invoke-RestMethod:请求已中止:无法创建 SSL/TLS 安全通道。
QlikSense 使用 1.2,因此我添加了 [Net.ServicePointManager]::SecurityProtocol = "Tls12"。
我试过其他版本。
我疯狂地使用谷歌搜索,找不到更多信息。
对于 nPrint,[Net.ServicePointManager]::SecurityProtocol = "Tls12" 使用 CLI 模块解决了它。
在这种情况下,这可以体现在证书上吗?
将您的脚本设置为使用 TLS1.2 确实需要您的服务器也支持它。这里有一些额外的故障排除尝试:
# check your client certificate (make sure it's not expired or something):
$cert = gci cert:localmachine\my | where thumbprint -eq '1fcad2353817a88b785b11fd543d8c3507fc8bf3'
# Use -AllowUntrustedRoot if the cert doesn't have a valid revocation list to check
Test-Certificate $cert -AllowUntrustedRoot
# Check the protocols offered by the server include TLS 1.2 - I use nmap (external tool)
./nmap.exe --script ssl-enum-ciphers -p 443 server1
443/tcp open https
| ssl-enum-ciphers:
| TLSv1.2:
| ciphers etc...
# Try and connect manually with the command that's failing:
Invoke-RestMethod -Uri "https://Server1/path/to/api" -Certificate $cert
由于是休息方式,您也可以尝试在浏览器中连接,看看服务器端的证书是否可以接受。
如果您的计算机不信任服务器证书,您可以绕过此检查(不推荐)。这至少需要 powershell v6,并且您必须编辑 qlik-cli 模块。
Invoke-RestMethod -Uri $URI -SkipCertificateCheck -Certificate $cert
此问题已解决。该模块使用 QLikSense 创建的名为 Qlik Client 的证书。
您必须将此与模块一起使用,而不是与 Qlik Sense 一起使用的普通证书。
我正在为 PS 使用名为 Qlik-Cli 的模块,
这是连接和启动任务的代码,
> [Net.ServicePointManager]::SecurityProtocol = "Tls12"
> $logpath = "E:\Tools\Scripts\log.txt"
> Import-Module -Name Qlik-Cli
> $cert = gci cert:localmachine\my | where { $_.Thumbprint -eq '1fcad2353817a88b785b11fd543d8c3507fc8bf3'}
> Connect-Qlik -Computername server1 -Certificate $cert -Username ad\qsadmin
> Start-QlikTask -id df9dfa2f-32ca-4db4-bdce-15ad923fd59g
但我遇到了问题,Invoke-RestMethod:请求已中止:无法创建 SSL/TLS 安全通道。
QlikSense 使用 1.2,因此我添加了 [Net.ServicePointManager]::SecurityProtocol = "Tls12"。 我试过其他版本。
我疯狂地使用谷歌搜索,找不到更多信息。 对于 nPrint,[Net.ServicePointManager]::SecurityProtocol = "Tls12" 使用 CLI 模块解决了它。
在这种情况下,这可以体现在证书上吗?
将您的脚本设置为使用 TLS1.2 确实需要您的服务器也支持它。这里有一些额外的故障排除尝试:
# check your client certificate (make sure it's not expired or something):
$cert = gci cert:localmachine\my | where thumbprint -eq '1fcad2353817a88b785b11fd543d8c3507fc8bf3'
# Use -AllowUntrustedRoot if the cert doesn't have a valid revocation list to check
Test-Certificate $cert -AllowUntrustedRoot
# Check the protocols offered by the server include TLS 1.2 - I use nmap (external tool)
./nmap.exe --script ssl-enum-ciphers -p 443 server1
443/tcp open https
| ssl-enum-ciphers:
| TLSv1.2:
| ciphers etc...
# Try and connect manually with the command that's failing:
Invoke-RestMethod -Uri "https://Server1/path/to/api" -Certificate $cert
由于是休息方式,您也可以尝试在浏览器中连接,看看服务器端的证书是否可以接受。
如果您的计算机不信任服务器证书,您可以绕过此检查(不推荐)。这至少需要 powershell v6,并且您必须编辑 qlik-cli 模块。
Invoke-RestMethod -Uri $URI -SkipCertificateCheck -Certificate $cert
此问题已解决。该模块使用 QLikSense 创建的名为 Qlik Client 的证书。
您必须将此与模块一起使用,而不是与 Qlik Sense 一起使用的普通证书。