Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ All notable changes to Tarn are documented in this file. The format is based on

### Added

- Sites that ask for a client certificate offer the certificates they accept and send only the
one picked; Cancel sends none (macOS and Windows). Chromium tabs no longer send the first
certificate without asking.
- An actions page for each command bar row: → with the cursor at the end of the field (⌘K already
opens the bar), the row's … button, or on phones its More button lists what the row can do — a
tab: Switch, Close, Copy Link, Move to another space; a history page: Open, Open in New Tab, Copy
Expand Down
16 changes: 14 additions & 2 deletions crates/app/src/browser/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ impl Browser {
self.after_prompt(window, cx);
}

pub(crate) fn choose_certificate(&mut self, index: usize, window: &mut Window, cx: &mut Context<Self>) {
let Some(key) = self.model.active else { return };
if self.prompt_guarded() {
return;
}
let Some(prompt) = self.prompts.get_mut(&key).and_then(VecDeque::pop_front) else { return };
prompt.choose(index);
self.after_prompt(window, cx);
}

/// Esc declines the prompt in front, as Cancel or Deny does, without remembering the answer.
pub(crate) fn dismiss_prompt(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.remember_permission = false;
Expand Down Expand Up @@ -579,10 +589,12 @@ impl Browser {
}
}

/// A permission prompt's Allow and Remember, and Keep Anyway on a malware warning, ignore clicks for a
/// A permission prompt's Allow and Remember, Keep Anyway on a malware warning and a certificate choice ignore clicks for a
/// moment after they appear, so a page cannot time a click to land on them.
pub(crate) fn prompt_guarded(&self) -> bool {
self.active_prompt().is_some_and(|p| p.kind.is_permission() || matches!(p.kind, PromptKind::MaliciousDownload { .. })) && !self.layout_stable()
self.active_prompt()
.is_some_and(|p| p.kind.is_permission() || matches!(p.kind, PromptKind::MaliciousDownload { .. } | PromptKind::ClientCertificate { .. }))
&& !self.layout_stable()
}

pub(super) fn on_prompt_input_event(&mut self, input: &Entity<TextInput>, event: &TextInputEvent, window: &mut Window, cx: &mut Context<Self>) {
Expand Down
19 changes: 17 additions & 2 deletions crates/app/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ fn kind_name(kind: &PromptKind) -> &'static str {
PromptKind::Microphone => "microphone",
PromptKind::CameraAndMicrophone => "camera+microphone",
PromptKind::Credentials { .. } => "credentials",
PromptKind::ClientCertificate { .. } => "certificate",
PromptKind::ExtensionAccess { .. } => "extension",
PromptKind::MaliciousDownload { .. } => "malicious download",
}
Expand All @@ -416,6 +417,7 @@ fn prompt_card(b: &Browser, window: &Window, cx: &mut Context<Browser>) -> Optio
PromptKind::Credentials { realm } => {
(origin, format!("asks you to sign in{}", if realm.is_empty() { String::new() } else { format!(" ({})", ui::text::bounded_title(realm)) }))
}
PromptKind::ClientCertificate { .. } => (origin, "asks for a certificate to identify you".into()),
PromptKind::ExtensionAccess { extension, key } => (
format!("The extension \u{201C}{}\u{201D}", crate::extensions::shown(extension)),
format!("({}) wants to read and change {origin}", b.extension_badge(key)),
Expand Down Expand Up @@ -464,6 +466,7 @@ fn prompt_card(b: &Browser, window: &Window, cx: &mut Context<Browser>) -> Optio
PromptKind::MaliciousDownload { .. } => buttons
.child(secure_button("prompt-accept", "Keep Anyway", false).text_color(Secure::danger()).on_click(answer(false, true)))
.child(secure_button("prompt-decline", "Cancel Download", true).on_click(answer(false, false))),
PromptKind::ClientCertificate { .. } => buttons.child(silence()).child(secure_ghost_button("prompt-decline", "Cancel").on_click(answer(false, false))),
PromptKind::Credentials { .. } => buttons
.child(silence())
.child(secure_ghost_button("prompt-decline", "Cancel").on_click(answer(false, false)))
Expand All @@ -473,6 +476,10 @@ fn prompt_card(b: &Browser, window: &Window, cx: &mut Context<Browser>) -> Optio
.child(secure_ghost_button("prompt-decline", "Cancel").on_click(answer(false, false)))
.child(secure_button("prompt-accept", "OK", true).on_click(answer(false, true))),
};
let certificates = match &prompt.kind {
PromptKind::ClientCertificate { names } => Some(names.clone()),
_ => None,
};
let card = floating()
.px_3()
.py_2p5()
Expand All @@ -497,9 +504,17 @@ fn prompt_card(b: &Browser, window: &Window, cx: &mut Context<Browser>) -> Optio
)
.child(buttons),
)
.when(prompt.insecure, |d| d.child(div().text_color(Secure::warning()).child("This connection is not secure: the password would be sent unencrypted.")))
.when(prompt.insecure && matches!(prompt.kind, PromptKind::Credentials { .. }), |d| {
d.child(div().text_color(Secure::warning()).child("This connection is not secure: the password would be sent unencrypted."))
})
.when(matches!(prompt.kind, PromptKind::Text { .. }), |d| d.child(field(b.prompt_input.clone())))
.when(matches!(prompt.kind, PromptKind::Credentials { .. }), |d| d.child(field(b.auth_user.clone())).child(field(b.auth_pass.clone())));
.when(matches!(prompt.kind, PromptKind::Credentials { .. }), |d| d.child(field(b.auth_user.clone())).child(field(b.auth_pass.clone())))
.when_some(certificates, |d, names| {
d.children(names.iter().enumerate().map(|(i, name)| {
secure_button(("prompt-certificate", i), ui::text::bounded_title(name), false)
.on_click(cx.listener(move |b: &mut Browser, _, w, cx| b.choose_certificate(i, w, cx)))
}))
});
Some((title, card))
}

