对单个特定https
端点的请求在我的一台服务器上失败,PHP CURL 出现"NSS:找不到客户端证书(未指定昵称)"错误。
当我使用verbose
选项从命令行运行相同的查询时,我遇到了相同的错误,但之后我也得到了有效的响应(在同一个 CURL 请求中出现错误之后)。
然后,我为我的 PHP CURL 请求启用了verbose
选项,并将其显示为如下所示的测试:
$error = curl_error($curl);
if ($error) {
echo "cURL Error #:" . $error;
rewind($verbose);
$verboseLog = htmlspecialchars(stream_get_contents($verbose));
echo "<pre>";
print_r($verboseLog);
} else {
echo $response;
}
并得到这个作为输出:
cURL Error #:NSS: client certificate not found (nickname not specified)
* About to connect() to <address> port 8001 (#0)
* Trying <ip>... * connected
* Connected to <address> (<ip>) port 8001 (#0)
* skipping SSL peer certificate verification
* NSS: client certificate not found (nickname not specified)
* SSL connection using TLS_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
* subject: CN=*.<address>m,O=XXX A.S.,OU=IT,L=Umraniye,ST=Istanbul,C=TR
* start date: Jun 11 12:52:03 2015 GMT
* expire date: Jun 09 14:16:13 2018 GMT
* common name: *.<address>
* issuer: CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE
> POST /<url_part> HTTP/1.1
Host: <address>:8001
Accept: */*
Accept-Encoding: deflate, gzip
authorization: Basic UlBlahBlahnJrcjEyMzQ1Ng==
cache-control: no-cache
content-type: application/json
postman-token: eeefe018-7cac-1706-7b6d-847800a7ad0f
Content-Length: 333
< HTTP/1.1 200 OK
< set-cookie: sap-usercontext=sap-client=100; path=/
< set-cookie: SAP_SESSIONID_CFP_100=ohZvfO5ZOwq_LTE76Zgz9L-C0NdhlRHngM0AF6R3IFY%3d; path=/
< content-type: application/json; charset=utf-8
< content-length: 1150
< cache-control: max-age=0
< sap-cache-control: +180
< sap-isc-uagent: 0
<
* Connection #0 to host <address> left intact
* Closing connection #0
因此,CURL 请求以错误完成,但在详细日志中,我们看到在错误后也获取了有效的响应。
这是我的问题:
- 只要其他不同的
https
端点完全正常工作,有什么方法可以克服此NSS问题?它是否与端点的服务器配置相连并且可以在那里解析? - 如果第一项失败,是否可以不抛出 CURL NSS 错误,而是获得响应?
CURLOPT_FAILONERROR
选项无济于事。
CURL 是使用 NSS 构建的:
curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz
更新:
第二项可以关闭,因为这个错误真的很奇怪:curl_error
返回错误,但curl_exec
同时返回有效的响应。
尝试为证书提供绝对路径并添加"./"前缀。例如"./path-to-your-cert">