mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
implement tls locales/i18n.json en en-tts
This commit is contained in:
parent
3acc43f2b0
commit
2f042cff70
4 changed files with 64 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
46
libs/tls/locales/i18n.json
Normal file
46
libs/tls/locales/i18n.json
Normal file
|
|
@ -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 <host>\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 <host>\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 <sub-command>",
|
||||
"en-tts": "net tls <sub-command>"
|
||||
},
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
|
@ -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 <sub-command>\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 <host>\tsave host CA'a if trusted\n").ok();
|
||||
write!(ret, "\ttest <host>\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 <host>\t{}\n", t!("tls.probe_cmd", locales::LANG)).ok();
|
||||
write!(ret, "\ttest <host>\t{}\n", t!("tls.test_cmd", locales::LANG)).ok();
|
||||
write!(ret, "\ttrusted\t{}\n", t!("tls.trusted_cmd", locales::LANG)).ok();
|
||||
}
|
||||
}
|
||||
Ok(Some(ret))
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue