Skip to content

Commit

Permalink
able to disable signature verification (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc authored Nov 1, 2022
1 parent 3c78693 commit 4508337
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions executor/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ pub enum TaskResponse {
Error(String),
}


fn is_magic_signature(signature: &[u8]) -> bool {
signature.starts_with(&[0xde, 0xad, 0xbe, 0xef]) && signature[4..].iter().all(|&b| b == 0xcd)
}

impl Task {
pub async fn run(&self, task_id: u32, client: &Client) -> Result<TaskResponse, jsonrpsee::core::Error> {
let resp = match self.kind {
Expand Down Expand Up @@ -122,6 +127,14 @@ impl Task {
.await?;
req.inject_key(next_key.map(|k| k.0))
}
RuntimeHostVm::SignatureVerification(req) => {
let bypass = is_magic_signature(req.signature().as_ref());
if bypass {
req.resume_success()
} else {
req.verify_and_resume()
}
}
}
};

Expand Down Expand Up @@ -178,3 +191,17 @@ impl Task {
)))
}
}

#[test]
fn is_magic_signature_works() {
assert!(is_magic_signature(&[0xde, 0xad, 0xbe, 0xef, 0xcd, 0xcd]));
assert!(is_magic_signature(&[
0xde, 0xad, 0xbe, 0xef, 0xcd, 0xcd, 0xcd, 0xcd
]));
assert!(!is_magic_signature(&[
0xde, 0xad, 0xbe, 0xef, 0xcd, 0xcd, 0xcd, 0x00
]));
assert!(!is_magic_signature(&[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]));
}

0 comments on commit 4508337

Please sign in to comment.