Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
03e6d43
psa-client-server: move psasim from framework repo to the mbedtls one
valeriosetti May 3, 2024
1d3db6b
crypto-client test: add mechanism to build crypto library for client …
valeriosetti May 7, 2024
527beec
crypto-client test: ensure that client/server are linked against prop…
valeriosetti May 9, 2024
c71b396
crypto-client test: implement the first IPC call for psa_crypto_init()
valeriosetti May 9, 2024
23ac8d9
crypto-client: reorganize source files/folders
valeriosetti May 10, 2024
7535106
crypto-client: simplify build of mbedtls static libraries
valeriosetti May 10, 2024
36e4fa1
crypto-client: fix the SID
valeriosetti May 10, 2024
b20360b
crypto-client: remove log files on "make clean"
valeriosetti May 10, 2024
6e00ad7
crypto-client: allow debug build of libraries and test binaries
valeriosetti May 10, 2024
b98608c
psa_ff_client: fix typos and useless blank lines
valeriosetti May 14, 2024
cbc38ce
psasim: create a seedfile to be used for the crypto server
valeriosetti May 14, 2024
1812c84
psa_autogen.py: improve management of output files
valeriosetti May 15, 2024
dceeb8b
Replace final sprintf() with snprintf() in psa_ff_server.c
tom-cosgrove-arm May 27, 2024
f28d21e
Fix psa_ff_server.c to calculate the amount of data from client corre…
tom-cosgrove-arm May 27, 2024
3a197ac
Fix PSA sim test awk script by removing extra $
tom-cosgrove-arm May 27, 2024
68acbc2
Fix sending a response of more than 184 bytes in psa_ff_server.c:psa_…
tom-cosgrove-arm May 28, 2024
9661c79
Only print PSA crypto sim server messages when DEBUG defined
tom-cosgrove-arm May 28, 2024
74eb1b2
Remove unnecessary blank lines at top of functions in psa_ff_server.c
tom-cosgrove-arm May 28, 2024
1fc43f0
Fix code style in psa_ff_server.c
tom-cosgrove-arm May 29, 2024
c490eb1
Add PSA crypto sim serialisation functions for basic types
tom-cosgrove-arm May 29, 2024
857e390
Add PSA crypto sim serialisation functions for rest of types needed f…
tom-cosgrove-arm May 29, 2024
418982e
Add PSA crypto sim client and server implementations of psa_hash_comp…
tom-cosgrove-arm May 29, 2024
0adb4f4
The PSA sim logs aren't very many lines, so show them during tests
tom-cosgrove-arm May 29, 2024
3f77a27
Hook the new psa_sim_crypto_{client,server} into the build and tests
tom-cosgrove-arm May 29, 2024
f84634c
Add PSA crypto sim serialisation functions needed for the remaining P…
tom-cosgrove-arm May 29, 2024
51f13be
Add the rest of the psa_hash_xxx() functions to the simulator
tom-cosgrove-arm May 29, 2024
a15ccb4
Extend PSA crypto simulator tests to run psa_hash.c under the simulator
tom-cosgrove-arm May 29, 2024
3e1b2b1
Mark temporary PSA crypto sim Perl scripts as executable
tom-cosgrove-arm May 29, 2024
8296a8f
PSA crypto sim's server wrappers need to free deseraliased buffers wh…
tom-cosgrove-arm May 29, 2024
1e51646
Add missing licences
tom-cosgrove-arm May 30, 2024
28d2cce
Correctly build client-side code that's to be run under the PSA crypt…
tom-cosgrove-arm Jun 10, 2024
fe4c220
We want the PSA hash code if MBEDTLS_PSA_CRYPTO_CLIENT && !MBEDTLS_PS…
tom-cosgrove-arm Jun 10, 2024
5f1e104
Store operation_ts on PSA sim server side; only send handle to client
tom-cosgrove-arm Jun 10, 2024
49e9a14
Make psa_sim_generate.pl output the new type of server wrapper we want
tom-cosgrove-arm Jun 10, 2024
6412d01
Move the comment block in psa_sim_serialise.c back to where it belongs
tom-cosgrove-arm Jun 10, 2024
4a23709
psa_sim_serialise.pl now creates the updated .h file
tom-cosgrove-arm Jun 10, 2024
cbce9f1
psa_sim_serialise.pl now creates the updated .c file
tom-cosgrove-arm Jun 10, 2024
2590e95
Revert "Correctly build client-side code that's to be run under the P…
tom-cosgrove-arm Jun 11, 2024
cfd4c5c
Use our own copy of programs/psa/psa_hash.c in the PSA simulator tests
tom-cosgrove-arm Jun 11, 2024
71f9fba
psa_sim_crypto_[client/server]: check if CRYPTO_C is enabled
valeriosetti Jun 10, 2024
ba91c29
psasim: build server library and binary before client's ones
valeriosetti Jun 10, 2024
2e2452e
Have PSA sim client wrappers say which call fails, if one does
tom-cosgrove-arm Jun 11, 2024
0172af4
Make it possible to pass arguments to PSA sim psa_client
tom-cosgrove-arm Jun 11, 2024
08064a5
Add support for and run (a copy of) the PSA aead_demo program under P…
tom-cosgrove-arm Jun 11, 2024
ef42617
Adjust build systems
ronald-cron-arm Jun 10, 2024
6f234cf
psa_sim: make server ping time much faster
valeriosetti Jun 17, 2024
7bab44e
psasim-server: add function to reset operations slots
valeriosetti Jun 17, 2024
929ab91
Have psa_sim_generate.pl add psa_crypto_close() to psa_sim_crypto_ser…
tom-cosgrove-arm Jun 18, 2024
ff3a7d8
Have psa_sim_serialise.pl generate psa_sim_serialize_reset()
tom-cosgrove-arm Jun 18, 2024
aabb635
psa_sim: improve log prints
valeriosetti Jun 17, 2024
18d990b
Update psa_sim_generate.pl to create the psa_sim_crypto_client.c we want
tom-cosgrove-arm Jun 18, 2024
75aa95b
Update psa_sim_serialise.pl to create the psa_sim_serialise.c we want
tom-cosgrove-arm Jun 18, 2024
7e1e77c
Merge pull request #9279 from valeriosetti/reduce-psasim-ping-interval
minosgalanakis Jun 18, 2024
3f56767
Merge pull request #9247 from ronald-cron-arm/move-psa-headers
ronald-cron-arm Jun 18, 2024
2cb4fd4
Merge pull request #9278 from valeriosetti/fix-psasim-logs
tom-cosgrove-arm Jun 19, 2024
97173fa
Merge pull request #9280 from valeriosetti/psasim-reset-slots-on-disc…
tom-cosgrove-arm Jun 19, 2024
7c288f9
psasim: add support for psa_generate_random()
tom-cosgrove-arm Jun 21, 2024
46bd389
psasim: add support for psa_mac_xxx() functions
tom-cosgrove-arm Jun 21, 2024
f6b7ffa
psasim: add support for psa_cipher_xxx() functions
tom-cosgrove-arm Jun 21, 2024
685d07c
psasim: skip some functions; see _SKIP_FUNCTIONS in generate_psa_wrap…
tom-cosgrove-arm Jun 21, 2024
745024d
psasim: use ser_params and ser_result variable names in client; 'para…
tom-cosgrove-arm Jun 21, 2024
3d21ed7
psasim: psa_key_derivation_verify_bytes() doesn't follow the naming c…
tom-cosgrove-arm Jun 21, 2024
9b4c538
psasim: add the ability to serialise psa_key_production_parameters_t
tom-cosgrove-arm Jun 21, 2024
f60998a
psasim: add support for psa_key_derivation_xxx() and psa_raw_key_agre…
tom-cosgrove-arm Jun 21, 2024
a291f69
psasim: add support for psa_generate_key*() to the simulator
tom-cosgrove-arm Jun 21, 2024
3ba8f2a
psasim: add support for psa_{sign,verify}_{message,hash}() to the sim…
tom-cosgrove-arm Jun 21, 2024
851f6be
psasim: add support for psa_asymmetric_{encrypt,decrypt}() to the sim…
tom-cosgrove-arm Jun 21, 2024
2eaf21a
psasim: add support for key functions that don't need psa_key_attribu…
tom-cosgrove-arm Jun 21, 2024
e3a41e1
psasim: add support for PSA functions that return uint32_t or void
tom-cosgrove-arm Jun 21, 2024
2b8e5ee
psasim: add support for psa_{sign,verify}_hash_xxx() and get/set max ops
tom-cosgrove-arm Jun 21, 2024
7ae688b
psasim: add support for psa_copy_key()
tom-cosgrove-arm Jun 21, 2024
717f46a
psasim: add support for psa_reset_key_attributes()
tom-cosgrove-arm Jun 21, 2024
cae191e
psasim: have the generator script check for type = "void" rather than…
tom-cosgrove-arm Jun 21, 2024
adee928
psasim: merge all AUT programs into a single executable
valeriosetti Jun 24, 2024
7e81be3
psasim: add AUT for psa_generate_random()
valeriosetti Jun 24, 2024
b862807
psasim: add AUT for MAC
valeriosetti Jun 24, 2024
91e70b8
psasim: add AUT for key generation and raw key agreement
valeriosetti Jun 24, 2024
e0fc14f
psasim: add AUT for PSA sign and verify
valeriosetti Jun 24, 2024
1bd0ec2
psasim: add AUT for symmetric encryption/decryption
valeriosetti Jun 24, 2024
503607d
psasim: add AUT for key derivation
valeriosetti Jun 24, 2024
aa0848e
psasim: add AUT for cipher encryption/decryption
valeriosetti Jun 24, 2024
8bbcfdd
psasim: add AUT for asymmetric encryption/decryption
valeriosetti Jun 24, 2024
cdb1834
psasim: fix max line length in generated files
valeriosetti Jun 25, 2024
5dd7492
Adjust build systems
ronald-cron-arm Jun 14, 2024
8e768d6
Merge pull request #9299 from ronald-cron-arm/move-mbedtls-crypto-hea…
ronald-cron-arm Jul 1, 2024
6cf9e2d
psasim: minor fixes to the core
valeriosetti Jun 27, 2024
2ca87d3
psasim: invalidate operations on abort+finish
tom-cosgrove-arm Jun 29, 2024
83e2dd3
psasim: remove sleep on server side to make test as fast as possible
valeriosetti Jul 1, 2024
d676a64
Merge pull request #9328 from valeriosetti/psasim-improvements
tom-cosgrove-arm Jul 2, 2024
a93703b
makefile: allow to build and link test suites against psasim
valeriosetti Jun 27, 2024
4611aea
psasim: update bash scripts
valeriosetti Jun 27, 2024
83161b8
psasim: add a bit of white-box testing to hash operations
tom-cosgrove-arm Jun 29, 2024
bbafd61
Merge pull request #9237 from valeriosetti/issue8968
tom-cosgrove-arm Jul 2, 2024
435bf58
Adapt psasim
ronald-cron-arm Jul 18, 2024
70243b6
Revert "Adapt psasim"
ronald-cron-arm Jul 22, 2024
f42394c
psasim: Fix doorbell file path
ronald-cron-arm Jul 22, 2024
1422da6
psasim: Fix IPCs removal
ronald-cron-arm Jul 22, 2024
9184956
psasim: Move file clean-up to all.sh
ronald-cron-arm Jul 22, 2024
edc36bb
psasim: Rename kill_server.sh to kill_servers.sh
ronald-cron-arm Jul 22, 2024
d849ccd
all.sh: psasim: Start server in tf-psa-crypto/tests
ronald-cron-arm Jul 22, 2024
2183e7e
Merge pull request #9394 from ronald-cron-arm/move-crypto-test-suites
ronald-cron-arm Jul 24, 2024
7126eed
Write output files to the expected directory
gilles-peskine-arm Jul 31, 2024
3d8904e
Parse the actual headers
gilles-peskine-arm Jul 31, 2024
41e2c10
Enhance existing skip mechanism instead of duplicating it
gilles-peskine-arm Aug 1, 2024
ad63291
Remove cruft and update documentation
gilles-peskine-arm Aug 2, 2024
7b31144
Migrate psasim wrappers to psa_custom_key_parameters_t
gilles-peskine-arm Jul 31, 2024
2c23035
Update generated PSA wrappers
gilles-peskine-arm Jul 31, 2024
86a2086
psasim: small fixes to all.sh and test bash scripts
valeriosetti Aug 5, 2024
db72bd7
Merge pull request #9446 from gilles-peskine-arm/psa_generate_key_cus…
gilles-peskine-arm Aug 6, 2024
fd7c8da
Merge pull request #9427 from valeriosetti/psasim-small-fixes
tom-cosgrove-arm Aug 7, 2024
3107d47
Merge pull request #1264 from Mbed-TLS/pre3.6.1_test_merge_upstream_dev
gilles-peskine-arm Aug 12, 2024
bdfee95
Merge pull request #9525 from mpg/dev-mergeback
gilles-peskine-arm Sep 2, 2024
ee1c5fc
Fix failing psasim tests
Harry-Ramsey Oct 7, 2024
9cec1dd
Merge pull request #9653 from Harry-Ramsey/revert-version-features-de…
ronald-cron-arm Oct 9, 2024
51888ad
Fix linking error for mbedtls_test_hook_error_add
Harry-Ramsey Oct 21, 2024
5a88624
Fix formatting issue
Harry-Ramsey Oct 21, 2024
072448d
Add PSA interuptable key agreement APIs
waleed-elmelegy-arm Aug 6, 2024
bf50529
Add required code to psa_sim_generate.pl
paul-elliott-arm Nov 15, 2024
e6cc207
Regenerate PSA Sim headers
paul-elliott-arm Nov 14, 2024
16603e9
Fix paths for programs/psa
Harry-Ramsey Oct 22, 2024
2243e83
Refactor tests and programs comment
Harry-Ramsey Nov 4, 2024
543b5e3
psasim: add support for psa_export_public_key_iop
valeriosetti Mar 3, 2025
fa00b06
psasim: add support for psa_can_do_hash()
valeriosetti Mar 3, 2025
d2aa0c8
Merge pull request #10027 from valeriosetti/md-psa-dispatch-development
gilles-peskine-arm Mar 4, 2025
ba28e95
psasim: update README file
valeriosetti Mar 4, 2025
0ffdaff
tests: psasim: remove references to mbedtls_psa_register_se_key()
valeriosetti Mar 21, 2025
c9e851f
Merge pull request #10050 from valeriosetti/issue8151-development
ronald-cron-arm Mar 26, 2025
5c17808
[development] Remove code relating to MBEDTLS_PSA_INJECT_ENTROPY
felixc-arm Mar 19, 2025
7c03234
Merge pull request #10032 from valeriosetti/psasim-doc-update
mpg Mar 28, 2025
34f8851
Merge pull request #10073 from felixc-arm/remove-inject-entropy
ronald-cron-arm Mar 28, 2025
7282057
psasim: add timeout while waiting for psa_server to start
valeriosetti Apr 8, 2025
699f732
Add __attribute__ ((nonstring)) to remove unterminated-string-initial…
felixc-arm Jun 11, 2025
70cf23a
Replace __attribute__((nonstring)) with macro MBEDTLS_ATTRIBUTE_UNTER…
felixc-arm Jun 12, 2025
0197376
Add include so psasim files can find new macro
felixc-arm Jun 14, 2025
9004f6e
Add explanatory comment above #include "../tf-psa-crypto/core/common.h"
Jun 19, 2025
ccd222a
Remove trailing whitespace
Jun 19, 2025
ac22280
Merge pull request #10216 from felixc-arm/gcc-15-warning-dev
mpg Jun 20, 2025
ad53a64
Update references to tf-psa-crypto/core/common.h
bensze01 Jul 18, 2025
e70bedf
Merge pull request #10309 from bensze01/rename-tf-psa-crypto-common.h
bensze01 Jul 23, 2025
8bfe08d
Update PSASim tests to new call signature
bensze01 Aug 18, 2025
b78f810
Include fixups (headers moves to private directory)
amtkarm1 Jun 16, 2025
0380189
Merge pull request #1426 from gilles-peskine-arm/restricted-mbedtls-m…
gilles-peskine-arm Sep 17, 2025
624c8c4
Add missing include of stdio.h
davidhorstmann-arm Sep 26, 2025
965856f
Merge remote-tracking branch 'restricted/development-restricted' into…
minosgalanakis Oct 11, 2025
8c93b69
Move psasim files into root
minosgalanakis Nov 17, 2025
e186662
Import psasim from MbedTLS
minosgalanakis Nov 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 75 additions & 58 deletions psasim/Makefile
Original file line number Diff line number Diff line change
@@ -1,64 +1,81 @@
CFLAGS ?= -Wall -std=c99
INCLUDE := -I./include/
DESTDIR ?= /usr/local
PREFIX := libpsaff
BUILDDIR ?= bin
CFLAGS += -Wall -Werror -std=c99 -D_XOPEN_SOURCE=1 -D_POSIX_C_SOURCE=200809L

