使用 powershell 连接到 HTTPS 站点
Using powershell to connect to HTTPS sites
有人为我提供了一个新的 Server 2012 框来进行设置。
我正在尝试使用 powershell 安装 chocolatey
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
出现错误
Exception calling "DownloadString" with "1" argument(s): "The underlying connection was closed: An unexpected error
occurred on a receive."
At line:1 char:1
+ iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/in ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
我可以在浏览器中访问that URL。
起初我以为这与巧克力有关,但后来我意识到
(New-Object System.Net.WebClient).DownloadString('http://google.com'))
可以下载html内容
但是
((New-Object System.Net.WebClient).DownloadString('https://google.com'))
失败并出现同样的错误
The underlying connection was closed: An unexpected error occurred on a receive.
盒子:
- 是windows server 2012 build 9600
- 不使用代理
- 是否关闭了防火墙
我确定我在做一些愚蠢的事情,但看不到什么...
---更新---
我遵循了这些步骤:
```
1.In 控制面板,单击管理工具,然后双击本地安全策略。
2.In 本地安全设置,展开本地策略,然后单击安全选项。
3.Under 右窗格中的策略,双击系统加密:使用符合 FIPS 的算法进行加密、散列和签名,然后单击启用。
- 运行 gpupdate /force
```
之后可以下载巧克力安装脚本但随后失败:
STDOUT: FIPS Mode detected - run 'choco feature enable -n useFipsCompliantChecksums'
to use Chocolatey.
When FIPS Mode is enabled, Chocolatey requires useFipsCompliantChecksums feature also be enabled.
STDERR:
---- End output of C:\ProgramData\chocolatey/bin/choco.exe list -l -r ----
Ran C:\ProgramData\chocolatey/bin/choco.exe list -l -r returned 1
仍然觉得没有必要更改 GPO
试试这个:
$WBC = New-Object System.Net.WebClient
$WBC.DownloadString("https://google.com")
原来这是因为为了符合 PCI DSS 3.1 而在我们的服务器映像中禁用了 TLS 1.0。
回滚对图像的更改解决了 powershell 问题。
短期内我们可以运行
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
在使用 System.Net.WebClient
之前,但我也想找到一种在机器级别强制执行的方法...
我 logged this with Chocolatey 他们解决了这个问题 \o/
有人为我提供了一个新的 Server 2012 框来进行设置。
我正在尝试使用 powershell 安装 chocolatey
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
出现错误
Exception calling "DownloadString" with "1" argument(s): "The underlying connection was closed: An unexpected error
occurred on a receive."
At line:1 char:1
+ iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/in ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
我可以在浏览器中访问that URL。
起初我以为这与巧克力有关,但后来我意识到
(New-Object System.Net.WebClient).DownloadString('http://google.com'))
可以下载html内容
但是
((New-Object System.Net.WebClient).DownloadString('https://google.com'))
失败并出现同样的错误
The underlying connection was closed: An unexpected error occurred on a receive.
盒子:
- 是windows server 2012 build 9600
- 不使用代理
- 是否关闭了防火墙
我确定我在做一些愚蠢的事情,但看不到什么...
---更新---
我遵循了这些步骤:
``` 1.In 控制面板,单击管理工具,然后双击本地安全策略。
2.In 本地安全设置,展开本地策略,然后单击安全选项。
3.Under 右窗格中的策略,双击系统加密:使用符合 FIPS 的算法进行加密、散列和签名,然后单击启用。
- 运行 gpupdate /force ```
之后可以下载巧克力安装脚本但随后失败:
STDOUT: FIPS Mode detected - run 'choco feature enable -n useFipsCompliantChecksums'
to use Chocolatey.
When FIPS Mode is enabled, Chocolatey requires useFipsCompliantChecksums feature also be enabled.
STDERR:
---- End output of C:\ProgramData\chocolatey/bin/choco.exe list -l -r ----
Ran C:\ProgramData\chocolatey/bin/choco.exe list -l -r returned 1
仍然觉得没有必要更改 GPO
试试这个:
$WBC = New-Object System.Net.WebClient
$WBC.DownloadString("https://google.com")
原来这是因为为了符合 PCI DSS 3.1 而在我们的服务器映像中禁用了 TLS 1.0。
回滚对图像的更改解决了 powershell 问题。
短期内我们可以运行
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
在使用 System.Net.WebClient
之前,但我也想找到一种在机器级别强制执行的方法...
我 logged this with Chocolatey 他们解决了这个问题 \o/