| 1 |
//! Command-line parser for `sq key revoke`. |
| 2 |
|
| 3 |
use clap::Args; |
| 4 |
|
| 5 |
use crate::cli::types::ClapData; |
| 6 |
use crate::cli::types::FileOrStdout; |
| 7 |
|
| 8 |
use crate::cli::examples::*; |
| 9 |
use crate::cli::key::KeyReasonForRevocation; |
| 10 |
use crate::cli::types::cert_designator::*; |
| 11 |
|
| 12 |
const REVOKE_EXAMPLES: Actions = Actions { |
| 13 |
actions: &[ |
| 14 |
Action::setup().command(&[ |
| 15 |
"sq", "key", "import", "alice-secret.pgp" |
| 16 |
]).build(), |
| 17 |
|
| 18 |
Action::example().comment("\ |
| 19 |
Revoke Alice's key, indicating that there is a new certificate." |
| 20 |
).command(&[ |
| 21 |
"sq", "key", "revoke", |
| 22 |
"--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 23 |
"--reason", "superseded", |
| 24 |
"--message", "My new cert is C5999E8191BF7B503653BE958B1F7910D01F86E5", |
| 25 |
]).build(), |
| 26 |
|
| 27 |
Action::example().comment("\ |
| 28 |
Revoke the key, indicating that the secret key material was \ |
| 29 |
compromised." |
| 30 |
).command(&[ |
| 31 |
"sq", "key", "revoke", |
| 32 |
"--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 33 |
"--reason", "compromised", |
| 34 |
"--message", "Computer attacked, secret key material compromised", |
| 35 |
]).build(), |
| 36 |
] |
| 37 |
}; |
| 38 |
test_examples!(sq_key_revoke, REVOKE_EXAMPLES); |
| 39 |
|
| 40 |
#[derive(Debug, Args)] |
| 41 |
#[clap( |
| 42 |
about = "Revoke a certificate", |
| 43 |
long_about = "\ |
| 44 |
Revoke a certificate |
| 45 |
|
| 46 |
Creates a revocation certificate for a certificate. |
| 47 |
|
| 48 |
If `--revoker` or `--revoker-file` is provided, then that key is used \ |
| 49 |
to create the revocation certificate. If that key is different from \ |
| 50 |
the certificate that is being revoked, this results in a third-party \ |
| 51 |
revocation. This is normally only useful if the owner of the \ |
| 52 |
certificate designated the key to be a designated revoker. |
| 53 |
|
| 54 |
`sq key revoke` respects the reference time set by the top-level \ |
| 55 |
`--time` argument. When set, it uses the specified time instead of \ |
| 56 |
the current time when determining what keys are valid, and it sets \ |
| 57 |
the revocation certificate's creation time to the reference time \ |
| 58 |
instead of the current time. |
| 59 |
", |
| 60 |
after_help = REVOKE_EXAMPLES, |
| 61 |
)] |
| 62 |
pub struct Command { |
| 63 |
#[command(flatten)] |
| 64 |
pub cert: CertDesignators<CertUserIDEmailFileArgs, |
| 65 |
CertPrefix, |
| 66 |
OneValueAndFileRequiresOutput, |
| 67 |
KeyRevokeCertDoc>, |
| 68 |
|
| 69 |
#[command(flatten)] |
| 70 |
pub revoker: CertDesignators<CertUserIDEmailFileArgs, |
| 71 |
RevokerPrefix, |
| 72 |
OneOptionalValue, |
| 73 |
KeyRevokeRevokerDoc>, |
| 74 |
|
| 75 |
#[clap( |
| 76 |
long, |
| 77 |
value_name = "REASON", |
| 78 |
required = true, |
| 79 |
help = "The reason for the revocation", |
| 80 |
long_help = "\ |
| 81 |
The reason for the revocation |
| 82 |
|
| 83 |
If the reason happened in the past, you should specify that using the \ |
| 84 |
`--time` argument. This allows OpenPGP implementations to more \ |
| 85 |
accurately reason about artifacts whose validity depends on the validity \ |
| 86 |
of the certificate.", |
| 87 |
value_enum, |
| 88 |
)] |
| 89 |
pub reason: KeyReasonForRevocation, |
| 90 |
|
| 91 |
#[clap( |
| 92 |
long, |
| 93 |
value_name = "MESSAGE", |
| 94 |
required = true, |
| 95 |
help = "A short, explanatory text", |
| 96 |
long_help = "\ |
| 97 |
A short, explanatory text |
| 98 |
|
| 99 |
The text is shown to a viewer of the revocation certificate, and \ |
| 100 |
explains why the certificate has been revoked. For instance, if Alice \ |
| 101 |
has created a new key, she would generate a `superseded` revocation \ |
| 102 |
certificate for her old key, and might include the message `I've \ |
| 103 |
created a new certificate, $FINGERPRINT, please use that in the \ |
| 104 |
future.`", |
| 105 |
)] |
| 106 |
pub message: String, |
| 107 |
|
| 108 |
#[command(flatten)] |
| 109 |
pub signature_notations: crate::cli::types::SignatureNotationsArg, |
| 110 |
|
| 111 |
#[clap( |
| 112 |
long, |
| 113 |
value_name = FileOrStdout::VALUE_NAME, |
| 114 |
help = "Write to the specified FILE", |
| 115 |
long_help = "\ |
| 116 |
Write to the specified FILE |
| 117 |
|
| 118 |
If not specified, and the certificate was read from the certificate \ |
| 119 |
store, imports the modified certificate into the cert store. If not \ |
| 120 |
specified, and the certificate was read from a file, writes the \ |
| 121 |
modified certificate to stdout.", |
| 122 |
)] |
| 123 |
pub output: Option<FileOrStdout>, |
| 124 |
} |
| 125 |
|
| 126 |
/// Documentation for the cert designators for the key revoke. |
| 127 |
pub struct KeyRevokeCertDoc {} |
| 128 |
|
| 129 |
impl AdditionalDocs for KeyRevokeCertDoc { |
| 130 |
fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr { |
| 131 |
match arg { |
| 132 |
"file" => |
| 133 |
"Revoke the key read from PATH" |
| 134 |
.into(), |
| 135 |
_ => { |
| 136 |
debug_assert!(help.starts_with("Use certificates")); |
| 137 |
help.replace("Use certificates", |
| 138 |
"Revoke the key") |
| 139 |
}, |
| 140 |
}.into() |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
/// Documentation for the revoker designators for the key revoke. |
| 145 |
pub struct KeyRevokeRevokerDoc {} |
| 146 |
|
| 147 |
impl AdditionalDocs for KeyRevokeRevokerDoc { |
| 148 |
fn help(_: &'static str, help: &'static str) -> clap::builder::StyledStr { |
| 149 |
format!("{} to create the revocation certificate", |
| 150 |
help.replace("certificates", "key")).into() |
| 151 |
} |
| 152 |
|
| 153 |
fn long_help(_: &'static str, help: &'static str) -> Option<clap::builder::StyledStr> { |
| 154 |
Some(format!("{} to create the revocation certificate |
| 155 |
|
| 156 |
Sign the revocation certificate using the specified key. By default, \ |
| 157 |
the certificate being revoked is used. Using this option, it is \ |
| 158 |
possible to create a third-party revocation.", |
| 159 |
help.replace("certificates", "key")).into()) |
| 160 |
} |
| 161 |
} |