Expand Down
2 changes: 1 addition & 1 deletion crates/browser-core/src/glyphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub fn glyph(kind: &str) -> &'static str {
"microphone" => "mic",
"location" | "geolocation" => "map-pin",
"notifications" => "bell",
"credentials" => "key-round",
"credentials" | "certificate" => "key-round",
"extension" => "shield",
"alert" | "confirm" | "download" | "malicious download" => "triangle-alert",
"external" => "external-link",
Expand Down
3 changes: 3 additions & 0 deletions crates/browser-core/src/prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn meaning(kind: &str) -> Option<&'static str> {
"location" | "geolocation" => "The site sees where you are while this tab is open.",
"notifications" => "The site can show notifications while Tarn runs.",
"credentials" => "Your name and password go to this site only.",
"certificate" => "The certificate you pick goes to this site only and tells it who you are.",
"extension" => "The extension can read and change pages on this site.",
"malicious download" => "The file comes from a site on the malware list.",
"external" => "Tarn hands the link to the app that opens it.",
Expand Down Expand Up @@ -61,6 +62,7 @@ impl Prompt {
None => "asks you to sign in".to_owned(),
},
"camera+microphone" | "camera and microphone" => "wants to use your camera and microphone".to_owned(),
"certificate" => "asks for a certificate to identify you".to_owned(),
kind => format!("wants to use your {kind}"),
}
}
Expand Down Expand Up @@ -190,6 +192,7 @@ mod tests {
assert_eq!(ask("camera+microphone", None), "wants to use your camera and microphone");
assert_eq!(ask("credentials", Some("")), "asks you to sign in");
assert_eq!(ask("credentials", Some("Admin")), "asks you to sign in (Admin)");
assert_eq!(ask("certificate", None), "asks for a certificate to identify you");
assert!(ask("credentials", Some(&"r".repeat(5000))).len() < 600);
}
}
32 changes: 32 additions & 0 deletions crates/engine/src/chromium/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,18 @@ wrap_request_handler! {
1
}

// CEF's UI thread. Left unanswered, Chromium would send the first certificate unasked.
fn on_select_client_certificate(&self, _browser: Option<&mut Browser>, is_proxy: i32, host: Option<&CefString>, port: i32, certificates: Option<&[Option<X509Certificate>]>, callback: Option<&mut SelectClientCertificateCallback>) -> i32 {
let Some(callback) = callback else { return 1 };
let certificates: Vec<X509Certificate> = certificates.unwrap_or_default().iter().flatten().cloned().collect();
if is_proxy == 1 || certificates.is_empty() {
callback.select(None);
return 1;
}
ask_certificate(self.id, &string(host), port, certificates, callback.clone());
1
}

fn on_certificate_error(&self, _browser: Option<&mut Browser>, _cert_error: Errorcode, _request_url: Option<&CefString>, _ssl_info: Option<&mut Sslinfo>, callback: Option<&mut Callback>) -> i32 {
if let Some(callback) = callback {
callback.cancel();
Expand Down Expand Up @@ -1272,6 +1284,26 @@ fn ask_credentials(id: u64, origin_url: &str, realm: &str, callback: &AuthCallba
emit(&tab, Event::Prompt(crate::Prompt::answered(origin, None, insecure, String::new(), kind, reply, tab.silenced.clone())));
}

/// As for credentials, only the page's own origin, or the one its main frame is navigating to,
/// may ask; any other request, and Cancel, go on without a certificate.
fn ask_certificate(id: u64, host: &str, port: i32, certificates: Vec<X509Certificate>, callback: SelectClientCertificateCallback) {
let challenge = crate::view_policy::tls_challenge(host, port);
let origin = challenge.as_ref().and_then(crate::page::serialized_origin);
let (Some(tab), Some(challenge), Some(origin)) = (tab(id), challenge, origin) else { return callback.select(None) };
let (page, navigating) = (page_url(tab.browser.borrow().as_ref()), tab.navigating.borrow().as_deref().and_then(|o| Url::parse(o).ok()));
let own = [page, navigating].iter().any(|p| crate::view_policy::may_ask_credentials(&challenge, p.as_ref(), 0));
if !own || tab.silenced.get() || !crate::page::within_burst(&tab.recent_prompts, crate::page::PROMPT_BURST) {
return callback.select(None);
}
let names = certificates.iter().map(|c| c.subject().map(|s| CefString::from(&s.display_name()).to_string()).unwrap_or_default()).collect();
let reply = Box::new(move |answer: Option<(String, Option<(String, String)>)>| {
let mut chosen = answer.and_then(|(index, _)| index.parse::<usize>().ok()).and_then(|i| certificates.get(i).cloned());
callback.select(chosen.as_mut());
});
let kind = crate::PromptKind::ClientCertificate { names };
emit(&tab, Event::Prompt(crate::Prompt::answered(origin, None, false, String::new(), kind, reply, tab.silenced.clone())));
}

/// Drops a step into the restored list that did not navigate, and the marks it set for its load.
#[cfg(windows)]
fn abandon_step(tab: &Tab) {
Expand Down
Loading
Loading