Debian Codegraph @

src/cli/key/approvals.rs

raw
1 //! Command-line parser for `sq key expire`.
2
3 use clap::{
4 Args,
5 ArgGroup,
6 Subcommand,
7 };
8
9 use sequoia_openpgp as openpgp;
10 use openpgp::KeyHandle;
11
12 use crate::cli::types::ClapData;
13 use crate::cli::types::FileOrStdout;
14
15 use crate::cli::examples::*;
16 use crate::cli::types::cert_designator::*;
17 use crate::cli::types::UserIDDesignators;
18 use crate::cli::types::userid_designator;
19
20 #[derive(Debug, Subcommand)]
21 #[clap(
22 name = "approvals",
23 about = "Manages certification approvals",
24 long_about = "\
25 Manages certification approvals
26
27 Key holders may approve of third-party certifications associated with \
28 their certificate. This subcommand manages the approvals.
29
30 To prevent certificate flooding attacks, modern key servers prevent \
31 uncontrolled distribution of third-party certifications on \
32 certificates. To allow the key holder to control what information is \
33 distributed with their certificate, these key servers only distribute \
34 third-party certifications that the key holder has explicitly \
35 approved.
36 ",
37 subcommand_required = true,
38 arg_required_else_help = true,
39 disable_help_subcommand = true,
40 )]
41 #[non_exhaustive]
42 pub enum Command {
43 List(ListCommand),
44 Update(UpdateCommand),
45 }
46
47 const LIST_EXAMPLES: Actions = Actions {
48 actions: &[
49 Action::Example(Example {
50 comment: "\
51 Lists the approved certifications on all the user IDs.",
52 command: &[
53 "sq", "key", "approvals", "list",
54 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
55 ],
56 hide: &[],
57 }),
58
59 Action::Example(Example {
60 comment: "\
61 Lists the unapproved certifications on all the user IDs.",
62 command: &[
63 "sq", "key", "approvals", "list",
64 "--pending",
65 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
66 ],
67 hide: &[],
68 }),
69
70 Action::Example(Example {
71 comment: "\
72 Lists all unapproved certifications on a given user ID.",
73 command: &[
74 "sq", "key", "approvals", "list",
75 "--pending",
76 "[email protected]",
77 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
78 ],
79 hide: &[],
80 }),
81 ]
82 };
83 test_examples!(sq_key_approvals_list, LIST_EXAMPLES);
84
85 #[derive(Debug, Args)]
86 #[clap(
87 name = "list",
88 about = "Lists third-party certifications and their approval status",
89 long_about = "\
90 Lists third-party certifications and their approval status
91
92 To prevent certificate flooding attacks, modern key servers prevent \
93 uncontrolled distribution of third-party certifications on \
94 certificates. To allow the key holder to control what information is \
95 distributed with their certificate, these key servers only distribute \
96 third-party certifications that the key holder has explicitly \
97 approved.
98 ",
99 after_help = LIST_EXAMPLES,
100 )]
101 pub struct ListCommand {
102 #[command(flatten)]
103 pub cert: CertDesignators<CertUserIDEmailFileArgs,
104 CertPrefix,
105 OneValue,
106 ApprovalsListDoc>,
107
108 #[command(flatten)]
109 pub userids: UserIDDesignators<
110 userid_designator::PlainByArgs,
111 userid_designator::OptionalValue>,
112
113 #[clap(
114 long = "pending",
115 help = "List unapproved certifications",
116 )]
117 pub pending: bool,
118 }
119
120 /// Documentation for the cert designators for the key approvals list
121 /// command.
122 pub struct ApprovalsListDoc {}
123
124 impl AdditionalDocs for ApprovalsListDoc {
125 fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr {
126 match arg {
127 "file" =>
128 "List the approvals on the certificate read from PATH"
129 .into(),
130 _ => {
131 debug_assert!(help.starts_with("Use certificates"));
132 help.replace("Use certificates",
133 "List the approvals on the certificate")
134 .into()
135 },
136 }
137 }
138 }
139
140 const UPDATE_EXAMPLES: Actions = Actions {
141 actions: &[
142 Action::setup().command(&[
143 "sq", "key", "import", "alice-secret.pgp",
144 ]).build(),
145
146 Action::setup().command(&[
147 "sq", "key", "import", "bob-secret.pgp",
148 ]).build(),
149
150 Action::setup().command(&[
151 "sq", "pki", "vouch", "add",
152 "--certifier=511257EBBF077B7AEDAE5D093F68CB84CE537C9A",
153 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
154 "[email protected]",
155 ]).build(),
156
157 Action::setup().command(&[
158 "sq", "pki", "link", "add",
159 "--cert=511257EBBF077B7AEDAE5D093F68CB84CE537C9A",
160 "[email protected]",
161 ]).build(),
162
163 Action::example().comment("\
164 Approve of all of the certifications on all of Alice's user IDs."
165 ).command(&[
166 "sq", "key", "approvals", "update",
167 "--add-all",
168 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
169 ]).build(),
170
171 Action::example().comment("\
172 Approve of all of the certifications on all of Alice's user IDs made by Bob, \
173 discarding all prior approvals first."
174 ).command(&[
175 "sq", "key", "approvals", "update",
176 "--remove-all",
177 "--add-by=511257EBBF077B7AEDAE5D093F68CB84CE537C9A",
178 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
179 ]).build(),
180
181 Action::example().comment("\
182 Approve of all of the certifications on a specific user ID by certifiers that \
183 can be authenticated, discarding all prior approvals first."
184 ).command(&[
185 "sq", "key", "approvals", "update",
186 "--remove-all",
187 "--add-authenticated",
188 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
189 "--userid=Alice <[email protected]>",
190 ]).build(),
191
192 Action::example().comment("\
193 Remove the approval of Bob's certification on all of Alice's user IDs."
194 ).command(&[
195 "sq", "key", "approvals", "update",
196 "--remove-by=511257EBBF077B7AEDAE5D093F68CB84CE537C9A",
197 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
198 ]).build(),
199 ]
200 };
201 test_examples!(sq_key_approvals_update, UPDATE_EXAMPLES);
202
203 #[derive(Debug, Args)]
204 #[clap(
205 name = "update",
206 about = "Approves of third-party certifications allowing for their distribution",
207 long_about = "\
208 Approves of third-party certifications allowing for their distribution
209
210 To prevent certificate flooding attacks, modern key servers prevent \
211 uncontrolled distribution of third-party certifications on \
212 certificates. To allow the key holder to control what information is \
213 distributed with their certificate, these key servers only distribute \
214 third-party certifications that the key holder has explicitly \
215 approved.
216
217 By default, all user IDs are considered, but if at least one `--name`, \
218 `--email`, or `--userid` argument is given, only the matching user IDs \
219 are considered.
220
221 After the approvals have been changed, the certificate has to be \
222 distributed, e.g. by uploading it to a key server.
223 ",
224 after_help = UPDATE_EXAMPLES,
225 )]
226 #[clap(group(
227 ArgGroup::new("action")
228 .args(&[
229 "remove_all",
230 "remove_by",
231 "add_all",
232 "add_by",
233 "add_authenticated",
234 ])
235 .required(true)
236 .multiple(true)))]
237 pub struct UpdateCommand {
238 #[command(flatten)]
239 pub cert: CertDesignators<CertUserIDEmailFileArgs,
240 CertPrefix,
241 OneValueAndFileRequiresOutput,
242 ApprovalsListDoc>,
243
244 #[command(flatten)]
245 pub userids: UserIDDesignators<
246 userid_designator::PlainByArgs,
247 userid_designator::OptionalValue>,
248
249 #[clap(
250 long = "remove-all",
251 help = "Remove all prior approvals",
252 conflicts_with = "add_all",
253 long_help = "\
254 Remove all prior approvals
255
256 By default, this command adds to the set of already approved
257 certifications. If this flag is given, the existing approvals are
258 disregarded, and only the newly selected certifications are approved,
259 if any.
260 ",
261 )]
262 pub remove_all: bool,
263
264 #[clap(
265 long = "remove-by",
266 value_name = "FINGERPRINT|KEYID",
267 help = "Remove all prior approvals of certifications by this certifier",
268 conflicts_with = "remove_all",
269 )]
270 pub remove_by: Vec<KeyHandle>,
271
272 #[clap(
273 long = "add-all",
274 help = "Approve of all pending certifications",
275 conflicts_with_all = ["remove_all", "remove_by"],
276 )]
277 pub add_all: bool,
278
279 #[clap(
280 long = "add-by",
281 value_name = "FINGERPRINT|KEYID",
282 help = "Approve of all certifications by this certifier",
283 conflicts_with = "add_all",
284 )]
285 pub add_by: Vec<KeyHandle>,
286
287 #[clap(
288 long = "add-authenticated",
289 value_name = "AMOUNT",
290 help = "Approve of all certifications by authenticated certifiers",
291 long_help = "\
292 Approve of all certifications by authenticated certifiers
293
294 For all pending approvals, try to authenticate any user ID on the
295 certifier, and if any can be authenticated, approve of the certification.",
296 conflicts_with = "add_all",
297 )]
298 pub add_authenticated: bool,
299
300 #[clap(
301 long,
302 value_name = FileOrStdout::VALUE_NAME,
303 help = "Write to the specified FILE",
304 long_help = "\
305 Write to the specified FILE
306
307 If not specified, and the certificate was read from the certificate \
308 store, imports the modified certificate into the cert store. If not \
309 specified, and the certificate was read from a file, writes the \
310 modified certificate to stdout.",
311 )]
312 pub output: Option<FileOrStdout>,
313 }