doubu7425 2014-05-29 11:31
浏览 127
已采纳

Azure网站使用curl调用时使用错误的SSL证书(错误51)

I have a project on Azure Websites, hosting an API which should be accessible only using HTTPS, using my custom .com domain. A-Records were created to the .com domain, which is working properly. The SSL Certificate were bought, uploaded and the SSL bindings are set-up correctly in the management panel.

When I access a method of the API using IE/Chrome/FF, the proper certificate (issued for my .com domain) is displayed. When I access it using the following PHP code using curl, I get an error message as if the server responded with the default *azurewebsites.com certificate, which fails as the request was made to the .com domain.

$ch = curl_init('https://mydomain.com/api/v1/method');
$cabundle = dirname(__FILE__).'/ca-bundle.crt';

curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $jsonRequest);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt( $ch, CURLOPT_CAINFO, $cabundle);

$content = curl_exec($ch);
$curlInfo = curl_getinfo($ch);

(as you can see, I'm already using the CA file required to validate the certs, if I run a file_exists passing the $cabundle variable as parameter, it returns true)

The error I get:

curl error 51: SSL: certificate subject name '*.azurewebsites.net' does not match target host name 'mydomain.com' content

As already told, if I access the same URL using a browser, the correct certificate for my .com domain is the one shown in the view certificate details screen.

What should I do either for curl requesting/validating the right certificate, or Azure respond with the correct certificate for the domain requested?

PS: setting CURLOPT_SSL_VERIFYPEER to false, or CURLOPT_SSL_VERIFYHOST to 0 or 1 are not options, security is essential to this project, and a MITM attack could be very harmful.

  • 写回答

1条回答 默认 最新

  • dongmeiba6151 2014-05-29 13:03
    关注

    Probably there are several certificates behind the same IP and you need to use SNI (server name indication, e.g. the server name is sent within the SSL handshake). Not all versions of curl support SNI, please check Use cURL with SNI (Server Name Indication).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况