You are here

private function SamlSpConfig::certInfo in SAML Service Provider 8.3

Same name and namespace in other branches
  1. 8.2 src/Form/SamlSpConfig.php \Drupal\saml_sp\Form\SamlSpConfig::certInfo()
  2. 4.x src/Form/SamlSpConfig.php \Drupal\saml_sp\Form\SamlSpConfig::certInfo()
  3. 3.x src/Form/SamlSpConfig.php \Drupal\saml_sp\Form\SamlSpConfig::certInfo()

Retrieves pertinent certificate data and output in a string for display.

Parameters

string $cert_location: The location of the certificate file.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup|false Certificate information, or false if the it can't be read or parsed.

1 call to SamlSpConfig::certInfo()
SamlSpConfig::buildForm in src/Form/SamlSpConfig.php
Form constructor.

File

src/Form/SamlSpConfig.php, line 500

Class

SamlSpConfig
Provides the configuration form.

Namespace

Drupal\saml_sp\Form

Code

private function certInfo($cert_location) {
  if (!empty($cert_location) && file_exists($cert_location) && function_exists('openssl_x509_parse')) {
    $encoded_cert = trim(file_get_contents($cert_location));
    $cert = openssl_x509_parse(Utils::formatCert($encoded_cert));

    // Flatten the issuer array.
    if (!empty($cert['issuer'])) {
      foreach ($cert['issuer'] as $key => &$value) {
        if (is_array($value)) {
          $value = implode("/", $value);
        }
      }
    }
    if ($cert) {
      $info = t('Name: %cert-name<br/>Issued by: %issuer<br/>Valid: %valid-from - %valid-to', [
        '%cert-name' => isset($cert['name']) ? $cert['name'] : '',
        '%issuer' => isset($cert['issuer']) && is_array($cert['issuer']) ? implode('/', $cert['issuer']) : '',
        '%valid-from' => isset($cert['validFrom_time_t']) ? date('c', $cert['validFrom_time_t']) : '',
        '%valid-to' => isset($cert['validTo_time_t']) ? date('c', $cert['validTo_time_t']) : '',
      ]);
      return $info;
    }
  }
  return FALSE;
}