Problem/Motivation
SSL negotiation with *.api.mailchimp.com may fail in Debian 8 and Ubuntu 15.04 using PHP 5.6. The error message is simply
Notice: Undefined property: stdClass::$data in DrupalMailchimp
Some investigation (#11) and support from MailChimp.com (#8, #12) has revealed that a missing Root CA in /etc/ssl/certs/ca-certificates.crt may cause the problem.
The Root CA used to sign *.api.mailchimp.com was removed from Mozilla NSS CA Certificates bundle in February 2015, and was removed from Debian 8's ca-certificates package in January 2016.
Proposed resolution
None. This is a problem on the Mailchimp side and not something that should be fixed (except by Mailchimp rolling out a certificate signed by a properly secure CA).
Solution / Workaround
The following should work on affected Debian or Ubuntu systems:
- Become root:
sudo su - Add the missing .crt file back into /usr/share/ca-certificates:
cd /usr/share/ca-certificates cat > GTE_CyberTrust_Global_Root.crt << __EOF__ -----BEGIN CERTIFICATE----- MIICWjCCAcMCAgGlMA0GCSqGSIb3DQEBBAUAMHUxCzAJBgNVBAYTAlVTMRgwFgYD VQQKEw9HVEUgQ29ycG9yYXRpb24xJzAlBgNVBAsTHkdURSBDeWJlclRydXN0IFNv bHV0aW9ucywgSW5jLjEjMCEGA1UEAxMaR1RFIEN5YmVyVHJ1c3QgR2xvYmFsIFJv b3QwHhcNOTgwODEzMDAyOTAwWhcNMTgwODEzMjM1OTAwWjB1MQswCQYDVQQGEwJV UzEYMBYGA1UEChMPR1RFIENvcnBvcmF0aW9uMScwJQYDVQQLEx5HVEUgQ3liZXJU cnVzdCBTb2x1dGlvbnMsIEluYy4xIzAhBgNVBAMTGkdURSBDeWJlclRydXN0IEds b2JhbCBSb290MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCVD6C28FCc6HrH iM3dFw4usJTQGz0O9pTAipTHBsiQl8i4ZBp6fmw8U+E3KHNgf7KXUwefU/ltWJTS r41tiGeA5u2ylc9yMcqlHHK6XALnZELn+aks1joNrI1CqiQBOeacPwGFVw1Yh0X4 04Wqk2kmhXBIgD8SFcd5tB8FLztimQIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAG3r GwnpXtlR22ciYaQqPEh346B8pt5zohQDhT37qw4wxYMWM4ETCJ57NE7fQMh017l9 3PR2VX2bY1QY6fDq81yx2YtCHrnAlU66+tXifPVoYb+O7AWXX1uw16OFNMQkpw0P lZPvy5TYnh+dXIVtx6quTx8itc2VrbqnzPmrC3p/ -----END CERTIFICATE----- __EOF__ - Now:
dpkg-reconfigure ca-certificatesand choose ask to Trust new certificates from certificate authorities? in the first dialog. - A second screen appears with a list of all the CA certificates. You should see the GTE_CyberTrust_Global_Root.crt cert we just added at the very top of the list. Press Space Bar and it should toggle the certificate on with an asterisk showing. Now hit Tab and Enter on the OK.
- You should see output similar to this:
root@yourserver:/usr/share/ca-certificates# dpkg-reconfigure ca-certificates Processing triggers for ca-certificates (20141019+deb8u1) ... Updating certificates in /etc/ssl/certs... 1 added, 0 removed; done. Running hooks in /etc/ca-certificates/update.d....done. - That's it! Test the Mailchimp again and it should be working.
Original report from @Leucocepha
I am setting up a new website and wish to be able to view MailChimps in my website.
I initially struggled to get the MCAPI working, but now that I have I am getting the script error "Notice: Undefined property: stdClass::$data in DrupalMailchimp"
Is there something that I am doing wrong? I need to get this working urgently.
Comments
Comment #1
Leucocepha commentedIs there anyone out there to help me with this?
I'm completely unable to use this module and it is the main reason for rebuilding my website.
Comment #2
jami commentedHi Leucocepha. I'd like to help you out. What URL are you viewing when you see the error?
Comment #3
Leucocepha commentedHi Jami,
I'd really appreciate the help. I am getting the error when I go into Admin -> Configuration -> Mail Chimp -> Lists.
I am also getting the same error on the "Campaign" tab along with (but I figure if I fix one, I fix them all) ...
Mailchimp_HttpError: MailChimp API call to templates/list failed: Error opening socket ssl://us9.api.mailchimp.com:443: in DrupalMailchimp->call() (line 89 of xxxxxxx\modules\mailchimp\includes\mailchimp.inc).
I've considered that openSSL is not working on my webserver... Running Windows 2012 R2 with IIS and MySQL PHP 5.6.8.
PHP reports openSSL is enabled and working (I've gone through the blog posts saying how to correctly enable it with paths etc). I'm also running Facebook Pull on my website which I'm thinking pulls from the SSL site and that is working okay.
The customer is very keen to get a new website up and running and this is the last hurdle that I need to overcome so I am quite desperate to get it working.
Comment #4
Leucocepha commentedPlease? Anyone have any ideas?
Comment #5
ruscoe commentedWhat happens if you execute this code somewhere within your Drupal site?
$resultshould be an array containing the key 'code' with the value '200'. If not, there's an issue making HTTP requests from Drupal that needs to be tracked down.Comment #6
Leucocepha commentedThanks Ruscoe,
When I enter that code and output $result using "print_r(array_values($result));" I get an error saying that it isn't an array. So when I just output $result as text I get stdClass Object ( [code] => 0 [error] => Error opening socket ssl://us10.api.mailchimp.com:443 )
If I change the website in your code to "Https://www.facebook.com" I get ...
stdClass Object ( [request] => GET / HTTP/1.0 User-Agent: Drupal (+http://drupal.org/) Host: www.facebook.com [data] =>[protocol] => HTTP/1.1 [status_message] => OK [headers] => Array ( [pragma] => no-cache [cache-control] => private, no-cache, no-store, must-revalidate [expires] => Sat, 01 Jan 2000 00:00:00 GMT [p3p] => CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p" [strict-transport-security] => max-age=15552000; preload [x-frame-options] => DENY [x-xss-protection] => 0 [x-content-type-options] => nosniff [set-cookie] => reg_fb_ref=https%3A%2F%2Fwww.facebook.com%2F; path=/; domain=.facebook.com; httponly,reg_fb_gate=https%3A%2F%2Fwww.facebook.com%2F; path=/; domain=.facebook.com; httponly [vary] => Accept-Encoding [content-type] => text/html [x-fb-debug] => 0bRYGyLAKqI0IglEb/LQ2K4SrFK8JE/YPSdBNGHzn76y5ZlNkYdlsyBK95WIo2dLk3EivCNK/5x3CaUzQG4kUw== [date] => Tue, 12 May 2015 11:40:19 GMT [connection] => close ) [code] => 200 )
and similarly if I use the URL for this thread results in something very similar.
Any ideas why Drupal can not access the Mailchimp data, but appears to be able to with other sites?
Comment #7
ruscoe commentedIt's possible that MailChimp is using a different version/configuration of SSL than Facebook and other services you're able to connect to. I don't have access to an instance of IIS to test with.
What I recommend is contacting MailChimp's API support team and asking them about connecting to their API from IIS. They may be aware of an issue or at least be willing to monitor connections from your IP address to see what the problem is.
Comment #8
Leucocepha commentedThis is the response I got from MailChimp's API support Team....
Thanks for reaching out. Here in MailChimp support, we're really focused on using the API itself, so we're a bit limited when it comes to troubleshooting environments where the calls are made. In this case, it does seem to be related to SSL, but I wouldn't really be the best resource for editing SSL permissions when making requests from a Drupal site. One thing to test would be to make a call to a 2.0 endpoint, and then a 1.3 endpoint, as the 1.3 endpoints allow for non-encrypted calls to be made. Here's the 2.0 call you can test with:
https://us10.api.mailchimp.com/2.0/helper/ping?apikey=<<>>
The 1.3 call you can try out is:
http://us10.api.mailchimp.com/1.3?method=ping&apikey=<<>>
If the 1.3 call works, then that would narrow down that it's related to making a connection to an SSL-encrypted endpoint. It looks like you're using PHP when making this call, and in more recent version of PHP, the curl function doesn't include the correct certs to make these kinds of connections. I'd recommend trying out the steps in this guide to grab those certs to see if it helps: http://stackoverflow.com/questions/9774349/php-curl-not-working-with-https
I can confirm that it works with the 1.3 API without SSL, but doesn't with the 2.0 API with SSL
The website the reference suggests that I need to add a .pem file for certificate verification. I am using PHP 5.6.8, can anyone confirm if this is required? And if so, how do I add it?
Comment #9
ruscoe commentedLooks like you're going to need to create your own SSL certificate if you don't already have one (the .pem file.)
I found a couple of resources here and here that look promising, but my experience is entirely with Linux-based servers so I can't provide any personal insight.
Once you have that, it should just be a case of informing cURL of the file's location: http://stackoverflow.com/a/17409437
Comment #10
Leucocepha commentedI'm afraid this makes no sense to me, I can create an SSL certificate, but that isn't going to help with accepting the Mailchimp SSL certificate.
Also the stackoverflow post doesn't help with how to apply this to a drupal website. (I'm a drupal Newbie).
Anyway, I have resolved this problem by reluctantly downgrading my php to 5.5.
Now if anyone can tell me how I can display mailchimp campaigns in a node, that would be fantastic.
Comment #11
kaareI've spent some time investigating this, and the problem seems to be over at mailchimp's api server. This script will fail:
Nesting down, the problem still exists on the command line (Curl 7.38):
So turning validation off works:
Using any of the certificate bundles either provided by debian (
/etc/ssl/certs/ca-certificates.crt) or the one generated from mozilla.org over at http://curl.haxx.se/docs/caextract.html fails:Trying the trick mentioned in the above error message with creating a trusted certificate based on the output from the
opensslcommand fails:And there is no php.ini directive to turn of curl certificate validation, it has to be done when you have the curl handler:
Which we don't have. Not even in
drupal_http_request().No way to hack around this. Except implementing your own HTTP request function and point the variabledrupal_http_request_functionto it.This is a result of increased security in Curl, which are not followed up by MailChimp. I've sent a new support message with pretty much the same debugging info. Waiting for reply.
Comment #12
kaareFrom Mailchimp support:
I'm using Debian 8. For fun I tried to use a replacement
/etc/ssl/certs/ca-certificates.crtfrom Debian 7 and it worked. Trying to manually add the certificates missing in Debian 8 from Debian 7 failed. Further experimentation lead me to /etc/ca-certificates.conf which had some certs disabled, and it is also auto-generated.A simple
Fixed the SSL problem. This should fix it in Ubuntu 15.04 as well.
Comment #13
kaareComment #14
das-peter commentedA possible workaround is to use cURL HTTP Request.
Comment #15
greg boggsIt looks like both proposed fixes work and both are outside the code base of the module. Hopefully, this will improve on the API side in the near future for Debian server administrators.
Comment #16
Joram commentedI'm using xampp localhost on Windows 10 and php 5.6. In php.ini the line "extension=php_openssl.dll" is uncommented.
When refreshing lists i encountered the same error:
"Notice: Undefined property: stdClass::$data in DrupalMailchimp".
Checking "Recent log messages" i got:
"An error occurred requesting list information from Mailchimp. "MailChimp API call to lists/list failed: Error opening socket ssl://us11.api.mailchimp.com:443: "".
#14 fixed the problem for me and now lists are loading in perfectly. Thank you.
Comment #18
ws_cyril commentedI had the same error :
Mailchimp_HttpError: MailChimp API call to templates/list failed: Error opening socket ssl://us7.api.mailchimp.com:443: in DrupalMailchimp->call() (line 89 of xxxxxxx\modules\mailchimp\includes\mailchimp.inc).
I tried the solution #14 and it worked for me ! Thanks !
Comment #19
damien_vancouver commentedAs of early January 2016, this problem is back for any Linux distributions that use Mozilla's NSS CA-Certificates bundle. This includes Debian 8 Jessie, as well as probably Ubuntu and possibly RHEL/Fedora as well.
I've posted the solution at the end of this comment. Here is why the problem has occurred.
Mailchimp uses a certificate for *.api.mailchimp.com, which is signed with a Root CA that has been removed from Mozilla's trusted bundle (and thereby Debian Linux). This bad root CA is called "GTE_CyberTrust_Global_Root.crt". The reason that this root CA cert was finally removed is that it is insecure - it uses MD5 (not even SHA1!) for a signature algorithm and it is only a 1024 bit RSA key (which is WAY too weak for a Root CA) Mozilla has been trying to get this cert removed since 2014 and it's finally happened and now has trickled down to the "ca-certificates" package in Debian, which was updated earlier this month.
More info here:
Mozilla bug that started it all: https://bugzilla.mozilla.org/show_bug.cgi?id=1047011
Debian bug for Debian to update its certificates: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=806239
Debian package changelog where you can see it being removed last version: http://metadata.ftp-master.debian.org/changelogs/main/c/ca-certificates/...
Official announcement from Mozilla on the removal of weak keys: https://blog.mozilla.org/security/2015/01/28/phase-2-phasing-out-certifi...
So, if you've installed Linux updates (which most everybody responsible did, after last week's unrelated Linux kernel privilege escalation bug), then you should have the new ca-certificates, and your Mailchimp API calls will have stopped working with an error like this:
"MailChimp API call to <em class="placeholder">lists/list</em> failed: Error opening socket ssl://us9.api.mailchimp.com:443: "Solution
The solution is simple enough - add the missing certificate back into the trusted CA certificates. For Debian or Ubuntu, you can do that with the following steps:
sudo sudpkg-reconfigure ca-certificatesand choose ask to Trust new certificates from certificate authorities? in the first dialog.I have updated the issue description with this solution so that it's up to date.
Comment #20
damien_vancouver commentedComment #21
lukas.fischer commented#19 fixed it. Thank you very much @damien_vancouver
Comment #22
apermuy commented#14 works for me.
Comment #23
Max_Headroom commentedPlease note: #14 may cause other problems where drupal_http_request is needed. In my case Services stopped working.
Comment #24
raprieto commentedI'm using Debian 8 and PHP7 and was getting
An error occurred requesting list information from MailChimp. "MailChimp API call to lists/list failed: Error opening socket ssl://us7.api.mailchimp.com:443: "
#19 worked for me. Thank you.