Skip to content

Commit 0a0ab8a

Browse files
committed
optee-utee: Enable TA-to-TA Invocation
This commit provides the Rust API for GP API TEE_InvokeTACommand(), which enable the user TA calls another user TA or pseudo TA. - Add abstraction of TeeParameters and TaSession; - Add inter-ta example and test scripts. Signed-off-by: Yuan Zhuang <yuanz@apache.org> Reviewed-by: Zehui Chen <ivila@apache.org>
1 parent fb30450 commit 0a0ab8a

File tree

18 files changed

+1223
-77
lines changed

18 files changed

+1223
-77
lines changed

ci/ci.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fi
5252
./test_tcp_client.sh
5353
./test_udp_socket.sh
5454
./test_client_pool.sh
55+
./test_inter_ta.sh
5556

5657

5758
popd

examples/inter_ta-rs/Makefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# If _HOST or _TA specific compiler/target are not specified, then use common
19+
# compiler/target for both
20+
CROSS_COMPILE_HOST ?= aarch64-linux-gnu-
21+
CROSS_COMPILE_TA ?= aarch64-linux-gnu-
22+
TARGET_HOST ?= aarch64-unknown-linux-gnu
23+
TARGET_TA ?= aarch64-unknown-linux-gnu
24+
25+
.PHONY: host ta all clean
26+
27+
all: host ta
28+
29+
host:
30+
$(q)make -C host TARGET=$(TARGET_HOST) \
31+
CROSS_COMPILE=$(CROSS_COMPILE_HOST)
32+
33+
ta:
34+
$(q)make -C ta TARGET=$(TARGET_TA) \
35+
CROSS_COMPILE=$(CROSS_COMPILE_TA)
36+
37+
clean:
38+
$(q)make -C host clean
39+
$(q)make -C ta clean
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[package]
19+
name = "inter_ta-rs"
20+
version = "0.4.0"
21+
authors = ["Teaclave Contributors <dev@teaclave.apache.org>"]
22+
license = "Apache-2.0"
23+
repository = "https://github.com/apache/incubator-teaclave-trustzone-sdk.git"
24+
description = "An example of Rust OP-TEE TrustZone SDK."
25+
edition = "2018"
26+
27+
[dependencies]
28+
libc = "0.2.48"
29+
proto = { path = "../proto" }
30+
optee-teec = { path = "../../../optee-teec" }
31+
32+
[profile.release]
33+
lto = true

