【发布时间】:2016-08-18 21:23:47
【问题描述】:
我正在使用 TestApi 使用 PEM 和 KEY 文件检查 SSL 连接。 但是,如果我编辑我的私钥,似乎无论如何我都可以获得标题。 它真的应该这样吗?我从来没有收到关于密钥的错误。但是,当认证不正确时,我确实会出错。
我总是得到一个
HTTP/1.1 200 OK 内容类型:text/xml;charset=UTF-8 内容长度:5983 日期:2016 年 8 月 18 日星期四 21:10:33 GMT 服务器:TheServer TheServer BUS RP 接口版本:4.0。 0
接着是来自htmlentities 的大量文本。
$url = "https://mylink?wsdl";
// cert file/pass (same as pfx above but converted to pem and key)
$cert_file = "myPemfile.pem";
$cert_password = "myKeyfile.key"; // I've intentionally set the wrong key... but God knows why it still works
// server cert which we trust (this is needed when using VERIFYPEER below)
$cert_server = "serverCA.pem";
$ch = curl_init();
$options = array(
CURLOPT_RETURNTRANSFER => true, //return output
CURLOPT_HEADER => true, // just to see header response
CURLOPT_FOLLOWLOCATION => true, // cant figure this out yet (probably means internal redirect within $url)
CURLOPT_SSL_VERIFYHOST => 2, //ok
CURLOPT_SSL_VERIFYPEER => true, // yes
CURLOPT_CAINFO => $cert_server, // set it
CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)', // ? seems this is needed
CURLOPT_VERBOSE => false, // change to true/false if you want/(dont want) verbose
CURLOPT_URL => $url , //set
CURLOPT_SSLCERT => $cert_file, //set
//CURLOPT_SSLCERTTYPE => 'PEM', // well.. default is PEM anyway
CURLOPT_SSLKEY => $cert_password, //set
);
curl_setopt_array($ch , $options);
$output = curl_exec($ch);
if(!$output)
{
echo "Curl Error : " . curl_error($ch);
}
else
{
echo "<br /> db: output unparsed :<br />" . $output . "<br /> db: DONE <br /><br />";
echo htmlentities($output);
}
【问题讨论】:
-
我一直对此有点模糊,但发现不需要设置 certs\keys 但发现 curl 会自己处理它。
-
在这种情况下,我什至不需要指出密钥文件就可以了。我不知道这是否只是因为它是一个 testApi ..也许?但是你所说的“curl 自己照顾它”听起来并不令人信服,也没有任何意义......但是......我不知道你可能是对的
-
你的浏览器会自己处理它,对吧? curl 有一个证书包,就像浏览器一样。但是就像我说的有点朦胧,我确实使用 curl 通过 https 来命中 api 端点,而没有添加任何特殊的东西,因为它是 https 与 http。
-
好吧..这更有意义。但是忽略私钥?真的吗?我更倾向于我在这里做了一些事情。无论是代码还是思想
-
我刚刚看到 PEM 文件包含私钥...为什么我需要一个单独的 KEY 文件?...呵呵...