Signer provenance (#4477)
* Signer - Tracking Request Provenance * Basic UI * Changing messages * VecDeque::from * Fix dapps tests * Addressing UI grumbles
This commit is contained in:
@@ -28,7 +28,7 @@ extern crate ctrlc;
|
||||
extern crate docopt;
|
||||
extern crate env_logger;
|
||||
extern crate fdlimit;
|
||||
extern crate hyper; // for price_info.rs
|
||||
extern crate hyper;
|
||||
extern crate isatty;
|
||||
extern crate jsonrpc_core;
|
||||
extern crate num_cpus;
|
||||
@@ -60,15 +60,14 @@ extern crate parity_reactor;
|
||||
extern crate parity_updater as updater;
|
||||
extern crate rpc_cli;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log as rlog;
|
||||
|
||||
#[cfg(feature="stratum")]
|
||||
extern crate ethcore_stratum;
|
||||
#[cfg(feature = "dapps")]
|
||||
extern crate ethcore_dapps;
|
||||
|
||||
|
||||
#[macro_use]
|
||||
extern crate log as rlog;
|
||||
|
||||
macro_rules! dependency {
|
||||
($dep_ty:ident, $url:expr) => {
|
||||
{
|
||||
|
||||
@@ -21,9 +21,10 @@ use std::io;
|
||||
use io::PanicHandler;
|
||||
|
||||
use dir::default_data_path;
|
||||
use ethcore_rpc::{self as rpc, RpcServerError, IpcServerError, Metadata};
|
||||
use ethcore_rpc::{self as rpc, RpcServerError, IpcServerError, Metadata, Origin};
|
||||
use ethcore_rpc::informant::{RpcStats, Middleware};
|
||||
use helpers::parity_ipc_path;
|
||||
use hyper;
|
||||
use jsonrpc_core::MetaIoHandler;
|
||||
use jsonrpc_core::reactor::{RpcHandler, Remote};
|
||||
use rpc_apis;
|
||||
@@ -89,6 +90,18 @@ pub struct Dependencies {
|
||||
pub stats: Arc<RpcStats>,
|
||||
}
|
||||
|
||||
pub struct RpcExtractor;
|
||||
impl rpc::HttpMetaExtractor<Metadata> for RpcExtractor {
|
||||
fn read_metadata(&self, req: &hyper::server::Request<hyper::net::HttpStream>) -> Metadata {
|
||||
let origin = req.headers().get::<hyper::header::Origin>()
|
||||
.map(|origin| format!("{}://{}", origin.scheme, origin.host))
|
||||
.unwrap_or_else(|| "unknown".into());
|
||||
let mut metadata = Metadata::default();
|
||||
metadata.origin = Origin::Rpc(origin);
|
||||
metadata
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_http(conf: HttpConfiguration, deps: &Dependencies) -> Result<Option<HttpServer>, String> {
|
||||
if !conf.enabled {
|
||||
return Ok(None);
|
||||
@@ -113,7 +126,7 @@ pub fn setup_http_rpc_server(
|
||||
let apis = setup_apis(apis, dependencies);
|
||||
let handler = RpcHandler::new(Arc::new(apis), dependencies.remote.clone());
|
||||
let ph = dependencies.panic_handler.clone();
|
||||
let start_result = rpc::start_http(url, cors_domains, allowed_hosts, ph, handler);
|
||||
let start_result = rpc::start_http(url, cors_domains, allowed_hosts, ph, handler, RpcExtractor);
|
||||
match start_result {
|
||||
Err(RpcServerError::IoError(err)) => match err.kind() {
|
||||
io::ErrorKind::AddrInUse => Err(format!("RPC address {} is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --jsonrpc-port and --jsonrpc-interface options.", url)),
|
||||
|
||||
@@ -23,12 +23,14 @@ pub use ethcore_signer::Server as SignerServer;
|
||||
use ansi_term::Colour;
|
||||
use dir::default_data_path;
|
||||
use ethcore_rpc::informant::RpcStats;
|
||||
use ethcore_rpc;
|
||||
use ethcore_signer as signer;
|
||||
use helpers::replace_home;
|
||||
use io::{ForwardPanic, PanicHandler};
|
||||
use jsonrpc_core::reactor::{RpcHandler, Remote};
|
||||
use rpc_apis;
|
||||
use util::path::restrict_permissions_owner;
|
||||
use util::H256;
|
||||
|
||||
const CODES_FILENAME: &'static str = "authcodes";
|
||||
|
||||
@@ -67,6 +69,16 @@ pub struct NewToken {
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct StandardExtractor;
|
||||
impl signer::MetaExtractor<ethcore_rpc::Metadata> for StandardExtractor {
|
||||
fn extract_metadata(&self, session: &H256) -> ethcore_rpc::Metadata {
|
||||
let mut metadata = ethcore_rpc::Metadata::default();
|
||||
metadata.origin = ethcore_rpc::Origin::Signer((*session).into());
|
||||
metadata
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start(conf: Configuration, deps: Dependencies) -> Result<Option<SignerServer>, String> {
|
||||
if !conf.enabled {
|
||||
Ok(None)
|
||||
@@ -133,7 +145,7 @@ fn do_start(conf: Configuration, deps: Dependencies) -> Result<SignerServer, Str
|
||||
let server = server.stats(deps.rpc_stats.clone());
|
||||
let apis = rpc_apis::setup_rpc(deps.rpc_stats, deps.apis, rpc_apis::ApiSet::SafeContext);
|
||||
let handler = RpcHandler::new(Arc::new(apis), deps.remote);
|
||||
server.start(addr, handler)
|
||||
server.start_with_extractor(addr, handler, StandardExtractor)
|
||||
};
|
||||
|
||||
match start_result {
|
||||
|
||||
Reference in New Issue
Block a user