| 1 |
use std::path::PathBuf; |
| 2 |
|
| 3 |
use clap::{Command, CommandFactory, Parser}; |
| 4 |
|
| 5 |
use sequoia_policy_config::ConfiguredStandardPolicy; |
| 6 |
|
| 7 |
mod time; |
| 8 |
|
| 9 |
// The argument parser. |
| 10 |
pub fn build() -> Command { |
| 11 |
let sqv_version = Box::leak( |
| 12 |
format!( |
| 13 |
"{} (sequoia-openpgp {}, using {})", |
| 14 |
env!("CARGO_PKG_VERSION"), |
| 15 |
sequoia_openpgp::VERSION, |
| 16 |
sequoia_openpgp::crypto::backend() |
| 17 |
) |
| 18 |
.into_boxed_str(), |
| 19 |
) as &str; |
| 20 |
|
| 21 |
SqvCommand::command() |
| 22 |
.version(sqv_version) |
| 23 |
// To improve readability limit the width of the text columns. |
| 24 |
.max_term_width(100) |
| 25 |
} |
| 26 |
|
| 27 |
#[derive(Parser)] |
| 28 |
#[command( |
| 29 |
name="sqv", |
| 30 |
about = "An OpenPGP signature verification tool", |
| 31 |
long_about = format!("\ |
| 32 |
An OpenPGP signature verification tool |
| 33 |
|
| 34 |
sqv is a simple signature verification tool. It checks that \ |
| 35 |
signatures are valid, and correctly issued by one of the certificates \ |
| 36 |
in the specified keyring. |
| 37 |
|
| 38 |
sqv can verify detached signatures, inline-signed messages, and |
| 39 |
messages using the Cleartext Signature Framework. |
| 40 |
|
| 41 |
To verify detached signatures, use the `--signature-file` argument |
| 42 |
followed by the path to the detached signature file, and give the data |
| 43 |
file as first positional argument: |
| 44 |
|
| 45 |
$ sqv --keyring=... --signature-file=image.iso.sig image.iso |
| 46 |
|
| 47 |
To verify an inline-signed message, use the `--message` argument, and |
| 48 |
give the path to the inline-signed message as first positional |
| 49 |
argument. When verifying an inline-signed `--output` has to be given: |
| 50 |
|
| 51 |
$ sqv --keyring=... --output=authenticated.txt \\ |
| 52 |
--message signed.pgp |
| 53 |
|
| 54 |
To verify a message using the Cleartext Signature Framework, use the |
| 55 |
`--cleartext` argument, and give the path to the message as first |
| 56 |
positional argument. When verifying an inline-signed `--output` has |
| 57 |
to be given: |
| 58 |
|
| 59 |
$ sqv --keyring=... --output=authenticated.txt \\ |
| 60 |
--cleartext message.txt |
| 61 |
|
| 62 |
Finally, there is a legacy way to verify detached signatures, where |
| 63 |
the path to the signature file and the path to the data file are given |
| 64 |
as positional arguments. This form is deprecated, prefer the explicit |
| 65 |
`--signature-file` form. |
| 66 |
|
| 67 |
By default, one signature must be valid. This can be changed using \ |
| 68 |
the `--signatures` arguments. |
| 69 |
|
| 70 |
A signature is valid if a signing-capable key can verify the \ |
| 71 |
signature. The signing-capable key must be correctly bound to a \ |
| 72 |
certificate in the keyring, and it must not be revoked, or expired. \ |
| 73 |
The certificate must not be revoked or expired. The signature, the \ |
| 74 |
signing-capable key and the certificate must all be valid according to \ |
| 75 |
the cryptographic policy. |
| 76 |
|
| 77 |
By default, sqv configures the cryptographic policy using <{}>. That \ |
| 78 |
can be overwritten by setting the {} environment variable to an \ |
| 79 |
alternate file. The path must be absolute. The file's format is \ |
| 80 |
described here: <https://docs.rs/sequoia-policy-config/>. |
| 81 |
|
| 82 |
In some cases, the user expects signatures to be made within a certain \ |
| 83 |
temporal window. This can be enforced using the `--not-before` and \ |
| 84 |
`--not-after` arguments. The TIMESTAMPs must be given in ISO 8601 \ |
| 85 |
format (e.g. `2017-03-04T13:25:35Z`, `2017-03-04T13:25`, \ |
| 86 |
`20170304T1325+0830`, `2017-03-04`, `2017031`, etc.). If no timezone \ |
| 87 |
is specified, UTC is assumed. |
| 88 |
|
| 89 |
Exits with a non-zero status if the specified number of signatures \ |
| 90 |
could not be verified. |
| 91 |
", |
| 92 |
ConfiguredStandardPolicy::CONFIG_FILE, |
| 93 |
ConfiguredStandardPolicy::ENV_VAR), |
| 94 |
after_help = "Examples: |
| 95 |
|
| 96 |
# Verify a detached signature. |
| 97 |
$ sqv --keyring=trusted.pgp --signature-file=document.sig \\ |
| 98 |
document.txt |
| 99 |
|
| 100 |
# Verify a detached signature, legacy interface. |
| 101 |
$ sqv --keyring=trusted.pgp document.sig document.txt |
| 102 |
|
| 103 |
# Verify a signed message. |
| 104 |
$ sqv --keyring trusted.pgp --message document.pgp |
| 105 |
|
| 106 |
# Verify a message using the Cleartext Signature Framework. |
| 107 |
$ sqv --keyring trusted.pgp --cleartext document.pgp |
| 108 |
", |
| 109 |
arg_required_else_help = true, |
| 110 |
disable_colored_help = true, |
| 111 |
)] |
| 112 |
#[clap(group(clap::ArgGroup::new("kind") |
| 113 |
.args(&["detached", "message", "cleartext"]).required(false)))] |
| 114 |
pub struct SqvCommand { |
| 115 |
#[clap( |
| 116 |
long, |
| 117 |
value_name = "FILE", |
| 118 |
conflicts_with_all = ["detached", "data"], |
| 119 |
required_unless_present_any = ["detached", "data"], |
| 120 |
help = "Write to FILE", |
| 121 |
long_help = "\ |
| 122 |
Write to FILE. |
| 123 |
|
| 124 |
This is required when verifying an inline signed message (using \ |
| 125 |
--message) and a cleartext signed message (using --cleartext) and is \ |
| 126 |
forbidden when verifying a detached signature (using |
| 127 |
--signature-file)." |
| 128 |
)] |
| 129 |
pub output: Option<PathBuf>, |
| 130 |
|
| 131 |
#[clap( |
| 132 |
long, |
| 133 |
help = "Overwrite the output file if it already exists" |
| 134 |
)] |
| 135 |
pub overwrite: bool, |
| 136 |
|
| 137 |
#[clap( |
| 138 |
long = "signature-file", |
| 139 |
value_name = "SIG", |
| 140 |
help = "Verify a detached signature file" |
| 141 |
)] |
| 142 |
pub detached: Option<PathBuf>, |
| 143 |
|
| 144 |
#[clap( |
| 145 |
long = "message", |
| 146 |
value_name = "SIG", |
| 147 |
help = "Verify an inline signed message" |
| 148 |
)] |
| 149 |
pub message: bool, |
| 150 |
|
| 151 |
#[clap( |
| 152 |
long = "cleartext", |
| 153 |
value_name = "SIG", |
| 154 |
help = "Verify a cleartext-signed message" |
| 155 |
)] |
| 156 |
pub cleartext: bool, |
| 157 |
|
| 158 |
/// A keyring. |
| 159 |
#[clap( |
| 160 |
long, |
| 161 |
value_name = "FILE", |
| 162 |
required = true)] |
| 163 |
pub keyring: Vec<PathBuf>, |
| 164 |
|
| 165 |
|
| 166 |
/// Consider signatures created after TIMESTAMP as invalid. |
| 167 |
/// |
| 168 |
/// If only a date is given, 23:59:59 is used for the time. |
| 169 |
/// [default: now] |
| 170 |
#[clap( |
| 171 |
long, |
| 172 |
value_name = "TIMESTAMP")] |
| 173 |
pub not_after: Option<String>, |
| 174 |
|
| 175 |
/// Consider signatures created before TIMESTAMP as invalid. |
| 176 |
/// |
| 177 |
/// If only a date is given, 00:00:00 is used for the time. |
| 178 |
/// [default: no constraint] |
| 179 |
#[clap( |
| 180 |
long, |
| 181 |
value_name = "TIMESTAMP")] |
| 182 |
pub not_before: Option<String>, |
| 183 |
|
| 184 |
/// The number of valid signatures to return success. |
| 185 |
/// |
| 186 |
/// Note: this counts the number of certificates, not signatures. |
| 187 |
/// Thus, if two signatures are issued by the same certificate, |
| 188 |
/// they only count once. |
| 189 |
#[clap( |
| 190 |
long, |
| 191 |
short = 'n', |
| 192 |
value_name = "N", |
| 193 |
default_value_t = 1)] |
| 194 |
pub signatures: usize, |
| 195 |
|
| 196 |
/// The inline-signed message, message using the Cleartext |
| 197 |
/// Signature Framework, or data file. |
| 198 |
#[clap(value_name = "FILE")] |
| 199 |
pub file: PathBuf, |
| 200 |
|
| 201 |
/// In the legacy way of invoking sqv, the signature file is given |
| 202 |
/// as first positional argument, and the data file as second. |
| 203 |
#[clap( |
| 204 |
hide = true, |
| 205 |
value_name = "DATA-FILE", |
| 206 |
conflicts_with_all = ["detached", "message", "cleartext"], |
| 207 |
)] |
| 208 |
pub data: Option<PathBuf>, |
| 209 |
|
| 210 |
/// Be verbose. |
| 211 |
#[clap( |
| 212 |
long, |
| 213 |
short = 'v')] |
| 214 |
pub verbose: bool, |
| 215 |
|
| 216 |
#[clap( |
| 217 |
long = "time", |
| 218 |
allow_hyphen_values = true, |
| 219 |
value_name = "TIMESTAMP", |
| 220 |
help = "Set the reference time as an ISO 8601 formatted timestamp", |
| 221 |
long_help = "\ |
| 222 |
Set the reference time as an ISO 8601 formatted timestamp or \ |
| 223 |
relative offset. |
| 224 |
|
| 225 |
This sets the reference time for the sqv session. Normally, \ |
| 226 |
sqv uses the current time. This argument allows you to use a \ |
| 227 |
different time. |
| 228 |
|
| 229 |
This time is also used as the default value for --not-after and \ |
| 230 |
--policy-as-of, and it is passed to the signature verifier as \ |
| 231 |
the reference time for evaluating whether keys and certificates \ |
| 232 |
are valid. |
| 233 |
|
| 234 |
TIME is interpreted as an ISO 8601 timestamp. To set the \ |
| 235 |
time to January 1, 2007 at midnight UTC, you can do: |
| 236 |
|
| 237 |
$ sqv --time 20070101 --keyring keyring.pgp --message msg.pgp |
| 238 |
|
| 239 |
An offset can also be used. For instance, to set the time to \ |
| 240 |
one year ago, do: |
| 241 |
|
| 242 |
$ sqv --time -1y --keyring keyring.pgp --message msg.pgp |
| 243 |
" |
| 244 |
)] |
| 245 |
pub time: Option<time::Time>, |
| 246 |
|
| 247 |
#[clap( |
| 248 |
long = "policy-as-of", |
| 249 |
allow_hyphen_values = true, |
| 250 |
value_name = "TIMESTAMP", |
| 251 |
help = "Select the cryptographic policy as of the specified time", |
| 252 |
long_help = "\ |
| 253 |
Select the cryptographic policy as of the specified time |
| 254 |
|
| 255 |
The time is \ |
| 256 |
expressed as an ISO 8601 formatted timestamp. The policy determines \ |
| 257 |
what cryptographic constructs are allowed. |
| 258 |
|
| 259 |
If you are working with a message that sq rejects, because it is \ |
| 260 |
protected by cryptographic constructs that are now considered broken, \ |
| 261 |
you can use this option to select a different cryptographic policy. \ |
| 262 |
If you are relying on the cryptography, e.g., you are verifying a \ |
| 263 |
signature, then you should only do this if you are confident that the \ |
| 264 |
message hasn't been tampered with. |
| 265 |
|
| 266 |
TIME is interpreted as an ISO 8601 timestamp. To set the \ |
| 267 |
policy time to January 1, 2007 at midnight UTC, you can do: |
| 268 |
|
| 269 |
$ sqv --policy-as-of 20070101 --message msg.pgp |
| 270 |
|
| 271 |
Defaults to the current time. |
| 272 |
", |
| 273 |
)] |
| 274 |
pub policy_as_of: Option<time::Time>, |
| 275 |
} |