예제 #1
0
 /**
  * Verify the checksums on $tmp_file for the package we are verifying
  * 
  * @param array $blockdata
  * @param string $tmp_file
  * @return boolean
  */
 private function verifyChecksums($blockdata, $tmp_file)
 {
     $matches = 0;
     $filedata = \file_get_contents($tmp_file);
     // Now let's check all of the hashes
     foreach ($blockdata['checksums'] as $algo => $hash) {
         switch ($algo) {
             case 'BLAKE2b':
                 // We used libsodium
                 $line = \Sodium::crypto_generichash($filedata);
                 break;
             default:
                 // A simple hash (SHA256, etc)
                 $line = \hash($algo, $filedata, true);
         }
         if (\hash_equals($line, \Sodium::sodium_hex2bin($hash))) {
             ++$matches;
         } else {
             die("{$algo} hash did not match!");
         }
     }
     unset($filedata);
     // explicitly free
     return $matches > 0;
 }