You are here

function SamlSpConfig::certInfo in SAML Service Provider 8.2

Same name and namespace in other branches
  1. 8.3 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()

with the certificate location retrieve pertinant certificate data and output in a string for display

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

File

src/Form/SamlSpConfig.php, line 399
Contains \Drupal\saml_sp\Form\SamlSpConfigSPForm.

Class

SamlSpConfig

Namespace

Drupal\saml_sp\Form

Code

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(\OneLogin_Saml2_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', array(
        '%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;
}