Check PGP and x509 signatures, draft code

This commit is contained in:
djmaze 2026-10-28 16:52:54 +01:00
parent f6e9ea600c
commit b5d587dc77
5 changed files with 82 additions and 19 deletions

View file

@ -104,6 +104,14 @@ foreach (glob(ROOT_DIR . '/plugins/*', GLOB_NOSORT | GLOB_ONLYDIR) as $dir) {
$tar = new PharData($tar_destination);
$tar->buildFromDirectory('./plugins/', '/' . \preg_quote("./plugins/{$name}/", '/') . '((?!\.bak).)*$/');
$tar->compress(Phar::GZ);
/*
$private = \openssl_get_privatekey(\file_get_contents('private.pem'));
$pkey = '';
\openssl_pkey_export($private, $pkey);
$tar->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
$tar->setSignatureAlgorithm(Phar::Phar::PGP, file_get_contents($private_key));
$signature = $tar->getSignature();
*/
unlink($tar_destination);
rename("{$tar_destination}.gz", $tgz_destination);
/*
@ -116,10 +124,18 @@ foreach (glob(ROOT_DIR . '/plugins/*', GLOB_NOSORT | GLOB_ONLYDIR) as $dir) {
unlink($phar_destination);
rename("{$phar_destination}.gz", $phar_destination);
}
*/
if (isset($options['sign'])) {
passthru('gpg --local-user 1016E47079145542F8BA133548208BA13290F3EB --armor --detach-sign '.escapeshellarg($tgz_destination), $return_var);
$arg = escapeshellarg($tgz_destination);
passthru('gpg --local-user 1016E47079145542F8BA133548208BA13290F3EB --armor --detach-sign '.$arg, $return_var);
$manifest_item['pgp_sig'] = trim(preg_replace('/-----(BEGIN|END) PGP SIGNATURE-----/', '', file_get_contents($tgz_destination.'.asc')));
$cert_dir = $_SERVER['HOME'].'/.snappymail/certificates';
$out = escapeshellarg($tgz_destination . '.sig');
passthru("openssl dgst -sha256 -sign {$cert_dir}/sign_releases.key -out {$out} {$arg}", $return_var);
// passthru("openssl dgst -sha512 -sign {$cert_dir}/sign_releases.key -out {$out} {$arg}", $return_var);
// $manifest_item['ssl_sig'] = base64_encode(file_get_contents($tgz_destination.'.sig'));
}
ksort($manifest_item);
$manifest[$name] = $manifest_item;