From 492d089d5c641b70b899f9570b89de7a1a603c2b Mon Sep 17 00:00:00 2001 From: nworbnhoj Date: Wed, 29 Nov 2023 12:03:15 +1100 Subject: [PATCH 1/4] fix typos --- libs/tls/README.md | 6 +++--- libs/tls/locales/i18n.json | 4 ++-- libs/tls/src/lib.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/tls/README.md b/libs/tls/README.md index a0dda3812..634657a09 100644 --- a/libs/tls/README.md +++ b/libs/tls/README.md @@ -15,8 +15,8 @@ Note that hosts with self-signed Certificates may be probed and trusted (e.g. [c A small set of shellchat commands are included to enact the base functionality: - `net tls probe ` will initiate a modified tls handshake with ``, obtain the certificate chain offered by ``, and immediately terminate the connection. A call to Tls::check_trust() will present the CA certificate chain in a modal to be individually selected and saved to PDDB if trusted. -- `net tls test ` will attempt a normal tls handshake with `` based on the trusted Root CA certificates in the PDDB. If the connection is successful, then a simple `get` is emitted, the response accepted, and the connection closed. -- `net tls mozilla` trusts and saves all Root CA's in the [webpki-roots crate](https://crates.io/crates/webpki-roots) - which contains Mozilla's root certificates. (requires `--feature rootCA`) +- `net tls test ` will attempt a normal tls handshake with `` based on the trusted Root CA certificates in the PDDB. If the connection is successful, then a simple `get` is emitted, the response accepted, and the connection closed. +- `net tls mozilla` trusts and saves all Root CA's in the [webpki-roots crate](https://crates.io/crates/webpki-roots) - which contains Mozilla's root certificates. (requires `--feature rootCA`) - `net list` lists all trusted certificates in the PDDB - `net deleteall` deletes all trusted certificates in the PDDB @@ -37,5 +37,5 @@ Considerations: - there is an outstanding **issue** where the `checkbox` modal does not display options with multiple lines correctly. This impacts the display of fingerprints for some certificates with longer subjects. - It may be worth considering rendering public `pddb::KEY_NAME_LEN` to allow developer to avoid sending overly long key's which will be rejected by the pddb. - probably need a shellchat `net tls delete ` -- some broken code is included for a future fix if required [RustlsOwnedTrustAnchor::publik_key()](https://github.com/betrusted-io/xous-core/pull/394/commits/4e0298c17ad2c51aa220a88dc69bf2f56e51076f) +- some broken code is included for a future fix if required [RustlsOwnedTrustAnchor::public_key()](https://github.com/betrusted-io/xous-core/pull/394/commits/4e0298c17ad2c51aa220a88dc69bf2f56e51076f) - some hosts (eg bunnyfoo.com) emit an `unexpected eof` error during tls handshake 🤷 diff --git a/libs/tls/locales/i18n.json b/libs/tls/locales/i18n.json index f6f4cdea3..dd04aacda 100644 --- a/libs/tls/locales/i18n.json +++ b/libs/tls/locales/i18n.json @@ -40,8 +40,8 @@ "en-tts": "save host CA'a if trusted" }, "tls.probe_fail_servername": { - "en": "failed to create sever name from", - "en-tts": "failed to create sever name from" + "en": "failed to create server name from", + "en-tts": "failed to create server name from" }, "tls.probe_done": { "en": "trusted CA's", diff --git a/libs/tls/src/lib.rs b/libs/tls/src/lib.rs index c7c862221..6fd678673 100644 --- a/libs/tls/src/lib.rs +++ b/libs/tls/src/lib.rs @@ -278,7 +278,7 @@ impl Tls { root_store } - /// Probes the target and returns true is at least 1 certificate is trusted + /// Probes the target and returns a count of newly trusted 1 certificates /// /// Establishes a tls connection to the target host, extracts the /// certificates offered and immediately closes the connection. From 7e485885b750ea027f80a14a1f0e9956c1bf44b5 Mon Sep 17 00:00:00 2001 From: nworbnhoj Date: Wed, 29 Nov 2023 13:23:12 +1100 Subject: [PATCH 2/4] introduce tls probe help modals - invalid certificate modal - unknown issuer modal - not valid yet modal --- libs/tls/locales/i18n.json | 12 ++++++++++++ libs/tls/src/danger.rs | 29 +++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/libs/tls/locales/i18n.json b/libs/tls/locales/i18n.json index dd04aacda..303ca9028 100644 --- a/libs/tls/locales/i18n.json +++ b/libs/tls/locales/i18n.json @@ -43,6 +43,18 @@ "en": "failed to create server name from", "en-tts": "failed to create server name from" }, + "tls.probe_invalid_certificate": { + "en": "Invalid certificate : ", + "en-tts": "Invalid certificate : " + }, + "tls.probe_help_unknown_issuer": { + "en": "you may choose to trust a known CA", + "en-tts": "you may choose to trust a known CA" + }, + "tls.probe_help_not_valid_yet": { + "en": "error maybe caused by an improperly set clock", + "en-tts": "error maybe caused by an improperly set clock" + }, "tls.probe_done": { "en": "trusted CA's", "en-tts": "trusted CA's" diff --git a/libs/tls/src/danger.rs b/libs/tls/src/danger.rs index b7c606788..f47acf11c 100644 --- a/libs/tls/src/danger.rs +++ b/libs/tls/src/danger.rs @@ -1,5 +1,8 @@ +use locales::t; +use modals::Modals; use rustls::client::{ServerCertVerified, WebPkiVerifier}; use rustls::{CertificateError, Error, RootCertStore}; +use xous_names::XousNames; pub struct StifledCertificateVerification { pub roots: RootCertStore, @@ -28,8 +31,30 @@ impl rustls::client::ServerCertVerifier for StifledCertificateVerification { now, ) { Ok(ok) => Ok(ok), - Err(Error::InvalidCertificate(CertificateError::UnknownIssuer)) => { - Ok(ServerCertVerified::assertion()) + Err(Error::InvalidCertificate(e)) => { + let xns = XousNames::new().unwrap(); + let modals = Modals::new(&xns).unwrap(); + modals + .show_notification( + format!("{}\n{:?}", t!("tls.probe_invalid_certificate", locales::LANG), e).as_str(), + None, + ) + .expect("modal failed"); + match e { + CertificateError::UnknownIssuer => { + modals + .show_notification(t!("tls.probe_help_unknown_issuer", locales::LANG), None) + .expect("modal failed"); + Ok(ServerCertVerified::assertion()) + } + CertificateError::NotValidYet => { + modals + .show_notification(t!("tls.probe_help_not_valid_yet", locales::LANG), None) + .expect("modal failed"); + Err(Error::InvalidCertificate(e)) + } + _ => Err(Error::InvalidCertificate(e)), + } } Err(e) => Err(e), } From ffa3d56af425e65f7efd802694279498d27095f4 Mon Sep 17 00:00:00 2001 From: nworbnhoj Date: Thu, 30 Nov 2023 07:24:58 +1100 Subject: [PATCH 3/4] fix ChatOp::PostAdd to default correctly to dialogue_key set by ChatOp::DialogueSet --- libs/chat/src/lib.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/libs/chat/src/lib.rs b/libs/chat/src/lib.rs index 52fc28563..d5f6e5834 100644 --- a/libs/chat/src/lib.rs +++ b/libs/chat/src/lib.rs @@ -354,7 +354,7 @@ pub fn server( log::info!("my PID is {}", xous::process::id()); let mut ui = ui::Ui::new(sid, app_name, app_menu, app_cid, opcode_event); - + let mut dialogue_key = None; let mut allow_redraw = false; loop { let msg = xous::receive_message(sid).unwrap(); @@ -408,7 +408,7 @@ pub fn server( let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let dialogue = buffer.to_original::().unwrap(); - let dialogue_key = match dialogue.key { + dialogue_key = match dialogue.key { Some(key) => Some(key.to_string()), None => None, }; @@ -526,19 +526,24 @@ pub fn server( } Some(ChatOp::PostAdd) => { log::info!("ChatOp::PostAdd"); - let buffer = - unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; - match buffer.to_original::() { - Ok(post) => ui - .post_add( - post.dialogue_id.as_str().unwrap(), - post.author.as_str().unwrap(), - post.timestamp, - post.text.as_str().unwrap(), - None, // TODO implement - ) - .unwrap(), - Err(e) => log::warn!("failed to deserialize Post: {:?}", e), + match dialogue_key { + Some(ref dialogue_id) => { + let buffer = + unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; + match buffer.to_original::() { + Ok(post) => ui + .post_add( + &dialogue_id, + post.author.as_str().unwrap(), + post.timestamp, + post.text.as_str().unwrap(), + None, // TODO implement + ) + .unwrap(), + Err(e) => log::warn!("failed to deserialize Post: {:?}", e), + } + } + None => log::warn!("failed to PostAdd with Dialogue == None"), } } Some(ChatOp::PostDel) => { From 9de7f0545a16839c7a3bc2436279df96c0dba2eb Mon Sep 17 00:00:00 2001 From: nworbnhoj Date: Thu, 30 Nov 2023 07:29:33 +1100 Subject: [PATCH 4/4] remove redundant rustls package from mtxchat manifest --- apps/mtxchat/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/mtxchat/Cargo.toml b/apps/mtxchat/Cargo.toml index f4fcc7dd4..c02f1e02d 100644 --- a/apps/mtxchat/Cargo.toml +++ b/apps/mtxchat/Cargo.toml @@ -33,7 +33,6 @@ chat = { path = "../../libs/chat" } modals = { path = "../../services/modals" } percent-encoding = "2.2" rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} -rustls = { version = "0.21.7" } serde = { version = "1.0", features = [ "derive" ] } tls = { path = "../../libs/tls" } ureq = { version = "2.7.1", features = ["json"] }