2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2017-02-20 16:13:21 +01:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2017-02-20 16:13:21 +01:00
|
|
|
// 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.
|
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
2017-02-20 16:13:21 +01:00
|
|
|
// 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
|
2019-01-07 11:33:07 +01:00
|
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2017-02-20 16:13:21 +01:00
|
|
|
|
2017-04-03 11:13:51 +02:00
|
|
|
extern crate byteorder;
|
2019-08-15 17:59:22 +02:00
|
|
|
extern crate client_traits;
|
2019-01-04 14:05:46 +01:00
|
|
|
extern crate common_types;
|
2018-02-09 09:32:06 +01:00
|
|
|
extern crate ethabi;
|
|
|
|
extern crate ethcore;
|
2019-01-17 16:43:08 +01:00
|
|
|
extern crate ethcore_call_contract as call_contract;
|
2018-04-10 12:13:49 +02:00
|
|
|
extern crate ethcore_sync as sync;
|
2018-02-09 09:32:06 +01:00
|
|
|
extern crate ethereum_types;
|
|
|
|
extern crate ethkey;
|
2017-02-20 16:13:21 +01:00
|
|
|
extern crate hyper;
|
2018-02-09 09:32:06 +01:00
|
|
|
extern crate keccak_hash as hash;
|
|
|
|
extern crate kvdb;
|
2019-01-04 14:05:46 +01:00
|
|
|
extern crate parity_bytes as bytes;
|
|
|
|
extern crate parity_crypto as crypto;
|
|
|
|
extern crate parity_runtime;
|
2017-02-20 16:13:21 +01:00
|
|
|
extern crate parking_lot;
|
2019-10-02 10:25:51 +02:00
|
|
|
extern crate percent_encoding;
|
2017-07-06 11:26:14 +02:00
|
|
|
extern crate rustc_hex;
|
2017-04-03 11:13:51 +02:00
|
|
|
extern crate serde;
|
|
|
|
extern crate serde_json;
|
2017-10-02 15:27:31 +02:00
|
|
|
extern crate tiny_keccak;
|
2018-04-10 19:25:27 +02:00
|
|
|
extern crate tokio;
|
2018-02-09 09:32:06 +01:00
|
|
|
extern crate tokio_io;
|
|
|
|
extern crate tokio_service;
|
2017-02-20 16:13:21 +01:00
|
|
|
extern crate url;
|
2019-04-20 07:31:37 +02:00
|
|
|
extern crate jsonrpc_server_utils;
|
2017-02-20 16:13:21 +01:00
|
|
|
|
2018-02-09 09:32:06 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate ethabi_derive;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate ethabi_contract;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate futures;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2017-02-20 16:13:21 +01:00
|
|
|
|
2019-01-08 15:07:20 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate env_logger;
|
2018-04-13 21:14:53 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate kvdb_rocksdb;
|
|
|
|
|
2019-02-07 14:34:24 +01:00
|
|
|
#[cfg(feature = "accounts")]
|
|
|
|
extern crate ethcore_accounts as accounts;
|
|
|
|
|
2017-03-13 12:54:56 +01:00
|
|
|
mod key_server_cluster;
|
2017-02-20 16:13:21 +01:00
|
|
|
mod types;
|
2018-04-06 12:03:13 +02:00
|
|
|
mod helpers;
|
2017-02-20 16:13:21 +01:00
|
|
|
|
2017-10-16 17:12:02 +02:00
|
|
|
mod traits;
|
2017-02-20 16:13:21 +01:00
|
|
|
mod acl_storage;
|
|
|
|
mod key_server;
|
|
|
|
mod key_storage;
|
2017-04-03 11:13:51 +02:00
|
|
|
mod serialization;
|
2017-07-19 10:35:17 +02:00
|
|
|
mod key_server_set;
|
2017-07-25 08:24:54 +02:00
|
|
|
mod node_key_pair;
|
2017-11-14 12:26:31 +01:00
|
|
|
mod listener;
|
2017-12-20 14:02:21 +01:00
|
|
|
mod trusted_client;
|
2017-02-20 16:13:21 +01:00
|
|
|
|
2017-04-03 17:46:51 +02:00
|
|
|
use std::sync::Arc;
|
2018-04-13 21:14:53 +02:00
|
|
|
use kvdb::KeyValueDB;
|
2017-04-03 17:46:51 +02:00
|
|
|
use ethcore::client::Client;
|
2018-04-09 16:38:59 +02:00
|
|
|
use ethcore::miner::Miner;
|
2018-04-10 12:13:49 +02:00
|
|
|
use sync::SyncProvider;
|
2018-11-25 18:36:43 +01:00
|
|
|
use parity_runtime::Executor;
|
2017-04-03 17:46:51 +02:00
|
|
|
|
2018-05-01 15:02:14 +02:00
|
|
|
pub use types::{ServerKeyId, EncryptedDocumentKey, RequestSignature, Public,
|
2017-11-24 10:33:33 +01:00
|
|
|
Error, NodeAddress, ContractAddress, ServiceConfiguration, ClusterConfiguration};
|
2017-07-25 08:24:54 +02:00
|
|
|
pub use traits::{NodeKeyPair, KeyServer};
|
2019-02-07 14:34:24 +01:00
|
|
|
pub use self::node_key_pair::PlainNodeKeyPair;
|
|
|
|
#[cfg(feature = "accounts")]
|
|
|
|
pub use self::node_key_pair::KeyStoreNodeKeyPair;
|
2017-02-20 16:13:21 +01:00
|
|
|
|
|
|
|
/// Start new key server instance
|
2018-11-25 18:36:43 +01:00
|
|
|
pub fn start(client: Arc<Client>, sync: Arc<SyncProvider>, miner: Arc<Miner>, self_key_pair: Arc<NodeKeyPair>, mut config: ServiceConfiguration,
|
|
|
|
db: Arc<KeyValueDB>, executor: Executor) -> Result<Box<KeyServer>, Error>
|
|
|
|
{
|
2018-04-09 16:38:59 +02:00
|
|
|
let trusted_client = trusted_client::TrustedClient::new(self_key_pair.clone(), client.clone(), sync, miner);
|
2018-06-14 09:01:52 +02:00
|
|
|
let acl_storage: Arc<acl_storage::AclStorage> = match config.acl_check_contract_address.take() {
|
|
|
|
Some(acl_check_contract_address) => acl_storage::OnChainAclStorage::new(trusted_client.clone(), acl_check_contract_address)?,
|
|
|
|
None => Arc::new(acl_storage::DummyAclStorage::default()),
|
|
|
|
};
|
2018-01-10 11:33:45 +01:00
|
|
|
|
2018-06-14 09:01:52 +02:00
|
|
|
let key_server_set = key_server_set::OnChainKeyServerSet::new(trusted_client.clone(), config.cluster_config.key_server_set_contract_address.take(),
|
|
|
|
self_key_pair.clone(), config.cluster_config.auto_migrate_enabled, config.cluster_config.nodes.clone())?;
|
2018-04-13 21:14:53 +02:00
|
|
|
let key_storage = Arc::new(key_storage::PersistentKeyStorage::new(db)?);
|
2018-11-25 18:36:43 +01:00
|
|
|
let key_server = Arc::new(key_server::KeyServerImpl::new(&config.cluster_config, key_server_set.clone(), self_key_pair.clone(),
|
|
|
|
acl_storage.clone(), key_storage.clone(), executor.clone())?);
|
2017-11-22 08:05:14 +01:00
|
|
|
let cluster = key_server.cluster();
|
2018-04-03 16:54:34 +02:00
|
|
|
let key_server: Arc<KeyServer> = key_server;
|
2017-11-24 10:33:33 +01:00
|
|
|
|
2018-04-03 16:54:34 +02:00
|
|
|
// prepare HTTP listener
|
2017-11-14 12:26:31 +01:00
|
|
|
let http_listener = match config.listener_address {
|
2019-04-20 07:31:37 +02:00
|
|
|
Some(listener_address) => Some(listener::http_listener::KeyServerHttpListener::start(listener_address, config.cors, Arc::downgrade(&key_server), executor)?),
|
2017-11-14 12:26:31 +01:00
|
|
|
None => None,
|
|
|
|
};
|
2018-04-03 16:54:34 +02:00
|
|
|
|
|
|
|
// prepare service contract listeners
|
|
|
|
let create_service_contract = |address, name, api_mask|
|
|
|
|
Arc::new(listener::service_contract::OnChainServiceContract::new(
|
|
|
|
api_mask,
|
|
|
|
trusted_client.clone(),
|
|
|
|
name,
|
|
|
|
address,
|
|
|
|
self_key_pair.clone()));
|
|
|
|
|
|
|
|
let mut contracts: Vec<Arc<listener::service_contract::ServiceContract>> = Vec::new();
|
|
|
|
config.service_contract_address.map(|address|
|
|
|
|
create_service_contract(address,
|
|
|
|
listener::service_contract::SERVICE_CONTRACT_REGISTRY_NAME.to_owned(),
|
|
|
|
listener::ApiMask::all()))
|
|
|
|
.map(|l| contracts.push(l));
|
|
|
|
config.service_contract_srv_gen_address.map(|address|
|
|
|
|
create_service_contract(address,
|
|
|
|
listener::service_contract::SRV_KEY_GEN_SERVICE_CONTRACT_REGISTRY_NAME.to_owned(),
|
|
|
|
listener::ApiMask { server_key_generation_requests: true, ..Default::default() }))
|
|
|
|
.map(|l| contracts.push(l));
|
|
|
|
config.service_contract_srv_retr_address.map(|address|
|
|
|
|
create_service_contract(address,
|
|
|
|
listener::service_contract::SRV_KEY_RETR_SERVICE_CONTRACT_REGISTRY_NAME.to_owned(),
|
|
|
|
listener::ApiMask { server_key_retrieval_requests: true, ..Default::default() }))
|
|
|
|
.map(|l| contracts.push(l));
|
|
|
|
config.service_contract_doc_store_address.map(|address|
|
|
|
|
create_service_contract(address,
|
|
|
|
listener::service_contract::DOC_KEY_STORE_SERVICE_CONTRACT_REGISTRY_NAME.to_owned(),
|
|
|
|
listener::ApiMask { document_key_store_requests: true, ..Default::default() }))
|
|
|
|
.map(|l| contracts.push(l));
|
|
|
|
config.service_contract_doc_sretr_address.map(|address|
|
|
|
|
create_service_contract(address,
|
|
|
|
listener::service_contract::DOC_KEY_SRETR_SERVICE_CONTRACT_REGISTRY_NAME.to_owned(),
|
|
|
|
listener::ApiMask { document_key_shadow_retrieval_requests: true, ..Default::default() }))
|
|
|
|
.map(|l| contracts.push(l));
|
|
|
|
|
|
|
|
let contract: Option<Arc<listener::service_contract::ServiceContract>> = match contracts.len() {
|
|
|
|
0 => None,
|
|
|
|
1 => Some(contracts.pop().expect("contract.len() is 1; qed")),
|
|
|
|
_ => Some(Arc::new(listener::service_contract_aggregate::OnChainServiceContractAggregate::new(contracts))),
|
|
|
|
};
|
|
|
|
|
|
|
|
let contract_listener = match contract {
|
|
|
|
Some(contract) => Some({
|
|
|
|
let listener = listener::service_contract_listener::ServiceContractListener::new(
|
|
|
|
listener::service_contract_listener::ServiceContractListenerParams {
|
|
|
|
contract: contract,
|
|
|
|
self_key_pair: self_key_pair.clone(),
|
|
|
|
key_server_set: key_server_set,
|
|
|
|
acl_storage: acl_storage,
|
|
|
|
cluster: cluster,
|
|
|
|
key_storage: key_storage,
|
|
|
|
}
|
|
|
|
)?;
|
|
|
|
client.add_notify(listener.clone());
|
|
|
|
listener
|
|
|
|
}),
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
2017-11-24 10:33:33 +01:00
|
|
|
Ok(Box::new(listener::Listener::new(key_server, http_listener, contract_listener)))
|
2017-02-20 16:13:21 +01:00
|
|
|
}
|