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