Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3-php5-curl on AWS EC2 instance - requested domain name does not match the server's certificate

I am using s3-php5-curl to access my AWS S3 bucket.

The getBucket() function works fine and retrieves a result when I host the PHP app myself but when I put the exact same code into a AWS EC2 instance (default AIM - Linux, Apache, PHP), I get the following error:

Warning: S3::getBucket(): [51] Unable to communicate securely with peer: requested domain name does not match the server's certificate. In /var/www/html/s3-php5-curl/S3.php on line 136 Warning: Invalid argument supplied for foreach() in /var/www/html/index.php on line 15

I can't make sense of it. What does it mean and how can I resolve it?

EDIT: I did mark this as answered but I was wrong. I have linked to what the underlying problem seems to be irrespective of whether you use the Amazon SDK or the php5-curl library. There seems to be a general problem affecting EC2 users in some regions who try to programmatically access their S3 buckets relating to SSL certification where the bucket name includes a full-stop (aka period). It has been documented but lays unresolved here.

like image 213
chrislewisdev Avatar asked Mar 18 '13 21:03

chrislewisdev


People also ask

How do I add a SSL certificate to AWS?

There are three steps to install an SSL/TLS certificate on your EC2 Windows instance: Create a Certificate Signing Request (CSR) and request your SSL certificate. Install your SSL certificate. Assign the SSL certificate to your IIS deployment.

How do I enable https on AWS?

Select the check box next to your web server instance. Select the Actions drop-down menu at the top of the page. Select Security and then Change Security Groups. For Associated security groups, select the search box and choose the security group that you created for HTTPS.


2 Answers

Try using AWS SDK for PHP 1.5.5 and make sure that you specify your region and set path_style to true. For me I'm in Singapore so my code will be:

 $s3 = new AmazonS3();
 $s3->set_region(AmazonS3::REGION_APAC_SE1);
 $s3->path_style = true;

This seems to work for me.

Hope it helps!

Cheers, Ardy

like image 160
Ardy Dedase Avatar answered Nov 08 '22 21:11

Ardy Dedase


Unable to communicate securely with peer: requested domain name does not match the server's certificate.

This error occurs when CURL tries to verify the certificate. While you can disable this setting with curl options, why the certificate name mismatch exists.

It looks like the library you have is somewhat dated, you may want to consider using this: http://aws.amazon.com/sdkforphp/

like image 32
datasage Avatar answered Nov 08 '22 20:11

datasage