| 1 |
use std::path::PathBuf; |
| 2 |
use clap::{Args, Parser, Subcommand}; |
| 3 |
|
| 4 |
use sequoia_net::wkd; |
| 5 |
|
| 6 |
use crate::cli::types::ClapData; |
| 7 |
use crate::cli::types::FileOrCertStore; |
| 8 |
use crate::cli::types::FileOrStdout; |
| 9 |
use crate::cli::types::cert_designator::{ |
| 10 |
CertDesignators, |
| 11 |
CertUserIDEmailFileArgs, |
| 12 |
CertPrefix, |
| 13 |
OptionalValue, |
| 14 |
}; |
| 15 |
|
| 16 |
use crate::cli::examples::*; |
| 17 |
|
| 18 |
#[derive(Parser, Debug)] |
| 19 |
#[clap( |
| 20 |
name = "wkd", |
| 21 |
about = "Retrieve and publishes certificates via Web Key Directories", |
| 22 |
long_about = |
| 23 |
"Retrieve and publishes certificates via Web Key Directories |
| 24 |
|
| 25 |
The Web Key Directory (WKD) is a method for publishing and retrieving \ |
| 26 |
certificates from web servers. |
| 27 |
", |
| 28 |
subcommand_required = true, |
| 29 |
arg_required_else_help = true, |
| 30 |
disable_help_subcommand = true, |
| 31 |
)] |
| 32 |
pub struct Command { |
| 33 |
#[clap(subcommand)] |
| 34 |
pub subcommand: Subcommands, |
| 35 |
} |
| 36 |
|
| 37 |
#[derive(Debug, Subcommand)] |
| 38 |
pub enum Subcommands { |
| 39 |
Search(SearchCommand), |
| 40 |
Publish(PublishCommand), |
| 41 |
} |
| 42 |
|
| 43 |
#[derive(Debug, Args)] |
| 44 |
#[clap( |
| 45 |
about = "Retrieve certificates from a Web Key Directory", |
| 46 |
long_about = |
| 47 |
"Retrieve certificates from a Web Key Directory |
| 48 |
|
| 49 |
By default, any returned certificates are stored in the local \ |
| 50 |
certificate store. This can be overridden by using `--output` \ |
| 51 |
option. |
| 52 |
|
| 53 |
When a certificate is retrieved from a WKD, and imported into the \ |
| 54 |
local certificate store, any User IDs with the email address that was \ |
| 55 |
looked up are certificated with a local WKD-specific key. That proxy \ |
| 56 |
certificate is in turn certified as a minimally trusted CA (trust \ |
| 57 |
amount: 1 of 120) by the local trust root. How much the WKD proxy CA \ |
| 58 |
is trusted can be tuned using `sq pki link add` or `sq pki link retract` \ |
| 59 |
in the usual way. |
| 60 |
", |
| 61 |
after_help = SEARCH_EXAMPLES, |
| 62 |
)] |
| 63 |
pub struct SearchCommand { |
| 64 |
#[clap( |
| 65 |
long, |
| 66 |
conflicts_with = "addresses", |
| 67 |
help = "Fetch updates for all known certificates", |
| 68 |
)] |
| 69 |
pub all: bool, |
| 70 |
|
| 71 |
#[clap( |
| 72 |
value_name = "ADDRESS", |
| 73 |
required = true, |
| 74 |
help = "Retrieve certificate(s) for ADDRESS", |
| 75 |
)] |
| 76 |
pub addresses: Vec<String>, |
| 77 |
|
| 78 |
#[clap( |
| 79 |
help = FileOrCertStore::HELP_OPTIONAL, |
| 80 |
long, |
| 81 |
value_name = FileOrCertStore::VALUE_NAME, |
| 82 |
)] |
| 83 |
pub output: Option<FileOrStdout>, |
| 84 |
} |
| 85 |
|
| 86 |
const SEARCH_EXAMPLES: Actions = Actions { |
| 87 |
actions: &[ |
| 88 |
Action::example().comment( |
| 89 |
"Retrieve Alice's certificate over WKD." |
| 90 |
).command(&[ |
| 91 |
"sq", "network", "wkd", "search", "[email protected]", |
| 92 |
]).syntax_check(), |
| 93 |
|
| 94 |
Action::example().comment( |
| 95 |
"Retrieve updates for all known certificates over WKD." |
| 96 |
).command(&[ |
| 97 |
"sq", "network", "wkd", "search", "--all", |
| 98 |
]).syntax_check(), |
| 99 |
], |
| 100 |
}; |
| 101 |
test_examples!(sq_network_wkd_search, SEARCH_EXAMPLES); |
| 102 |
|
| 103 |
const PUBLISH_EXAMPLES: Actions = Actions { |
| 104 |
actions: &[ |
| 105 |
Action::setup().command(&[ |
| 106 |
"sq", "cert", "import", "juliet.pgp", |
| 107 |
]).build(), |
| 108 |
|
| 109 |
Action::setup().command(&[ |
| 110 |
"sq", "pki", "link", "add", |
| 111 |
"--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 112 |
"--userid=Alice <[email protected]>", |
| 113 |
]).build(), |
| 114 |
|
| 115 |
Action::example().comment( |
| 116 |
"Create a new WKD hierarchy in the local directory \ |
| 117 |
`public_html`, and insert Alice's cert.", |
| 118 |
).command(&[ |
| 119 |
"sq", "network", "wkd", "publish", "--create", |
| 120 |
"--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 121 |
"--domain=example.org", "public_html", |
| 122 |
]).build(), |
| 123 |
|
| 124 |
Action::example().comment( |
| 125 |
"Add Bob's cert to the existing WKD hierarchy \ |
| 126 |
in the local directory `public_html`.", |
| 127 |
).command(&[ |
| 128 |
"sq", "network", "wkd", "publish", |
| 129 |
"--cert=511257EBBF077B7AEDAE5D093F68CB84CE537C9A", |
| 130 |
"--domain=example.org", "public_html", |
| 131 |
]).build(), |
| 132 |
|
| 133 |
Action::example().comment( |
| 134 |
"Add all certs with an authenticated user ID \ |
| 135 |
in example.org to the existing WKD hierarchy.", |
| 136 |
).command(&[ |
| 137 |
"sq", "network", "wkd", "publish", |
| 138 |
"--domain=example.org", |
| 139 |
"--all", |
| 140 |
"public_html", |
| 141 |
]).build(), |
| 142 |
|
| 143 |
Action::example().comment( |
| 144 |
"Refresh all certs in the existing WKD hierarchy \ |
| 145 |
in the local directory `public_html` from the \ |
| 146 |
cert store.", |
| 147 |
).command(&[ |
| 148 |
"sq", "network", "wkd", "publish", |
| 149 |
"--domain=example.org", "public_html", |
| 150 |
]).build(), |
| 151 |
], |
| 152 |
}; |
| 153 |
|
| 154 |
test_examples!(sq_network_wkd_publish, PUBLISH_EXAMPLES); |
| 155 |
|
| 156 |
#[derive(Debug, Args)] |
| 157 |
#[clap( |
| 158 |
about = "Publish certificates in a Web Key Directory", |
| 159 |
long_about = |
| 160 |
"Publish certificates in a Web Key Directory |
| 161 |
|
| 162 |
Publishes certificates or certificate updates in a Web Key Directory \ |
| 163 |
(WKD). You can create or update a WKD hierarchy on the local system by \ |
| 164 |
specifying a path as destination. |
| 165 |
|
| 166 |
Typically, a WKD is stored on a web server. If `--rsync` is given, this \ |
| 167 |
command manages remote WKD directory hierarchies by using rsync(1). |
| 168 |
|
| 169 |
To insert a new certificate into the WKD, use `--cert`. |
| 170 |
|
| 171 |
Any updates for certificates already existing in the WKD are \ |
| 172 |
automatically published. |
| 173 |
|
| 174 |
Note: To update a WKD hierarchy, it is first copied to a temporary \ |
| 175 |
location on the local machine, new certificates or certificate updates \ |
| 176 |
are inserted into the local copy, and the hierarchy is copied back to \ |
| 177 |
its original location. As this is not an atomic operation, care must \ |
| 178 |
be taken to avoid concurrent updates. |
| 179 |
", |
| 180 |
after_help = PUBLISH_EXAMPLES, |
| 181 |
)] |
| 182 |
pub struct PublishCommand { |
| 183 |
#[command(flatten)] |
| 184 |
pub certs: CertDesignators<CertUserIDEmailFileArgs, |
| 185 |
CertPrefix, |
| 186 |
OptionalValue>, |
| 187 |
|
| 188 |
#[clap( |
| 189 |
long = "all", |
| 190 |
help = "Publish authenticated certs with a user ID matching domain", |
| 191 |
long_help = "\ |
| 192 |
Publish authenticated certs with a user ID matching domain |
| 193 |
|
| 194 |
Use all certificates that have a user ID matching the domain given \ |
| 195 |
to the `--domain` parameter that can be fully authenticated.", |
| 196 |
)] |
| 197 |
pub all: bool, |
| 198 |
|
| 199 |
#[clap( |
| 200 |
long = "create", |
| 201 |
help = "Create the WKD hierarchy if it does not exist yet", |
| 202 |
)] |
| 203 |
pub create: bool, |
| 204 |
|
| 205 |
#[clap( |
| 206 |
long = "method", |
| 207 |
value_name = "METHOD", |
| 208 |
requires = "create", |
| 209 |
help = "Select kind of WKD hierarchy to be created", |
| 210 |
long_help = "Select kind of WKD hierarchy to be created |
| 211 |
|
| 212 |
The advanced method, which is the default and should be preferred, \ |
| 213 |
is hosted on a separate domain (e.g. openpgpkey.example.org). |
| 214 |
|
| 215 |
The direct method is hosted on the same domain (e.g. example.org).", |
| 216 |
)] |
| 217 |
pub method: Option<Method>, |
| 218 |
|
| 219 |
#[clap( |
| 220 |
long = "rsync", |
| 221 |
help = "Use rsync(1) to access DEST", |
| 222 |
)] |
| 223 |
pub rsync: bool, |
| 224 |
|
| 225 |
#[clap( |
| 226 |
long = "rsync-path", |
| 227 |
value_name = "RSYNC", |
| 228 |
help = "Path to the local rsync command to use, implies --rsync", |
| 229 |
)] |
| 230 |
pub rsync_path: Option<PathBuf>, |
| 231 |
|
| 232 |
#[clap( |
| 233 |
long = "domain", |
| 234 |
value_name = "FQDN", |
| 235 |
help = "Generate a WKD for a fully qualified domain name for email", |
| 236 |
)] |
| 237 |
pub domain: String, |
| 238 |
#[clap( |
| 239 |
value_name = "DEST", |
| 240 |
help = "Location of the WKD on the local or remote machine", |
| 241 |
long_help = "Location of the WKD on the local or remote machine |
| 242 |
|
| 243 |
If --rsync is given, this is passed as-is to rsync(1).", |
| 244 |
)] |
| 245 |
pub destination: String, |
| 246 |
} |
| 247 |
|
| 248 |
#[derive(clap::ValueEnum, Debug, Clone, Copy, Default)] |
| 249 |
pub enum Method { |
| 250 |
/// Create a WKD using the advanced method. |
| 251 |
#[default] |
| 252 |
Advanced, |
| 253 |
|
| 254 |
/// Create a WKD using the direct method. |
| 255 |
Direct, |
| 256 |
} |
| 257 |
|
| 258 |
impl From<Method> for wkd::Variant { |
| 259 |
fn from(v: Method) -> wkd::Variant { |
| 260 |
match v { |
| 261 |
Method::Advanced => wkd::Variant::Advanced, |
| 262 |
Method::Direct => wkd::Variant::Direct, |
| 263 |
} |
| 264 |
} |
| 265 |
} |