Changed domain encryption scheme.
This commit is contained in:
+13
-3
@@ -607,11 +607,21 @@ impl Chain {
|
|||||||
let class = String::from("domain");
|
let class = String::from("domain");
|
||||||
let data = statement.read::<String>(4).unwrap();
|
let data = statement.read::<String>(4).unwrap();
|
||||||
let pub_key = Bytes::from_bytes(&statement.read::<Vec<u8>>(5).unwrap());
|
let pub_key = Bytes::from_bytes(&statement.read::<Vec<u8>>(5).unwrap());
|
||||||
let transaction = Transaction { identity: identity.clone(), confirmation, class, data, pub_key };
|
let transaction = Transaction { identity: identity.clone(), confirmation: confirmation.clone(), class, data, pub_key };
|
||||||
//debug!("Found transaction for domain {}: {:?}", domain, &transaction);
|
//debug!("Found transaction for domain {}: {:?}", domain, &transaction);
|
||||||
if let Some(data) = transaction.get_domain_data() {
|
if let Some(data) = transaction.get_domain_data() {
|
||||||
let b = self.get_block(index - 1).unwrap();
|
let mut domain = keystore.decrypt(data.domain.as_slice(), &confirmation.as_slice()[..12]);
|
||||||
let domain = keystore.decrypt(data.domain.as_slice(), &b.hash.as_slice()[..12]);
|
if domain.is_empty() {
|
||||||
|
// Legacy encryption scheme
|
||||||
|
for i in 1..=10 {
|
||||||
|
let b = self.get_block(index - i).unwrap();
|
||||||
|
domain = keystore.decrypt(data.domain.as_slice(), &b.hash.as_slice()[..12]);
|
||||||
|
if !domain.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut domain = String::from_utf8(domain.to_vec()).unwrap();
|
let mut domain = String::from_utf8(domain.to_vec()).unwrap();
|
||||||
if domain.is_empty() {
|
if domain.is_empty() {
|
||||||
domain = String::from("unknown");
|
domain = String::from("unknown");
|
||||||
|
|||||||
+17
-9
@@ -25,6 +25,7 @@ use alfis::miner::Miner;
|
|||||||
use Cmd::*;
|
use Cmd::*;
|
||||||
|
|
||||||
use self::web_view::{Handle, WebView};
|
use self::web_view::{Handle, WebView};
|
||||||
|
use alfis::blockchain::hash_utils::hash_identity;
|
||||||
|
|
||||||
pub fn run_interface(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>) {
|
pub fn run_interface(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>) {
|
||||||
let file_content = include_str!("webview/index.html");
|
let file_content = include_str!("webview/index.html");
|
||||||
@@ -357,7 +358,7 @@ fn action_create_domain(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>,
|
|||||||
}
|
}
|
||||||
let keystore = context.get_keystore().unwrap();
|
let keystore = context.get_keystore().unwrap();
|
||||||
let pub_key = keystore.get_public();
|
let pub_key = keystore.get_public();
|
||||||
let mut data = match serde_json::from_str::<DomainData>(&data) {
|
let data = match serde_json::from_str::<DomainData>(&data) {
|
||||||
Ok(data) => { data }
|
Ok(data) => { data }
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
show_warning(web_view, "Something wrong with domain data. I cannot mine it.");
|
show_warning(web_view, "Something wrong with domain data. I cannot mine it.");
|
||||||
@@ -383,12 +384,8 @@ fn action_create_domain(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>,
|
|||||||
MineResult::Fine => {
|
MineResult::Fine => {
|
||||||
let zone = get_domain_zone(&name);
|
let zone = get_domain_zone(&name);
|
||||||
let difficulty = context.chain.get_zone_difficulty(&zone);
|
let difficulty = context.chain.get_zone_difficulty(&zone);
|
||||||
let last_block = context.chain.last_block().unwrap();
|
|
||||||
let encrypted = keystore.encrypt(name.as_bytes(), &last_block.hash.as_slice()[..12]);
|
|
||||||
data.domain = encrypted;
|
|
||||||
let data = serde_json::to_string(&data).unwrap();
|
|
||||||
std::mem::drop(context);
|
std::mem::drop(context);
|
||||||
create_domain(c, miner, CLASS_DOMAIN, &name, &data, difficulty, &keystore);
|
create_domain(c, miner, CLASS_DOMAIN, &name, data, difficulty, &keystore);
|
||||||
let _ = web_view.eval("domainMiningStarted();");
|
let _ = web_view.eval("domainMiningStarted();");
|
||||||
event_info(web_view, &format!("Mining of domain \\'{}\\' has started", &name));
|
event_info(web_view, &format!("Mining of domain \\'{}\\' has started", &name));
|
||||||
}
|
}
|
||||||
@@ -451,12 +448,12 @@ fn action_create_zone(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>, we
|
|||||||
let data = serde_json::to_string(&data).unwrap();
|
let data = serde_json::to_string(&data).unwrap();
|
||||||
match transaction {
|
match transaction {
|
||||||
None => {
|
None => {
|
||||||
create_domain(Arc::clone(&context), miner.clone(), CLASS_ZONE, &name, &data, ZONE_DIFFICULTY, &keystore);
|
create_zone(Arc::clone(&context), miner.clone(), CLASS_ZONE, &name, &data, ZONE_DIFFICULTY, &keystore);
|
||||||
event_info(web_view, &format!("Mining of zone \\'{}\\' has started", &name));
|
event_info(web_view, &format!("Mining of zone \\'{}\\' has started", &name));
|
||||||
}
|
}
|
||||||
Some(transaction) => {
|
Some(transaction) => {
|
||||||
if transaction.pub_key == keystore.get_public() {
|
if transaction.pub_key == keystore.get_public() {
|
||||||
create_domain(Arc::clone(&context), miner.clone(), CLASS_ZONE, &name, &data, ZONE_DIFFICULTY, &keystore);
|
create_zone(Arc::clone(&context), miner.clone(), CLASS_ZONE, &name, &data, ZONE_DIFFICULTY, &keystore);
|
||||||
event_info(web_view, &format!("Mining of zone \\'{}\\' has started", &name));
|
event_info(web_view, &format!("Mining of zone \\'{}\\' has started", &name));
|
||||||
} else {
|
} else {
|
||||||
warn!("Tried to mine not owned domain!");
|
warn!("Tried to mine not owned domain!");
|
||||||
@@ -544,7 +541,7 @@ fn format_event_now(kind: &str, message: &str) -> String {
|
|||||||
format!("addEvent('{}', '{}', '{}');", kind, time.format("%d.%m.%y %X"), message)
|
format!("addEvent('{}', '{}', '{}');", kind, time.format("%d.%m.%y %X"), message)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_domain(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>, class: &str, name: &str, data: &str, difficulty: u32, keystore: &Keystore) {
|
fn create_zone(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>, class: &str, name: &str, data: &str, difficulty: u32, keystore: &Keystore) {
|
||||||
let name = name.to_owned();
|
let name = name.to_owned();
|
||||||
info!("Generating domain or zone {}", &name);
|
info!("Generating domain or zone {}", &name);
|
||||||
if context.lock().unwrap().x_zones.has_zone(&name) {
|
if context.lock().unwrap().x_zones.has_zone(&name) {
|
||||||
@@ -556,6 +553,17 @@ fn create_domain(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>, class:
|
|||||||
miner.lock().unwrap().add_block(block, keystore.clone());
|
miner.lock().unwrap().add_block(block, keystore.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_domain(_context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>, class: &str, name: &str, mut data: DomainData, difficulty: u32, keystore: &Keystore) {
|
||||||
|
let name = name.to_owned();
|
||||||
|
let confirmation = hash_identity(&name, Some(&keystore.get_public()));
|
||||||
|
data.domain = keystore.encrypt(name.as_bytes(), &confirmation.as_slice()[..12]);
|
||||||
|
|
||||||
|
let data = serde_json::to_string(&data).unwrap();
|
||||||
|
let transaction = Transaction::from_str(name, class.to_owned(), data, keystore.get_public().clone());
|
||||||
|
let block = Block::new(Some(transaction), keystore.get_public(), Bytes::default(), difficulty);
|
||||||
|
miner.lock().unwrap().add_block(block, keystore.clone());
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(tag = "cmd", rename_all = "camelCase")]
|
#[serde(tag = "cmd", rename_all = "camelCase")]
|
||||||
pub enum Cmd {
|
pub enum Cmd {
|
||||||
|
|||||||
Reference in New Issue
Block a user