Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bin/cli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

use Symfony\Component\Console\Application;

// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
include $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';

$application = new Application('Attestation CLI');
$application->addCommands([
new \ThePhpFoundation\Attestation\Command\Verify(),
]);

$application->run();
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"php": "^7.4||^8.0",
"ext-json": "*",
"composer/composer": "^2.2",
"symfony/console": "^5.4",
"webmozart/assert": "^1.11"
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions src/Command/Verify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace ThePhpFoundation\Attestation\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use ThePhpFoundation\Attestation\FilenameWithChecksum;
use ThePhpFoundation\Attestation\Verification\VerifyAttestationWithOpenSsl;

class Verify extends Command
{
protected static $defaultName = 'verify';

protected function configure(): void
{
// @todo we should probably make this match https://github.com/sigstore/sigstore-conformance/blob/main/docs/cli_protocol.md#verify
$this->addArgument('filename', InputArgument::REQUIRED, 'The filename to verify');
$this->addOption('owner', 'o', InputOption::VALUE_REQUIRED, 'The owner to verify against');
}

public function execute(InputInterface $input, OutputInterface $output): int
{
$file = $input->getArgument('filename');
$owner = (string) $input->getOption('owner');

Check failure on line 29 in src/Command/Verify.php

View workflow job for this annotation

GitHub Actions / static-analysis

Cannot cast mixed to string.

if ($owner === '') {
$output->writeln('Specify owner, e.g. --owner=blah');

return 1;
}

$output->writeln(sprintf(
'Verifying file: <info>%s</info>, for owner <info>%s</info>...',
$file,

Check failure on line 39 in src/Command/Verify.php

View workflow job for this annotation

GitHub Actions / static-analysis

Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, mixed given.
$owner,
));

$verifier = VerifyAttestationWithOpenSsl::factory();
$verifier->verify(
FilenameWithChecksum::fromFilename($file),

Check failure on line 45 in src/Command/Verify.php

View workflow job for this annotation

GitHub Actions / static-analysis

Parameter #1 $filename of static method ThePhpFoundation\Attestation\FilenameWithChecksum::fromFilename() expects non-empty-string, mixed given.
$owner,
basename($file), // @todo this might not match the record!

Check failure on line 47 in src/Command/Verify.php

View workflow job for this annotation

GitHub Actions / static-analysis

Parameter #3 $expectedSubjectName of method ThePhpFoundation\Attestation\Verification\VerifyAttestationWithOpenSsl::verify() expects non-empty-string, string given.

Check failure on line 47 in src/Command/Verify.php

View workflow job for this annotation

GitHub Actions / static-analysis

Parameter #1 $path of function basename expects string, mixed given.
[], // @todo what should we verify here?
);

$output->writeln('✅ Verified');

return 0;
}
}
Loading