Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CaBundle.php

function CaBundle::validateCaFile

Validates a CA file using opensl_x509_parse only if it is safe to use

Parameters

string $filename:

LoggerInterface $logger optional logger for information about which CA files were loaded:

Return value

bool

2 calls to CaBundle::validateCaFile()
CaBundle::caFileUsable in vendor/composer/ca-bundle/src/CaBundle.php
StreamContextFactory::getTlsDefaults in vendor/composer/composer/src/Composer/Util/StreamContextFactory.php

File

vendor/composer/ca-bundle/src/CaBundle.php, line 157

Class

CaBundle
@author Chris Smith <chris@cs278.org> @author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\CaBundle

Code

public static function validateCaFile($filename, ?LoggerInterface $logger = null) {
    static $warned = false;
    if (isset(self::$caFileValidity[$filename])) {
        return self::$caFileValidity[$filename];
    }
    $contents = file_get_contents($filename);
    if (is_string($contents) && strlen($contents) > 0) {
        $contents = preg_replace("/^(\\-+(?:BEGIN|END))\\s+TRUSTED\\s+(CERTIFICATE\\-+)\$/m", '$1 $2', $contents);
        if (null === $contents) {
            // regex extraction failed
            $isValid = false;
        }
        else {
            $isValid = (bool) openssl_x509_parse($contents);
        }
    }
    else {
        $isValid = false;
    }
    if ($logger) {
        $logger->debug('Checked CA file ' . realpath($filename) . ': ' . ($isValid ? 'valid' : 'invalid'));
    }
    return self::$caFileValidity[$filename] = $isValid;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal