These two are a bad combination:
-cipher ECDHE-ECDSA-AES128-GCM-SHA256
And:
error:/SourceCache/OpenSSL098/OpenSSL098-50/src/ssl/s23_clnt.c
OpenSSL 0.9.8 does not have full EC support. And it does not support TLS 1.1 or 1.2. To get the AEAD cipher suites, you need to use TLS 1.2. That means you need OpenSSL 1.0.0 or above (IIRC).
OpenSSL 1.0.1 and 1.0.2 have them, so its probably better to use those versions.
openssl s_client -connect thepiratebay.gd:443 ...
The command you are looking for is: openssl s_client -connect thepiratebay.gd:443 -tls1_2 -servername thepiratebay.gd -CAfile XXX
. -servername
enlists SNI.
When I hit the site, the server was certified by AddTrust External CA Root. When you hit the site, it was certified by DigiCert High Assurance EV Root CA. And when you hit the site again, it was certified by COMODO ECC Certification Authority.
The different CAs and configurations speak to a distributed site behind a load balancer, with each participating web server in a slightly different configuration.
In addition to multiple web servers and configurations, some of the web servers themselves are misconfigured. They are misconfigured because they do not send the chain required to build a path for validation.
The chain should include (1) the server certificate; (2) Subordinate CAs or intermediates that form the chain to the "root". For (2), there may be one or more intermediates.
The chain should not include the root. You have to have the root, and it must be trusted.
This website seem to open fine using web browser or curl, however, I was not able to find a way to connect to it via openssl...
This is because the browsers carry around a list of hundreds of Root CAs and Subordinate CAs due to web server misconfigurations :) The list includes AddTrust External CA Root, DigiCert High Assurance EV Root CA, and COMODO ECC Root Certificate Authority.
Can anyone advice how to connect to this particular website using openssl?
OK, for the OpenSSL command, you should use -CAfile
. Usually, you just use something like openssl s_client -connect ... -CAfile DigiCertHighAssuranceEVRootCA.crt
(for the server certified with DigiCert High Assurance EV Root CA). But that won't work in this case.
You have to create a single file with the required Root and Subordinate CAs. The file should be a concatenation of the Root CAs and Subordinate CAs in PEM format required to build a path to validate the server certificate. It looks like it will need at least 3 or 4 certificates.
Or, you could forgo building you own file, and use something like cacert.pem
. But there is some risk in using the CA Zoo (my affectionate term for them). For some of the risks, see Is cacert.pem unique to my computer?.
Programmatically, you would use SSL_CTX_load_verify_locations
in OpenSSL. The concatenated PEM file is passed though CAfile
.
I'm not sure what you would use in PHP.
Related, cacert.pem
has 155 roots and subordinates. Most of them are not needed to certify the site thepiratebay.gd
:
$ cat cacert.pem | grep BEGIN | wc -l
155
Hence the reason you want to restrict your CAfile
to only those necessary to certify the site.
(comment) Not sure this is the correct thread to ask, but now I wonder if there is a way to skip some of these checks programmatically to reduce number of false negatives...
I would probably not forgo the checks. Now that you understand what's going on, it should be easier to work with the system rather than abandoning it.
To reiterate, either:
Use only necessary Root and Subordinate CAs
- You build it, concatenation of PEM certificates
- Create file
piratebay-certs.pem
- Add necessary CAs
Use a CA Zoo with predifined trusted Root and Subordinate CAs
- You download it
cacert.pem
The third option is to get the site to fix its web server configurations. But if it has not happened by now, it probably won't happen. (And it could be a design decision - the site may be using multiple CAs to ensure no one CA can DoS the site. But that does not address the incomplete chain).
And the more general observation:
I have a PHP script that checks URLs availability (basically, the script should return true for a given URL when the URL could be opened in browser and vice versa
Moving away from piratebay.gd
in particular to checking random URLs, you will probably have to use cacert.pem
. That's because a random sample of 1 million sites will likely use all of them.
If piratebay.gd
still fails, then find out what is missing from cacert.pem
, and then:
cat cacert.pem > my-expanded-cacert.pem
cat missing-cert.pem >> my-expanded-cacert.pem