| 1 |
//! Command-line parser for `sq verify`. |
| 2 |
|
| 3 |
use std::path::PathBuf; |
| 4 |
|
| 5 |
use clap::{ArgGroup, Parser}; |
| 6 |
|
| 7 |
use super::types::ClapData; |
| 8 |
use super::types::FileOrStdin; |
| 9 |
use super::types::FileOrStdout; |
| 10 |
use super::types::cert_designator::*; |
| 11 |
|
| 12 |
use crate::cli::examples; |
| 13 |
use examples::*; |
| 14 |
|
| 15 |
const VERIFY_EXAMPLES: Actions = Actions { |
| 16 |
actions: &[ |
| 17 |
Action::setup().command(&[ |
| 18 |
"sq", "cert", "import", "juliet.pgp", |
| 19 |
]).build(), |
| 20 |
|
| 21 |
Action::setup().command(&[ |
| 22 |
"sq", "--time", "2024-06-19", |
| 23 |
"pki", "link", "add", |
| 24 |
"--cert", "7A58B15E3B9459483D9FFA8D40E299AC5F2B0872", |
| 25 |
"--email", "[email protected]", |
| 26 |
]).build(), |
| 27 |
|
| 28 |
Action::example().comment( |
| 29 |
"Verify a signed message.", |
| 30 |
).command(&[ |
| 31 |
"sq", "verify", "--message", "document.pgp", |
| 32 |
]).build(), |
| 33 |
|
| 34 |
Action::example().comment( |
| 35 |
"Verify a detached signature.", |
| 36 |
).command(&[ |
| 37 |
"sq", "verify", "--signature-file=document.sig", "document.txt", |
| 38 |
]).build(), |
| 39 |
|
| 40 |
Action::example().comment( |
| 41 |
"Verify a message as of June 19, 2024 at midnight UTC.", |
| 42 |
).command(&[ |
| 43 |
"sq", "verify", "--time", "2024-06-19", |
| 44 |
"--message", "document.pgp", |
| 45 |
]).build(), |
| 46 |
], |
| 47 |
}; |
| 48 |
test_examples!(sq_verify, VERIFY_EXAMPLES); |
| 49 |
|
| 50 |
#[derive(Parser, Debug)] |
| 51 |
#[clap( |
| 52 |
name = "verify", |
| 53 |
about = "Verify signed messages or detached signatures", |
| 54 |
long_about = "Verify signed messages or detached signatures |
| 55 |
|
| 56 |
When verifying signed messages, the message is written to stdout or \ |
| 57 |
the file given to `--output`. |
| 58 |
|
| 59 |
When a detached message is verified, no output is produced. Detached \ |
| 60 |
signatures are often used to sign software packages. |
| 61 |
|
| 62 |
Verification is only successful if there is no bad signature, and the \ |
| 63 |
number of successfully verified signatures reaches the threshold \ |
| 64 |
configured with the `--signatures` parameter. If the verification \ |
| 65 |
fails, the program terminates with an exit status indicating failure, \ |
| 66 |
and the output file is deleted. If the output was sent to stdout, \ |
| 67 |
then the last 25 MiB of the message are withheld (consequently, if \ |
| 68 |
the message is smaller than 25 MiB, no output is produced). |
| 69 |
|
| 70 |
A signature is considered to have been authenticated if the signer can \ |
| 71 |
be authenticated. If the signer is provided via `--signer-file`, \ |
| 72 |
then the signer is considered authenticated. Otherwise, the signer is \ |
| 73 |
looked up and authenticated using the Web of Trust. If at least one \ |
| 74 |
User ID can be fully authenticated, then the signature is considered \ |
| 75 |
to have been authenticated. If the signature includes a Signer User \ |
| 76 |
ID subpacket, then only that User ID is considered. Note: the User ID \ |
| 77 |
need not be self signed. |
| 78 |
|
| 79 |
The converse operation is `sq sign`. |
| 80 |
|
| 81 |
If you are looking for a standalone program to verify detached \ |
| 82 |
signatures, consider using sequoia-sqv. |
| 83 |
|
| 84 |
`sq verify` respects the reference time set by the top-level \ |
| 85 |
`--time` argument. When set, it verifies the message as of the \ |
| 86 |
reference time instead of the current time. |
| 87 |
", |
| 88 |
after_help = VERIFY_EXAMPLES, |
| 89 |
)] |
| 90 |
#[clap(group(ArgGroup::new("kind") |
| 91 |
.args(&["detached", "message", "cleartext"]).required(true)))] |
| 92 |
pub struct Command { |
| 93 |
#[clap( |
| 94 |
default_value_t = FileOrStdin::default(), |
| 95 |
help = FileOrStdin::HELP_OPTIONAL, |
| 96 |
value_name = FileOrStdin::VALUE_NAME, |
| 97 |
)] |
| 98 |
pub input: FileOrStdin, |
| 99 |
#[clap( |
| 100 |
default_value_t = FileOrStdout::default(), |
| 101 |
help = FileOrStdout::HELP_OPTIONAL, |
| 102 |
long, |
| 103 |
value_name = FileOrStdout::VALUE_NAME, |
| 104 |
conflicts_with = "detached", |
| 105 |
)] |
| 106 |
pub output: FileOrStdout, |
| 107 |
|
| 108 |
#[clap( |
| 109 |
long = "signature-file", |
| 110 |
value_name = "SIG", |
| 111 |
help = "Verify a detached signature file" |
| 112 |
)] |
| 113 |
pub detached: Option<PathBuf>, |
| 114 |
|
| 115 |
#[clap( |
| 116 |
long = "message", |
| 117 |
value_name = "SIG", |
| 118 |
help = "Verify an inline signed message" |
| 119 |
)] |
| 120 |
pub message: bool, |
| 121 |
|
| 122 |
#[clap( |
| 123 |
long = "cleartext", |
| 124 |
value_name = "SIG", |
| 125 |
help = "Verify a cleartext-signed message" |
| 126 |
)] |
| 127 |
pub cleartext: bool, |
| 128 |
|
| 129 |
#[clap( |
| 130 |
long = "signatures", |
| 131 |
value_name = "N", |
| 132 |
default_value_t = 1, |
| 133 |
help = "Set the threshold of valid signatures to N", |
| 134 |
long_help = "Set the threshold of valid signatures to N |
| 135 |
|
| 136 |
If this threshold is not reached, the message \ |
| 137 |
will not be considered verified.", |
| 138 |
)] |
| 139 |
pub signatures: usize, |
| 140 |
|
| 141 |
#[command(flatten)] |
| 142 |
pub signers: CertDesignators<FileCertUserIDEmailDomainArgs, |
| 143 |
SignerPrefix, |
| 144 |
OptionalValue, |
| 145 |
ToVerifyDoc>, |
| 146 |
} |