| 1 |
//! Command-line parser for `sq pki`. |
| 2 |
|
| 3 |
use std::ops::Deref; |
| 4 |
|
| 5 |
use clap::Parser; |
| 6 |
|
| 7 |
use crate::cli::types::TrustAmount; |
| 8 |
|
| 9 |
pub mod authenticate; |
| 10 |
pub mod identify; |
| 11 |
pub mod lookup; |
| 12 |
pub mod link; |
| 13 |
pub mod path; |
| 14 |
pub mod vouch; |
| 15 |
|
| 16 |
#[derive(Debug, Parser)] |
| 17 |
#[clap( |
| 18 |
name = "pki", |
| 19 |
about = "Authenticate certs using the Web of Trust", |
| 20 |
long_about = |
| 21 |
"Authenticate certs using the Web of Trust |
| 22 |
|
| 23 |
The \"Web of Trust\" is a decentralized trust model popularized by PGP. \ |
| 24 |
It is a superset of X.509, which is a hierarchical trust model, and is \ |
| 25 |
the most popular trust model on the public internet today. As used on \ |
| 26 |
the public internet, however, X.509 relies on a handful of global \ |
| 27 |
certification authorities (CAs) who often undermine its security. |
| 28 |
|
| 29 |
The Web of Trust is more nuanced than X.509. Using the Web of Trust, \ |
| 30 |
require multiple, independent paths to authenticate a binding by only \ |
| 31 |
partially trusting CAs. This prevents a single bad actor from \ |
| 32 |
compromising their security. And those who have stronger security \ |
| 33 |
requirements can use the Web of Trust in a completely decentralized \ |
| 34 |
manner where only the individuals they select – who are not \ |
| 35 |
necessarily institutions – act as trusted introducers. |
| 36 |
", |
| 37 |
subcommand_required = true, |
| 38 |
arg_required_else_help = true, |
| 39 |
disable_help_subcommand = true, |
| 40 |
)] |
| 41 |
pub struct Command { |
| 42 |
#[command(subcommand)] |
| 43 |
pub subcommand: Subcommands, |
| 44 |
} |
| 45 |
|
| 46 |
#[derive(clap::Subcommand, Debug)] |
| 47 |
pub enum Subcommands { |
| 48 |
Authenticate(authenticate::Command), |
| 49 |
Lookup(lookup::Command), |
| 50 |
Identify(identify::Command), |
| 51 |
Vouch(vouch::Command), |
| 52 |
Link(link::Command), |
| 53 |
Path(path::Command), |
| 54 |
} |
| 55 |
|
| 56 |
#[derive(clap::Args, Debug)] |
| 57 |
pub struct GossipArg { |
| 58 |
/// Treats all certificates as unreliable trust roots |
| 59 |
/// |
| 60 |
/// This option is useful for figuring out what others think about |
| 61 |
/// a certificate (i.e., gossip or hearsay). In other words, this |
| 62 |
/// finds arbitrary paths to a particular certificate. |
| 63 |
/// |
| 64 |
/// Gossip is useful in helping to identify alternative ways to |
| 65 |
/// authenticate a certificate. For instance, imagine Ed wants to |
| 66 |
/// authenticate Laura's certificate, but asking her directly is |
| 67 |
/// inconvenient. Ed discovers that Micah has certified Laura's |
| 68 |
/// certificate, but Ed hasn't yet authenticated Micah's |
| 69 |
/// certificate. If Ed is willing to rely on Micah as a trusted |
| 70 |
/// introducer, and authenticating Micah's certificate is easier |
| 71 |
/// than authenticating Laura's certificate, then Ed has learned |
| 72 |
/// about an easier way to authenticate Laura's certificate. |
| 73 |
/// |
| 74 |
/// Stable since 1.1.0. |
| 75 |
#[arg(long)] |
| 76 |
pub gossip: bool, |
| 77 |
} |
| 78 |
|
| 79 |
impl Deref for GossipArg { |
| 80 |
type Target = bool; |
| 81 |
|
| 82 |
fn deref(&self) -> &Self::Target { |
| 83 |
&self.gossip |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
#[derive(clap::Args, Debug)] |
| 88 |
pub struct UnusableArg { |
| 89 |
/// Show bindings that are unusable |
| 90 |
/// |
| 91 |
/// Normally, unusable certificates and bindings are not shown. |
| 92 |
/// This option considers bindings, even if they are not unusable, |
| 93 |
/// because they (or the certificates) are not valid according to |
| 94 |
/// the policy, are revoked, or are not live. |
| 95 |
/// |
| 96 |
/// This option only makes sense with `--gossip`, because unusable |
| 97 |
/// bindings are still considered unauthenticated. |
| 98 |
/// |
| 99 |
/// Stable since 1.1.0. |
| 100 |
#[arg(long, requires="gossip")] |
| 101 |
pub unusable: bool, |
| 102 |
} |
| 103 |
|
| 104 |
impl Deref for UnusableArg { |
| 105 |
type Target = bool; |
| 106 |
|
| 107 |
fn deref(&self) -> &Self::Target { |
| 108 |
&self.unusable |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
#[derive(clap::Args, Debug)] |
| 113 |
pub struct CertificationNetworkArg { |
| 114 |
/// Treats the network as a certification network |
| 115 |
/// |
| 116 |
/// Normally, the authentication machinery treats the Web of Trust |
| 117 |
/// network as an authentication network where a certification |
| 118 |
/// only means that the binding is correct, not that the target |
| 119 |
/// should be treated as a trusted introducer. In a certification |
| 120 |
/// network, the targets of certifications are treated as trusted |
| 121 |
/// introducers with infinite depth, and any regular expressions |
| 122 |
/// are ignored. Note: The trust amount remains unchanged. This |
| 123 |
/// is how most so-called PGP path-finding algorithms work. |
| 124 |
#[arg(long)] |
| 125 |
pub certification_network: bool, |
| 126 |
} |
| 127 |
|
| 128 |
impl Deref for CertificationNetworkArg { |
| 129 |
type Target = bool; |
| 130 |
|
| 131 |
fn deref(&self) -> &Self::Target { |
| 132 |
&self.certification_network |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
#[derive(clap::Args, Debug)] |
| 137 |
pub struct RequiredTrustAmountArg { |
| 138 |
/// The required amount of trust |
| 139 |
/// |
| 140 |
/// 120 indicates full authentication; values less than 120 |
| 141 |
/// indicate partial authentication. When |
| 142 |
/// `--certification-network` is passed, this defaults to 1200, |
| 143 |
/// i.e., this command tries to find 10 paths. |
| 144 |
#[arg(long="amount", value_name = "AMOUNT")] |
| 145 |
pub trust_amount: Option<TrustAmount<usize>>, |
| 146 |
} |
| 147 |
|
| 148 |
impl Deref for RequiredTrustAmountArg { |
| 149 |
type Target = Option<TrustAmount<usize>>; |
| 150 |
|
| 151 |
fn deref(&self) -> &Self::Target { |
| 152 |
&self.trust_amount |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
#[derive(clap::Args, Debug)] |
| 157 |
pub struct ShowPathsArg { |
| 158 |
/// Show why a binding is authenticated |
| 159 |
/// |
| 160 |
/// By default, only a user ID and certificate binding's degree of |
| 161 |
/// authentication (a value between 0 and 120) is shown. This |
| 162 |
/// changes the output to also show how that value was computed by |
| 163 |
/// showing the paths from the trust roots to the bindings. |
| 164 |
#[arg(long)] |
| 165 |
pub show_paths: bool, |
| 166 |
} |
| 167 |
|
| 168 |
impl Deref for ShowPathsArg { |
| 169 |
type Target = bool; |
| 170 |
|
| 171 |
fn deref(&self) -> &Self::Target { |
| 172 |
&self.show_paths |
| 173 |
} |
| 174 |
} |