| 1 |
//! Command-line parser for `sq pki authenticate`. |
| 2 |
|
| 3 |
use clap::Parser; |
| 4 |
|
| 5 |
use crate::cli::examples; |
| 6 |
use examples::Action; |
| 7 |
use examples::Actions; |
| 8 |
|
| 9 |
use crate::cli::types::CertDesignators; |
| 10 |
use crate::cli::types::UserIDDesignators; |
| 11 |
use crate::cli::types::cert_designator; |
| 12 |
use crate::cli::types::userid_designator; |
| 13 |
|
| 14 |
use super::CertificationNetworkArg; |
| 15 |
use super::GossipArg; |
| 16 |
use super::RequiredTrustAmountArg; |
| 17 |
use super::ShowPathsArg; |
| 18 |
use super::UnusableArg; |
| 19 |
|
| 20 |
/// Authenticate a binding |
| 21 |
/// |
| 22 |
/// Authenticate a binding (a certificate and User ID) by looking |
| 23 |
/// for a path from the trust roots to the specified binding in |
| 24 |
/// the Web of Trust. Because certifications may express |
| 25 |
/// uncertainty (i.e., certifications may be marked as conveying |
| 26 |
/// only partial or marginal trust), multiple paths may be needed. |
| 27 |
/// |
| 28 |
/// An error is return if no binding could be authenticated to the |
| 29 |
/// specified level (by default: fully authenticated, i.e., a trust |
| 30 |
/// amount of 120). |
| 31 |
/// |
| 32 |
/// If any valid paths to the binding are found, they are printed |
| 33 |
/// on stdout whether they are sufficient to authenticate the |
| 34 |
/// binding or not. |
| 35 |
#[derive(Parser, Debug)] |
| 36 |
#[clap( |
| 37 |
name = "authenticate", |
| 38 |
after_help = EXAMPLES, |
| 39 |
)] |
| 40 |
pub struct Command { |
| 41 |
// Note: don't add --cert-file: the certificate needs to be merged |
| 42 |
// into the certificate store, and --cert-file doesn't do that. |
| 43 |
// Instead, the user should use --keyring FILE and --cert FPR. |
| 44 |
#[command(flatten)] |
| 45 |
pub cert: CertDesignators< |
| 46 |
cert_designator::CertArg, |
| 47 |
cert_designator::CertPrefix, |
| 48 |
cert_designator::OneValue>, |
| 49 |
|
| 50 |
#[command(flatten)] |
| 51 |
pub userid: UserIDDesignators< |
| 52 |
userid_designator::PlainByArgs, |
| 53 |
userid_designator::OneValueNoLinting, |
| 54 |
Documentation>, |
| 55 |
|
| 56 |
#[command(flatten)] |
| 57 |
pub show_paths: ShowPathsArg, |
| 58 |
|
| 59 |
#[command(flatten)] |
| 60 |
pub gossip: GossipArg, |
| 61 |
|
| 62 |
#[command(flatten)] |
| 63 |
pub unusable: UnusableArg, |
| 64 |
|
| 65 |
#[command(flatten)] |
| 66 |
pub certification_network: CertificationNetworkArg, |
| 67 |
|
| 68 |
#[command(flatten)] |
| 69 |
pub trust_amount: RequiredTrustAmountArg, |
| 70 |
} |
| 71 |
|
| 72 |
/// Documentation for the user ID designators. |
| 73 |
#[derive(Debug, Clone)] |
| 74 |
pub struct Documentation(()); |
| 75 |
|
| 76 |
impl userid_designator::Documentation for Documentation { |
| 77 |
fn help(typ: userid_designator::UserIDDesignatorType, |
| 78 |
_plain: bool, |
| 79 |
semantics: userid_designator::UserIDDesignatorSemantics) |
| 80 |
-> (&'static str, Option<&'static str>) |
| 81 |
{ |
| 82 |
use userid_designator::UserIDDesignatorType::*; |
| 83 |
match (typ, semantics) { |
| 84 |
(UserID, _) => { |
| 85 |
("Authenticate the specified user ID", |
| 86 |
Some("\ |
| 87 |
Authenticate the specified user ID |
| 88 |
|
| 89 |
The specified user ID does not need to be self signed.")) |
| 90 |
} |
| 91 |
(Email, _) => { |
| 92 |
("Authenticate the specified email address", |
| 93 |
Some("\ |
| 94 |
Authenticate the specified email address |
| 95 |
|
| 96 |
This checks whether it is possible to authenticate a user ID with the \ |
| 97 |
specified email address. The user IDs do not need to be self signed. \ |
| 98 |
To authenticate a user ID containing just the specified email address, \ |
| 99 |
use `--userid <EMAIL>`.")) |
| 100 |
} |
| 101 |
(Name, _) => { |
| 102 |
("Authenticate the specified display name", |
| 103 |
Some("\ |
| 104 |
Authenticate the specified display name |
| 105 |
|
| 106 |
This checks whether it is possible to authenticate a user ID with the \ |
| 107 |
specified display name. The user IDs do not need to be self signed. \ |
| 108 |
To authenticate a user ID containing just the specified display name, \ |
| 109 |
use `--userid NAME`.")) |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
const EXAMPLES: Actions = Actions { |
| 116 |
actions: &[ |
| 117 |
// Link Alice's certificate. |
| 118 |
Action::setup().command(&[ |
| 119 |
"sq", "pki", "link", "add", |
| 120 |
"--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 121 |
"--all", |
| 122 |
]).build(), |
| 123 |
|
| 124 |
Action::example().comment( |
| 125 |
"Authenticate a specific binding.", |
| 126 |
).command(&[ |
| 127 |
"sq", "pki", "authenticate", |
| 128 |
"--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 129 |
"--userid", "Alice <[email protected]>", |
| 130 |
]).build(), |
| 131 |
|
| 132 |
Action::example().comment( |
| 133 |
"Check whether we can authenticate any user ID with the specified email \ |
| 134 |
address for the given certificate.", |
| 135 |
).command(&[ |
| 136 |
"sq", "pki", "authenticate", |
| 137 |
"--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 138 |
"--email", "[email protected]", |
| 139 |
]).build(), |
| 140 |
], |
| 141 |
}; |
| 142 |
test_examples!(sq_pki_authenticate, EXAMPLES); |