Skip to content

Commit

Permalink
Post-checkout cleanup of newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed May 8, 2024
1 parent 18710d3 commit f4d4cca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 17 additions & 1 deletion src/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,24 @@ public static function postAutoloadDump(Event $event)
require_once $vendorDir . '/autoload.php';

$dataDir = \dirname($vendorDir) . '/data';
(new RemoteFetch($dataDir))->getLatestBundle();
(new RemoteFetch($dataDir))->getLatestBundle(false, false);
self::dos2unixAll($dataDir);

echo '[OK] Remote Fetch of latest CACert Bundle', PHP_EOL;
}

/**
* Prevent newline weirdness with Git from causing invalid files (SHA-256, signatures)
*
* @param string $dataDir
* @return void
*/
protected static function dos2unixAll($dataDir)
{
foreach (glob($dataDir . '/*.pem') as $pemFile) {
$contents = file_get_contents($pemFile);
$fixed = str_replace("\r\n", "\n", $pemFile);
file_put_contents($pemFile, $fixed);
}
}
}
3 changes: 0 additions & 3 deletions src/Fetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public function getLatestBundle($checkEd25519Signature = null, $checkChronicle =
if ($checkEd25519Signature) {
$valid = $validator->checkEd25519Signature($bundle);
if (!$valid) {
var_dump('invalid signature for' . $bundle->getFilePath());
$this->markBundleAsBad($bundleIndex, 'Ed25519 signature mismatch');
}
}
Expand All @@ -108,11 +107,9 @@ public function getLatestBundle($checkEd25519Signature = null, $checkChronicle =
$index = array_search($bundle->getFilePath(), $this->unverified, true);
if ($index !== false) {
$validChronicle = $validator->checkChronicleHash($bundle);
$valid = $valid && $validChronicle;
if ($validChronicle) {
unset($this->unverified[$index]);
} else {
var_dump('invalid chronicle entry for' . $bundle->getFilePath());
$this->markBundleAsBad($bundleIndex, 'Chronicle');
}
}
Expand Down

0 comments on commit f4d4cca

Please sign in to comment.