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

Introduce SecretStore for Substrate binary #28

Merged
merged 8 commits into from
Mar 17, 2020
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"bin/substrate",
"bin/substrate-node",
"blockchain-service",
"ethereum-service",
Expand Down
3 changes: 3 additions & 0 deletions bin/substrate-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
jsonrpc-core = "14.0.3"
structopt = "0.3.8"
sc-basic-authorship = "0.8.0-alpha.3"
sc-cli = "0.8.0-alpha.3"
sc-client = "0.8.0-alpha.3"
sc-consensus-aura = "0.8.0-alpha.3"
sc-executor = "0.8.0-alpha.3"
sc-finality-grandpa = "0.8.0-alpha.3"
sc-rpc = "2.0.0-alpha.3"
sc-transaction-pool = "2.0.0-alpha.3"
sc-service = "0.8.0-alpha.3"
sp-consensus = "0.8.0-alpha.3"
Expand All @@ -20,6 +22,7 @@ sp-core = "2.0.0-alpha.3"
sp-finality-grandpa = "2.0.0-alpha.3"
sp-inherents = "2.0.0-alpha.3"
sp-runtime = "2.0.0-alpha.3"
substrate-frame-rpc-system = "2.0.0-alpha.3"
secretstore-runtime = { package = "parity-secretstore-substrate-runtime", path = "../../substrate-runtime/runtime" }

[build-dependencies]
Expand Down
10 changes: 8 additions & 2 deletions bin/substrate-node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ impl Alternative {
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
],
true,
),
Expand All @@ -97,10 +101,12 @@ impl Alternative {
}
}

fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
fn testnet_genesis(
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
_enable_println: bool) -> GenesisConfig {
_enable_println: bool,
) -> GenesisConfig {
GenesisConfig {
frame_system: Some(SystemConfig {
code: WASM_BINARY.to_vec(),
Expand Down
9 changes: 9 additions & 0 deletions bin/substrate-node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ macro_rules! new_full_start {
import_setup = Some((grandpa_block_import, grandpa_link));

Ok(import_queue)
})?
.with_rpc_extensions(|builder| -> Result<jsonrpc_core::IoHandler<sc_rpc::Metadata>, _> {
use substrate_frame_rpc_system::{FullSystem, SystemApi};

let mut io = jsonrpc_core::IoHandler::default();
io.extend_with(
SystemApi::to_delegate(FullSystem::new(builder.client().clone(), builder.pool()))
);
Ok(io)
})?;

(builder, import_setup, inherent_data_providers)
Expand Down
45 changes: 45 additions & 0 deletions bin/substrate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "parity-secretstore-substrate"
version = "1.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]

# utilitarian dependencies

ansi_term = "0.9"
clap = { version = "2.33", features = ["yaml"] }
codec = { package = "parity-scale-codec", version = "1.0" }
env_logger = "0.7"
futures = { version = "0.3", features = ["thread-pool"] }
hex = "0.4"
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee.git", features = ["ws"] }
log = "0.4"
parity-crypto = { version = "0.5", features = ["publickey"] }
parking_lot = "0.9"
serde = { version = "1.0", features = ["derive"] }
serde_with = "1.4"
serde_json = "1.0"
time = "0.1"
toml = "0.5"

# direct substrate references

frame-system = "2.0.0-alpha.3"
pallet-transaction-payment = "2.0.0-alpha.3"
sp-core = "2.0.0-alpha.3"
sp-runtime = "2.0.0-alpha.3"
sp-version = "2.0.0-alpha.3"

# internal secret store references

key-server = { package = "parity-secretstore-key-server", path = "../../key-server" }
primitives = { package = "parity-secretstore-primitives", path = "../../primitives" }
substrate-runtime = { package = "parity-secretstore-substrate-runtime", path = "../../substrate-runtime/runtime" }
substrate-service = { package = "parity-secretstore-substrate-service", path = "../../substrate-service" }
runtime-module = { package = "parity-secretstore-substrate-runtime-module", path = "../../substrate-runtime/module" }
runtime-primitives = { package = "parity-secretstore-substrate-runtime-primitives", path = "../../substrate-runtime/primitives" }

[dev-dependencies]
tempdir = "0.3"
28 changes: 28 additions & 0 deletions bin/substrate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Secret Store for Substrate

More docs will be added later...

## Quick start

```bash
#!/bin/bash
set -e

rm -rf db
rm -rf ssdb.1
rm -rf ssdb.2
rm -rf ssdb.3
rm -rf ssdb.4

cargo build --manifest-path=../secret-store/Cargo.toml -p parity-secretstore-substrate-node
cp ../secret-store/target/debug/parity-secretstore-substrate-node .
cargo build --manifest-path=../secret-store/Cargo.toml -p parity-secretstore-substrate
cp ../secret-store/target/debug/parity-secretstore-substrate .

RUST_LOG=sc_rpc=trace,txpool=trace,txqueue=trace unbuffer ./parity-secretstore-substrate-node --dev --base-path db 2>&1 | unbuffer -p gawk '{ print strftime("Node: [%Y-%m-%d %H:%M:%S]"), $0 }' | unbuffer -p tee ssnode.log&
sleep 10
RUST_LOG=secretstore=trace,secretstore_net=trace unbuffer ./parity-secretstore-substrate --self-secret=0101010101010101010101010101010101010101010101010101010101010101 --db-path=ssdb.1 --net-port=10000 --sub-signer=//Alice 2>&1 | unbuffer -p gawk '{ print strftime("Alice: [%Y-%m-%d %H:%M:%S]"), $0 }' | unbuffer -p tee ssalice.log&
RUST_LOG=secretstore=trace,secretstore_net=trace unbuffer ./parity-secretstore-substrate --self-secret=0202020202020202020202020202020202020202020202020202020202020202 --db-path=ssdb.2 --net-port=10001 --sub-signer=//Bob 2>&1 | unbuffer -p gawk '{ print strftime("Bob: [%Y-%m-%d %H:%M:%S]"), $0 }' | unbuffer -p tee ssbob.log&
RUST_LOG=secretstore=trace,secretstore_net=trace unbuffer ./parity-secretstore-substrate --self-secret=0303030303030303030303030303030303030303030303030303030303030303 --db-path=ssdb.3 --net-port=10002 --sub-signer=//Charlie 2>&1 | unbuffer -p gawk '{ print strftime("Charlie: [%Y-%m-%d %H:%M:%S]"), $0 }' | unbuffer -p tee sscharlie.log&
RUST_LOG=secretstore=trace,secretstore_net=trace unbuffer ./parity-secretstore-substrate --self-secret=0404040404040404040404040404040404040404040404040404040404040404 --db-path=ssdb.4 --net-port=10003 --sub-signer=//Dave 2>&1 | unbuffer -p gawk '{ print strftime("Dave: [%Y-%m-%d %H:%M:%S]"), $0 }' | unbuffer -p tee ssdave.log&
```
49 changes: 49 additions & 0 deletions bin/substrate/src/acl_storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
// This file is part of Parity Secret Store.

// Parity Secret Store is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity Secret Store is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity Secret Store. If not, see <http://www.gnu.org/licenses/>.

use codec::Encode;
use primitives::{
Address, ServerKeyId,
acl_storage::AclStorage,
error::Error,
};
use crate::substrate_client::{BlockRef, Client};

pub struct OnChainAclStorage {
client: Client,
}

impl OnChainAclStorage {
/// Crate new on-chain ACL storage.
pub fn new(client: Client) -> Self {
OnChainAclStorage {
client,
}
}
}

impl AclStorage for OnChainAclStorage {
fn check(&self, requester_address: Address, server_key_id: &ServerKeyId) -> Result<bool, Error> {
// we always check at best block - there's no need to use deprecated ACLs
futures::executor::block_on(async {
self.client.call_runtime_method(
BlockRef::LocalBest,
"SecretStoreAclApi_check",
(requester_address, server_key_id).encode(),
).await.map_err(|err| Error::Internal(format!("{:?}", err)))
})
}
}
Loading