.PHONY: all install test uninstall run docker ci
ifeq ($(DEBUG),1)
override CFLAGS += -DDEBUG -O0 -g
endif

all: libpsaff.so
CLIENT_LIBS := -Lclient_libs -lpsaclient -lmbedtls -lmbedx509 -lmbedcrypto
SERVER_LIBS := -Lserver_libs -lmbedcrypto

libpsaff.so:
$(CC) $(INCLUDE) $(CFLAGS) -c -fpic src/common.c -o common.o
$(CC) $(INCLUDE) $(CFLAGS) -c -fpic src/client.c -o client.o
$(CC) $(INCLUDE) $(CFLAGS) -c -fpic src/service.c -o server.o
$(CC) -shared -o libpsaff.so common.o client.o server.o
MBEDTLS_ROOT_PATH = ../../..
COMMON_INCLUDE := -I./include -I$(MBEDTLS_ROOT_PATH)/include \
-I$(MBEDTLS_ROOT_PATH)/tf-psa-crypto/include \
-I$(MBEDTLS_ROOT_PATH)/tf-psa-crypto/drivers/builtin/include

ifeq ($(DEBUG),1)
CFLAGS += -DDEBUG -g
endif
GENERATED_H_FILES = include/psa_manifest/manifest.h \
include/psa_manifest/pid.h \
include/psa_manifest/sid.h

