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

Commit

Permalink
fix some warnings and clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Alain Brenzikofer committed Feb 20, 2020
1 parent 6ed521b commit 7328b37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
13 changes: 7 additions & 6 deletions host_calls/src/remote_attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use sgx_types::*;
use sgx_ucrypto::SgxEccHandle;

use super::{SgxReport, SgxStatus};
use codec::{Decode, Encode};
use codec::Encode;

type SignatureAlgorithms = &'static [&'static webpki::SignatureAlgorithm];

Expand All @@ -50,12 +50,12 @@ pub const IAS_REPORT_CA: &[u8] = include_bytes!("../AttestationReportSigningCACe

// prevents panics in case of index out of bounds
fn safe_indexing(data: &[u8], start: usize, end: usize) -> Result<&[u8], &'static str> {
if (start > end) { return Err("Illegal indexing")}
if (data.len() < end) { return Err("Index would be out of bounds")}
if start > end { return Err("Illegal indexing")}
if data.len() < end { return Err("Index would be out of bounds")}
Ok(&data[start..end])
}
fn safe_indexing_one(data: &[u8], idx: usize) -> Result<u8, &'static str> {
if (data.len() < idx) { return Err("Index would be out of bounds")}
if data.len() < idx { return Err("Index would be out of bounds")}
Ok(data[idx])
}

Expand Down Expand Up @@ -271,15 +271,15 @@ pub fn verify_mra_cert(
let _result = ecc_handle.open();

let mut ephemeral_pub = sgx_ec256_public_t::default();
if (pub_k.len() != 64) { return Err("wrong size of signer ephemeral public key") }
if pub_k.len() != 64 { return Err("wrong size of signer ephemeral public key") }
ephemeral_pub.gx.copy_from_slice(&pub_k[..32]);
ephemeral_pub.gy.copy_from_slice(&pub_k[32..]);
// key is stored in little-endian order in RA report. reverse!
ephemeral_pub.gx.reverse();
ephemeral_pub.gy.reverse();

let mut signature = sgx_ec256_signature_t::default();
if (xt_signer_attn.len() != 16) { return Err("wrong size of signer attestation signature") }
if xt_signer_attn.len() != 16 { return Err("wrong size of signer attestation signature") }
signature.x.copy_from_slice(&xt_signer_attn[..8]);
signature.y.copy_from_slice(&xt_signer_attn[8..]);

Expand Down Expand Up @@ -311,6 +311,7 @@ pub fn verify_mra_cert(
#[cfg(test)]
mod tests {
use super::*;
use codec::Decode;
// reproduce with "substratee_worker dump_ra"
const TEST1_CERT: &[u8] = include_bytes!("../test/test_ra_cert_MRSIGNER1_MRENCLAVE1.der");
const TEST2_CERT: &[u8] = include_bytes!("../test/test_ra_cert_MRSIGNER2_MRENCLAVE2.der");
Expand Down
3 changes: 3 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]

//SCS: remove this once clippy rules are aligned with substrate
#![warn(clippy::not_unsafe_ptr_arg_deref)]

// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
Expand Down
7 changes: 3 additions & 4 deletions runtime/src/substratee_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use codec::{Decode, Encode};
use host_calls::runtime_interfaces::verify_ra_report;
use host_calls::{SgxReport, SgxStatus};
use host_calls::SgxReport;
use rstd::prelude::*;
use rstd::str;
use runtime_io::misc::print_utf8;
Expand All @@ -31,7 +31,6 @@ pub trait Trait: balances::Trait {

const MAX_RA_REPORT_LEN: usize = 4096;
const MAX_URL_LEN: usize = 256;
const RA_SIGNER_ATTN_LEN: usize = 64;

#[derive(Encode, Decode, Default, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "std", derive(Debug))]
Expand Down Expand Up @@ -131,7 +130,7 @@ decl_module! {
}

pub fn call_worker(origin, request: Request) -> Result {
let sender = ensure_signed(origin)?;
let _sender = ensure_signed(origin)?;
Self::deposit_event(RawEvent::Forwarded(request));
Ok(())
}
Expand All @@ -156,7 +155,7 @@ impl<T: Trait> Module<T> {
fn register_verified_enclave(sender: &T::AccountId, report: &SgxReport, url: &Vec<u8>) -> Result {
let enclave = Enclave {
pubkey: sender.clone(),
mr_enclave: report.mr_enclave.clone(),
mr_enclave: report.mr_enclave,
timestamp: report.timestamp,
url: url.clone(),
};
Expand Down

0 comments on commit 7328b37

Please sign in to comment.