forked from apache/incubator-teaclave-trustzone-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
112 changed files
with
4,765 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ header: | |
- 'KEYS' | ||
- 'DISCLAIMER-WIP' | ||
- '*.json' | ||
- 'examples/tls_server-rs/ta/test-ca/**' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
# If _HOST or _TA specific compiler/target are not specified, then use common | ||
# compiler/target for both | ||
CROSS_COMPILE_HOST ?= aarch64-linux-gnu- | ||
CROSS_COMPILE_TA ?= aarch64-linux-gnu- | ||
TARGET_HOST ?= aarch64-unknown-linux-gnu | ||
TARGET_TA ?= aarch64-unknown-linux-gnu | ||
|
||
all: | ||
$(q)make -C host TARGET_HOST=$(TARGET_HOST) \ | ||
CROSS_COMPILE_HOST=$(CROSS_COMPILE_HOST) | ||
$(q)make -C ta TARGET_TA=$(TARGET_TA) \ | ||
CROSS_COMPILE_TA=$(CROSS_COMPILE_TA) | ||
|
||
clean: | ||
$(q)make -C host clean | ||
$(q)make -C ta clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
[package] | ||
name = "message_passing_interface-rs" | ||
version = "0.3.0" | ||
authors = ["Teaclave Contributors <[email protected]>"] | ||
license = "Apache-2.0" | ||
repository = "https://github.com/apache/incubator-teaclave-trustzone-sdk.git" | ||
description = "An example of Rust OP-TEE TrustZone SDK." | ||
edition = "2018" | ||
|
||
[dependencies] | ||
url = "2.5.0" | ||
proto = { path = "../proto" } | ||
optee-teec = { path = "../../../optee-teec" } | ||
|
||
[profile.release] | ||
lto = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
NAME := message_passing_interface-rs | ||
|
||
TARGET_HOST ?= aarch64-unknown-linux-gnu | ||
CROSS_COMPILE_HOST ?= aarch64-linux-gnu- | ||
OBJCOPY := $(CROSS_COMPILE_HOST)objcopy | ||
LINKER_CFG := target.$(TARGET_HOST).linker=\"$(CROSS_COMPILE_HOST)gcc\" | ||
|
||
OUT_DIR := $(CURDIR)/target/$(TARGET_HOST)/release | ||
|
||
|
||
all: host strip | ||
|
||
host: | ||
@cargo build --target $(TARGET_HOST) --release --config $(LINKER_CFG) | ||
|
||
strip: host | ||
@$(OBJCOPY) --strip-unneeded $(OUT_DIR)/$(NAME) $(OUT_DIR)/$(NAME) | ||
|
||
clean: | ||
@cargo clean | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use optee_teec::{Context, Operation, ParamNone, ParamTmpRef, ParamType, ParamValue, Uuid}; | ||
use proto; | ||
use url; | ||
|
||
type Result<T> = optee_teec::Result<T>; | ||
|
||
pub struct EnclaveClient { | ||
uuid: String, | ||
context: optee_teec::Context, | ||
buffer: Vec<u8>, | ||
} | ||
|
||
impl EnclaveClient { | ||
pub fn open(url: &str) -> Result<Self> { | ||
let url = url::Url::parse(url).unwrap(); | ||
match url.scheme() { | ||
"trustzone-enclave" => Self::open_uuid(url.host_str().unwrap()), | ||
_ => unimplemented!(), | ||
} | ||
} | ||
|
||
fn open_uuid(uuid: &str) -> Result<Self> { | ||
let context = Context::new()?; | ||
Ok(Self { | ||
uuid: uuid.to_string(), | ||
context: context, | ||
buffer: vec![0; 128], | ||
}) | ||
} | ||
|
||
pub fn invoke(&mut self, input: &proto::EnclaveInput) -> Result<proto::EnclaveOutput> { | ||
let command_id = input.command as u32; | ||
let mut serialized_input = proto::serde_json::to_vec(input).unwrap(); | ||
|
||
let p0 = ParamTmpRef::new_input(serialized_input.as_mut_slice()); | ||
let p1 = ParamTmpRef::new_output(&mut self.buffer); | ||
let p2 = ParamValue::new(0, 0, ParamType::ValueInout); | ||
|
||
let mut operation = Operation::new(0, p0, p1, p2, ParamNone); | ||
|
||
let uuid = Uuid::parse_str(&self.uuid).unwrap(); | ||
let mut session = self.context.open_session(uuid)?; | ||
session.invoke_command(command_id, &mut operation)?; | ||
let len = operation.parameters().2.a() as usize; | ||
|
||
let output: proto::EnclaveOutput = | ||
proto::serde_json::from_slice(&self.buffer[0..len]).unwrap(); | ||
Ok(output) | ||
} | ||
} | ||
|
||
fn main() -> optee_teec::Result<()> { | ||
let url = format!("trustzone-enclave://{}", proto::UUID); | ||
let mut enclave = EnclaveClient::open(&url).unwrap(); | ||
let input = proto::EnclaveInput { | ||
command: proto::Command::Hello, | ||
message: String::from("World!"), | ||
}; | ||
let output = enclave.invoke(&input).unwrap(); | ||
println!("{:?}", output); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
[package] | ||
name = "proto" | ||
version = "0.3.0" | ||
authors = ["Teaclave Contributors <[email protected]>"] | ||
license = "Apache-2.0" | ||
repository = "https://github.com/apache/incubator-teaclave-trustzone-sdk.git" | ||
description = "Data structures and functions shared by host and TA." | ||
edition = "2018" | ||
|
||
[dependencies] | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
|
||
[build-dependencies] | ||
uuid = { version = "1.8", default-features = false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::fs; | ||
use std::path::PathBuf; | ||
use std::fs::File; | ||
use std::env; | ||
use std::io::Write; | ||
|
||
fn main() { | ||
let uuid = match fs::read_to_string("../uuid.txt") { | ||
Ok(u) => { | ||
u.trim().to_string() | ||
}, | ||
Err(_) => { | ||
panic!("Cannot find uuid.txt"); | ||
} | ||
}; | ||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
let mut buffer = File::create(out.join("uuid.txt")).unwrap(); | ||
write!(buffer, "{}", uuid).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use serde::{Serialize, Deserialize}; | ||
pub use serde_json; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Copy, Clone)] | ||
pub enum Command { | ||
Hello, | ||
Bye, | ||
Unknown, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct EnclaveInput { | ||
pub command: Command, | ||
pub message: String | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct EnclaveOutput { | ||
pub message: String | ||
} | ||
|
||
impl From<u32> for Command { | ||
#[inline] | ||
fn from(value: u32) -> Command { | ||
match value { | ||
0 => Command::Hello, | ||
1 => Command::Bye, | ||
_ => Command::Unknown, | ||
} | ||
} | ||
} | ||
|
||
|
||
pub const UUID: &str = &include_str!(concat!(env!("OUT_DIR"), "/uuid.txt")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
[package] | ||
name = "ta" | ||
version = "0.3.0" | ||
authors = ["Teaclave Contributors <[email protected]>"] | ||
license = "Apache-2.0" | ||
repository = "https://github.com/apache/incubator-teaclave-trustzone-sdk.git" | ||
description = "An example of Rust OP-TEE TrustZone SDK." | ||
edition = "2018" | ||
|
||
[dependencies] | ||
proto = { path = "../proto" } | ||
optee-utee-sys = { path = "../../../optee-utee/optee-utee-sys" } | ||
optee-utee = { path = "../../../optee-utee" } | ||
|
||
[build-dependencies] | ||
uuid = { version = "1.8", default-features = false } | ||
proto = { path = "../proto" } | ||
|
||
[profile.release] | ||
panic = "abort" | ||
lto = false | ||
opt-level = 1 |
Oops, something went wrong.