LIBPSACLIENT_SRC = src/psa_ff_client.c \
src/psa_sim_crypto_client.c \
src/psa_sim_serialise.c
LIBPSACLIENT_OBJS=$(LIBPSACLIENT_SRC:.c=.o)

PSA_CLIENT_BASE_SRC = $(LIBPSACLIENT_SRC) src/client.c

PSA_CLIENT_FULL_SRC = $(LIBPSACLIENT_SRC) \
$(wildcard src/aut_*.c)

PARTITION_SERVER_BOOTSTRAP = src/psa_ff_bootstrap_TEST_PARTITION.c

PSA_SERVER_SRC = $(PARTITION_SERVER_BOOTSTRAP) \
src/psa_ff_server.c \
src/psa_sim_crypto_server.c \
src/psa_sim_serialise.c

.PHONY: all clean client_libs server_libs

all:

test/seedfile:
dd if=/dev/urandom of=./test/seedfile bs=64 count=1

src/%.o: src/%.c $(GENERATED_H_FILES)
$(CC) $(COMMON_INCLUDE) $(CFLAGS) -c $< $(LDFLAGS) -o $@

client_libs/libpsaclient: $(LIBPSACLIENT_OBJS)
mkdir -p client_libs
$(AR) -src client_libs/libpsaclient.a $(LIBPSACLIENT_OBJS)

test/psa_client_base: $(PSA_CLIENT_BASE_SRC) $(GENERATED_H_FILES) test/seedfile
$(CC) $(COMMON_INCLUDE) $(CFLAGS) $(PSA_CLIENT_BASE_SRC) $(CLIENT_LIBS) $(LDFLAGS) -o $@

test/psa_client_full: $(PSA_CLIENT_FULL_SRC) $(GENERATED_H_FILES) test/seedfile
$(CC) $(COMMON_INCLUDE) $(CFLAGS) $(PSA_CLIENT_FULL_SRC) $(CLIENT_LIBS) $(LDFLAGS) -o $@

test/psa_server: $(PSA_SERVER_SRC) $(GENERATED_H_FILES)
$(CC) $(COMMON_INCLUDE) $(CFLAGS) $(PSA_SERVER_SRC) $(SERVER_LIBS) $(LDFLAGS) -o $@

$(PARTITION_SERVER_BOOTSTRAP) $(GENERATED_H_FILES): src/manifest.json src/server.c
tools/psa_autogen.py src/manifest.json

# Build MbedTLS libraries (crypto, x509 and tls) and copy them locally to
# build client/server applications.
#
# Note: these rules assume that mbedtls_config.h is already configured by all.sh.
# If not using all.sh then the user must do it manually.
client_libs: client_libs/libpsaclient
client_libs server_libs:
$(MAKE) -C $(MBEDTLS_ROOT_PATH)/library CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" libmbedcrypto.a libmbedx509.a libmbedtls.a
mkdir -p $@
cp $(MBEDTLS_ROOT_PATH)/library/libmbed*.a $@/