examples/inter_ta-rs/host/Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
NAME := inter_ta-rs
19+
20+
TARGET ?= aarch64-unknown-linux-gnu
21+
CROSS_COMPILE ?= aarch64-linux-gnu-
22+
OBJCOPY := $(CROSS_COMPILE)objcopy
23+
LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
24+
25+
OUT_DIR := $(CURDIR)/target/$(TARGET)/release
26+
27+
28+
all: host strip
29+
30+
host:
31+
@cargo build --target $(TARGET_HOST) --release --config $(LINKER_CFG)
32+
33+
strip: host
34+
@$(OBJCOPY) --strip-unneeded $(OUT_DIR)/$(NAME) $(OUT_DIR)/$(NAME)
35+
36+
clean:
37+
@cargo clean
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use optee_teec::{Context, ErrorKind, Operation, ParamNone, Uuid};
19+
use proto::{Command, UUID};
20+
21+
fn main() -> optee_teec::Result<()> {
22+
let mut ctx = Context::new()?;
23+
let uuid =
24+
Uuid::parse_str(UUID).map_err(|_| optee_teec::Error::from(ErrorKind::BadParameters))?;
25+
let mut session = ctx.open_session(uuid)?;
26+
let mut operation = Operation::new(0, ParamNone, ParamNone, ParamNone, ParamNone);
27+
28+
// Nothing to send, just invoke the Test command
29+
session.invoke_command(Command::Test as u32, &mut operation)?;
30+
println!("Success");
31+
Ok(())
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[package]
19+
name = "proto"
20+
version = "0.4.0"
21+
authors = ["Teaclave Contributors <dev@teaclave.apache.org>"]
22+
license = "Apache-2.0"
23+
repository = "https://github.com/apache/incubator-teaclave-trustzone-sdk.git"
24+
description = "Data structures and functions shared by host and TA."
25+
edition = "2018"
26+
27+
[dependencies]
28+
num_enum = { version = "0.7.3", default-features = false }
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#![no_std]
19+
use num_enum::{FromPrimitive, IntoPrimitive};
20+
21+
// For CA-TA invocation:
22+
#[derive(FromPrimitive, IntoPrimitive)]
23+
#[repr(u32)]
24+
pub enum Command {
25+
Test,
26+
#[default]
27+
Unknown,
28+
}
29+
30+
// If Uuid::parse_str() returns an InvalidLength error, there may be an extra
31+
// newline in your uuid.txt file. You can remove it by running
32+
// `truncate -s 36 uuid.txt`.
33+
pub const UUID: &str = &include_str!("../../uuid.txt");
34+
35+
// For TA-TA invocation testcases:
36+
#[derive(FromPrimitive, IntoPrimitive)]
37+
#[repr(u32)]
38+
pub enum SystemPtaCommand {
39+
AddRngEntropy,
40+
DeriveTaUniqueKey,
41+
// We omit other commands here.
42+
// Full definitions can be found in optee_os system_pta.h.
43+
#[default]
44+
Unknown,
45+
}
46+
47+
#[derive(FromPrimitive, IntoPrimitive)]
48+
#[repr(u32)]
49+
pub enum HelloWorldTaCommand {
50+
IncValue,
51+
DecValue,
52+
#[default]
53+
Unknown,
54+
}
55+
56+
pub const SYSTEM_PTA_UUID: &str = "3a2f8978-5dc0-11e8-9c2d-fa7ae01bbebc";
57+
pub const HELLO_WORLD_USER_TA_UUID: &str = "133af0ca-bdab-11eb-9130-43bf7873bf67";

examples/inter_ta-rs/ta/Cargo.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[package]
19+
name = "ta"
20+
version = "0.4.0"
21+
authors = ["Teaclave Contributors <dev@teaclave.apache.org>"]
22+
license = "Apache-2.0"
23+
repository = "https://github.com/apache/incubator-teaclave-trustzone-sdk.git"
24+
description = "An example of Rust OP-TEE TrustZone SDK."
25+
edition = "2018"
26+
27+
[dependencies]
28+
proto = { path = "../proto" }
29+
optee-utee-sys = { path = "../../../optee-utee/optee-utee-sys" }
30+
optee-utee = { path = "../../../optee-utee" }
31+
32+
[build-dependencies]
33+
proto = { path = "../proto" }
34+
optee-utee-build = { path = "../../../optee-utee-build" }
35+
36+
[profile.release]
37+
panic = "abort"
38+
lto = true
39+
opt-level = 1

examples/inter_ta-rs/ta/Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
UUID ?= $(shell cat "../uuid.txt")
19+
20+
TARGET ?= aarch64-unknown-linux-gnu
21+
CROSS_COMPILE ?= aarch64-linux-gnu-
22+
OBJCOPY := $(CROSS_COMPILE)objcopy
23+
# Configure the linker to use GCC, which works on both cross-compilation and ARM machines
24+
LINKER_CFG := target.$(TARGET).linker=\"$(CROSS_COMPILE)gcc\"
25+
26+
TA_SIGN_KEY ?= $(TA_DEV_KIT_DIR)/keys/default_ta.pem
27+
SIGN := $(TA_DEV_KIT_DIR)/scripts/sign_encrypt.py
28+
OUT_DIR := $(CURDIR)/target/$(TARGET)/release
29+
30+
BUILDER = $(if $(STD),xargo,cargo)
31+
32+
all: ta strip sign
33+
34+
ta:
35+
@$(BUILDER) build --target $(TARGET) --release --config $(LINKER_CFG)
36+
37+
strip: ta
38+
@$(OBJCOPY) --strip-unneeded $(OUT_DIR)/ta $(OUT_DIR)/stripped_ta
39+
40+
sign: strip
41+
@$(SIGN) --uuid $(UUID) --key $(TA_SIGN_KEY) --in $(OUT_DIR)/stripped_ta --out $(OUT_DIR)/$(UUID).ta
42+
@echo "SIGN => ${UUID}"
43+
44+
clean:
45+
@cargo clean

examples/inter_ta-rs/ta/Xargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[dependencies.std]
19+
path = "../../../rust/rust/library/std"
20+
21+
[patch.crates-io]
22+
libc = { path = "../../../rust/libc" }
23+
rustc-std-workspace-core = { path = "../../../rust/rust/library/rustc-std-workspace-core" }
24+
rustc-std-workspace-alloc = { path = "../../../rust/rust/library/rustc-std-workspace-alloc" }

0 commit comments

Comments
 (0)