mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
init profile TOFU features
This commit is contained in:
parent
5aa6b1464c
commit
f831212d40
11 changed files with 403 additions and 44 deletions
|
|
@ -11,7 +11,7 @@ use gtk::{
|
|||
glib::{Priority, Uri},
|
||||
prelude::{ButtonExt, FileExt, SocketClientExt},
|
||||
};
|
||||
use sourceview::prelude::InputStreamExtManual;
|
||||
use sourceview::prelude::{ActionExt, InputStreamExtManual, TlsConnectionExt};
|
||||
use std::{cell::Cell, path::MAIN_SEPARATOR, rc::Rc, time::Duration};
|
||||
|
||||
/// [Gemini protocol](https://geminiprotocol.net/docs/protocol-specification.gmi) client driver
|
||||
|
|
@ -150,6 +150,8 @@ fn handle(
|
|||
) {
|
||||
const EVENT_COMPLETED: &str = "Completed";
|
||||
let uri = request.uri().clone();
|
||||
let server_certificates = this.page.profile.tofu.server_certificates(&uri);
|
||||
let has_server_certificates = server_certificates.is_some();
|
||||
this.client.request_async(
|
||||
request,
|
||||
Priority::DEFAULT,
|
||||
|
|
@ -160,6 +162,7 @@ fn handle(
|
|||
.profile
|
||||
.identity
|
||||
.get(&uri.to_string()).map(|identity|identity.to_tls_certificate().unwrap()),
|
||||
server_certificates,
|
||||
{
|
||||
let page = this.page.clone();
|
||||
let redirects = this.redirects.clone();
|
||||
|
|
@ -186,6 +189,12 @@ fn handle(
|
|||
// * unwrap fails only on `connection.socket_connection.is_closed()`
|
||||
// drop the panic as unexpected here.
|
||||
}
|
||||
// Register new peer certificate if the TOFU index is empty
|
||||
if !has_server_certificates {
|
||||
page.profile.tofu.add(
|
||||
connection.tls_client_connection.peer_certificate().unwrap()
|
||||
).unwrap() // expect new record
|
||||
}
|
||||
// Handle response
|
||||
match response {
|
||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#input-expected
|
||||
|
|
@ -608,8 +617,38 @@ fn handle(
|
|||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let s = page.content.to_status_failure();
|
||||
s.set_description(Some(&e.to_string()));
|
||||
let s = match e {
|
||||
ggemini::client::Error::Request(connection, e) => match e {
|
||||
ggemini::client::connection::Error::Request(_, e) => {
|
||||
use gtk::gio::TlsError;
|
||||
if e.kind::<TlsError>().is_some_and(|e| matches!(e, TlsError::BadCertificate)) {
|
||||
page.content.to_status_tofu({
|
||||
let p = page.clone();
|
||||
move || {
|
||||
p.profile.tofu.add(
|
||||
connection.tls_client_connection.peer_certificate().unwrap()
|
||||
).unwrap(); // expect new record
|
||||
p.item_action.reload.activate(None)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
let s = page.content.to_status_failure();
|
||||
s.set_description(Some(&e.to_string()));
|
||||
s
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let s = page.content.to_status_failure();
|
||||
s.set_description(Some(&e.to_string()));
|
||||
s
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let s = page.content.to_status_failure();
|
||||
s.set_description(Some(&e.to_string()));
|
||||
s
|
||||
}
|
||||
};
|
||||
page.set_progress(0.0);
|
||||
page.set_title(&s.title());
|
||||
if is_snap_history {
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ impl Content {
|
|||
/// * action removes previous children component from `Self`
|
||||
pub fn to_image(&self, paintable: &impl IsA<Paintable>) -> Image {
|
||||
self.clean();
|
||||
let image = Image::new_from_paintable(paintable);
|
||||
self.g_box.append(&image.picture);
|
||||
image
|
||||
let i = Image::new_from_paintable(paintable);
|
||||
self.g_box.append(&i.picture);
|
||||
i
|
||||
}
|
||||
|
||||
/// Set new `content::Status` component for `Self` with new `status::Download` preset
|
||||
|
|
@ -66,9 +66,9 @@ impl Content {
|
|||
on_choose: impl Fn(File, Rc<status::download::Action>) + 'static,
|
||||
) -> StatusPage {
|
||||
self.clean();
|
||||
let status = status::download::build(initial_filename, cancellable, on_choose);
|
||||
self.g_box.append(&status);
|
||||
status
|
||||
let s = status::download::build(initial_filename, cancellable, on_choose);
|
||||
self.g_box.append(&s);
|
||||
s
|
||||
}
|
||||
|
||||
/// Set new `content::Status` component for `Self` with new `status::Failure` preset
|
||||
|
|
@ -76,9 +76,19 @@ impl Content {
|
|||
/// * action removes previous children component from `Self`
|
||||
pub fn to_status_failure(&self) -> StatusPage {
|
||||
self.clean();
|
||||
let status = status::failure::new();
|
||||
self.g_box.append(&status);
|
||||
status
|
||||
let s = status::failure::new();
|
||||
self.g_box.append(&s);
|
||||
s
|
||||
}
|
||||
|
||||
/// Set new `content::Status` component for `Self` with new `status::Tofu` preset
|
||||
///
|
||||
/// * action removes previous children component from `Self`
|
||||
pub fn to_status_tofu(&self, on_accept: impl Fn() + 'static) -> StatusPage {
|
||||
self.clean();
|
||||
let s = status::tofu::build(on_accept);
|
||||
self.g_box.append(&s);
|
||||
s
|
||||
}
|
||||
|
||||
/// Set new `content::Status` component for `Self` with new `status::Mime` issue preset
|
||||
|
|
@ -90,9 +100,9 @@ impl Content {
|
|||
download: Option<(&Rc<ItemAction>, &Uri)>,
|
||||
) -> StatusPage {
|
||||
self.clean();
|
||||
let status = status::mime::build(mime, download);
|
||||
self.g_box.append(&status);
|
||||
status
|
||||
let s = status::mime::build(mime, download);
|
||||
self.g_box.append(&s);
|
||||
s
|
||||
}
|
||||
|
||||
/// Set new `content::Status` component for `Self` with new `status::Identity` preset
|
||||
|
|
@ -100,9 +110,9 @@ impl Content {
|
|||
/// * action removes previous children component from `Self`
|
||||
pub fn to_status_identity(&self) -> StatusPage {
|
||||
self.clean();
|
||||
let status = status::identity::build((&self.tab_action, &self.item_action));
|
||||
self.g_box.append(&status);
|
||||
status
|
||||
let s = status::identity::build((&self.tab_action, &self.item_action));
|
||||
self.g_box.append(&s);
|
||||
s
|
||||
}
|
||||
|
||||
/// Set new `content::Status` component for `Self` with new `status::Loading` preset
|
||||
|
|
@ -110,9 +120,9 @@ impl Content {
|
|||
/// * action removes previous children component from `Self`
|
||||
pub fn to_status_loading(&self, show_with_delay: Option<Duration>) -> StatusPage {
|
||||
self.clean();
|
||||
let status = status::loading::build(show_with_delay);
|
||||
self.g_box.append(&status);
|
||||
status
|
||||
let s = status::loading::build(show_with_delay);
|
||||
self.g_box.append(&s);
|
||||
s
|
||||
}
|
||||
|
||||
/// `text/gemini`
|
||||
|
|
@ -147,17 +157,17 @@ impl Content {
|
|||
/// `text/plain`
|
||||
pub fn to_text_plain(&self, data: &str) -> Text {
|
||||
self.clean();
|
||||
let text = Text::plain(data);
|
||||
self.g_box.append(&text.scrolled_window);
|
||||
text
|
||||
let t = Text::plain(data);
|
||||
self.g_box.append(&t.scrolled_window);
|
||||
t
|
||||
}
|
||||
|
||||
/// [text/nex](https://nightfall.city/nex/info/specification.txt)
|
||||
pub fn to_text_nex(&self, base: &Uri, data: &str) -> Text {
|
||||
self.clean();
|
||||
let text = Text::nex((&self.window_action, &self.item_action), base, data);
|
||||
self.g_box.append(&text.scrolled_window);
|
||||
text
|
||||
let t = Text::nex((&self.window_action, &self.item_action), base, data);
|
||||
self.g_box.append(&t.scrolled_window);
|
||||
t
|
||||
}
|
||||
|
||||
pub fn to_directory(
|
||||
|
|
@ -172,9 +182,9 @@ impl Content {
|
|||
/// * system `source:`
|
||||
pub fn to_text_source(&self, data: &str) -> Text {
|
||||
self.clean();
|
||||
let text = Text::source(data);
|
||||
self.g_box.append(&text.scrolled_window);
|
||||
text
|
||||
let t = Text::source(data);
|
||||
self.g_box.append(&t.scrolled_window);
|
||||
t
|
||||
}
|
||||
|
||||
/// Remove all children components from `Self`
|
||||
|
|
|
|||
|
|
@ -3,5 +3,6 @@ pub mod failure;
|
|||
pub mod identity;
|
||||
pub mod loading;
|
||||
pub mod mime;
|
||||
pub mod tofu;
|
||||
|
||||
use super::{ItemAction, TabAction};
|
||||
|
|
|
|||
40
src/app/browser/window/tab/item/page/content/status/tofu.rs
Normal file
40
src/app/browser/window/tab/item/page/content/status/tofu.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use adw::StatusPage;
|
||||
use gtk::{
|
||||
Align, Button,
|
||||
prelude::{BoxExt, ButtonExt, WidgetExt},
|
||||
};
|
||||
|
||||
pub fn build(on_accept: impl Fn() + 'static) -> StatusPage {
|
||||
let b = gtk::Box::builder()
|
||||
.halign(Align::Center)
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.spacing(16)
|
||||
.build();
|
||||
|
||||
b.append(>k::Label::builder().selectable(true).use_markup(true).label(
|
||||
"<a href=\"https://geminiprotocol.net/docs/protocol-specification.gmi#tls-server-certificate-validation\" title=\"Gemini protocol specification (HTTP link)\">Read more...</a>"
|
||||
).build());
|
||||
|
||||
b.append(&{
|
||||
let b = Button::builder()
|
||||
.css_classes(["warning"])
|
||||
.label("Accept")
|
||||
.tooltip_text("Add an exception")
|
||||
.halign(Align::Center)
|
||||
.build();
|
||||
|
||||
b.connect_clicked(move |this| {
|
||||
this.set_sensitive(false);
|
||||
on_accept()
|
||||
});
|
||||
|
||||
b
|
||||
});
|
||||
|
||||
StatusPage::builder()
|
||||
.child(&b)
|
||||
.icon_name("security-medium-symbolic")
|
||||
.title("Server certificate has been changed")
|
||||
.description("it could be a man-in-the-middle attack")
|
||||
.build()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue