unsafely disable TLS cert validation for now
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Cadey Ratio 2020-07-25 14:16:31 -04:00
parent d96a7a85bf
commit 02558b4dff
3 changed files with 40 additions and 27 deletions

View File

@ -10,7 +10,7 @@ edition = "2018"
num = "0.2" num = "0.2"
num-derive = "0.3" num-derive = "0.3"
num-traits = "0.2" 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 = { version = "0.21.0", optional = true }
webpki-roots = { version = "0.20", optional = true } webpki-roots = { version = "0.20", optional = true }
log = "0.4" log = "0.4"

View File

@ -1,7 +1,7 @@
use cursive::{ use cursive::{
event::Key, event::Key,
menu::MenuTree, menu::MenuTree,
theme::{BaseColor, Color, Effect, Style}, theme::{Effect, Style},
traits::*, traits::*,
utils::markup::StyledString, utils::markup::StyledString,
views::{Dialog, EditView, Panel, ResizedView, TextView}, views::{Dialog, EditView, Panel, ResizedView, TextView},
@ -53,9 +53,11 @@ fn help(siv: &mut Cursive) {
let content = include_str!("./help.gmi"); let content = include_str!("./help.gmi");
siv.add_layer( siv.add_layer(
Dialog::around(Panel::new(TextView::new(render_gemini(content)).scrollable())) Dialog::around(Panel::new(
.title("Help") TextView::new(render_gemini(content)).scrollable(),
.dismiss_button("Ok"), ))
.title("Help")
.dismiss_button("Ok"),
); );
} }
@ -99,22 +101,25 @@ fn show(siv: &mut Cursive, url: &str, resp: Response) {
use StatusCode::*; use StatusCode::*;
match resp.status { match resp.status {
Success => { Success => match str::from_utf8(&resp.body) {
match str::from_utf8(&resp.body) { Ok(content) => {
Ok(content) => { let content: StyledString = if resp.meta.starts_with("text/gemini") {
siv.add_fullscreen_layer(ResizedView::with_full_screen( render_gemini(content)
Dialog::around(TextView::new(render_gemini(content)).scrollable()) } else {
.title(format!("{}: {}", url, resp.meta)), StyledString::plain(content)
)); };
} siv.add_fullscreen_layer(ResizedView::with_full_screen(
Err(why) => { Dialog::around(TextView::new(content).scrollable())
siv.add_layer(Dialog::info(format!( .title(format!("{}: {}", url, resp.meta)),
"UTF/8 decoding error for {}: {:?}", ));
url, why
)));
}
} }
} Err(why) => {
siv.add_layer(Dialog::info(format!(
"UTF/8 decoding error for {}: {:?}",
url, why
)));
}
},
TemporaryRedirect => { TemporaryRedirect => {
open(siv, resp.meta.as_str()); open(siv, resp.meta.as_str());
@ -141,10 +146,7 @@ fn render_gemini(body: &str) -> StyledString {
match node { match node {
Text(line) => styled.append(StyledString::plain(line)), Text(line) => styled.append(StyledString::plain(line)),
Link { to, name } => match name { Link { to, name } => match name {
None => styled.append(StyledString::styled( None => styled.append(StyledString::styled(to, Style::from(Effect::Underline))),
to,
Style::from(Effect::Underline),
)),
Some(name) => styled.append(StyledString::styled( Some(name) => styled.append(StyledString::styled(
format!("{}: {}", to, name), format!("{}: {}", to, name),
Style::from(Effect::Underline), Style::from(Effect::Underline),

View File

@ -5,10 +5,21 @@ use url::Url;
fn config() -> ClientConfig { fn config() -> ClientConfig {
let mut config = ClientConfig::new(); let mut config = ClientConfig::new();
config.dangerous().set_certificate_verifier(Arc::new(NoCertificateVerification{}));
config 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<rustls::ServerCertVerified, rustls::TLSError> {
Ok(rustls::ServerCertVerified::assertion())
}
} }
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]