| 1 |
//! Command-line parser for `sq cert list`. |
| 2 |
|
| 3 |
use clap::Parser; |
| 4 |
|
| 5 |
use crate::cli::examples::Action; |
| 6 |
use crate::cli::examples::Actions; |
| 7 |
use crate::cli::pki::CertificationNetworkArg; |
| 8 |
use crate::cli::pki::GossipArg; |
| 9 |
use crate::cli::pki::RequiredTrustAmountArg; |
| 10 |
use crate::cli::pki::ShowPathsArg; |
| 11 |
use crate::cli::pki::UnusableArg; |
| 12 |
use crate::cli::types::cert_designator::*; |
| 13 |
|
| 14 |
const EXAMPLES: Actions = Actions { |
| 15 |
actions: &[ |
| 16 |
Action::setup().command(&[ |
| 17 |
"sq", "pki", "link", "add", |
| 18 |
"--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 19 |
"--all", |
| 20 |
]).build(), |
| 21 |
|
| 22 |
Action::example().comment( |
| 23 |
"List all bindings for user IDs containing an email address from \ |
| 24 |
example.org, and that can be authenticated." |
| 25 |
).command (&[ |
| 26 |
"sq", "cert", "list", "@example.org", |
| 27 |
]).build(), |
| 28 |
|
| 29 |
Action::example().comment( |
| 30 |
"List all authenticated bindings for User IDs containing a specific email address." |
| 31 |
).command (&[ |
| 32 |
"sq", "cert", "list", |
| 33 |
"[email protected]", |
| 34 |
]).build(), |
| 35 |
|
| 36 |
Action::example().comment( |
| 37 |
"List all paths to certificates containing a specific email address." |
| 38 |
).command (&[ |
| 39 |
"sq", "cert", "list", "--gossip", "--show-paths", |
| 40 |
"[email protected]", |
| 41 |
]).build(), |
| 42 |
] |
| 43 |
}; |
| 44 |
test_examples!(sq_cert_list, EXAMPLES); |
| 45 |
|
| 46 |
/// List certificates and user IDs |
| 47 |
/// |
| 48 |
/// List certificates and user IDs that match a query, are usable, and |
| 49 |
/// can be authenticated. By default, bindings (certificate and user |
| 50 |
/// ID pairs) must be fully authenticated. If no certificates or |
| 51 |
/// bindings match a query, then the command returns a non-zero exit |
| 52 |
/// code. |
| 53 |
/// |
| 54 |
/// If no queries are provided, then all bindings that are usable, and |
| 55 |
/// can be authenticated are listed. If there are no such bindings, |
| 56 |
/// the command still succeeds. |
| 57 |
/// |
| 58 |
/// By default, unusable certificates, i.e., those that are not valid |
| 59 |
/// according to the policy, are revoked, or are not live, are |
| 60 |
/// skipped. Likewise, user ID self signatures and certifications |
| 61 |
/// that are not valid according to the policy, and user IDs that are |
| 62 |
/// revoked are skipped. |
| 63 |
#[derive(Parser, Debug)] |
| 64 |
#[clap( |
| 65 |
name = "list", |
| 66 |
after_help = EXAMPLES, |
| 67 |
)] |
| 68 |
pub struct Command { |
| 69 |
#[command(flatten)] |
| 70 |
pub certs: CertDesignators<CertUserIDEmailDomainGrepArgs, |
| 71 |
CertPrefix, |
| 72 |
OptionalValue, |
| 73 |
ListCertDoc>, |
| 74 |
|
| 75 |
#[clap( |
| 76 |
value_name = "FINGERPRINT|KEYID|PATTERN", |
| 77 |
help = "List certs that match the pattern", |
| 78 |
long_help = "\ |
| 79 |
List certs that match the pattern |
| 80 |
|
| 81 |
If the pattern appears to be a fingerprint or key ID, it is treated as \ |
| 82 |
if it were passed to `--cert`, which matches on the certificate's \ |
| 83 |
fingerprint. Otherwise, it is treated as if it were passed to \ |
| 84 |
`--cert-grep`, which matches on user IDs.", |
| 85 |
conflicts_with_all = &["cert", "cert-userid", "cert-email", |
| 86 |
"cert-domain", "cert-grep"], |
| 87 |
)] |
| 88 |
pub pattern: Option<String>, |
| 89 |
|
| 90 |
#[command(flatten)] |
| 91 |
pub show_paths: ShowPathsArg, |
| 92 |
|
| 93 |
#[command(flatten)] |
| 94 |
pub gossip: GossipArg, |
| 95 |
|
| 96 |
#[command(flatten)] |
| 97 |
pub unusable: UnusableArg, |
| 98 |
|
| 99 |
#[command(flatten)] |
| 100 |
pub certification_network: CertificationNetworkArg, |
| 101 |
|
| 102 |
#[command(flatten)] |
| 103 |
pub trust_amount: RequiredTrustAmountArg, |
| 104 |
} |
| 105 |
|
| 106 |
/// Documentation for the cert designators for the cert list. |
| 107 |
pub struct ListCertDoc {} |
| 108 |
|
| 109 |
impl AdditionalDocs for ListCertDoc { |
| 110 |
fn help(arg: &'static str, _help: &'static str) -> clap::builder::StyledStr { |
| 111 |
match arg { |
| 112 |
"cert" => "\ |
| 113 |
List certificates with the specified fingerprint or key ID".into(), |
| 114 |
"userid" => "\ |
| 115 |
List bindings with the specified user ID".into(), |
| 116 |
"email" => "\ |
| 117 |
List bindings with user IDs that contain the specified email address".into(), |
| 118 |
"domain" => "\ |
| 119 |
List bindings with user IDs that contain an email address in the \ |
| 120 |
specified domain".into(), |
| 121 |
"grep" => "\ |
| 122 |
List bindings with a user ID that contains the pattern".into(), |
| 123 |
_ => unreachable!(), |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
fn long_help(arg: &'static str, _help: &'static str) |
| 128 |
-> Option<clap::builder::StyledStr> |
| 129 |
{ |
| 130 |
match arg { |
| 131 |
"cert" => Some(format!("\ |
| 132 |
{} |
| 133 |
|
| 134 |
Note: fingerprints and key IDs are self-authenticating identifiers. As \ |
| 135 |
such, a certificate with the specified fingerprint or key ID is \ |
| 136 |
considered authenticated; no user IDs have to be authenticated.", |
| 137 |
Self::help(arg, "")).into()), |
| 138 |
"userid" => Some(format!("\ |
| 139 |
{} |
| 140 |
|
| 141 |
The user ID must match exactly.", |
| 142 |
Self::help(arg, "")).into()), |
| 143 |
"email" => Some(format!("\ |
| 144 |
{} |
| 145 |
|
| 146 |
Email addresses are first normalized by doing puny-code normalization on \ |
| 147 |
the domain, and lower casing the local part in the so-called empty \ |
| 148 |
locale.", |
| 149 |
Self::help(arg, "")).into()), |
| 150 |
"domain" => Some(format!("\ |
| 151 |
{} |
| 152 |
|
| 153 |
A user ID's domain is extracted from the email address, if any, and is \ |
| 154 |
normalized by doing puny-code normalization.", |
| 155 |
Self::help(arg, "")).into()), |
| 156 |
"grep" => Some(format!("\ |
| 157 |
{} |
| 158 |
|
| 159 |
Performs a case-insensitive substring search. Case-folding is done in \ |
| 160 |
the empty locale.", |
| 161 |
Self::help(arg, "")).into()), |
| 162 |
_ => { |
| 163 |
None |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
} |