Actualización PHP-FPM + Curl -- curl: (51) SSL: no alternative certificate subject name matches target host name


#1

1. Introducción

Recientemente, varios usuarios están reportando errores de conexión con certificados utilizando wildcards o combinaciones de esto, utilizando el módulo php curl, y también con la línea de comandos curl.

El error que aparece es el siguiente:

> curl: (51) SSL: no alternative certificate subject name matches target host nameaddons.prestashop.com

El error ocurre con distintas versiones de PHP (7.2, 7.3, 7.4, 8.0, 8.1 y 8.2) y en comón tienen que usa la versión cURL igual o inferior a 7.38.0.

Este artículo sirve para documentar el problema, registrar la actualización aplicada a los motores php que distribuye Core-Admin y también para dar alternativas, aunque no recomendadas, pueden ayudar a salir del paso.

2. Fallo webs conocidas:

A continuación se muestra fallos registrados para webs conocidas con las salidas concretas:

  1. Fallo con: addons.prestashop.com:

    root@node05-server:~# curl -I -v https://addons.prestashop.com/es/
    * Hostname was NOT found in DNS cache
    * Trying 104.16.211.130…
    * Connected to addons.prestashop.com (104.16.211.130) port 443 (#0)
    * successfully set certificate verify locations:
    * CAfile: none
    CApath: /etc/ssl/certs
    * SSLv3, TLS handshake, Client hello (1):
    * SSLv3, TLS handshake, Server hello (2):
    * SSLv3, TLS handshake, CERT (11):
    * SSLv3, TLS handshake, Server key exchange (12):
    * SSLv3, TLS handshake, Server finished (14):
    * SSLv3, TLS handshake, Client key exchange (16):
    * SSLv3, TLS change cipher, Client hello (1):
    * SSLv3, TLS handshake, Finished (20):
    * SSLv3, TLS change cipher, Client hello (1):
    * SSLv3, TLS handshake, Finished (20):
    * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
    * Server certificate:
    * subject: CN=*.prestashop.com
    * start date: 2024-07-02 09:42:43 GMT
    * expire date: 2025-08-03 09:42:43 GMT
    * subjectAltName does not match addons.prestashop.com * SSL: no alternative certificate subject name matches target host name 'addons.prestashop.com
    * Closing connection 0
    * SSLv3, TLS alert, Client hello (1):
    curl: (51) SSL: no alternative certificate subject name
    matches target host name ‘addons.prestashop.com’`

  2. Cómo probar si funciona con las versiones alternativas de Core-Admin o versiones más actualizadas:

    root@node05-server:~# /usr/core-admin/php/7.2/bin/curl -I -v https://addons.prestashop.com/es/
    * Trying 104.16.211.130:443…
    * Connected to addons.prestashop.com (104.16.211.130) port 443 (#0)
    * Cipher selection:
    ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
    * TLSv1.2 (OUT), TLS handshake, Client hello (1):
    * CAfile: /etc/ssl/certs/ca-certificates.crt
    * CApath: none
    * TLSv1.2 (IN), TLS handshake, Server hello (2):
    * TLSv1.2 (IN), TLS handshake, Certificate (11):
    * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
    * TLSv1.2 (IN), TLS handshake, Server finished (14):
    * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
    * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
    * TLSv1.2 (OUT), TLS handshake, Finished (20):
    * TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
    * TLSv1.2 (IN), TLS handshake, Finished (20):
    * SSL connection using TLSv1.2 /
    ECDHE-RSA-AES128-GCM-SHA256
    * Server certificate:
    * subject: CN=.prestashop.com
    * start date: Jul 2 09:42:43 2024 GMT
    * expire date: Aug 3 09:42:43 2025 GMT
    * subjectAltName: host “addons.prestashop.com” matched
    cert’s "
    .prestashop.com"
    * issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com,
    Inc.; OU=http://certs.godaddy.com/repository/;
    CN=Go Daddy Secure Certificate Authority - G2
    * SSL certificate verify ok.
    * using HTTP/1.x
    HEAD /es/ HTTP/1.1`

  3. A continuación también se proporciona código concreto php para poder realizar una prueba desde el alojamiento afectado al sitio que se intenta contactar con el fallo:

    <?php // URL del sitio a verificar $url = " https://addons.prestashop.com/es/ ";

    // Obtener información de la versión de cURL
    $curl_info = curl_version();

    // Mostrar la versión de cURL (libcurl)
    echo "Versión de cURL: " . $curl_info[‘version’] . “\n”;

    // Opcional: Mostrar más detalles de la configuración de cURL
    echo “Información completa de cURL:\n”;
    print_r($curl_info);

    echo “Comprobando conexión con: $url\n”;

    // Inicializar cURL
    $ch = curl_init();

    // Configurar opciones de cURL
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);

    // Crear un flujo para capturar la salida detallada
    $verbose = fopen(‘php://temp’, ‘w+’);
    curl_setopt($ch, CURLOPT_STDERR, $verbose);

    // Ejecutar la solicitud
    $response = curl_exec($ch);

    // Obtener información de la conexión
    $info = curl_getinfo($ch);
    $http_code = $info[‘http_code’];
    $final_url = $info[‘url’];

    // Verificar si hubo errores
    if ($response === false) {
    echo "Error en cURL: " . curl_error($ch) . “\n”;
    } else {
    echo “Conexión completada.\n”;
    echo "Código de estado HTTP: " . $http_code . “\n”;
    echo "URL final tras redirecciones: " . $final_url . “\n”;

    // Separar cabeceras y cuerpo
    $header_size = $info[‘header_size’];
    $headers = substr($response, 0, $header_size);
    $body = substr($response, $header_size);

    echo “\nCabeceras de la respuesta:\n” . $headers . “\n”;

    // Intentar obtener información del certificado
    $ssl_info = curl_getinfo($ch, CURLINFO_CERTINFO);
    if (!empty($ssl_info)) {
    echo “\nInformación del certificado SSL:\n”;
    foreach ($ssl_info as $cert) {
    echo "Emisor: " . ($cert[‘Issuer’] ?? ‘No disponible’) . “\n”;
    echo "Sujeto: " . ($cert[‘Subject’] ?? ‘No disponible’) . “\n”;
    echo "Fecha de inicio: " . ($cert[‘Start date’] ?? ‘No disponible’) . “\n”;
    echo "Fecha de expiración: " . ($cert[‘Expire date’] ?? ‘No disponible’) . “\n”;
    echo “-----------------------------------\n”;
    }
    } else {
    echo “No se pudo obtener información del certificado.\n”;
    }
    }

    // Mostrar información detallada de la conexión
    rewind($verbose);
    $verboseLog = stream_get_contents($verbose);
    echo “\nInformación detallada de la conexión:\n” . $verboseLog . “\n”;

    // Cerrar recursos
    curl_close($ch);
    fclose($verbose);
    ?>

3. Solución para el fallo

  1. Si es una instalación de core-admin, simplemente actualizar (ya debería estar, si se disponen de las actualizaciones automáticas, que es la configuración por defecto).

  2. Si hay dudas, se pueden reiniciar los motores php-fpm para asegurar que se usan las últimas versiones actualizadas:

    >> core-admin-php-fpm-restart-all.sh

  3. Alternativas no recomendadas: se pueden ajustar las siguientes dos indicaciones para desactvar la verificación de certificado. Como decimos, no se recomienda, pero puede ayudar a salir del paso:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

4. Revisión

  1. El problema fue corregido en la revisión:

    03/06/2025 – 1.0.76-16544
    >> dpkg -l | grep core-admin | head -n1
    ii core-admin-agent 1.0.76-16544 all Core Admin agent

  2. Versiones afectadas PHP y curl encontradas en el incidente:

    Versiones php afectadas: 7.2, 7.3, 7.4 para máquinas debian jessie amd64 y Debian Wheezy Amd64

    Versiones de curl por debajo 7.38.0