From 2f042cff70cc24e3739c21dba94fae61905ed557 Mon Sep 17 00:00:00 2001 From: nworbnhoj Date: Wed, 28 Jun 2023 13:35:51 +1000 Subject: [PATCH] implement tls locales/i18n.json en en-tts --- libs/tls/Cargo.toml | 1 + libs/tls/locales/i18n.json | 46 ++++++++++++++++++++++++++++++++++++++ libs/tls/src/cmd.rs | 24 ++++++++++++-------- libs/tls/src/lib.rs | 3 ++- 4 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 libs/tls/locales/i18n.json diff --git a/libs/tls/Cargo.toml b/libs/tls/Cargo.toml index 6311e3f60..2ce191452 100644 --- a/libs/tls/Cargo.toml +++ b/libs/tls/Cargo.toml @@ -19,6 +19,7 @@ modals = { path = "../../services/modals" } net = { path = "../../services/net" } pddb = { path = "../../services/pddb" } +locales = {path = "../../locales"} rkyv = "0.4.3" # note requirement for patch to xous-ring in workspace Cargo.toml diff --git a/libs/tls/locales/i18n.json b/libs/tls/locales/i18n.json new file mode 100644 index 000000000..915c95989 --- /dev/null +++ b/libs/tls/locales/i18n.json @@ -0,0 +1,46 @@ +{ + "tls.check_trust_prompt": { + "en": "Do you trust any of these certificate authorities?", + "en-tts": "Do you trust any of these certificate authorities?" + }, + "tls.cmd_help": { + "en": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls probe \n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser.", + "en-tts": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls probe \n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser." + }, + "tls.cmd": { + "en": "net tls ", + "en-tts": "net tls " + }, + "tls.mozilla_cmd": { + "en": "trust all Root CA's in webpki-roots", + "en-tts": "trust all Root CA's in webpki-roots" + }, + "tls.probe_cmd": { + "en": "save host CA'a if trusted", + "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" + }, + "tls.test_cmd": { + "en": "make tls connection to host", + "en-tts": "make tls connection to host" + }, + "tls.test_success_tcp": { + "en": "tcp connected\n", + "en-tts": "tcp connected" + }, + "tls.test_success_get": { + "en": "tls accepted GET\n", + "en-tts": "tls accepted GET" + }, + "tls.test_success_bytes": { + "en": "tls received bytes", + "en-tts": "tls received bytes" + }, + "tls.trusted_cmd": { + "en": "list trusted CA certificates", + "en-tts": "list trusted CA certificates" + } +} diff --git a/libs/tls/src/cmd.rs b/libs/tls/src/cmd.rs index 51771ce02..143a80510 100644 --- a/libs/tls/src/cmd.rs +++ b/libs/tls/src/cmd.rs @@ -1,4 +1,5 @@ use crate::{check_trust, danger, trusted::Trusted}; +use locales::t; use std::convert::TryInto; use std::io::Read; use std::io::Write; @@ -11,6 +12,10 @@ pub fn shellchat<'a>( use core::fmt::Write; let mut ret = String::new(); match tokens.next() { + Some("help") => { + write!(ret, "{}", t!("tls.cmd_help", locales::LANG)).ok(); + () + } // save/trust all Root CA's in webpki-roots en-masse #[cfg(feature = "rootCA")] Some("mozilla") => { @@ -54,7 +59,7 @@ pub fn shellchat<'a>( }; let server_name = target.try_into().unwrap_or_else(|e| { log::warn!("failed to create sever_name from {target}: {e}"); - write!(ret, "failed to create sever_name from {target}").ok(); + write!(ret, "{} {target}", t!("tls.probe_fail_servername", locales::LANG)).ok(); "bunnyfoo.com".try_into().unwrap() }); let mut conn = rustls::ClientConnection::new(Arc::new(config), server_name).unwrap(); @@ -108,20 +113,20 @@ pub fn shellchat<'a>( match TcpStream::connect(url) { Ok(mut sock) => { log::info!("tcp connected"); - write!(ret, "tcp connected\n").ok(); + write!(ret, "{}", t!("tls.test_success_tcp", locales::LANG)).ok(); let mut tls = rustls::Stream::new(&mut conn, &mut sock); log::info!("create http headers and write to server"); let msg = format!("GET / HTTP/1.1\r\nHost: {}\r\nConnection: close\r\nAccept-Encoding: identity\r\n\r\n", target); match tls.write_all(msg.as_bytes()) { Ok(()) => { log::info!("tls accepted GET"); - write!(ret, "tls accepted GET\n").ok(); + write!(ret, "{}", t!("tls.test_success_get", locales::LANG)).ok(); let mut plaintext = Vec::new(); log::info!("read TLS response"); match tls.read_to_end(&mut plaintext) { Ok(n) => { log::info!("tls received {} bytes", n); - write!(ret, "tls received {} bytes\n", n).ok(); + write!(ret, "{} {}\n", t!("tls.test_success_bytes", locales::LANG), n).ok(); log::info!( "{}", std::str::from_utf8(&plaintext).unwrap_or("utf-error") @@ -158,12 +163,13 @@ pub fn shellchat<'a>( log::info!("finished TLS trusted listing"); } None | _ => { - write!(ret, "net tls \n").ok(); + write!(ret, "{}\n", t!("tls.cmd", locales::LANG)).ok(); + write!(ret, "\thelp\n").ok(); #[cfg(feature = "rootCA")] - write!(ret, "\tmozilla\ttrust all Root CA's in webpki-roots\n").ok(); - write!(ret, "\tprobe \tsave host CA'a if trusted\n").ok(); - write!(ret, "\ttest \tmake tls connection to host\n").ok(); - write!(ret, "\ttrusted\tlist trusted CA certificates\n").ok(); + write!(ret, "\tmozilla\t{}\n", t!("tls.mozilla_cmd", locales::LANG)).ok(); + write!(ret, "\tprobe \t{}\n", t!("tls.probe_cmd", locales::LANG)).ok(); + write!(ret, "\ttest \t{}\n", t!("tls.test_cmd", locales::LANG)).ok(); + write!(ret, "\ttrusted\t{}\n", t!("tls.trusted_cmd", locales::LANG)).ok(); } } Ok(Some(ret)) diff --git a/libs/tls/src/lib.rs b/libs/tls/src/lib.rs index 6d6d92698..30b617eaf 100644 --- a/libs/tls/src/lib.rs +++ b/libs/tls/src/lib.rs @@ -4,6 +4,7 @@ pub mod rota; pub mod trusted; use crate::rota::RustlsOwnedTrustAnchor; +use locales::t; use modals::Modals; use rkyv::{ de::deserializers::AllocDeserializer, @@ -54,7 +55,7 @@ pub fn check_trust(certificates: &[Certificate]) -> bool { modals .add_list(chain) .expect("couldn't build checkbox list"); - match modals.get_checkbox("Do you trust any of these certificate authorities?") { + match modals.get_checkbox(t!("tls.check_trust_prompt", locales::LANG)) { Ok(trusted) => { trusted .iter()