Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Exposing all RPCs over dapps port as CLI option (#4346)
Browse files Browse the repository at this point in the history
* Exposing all RPC over dapps port as CLI option

* Fix test.
  • Loading branch information
tomusdrw authored and gavofyork committed Jan 30, 2017
1 parent 089da2a commit 47e1c5e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ usage! {
or |c: &Config| otry!(c.dapps).user.clone().map(Some),
flag_dapps_pass: Option<String> = None,
or |c: &Config| otry!(c.dapps).pass.clone().map(Some),
flag_dapps_apis_all: bool = false, or |_| None,

// -- Sealing/Mining Options
flag_author: Option<String> = None,
Expand Down Expand Up @@ -629,6 +630,7 @@ mod tests {
flag_dapps_path: "$HOME/.parity/dapps".into(),
flag_dapps_user: Some("test_user".into()),
flag_dapps_pass: Some("test_pass".into()),
flag_dapps_apis_all: false,

// -- Sealing/Mining Options
flag_author: Some("0xdeadbeefcafe0000000000000000000000000001".into()),
Expand Down
3 changes: 3 additions & 0 deletions parity/cli/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ API and Console Options:
conjunction with --dapps-user. (default: {flag_dapps_pass:?})
--dapps-path PATH Specify directory where dapps should be installed.
(default: {flag_dapps_path})
--dapps-apis-all Expose all possible RPC APIs on Dapps port.
WARNING: INSECURE. Used only for development.
(default: {flag_dapps_apis_all})

Sealing/Mining Options:
--author ADDRESS Specify the block author (aka "coinbase") address
Expand Down
1 change: 1 addition & 0 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ impl Configuration {
} else {
vec![]
},
all_apis: self.args.flag_dapps_apis_all,
}
}

Expand Down
30 changes: 21 additions & 9 deletions parity/dapps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

use std::path::PathBuf;
use std::sync::Arc;
use io::PanicHandler;
use rpc_apis;

use dir::default_data_path;
use ethcore::client::Client;
use ethsync::SyncProvider;
use hash_fetch::fetch::Client as FetchClient;
use helpers::replace_home;
use dir::default_data_path;
use io::PanicHandler;
use jsonrpc_core::reactor::Remote;
use rpc_apis::SignerService;
use hash_fetch::fetch::Client as FetchClient;
use rpc_apis::{self, SignerService};

#[derive(Debug, PartialEq, Clone)]
pub struct Configuration {
Expand All @@ -36,6 +36,7 @@ pub struct Configuration {
pub pass: Option<String>,
pub dapps_path: PathBuf,
pub extra_dapps: Vec<PathBuf>,
pub all_apis: bool,
}

impl Default for Configuration {
Expand All @@ -50,6 +51,7 @@ impl Default for Configuration {
pass: None,
dapps_path: replace_home(&data_dir, "$BASE/dapps").into(),
extra_dapps: vec![],
all_apis: false,
}
}
}
Expand Down Expand Up @@ -89,7 +91,8 @@ pub fn new(configuration: Configuration, deps: Dependencies) -> Result<Option<We
configuration.extra_dapps,
&addr,
configuration.hosts,
auth
auth,
configuration.all_apis,
)?))
}

Expand All @@ -110,6 +113,7 @@ mod server {
_url: &SocketAddr,
_allowed_hosts: Option<Vec<String>>,
_auth: Option<(String, String)>,
_all_apis: bool,
) -> Result<WebappServer, String> {
Err("Your Parity version has been compiled without WebApps support.".into())
}
Expand All @@ -124,14 +128,14 @@ mod server {
use std::io;
use util::{Bytes, Address, U256};

use ansi_term::Colour;
use ethcore::transaction::{Transaction, Action};
use ethcore::client::{Client, BlockChainClient, BlockId};

use rpc_apis;
use ethcore_rpc::is_major_importing;
use hash_fetch::urlhint::ContractClient;
use jsonrpc_core::reactor::RpcHandler;
use parity_reactor;
use rpc_apis;

pub use ethcore_dapps::Server as WebappServer;

Expand All @@ -142,6 +146,7 @@ mod server {
url: &SocketAddr,
allowed_hosts: Option<Vec<String>>,
auth: Option<(String, String)>,
all_apis: bool,
) -> Result<WebappServer, String> {
use ethcore_dapps as dapps;

Expand All @@ -162,7 +167,14 @@ mod server {
.signer_address(deps.signer.address())
.allowed_hosts(allowed_hosts);

let apis = rpc_apis::setup_rpc(Default::default(), deps.apis.clone(), rpc_apis::ApiSet::UnsafeContext);
let api_set = if all_apis {
warn!("{}", Colour::Red.bold().paint("*** INSECURE *** Running Dapps with all APIs exposed."));
info!("If you do not intend this, exit now.");
rpc_apis::ApiSet::SafeContext
} else {
rpc_apis::ApiSet::UnsafeContext
};
let apis = rpc_apis::setup_rpc(Default::default(), deps.apis.clone(), api_set);
let handler = RpcHandler::new(Arc::new(apis), deps.remote);
let start_result = match auth {
None => {
Expand Down

0 comments on commit 47e1c5e

Please sign in to comment.