Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
feat(security): added whitelists, blacklists and TLS protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilit0x committed Jul 26, 2023
1 parent b187021 commit a98a066
Show file tree
Hide file tree
Showing 14 changed files with 377 additions and 193 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "share"
version = "0.0.16"
version = "0.0.17"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,16 @@ Contributions of any kind are welcome! See the [contributing guide](contributing
# Roadmap

### Utilities
- [ ] Configuration File: Enables users to pass in a config file as an argument instead of listing all parameters manually.
- [x] Configuration File: Enables users to pass in a config file as an argument instead of listing all parameters manually.
- [x] Default path to save items(messgaes, secrets and files).
- [x] Replace secrets or update them
- [x] When files with the same name are received, discard, keep, inform, or update them
- [ ] Add a whitelist of IPs to allow connection from
- [x] Add a whitelist of IPs to allow connection from
- [ ] Publish `share` to crates.io to enable users to `cargo install secure-share`
### Security
- [ ] Signed Certificates from Let's Encrypt.
- [ ] Whitelists and Blacklists
- [x] TLS
- [x] Whitelists and Blacklists
### Protocols
- [ ] Support QUIC. Use QUIC as default and fall back to TCP
Expand Down
6 changes: 4 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ message: #Optional during receive
- test message
file: #Optional during receive
- "./dev_build.sh"
debug: 0 #Compulsory. 0 is for off and 1 and above for on

debug: 1 #Compulsory. 0 is for off and 1 and above for on
blacklists:
- 127.0.0.1
- 34.138.139.178
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onboardbase/secure-share",
"version": "0.0.16",
"version": "0.0.17",
"description": "Share anything with teammates across machines via CLI",
"scripts": {
"test": "jest",
Expand Down
1 change: 0 additions & 1 deletion src/common/mod.rs

This file was deleted.

14 changes: 14 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{
collections::HashSet,
fs::{self, OpenOptions},
net::Ipv4Addr,
path::{Path, PathBuf},
};

Expand All @@ -17,6 +19,8 @@ pub struct Config {
port: i32,
debug: u8,
save_path: PathBuf,
whitelists: Option<HashSet<Ipv4Addr>>,
blacklists: Option<HashSet<Ipv4Addr>>,
}

impl Config {
Expand Down Expand Up @@ -44,6 +48,8 @@ impl Config {
port: opts.port.unwrap_or(0),
debug: opts.debug,
save_path: Config::create_default_path()?,
whitelists: None,
blacklists: None,
};
Ok(config)
}
Expand Down Expand Up @@ -105,4 +111,12 @@ impl Config {
pub fn save_path(&self) -> PathBuf {
self.save_path.clone()
}

pub fn whitelists(&self) -> Option<HashSet<Ipv4Addr>> {
self.whitelists.clone()
}

pub fn blacklists(&self) -> Option<HashSet<Ipv4Addr>> {
self.blacklists.clone()
}
}
1 change: 1 addition & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod security;
60 changes: 60 additions & 0 deletions src/handlers/security.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use libp2p::{
identify::{Event, Info},
multiaddr::Protocol,
};

use crate::config::Config;

pub fn is_ip_whitelisted(event: &Event, config: &Config) -> bool {
if let Some(whitelists) = config.whitelists() {
match event {
Event::Received {
info: Info { listen_addrs, .. },
..
} => {
let addresses = listen_addrs
.iter()
.map(|addr| {
let components = addr.iter().collect::<Vec<_>>();
components[0].clone()
})
.collect::<Vec<_>>();

addresses.iter().all(|addr| match addr {
Protocol::Ip4(ip_addr) => whitelists.contains(ip_addr),
_ => false,
})
}
_ => true,
}
} else {
true
}
}

pub fn is_ip_blacklisted(event: &Event, config: &Config) -> bool {
if let Some(blacklists) = config.blacklists() {
match event {
Event::Received {
info: Info { listen_addrs, .. },
..
} => {
let addresses = listen_addrs
.iter()
.map(|addr| {
let components = addr.iter().collect::<Vec<_>>();
components[0].clone()
})
.collect::<Vec<_>>();

addresses.iter().any(|addr| match addr {
Protocol::Ip4(ip_addr) => blacklists.contains(ip_addr),
_ => false,
})
}
_ => false,
}
} else {
false
}
}
1 change: 1 addition & 0 deletions src/item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct ItemResponse {
pub status: Status,
pub no_of_success: usize,
pub no_of_fails: usize,
pub err: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
use clap::Parser;
use config::Config;
use libp2p::PeerId;
use network::punch;
use std::{process::exit, str::FromStr};
use tracing::error;

mod config;
mod hole_puncher;
mod handlers;
mod item;
mod logger;
mod network;

#[derive(Parser, Debug)]
#[command(name = "share")]
#[command(author = "Onboardbase. <onboardbase.com>")]
#[command(version = "0.0.16")]
#[command(version = "0.0.17")]
#[command(about = "Share anything with teammates across machines via CLI.", long_about = None)]
pub struct Cli {
/// Separated list of secrets to share. Key-Value pair is seperated by a comma. "my_key,my_value"
Expand Down Expand Up @@ -81,7 +83,7 @@ async fn main() {
logger::log(&config).unwrap();

let code = {
match hole_puncher::punch(mode, remote_peer_id, config) {
match punch(mode, remote_peer_id, config) {
Ok(_) => 1,
Err(err) => {
error!("{:#?}", err.to_string());
Expand Down
Loading

0 comments on commit a98a066

Please sign in to comment.