clean:
rm -rf $(BUILDDIR)
rm -f *.so *.o
rm -rf test/*dSYM
cd test && make clean

test:
cd test && make

test/partition:
cd test && make

run: test/partition
pkill partition || true
pkill client || true
ipcs | grep q | awk '{ printf " -q " $$2 }' | xargs ipcrm > /dev/null 2>&1 || true
(sleep 3 && ./test/client)&
./test/partition

ci:
pkill client || true
ipcs | grep q | awk '{ printf " -q " $$2 }' | xargs ipcrm > /dev/null 2>&1 || true
./test/partition 2>&1 &
sleep 3 && ./test/client
pkill partition || true

docker:
@docker run --rm -ti -v $$PWD:/opt --entrypoint /bin/bash ubuntu \
-c "cd /opt && ls && apt-get update -qq && apt install \
-y gcc make gdb python -qq && make clean && make install && make test && ldconfig && make run"

install: libpsaff.so
mkdir -p $(DESTDIR)/lib
mkdir -p $(DESTDIR)/include
cp libpsaff.so $(DESTDIR)/lib/
cp -r include/* $(DESTDIR)/include/
cp tools/psa_autogen /usr/local/bin/

uninstall:
rm $(DESTDIR)/lib/libpsaff.so
rm -rf $(DESTDIR)/include/psa
rm -rf $(DESTDIR)/include/psasim
rm -f /usr/local/bin/psa_autogen
clean_server_intermediate_files:
rm -f $(PARTITION_SERVER_BOOTSTRAP)
rm -rf include/psa_manifest

clean: clean_server_intermediate_files
rm -f test/psa_client_base test/psa_client_full test/psa_server
rm -rf client_libs server_libs
rm -f test/psa_service_* test/psa_notify_* test/*.log
rm -f test/seedfile
76 changes: 29 additions & 47 deletions psasim/README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,42 @@
# psasim

This tool simulates a PSA Firmware Framework implementation.
It allows you to develop secure partitions and their clients on a desktop computer.
It should be able to run on all systems that support POSIX and System V IPC:
e.g. macOS, Linux, FreeBSD, and perhaps Windows 10 WSL2.
PSASIM holds necessary C source and header files which allows to test Mbed TLS in a "pure crypto client" scenario, i.e `MBEDTLS_PSA_CRYPTO_CLIENT && !MBEDTLS_PSA_CRYPTO_C`.
In practical terms it means that this allow to build PSASIM with Mbed TLS sources and get 2 Linux applications, a client and a server, which are connected through Linux's shared memeory, and in which the client relies on the server to perform all PSA Crypto operations.

Please note that the code in this directory is maintained by the Mbed TLS / PSA Crypto project solely for the purpose of testing the use of Mbed TLS with client/service separation. We do not recommend using this code for any other purpose. In particular:
The goal of PSASIM is _not_ to provide a ready-to-use solution for anyone looking to implement the pure crypto client structure (see [Limitations](#limitations) for details), but to provide an example of TF-PSA-Crypto RPC (Remote Procedure Call) implementation using Mbed TLS.
## Limitations

* This simulator is not intended to pass or demonstrate compliance.
* This code is only intended for simulation and does not have any security goals. It does not isolate services from clients.
In the current implementation:

## Building
- Only Linux PC is supported.
- There can be only 1 client connected to 1 server.
- Shared memory is the only communication medium allowed. Others can be implemented (ex: net sockets), but in terms of simulation speed shared memory proved to be the fastest.
- Server is not secure at all: keys and operation structs are stored on the RAM, so they can easily be dumped.

To build and run the test program make sure you have `make`, `python` and a
C compiler installed and then enter the following commands:
## Testing

```sh
make install
make run
```
Please refer to `tests/scripts/components-psasim.sh` for guidance on how to build & test PSASIM:

On Linux you may need to run `ldconfig` to ensure the library is properly installed.
- `component_test_psasim()`: builds the server and a couple of test clients which are used to evaluate some basic PSA Crypto API commands.
- `component_test_suite_with_psasim()`: builds the server and _all_ the usual test suites (those found under the `<mbedtls-root>/tests/suites/*` folder) which are used by the CI and runs them. A small subset of test suites (`test_suite_constant_time_hmac`,`test_suite_lmots`,`test_suite_lms`) are being skipped, for CI turnover time optimization. They can be run locally if required.

An example pair of programs is included in the `test` directory.
## How to update automatically generated files

## Features
A significant portion of the intermediate code of PSASIM is auto-generated using Perl. In particular:

The implemented API is intended to be compliant with PSA-FF 1.0.0 with the exception of a couple of things that are a work in progress:
- `psa_sim_serialise.[c|h]`:
- Generated by `psa_sim_serialise.pl`.
- These files provide the serialisation/deserialisation support that is required to pass functions' parameters between client and server.
- `psa_sim_crypto_[client|server].c` and `psa_functions_codes.h`:
- Generated by `psa_sim_generate.pl`.
- `psa_sim_crypto_[client|server].c` provide interfaces for PSA Crypto APIs on client and server sides, while `psa_functions_codes.h` simply enumerates all PSA Crypto APIs.

* `psa_notify` support
* "strict" policy in manifest
These files need to be regenerated whenever some PSA Crypto API is added/deleted/modified. The procedure is as follows:

The only supported "interrupts" are POSIX signals, which act
as a "virtual interrupt".

The standard PSA RoT APIs are not included (e.g. cryptography, attestation, lifecycle etc).

## Design

The code is designed to be readable rather than fast or secure.
In this implementation only one message is delivered to a
RoT service at a time.
The code is not thread-safe.

To debug the simulator enable the debug flag:

```sh
make DEBUG=1 install
```

## Unsupported features

Because this is a simulator there are a few things that
can't be reasonably emulated:

* Manifest MMIO regions are unsupported
* Manifest priority field is ignored
* Partition IDs are in fact POSIX `pid_t`, which are only assigned at runtime,
making it infeasible to populate pid.h with correct values.
- `psa_sim_serialise.[c|h]`:
- go to `<mbedtls-root>/tests/psa-client-server/psasim/src/`
- run `./psa_sim_serialise.pl h > psa_sim_serialise.h`
- run `./psa_sim_serialise.pl c > psa_sim_serialise.c`
- `psa_sim_crypto_[client|server].c` and `psa_functions_codes.h`:
- go to Mbed TLS' root folder
- run `./tests/psa-client-server/psasim/src/psa_sim_generate.pl`
75 changes: 75 additions & 0 deletions psasim/include/client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* PSA Firmware Framework client header for psasim. */

