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), }