You are here

protected static function ModifiedFilesService::processHashes in Automatic Updates 7

Process checking hashes of files from external URL.

Parameters

string $data: Response data.

array $info: Array of extension information.

\ArrayIterator $modified_files: The list of modified files.

1 call to ModifiedFilesService::processHashes()
ModifiedFilesService::getModifiedFiles in ./ModifiedFilesService.php
Get list of modified files.

File

./ModifiedFilesService.php, line 60

Class

ModifiedFilesService
Modified files service.

Code

protected static function processHashes($data, array $info, \ArrayIterator $modified_files) {
  $directory_root = $info['install path'];
  if ($info['project'] === 'drupal') {
    $directory_root = '';
  }
  $module_path = drupal_get_path('module', 'automatic_updates');
  $key = file_get_contents($module_path . '/artifacts/keys/root.pub');
  $verifier = new Verifier($key);
  $files = $verifier
    ->verifyCsigMessage($data);
  $checksums = new ChecksumList($files, TRUE);
  foreach (new FailedCheckumFilter($checksums, $directory_root) as $failed_checksum) {
    $file_path = implode(DIRECTORY_SEPARATOR, array_filter([
      $directory_root,
      $failed_checksum->filename,
    ]));
    if (!file_exists($file_path)) {
      $modified_files
        ->append($file_path);
      continue;
    }
    $actual_hash = @hash_file(strtolower($failed_checksum->algorithm), $file_path);
    if ($actual_hash === FALSE || empty($actual_hash) || strlen($actual_hash) < 64 || strcmp($actual_hash, $failed_checksum->hex_hash) !== 0) {
      $modified_files
        ->append($file_path);
    }
  }
}