cURL SSL 连接错误 35,NSS 错误 -5961

标签 curl ssl windows-7 centos

我有一台只能通过端口 768 上的 HTTPS 访问的远程 Windows 7 服务器。该服务器正在使用来自本地 CentOS 服务器中列出的 CA 的签名证书。

每当我尝试使用以下命令通过 cURL 访问远程服务器时,都会出现如下错误:

[usr@serv certs]# curl -3 -v https://1.1.1.1:768/user/login
* About to connect() to 1.1.1.1 port 768 (#0)
*   Trying 1.1.1.1... connected
* Connected to 1.1.1.1 (1.1.1.1) port 768 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* NSS error -5961
* Closing connection #0
* SSL connect error
curl: (35) SSL connect error

(请注意,出于安全原因,IP 地址已被隐藏)。

我正在运行以下版本的 cURL:

curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2

值得注意的是,这适用于另外两台运行 Windows XP 而不是 Windows 7 的远程服务器。

我曾尝试强制 cURL 使用 SSLv3(使用 -3 标志和 -SSLv3 标志)但没有成功。


我刚刚在运行 Raspbian 的 Raspberry Pi 上测试了相同的 CURL 命令,并且能够成功连接。因此,我认为这可能是 CentOS 服务器上使用的 cURL 版本的问题。树莓派正在运行以下版本:

curl 7.26.0 (arm-unknown-linux-gnueabihf) libcurl/7.26.0 OpenSSL/1.0.1e zlib/1.2.7 libidn/1.25 libssh2/1.4.2 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtmp rtsp scp sftp smtp smtps telnet tftp
Features: Debug GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP

最佳答案

使用 NSS 的

curl 默认从 PEM 格式的 "/etc/pki/tls/certs/ca-bundle.crt" 读取根 CA 证书。

* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/ca-bundle.crt

您可以通过 curl 的选项 --cacert 使用包含 CA 证书的 PEM 文件指定另一个(您的)CA 证书(或捆绑在 NSS Shared DB 上)。

如果您没有使用 --cacert 选项手动指定证书,NSS 会尝试从 NSS 数据库(位于 /etc/pki/nssdb) 自动。您可以通过 curl 的选项 --cert 指定它的昵称,如果 key 嵌入在证书中,这应该足够了,如果没有,您可以使用 - 指定带有证书 key 的 PEM 文件-键。如果 key 受密码保护,您可以通过 curl 的选项 --pass 提供它,这样您就可以使用 nss-tools 将证书导入 NSS 共享数据库。 (yum 安装 nss-tools)

添加证书(普通命令行)

certutil -d sql:/etc/pki/nssdb -A -t <TRUSTARGS> -n <certificate nickname> -i <certificate filename>

关于信达

指定要在现有证书中修改或在创建证书或将其添加到数据库时应用于证书的信任属性。

There are three available trust categories for each certificate, expressed in this order: " SSL , email , object signing ". In each category position use zero or more of the following attribute codes:

  • p prohibited (explicitly distrusted)
  • P Trusted peer
  • c Valid CA
  • T Trusted CA to issue client certificates (implies c)
  • C Trusted CA to issue server certificates (SSL only) (implies c)
  • u Certificate can be used for authentication or signing
  • w Send warning (use with other attributes to include a warning when the certificate is used in that context)

The attribute codes for the categories are separated by commas, and the entire set of attributes enclosed by quotation marks. For example:

-t "TCu,Cu,Tuw"

信任根 CA 证书以颁发 SSL 服务器证书

certutil -d sql:/etc/pki/nssdb -A -t "C,," -n <certificate nickname> -i <certificate filename> 

导入中级 CA 证书

certutil -d sql:/etc/pki/nssdb -A -t ",," -n <certificate nickname> -i <certificate filename>

信任自签名服务器证书

certutil -d sql:/etc/pki/nssdb -A -t "P,," -n <certificate nickname> -i <certificate filename> 

为SSL客户端认证添加个人证书和私钥

pk12util -d sql:/etc/pki/nssdb -i PKCS12_file_with_your_cert.p12

列出存储在 NSS 数据库中的所有证书

certutil -d sql:/etc/pki/nssdb -L

列出证书的详细信息

certutil -d sql:/etc/pki/nssdb -L -n <certificate nickname>

删除证书

certutil -d sql:/etc/pki/nssdb -D -n <certificate nickname>

希望这对您有所帮助。

关于cURL SSL 连接错误 35,NSS 错误 -5961,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21887315/

相关文章:

curl - 如何使用 curl 在分块帖子中指定 block 大小

java - 在 keystore 传输安全层 (TLS) 中保护根证书和中间证书

java - Android 4.4.2 SSL 握手中止

python - cwd的字符串变量

laravel - PHPUnit 上下文中的 Guzzle curl 错误 51

ios - curl 命令、-H 选项和 Square API

apache - 为什么 Google 不通过 SSL 提供 adsense?

windows-7 - 使用 PowerShell 运行应用程序并等待其完成

delphi - 调用 ConvertStringSidToSid() 时为 "System Error. Code: 87"

php - lib CURL 不遵守超时,因为它显示文档不存在