This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(security): added whitelists, blacklists and TLS protocol
- Loading branch information
Showing
14 changed files
with
377 additions
and
193 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod security; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.