Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slip10redo #1689

Merged
merged 34 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
57678e7
Adding chris's slip10 changes
wjuan-mob Mar 22, 2022
d4521be
mnemonics replacing slip10
wjuan-mob Mar 22, 2022
241d603
Merge branch 'mobilecoinfoundation:master' into slip10redo
wjuan-mob Mar 23, 2022
3109008
fix clippy
wjuan-mob Mar 23, 2022
1f06b83
Removing slip10 where inappropriate
wjuan-mob Mar 24, 2022
4a38e68
Merge branch 'slip10redo' of github.com:wjuan-mob/mobilecoin into sli…
wjuan-mob Mar 24, 2022
85374ca
Merge remote-tracking branch 'origin/master' into slip10redo
wjuan-mob Apr 7, 2022
b043b38
Addressing review comments
wjuan-mob Apr 8, 2022
ee10d22
Update mobilecoind/api/proto/mobilecoind_api.proto
wjuan-mob Apr 8, 2022
53eb864
Update util/keyfile/src/bin/main.rs
wjuan-mob Apr 8, 2022
cf7cb48
Updating conformance and local network tests to pass report id
wjuan-mob Apr 8, 2022
b4a28f6
linting
wjuan-mob Apr 8, 2022
f1cabb2
Merge remote-tracking branch 'shared/master' into slip10redo
wjuan-mob Apr 8, 2022
8fccb31
Changing fog report id to empty string in conformace and local networ…
wjuan-mob Apr 8, 2022
3e182b6
Adding back readme
wjuan-mob Apr 8, 2022
371ec6a
Escaping the empty string in fog conformance test
wjuan-mob Apr 8, 2022
9e02af8
Adding missing account index
wjuan-mob Apr 8, 2022
7ffd741
lint
wjuan-mob Apr 8, 2022
d515e31
Update fog/sample-paykit/proto/remote_wallet.proto
wjuan-mob Apr 22, 2022
0a77103
Update util/keyfile/src/mnemonic_acct.rs
wjuan-mob Apr 22, 2022
f15abce
Update util/keyfile/src/error.rs
wjuan-mob Apr 22, 2022
5a21c20
Merge branch 'master' into slip10redo
wjuan-mob Apr 22, 2022
6739823
Fixing prost
wjuan-mob Apr 22, 2022
034ba65
Update util/keyfile/src/bin/keygen_main.rs
wjuan-mob Apr 22, 2022
af6bd96
Update util/keyfile/src/bin/main.rs
wjuan-mob Apr 22, 2022
6890384
Update util/keyfile/src/bin/keygen_main.rs
wjuan-mob Apr 22, 2022
5724559
Update util/keyfile/src/bin/main.rs
wjuan-mob Apr 22, 2022
ab0f64d
removing structopt from merge
wjuan-mob Apr 22, 2022
8103ae0
Merge branch 'slip10redo' of github.com:wjuan-mob/mobilecoin into sli…
wjuan-mob Apr 22, 2022
543540a
clean up
wjuan-mob Apr 22, 2022
c3ed152
fixing previous
wjuan-mob Apr 22, 2022
473a090
addressing review comments
wjuan-mob Apr 25, 2022
6e89310
importing read and write directly instead of using prelude
wjuan-mob Apr 25, 2022
f227404
Resolving lint
wjuan-mob Apr 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions account-keys/slip10/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use zeroize::Zeroize;

