public static function getCertificateNames($certificate)
    {
        if (is_array($certificate)) {
            $info = $certificate;
        } elseif (CaBundle::isOpensslParseSafe()) {
            $info = openssl_x509_parse($certificate, false);
        }

        if (!isset($info['subject']['commonName'])) {
            return null;
        }

        $commonName = strtolower($info['subject']['commonName']);
        $subjectAltNames = array();

        if (isset($info['extensions']['subjectAltName'])) {
            $subjectAltNames = preg_split('{\s*,\s*}', $info['extensions']['subjectAltName']);
            $subjectAltNames = array_filter(array_map(function ($name) {
                if (0 === strpos($name, 'DNS:')) {
                    return strtolower(ltrim(substr($name, 4)));
                }

                return null;
            }, $subjectAltNames));
            $subjectAltNames = array_values($subjectAltNames);
        }

        return array(
            'cn' => $commonName,
            'san' => $subjectAltNames,
        );
    }
public static function getCertificateNames($certificate)
    {
        if (is_array($certificate)) {
            $info = $certificate;
        } elseif (CaBundle::isOpensslParseSafe()) {
            $info = openssl_x509_parse($certificate, false);
        }

        if (!isset($info['subject']['commonName'])) {
            return null;
        }

        $commonName = strtolower($info['subject']['commonName']);
        $subjectAltNames = array();

        if (isset($info['extensions']['subjectAltName'])) {
            $subjectAltNames = preg_split('{\s*,\s*}', $info['extensions']['subjectAltName']);
            $subjectAltNames = array_filter(array_map(function ($name) {
                if (0 === strpos($name, 'DNS:')) {
                    return strtolower(ltrim(substr($name, 4)));
                }

                return null;
            }, $subjectAltNames));
            $subjectAltNames = array_values($subjectAltNames);
        }

        return array(
            'cn' => $commonName,
            'san' => $subjectAltNames,
        );
    }
public static function getCertificateNames ( $ certificate ) { if ( is_array ( $ certificate ) ) { $ info = $ certificate ; } elseif ( CaBundle :: isOpensslParseSafe ( ) ) { $ info = openssl_x509_parse ( $ certificate , false ) ; } if ( ! isset ( $ info [ 'subject' ] [ 'commonName' ] ) ) { return null ; } $ commonName = strtolower ( $ info [ 'subject' ] [ 'commonName' ] ) ; $ subjectAltNames = array ( ) ; if ( isset ( $ info [ 'extensions' ] [ 'subjectAltName' ] ) ) { $ subjectAltNames = preg_split ( '{\s*,\s*}' , $ info [ 'extensions' ] [ 'subjectAltName' ] ) ; $ subjectAltNames = array_filter ( array_map ( function ( $ name ) { if ( 0 === strpos ( $ name , 'DNS:' ) ) { return strtolower ( ltrim ( substr ( $ name , 4 ) ) ) ; } return null ; } , $ subjectAltNames ) ) ; $ subjectAltNames = array_values ( $ subjectAltNames ) ; } return array ( 'cn' => $ commonName , 'san' => $ subjectAltNames , ) ; }
Extract DNS names out of an X.509 certificate.

@param mixed $certificate X.509 certificate

@return array|null
Extract DNS names out of an X . 509 certificate .