/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/

#ifndef __PSA_CLIENT_H__
#define __PSA_CLIENT_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stddef.h>

#include "psa/crypto.h"

#include "error_ext.h"
/*********************** PSA Client Macros and Types *************************/

#define PSA_FRAMEWORK_VERSION (0x0100)

#define PSA_VERSION_NONE (0)

/* PSA response types */
#define PSA_CONNECTION_REFUSED PSA_ERROR_CONNECTION_REFUSED
#define PSA_CONNECTION_BUSY PSA_ERROR_CONNECTION_BUSY
#define PSA_DROP_CONNECTION PSA_ERROR_PROGRAMMER_ERROR

/* PSA message handles */
#define PSA_NULL_HANDLE ((psa_handle_t) 0)

#define PSA_HANDLE_IS_VALID(handle) ((psa_handle_t) (handle) > 0)
#define PSA_HANDLE_TO_ERROR(handle) ((psa_status_t) (handle))

/**
* A read-only input memory region provided to an RoT Service.
*/
typedef struct psa_invec {
const void *base;
size_t len;
} psa_invec;

/**
* A writable output memory region provided to an RoT Service.
*/
typedef struct psa_outvec {
void *base;
size_t len;
} psa_outvec;

/*************************** PSA Client API **********************************/

uint32_t psa_framework_version(void);