/// An enumeration of errors which can occur while working with SLIP-0010 key
/// derivation
#[derive(Debug, Display, Eq, PartialEq)]
#[derive(Clone, Debug, Display, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum Error {
/// There was an error creating the account key: {0}
AccountKey(AccountKeyError),
Expand Down Expand Up @@ -665,11 +665,6 @@ mod test {
#[test]
fn mnemonic_into_account_key() {
for data in EN_MNEMONIC_STRINGS.iter() {
std::eprintln!(
"Generating for phrase {} at path m/44'/866'/{}'",
data.phrase,
data.account_index
);
let mnemonic = Mnemonic::from_phrase(data.phrase, Language::English)
.expect("Could not read test phrase into mnemonic");
let key = mnemonic.derive_slip10_key(data.account_index);
Expand Down
2 changes: 1 addition & 1 deletion account-keys/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use displaydoc::Display;
pub type Result<T> = StdResult<T, Error>;

/// Errors which can occur when a field isn't well formed.
#[derive(Debug, Display, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[derive(Clone, Debug, Display, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub enum Error {
/// The Fog Report URL is too long
ReportUrlLength,
Expand Down
16 changes: 5 additions & 11 deletions fog/distribution/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,18 @@ fn main() {

let config = Config::from_args();

// Read account root_entropies from disk
let src_accounts: Vec<AccountKey> = mc_util_keyfile::keygen::read_default_root_entropies(
// Read account keys from disk
let src_accounts: Vec<AccountKey> = mc_util_keyfile::keygen::read_default_mnemonics(
config.sample_data_dir.join(Path::new("keys")),
)
.expect("Could not read default root entropies from keys")
.iter()
.map(AccountKey::from)
.collect();
.expect("Could not read default mnemonics from keys");

let dest_accounts: Vec<AccountKey> = mc_util_keyfile::keygen::read_default_root_entropies(
let dest_accounts: Vec<AccountKey> = mc_util_keyfile::keygen::read_default_mnemonics(
config
.sample_data_dir
.join(Path::new(&config.fog_keys_subdir)),
)
.expect("Could not read fog keys")
.iter()
.map(AccountKey::from)
.collect();
.expect("Could not read fog keys");

// Open the ledger_db to process the bootstrapped ledger
log::info!(logger, "Loading ledger");
Expand Down
4 changes: 2 additions & 2 deletions fog/sample-paykit/proto/remote_wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ service RemoteWalletApi {
}

message FreshBalanceCheckRequest {
/// Root entropy for the account the new client will be using.
bytes root_entropy = 1;
/// Slip10 key for the account the new client will be using.
bytes slip10_key = 1;
jcape marked this conversation as resolved.
Show resolved Hide resolved

/// FOG URI (should have view and ledger servers accessible).
string fog_uri = 2;
Expand Down
4 changes: 1 addition & 3 deletions fog/sample-paykit/src/bin/balance_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
//! didn't have the expected value). See fog-conformance-test documentation for
//! more details.

use mc_account_keys::AccountKey;
use mc_common::logger::{create_root_logger, log};
use mc_fog_sample_paykit::ClientBuilder;
use mc_fog_uri::{FogLedgerUri, FogViewUri};
Expand Down Expand Up @@ -50,9 +49,8 @@ fn main() {
let config = Config::from_args();
let logger = create_root_logger();

let root_identity =
let account_key =
mc_util_keyfile::read_keyfile(config.keyfile).expect("Could not read private key file");
let account_key = AccountKey::from(&root_identity);

// Note: The balance check program is not supposed to submit anything to
// consensus or talk to consensus, so this is just a dummy value
Expand Down
19 changes: 12 additions & 7 deletions fog/sample-paykit/src/bin/sample_paykit_remote_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! the sample paykit.

use grpcio::{RpcContext, RpcStatus, UnarySink};
use mc_account_keys::{AccountKey, RootEntropy, RootIdentity};
use mc_account_keys::AccountKey;
use mc_common::logger::{create_root_logger, log, Logger};
use mc_fog_sample_paykit::{
empty::Empty,
Expand All @@ -21,9 +21,10 @@ use mc_transaction_core::{tokens::Mob, Token};
use mc_util_grpc::{
rpc_internal_error, rpc_invalid_arg_error, send_result, ConnectionUriGrpcioServer,
};
use mc_util_keyfile::Slip10IdentityJson;
use mc_util_uri::{ConsensusClientUri, Uri, UriScheme};
use std::{
convert::TryFrom,
convert::{TryFrom, TryInto},
str::FromStr,
sync::{Arc, Mutex},
thread::sleep,
Expand Down Expand Up @@ -77,12 +78,16 @@ impl RemoteWalletService {
&self,
request: FreshBalanceCheckRequest,
) -> Result<BalanceCheckResponse, RpcStatus> {
let root_entropy = RootEntropy::try_from(&request.root_entropy[..])
.map_err(|err| rpc_invalid_arg_error("root_entropy", err, &self.logger))?;

let root_identity = RootIdentity::from(&root_entropy);
let id = Slip10IdentityJson {
slip10_key: (&request.slip10_key[..])
.try_into()
.map_err(|err| rpc_invalid_arg_error("slip10 key", err, &self.logger))?,
..Default::default()
};

let account_key = AccountKey::from(&root_identity);
let account_key = AccountKey::try_from(&id).map_err(|err| {
rpc_invalid_arg_error("could not build account key", err, &self.logger)
})?;

// Note: The balance check program is not supposed to submit anything to
// consensus or talk to consensus, so this is just a dummy value
Expand Down
11 changes: 7 additions & 4 deletions fog/test-client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use serde::Serialize;
use std::{path::PathBuf, time::Duration};
use structopt::StructOpt;

// Hack to work around Vec special handling in structopt
#[allow(dead_code)]
type VecBytes = Vec<u8>;
wjuan-mob marked this conversation as resolved.
Show resolved Hide resolved

wjuan-mob marked this conversation as resolved.
Show resolved Hide resolved
/// StructOpt for test-client binary
///
/// Serialize is used to create a json summary
Expand Down Expand Up @@ -135,12 +139,11 @@ impl TestClientConfig {

// Load the key files
log::info!(logger, "Loading account keys from {:?}", key_dir);
mc_util_keyfile::keygen::read_default_root_entropies(&key_dir)
mc_util_keyfile::keygen::read_default_mnemonics(&key_dir)
.unwrap()
.iter()
.into_iter()
.take(self.num_clients)
.map(AccountKey::from)
.collect()
.collect::<_>()
}
}

Expand Down
13 changes: 5 additions & 8 deletions fog/test_infra/src/bin/add_test_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//! is returned.

use core::convert::TryFrom;
use mc_account_keys::{AccountKey, DEFAULT_SUBADDRESS_INDEX};
use mc_account_keys::DEFAULT_SUBADDRESS_INDEX;
use mc_common::logger::create_root_logger;
use mc_crypto_hashes::{Blake2b256, Digest};
use mc_crypto_keys::{Ed25519Pair, RistrettoPrivate, RistrettoPublic};
Expand Down Expand Up @@ -100,13 +100,10 @@ fn main() {
let fog_pubkey = RistrettoPublic::try_from(&config.fog_pubkey)
.expect("Could not parse fog_pubkey as Ristretto");

// Read user root entropy keys from disk
let root_entropies = mc_util_keyfile::keygen::read_default_root_entropies(config.keys)
.expect("Could not read root identity files");
assert_ne!(0, root_entropies.len());

// Create account keys from this
let account_keys: Vec<AccountKey> = root_entropies.iter().map(AccountKey::from).collect();
// Read account keys from disk
let account_keys = mc_util_keyfile::keygen::read_default_mnemonics(config.keys)
.expect("Could not read slip10 identity files");
assert_ne!(0, account_keys.len());

// Open the ledger db
let mut ledger = LedgerDB::open(&config.ledger).expect("Could not open ledger db");
Expand Down
3 changes: 1 addition & 2 deletions fog/view/load-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ fn main() {
let config = Config::from_args();
let logger = create_root_logger();

let root_identity =
let account_key =
mc_util_keyfile::read_keyfile(config.keyfile).expect("Could not read private key file");
let account_key = AccountKey::from(&root_identity);

let num_reqs = Arc::new(AtomicU64::new(0));
for _ in 0..config.num_workers {
Expand Down
9 changes: 8 additions & 1 deletion mobilecoind/api/proto/mobilecoind_api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ service MobilecoindAPI {
rpc GenerateRootEntropy (google.protobuf.Empty) returns (GenerateRootEntropyResponse) {}
rpc GenerateMnemonic (google.protobuf.Empty) returns (GenerateMnemonicResponse) {}
rpc GetAccountKeyFromRootEntropy (GetAccountKeyFromRootEntropyRequest) returns (GetAccountKeyResponse) {}
rpc GetAccountKeyFromSlip10 (GetAccountKeyFromSlip10Request) returns (GetAccountKeyResponse) {}
rpc GetAccountKeyFromMnemonic (GetAccountKeyFromMnemonicRequest) returns (GetAccountKeyResponse) {}
rpc GetPublicAddress (GetPublicAddressRequest) returns (GetPublicAddressResponse) {}

Expand Down Expand Up @@ -336,6 +337,12 @@ message GenerateMnemonicResponse {
message GetAccountKeyFromRootEntropyRequest {
bytes root_entropy = 1;
}

// Generate an AccountKey from a 32 byte slip10 value.
message GetAccountKeyFromSlip10Request {
bytes slip10_key = 1;
}
jcape marked this conversation as resolved.
Show resolved Hide resolved

// Generate an AccountKey from a mnemonic.
message GetAccountKeyFromMnemonicRequest {
string mnemonic = 1;
Expand Down Expand Up @@ -767,4 +774,4 @@ message SetDbPasswordRequest {
// Unlock a currently password-protected database.
message UnlockDbRequest {
bytes password = 1;
}
}
wjuan-mob marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 26 additions & 1 deletion mobilecoind/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
use bip39::{Language, Mnemonic, MnemonicType};
use grpcio::{EnvBuilder, RpcContext, RpcStatus, RpcStatusCode, ServerBuilder, UnarySink};
use mc_account_keys::{AccountKey, PublicAddress, RootIdentity, DEFAULT_SUBADDRESS_INDEX};
use mc_account_keys_slip10::Slip10KeyGenerator;
use mc_account_keys_slip10::{Slip10Key, Slip10KeyGenerator};
use mc_common::{
logger::{log, Logger},
HashMap,
Expand Down Expand Up @@ -394,6 +394,30 @@ impl<T: BlockchainConnection + UserTxConnection + 'static, FPR: FogPubkeyResolve
Ok(response)
}

fn get_account_key_from_slip10_impl(
&mut self,
request: mc_mobilecoind_api::GetAccountKeyFromSlip10Request,
) -> Result<mc_mobilecoind_api::GetAccountKeyResponse, RpcStatus> {
// Get the entropy.
if request.get_slip10_key().len() != 32 {
return Err(RpcStatus::with_message(
RpcStatusCode::INVALID_ARGUMENT,
"entropy".into(),
));
}

// Use slip10_key to construct AccountKey.
let mut slip10_key = [0u8; 32];
slip10_key.copy_from_slice(request.get_slip10_key());
let key = Slip10Key::from(slip10_key);
let account_key = AccountKey::from(key);

// Return response.
let mut response = mc_mobilecoind_api::GetAccountKeyResponse::new();
response.set_account_key((&account_key).into());
Ok(response)
}

fn get_account_key_from_mnemonic_impl(
&mut self,
request: mc_mobilecoind_api::GetAccountKeyFromMnemonicRequest,
Expand Down Expand Up @@ -1904,6 +1928,7 @@ build_api! {
generate_root_entropy Empty GenerateRootEntropyResponse generate_root_entropy_impl,
generate_mnemonic Empty GenerateMnemonicResponse generate_mnemonic_impl,
get_account_key_from_root_entropy GetAccountKeyFromRootEntropyRequest GetAccountKeyResponse get_account_key_from_root_entropy_impl,
get_account_key_from_slip10 GetAccountKeyFromSlip10Request GetAccountKeyResponse get_account_key_from_slip10_impl,
get_account_key_from_mnemonic GetAccountKeyFromMnemonicRequest GetAccountKeyResponse get_account_key_from_mnemonic_impl,
get_public_address GetPublicAddressRequest GetPublicAddressResponse get_public_address_impl,

Expand Down
4 changes: 2 additions & 2 deletions mobilecoind/strategies/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def connect(host, port):
def register_account(key_data, stub) -> AccountData:
# Generate an account key from this root entropy
resp = stub.GetAccountKeyFromRootEntropy(
mobilecoind_api_pb2.GetAccountKeyFromRootEntropyRequest(
root_entropy=bytes(key_data['root_entropy'])))
mobilecoind_api_pb2.GetAccountKeyFromSlip10Request(
slip10_key=bytes.fromhex(key_data['slip10_key'])))
account_key = resp.account_key

# Add this account to the wallet
Expand Down
2 changes: 1 addition & 1 deletion sgx/css-dump/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() {
let input = if config.input.is_some() {
std::fs::read(config.input.unwrap()).expect("Could not read input file")
} else {
// sigstruct structures are 1 x86_64 page
// sigstruct structures should be 1208 bytes
let mut bytes = vec![0u8; mem::size_of::<Signature>()];
io::stdin()
.read_exact(&mut bytes)
Expand Down
2 changes: 1 addition & 1 deletion tools/fog-local-network/fog_conformance_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def start(self):
with grpc.insecure_channel(self.remote_wallet_host_port) as channel:
stub = remote_wallet_pb2_grpc.RemoteWalletApiStub(channel)
response = self._retrying_grpc_request(stub.FreshBalanceCheck, remote_wallet_pb2.FreshBalanceCheckRequest(
root_entropy=bytes(key['root_entropy']),
slip10_key=bytes.fromhex(key['slip10_key']),
fog_uri=self.fog_url,
))

Expand Down
8 changes: 8 additions & 0 deletions util/from-random/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ pub trait FromRandom: Sized {
/// Using a mutable RNG, take it's output to securely initialize the object
fn from_random<R: CryptoRng + RngCore>(csprng: &mut R) -> Self;
}

impl FromRandom for [u8; 32] {
fn from_random<R: CryptoRng + RngCore>(csprng: &mut R) -> [u8; 32] {
let mut result = [0u8; 32];
wjuan-mob marked this conversation as resolved.
Show resolved Hide resolved
csprng.fill_bytes(&mut result);
result
}
}
8 changes: 7 additions & 1 deletion util/keyfile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,28 @@ path = "src/bin/read_pubfile.rs"

[dependencies]
mc-account-keys = { path = "../../account-keys" }
mc-account-keys-slip10 = { path = "../../account-keys/slip10" }
mc-api = { path = "../../api" }
mc-crypto-rand = { path = "../../crypto/rand" }
mc-util-from-random = { path = "../../util/from-random" }
mc-util-serial = { path = "../../util/serial", features = ["std"] }

base64 = "0.13"
displaydoc = "0.2"
hex = "0.4"
pem = "1.0"
prost = "0.9.0"
wjuan-mob marked this conversation as resolved.
Show resolved Hide resolved
rand = "0.8"
rand_core = "0.6.3"
rand_hc = "0.3"
serde = "1.0"
serde_json = "1.0"
structopt = "0.3"
tiny-bip39 = "0.8"
x509-signature = "0.5"

[dev-dependencies]
mc-crypto-x509-test-vectors = { path = "../../crypto/x509/test-vectors" }
mc-util-test-helper = { path = "../../util/test-helper" }

tempdir = "0.3"
tempfile = "3.2"
wjuan-mob marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions util/keyfile/src/backwards_compatibility.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"mnemonic":"exist profit best motion party reform discover garden mountain entire sing fire real owner common punch label rubber sunny gap invest void snack estate","account_index":0,"fog_report_url":null,"fog_report_id":null,"fog_authority_spki":null},{"mnemonic":"action sphere soft mercy month frown learn renew bottom pattern attend level chat neglect miracle cause decorate convince hand bread live execute grass palace","account_index":0,"fog_report_url":null,"fog_report_id":null,"fog_authority_spki":null},{"mnemonic":"file cupboard accuse solve dad clip diesel unveil burden eye renew slam bring nurse click zero shock cabin urge finger claw volcano found bag","account_index":0,"fog_report_url":null,"fog_report_id":null,"fog_authority_spki":null},{"mnemonic":"include library rigid pause panther deal style shuffle then dumb pumpkin pelican join coach flower situate slender exit figure jelly torch scissors dish begin","account_index":0,"fog_report_url":null,"fog_report_id":null,"fog_authority_spki":null},{"mnemonic":"typical shine grocery luggage lizard latin food warrior achieve leave season furnace seminar else verify toy result style captain cotton spare survey fame panther","account_index":0,"fog_report_url":null,"fog_report_id":null,"fog_authority_spki":null},{"mnemonic":"execute grant hazard aim true anxiety expect uncle muscle stairs around extend jelly column manage grit panda quiz assume modify error faith never broccoli","account_index":0,"fog_report_url":null,"fog_report_id":null,"fog_authority_spki":null},{"mnemonic":"music display finger thrive aspect genius obtain reason jar chimney someone brisk resemble pulp coast spawn border much focus autumn logic pave win liberty","account_index":0,"fog_report_url":null,"fog_report_id":null,"fog_authority_spki":null},{"mnemonic":"broccoli venture whale lizard antique title leader sick hedgehog skirt until happy this furnace admit siege man lawn toe enforce elder negative suggest treat","account_index":0,"fog_report_url":null,"fog_report_id":null,"fog_authority_spki":null},{"mnemonic":"buffalo strike film school celery embody cinnamon spot night uncover monitor useless uncle eager purpose brother essence lion vital doll cattle transfer dynamic turtle","account_index":0,"fog_report_url":null,"fog_report_id":null,"fog_authority_spki":null},{"mnemonic":"ethics wash coil hello never harsh one brand side chaos cause blood course orange write beach seat fat park enforce feed reward airport cement","account_index":0,"fog_report_url":null,"fog_report_id":null,"fog_authority_spki":null}]
wjuan-mob marked this conversation as resolved.
Show resolved Hide resolved
Loading