Base de connaissances:
fonction smarty pour expiration ssl libs/plugins/function.aqssl_info.php
Publié par Ghislain AQUEOS, Modifié en dernier par Ghislain AQUEOS sur 21 May 2019 09:28 AM
<?php

/*

 * Smarty plugin

 * -------------------------------------------------------------

 * File:     function.aqssl_info.php

 * Type:     aqssl_info

 * Name:     aqssl_info

 * Purpose:  function les info du certificat

 * -------------------------------------------------------------

 */

function smarty_function_aqssl_info($params, Smarty_Internal_Template $template)

{

        $orignal_parse = parse_url('https://'.$params['domaine'], PHP_URL_HOST);

        $get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));

        $read = stream_socket_client("ssl://".$orignal_parse.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);

        $cert = stream_context_get_params($read);

        $certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']);

        setlocale (LC_TIME, 'fr_FR.utf8','fra');

        $expirele = strftime("%A %d %B %Y",strtotime(date(DATE_RFC2822,$certinfo['validTo_time_t'])));

        if( $params['info'] == 'date' ){

                $retour = $expirele;

        } else {

                $retour  = '<p> Origine du certificat: '.$certinfo['issuer']['O'].'/'.$certinfo['issuer']['CN']."\n";

                $retour .= '<br\> Domaine principal: '.$certinfo['subject']['CN']."\n";

                $retour .= '<br\> Domaines alternatifs: '.$certinfo['extensions']['subjectAltName']."\n";

                $retour .= '<br\> Valide depuis: '.strftime("%A %d %B %Y",strtotime(date(DATE_RFC2822,$certinfo['validFrom_time_t'])))."\n";

                $retour .= '<br\> Valide jusqu\'a: '.$expirele."\n";

                $retour .= '</p>';

        }

    return $retour;

}

?>
(0 vote(s))
Utile
Pas utile

Commentaires (0)