【问题标题】:Using powershell to connect to HTTPS sites使用 powershell 连接到 HTTPS 站点
【发布时间】:2017-05-03 04:45:33
【问题描述】:

我得到了一个新的 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

起初我以为这与 Chocolatey 有关,但后来我意识到

(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
  • 不使用代理
  • 防火墙是否关闭

我确信我在做一些愚蠢的事情,但看不到什么......

--- 更新---

基于this answer

我按照以下步骤操作:

``` 1.在控制面板中,点击管理工具,然后双击本地安全策略。

2.在本地安全设置中,展开本地策略,然后点击安全选项。

3.在右侧窗格中的策略下,双击系统加密:使用符合 FIPS 的算法进行加密、散列和签名,然后单击启用。

  1. 运行 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

【问题讨论】:

  • 在下载内容之前尝试执行以下操作:[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
  • 可以在命令行一个接一个地运行吗?如果是这样,那没有效果。但这是否会永久关闭证书验证?感觉有点危险
  • 是的,这会关闭证书验证。例如,如果您使用自签名证书并且不想将其安装在所有客户端上,这将很有用。 G。测试目的。不过那可能不是你的问题

标签: powershell ssl windows-server-2012-r2


【解决方案1】:

事实证明,这是因为我们的服务器映像中禁用了 TLS 1.0 以符合 PCI DSS 3.1。

回滚对图像的更改解决了 powershell 问题。

短期内我们可以跑

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 在使用 System.Net.WebClient 之前,但我也想找到一种方法在机器级别执行它...


logged this with Chocolatey 他们解决了这个问题\o/

【讨论】:

    【解决方案2】:

    试试这个:

    $WBC = New-Object System.Net.WebClient
    
    $WBC.DownloadString("https://google.com") 
    

    【讨论】:

    • 这只是分布在两行中的相同命令。那样也行不通
    • 虽然这段代码 sn-p 可以解决问题,包括解释 really helps 以提高您的帖子质量。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人!请edit您的答案添加解释,并说明适用的限制和假设。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    • 2023-03-03
    • 1970-01-01
    • 2011-10-23
    • 2014-04-11
    相关资源
    最近更新 更多