这是在 mac 下 curl 使用 pem 证书时发生的问题。原因是 iOS/macOS 的默认 SSL 实现 Secure Transport 在指定证书字符串时只允许使用系统或用户钥匙串(Keychain)中的名称或 PKCS#12 编码的证书和密钥。
另外,如果使用的是当前目录下的文件最好使用“./”前缀,避免与钥匙串中的别名冲突。
如何查看自己在使用的 curl 的情况呢,使用 curl --version
:
# curl with SecureTransport
$ curl --version
curl 7.51.0 (x86_64-apple-darwin16.0) libcurl/7.51.0 SecureTransport zlib/1.2.8
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets
# curl with OpenSSL
curl 7.53.1 (x86_64-apple-darwin16.4.0) libcurl/7.53.1 OpenSSL/1.0.2k zlib/1.2.8
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP UnixSockets HTTPS-proxy
可以明显看到两者的区别。
我们可以使用 Homebrew 来安装 curl with OpenSSL:
$ brew unlink curl
$ brew install curl --with-openssl
$ brew link curl --force
# 记得在环境变量 PATH 中将 /usr/local/bin 放于 /usr/bin 之前
$ which curl
/usr/local/bin/curl
相关资料: