Updated Crypto to use MTP-Crypto
This commit is contained in:
parent
f252724a43
commit
5625c5db5f
10 changed files with 558 additions and 453 deletions
|
|
@ -1,16 +1,13 @@
|
|||
use base64::{Engine as _, engine::general_purpose::STANDARD};
|
||||
use hex;
|
||||
use iota_logger::{PrintType, log, log_cv, log_t};
|
||||
use iota_state::{RELOAD, SHUTDOWN};
|
||||
use iota_storage::users::user_manager::{add_user, save_users};
|
||||
use iota_storage::users::user_profile::UserProfile;
|
||||
use iota_util::crypto_helper::public_key_to_base64;
|
||||
use iota_util::crypto_helper::{self, hex_hash, public_key_bundle_to_base64};
|
||||
use iota_util::file_util::save_file;
|
||||
use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue};
|
||||
use rand_core::{OsRng, RngCore};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::time::Duration;
|
||||
use x448::{PublicKey, Secret};
|
||||
|
||||
use crate::omikron_connection::OMIKRON_CONNECTION;
|
||||
|
||||
|
|
@ -41,16 +38,11 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
|
|||
return (None, None);
|
||||
}
|
||||
};
|
||||
let mut buffer = [0u8; 56];
|
||||
let mut rng = OsRng;
|
||||
rng.fill_bytes(&mut buffer);
|
||||
let private_key = Secret::from_bytes(&buffer).unwrap();
|
||||
let public_key = PublicKey::from(&private_key);
|
||||
let keyring = crypto_helper::generate_keyring();
|
||||
let pub_key_bundle = keyring.public_key_bundle();
|
||||
let keyring_b64 = crypto_helper::keyring_to_base64(&keyring);
|
||||
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(&STANDARD.encode(&private_key.as_bytes()).as_bytes());
|
||||
let result = hasher.finalize();
|
||||
let private_key_hash = hex::encode(result);
|
||||
let private_key_hash = hex_hash(&keyring_b64);
|
||||
|
||||
let mut bytes = [0u8; 192];
|
||||
OsRng.fill_bytes(&mut bytes);
|
||||
|
|
@ -60,7 +52,7 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
|
|||
user_id as i64,
|
||||
username.to_string(),
|
||||
None,
|
||||
STANDARD.encode(&public_key.as_bytes()),
|
||||
public_key_bundle_to_base64(&pub_key_bundle),
|
||||
private_key_hash,
|
||||
reset_token.clone(),
|
||||
);
|
||||
|
|
@ -70,7 +62,7 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
|
|||
.add_typed_default(DataType::Username, DataValue::Str(username.to_string()))
|
||||
.add_typed_default(
|
||||
DataType::PublicKey,
|
||||
DataValue::Str(public_key_to_base64(&public_key)),
|
||||
DataValue::Str(public_key_bundle_to_base64(&pub_key_bundle)),
|
||||
)
|
||||
.add_typed_default(DataType::IotaId, DataValue::SignedNumber(user_id as i128))
|
||||
.add_typed_default(DataType::ResetToken, DataValue::Str(reset_token));
|
||||
|
|
@ -94,13 +86,13 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
|
|||
save_file(
|
||||
"",
|
||||
&format!("{}.tu", username),
|
||||
&format!("{}::{}", user_id, STANDARD.encode(&private_key.as_bytes())),
|
||||
&format!("{}::{}", user_id, keyring_b64),
|
||||
);
|
||||
|
||||
add_user(user_profile.clone());
|
||||
save_users();
|
||||
(
|
||||
Some(user_profile),
|
||||
Some(STANDARD.encode(&private_key.as_bytes())),
|
||||
Some(keyring_b64),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue