| 1 |
use clap::Parser; |
| 2 |
|
| 3 |
use crate::cli::config; |
| 4 |
use crate::cli::examples::Action; |
| 5 |
use crate::cli::examples::Actions; |
| 6 |
|
| 7 |
use crate::cli::types::ClapData; |
| 8 |
use crate::cli::types::FileOrCertStore; |
| 9 |
use crate::cli::types::FileOrStdout; |
| 10 |
use super::keyserver::DEFAULT_KEYSERVERS; |
| 11 |
|
| 12 |
#[derive(Parser, Debug)] |
| 13 |
#[clap( |
| 14 |
name = "search", |
| 15 |
about = "Retrieve certificates using all supported network services", |
| 16 |
long_about = |
| 17 |
"Retrieve certificates using all supported network services |
| 18 |
|
| 19 |
This command will try to locate relevant certificates given a query, \ |
| 20 |
which may be a fingerprint, a key ID, an email address, or a https \ |
| 21 |
URL. It may also discover and import certificate related to the one \ |
| 22 |
queried, such as alternative certs, expired certs, or revoked certs. |
| 23 |
|
| 24 |
Discovering related certs is useful: alternative certs support key \ |
| 25 |
rotations, expired certs allow verification of signatures made in the \ |
| 26 |
past, and discovering revoked certs is important to get the revocation \ |
| 27 |
information. The PKI mechanism will help to select the correct cert, \ |
| 28 |
see `sq pki`. |
| 29 |
|
| 30 |
By default, any returned certificates are stored in the local \ |
| 31 |
certificate store. This can be overridden by using `--output` \ |
| 32 |
option. |
| 33 |
|
| 34 |
When a certificate is retrieved from a verifying key server (currently, \ |
| 35 |
this is limited to a list of known servers: `hkps://keys.openpgp.org`, \ |
| 36 |
`hkps://keys.mailvelope.com`, and `hkps://mail-api.proton.me`), \ |
| 37 |
WKD, DANE, or via https, and \ |
| 38 |
imported into the local certificate store, the User IDs are also \ |
| 39 |
certificated with a local server-specific key. That proxy certificate \ |
| 40 |
is in turn certified as a minimally trusted CA (trust amount: 1 of \ |
| 41 |
120) by the local trust root. How much a proxy key server CA is \ |
| 42 |
trusted can be tuned using `sq pki link add` or `sq pki link retract` in \ |
| 43 |
the usual way. |
| 44 |
", |
| 45 |
arg_required_else_help = true, |
| 46 |
after_help = EXAMPLES, |
| 47 |
)] |
| 48 |
pub struct Command { |
| 49 |
#[clap( |
| 50 |
long = "iterations", |
| 51 |
value_name = "N", |
| 52 |
default_value_t = 3, |
| 53 |
help = "Iterate to find related updates and certs", |
| 54 |
long_help = config::augment_help( |
| 55 |
"network.search.iterations", |
| 56 |
"Iterate to find related updates and certs"), |
| 57 |
)] |
| 58 |
pub iterations: u8, |
| 59 |
|
| 60 |
/// Workaround for https://github.com/clap-rs/clap/issues/3846 |
| 61 |
#[clap(skip)] |
| 62 |
pub iterations_source: Option<clap::parser::ValueSource>, |
| 63 |
|
| 64 |
#[clap( |
| 65 |
long = "server", |
| 66 |
default_values_t = DEFAULT_KEYSERVERS.iter().map(ToString::to_string), |
| 67 |
value_name = "URI", |
| 68 |
help = "Set a key server to use (can be given multiple times)", |
| 69 |
long_help = config::augment_help( |
| 70 |
"network.keyserver.servers", |
| 71 |
"Set a key server to use (can be given multiple times)"), |
| 72 |
)] |
| 73 |
pub servers: Vec<String>, |
| 74 |
|
| 75 |
/// Workaround for https://github.com/clap-rs/clap/issues/3846 |
| 76 |
#[clap(skip)] |
| 77 |
pub servers_source: Option<clap::parser::ValueSource>, |
| 78 |
|
| 79 |
#[clap( |
| 80 |
long = "use-wkd", |
| 81 |
value_name = "ENABLE", |
| 82 |
default_value = "true", |
| 83 |
help = "Use WKD to search for certs", |
| 84 |
long_help = config::augment_help( |
| 85 |
"network.search.use-wkd", |
| 86 |
"Use WKD to search for certs"), |
| 87 |
)] |
| 88 |
pub use_wkd: Option<bool>, |
| 89 |
|
| 90 |
/// Workaround for https://github.com/clap-rs/clap/issues/3846 |
| 91 |
#[clap(skip)] |
| 92 |
pub use_wkd_source: Option<clap::parser::ValueSource>, |
| 93 |
|
| 94 |
#[clap( |
| 95 |
long = "use-dane", |
| 96 |
value_name = "ENABLE", |
| 97 |
default_value = "true", |
| 98 |
help = "Use DANE to search for certs", |
| 99 |
long_help = config::augment_help( |
| 100 |
"network.search.use-dane", |
| 101 |
"Use DANE to search for certs"), |
| 102 |
)] |
| 103 |
pub use_dane: Option<bool>, |
| 104 |
|
| 105 |
/// Workaround for https://github.com/clap-rs/clap/issues/3846 |
| 106 |
#[clap(skip)] |
| 107 |
pub use_dane_source: Option<clap::parser::ValueSource>, |
| 108 |
|
| 109 |
#[clap( |
| 110 |
help = FileOrCertStore::HELP_OPTIONAL, |
| 111 |
long, |
| 112 |
value_name = FileOrCertStore::VALUE_NAME, |
| 113 |
)] |
| 114 |
pub output: Option<FileOrStdout>, |
| 115 |
|
| 116 |
#[clap( |
| 117 |
long, |
| 118 |
conflicts_with = "query", |
| 119 |
help = "Fetch updates for all known certificates", |
| 120 |
)] |
| 121 |
pub all: bool, |
| 122 |
|
| 123 |
#[clap( |
| 124 |
value_name = "QUERY", |
| 125 |
required = true, |
| 126 |
help = "Retrieve certificate(s) using QUERY", |
| 127 |
long_help = "Retrieve certificate(s) using QUERY |
| 128 |
|
| 129 |
This may be a fingerprint, a KeyID, \ |
| 130 |
an email address, or a https URL.", |
| 131 |
)] |
| 132 |
pub query: Vec<String>, |
| 133 |
} |
| 134 |
|
| 135 |
const EXAMPLES: Actions = Actions { |
| 136 |
actions: &[ |
| 137 |
Action::example().comment( |
| 138 |
"Search for the Qubes master signing certificate.", |
| 139 |
).command(&[ |
| 140 |
"sq", "network", "search", |
| 141 |
"427F11FD0FAA4B080123F01CDDFA1A3E36879494", |
| 142 |
]).syntax_check(), |
| 143 |
|
| 144 |
Action::example().comment( |
| 145 |
"Search for certificates that have are associated \ |
| 146 |
with an email address.", |
| 147 |
).command(&[ |
| 148 |
"sq", "network", "search", "[email protected]", |
| 149 |
]).syntax_check(), |
| 150 |
], |
| 151 |
}; |
| 152 |
test_examples!(sq_network_search, EXAMPLES); |