Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ secluso-v*
*.p12
__pycache__
*.wic
metadata.json
metadata.json

# Prevent un-necessary Cargo.lock files from being introduced.
Cargo.lock
5 changes: 5 additions & 0 deletions camera_hub/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion camera_hub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ edition = "2021"
authors = ["Ardalan Amiri Sani <arrdalan@gmail.com>"]

[features]
default = ["logging"]
default = ["logging", "crypto-aws-lc"]
logging = ["log"]
# crypto-ring on armv6 (Pi Zero W)
crypto-aws-lc = ["secluso-client-lib/crypto-aws-lc"]
crypto-ring = ["secluso-client-lib/crypto-ring"]
ip = ["dep:rpassword", "dep:reqwest", "dep:http-auth", "dep:linfa", "dep:linfa-clustering", "dep:retina", "dep:serde_yaml2", "dep:ndarray", "dep:futures", "secluso-client-lib/camera_secret_qrcode"]
raspberry = ["dep:secluso-motion-ai"]
use_ai = ["secluso-motion-ai/ai"]
manual = []
telemetry = [] # todo: dep on the motion_ai crate
test = []
Expand Down
122 changes: 70 additions & 52 deletions camera_hub/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
//!
//! SPDX-License-Identifier: GPL-3.0-or-later

use crate::DeliveryMonitor;
use crate::pairing::get_names;
use crate::version::camera_version_info;
use crate::DeliveryMonitor;
use secluso_client_lib::config::{
Heartbeat, HeartbeatRequest, OPCODE_HEARTBEAT_REQUEST, OPCODE_HEARTBEAT_RESPONSE,
AddAppRequest, AddAppResponseCommon, AddAppResponseDedicated, OPCODE_ADD_APP_REQUEST, OPCODE_ADD_APP_RESPONSE,
AddAppRequest, AddAppResponseCommon, AddAppResponseDedicated, Heartbeat, HeartbeatRequest,
OPCODE_ADD_APP_REQUEST, OPCODE_ADD_APP_RESPONSE, OPCODE_HEARTBEAT_REQUEST,
OPCODE_HEARTBEAT_RESPONSE,
};
use secluso_client_lib::http_client::HttpClient;
use secluso_client_lib::mls_clients::{NUM_MLS_CLIENTS, MlsClientsCommon, MlsClientsDedicated, CONFIG_DED,
NUM_DEDICATED_MLS_CLIENTS, NUM_COMMON_MLS_CLIENTS};
use secluso_client_lib::mls_client::{MlsClient, ClientType};
use secluso_client_lib::mls_client::{ClientType, MlsClient};
use secluso_client_lib::mls_clients::{
MlsClientsCommon, MlsClientsDedicated, CONFIG_DED, NUM_COMMON_MLS_CLIENTS,
NUM_DEDICATED_MLS_CLIENTS, NUM_MLS_CLIENTS,
};
use std::io;

pub fn process_config_command(
Expand All @@ -39,7 +42,7 @@ pub fn process_config_command(
delivery_monitor_opt,
)?;
Ok(None)
},
}
OPCODE_ADD_APP_REQUEST => {
if primary_app {
if !second_app_already_paired {
Expand All @@ -58,11 +61,11 @@ pub fn process_config_command(
error!("Error: Secondary app cannot add other apps!");
Ok(None)
}
},
}
_ => {
error!("Error: Unknown config command opcode!");
Ok(None)
},
}
}
}
Err(e) => {
Expand Down Expand Up @@ -98,7 +101,12 @@ fn handle_heartbeat_request(
);
}

send_heartbeat_response(clients_com, clients_ded, heartbeat_request.timestamp, http_client)?;
send_heartbeat_response(
clients_com,
clients_ded,
heartbeat_request.timestamp,
http_client,
)?;

