From bc760dac27e7a2e6732194490ba0991b0669ef28 Mon Sep 17 00:00:00 2001 From: Lilit0x Date: Thu, 3 Aug 2023 06:36:04 +0100 Subject: [PATCH 1/3] fix: moved identifying connection details to when a connection is established --- npm/package.json | 2 +- share/src/network/hole_puncher.rs | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/npm/package.json b/npm/package.json index e0c4d57..6788ee6 100644 --- a/npm/package.json +++ b/npm/package.json @@ -7,7 +7,7 @@ "postinstall": "node ./install.js" }, "bin": { - "share": "run.js" + "scs": "run.js" }, "repository": { "type": "git", diff --git a/share/src/network/hole_puncher.rs b/share/src/network/hole_puncher.rs index 3e13382..a18aae1 100644 --- a/share/src/network/hole_puncher.rs +++ b/share/src/network/hole_puncher.rs @@ -142,6 +142,7 @@ pub fn punch(mode: Mode, remote_peer_id: Option, config: Config) -> Resu } let mut connection_deets = ConnectionDetails::new(); block_on(async { + let mut validated_ip = false; loop { match swarm.next().await.unwrap() { SwarmEvent::NewListenAddr { address, .. } => { @@ -172,19 +173,27 @@ pub fn punch(mode: Mode, remote_peer_id: Option, config: Config) -> Resu if !is_ip_whitelisted(&event, &config) { swarm.close_connection(connection_id); } + validated_ip = true; } SwarmEvent::Behaviour(Event::Ping(_)) => {} SwarmEvent::IncomingConnection { connection_id, .. } => { - connection_deets.save_id(connection_id); + debug!("INCOMING CONNECTION: {:?}", connection_id); } SwarmEvent::ConnectionEstablished { - peer_id, endpoint, .. + peer_id, + endpoint, + connection_id, + .. } => { + connection_deets.save_id(connection_id); + let addr = endpoint.get_remote_address(); info!("Established connection to {peer_id} via {addr}"); - //Send secrets to the receiver - make_request(mode, &mut swarm, peer_id, &config); + if validated_ip { + //Send secrets to the receiver + make_request(mode, &mut swarm, peer_id, &config); + } } SwarmEvent::OutgoingConnectionError { peer_id: _, error, .. From 5bc13de84e840415997ee4b0d2cdd221f43410cc Mon Sep 17 00:00:00 2001 From: Lilit0x Date: Thu, 3 Aug 2023 06:56:16 +0100 Subject: [PATCH 2/3] fix: restricted sending messages untile after ip validation --- config.yml | 6 +++--- share/src/network/hole_puncher.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/config.yml b/config.yml index 6d6f08f..8c98ed6 100644 --- a/config.yml +++ b/config.yml @@ -16,6 +16,6 @@ message: #Optional during receive file: #Optional during receive - "./dev_build.sh" debug: 1 #Compulsory. 0 is for off and 1 and above for on -blacklists: -- 127.0.0.1 -- 34.138.139.178 \ No newline at end of file +# blacklists: +# - 127.0.0.1 +# - 34.138.139.178 \ No newline at end of file diff --git a/share/src/network/hole_puncher.rs b/share/src/network/hole_puncher.rs index a18aae1..d775848 100644 --- a/share/src/network/hole_puncher.rs +++ b/share/src/network/hole_puncher.rs @@ -141,8 +141,8 @@ pub fn punch(mode: Mode, remote_peer_id: Option, config: Config) -> Resu } } let mut connection_deets = ConnectionDetails::new(); + block_on(async { - let mut validated_ip = false; loop { match swarm.next().await.unwrap() { SwarmEvent::NewListenAddr { address, .. } => { @@ -168,12 +168,14 @@ pub fn punch(mode: Mode, remote_peer_id: Option, config: Config) -> Resu // println!("deetttss {:#?}", connection_id); error!("This IP address is present in your blacklist."); swarm.close_connection(connection_id); + exit(1); } if !is_ip_whitelisted(&event, &config) { + error!("This IP address is not present in your whitleist."); swarm.close_connection(connection_id); + exit(1); } - validated_ip = true; } SwarmEvent::Behaviour(Event::Ping(_)) => {} SwarmEvent::IncomingConnection { connection_id, .. } => { @@ -190,10 +192,8 @@ pub fn punch(mode: Mode, remote_peer_id: Option, config: Config) -> Resu let addr = endpoint.get_remote_address(); info!("Established connection to {peer_id} via {addr}"); - if validated_ip { - //Send secrets to the receiver - make_request(mode, &mut swarm, peer_id, &config); - } + //Send secrets to the receiver + make_request(mode, &mut swarm, peer_id, &config); } SwarmEvent::OutgoingConnectionError { peer_id: _, error, .. From 5a6d5ed06ea01485c778eb64161359cb09b2cd31 Mon Sep 17 00:00:00 2001 From: Lilit0x Date: Thu, 3 Aug 2023 07:10:00 +0100 Subject: [PATCH 3/3] chore: bumped up version --- Cargo.lock | 2 +- npm/package.json | 2 +- share/Cargo.toml | 2 +- share/src/main.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d269c1..a0454c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2543,7 +2543,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "scs" -version = "0.1.1" +version = "0.1.2" dependencies = [ "anyhow", "assert_fs", diff --git a/npm/package.json b/npm/package.json index 6788ee6..f014e35 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "@onboardbase/secure-share", - "version": "0.1.1", + "version": "0.1.2", "description": "Share anything with teammates across machines via CLI", "scripts": { "test": "jest", diff --git a/share/Cargo.toml b/share/Cargo.toml index 1c8a048..ea30b0a 100644 --- a/share/Cargo.toml +++ b/share/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scs" -version = "0.1.1" +version = "0.1.2" edition = "2021" default-run = "scs" description = "Open source p2p share for devs to share anything with teammates across machines securely." diff --git a/share/src/main.rs b/share/src/main.rs index 1c312cf..51e1be3 100644 --- a/share/src/main.rs +++ b/share/src/main.rs @@ -14,7 +14,7 @@ mod network; #[derive(Parser, Debug)] #[command(name = "scs")] #[command(author = "Onboardbase. ")] -#[command(version = "0.1.1")] +#[command(version = "0.1.2")] #[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"