Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a restriction for IANA domain zones. Users cannot mine them fro…
…m now on.
- Loading branch information
Showing
8 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/target | ||
**/*.rs.bk | ||
/iana-tlds.txt | ||
/iana-hashes.txt |
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 |
---|---|---|
@@ -1,9 +1,67 @@ | ||
extern crate winres; | ||
|
||
use std::fs::File; | ||
use std::path::Path; | ||
use std::io::Write; | ||
|
||
use crypto::digest::Digest; | ||
use crypto::sha2::Sha256; | ||
|
||
fn main() { | ||
if cfg!(target_os = "windows") { | ||
let mut res = winres::WindowsResource::new(); | ||
res.set_icon("globe_icon.ico"); | ||
res.compile().unwrap(); | ||
} | ||
|
||
download_iana_zones("iana-tlds.txt", "iana-hashes.txt"); | ||
} | ||
|
||
fn download_iana_zones(zones_name: &str, hashes_name: &str) { | ||
let response = minreq::get("https://data.iana.org/TLD/tlds-alpha-by-domain.txt").send().expect("Could not make request!"); | ||
|
||
let response = response.as_str().expect("Response is not a valid UTF-8!").to_lowercase(); | ||
let list: Vec<_> = response.split("\n").collect(); | ||
let mut zones = String::new(); | ||
let mut hashes = String::new(); | ||
for string in list { | ||
if !string.starts_with("#") && !string.is_empty() { | ||
zones.push_str(string); | ||
zones.push('\n'); | ||
|
||
hashes.push_str(&hash_identity(string)); | ||
hashes.push('\n'); | ||
} | ||
} | ||
|
||
match File::create(Path::new(zones_name)) { | ||
Ok(mut file) => { | ||
file.write_all(zones.trim().as_bytes()).expect("Error saving TLDs file!"); | ||
} | ||
Err(e) => { println!("Error opening TLDs file!\n{}", e); } | ||
} | ||
|
||
match File::create(Path::new(hashes_name)) { | ||
Ok(mut file) => { | ||
file.write_all(hashes.trim().as_bytes()).expect("Error saving TLD-hashes file!"); | ||
} | ||
Err(e) => { println!("Error opening TLD-hashes file!\n{}", e); } | ||
} | ||
} | ||
|
||
fn hash_identity(identity: &str) -> String { | ||
let mut buf: [u8; 32] = [0; 32]; | ||
let mut digest = Sha256::new(); | ||
digest.input_str(identity); | ||
digest.result(&mut buf); | ||
to_hex(&buf) | ||
} | ||
|
||
/// Convert bytes array to HEX format | ||
pub fn to_hex(buf: &[u8]) -> String { | ||
let mut result = String::new(); | ||
for x in buf.iter() { | ||
result.push_str(&format!("{:01$X}", x, 2)); | ||
} | ||
result | ||
} |
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,28 @@ | ||
use std::collections::HashSet; | ||
|
||
pub struct Iana { | ||
zones: HashSet<String>, | ||
hashes: HashSet<String> | ||
} | ||
|
||
impl Iana { | ||
pub fn new() -> Self { | ||
let zones: HashSet<_> = include_str!("../iana-tlds.txt") | ||
.split("\n") | ||
.map(String::from) | ||
.collect(); | ||
let hashes: HashSet<_> = include_str!("../iana-hashes.txt") | ||
.split("\n") | ||
.map(String::from) | ||
.collect(); | ||
Self { zones, hashes } | ||
} | ||
|
||
pub fn has_zone(&self, zone: &str) -> bool { | ||
self.zones.contains(zone) | ||
} | ||
|
||
pub fn has_hash(&self, hash: &str) -> bool { | ||
self.hashes.contains(hash) | ||
} | ||
} |
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