-
Notifications
You must be signed in to change notification settings - Fork 60
/
main.rs
79 lines (67 loc) · 2.24 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#![no_main]
use optee_utee::{
ta_close_session, ta_create, ta_destroy, ta_invoke_command, ta_open_session, trace_println,
};
use optee_utee::{Error, ErrorKind, Parameters, Result};
use std::io::Write;
use proto::{self, Command};
fn handle_invoke(command: Command, input: proto::EnclaveInput) -> Result<proto::EnclaveOutput> {
match command {
Command::Hello => {
let output = proto::EnclaveOutput {
message: format!("Hello, {}", input.message)
};
Ok(output)
},
Command::Bye => {
let output = proto::EnclaveOutput {
message: format!("Bye, {}", input.message)
};
Ok(output)
},
_ => Err(Error::new(ErrorKind::BadParameters)),
}
}
#[ta_create]
fn create() -> Result<()> {
trace_println!("[+] TA create");
Ok(())
}
#[ta_open_session]
fn open_session(_params: &mut Parameters) -> Result<()> {
trace_println!("[+] TA open session");
Ok(())
}
#[ta_close_session]
fn close_session() {
trace_println!("[+] TA close session");
}
#[ta_destroy]
fn destroy() {
trace_println!("[+] TA destroy");
}
#[ta_invoke_command]
fn invoke_command(cmd_id: u32, params: &mut Parameters) -> Result<()> {
trace_println!("[+] TA invoke command");
let mut p0 = unsafe { params.0.as_memref().unwrap()};
let mut p1 = unsafe { params.1.as_memref().unwrap()};
let mut p2 = unsafe { params.2.as_value().unwrap() };
let input: proto::EnclaveInput = proto::serde_json::from_slice(p0.buffer()).unwrap();
let output = handle_invoke(Command::from(cmd_id), input).unwrap();
let output_vec = proto::serde_json::to_vec(&output).unwrap();
p1.buffer().write(&output_vec).unwrap();
p2.set_a(output_vec.len() as u32);
Ok(())
}
// TA configurations
const TA_FLAGS: u32 = 0;
const TA_DATA_SIZE: u32 = 64 * 1024;
const TA_STACK_SIZE: u32 = 4 * 1024;
const TA_VERSION: &[u8] = b"0.1\0";
const TA_DESCRIPTION: &[u8] = b"This is a hello world example.\0";
const EXT_PROP_VALUE_1: &[u8] = b"Hello World TA\0";
const EXT_PROP_VALUE_2: u32 = 0x0010;
const TRACE_LEVEL: i32 = 4;
const TRACE_EXT_PREFIX: &[u8] = b"TA\0";
const TA_FRAMEWORK_STACK_SIZE: u32 = 2048;
include!(concat!(env!("OUT_DIR"), "/user_ta_header.rs"));