| 1 |
use std::time::Duration; |
| 2 |
|
| 3 |
use clap::{Args, Parser, Subcommand}; |
| 4 |
|
| 5 |
use crate::cli::types::ClapData; |
| 6 |
use crate::cli::types::FileOrCertStore; |
| 7 |
use crate::cli::types::FileOrStdout; |
| 8 |
use crate::cli::types::cert_designator::{ |
| 9 |
CertDesignators, |
| 10 |
CertUserIDEmailFileArgs, |
| 11 |
CertOrAll, |
| 12 |
CertPrefix, |
| 13 |
}; |
| 14 |
|
| 15 |
use crate::cli::examples::*; |
| 16 |
|
| 17 |
#[derive(Parser, Debug)] |
| 18 |
#[clap( |
| 19 |
name = "dane", |
| 20 |
about = "Retrieve and publishes certificates via DANE", |
| 21 |
long_about = |
| 22 |
"Retrieve and publishes certificates via DANE |
| 23 |
|
| 24 |
DNS-Based Authentication of Named Entities (DANE) is a method for \ |
| 25 |
publishing and retrieving certificates in DNS as specified in RFC \ |
| 26 |
7929. |
| 27 |
", |
| 28 |
|
| 29 |
subcommand_required = true, |
| 30 |
arg_required_else_help = true, |
| 31 |
disable_help_subcommand = true, |
| 32 |
)] |
| 33 |
pub struct Command { |
| 34 |
#[clap(subcommand)] |
| 35 |
pub subcommand: Subcommands, |
| 36 |
} |
| 37 |
|
| 38 |
#[derive(Debug, Subcommand)] |
| 39 |
pub enum Subcommands { |
| 40 |
Search(SearchCommand), |
| 41 |
Generate(GenerateCommand), |
| 42 |
} |
| 43 |
|
| 44 |
const GENERATE_EXAMPLES: Actions = Actions { |
| 45 |
actions: &[ |
| 46 |
Action::setup().command(&[ |
| 47 |
"sq", "cert", "import", "juliet.pgp", |
| 48 |
]).build(), |
| 49 |
|
| 50 |
Action::setup().command(&[ |
| 51 |
"sq", "pki", "link", "add", |
| 52 |
"--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 53 |
"--userid=Alice <[email protected]>", |
| 54 |
]).build(), |
| 55 |
|
| 56 |
Action::example().comment( |
| 57 |
"Generate DANE records from juliet.pgp for example.org.", |
| 58 |
).command(&[ |
| 59 |
"sq", "network", "dane", "generate", |
| 60 |
"--domain=example.org", |
| 61 |
"--cert-file=juliet.pgp", |
| 62 |
]).build(), |
| 63 |
|
| 64 |
Action::example().comment( |
| 65 |
"Generate DANE records for all certs with an authenticated \ |
| 66 |
user ID in example.org.", |
| 67 |
).command(&[ |
| 68 |
"sq", "network", "dane", "generate", |
| 69 |
"--domain=example.org", |
| 70 |
"--all", |
| 71 |
]).build(), |
| 72 |
], |
| 73 |
}; |
| 74 |
test_examples!(sq_network_dane_generate, GENERATE_EXAMPLES); |
| 75 |
|
| 76 |
#[derive(Debug, Args)] |
| 77 |
#[clap( |
| 78 |
about = "Generate DANE records for the given domain and certs", |
| 79 |
long_about = |
| 80 |
"Generate DANE records for the given domain and certs |
| 81 |
|
| 82 |
The certificates are minimized, and one record per email address is \ |
| 83 |
emitted. If multiple user IDs map to one email address, then all \ |
| 84 |
matching user IDs are included in the emitted certificates. |
| 85 |
|
| 86 |
By default, OPENPGPKEY resource records are emitted. If your DNS \ |
| 87 |
server doesn't understand those, use `--type generic` to emit generic \ |
| 88 |
records instead. |
| 89 |
", |
| 90 |
after_help = GENERATE_EXAMPLES, |
| 91 |
)] |
| 92 |
pub struct GenerateCommand { |
| 93 |
#[command(flatten)] |
| 94 |
pub certs: CertDesignators<CertUserIDEmailFileArgs, |
| 95 |
CertPrefix, |
| 96 |
CertOrAll>, |
| 97 |
|
| 98 |
#[clap( |
| 99 |
long = "all", |
| 100 |
help = "Publish authenticated certs with a user ID matching domain", |
| 101 |
long_help = "\ |
| 102 |
Publish authenticated certs with a user ID matching domain |
| 103 |
|
| 104 |
Use all certificates that have a user ID matching the domain given \ |
| 105 |
to the `--domain` parameter that can be fully authenticated.", |
| 106 |
)] |
| 107 |
pub all: bool, |
| 108 |
|
| 109 |
#[clap( |
| 110 |
long = "domain", |
| 111 |
value_name = "FQDN", |
| 112 |
help = "Generate DANE records for this domain name", |
| 113 |
)] |
| 114 |
pub domain: String, |
| 115 |
|
| 116 |
#[clap( |
| 117 |
long = "ttl", |
| 118 |
value_name = "DURATION", |
| 119 |
value_parser = |arg: &str| -> Result<Duration, std::num::ParseIntError> |
| 120 |
{ Ok(Duration::from_secs(arg.parse()?)) }, |
| 121 |
default_value = "10800", |
| 122 |
help = "Set the TTL (maximum cache duration) of the resource records", |
| 123 |
)] |
| 124 |
pub ttl: Duration, |
| 125 |
#[clap( |
| 126 |
long = "size-limit", |
| 127 |
value_name = "BYTES", |
| 128 |
default_value = "12288", |
| 129 |
help = "Try to shrink the certificates to this size", |
| 130 |
)] |
| 131 |
pub size_limit: usize, |
| 132 |
|
| 133 |
#[clap( |
| 134 |
long = "type", |
| 135 |
value_name = "TYPE", |
| 136 |
default_value = "openpgp", |
| 137 |
help = "Change the emitted resource record type", |
| 138 |
)] |
| 139 |
pub typ: ResourceRecordType, |
| 140 |
} |
| 141 |
|
| 142 |
#[derive(clap::ValueEnum, Clone, Copy, Debug, Default, PartialEq, Eq)] |
| 143 |
pub enum ResourceRecordType { |
| 144 |
#[default] |
| 145 |
#[clap(name = "openpgp")] |
| 146 |
OpenPGP, |
| 147 |
Generic, |
| 148 |
} |
| 149 |
|
| 150 |
#[derive(Debug, Args)] |
| 151 |
#[clap( |
| 152 |
about = "Retrieve certificates using DANE", |
| 153 |
long_about = |
| 154 |
"Retrieve certificates using DANE |
| 155 |
|
| 156 |
By default, any returned certificates are stored in the local \ |
| 157 |
certificate store. This can be overridden by using `--output` \ |
| 158 |
option. |
| 159 |
|
| 160 |
When a certificate is retrieved using DANE, and imported into the \ |
| 161 |
local certificate store, any User IDs with the email address that was \ |
| 162 |
looked up are certificated with a local DANE-specific key. That proxy \ |
| 163 |
certificate is in turn certified as a minimally trusted CA (trust \ |
| 164 |
amount: 1 of 120) by the local trust root. How much the DANE proxy CA \ |
| 165 |
is trusted can be tuned using `sq pki link add` or `sq pki link retract` \ |
| 166 |
in the usual way. |
| 167 |
", |
| 168 |
after_help = SEARCH_EXAMPLES, |
| 169 |
)] |
| 170 |
pub struct SearchCommand { |
| 171 |
#[clap( |
| 172 |
long, |
| 173 |
conflicts_with = "addresses", |
| 174 |
help = "Fetch updates for all known certificates", |
| 175 |
)] |
| 176 |
pub all: bool, |
| 177 |
|
| 178 |
#[clap( |
| 179 |
value_name = "ADDRESS", |
| 180 |
required = true, |
| 181 |
help = "Retrieve certificate(s) for ADDRESS", |
| 182 |
)] |
| 183 |
pub addresses: Vec<String>, |
| 184 |
|
| 185 |
#[clap( |
| 186 |
help = FileOrCertStore::HELP_OPTIONAL, |
| 187 |
long, |
| 188 |
value_name = FileOrCertStore::VALUE_NAME, |
| 189 |
)] |
| 190 |
pub output: Option<FileOrStdout>, |
| 191 |
} |
| 192 |
|
| 193 |
const SEARCH_EXAMPLES: Actions = Actions { |
| 194 |
actions: &[ |
| 195 |
Action::example().comment( |
| 196 |
"Retrieve Alice's certificate over DANE." |
| 197 |
).command(&[ |
| 198 |
"sq", "network", "dane", "search", "[email protected]", |
| 199 |
]).syntax_check(), |
| 200 |
|
| 201 |
Action::example().comment( |
| 202 |
"Retrieve updates for all known certificates over DANE." |
| 203 |
).command(&[ |
| 204 |
"sq", "network", "dane", "search", "--all", |
| 205 |
]).syntax_check(), |
| 206 |
], |
| 207 |
}; |
| 208 |
test_examples!(sq_network_dane_search, SEARCH_EXAMPLES); |