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\CaBundleCode
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;
}