使用PEM文件进行SSL身份验证(cURL + PHP)

时间:2016-12-27 11:42:01

标签: php ssl curl

我已经能够在其他网站上做类似的事情,但现在我在使用特定网站上的SSL证书进行身份验证时遇到了问题。当我在浏览器中安装证书时,它完美地运行。但是,当我将.pfx文件转换为.pem文件并尝试将其与php + curl一起使用时,它不起作用。

我的代码如下:

<?php
$url = 'https://www2.agencianet.fazenda.df.gov.br/Inicio/Restrita/';
$pemfile = __DIR__ . '/pubKEY.pem';
$keyfile = __DIR__ . '/priKEY.pem';

$ch = curl_init($url);
$options = array(
    CURLOPT_FRESH_CONNECT => true,
    CURLOPT_HEADER => 1,
    CURLOPT_RETURNTRANSFER =>true,
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_HTTPHEADER => array(
        "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        "Accept-Language:pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2,es;q=0.2,gl;q=0.2,nl;q=0.2",
        "Cache-Control:no-cache",
        "Connection:keep-alive",
        "Host:www2.agencianet.fazenda.df.gov.br",
        "Pragma:no-cache",
        "Referer:http://agnet.fazenda.df.gov.br/",
        "Upgrade-Insecure-Requests:1",
        "User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"
    ),
    CURLOPT_SSL_VERIFYHOST => 0,
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_SSLVERSION => 0,
    CURLOPT_SSLCERT => $pemfile,
    CURLOPT_SSLKEY => $keyfile,
    CURLOPT_SSLCERTTYPE => 'PEM'
);
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
print_r($data);
print_r(curl_error($ch));
curl_close($ch);

pem文件是:

  

drive.google.com/drive/folders/0BxSFCb666mqCbUJIMlhIMjh0aGM?usp=sharing

一些图片:

[Image 1] [Image 2]

0 个答案:

没有答案