How to fix curl: (35) Cannot communicate securely with peer: no common encryption algorithm(s)
You are likely encountering a cryptographic handshake failure between your client and the remote server. The error message curl: (35) Cannot communicate securely with peer: no common encryption algorithm(s) indicates that the versions of OpenSSL or NSS bundled with your system do not share any TLS cipher suites with the target server. This is a classic compatibility issue often seen on legacy infrastructure like CentOS 7, where the default build might rely on older NSS libraries that have dropped support for ciphers the modern server requires, or vice versa.
In the scenario provided, the user is running CentOS 7 with curl 7.29.0 and OpenSSL 1.0.1e-fips. The target, torrage.com, serves content over HTTPS and enforces a strict cipher policy that the default configuration on the CentOS machine cannot satisfy. Simply updating the CA bundle or forcing HTTP redirects won't resolve this because the TLS negotiation happens before any application-level data is transferred.
Why the Default Configuration Fails
The verbose output from the shell reveals the core of the problem: NSS error -12286 (SSL_ERROR_NO_CYPHER_OVERLAP). This confirms that the client and server spoke different cryptographic languages during the initial handshake.
On older RHEL-based systems, curl often links against NSS (Network Security Services) rather than OpenSSL directly. If your system defaults to NSS 3.17 or earlier, it may not support modern ECDHE ciphers that many servers now mandate for forward secrecy. Even if you update the CA certificates, which is a common instinctive fix, the underlying cipher suite negotiation remains broken.
The Solution: Explicit Cipher Configuration
The most reliable way to bridge this gap without waiting for a full OS upgrade or recompiling NSS from source is to explicitly tell curl to use a cipher suite that both your client and the server support. In the case of torrage.com, the working cipher identified was ECDHE_RSA_AES_128_GCM_SHA_256.
You can implement this fix in PHP by setting the CURLOPT_SSL_CIPHER_LIST option. This overrides the default cipher preference list with a specific string that forces the client to attempt the connection using that specific algorithm.
Here is how to apply the fix within your PHP script:
$ch = curl_init('https://torrage.com/torrent/640FE84C613C17F663551D218689A64E8AEBEABE.torrent');
// Disable peer verification only if you have a valid reason to do so.
// It is often better to keep SSL_VERIFY set to true (default) and fix the ciphers first.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// Explicitly set the cipher list to resolve the overlap error
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'ECDHE_RSA_AES_128_GCM_SHA_256');
$data = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
echo "Error: $error";
} else {
echo "Success";
}
Important Trade-offs and Security Considerations
While this approach resolves the immediate connectivity issue, it is critical to understand the implications of forcing a specific cipher list. By setting CURLOPT_SSL_CIPHER_LIST, you are essentially restricting the client to a single handshake method. If the server updates its TLS configuration to require a different suite (for instance, moving to 256-bit encryption or changing the key exchange algorithm