Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions Cargo.lock

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

13 changes: 13 additions & 0 deletions crates/devutil-auth-ticket/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "devutil-auth-ticket"
version = "0.1.0"
edition = "2018"
authors = ["Humanode Team <core@humanode.io>"]
publish = false

[dependencies]
primitives-auth-ticket = { version = "0.1", path = "../primitives-auth-ticket" }
robonode-crypto = { version = "0.1", path = "../robonode-crypto" }

anyhow = "1"
hex = "0.4"
45 changes: 45 additions & 0 deletions crates/devutil-auth-ticket/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use std::convert::TryFrom;

pub use hex::{decode, encode};
pub use primitives_auth_ticket::{AuthTicket, OpaqueAuthTicket};

use robonode_crypto::{ed25519_dalek::Signer, Keypair};

pub struct Input {
pub robonode_keypair: Vec<u8>,
pub auth_ticket: AuthTicket,
}

pub struct Output {
pub auth_ticket: Vec<u8>,
pub robonode_signature: Vec<u8>,
pub robonode_public_key: Vec<u8>,
}

pub fn make(input: Input) -> Result<Output, anyhow::Error> {
let Input {
auth_ticket,
robonode_keypair,
} = input;

let robonode_keypair = Keypair::from_bytes(&robonode_keypair)?;

let opaque_auth_ticket = OpaqueAuthTicket::from(&auth_ticket);

let robonode_signature = robonode_keypair
.sign(opaque_auth_ticket.as_ref())
.to_bytes();

assert!(robonode_keypair
.verify(
opaque_auth_ticket.as_ref(),
&robonode_crypto::Signature::try_from(&robonode_signature[..]).unwrap()
)
.is_ok());

Ok(Output {
auth_ticket: opaque_auth_ticket.into(),
robonode_signature: robonode_signature.into(),
robonode_public_key: robonode_keypair.public.as_bytes()[..].into(),
})
}
33 changes: 33 additions & 0 deletions crates/devutil-auth-ticket/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use devutil_auth_ticket::*;

fn read_hex_env(key: &'static str) -> Vec<u8> {
let val = std::env::var(key).unwrap();
decode(val).unwrap()
}

fn main() {
let robonode_keypair = read_hex_env("ROBONODE_KEYPAIR");
let public_key = read_hex_env("AUTH_TICKET_PUBLIC_KEY");
let authentication_nonce = read_hex_env("AUTH_TICKET_AUTHENTICATION_NONCE");

let auth_ticket = AuthTicket {
public_key,
authentication_nonce,
};

let output = make(Input {
robonode_keypair,
auth_ticket,
})
.unwrap();

print!(
"{}\n{}\n{}\n\n{:?}\n{:?}\n{:?}\n",
encode(output.auth_ticket.clone()),
encode(output.robonode_signature.clone()),
encode(output.robonode_public_key.clone()),
output.auth_ticket,
output.robonode_signature,
output.robonode_public_key,
);
}
1 change: 1 addition & 0 deletions crates/humanode-peer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ publish = false
bioauth-flow = { version = "0.1", path = "../bioauth-flow" }
humanode-rpc = { version = "0.1", path = "../humanode-rpc" }
humanode-runtime = { version = "0.1", path = "../humanode-runtime" }
pallet-bioauth = { version = "0.1", path = "../pallet-bioauth" }
robonode-client = { version = "0.1", path = "../robonode-client" }

async-trait = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/humanode-peer/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
WASM_BINARY.ok_or_else(|| "Development wasm binary not available".to_string())?;

let robonode_public_key = RobonodePublicKeyWrapper::from_bytes(
&hex!("d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a")[..],
&hex!("5dde03934419252d13336e5a5881f5b1ef9ea47084538eb229f86349e7f394ab")[..],
)
.map_err(|err| format!("{:?}", err))?;

Expand Down
79 changes: 51 additions & 28 deletions crates/humanode-peer/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
client: Arc::clone(&client),
keystore: keystore_container.sync_keystore(),
task_manager: &mut task_manager,
transaction_pool,
transaction_pool: Arc::clone(&transaction_pool),
rpc_extensions_builder,
on_demand: None,
remote_blockchain: None,
Expand All @@ -135,7 +135,7 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
slot_duration,
client: Arc::clone(&client),
select_chain,
block_import: client,
block_import: Arc::clone(&client),
proposer_factory,
create_inherent_data_providers: move |_, ()| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
Expand Down Expand Up @@ -179,41 +179,64 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
let webapp_qrcode =
crate::qrcode::WebApp::new(&webapp_url, &rpc_url).map_err(ServiceError::Other)?;

let bioauth_flow_future = Box::pin(async move {
info!("bioauth flow starting up");
let should_enroll = std::env::var("ENROLL").unwrap_or_default() == "true";
if should_enroll {
info!("bioauth flow - enrolling in progress");
let bioauth_flow_future = {
let client = Arc::clone(&client);
let transaction_pool = Arc::clone(&transaction_pool);
Box::pin(async move {
info!("bioauth flow starting up");
let should_enroll = std::env::var("ENROLL").unwrap_or_default() == "true";
if should_enroll {
info!("bioauth flow - enrolling in progress");

webapp_qrcode.print();
webapp_qrcode.print();

flow.enroll(crate::validator_key::FakeTodo("TODO"))
.await
.expect("enroll failed");
flow.enroll(crate::validator_key::FakeTodo("TODO"))
.await
.expect("enroll failed");

info!("bioauth flow - enrolling complete");
}
info!("bioauth flow - enrolling complete");
}

info!("bioauth flow - authentication in progress");
info!("bioauth flow - authentication in progress");

webapp_qrcode.print();
webapp_qrcode.print();

let authenticate_response = loop {
let result = flow
.authenticate(crate::validator_key::FakeTodo("TODO"))
.await;
match result {
Ok(v) => break v,
Err(error) => {
error!(message = "bioauth flow - authentication failure", ?error);
}
let authenticate_response = loop {
let result = flow
.authenticate(crate::validator_key::FakeTodo("TODO"))
.await;
match result {
Ok(v) => break v,
Err(error) => {
error!(message = "bioauth flow - authentication failure", ?error);
}
};
};
};

info!("bioauth flow - authentication complete");
info!("bioauth flow - authentication complete");

info!(message = "We've obtained an auth ticket", auth_ticket = ?authenticate_response.auth_ticket);
});
info!(message = "We've obtained an auth ticket", auth_ticket = ?authenticate_response.auth_ticket);

let authenticate = pallet_bioauth::Authenticate {
ticket: authenticate_response.auth_ticket.into(),
ticket_signature: authenticate_response.auth_ticket_signature.into(),
};
let call = pallet_bioauth::Call::authenticate(authenticate);

let ext = humanode_runtime::UncheckedExtrinsic::new_unsigned(call.into());

let at = client.chain_info().best_hash;
transaction_pool
.pool()
.submit_and_watch(
&sp_runtime::generic::BlockId::Hash(at),
sp_runtime::transaction_validity::TransactionSource::Local,
ext.into(),
)
.await
.unwrap();
})
};

task_manager
.spawn_handle()
Expand Down
2 changes: 1 addition & 1 deletion crates/humanode-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ construct_runtime!(
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>},
PalletBioauth: pallet_bioauth::{Pallet, Config<T>, Call, Storage, Event<T>},
PalletBioauth: pallet_bioauth::{Pallet, Config<T>, Call, Storage, Event<T>, ValidateUnsigned},
}
);

Expand Down
Loading