mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
sigchat probe the Signal host server for tls certificates
- prompt the user for the Signal host server - probe the host for the tls Certificate Authorities chain of trust - allow the user to trust 1 or more Certificate Authorities
This commit is contained in:
parent
046873cec5
commit
c9e3f549a4
3 changed files with 85 additions and 4 deletions
|
|
@ -3,6 +3,14 @@
|
||||||
"en": "Failed to setup Signal Account",
|
"en": "Failed to setup Signal Account",
|
||||||
"en-tts": "Failed to setup Signal Account"
|
"en-tts": "Failed to setup Signal Account"
|
||||||
},
|
},
|
||||||
|
"sigchat.account.abort": {
|
||||||
|
"en": "Signal Account setup aborted",
|
||||||
|
"en-tts": "Signal Account setup aborted"
|
||||||
|
},
|
||||||
|
"sigchat.account.host.name": {
|
||||||
|
"en": "Please provide the Signal host server name",
|
||||||
|
"en-tts": "Please provide the Signal host server name"
|
||||||
|
},
|
||||||
"sigchat.account.link": {
|
"sigchat.account.link": {
|
||||||
"en": "Link to an existing Signal Account",
|
"en": "Link to an existing Signal Account",
|
||||||
"en-tts": "Link to an existing Signal Account"
|
"en-tts": "Link to an existing Signal Account"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) const SERVER_NAME_SIGCHAT: &str = "_Signal chat_";
|
pub(crate) const SERVER_NAME_SIGCHAT: &str = "_Signal chat_";
|
||||||
|
pub(crate) const DEFAULT_HOST_NAME: &str = "signal.org";
|
||||||
|
|
||||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||||
pub enum SigchatOp {
|
pub enum SigchatOp {
|
||||||
|
|
|
||||||
|
|
@ -100,8 +100,32 @@ impl<'a> SigChat<'a> {
|
||||||
.expect("failed radiobutton modal");
|
.expect("failed radiobutton modal");
|
||||||
match self.modals.get_radio_index() {
|
match self.modals.get_radio_index() {
|
||||||
Ok(index) => match index {
|
Ok(index) => match index {
|
||||||
0 => Ok(self.account_link()?),
|
0 => {
|
||||||
1 => Ok(self.account_register()?),
|
let host = self.name_modal(
|
||||||
|
DEFAULT_HOST_NAME,
|
||||||
|
t!("sigchat.account.host.name", locales::LANG),
|
||||||
|
);
|
||||||
|
match self.probe_host(&host) {
|
||||||
|
true => Ok(self.account_link(&host)?),
|
||||||
|
false => Err(Error::new(
|
||||||
|
ErrorKind::Other,
|
||||||
|
"failed to trust host certificate",
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
let host = self.name_modal(
|
||||||
|
DEFAULT_HOST_NAME,
|
||||||
|
t!("sigchat.account.host.name", locales::LANG),
|
||||||
|
);
|
||||||
|
match self.probe_host(&host) {
|
||||||
|
true => Ok(self.account_register(&host)?),
|
||||||
|
false => Err(Error::new(
|
||||||
|
ErrorKind::Other,
|
||||||
|
"failed to trust host certificate",
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
2 => {
|
2 => {
|
||||||
log::info!("account setup aborted");
|
log::info!("account setup aborted");
|
||||||
Err(Error::new(ErrorKind::Other, "account setup aborted"))
|
Err(Error::new(ErrorKind::Other, "account setup aborted"))
|
||||||
|
|
@ -121,24 +145,72 @@ impl<'a> SigChat<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Probe host for tls Certificate Authority chain of trust
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * `host` - the dns name or ip address of a Signal server
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// true if at least 1 Certificate Authority is trusted
|
||||||
|
///
|
||||||
|
fn probe_host(&self, host: &str) -> bool {
|
||||||
|
let tls = Tls::new();
|
||||||
|
match tls.probe(host) {
|
||||||
|
Ok(0) => {
|
||||||
|
self.modals
|
||||||
|
.show_notification(t!("sigchat.account.abort", locales::LANG), None)
|
||||||
|
.expect("abort failed");
|
||||||
|
false
|
||||||
|
}
|
||||||
|
Ok(_count) => true,
|
||||||
|
Err(e) => {
|
||||||
|
self.modals
|
||||||
|
.show_notification(&format!("{}", e), None)
|
||||||
|
.expect("qrcode failed");
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Link this device to an existing Signal Account
|
/// Link this device to an existing Signal Account
|
||||||
///
|
///
|
||||||
/// Signal allows to link additional devices to your primary device (e.g. Signal-Android).
|
/// Signal allows to link additional devices to your primary device (e.g. Signal-Android).
|
||||||
/// Note that currently Signal allows up to three linked devices per primary.
|
/// Note that currently Signal allows up to three linked devices per primary.
|
||||||
///
|
///
|
||||||
pub fn account_link(&self) {
|
pub fn account_link(&mut self, host: &str) -> Result<Account, Error> {
|
||||||
self.modals
|
self.modals
|
||||||
.show_notification(&"sorry - linking is not implemented yet", None)
|
.show_notification(&"sorry - linking is not implemented yet", None)
|
||||||
.expect("notification failed");
|
.expect("notification failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Prompt a name from the user
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * `default_name` - A name suggested to the user
|
||||||
|
/// * `prompt` - A prompt to explain what is being requested
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// the name provided by the user
|
||||||
|
///
|
||||||
|
fn name_modal(&self, default_name: &str, prompt: &str) -> String {
|
||||||
|
match self
|
||||||
|
.modals
|
||||||
|
.alert_builder(prompt)
|
||||||
|
.field(Some(default_name.to_string()), None)
|
||||||
|
.build()
|
||||||
|
{
|
||||||
|
Ok(text) => text.content()[0].content.to_string(),
|
||||||
|
_ => default_name.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Register a new Signal Account with this as the primary device.
|
/// Register a new Signal Account with this as the primary device.
|
||||||
///
|
///
|
||||||
/// A Signal Account requires a phone number to receive SMS or incoming calls for registration & validation.
|
/// A Signal Account requires a phone number to receive SMS or incoming calls for registration & validation.
|
||||||
/// The phone number must include the country calling code, i.e. the number must start with a "+" sign.
|
/// The phone number must include the country calling code, i.e. the number must start with a "+" sign.
|
||||||
/// Warning: this will disable the authentication of your phone as a primary device.
|
/// Warning: this will disable the authentication of your phone as a primary device.
|
||||||
///
|
///
|
||||||
pub fn account_register(&mut self) -> Result<Account, Error> {
|
pub fn account_register(&mut self, host: &str) -> Result<Account, Error> {
|
||||||
log::info!("Attempting to Register a new Signal Account");
|
log::info!("Attempting to Register a new Signal Account");
|
||||||
self.modals
|
self.modals
|
||||||
.show_notification(&"sorry - registration is not implemented yet", None)
|
.show_notification(&"sorry - registration is not implemented yet", None)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue