Validating sha3 of a dapp bundle (#1993)

* Validating sha3 of a file

* sha3 in utils

* Removing devtools
This commit is contained in:
Tomasz Drwięga
2016-08-24 16:53:07 +02:00
committed by Gav Wood
parent 3dd1bdda50
commit 33e0a234f2
7 changed files with 84 additions and 16 deletions

View File

@@ -30,7 +30,8 @@ use hyper::Control;
use hyper::status::StatusCode;
use random_filename;
use util::Mutex;
use util::{Mutex, H256};
use util::sha3::sha3;
use page::LocalPageEndpoint;
use handlers::{ContentHandler, AppFetcherHandler, DappHandler};
use endpoint::{Endpoint, EndpointPath, Handler};
@@ -137,10 +138,12 @@ impl<R: URLHint> AppFetcher<R> {
#[derive(Debug)]
pub enum ValidationError {
ManifestNotFound,
ManifestSerialization(String),
Io(io::Error),
Zip(zip::result::ZipError),
InvalidDappId,
ManifestNotFound,
ManifestSerialization(String),
HashMismatch { expected: H256, got: H256, },
}
impl From<io::Error> for ValidationError {
@@ -198,8 +201,15 @@ impl DappHandler for DappInstaller {
fn validate_and_install(&self, app_path: PathBuf) -> Result<Manifest, ValidationError> {
trace!(target: "dapps", "Opening dapp bundle at {:?}", app_path);
// TODO [ToDr] Validate file hash
let file = try!(fs::File::open(app_path));
let mut file = try!(fs::File::open(app_path));
let hash = try!(sha3(&mut file));
let dapp_id = try!(self.dapp_id.as_str().parse().map_err(|_| ValidationError::InvalidDappId));
if dapp_id != hash {
return Err(ValidationError::HashMismatch {
expected: dapp_id,
got: hash,
});
}
// Unpack archive
let mut zip = try!(zip::ZipArchive::new(file));
// First find manifest file

View File

@@ -55,11 +55,11 @@ extern crate rand;
extern crate ethabi;
extern crate jsonrpc_core;
extern crate jsonrpc_http_server;
extern crate mime_guess;
extern crate rustc_serialize;
extern crate parity_dapps;
extern crate ethcore_rpc;
extern crate ethcore_util as util;
extern crate mime_guess;
extern crate rustc_serialize;
mod endpoint;
mod apps;