Skip to content

Commit

Permalink
WIP: Add exit trust root server
Browse files Browse the repository at this point in the history
        TODO
        * Finish mvoing and testing array abi encoding/decoding
        * create abi packing functions for each type in the type file
          (effectively moving this from the rita_client_registration crate)
        * move the deserialization functions and tests over
        * expand fuzzing by serializing or deserializing randomly generated
          correct structs rather than just junk data
        * actually finish signature creation and return from the root of trust
          server
  • Loading branch information
jkilpatr committed Sep 14, 2024
1 parent bdf0d2f commit 1e8db00
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 12 deletions.
132 changes: 123 additions & 9 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"rita_bin",
"test_runner",
"integration_tests",
"exit_trust_root",
]

# Production relase profile, every trick is used to reduce binary size
Expand Down
1 change: 1 addition & 0 deletions althea_types/src/exits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::net::IpAddr;

pub mod encryption;
pub mod identity;
pub mod server_list_signatures;

#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash, Default)]
pub struct ExitRegistrationDetails {
Expand Down
2 changes: 2 additions & 0 deletions althea_types/src/exits/server_list_signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ mod tests {
// Serialize the signed exit server list
let serialized = serde_json::to_string(&signed_exit_server_list).unwrap();

println!("{}", serialized);

// Deserialize the serialized string back into a signed exit server list
let deserialized: SignedExitServerList = serde_json::from_str(&serialized).unwrap();

Expand Down
1 change: 1 addition & 0 deletions althea_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub use crate::connection_monitoring::*;
pub use crate::contact_info::*;
pub use crate::exits::encryption::*;
pub use crate::exits::identity::*;
pub use crate::exits::server_list_signatures::*;
pub use crate::exits::*;
pub use crate::hardware_info::*;
pub use crate::identity::*;
Expand Down
39 changes: 36 additions & 3 deletions althea_types/src/regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use serde::Serialize;
use serde::{Deserialize, Deserializer, Serializer};
use std::convert::Infallible;
use std::{
fmt::{self, Display},
str::FromStr,
Expand Down Expand Up @@ -758,8 +759,8 @@ impl Display for Regions {
}

impl FromStr for Regions {
type Err = String;
fn from_str(s: &str) -> Result<Regions, String> {
type Err = Infallible;
fn from_str(s: &str) -> Result<Regions, Infallible> {
let lowercase_s = s.to_lowercase();
match lowercase_s.as_str() {
"united states" => Ok(Regions::UnitedStates),
Expand Down Expand Up @@ -953,7 +954,7 @@ impl FromStr for Regions {
"vc" => Ok(Regions::SaintVincentAndTheGrenadines),
"trinidad and tobago" => Ok(Regions::TrinidadAndTobago),
"tt" => Ok(Regions::TrinidadAndTobago),
_ => Err("Invalid country code accepted formats are EX: US or United States (spaces included)".to_string()),
_ => Ok(Regions::UnkownRegion),
}
}
}
Expand All @@ -976,3 +977,35 @@ impl<'de> Deserialize<'de> for Regions {
s.parse().map_err(serde::de::Error::custom)
}
}

#[cfg(test)]
mod test {
use core::num;
use std::time::Duration;

use rand::random;

use super::Regions;

/// The number of current valid regions
const NUM_REGIONS: u8 = 179;

#[test]
fn string_serialize_and_parse() {
for i in 0..NUM_REGIONS {
let region = Regions::from(i);
let region_str = region.to_string();
let parsed_region: Regions = region_str.parse().unwrap();
assert_eq!(region, parsed_region);
}
}

#[test]
fn integer_serialize_and_parse() {
for i in 0..NUM_REGIONS {
let region = Regions::from(i);
let region_num_2: u8 = region.into();
assert_eq!(i, region_num_2);
}
}
}
26 changes: 26 additions & 0 deletions exit_trust_root/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "exit_trust_root"
version = "0.21.5"
edition = "2021"
license = "Apache-2.0"
description = "Server to provide a root of exit trust for Althea routers"

[[bin]]
name = "exit_trust_root"
path = "src/bin.rs"

[dependencies]
althea_types = { path = "../althea_types" }
actix-web = { version = "4.9", features = ["rustls","macros"] }
openssl-probe = "0.1.5"
env_logger = "0.11"
rustls = "0.20"
rustls-pemfile = "0.3"
log = "0.4"
clarity = "1.4"
web30 = "1.4"
crypto_box = "0.9"
rita_client_registration = { path = "../rita_client_registration" }

[features]
development = []
Loading

0 comments on commit 1e8db00

Please sign in to comment.