| 1 |
//! Dispatches and implements `sq config inspect`. |
| 2 |
|
| 3 |
use std::path::{Path, PathBuf}; |
| 4 |
|
| 5 |
use anyhow::Result; |
| 6 |
use clap::parser::ValueSource; |
| 7 |
|
| 8 |
use crate::{ |
| 9 |
Sq, |
| 10 |
cli::config::inspect, |
| 11 |
cli::network, |
| 12 |
config::ConfigFile, |
| 13 |
}; |
| 14 |
|
| 15 |
pub mod policy; |
| 16 |
|
| 17 |
pub fn dispatch(sq: Sq, cmd: inspect::Command) |
| 18 |
-> Result<()> |
| 19 |
{ |
| 20 |
match cmd.subcommand { |
| 21 |
inspect::Subcommands::Network(c) => network(sq, c), |
| 22 |
inspect::Subcommands::Paths(c) => paths(sq, c), |
| 23 |
inspect::Subcommands::Policy(c) => policy::dispatch(sq, c), |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
/// Implements `sq config inspect network`. |
| 28 |
fn network(sq: Sq, _: inspect::network::Command) -> Result<()> { |
| 29 |
fn may_use(what: &str, enabled: bool) -> String { |
| 30 |
format!("will {}use {}", |
| 31 |
if enabled { "" } else { "not " }, |
| 32 |
what) |
| 33 |
} |
| 34 |
|
| 35 |
let o = &mut std::io::stdout(); |
| 36 |
|
| 37 |
// First, sq network search, the most general interface. |
| 38 |
let use_wkd = sq.config.network_search_use_wkd( |
| 39 |
Some(true), Some(ValueSource::DefaultValue)); |
| 40 |
wwriteln!(stream=o, initial_indent = " - ", "sq network search"); |
| 41 |
wwriteln!(stream=o, initial_indent = " - ", "{}", |
| 42 |
may_use("WKD", use_wkd)); |
| 43 |
wwriteln!(stream=o, initial_indent = " - ", |
| 44 |
"relevant setting: network.search.use-wkd"); |
| 45 |
if use_wkd { |
| 46 |
wwriteln!(stream=o, initial_indent = " - ", "see below for impact"); |
| 47 |
} |
| 48 |
|
| 49 |
let use_dane = sq.config.network_search_use_dane( |
| 50 |
Some(true), Some(ValueSource::DefaultValue)); |
| 51 |
wwriteln!(stream=o, initial_indent = " - ", "{}", |
| 52 |
may_use("DANE", use_dane)); |
| 53 |
wwriteln!(stream=o, initial_indent = " - ", |
| 54 |
"relevant setting: network.search.use-dane"); |
| 55 |
if use_dane { |
| 56 |
wwriteln!(stream=o, initial_indent = " - ", "see below for impact"); |
| 57 |
} |
| 58 |
|
| 59 |
let key_servers = sq.config.key_servers( |
| 60 |
&network::keyserver::DEFAULT_KEYSERVERS, |
| 61 |
Some(clap::parser::ValueSource::DefaultValue)) |
| 62 |
.collect::<Vec<_>>(); |
| 63 |
|
| 64 |
if key_servers.is_empty() { |
| 65 |
wwriteln!(stream=o, initial_indent = " - ", |
| 66 |
"will use no key servers by default"); |
| 67 |
} else { |
| 68 |
wwriteln!(stream=o, initial_indent = " - ", |
| 69 |
"will use the following key servers"); |
| 70 |
for s in &key_servers { |
| 71 |
wwriteln!(stream=o, initial_indent = " - ", "{}", s); |
| 72 |
} |
| 73 |
} |
| 74 |
wwriteln!(stream=o, initial_indent = " - ", |
| 75 |
"relevant setting: network.keyservers"); |
| 76 |
if ! key_servers.is_empty() { |
| 77 |
wwriteln!(stream=o, initial_indent = " - ", "see below for impact"); |
| 78 |
} |
| 79 |
|
| 80 |
let iterations = sq.config.network_search_iterations( |
| 81 |
3, Some(ValueSource::DefaultValue)); |
| 82 |
if iterations == 0 { |
| 83 |
wwriteln!(stream=o, initial_indent = " - ", |
| 84 |
"will not search iteratively from \ |
| 85 |
your original query to discover related \ |
| 86 |
certificates"); |
| 87 |
} else { |
| 88 |
wwriteln!(stream=o, initial_indent = " - ", |
| 89 |
"will iteratively search up to {} steps from \ |
| 90 |
your original query to discover related \ |
| 91 |
certificates", |
| 92 |
iterations.saturating_sub(1)); |
| 93 |
wwriteln!(stream=o, initial_indent = " - ", |
| 94 |
"this will query certificates that you did not \ |
| 95 |
request, hopefully finding relevant related \ |
| 96 |
certificates, but increases the metadata \ |
| 97 |
leakage and may query \"suspicious\" \ |
| 98 |
certificates"); |
| 99 |
} |
| 100 |
wwriteln!(stream=o, initial_indent = " - ", |
| 101 |
"relevant setting: network.search.iterations"); |
| 102 |
|
| 103 |
// Then, sq network keyserver search. |
| 104 |
wwriteln!(stream=o); |
| 105 |
wwriteln!(stream=o, initial_indent = " - ", "sq network keyserver search"); |
| 106 |
if key_servers.is_empty() { |
| 107 |
wwriteln!(stream=o, initial_indent = " - ", |
| 108 |
"will use no key servers by default"); |
| 109 |
} else { |
| 110 |
wwriteln!(stream=o, initial_indent = " - ", |
| 111 |
"will use the following key servers"); |
| 112 |
for s in &key_servers { |
| 113 |
wwriteln!(stream=o, initial_indent = " - ", "{}", s); |
| 114 |
} |
| 115 |
} |
| 116 |
wwriteln!(stream=o, initial_indent = " - ", |
| 117 |
"relevant setting: network.keyservers"); |
| 118 |
wwriteln!(stream=o, initial_indent = " - ", "impact:"); |
| 119 |
wwriteln!(stream=o, initial_indent = " - ", |
| 120 |
"key servers and their operators can see all requests, \ |
| 121 |
and learn about your contacts, and track you"); |
| 122 |
wwriteln!(stream=o, initial_indent = " - ", |
| 123 |
"although the traffic is encrypted, network observers \ |
| 124 |
can use traffic analysis and observe the size of requests \ |
| 125 |
and responses, and infer information about you and \ |
| 126 |
your contacts, and track you"); |
| 127 |
|
| 128 |
// Then, sq network wkd search. |
| 129 |
wwriteln!(stream=o); |
| 130 |
wwriteln!(stream=o, initial_indent = " - ", "sq network wkd search"); |
| 131 |
wwriteln!(stream=o, initial_indent = " - ", "impact:"); |
| 132 |
wwriteln!(stream=o, initial_indent = " - ", |
| 133 |
"WKD servers and their operators can see all requests, \ |
| 134 |
and learn about your contacts, and track you"); |
| 135 |
wwriteln!(stream=o, initial_indent = " - ", |
| 136 |
"although the traffic is encrypted, network observers \ |
| 137 |
can use traffic analysis, and observe the size of requests \ |
| 138 |
and responses, and infer information about you and \ |
| 139 |
your contacts, and possibly track you"); |
| 140 |
|
| 141 |
// Then, sq network dane search. |
| 142 |
wwriteln!(stream=o); |
| 143 |
wwriteln!(stream=o, initial_indent = " - ", "sq network dane search"); |
| 144 |
wwriteln!(stream=o, initial_indent = " - ", "impact:"); |
| 145 |
wwriteln!(stream=o, initial_indent = " - ", |
| 146 |
"DNS servers and their operators can see all requests, \ |
| 147 |
and learn about your contacts, and track you"); |
| 148 |
wwriteln!(stream=o, initial_indent = " - ", |
| 149 |
"the traffic is not encrypted, network observers \ |
| 150 |
can see all requests, and learn about your contacts, \ |
| 151 |
and track you"); |
| 152 |
Ok(()) |
| 153 |
} |
| 154 |
|
| 155 |
/// Implements `sq config inspect paths`. |
| 156 |
fn paths(sq: Sq, _: inspect::paths::Command) -> Result<()> { |
| 157 |
let o = &mut std::io::stdout(); |
| 158 |
|
| 159 |
// Whether we have emitted anything. |
| 160 |
let mut dirty = false; |
| 161 |
|
| 162 |
// Formats a path. |
| 163 |
let mut p = |path: &Path, name: &str, description: &str| -> Result<()> { |
| 164 |
if dirty { |
| 165 |
wwriteln!(o); |
| 166 |
} |
| 167 |
dirty = true; |
| 168 |
|
| 169 |
wwriteln!(stream=o, initial_indent = " - ", "{}", name); |
| 170 |
wwriteln!(stream=o, initial_indent = " - ", "{}", path.display()); |
| 171 |
|
| 172 |
if ! path.exists() { |
| 173 |
wwriteln!(stream=o, initial_indent = " - ", "does not exist"); |
| 174 |
} |
| 175 |
|
| 176 |
wwriteln!(stream=o, initial_indent = " - ", "{}", description); |
| 177 |
|
| 178 |
Ok(()) |
| 179 |
}; |
| 180 |
|
| 181 |
if let Some(home) = &sq.home { |
| 182 |
p(home.location(), "home directory", |
| 183 |
"This holds the configuration file, and, unless overridden, \ |
| 184 |
the certificate store and key store.", |
| 185 |
)?; |
| 186 |
|
| 187 |
p(&ConfigFile::file_name(&home), "config file", |
| 188 |
"sq's configuration file.", |
| 189 |
)?; |
| 190 |
} |
| 191 |
|
| 192 |
p(&PathBuf::from(ConfigFile::global_crypto_policy_file()), |
| 193 |
"global cryptographic policy", |
| 194 |
"This is the global cryptographic policy file. If it exists, it \ |
| 195 |
is read before reading in the policy in sq's configuration file, \ |
| 196 |
which will refine the global one.", |
| 197 |
)?; |
| 198 |
|
| 199 |
if let Some(policy_path) = sq.config.policy_path() { |
| 200 |
p(policy_path, |
| 201 |
"referenced cryptographic policy", |
| 202 |
"This is the cryptographic policy file referenced in sq's \ |
| 203 |
configuration file. It is read after the global policy, \ |
| 204 |
and before the policy embedded in sq's configuration file, \ |
| 205 |
which will refine the global and referenced one.", |
| 206 |
)?; |
| 207 |
} |
| 208 |
|
| 209 |
if let Some(cert_store) = sq.cert_store_base() { |
| 210 |
p(&cert_store, "certificate store", |
| 211 |
"This holds all the certificates, indices for faster lookup, \ |
| 212 |
and some additional certificates like the trust root.", |
| 213 |
)?; |
| 214 |
} |
| 215 |
|
| 216 |
if let Ok(Some(key_store)) = sq.key_store_path() { |
| 217 |
p(&key_store, "key store", |
| 218 |
"This holds all the keys, either directly for those in the \ |
| 219 |
`softkeys` backend, or indirectly, using some configuration \ |
| 220 |
and metadata.", |
| 221 |
)?; |
| 222 |
} |
| 223 |
|
| 224 |
Ok(()) |
| 225 |
} |