首页 文章

AWS SSL安全性错误:[curl] 60:SSL证书概率...:无法获得本地颁发者证书

提问于
浏览
24

我正在尝试使用 Amazon SDK for php从运行 AppServ 2.5.10 (包括 Apache 2.2.8php 5.2.6mysql 5.0.51bphpMyAdmin 2.10.3 )的我的(localhost)Windows 8计算机连接亚马逊的S3文件 .

为了与 Amazon SDK's 命名空间功能兼容,我通过下载其压缩文件并将其解压缩来替换版本为 5.3.28 的php .

我的PHP代码可以正常访问 Amazon EC2 中的 S3 文件,但它在我的Windows本地主机中失败了 .

但是当我运行php srcipt来读取Windows本地主机中的 Amazon S3 存储桶文件时,我收到了如下SSL错误:

致命错误:未捕获异常'Guzzle \ Http \ Exception \ CurlException',消息'[curl] 60:SSL证书问题:无法获取本地颁发者证书[url] https://images-st.s3.amazonaws.com/ us / 123977_sale_red_car.png'在C:\ AppServ \ www \ ecity \ vendor \ guzzle \ guzzle \ src \ Guzzle \ Http \ Curl \ CurlMulti.php:342堆栈跟踪:#0 C:\ AppServ \ www \ ecity \ vendor \ guzzle \ guzzle \ src \ Guzzle \ Http \ Curl \ CurlMulti.php(283):Guzzle \ Http \ Curl \ CurlMulti-> isCurlException(Object(Guzzle \ Http \ Message \ Request),Object(Guzzle \ Http \ Curl \ CurlHandle),数组)#1 C:\ AppServ \ www \ ecity \ vendor \ guzzle \ guzzle \ src \ Guzzle \ Http \ Curl \ CurlMulti.php(248):Guzzle \ Http \ Curl \ CurlMulti-> processResponse(Object( Guzzle \ Http \ Message \ Request),Object(Guzzle \ Http \ Curl \ CurlHandle),数组)#2 C:\ AppServ \ www \ ecity \ vendor \ guzzle \ guzzle \ src \ Guzzle \ Http \ Curl \ CurlMulti.php (231):Guzzle \ Http \ Curl \ CurlMulti-> processMessages()#3 C:\ AppServ \ www \ ecity \ vendor \ guzzle \ guzzle \ src \ Guzzle \ Http \ Curl \ CurlMulti.php(215):Guzzle \ HTTP \卷曲\ CurlMulti-> execu teHandles()#4 C:\ AppServ \ www \ ecity \ ven在第288行的C:\ AppServ \ www \ ecity \ vendor \ aws \ aws-sdk-php \ src \ Aws \ Common \ Client \ AbstractClient.php

我从http://curl.haxx.se/ca/cacert.pem下载证书,并在php.ini中定义如下:

curl.cainfo = "C:\AppServ\cacert.pem"

但我仍然有同样的错误 . 看来php并不尊重 php.ini 中定义的 curl.cainfo .

根据 localhost/phpinfo.php ,我的php版本是 5.3.28 .

我还检查 cainfo 参数是否正确 C:\AppServ\cacert.pem 使用

echo ini_get( "curl.cainfo" ) ;

在PHP脚本中 .

高于 5.3 的Php版本应支持 php.ini 中的 curl.cainfo .

在Windows的命令行中,我检查卷曲行为,它似乎工作正常 .

C:\Users\Jordan>curl  https://s3-us-west-2.amazonaws.com/images-st/aaa.txt
   curl: (60) SSL certificate problem: unable to get local issuer certificate
   ......

C:\Users\Jordan>curl --cacert C:\AppServ\cacert.crt  https://s3-us-west-2.amazonaws.com/images-st/aaa.txt
  This is aaa.txt file.
  Stored in Amazon S3 bucket.

是因为我在Windows中使用的Apache与我从http://windows.php.net/download/ VC9 x86线程安全(2014年6月11日01:09:56)zip版本下载的php 5.3.28 zip文件不匹配 .

在我的apache的httpd-ssl.conf文件中,即使我在Windows 8中使用本地主机,也有以下设置 .

<VirtualHost _default_:443>

DocumentRoot "C:/AppServ/www"
ServerName localhost:443
ServerAdmin webmaster@localhost.com
ErrorLog "C:/AppServ/Apache2.2/logs/error.log"
TransferLog "C:/AppServ/Apache2.2/logs/access.log"

SSLEngine on

SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "C:/AppServ/Apache2.2/conf/mydomain.cert"
SSLCertificateKeyFile "C:/AppServ/Apache2.2/conf/mydomain.key"

<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
</FilesMatch>
<Directory "C:/Apache2.2/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

BrowserMatch ".*MSIE.*" \
     nokeepalive ssl-unclean-shutdown \
     downgrade-1.0 force-response-1.0

CustomLog "C:/AppServ/Apache2.2/logs/ssl_request.log" \
      "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

现在我想知道是什么问题以及如何连接到 Amazon S3 存储桶文件和 RDS 数据库而不产生这些 curl 无法从我的Windows 8本地主机获取本地颁发者证书问题 .

任何建议?

3 回答

  • 31

    正如Jeremy Lindblom在评论中所提到的, AWS SDK v2 的解决方案是在实例化SDK时设置 ssl.certificate_authority 选项:

    $aws = Aws\Common\Aws::factory(array(
        'region' => 'us-west-2',
        'ssl.certificate_authority' => '/path/to/updated/cacert.pem'
    ));
    

    http://docs.aws.amazon.com/aws-sdk-php/guide/latest/faq.html#what-do-i-do-about-a-curl-ssl-certificate-error


    我将在 AWS SDK v3 中添加更改,这是新方法:

    $client = new DynamoDbClient([
        'region'  => 'us-west-2',
        'version' => 'latest',
        'http'    => [
            'verify' => '/path/to/my/cert.pem'
        ]
    ]);
    

    http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/configuration.html#verify

  • 2

    我得到了同样的错误如果你想使用http,那么你可以使用以下解决方案:

    Error executing "PutObject" on "https://s3-ap-southeast-2.amazonaws.com/mybucketname/TestBanner1_e1d8d74e41"; AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
    

    我已经通过使用http方法解决了这个问题,使用安全的方法输入_ curl.cainfo =“/ path / to / file.cacert.pem”_在php.ini文件中是不安全的:

    Solution

    'options' => [
    'scheme' => 'http',
    ],
    

    Complete Example code:

    // ...
    's3bucket' => [
    'class' => \frostealth\yii2\aws\s3\Storage::className(),
    'region' => 'ap-southeast-2',
    'credentials' => [ // Aws\Credentials\CredentialsInterface|array|callable
    'key' => 'JGUTEHCDE.............OSHS',
    'secret' => 'SJEUC-----------jzy1-----rrT',
    ],
    'bucket' => 'yours3bucket',
    //'cdnHostname' => 'http://example.cloudfront.net',
    'defaultAcl' => \frostealth\yii2\aws\s3\Storage::ACL_PUBLIC_READ,
    'debug' => false, // bool|array
    'options' => [
    'scheme' => 'http',
    ],
    
    ],
    // ...
    
  • 6

    对于使用WampServer的用户,请打开 php.ini 文件,然后向下滚动到底部并添加以下内容:

    curl.cainfo = "C:\wamp\bin\php\php7.2.3\cacert.pem"

    确保您使用的当前php版本的文件夹中包含 cacert.pem 文件 . 在我的情况下,我在 php7.2.3 文件夹中 .

相关问题