Ok(())
}
Expand All @@ -109,15 +117,19 @@ fn send_heartbeat_response(
timestamp: u64,
http_client: &HttpClient,
) -> io::Result<()> {
let heartbeat = Heartbeat::generate(clients_com, clients_ded, timestamp, camera_version_info()?)?;
let heartbeat =
Heartbeat::generate(clients_com, clients_ded, timestamp, camera_version_info()?)?;

let mut config_msg = vec![OPCODE_HEARTBEAT_RESPONSE];
config_msg.extend(bincode::serialize(&heartbeat).unwrap());

let config_msg_enc = clients_ded[CONFIG_DED].encrypt(&config_msg)?;
clients_ded[CONFIG_DED].save_group_state().unwrap();

http_client.config_response(&clients_ded[CONFIG_DED].get_group_name().unwrap(), config_msg_enc)?;
http_client.config_response(
&clients_ded[CONFIG_DED].get_group_name().unwrap(),
config_msg_enc,
)?;

Ok(())
}
Expand All @@ -131,52 +143,49 @@ fn handle_add_app_request(
let add_app_requests: [AddAppRequest; NUM_MLS_CLIENTS] = bincode::deserialize(command_bytes)
.map_err(|e| io::Error::other(format!("Failed to deserialize add_app msg - {e}")))?;

let add_app_resps_com: [AddAppResponseCommon; NUM_COMMON_MLS_CLIENTS] = std::array::from_fn(|i| {
println!("handle_add_app_request [1]");
let camera_key_package = clients_com[i].key_package();

// FIXME: "app2" is hardcoded.
println!("handle_add_app_request [2]");
let camera_contact =
MlsClient::create_contact("app2", add_app_requests[i].new_app_key_package.clone())
let add_app_resps_com: [AddAppResponseCommon; NUM_COMMON_MLS_CLIENTS] =
std::array::from_fn(|i| {
println!("handle_add_app_request [1]");
let camera_key_package = clients_com[i].key_package();

// FIXME: "app2" is hardcoded.
println!("handle_add_app_request [2]");
let camera_contact =
MlsClient::create_contact("app2", add_app_requests[i].new_app_key_package.clone())
.unwrap();

println!("handle_add_app_request [3]");
// FIXME: Use a different secret per channel
let (welcome_msg_vec, psk_proposal_vec, commit_msg_vec) = clients_com[i]
.invite_with_secret(&camera_contact, add_app_requests[i].secret.clone())
.unwrap();

println!("handle_add_app_request [3]");
// FIXME: Use a different secret per channel
let (welcome_msg_vec, psk_proposal_vec, commit_msg_vec) = clients_com[i]
.invite_with_secret(&camera_contact, add_app_requests[i].secret.clone())
.unwrap();

println!("handle_add_app_request [4]");
clients_com[i].save_group_state().unwrap();
println!("handle_add_app_request [4]");
clients_com[i].save_group_state().unwrap();

println!("handle_add_app_request [5]");
AddAppResponseCommon {
camera_key_package,
welcome_msg_vec,
psk_proposal_vec,
commit_msg_vec,
}
});
println!("handle_add_app_request [5]");
AddAppResponseCommon {
camera_key_package,
welcome_msg_vec,
psk_proposal_vec,
commit_msg_vec,
}
});

let [(client_l, resp_l), (client_c, resp_c)]: [(MlsClient, AddAppResponseDedicated); NUM_DEDICATED_MLS_CLIENTS] =
std::array::from_fn(|i| {
let [(client_l, resp_l), (client_c, resp_c)]: [(MlsClient, AddAppResponseDedicated);
NUM_DEDICATED_MLS_CLIENTS] = std::array::from_fn(|i| {
// This part of code has a lot in common with initialize_mls_clients() in main.rs

// Initialize mls_client
// FIXME
let tag = if i == 0 {
"livestream2"
} else {
"config2"
};
let tag = if i == 0 { "livestream2" } else { "config2" };

let (camera_name, group_name) = get_names(
clients_ded[CONFIG_DED].get_file_dir(), // Could use either of the clients
true,
format!("camera_{}_name", tag),
format!("group_{}_name", tag),
);
clients_ded[CONFIG_DED].get_file_dir(), // Could use either of the clients
true,
format!("camera_{}_name", tag),
format!("group_{}_name", tag),
);
let mut client = MlsClient::new(
camera_name,
true,
Expand All @@ -193,15 +202,21 @@ fn handle_add_app_request(

// Now invite
let camera_key_package = client.key_package();
let app_key_package = add_app_requests[i + NUM_COMMON_MLS_CLIENTS].new_app_key_package.clone();
let app_key_package = add_app_requests[i + NUM_COMMON_MLS_CLIENTS]
.new_app_key_package
.clone();
let app_contact = MlsClient::create_contact("app", app_key_package).unwrap();
info!("Added contact.");

let (welcome_msg_vec, _, _) = client
.invite_with_secret(&app_contact, add_app_requests[i + NUM_COMMON_MLS_CLIENTS].secret.clone())
.invite_with_secret(
&app_contact,
add_app_requests[i + NUM_COMMON_MLS_CLIENTS].secret.clone(),
)
.inspect_err(|_| {
error!("invite() returned error:");
}).unwrap();
})
.unwrap();
client.save_group_state().unwrap();
info!("App invited to the group.");

Expand Down Expand Up @@ -230,7 +245,10 @@ fn handle_add_app_request(
println!("[1]: config_msg_enc len = {:?}", config_msg_enc.len());
clients_ded[CONFIG_DED].save_group_state().unwrap();

http_client.config_response(&clients_ded[CONFIG_DED].get_group_name().unwrap(), config_msg_enc)?;
http_client.config_response(
&clients_ded[CONFIG_DED].get_group_name().unwrap(),
config_msg_enc,
)?;

Ok(Some(new_clients_ded))
}
7 changes: 4 additions & 3 deletions camera_hub/src/delivery_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ impl DeliveryMonitor {
file.sync_all().unwrap();

//delete old state files
let d_files =
Self::get_state_files_sorted(&self.state_dir, "delivery_monitor_").unwrap();
let d_files = Self::get_state_files_sorted(&self.state_dir, "delivery_monitor_").unwrap();
assert!(d_files[0] == "delivery_monitor_".to_owned() + &current_timestamp.to_string());
for f in &d_files[1..] {
let _ = fs::remove_file(self.state_dir.clone() + "/" + f);
Expand Down Expand Up @@ -278,7 +277,9 @@ impl DeliveryMonitor {

pub fn get_thumbnail_file_path(&self, info: &ThumbnailMetaInfo) -> PathBuf {
let video_dir_path = Path::new(&self.thumbnail_dir);
video_dir_path.join(ThumbnailMetaInfo::get_filename_from_timestamp(info.timestamp))
video_dir_path.join(ThumbnailMetaInfo::get_filename_from_timestamp(
info.timestamp,
))
}

pub fn get_enc_video_file_path(&self, info: &VideoInfo) -> PathBuf {
Expand Down
Loading
Loading