You are here

public function Verifier::verifyCsigMessage in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/drupal/php-signify/src/Verifier.php \Drupal\Signify\Verifier::verifyCsigMessage()

Verify a string message signed with CSIG chained-signature extended Signify format.

Parameters

string $chained_signed_message: The string contents of the root/intermediate chained signify signature and message (e.g. the contents of a .csig file.)

\DateTime $now: If provided, a \DateTime object modeling "now".

Return value

string The message if the verification passed.

Throws

\SodiumException

\Drupal\Signify\VerifierException Thrown when the message was not verified.

1 call to Verifier::verifyCsigMessage()
Verifier::verifyCsigChecksumList in vendor/drupal/php-signify/src/Verifier.php
Verify a signed checksum list, and then verify the checksum for each file in the list.

File

vendor/drupal/php-signify/src/Verifier.php, line 244

Class

Verifier

Namespace

Drupal\Signify

Code

public function verifyCsigMessage($chained_signed_message, \DateTime $now = NULL) {
  $csig_lines = explode("\n", $chained_signed_message, 6);
  $root_signed_intermediate_key_and_validity = implode("\n", array_slice($csig_lines, 0, 5)) . "\n";
  $this
    ->verifyMessage($root_signed_intermediate_key_and_validity);
  $valid_through_dt = \DateTime::createFromFormat('Y-m-d', $csig_lines[2], new \DateTimeZone('UTC'));
  if (!$valid_through_dt instanceof \DateTime) {
    throw new VerifierException('Unexpected valid-through date format.');
  }
  $now_dt = $this
    ->getNow($now);
  $diff = $now_dt
    ->diff($valid_through_dt);
  if ($diff->invert) {
    throw new VerifierException(sprintf('The intermediate key expired %d day(s) ago.', $diff->days));
  }
  $intermediate_pubkey = implode("\n", array_slice($csig_lines, 3, 2)) . "\n";
  $chained_verifier = new self($intermediate_pubkey);
  $signed_message = implode("\n", array_slice($csig_lines, 5));
  return $chained_verifier
    ->verifyMessage($signed_message);
}