Skip to content

Commit 572b986

Browse files
committed
Pull in TS code and build on CI
This commit imports the TS code as a submodule and uses it to build and test the provider on the CI. Signed-off-by: Ionut Mihalcea <[email protected]>
1 parent 0b6645e commit 572b986

File tree

8 files changed

+34
-12
lines changed

8 files changed

+34
-12
lines changed

.github/workflows/ci.yml

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ jobs:
4242
run: docker build -t tpm-provider e2e_tests/provider_cfg/tpm
4343
- name: Run the container to execute the test script
4444
run: docker run -v $(pwd):/tmp/parsec -w /tmp/parsec tpm-provider /tmp/parsec/ci.sh tpm
45+
46+
trusted-service-provider:
47+
name: Integration tests using Cypto Trusted Service provider
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v2
51+
- name: Build the container
52+
run: docker build -t trusted-service-provider e2e_tests/provider_cfg/trusted-service
53+
- name: Run the container to execute the test script
54+
run: docker run -v $(pwd):/tmp/parsec -w /tmp/parsec trusted-service-provider /tmp/parsec/ci.sh trusted-service
4555

4656
links:
4757
name: Check links

.gitmodules

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "trusted-services-vendor"]
2+
path = trusted-services-vendor
3+
url = https://git.trustedfirmware.org/TS/trusted-services.git
4+
branch = integration

ci.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ while [ "$#" -gt 0 ]; do
6060
--no-stress-test )
6161
NO_STRESS_TEST="True"
6262
;;
63-
mbed-crypto | pkcs11 | tpm | all )
63+
mbed-crypto | pkcs11 | tpm | trusted-service | all )
6464
if [ -n "$PROVIDER_NAME" ]; then
6565
error_msg "Only one provider name must be given"
6666
fi
@@ -107,6 +107,10 @@ if [ "$PROVIDER_NAME" = "pkcs11" ] || [ "$PROVIDER_NAME" = "all" ]; then
107107
popd
108108
fi
109109

110+
if [ "$PROVIDER_NAME" = "trusted-service" ]; then
111+
git submodule update --init
112+
fi
113+
110114
echo "Build test"
111115
RUST_BACKTRACE=1 cargo build $FEATURES
112116

e2e_tests/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ mbed-crypto-provider = []
3434
tpm-provider = []
3535
pkcs11-provider = []
3636
cryptoauthlib-provider = []
37+
trusted-service-provider = []
3738
all-providers = ["pkcs11-provider","tpm-provider","mbed-crypto-provider","cryptoauthlib-provider"]

e2e_tests/provider_cfg/trusted-service/Dockerfile

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ RUN apt-get update && \
88
apt-get install -y clang libclang-dev && \
99
# Needed for Open SSL
1010
apt-get install -y pkg-config libssl-dev python3-distutils && \
11-
apt-get install -y python3-distutils python3-protobuf nanopb
11+
# Needed for Protobuf handling
12+
apt-get install -y python3-distutils python3-protobuf nanopb && \
13+
# Needed for the Trusted Services implementation
14+
apt-get install -y libc++-dev libc++abi-dev
1215

1316
WORKDIR /tmp
14-
COPY trusted-services /tmp/trusted-services
15-
RUN cd trusted-services/deployments/ts-lib/posix-x86/ \
17+
RUN git clone https://git.trustedfirmware.org/TS/trusted-services.git --branch integration
18+
RUN cd trusted-services/deployments/libts/linux-pc/ \
1619
&& cmake . \
1720
&& make \
18-
&& cp libts-lib.a nanopb_install/lib/libprotobuf-nanopb.a mbedcrypto_install/lib/libmbedcrypto.a /usr/local/lib/
21+
&& cp libts.so nanopb_install/lib/libprotobuf-nanopb.a mbedcrypto_install/lib/libmbedcrypto.a /usr/local/lib/
22+
23+
ENV LD_LIBRARY_PATH="/usr/local/lib"
1924

2025
# Install Rust toolchain
2126
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y

src/providers/trusted_service/context/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl Context {
161161
&mut status,
162162
)
163163
};
164-
if service_context == null_mut() {
164+
if service_context.is_null() {
165165
return Err(Error::new(
166166
ErrorKind::Other,
167167
"Failed to obtain a Trusted Service context",
@@ -181,7 +181,7 @@ impl Context {
181181
info!("Starting crypto Trusted Service context");
182182
let mut rpc_caller = null_mut();
183183
let rpc_session_handle = unsafe { service_context_open(service_context, &mut rpc_caller) };
184-
if rpc_caller == null_mut() || rpc_session_handle == null_mut() {
184+
if rpc_caller.is_null() || rpc_session_handle.is_null() {
185185
return Err(
186186
Error::new(ErrorKind::Other, "Failed to start Trusted Service context").into(),
187187
);
@@ -209,10 +209,10 @@ impl Context {
209209
let mut buf_out = null_mut();
210210
let call_handle =
211211
unsafe { rpc_caller_begin(self.rpc_caller, &mut buf_out, req.encoded_len()) };
212-
if call_handle == null_mut() {
212+
if call_handle.is_null() {
213213
error!("Call handle was null");
214214
return Err(PsaError::CommunicationFailure);
215-
} else if buf_out == null_mut() {
215+
} else if buf_out.is_null() {
216216
error!("Call buffer was null");
217217
return Err(PsaError::CommunicationFailure);
218218
}

src/providers/trusted_service/key_management.rs

-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ impl Provider {
8181
Ok(_) => Ok(psa_import_key::Result {}),
8282
Err(error) => {
8383
remove_key_id(&key_triple, &mut *store_handle)?;
84-
let error = ResponseStatus::from(error);
8584
format_error!("Import key status: ", error);
8685
Err(error)
8786
}
@@ -103,7 +102,6 @@ impl Provider {
103102
data: pub_key.into(),
104103
}),
105104
Err(error) => {
106-
let error = ResponseStatus::from(error);
107105
format_error!("Export key status: ", error);
108106
Err(error)
109107
}
@@ -129,7 +127,6 @@ impl Provider {
129127
Ok(psa_destroy_key::Result {})
130128
}
131129
Err(error) => {
132-
let error = ResponseStatus::from(error);
133130
format_error!("Destroy key status: ", error);
134131
Err(error)
135132
}

trusted-services-vendor

Submodule trusted-services-vendor added at eff4b28

0 commit comments

Comments
 (0)