uint32_t psa_version(uint32_t sid);

psa_handle_t psa_connect(uint32_t sid, uint32_t version);

psa_status_t psa_call(psa_handle_t handle,
int32_t type,
const psa_invec *in_vec,
size_t in_len,
psa_outvec *out_vec,
size_t out_len);

void psa_close(psa_handle_t handle);

#ifdef __cplusplus
}
#endif

#endif /* __PSA_CLIENT_H__ */
52 changes: 52 additions & 0 deletions psasim/include/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Common definitions used for clients and services */

/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/

#ifndef _COMMON_H_
#define _COMMON_H_

#include <stdint.h>
#include <stddef.h>

/* Increasing this might break on some platforms */
#define MAX_FRAGMENT_SIZE 200

#define CONNECT_REQUEST 1
#define CALL_REQUEST 2
#define CLOSE_REQUEST 3
#define VERSION_REQUEST 4
#define READ_REQUEST 5
#define READ_RESPONSE 6
#define WRITE_REQUEST 7
#define WRITE_RESPONSE 8
#define SKIP_REQUEST 9
#define PSA_REPLY 10

#define NON_SECURE (1 << 30)

typedef int32_t psa_handle_t;

#define PSA_MAX_IOVEC (4u)

#define PSA_IPC_CALL (0)

struct message_text {
int qid;
int32_t psa_type;
char buf[MAX_FRAGMENT_SIZE];
};

struct message {
long message_type;
struct message_text message_text;
};

typedef struct vector_sizes {
size_t invec_sizes[PSA_MAX_IOVEC];
size_t outvec_sizes[PSA_MAX_IOVEC];
} vector_sizes_t;

#endif /* _COMMON_H_ */
19 changes: 19 additions & 0 deletions psasim/include/error_ext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* PSA status codes used by psasim. */

/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/

#ifndef PSA_ERROR_H
#define PSA_ERROR_H

#include <stdint.h>

#include "common.h"

#define PSA_ERROR_PROGRAMMER_ERROR ((psa_status_t) -129)
#define PSA_ERROR_CONNECTION_REFUSED ((psa_status_t) -130)
#define PSA_ERROR_CONNECTION_BUSY ((psa_status_t) -131)

#endif
15 changes: 15 additions & 0 deletions psasim/include/init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Declarations of internal functions. */

/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/

#include <stdint.h>
#include <service.h>
void raise_signal(psa_signal_t signal);
void __init_psasim(const char **array,
int size,
const int allow_ns_clients_array[32],
const uint32_t versions[32],
const int strict_policy_array[32]);
Loading