| 1 |
//! Command-line parser for `sq pki vouch authorize`. |
| 2 |
|
| 3 |
use clap::ArgGroup; |
| 4 |
use clap::Parser; |
| 5 |
|
| 6 |
use crate::cli::THIRD_PARTY_CERTIFICATION_VALIDITY_IN_YEARS; |
| 7 |
|
| 8 |
use crate::cli::types::ClapData; |
| 9 |
use crate::cli::types::expiration; |
| 10 |
use crate::cli::types::ExpirationArg; |
| 11 |
use crate::cli::types::FileOrStdout; |
| 12 |
use crate::cli::types::TrustAmount; |
| 13 |
use crate::cli::types::UserIDDesignators; |
| 14 |
use crate::cli::types::cert_designator::{self, *}; |
| 15 |
use crate::cli::types::userid_designator; |
| 16 |
|
| 17 |
use crate::cli::examples::*; |
| 18 |
|
| 19 |
const AUTHORIZE_EXAMPLES: Actions = Actions { |
| 20 |
actions: &[ |
| 21 |
Action::setup().command(&[ |
| 22 |
"sq", "key", "import", |
| 23 |
"alice-secret.pgp", |
| 24 |
]).build(), |
| 25 |
|
| 26 |
Action::setup().command(&[ |
| 27 |
"sq", "cert", "import", |
| 28 |
"ca-secret.pgp", |
| 29 |
]).build(), |
| 30 |
|
| 31 |
Action::example().comment( |
| 32 |
"Certify that E7FC51AD886BBB5C4F44C3D7A9DA14F3E740F63F \ |
| 33 |
is a trusted introducer for example.org and example.com.", |
| 34 |
).command(&[ |
| 35 |
"sq", "pki", "vouch", "authorize", |
| 36 |
"--certifier=EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 37 |
"--cert=E7FC51AD886BBB5C4F44C3D7A9DA14F3E740F63F", |
| 38 |
"--domain=example.org", |
| 39 |
"--domain=example.com", |
| 40 |
"--all", |
| 41 |
]).build(), |
| 42 |
], |
| 43 |
}; |
| 44 |
test_examples!(sq_pki_vouch_authorize, AUTHORIZE_EXAMPLES); |
| 45 |
|
| 46 |
#[derive(Parser, Debug)] |
| 47 |
#[clap( |
| 48 |
name = "authorize", |
| 49 |
about = "Mark a certificate as a trusted introducer", |
| 50 |
long_about = format!( |
| 51 |
"Mark a certificate as a trusted introducer |
| 52 |
|
| 53 |
Creates a certification that says that the issuer considers the \ |
| 54 |
certificate to be a trusted introducer. Trusted introducer is another \ |
| 55 |
word for certification authority (CA). When a user relies on a \ |
| 56 |
trusted introducer, the user considers certifications made by the \ |
| 57 |
trusted introducer to be valid. A trusted introducer can also \ |
| 58 |
designate further trusted introducers. |
| 59 |
|
| 60 |
As is, a trusted introducer has a lot of power. This power can be \ |
| 61 |
limited in several ways. |
| 62 |
|
| 63 |
- The ability to specify further introducers can be constrained \ |
| 64 |
using the `--depth` parameter. |
| 65 |
|
| 66 |
- The degree to which an introducer is trusted can be changed using \ |
| 67 |
the `--amount` parameter. |
| 68 |
|
| 69 |
- The user IDs that an introducer can certify can be constrained by \ |
| 70 |
domain using the `--domain` parameter or a regular expression using \ |
| 71 |
the `--regex` parameter. |
| 72 |
|
| 73 |
These mechanisms allow Alice to say that she is willing to rely on the \ |
| 74 |
CA for example.org, but only for user IDs that have an email address \ |
| 75 |
for example.org, for instance. |
| 76 |
|
| 77 |
By default a delegation expires after {} years. Use the `--expiration` \ |
| 78 |
argument to override this. |
| 79 |
|
| 80 |
This subcommand respects the reference time set by the top-level \ |
| 81 |
`--time` argument. It sets the certification's creation time to the \ |
| 82 |
reference time. |
| 83 |
", |
| 84 |
THIRD_PARTY_CERTIFICATION_VALIDITY_IN_YEARS, |
| 85 |
), |
| 86 |
after_help = AUTHORIZE_EXAMPLES, |
| 87 |
)] |
| 88 |
#[clap(group(ArgGroup::new("constraint").args(&["regex", "domain", "unconstrained"]).required(true).multiple(true)))] |
| 89 |
pub struct Command { |
| 90 |
#[command(flatten)] |
| 91 |
pub certifier: CertDesignators<CertUserIDEmailFileSelfArgs, |
| 92 |
CertifierPrefix, |
| 93 |
OneValue, |
| 94 |
CertifierDoc>, |
| 95 |
|
| 96 |
#[command(flatten)] |
| 97 |
pub cert: CertDesignators< |
| 98 |
cert_designator::CertFileArgs, |
| 99 |
cert_designator::CertPrefix, |
| 100 |
cert_designator::OneValue>, |
| 101 |
|
| 102 |
#[command(flatten)] |
| 103 |
pub userids: UserIDDesignators< |
| 104 |
userid_designator::AllExactByAndAddArgs>, |
| 105 |
|
| 106 |
#[clap( |
| 107 |
long = "amount", |
| 108 |
value_name = "AMOUNT", |
| 109 |
default_value = "full", |
| 110 |
help = "Set the amount of trust", |
| 111 |
long_help = |
| 112 |
"Set the amount of trust |
| 113 |
|
| 114 |
Values between 1 and 120 are meaningful. \ |
| 115 |
120 means fully trusted. Values less than 120 indicate the degree \ |
| 116 |
of trust. 60 is usually used for partially trusted.", |
| 117 |
)] |
| 118 |
pub amount: TrustAmount<u8>, |
| 119 |
|
| 120 |
#[clap( |
| 121 |
long = "depth", |
| 122 |
value_name = "TRUST_DEPTH", |
| 123 |
default_value = "1", |
| 124 |
help = "Set the trust depth", |
| 125 |
long_help = |
| 126 |
"Set the trust depth |
| 127 |
|
| 128 |
This is sometimes referred to as the trust level. \ |
| 129 |
1 means CERTIFICATE is a trusted introducer (default), 2 means \ |
| 130 |
CERTIFICATE is a meta-trusted introducer and can authorize \ |
| 131 |
another trusted introducer, etc.", |
| 132 |
)] |
| 133 |
pub depth: u8, |
| 134 |
|
| 135 |
#[clap( |
| 136 |
long = "domain", |
| 137 |
value_name = "DOMAIN", |
| 138 |
help = "Add a domain constraint to the introducer", |
| 139 |
long_help = "\ |
| 140 |
Add a domain constraint to the introducer |
| 141 |
|
| 142 |
Add a domain to constrain what certifications are respected. A \ |
| 143 |
certification made by the certificate is only respected if it is over \ |
| 144 |
a user ID with an email address in the specified domain. Multiple \ |
| 145 |
domains may be specified. In that case, one must match.", |
| 146 |
)] |
| 147 |
pub domain: Vec<String>, |
| 148 |
#[clap( |
| 149 |
long = "regex", |
| 150 |
value_name = "REGEX", |
| 151 |
help = "Add a regular expression to constrain the introducer", |
| 152 |
long_help = "\ |
| 153 |
Add a regular expression to constrain the introducer |
| 154 |
|
| 155 |
Add a regular expression to constrain what certifications are \ |
| 156 |
respected. A certification made by the certificate is only respected \ |
| 157 |
if it is over a user ID that matches one of the specified regular \ |
| 158 |
expression. Multiple regular expressions may be specified. In that \ |
| 159 |
case, at least one must match.", |
| 160 |
)] |
| 161 |
pub regex: Vec<String>, |
| 162 |
#[clap( |
| 163 |
long, |
| 164 |
conflicts_with = "regex", |
| 165 |
help = "Don't constrain the introducer", |
| 166 |
long_help = "\ |
| 167 |
Don't constrain the introducer |
| 168 |
|
| 169 |
Normally an introducer is constrained so that only certain user IDs \ |
| 170 |
are respected, e.g., those that have an email address for a certain \ |
| 171 |
domain name. This option authorizes an introducer without \ |
| 172 |
constraining it in this way. Because this grants the introducer a lot \ |
| 173 |
of power, you have to opt in to this behavior explicitly.", |
| 174 |
)] |
| 175 |
pub unconstrained: bool, |
| 176 |
|
| 177 |
#[clap( |
| 178 |
long = "local", |
| 179 |
help = "Make the certification a local certification", |
| 180 |
long_help = |
| 181 |
"Make the certification a local certification |
| 182 |
|
| 183 |
Normally, local certifications are not exported.", |
| 184 |
)] |
| 185 |
pub local: bool, |
| 186 |
#[clap( |
| 187 |
long = "non-revocable", |
| 188 |
help = "Mark the certification as being non-revocable", |
| 189 |
long_help = |
| 190 |
"Mark the certification as being non-revocable |
| 191 |
|
| 192 |
That is, you cannot later revoke this \ |
| 193 |
certification. This should normally only \ |
| 194 |
be used with an expiration.", |
| 195 |
)] |
| 196 |
pub non_revocable: bool, |
| 197 |
|
| 198 |
#[command(flatten)] |
| 199 |
pub expiration: ExpirationArg<expiration::CertificationKind>, |
| 200 |
|
| 201 |
/// Workaround for https://github.com/clap-rs/clap/issues/3846 |
| 202 |
#[clap(skip)] |
| 203 |
pub expiration_source: Option<clap::parser::ValueSource>, |
| 204 |
|
| 205 |
#[command(flatten)] |
| 206 |
pub signature_notations: crate::cli::types::SignatureNotationsArg, |
| 207 |
|
| 208 |
#[clap( |
| 209 |
help = FileOrStdout::HELP_OPTIONAL, |
| 210 |
long, |
| 211 |
value_name = FileOrStdout::VALUE_NAME, |
| 212 |
)] |
| 213 |
pub output: Option<FileOrStdout>, |
| 214 |
} |