From 02558b4dff1337e285f5ef86a8d012fafa3283c6 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 25 Jul 2020 14:16:31 -0400 Subject: [PATCH] unsafely disable TLS cert validation for now --- Cargo.toml | 2 +- majc/src/main.rs | 48 +++++++++++++++++++++++++----------------------- src/client.rs | 17 ++++++++++++++--- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 20ffb30..effbeed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ edition = "2018" num = "0.2" num-derive = "0.3" num-traits = "0.2" -rustls = { version = "0.18", optional = true } +rustls = { version = "0.18", optional = true, features = ["dangerous_configuration"] } webpki = { version = "0.21.0", optional = true } webpki-roots = { version = "0.20", optional = true } log = "0.4" diff --git a/majc/src/main.rs b/majc/src/main.rs index b8d96fa..eecabb4 100644 --- a/majc/src/main.rs +++ b/majc/src/main.rs @@ -1,7 +1,7 @@ use cursive::{ event::Key, menu::MenuTree, - theme::{BaseColor, Color, Effect, Style}, + theme::{Effect, Style}, traits::*, utils::markup::StyledString, views::{Dialog, EditView, Panel, ResizedView, TextView}, @@ -53,9 +53,11 @@ fn help(siv: &mut Cursive) { let content = include_str!("./help.gmi"); siv.add_layer( - Dialog::around(Panel::new(TextView::new(render_gemini(content)).scrollable())) - .title("Help") - .dismiss_button("Ok"), + Dialog::around(Panel::new( + TextView::new(render_gemini(content)).scrollable(), + )) + .title("Help") + .dismiss_button("Ok"), ); } @@ -99,22 +101,25 @@ fn show(siv: &mut Cursive, url: &str, resp: Response) { use StatusCode::*; match resp.status { - Success => { - match str::from_utf8(&resp.body) { - Ok(content) => { - siv.add_fullscreen_layer(ResizedView::with_full_screen( - Dialog::around(TextView::new(render_gemini(content)).scrollable()) - .title(format!("{}: {}", url, resp.meta)), - )); - } - Err(why) => { - siv.add_layer(Dialog::info(format!( - "UTF/8 decoding error for {}: {:?}", - url, why - ))); - } + Success => match str::from_utf8(&resp.body) { + Ok(content) => { + let content: StyledString = if resp.meta.starts_with("text/gemini") { + render_gemini(content) + } else { + StyledString::plain(content) + }; + siv.add_fullscreen_layer(ResizedView::with_full_screen( + Dialog::around(TextView::new(content).scrollable()) + .title(format!("{}: {}", url, resp.meta)), + )); } - } + Err(why) => { + siv.add_layer(Dialog::info(format!( + "UTF/8 decoding error for {}: {:?}", + url, why + ))); + } + }, TemporaryRedirect => { open(siv, resp.meta.as_str()); @@ -141,10 +146,7 @@ fn render_gemini(body: &str) -> StyledString { match node { Text(line) => styled.append(StyledString::plain(line)), Link { to, name } => match name { - None => styled.append(StyledString::styled( - to, - Style::from(Effect::Underline), - )), + None => styled.append(StyledString::styled(to, Style::from(Effect::Underline))), Some(name) => styled.append(StyledString::styled( format!("{}: {}", to, name), Style::from(Effect::Underline), diff --git a/src/client.rs b/src/client.rs index 0e173ae..107a764 100644 --- a/src/client.rs +++ b/src/client.rs @@ -5,10 +5,21 @@ use url::Url; fn config() -> ClientConfig { let mut config = ClientConfig::new(); + config.dangerous().set_certificate_verifier(Arc::new(NoCertificateVerification{})); + config - .root_store - .add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS); - config +} + +struct NoCertificateVerification {} + +impl rustls::ServerCertVerifier for NoCertificateVerification { + fn verify_server_cert(&self, + _roots: &rustls::RootCertStore, + _presented_certs: &[rustls::Certificate], + _dns_name: webpki::DNSNameRef<'_>, + _ocsp: &[u8]) -> Result { + Ok(rustls::ServerCertVerified::assertion()) + } } #[derive(thiserror::Error, Debug)]