| 1 |
//! Command-line parser for `sq decrypt`. |
| 2 |
|
| 3 |
use std::path::PathBuf; |
| 4 |
|
| 5 |
use clap::Parser; |
| 6 |
|
| 7 |
use super::types::ClapData; |
| 8 |
use super::types::FileOrStdin; |
| 9 |
use super::types::FileOrStdout; |
| 10 |
use super::types::SessionKey; |
| 11 |
use super::types::cert_designator::*; |
| 12 |
|
| 13 |
use crate::cli::examples; |
| 14 |
use examples::Action; |
| 15 |
use examples::Actions; |
| 16 |
|
| 17 |
const DECRYPT_EXAMPLES: Actions = Actions { |
| 18 |
actions: &[ |
| 19 |
Action::example().comment( |
| 20 |
"Decrypt a file using a secret key", |
| 21 |
).command(&[ |
| 22 |
"sq", "decrypt", |
| 23 |
"--recipient-file", "juliet-secret.pgp", "ciphertext.pgp", |
| 24 |
]).build(), |
| 25 |
|
| 26 |
Action::example().comment( |
| 27 |
"Decrypt a file verifying signatures", |
| 28 |
).command(&[ |
| 29 |
"sq", "decrypt", |
| 30 |
"--recipient-file", "juliet-secret.pgp", |
| 31 |
"--signer-file", "romeo.pgp", |
| 32 |
"ciphertext.pgp" |
| 33 |
]).build(), |
| 34 |
|
| 35 |
Action::setup().command(&[ |
| 36 |
"sq", "key", "import", "juliet-secret.pgp", |
| 37 |
]).build(), |
| 38 |
|
| 39 |
Action::example().comment( |
| 40 |
"decrypt a file using the key store", |
| 41 |
).command(&[ |
| 42 |
"sq", "decrypt", "ciphertext.pgp", |
| 43 |
]).build(), |
| 44 |
], |
| 45 |
}; |
| 46 |
test_examples!(sq_decrypt, DECRYPT_EXAMPLES); |
| 47 |
|
| 48 |
#[derive(Parser, Debug)] |
| 49 |
#[clap( |
| 50 |
name = "decrypt", |
| 51 |
about = "Decrypt a message", |
| 52 |
long_about = |
| 53 |
"Decrypt a message |
| 54 |
|
| 55 |
Decrypt a message using either supplied keys, or by prompting for a \ |
| 56 |
password. If message tampering is detected, an error is returned. \ |
| 57 |
See below for details. |
| 58 |
|
| 59 |
If certificates are supplied using the `--signer-file` option, any \ |
| 60 |
signatures that are found are checked using these certificates. \ |
| 61 |
Verification is only successful if there is no bad signature, and the \ |
| 62 |
number of successfully verified signatures reaches the threshold \ |
| 63 |
configured with the `--signatures` parameter. |
| 64 |
|
| 65 |
If the signature verification fails, or if message tampering is \ |
| 66 |
detected, the program terminates with an exit status indicating \ |
| 67 |
failure. and the output file is deleted. If the output was sent \ |
| 68 |
to stdout, then the last 25 MiB of the message are withheld \ |
| 69 |
(consequently, if the message is smaller than 25 MiB, no output \ |
| 70 |
is produced). |
| 71 |
|
| 72 |
The converse operation is `sq encrypt`. |
| 73 |
", |
| 74 |
after_help = DECRYPT_EXAMPLES, |
| 75 |
)] |
| 76 |
// TODO use usize |
| 77 |
pub struct Command { |
| 78 |
#[clap( |
| 79 |
default_value_t = FileOrStdin::default(), |
| 80 |
help = FileOrStdin::HELP_OPTIONAL, |
| 81 |
value_name = FileOrStdin::VALUE_NAME, |
| 82 |
)] |
| 83 |
pub input: FileOrStdin, |
| 84 |
#[clap( |
| 85 |
default_value_t = FileOrStdout::default(), |
| 86 |
help = FileOrStdout::HELP_OPTIONAL, |
| 87 |
long, |
| 88 |
value_name = FileOrStdout::VALUE_NAME, |
| 89 |
)] |
| 90 |
pub output: FileOrStdout, |
| 91 |
#[clap( |
| 92 |
long = "signatures", |
| 93 |
value_name = "N", |
| 94 |
help = "Set the threshold of valid signatures to N", |
| 95 |
long_help = |
| 96 |
"Set the threshold of valid signatures to N |
| 97 |
|
| 98 |
The message will only be considered \ |
| 99 |
verified if this threshold is reached. \ |
| 100 |
[default: 1 if at least one signer cert file is given, 0 otherwise]", |
| 101 |
)] |
| 102 |
pub signatures: Option<usize>, |
| 103 |
|
| 104 |
#[command(flatten)] |
| 105 |
pub signers: CertDesignators<FileCertUserIDEmailDomainArgs, |
| 106 |
SignerPrefix, |
| 107 |
OptionalValue, |
| 108 |
ToVerifyDoc>, |
| 109 |
|
| 110 |
#[clap( |
| 111 |
long = "recipient-file", |
| 112 |
value_name = "KEY_FILE", |
| 113 |
help = "Decrypt the message using the key in KEY_FILE", |
| 114 |
)] |
| 115 |
pub secret_key_file: Vec<PathBuf>, |
| 116 |
#[clap( |
| 117 |
long = "dump-session-key", |
| 118 |
help = "Print the session key to stderr", |
| 119 |
)] |
| 120 |
pub dump_session_key: bool, |
| 121 |
#[clap( |
| 122 |
long = "session-key", |
| 123 |
value_name = "SESSION-KEY", |
| 124 |
help = "Decrypt an encrypted message using SESSION-KEY", |
| 125 |
)] |
| 126 |
pub session_key: Vec<SessionKey>, |
| 127 |
} |