From c2cbab1e9845b0e8abdc026e7939b49244e57e14 Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Fri, 8 Oct 2021 14:25:16 +0300 Subject: [PATCH] Improve stub_keystore configuration It is possible to either set the keyfile locations in board configuration or with the same environment variables as before. Signed-off-by: Jukka Laitinen --- boards/px4/fmu-v5/cryptotest.px4board | 5 +++ src/drivers/stub_keystore/CMakeLists.txt | 47 ++++++++++++------------ src/drivers/stub_keystore/Kconfig | 20 +++++++++- 3 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 boards/px4/fmu-v5/cryptotest.px4board diff --git a/boards/px4/fmu-v5/cryptotest.px4board b/boards/px4/fmu-v5/cryptotest.px4board new file mode 100644 index 0000000000..274e5b45ca --- /dev/null +++ b/boards/px4/fmu-v5/cryptotest.px4board @@ -0,0 +1,5 @@ +CONFIG_BOARD_CRYPTO=y +CONFIG_DRIVERS_SW_CRYPTO=y +CONFIG_DRIVERS_STUB_KEYSTORE=y +CONFIG_PUBLIC_KEY0="../../../Tools/test_keys/key0.pub" +CONFIG_PUBLIC_KEY1="../../../Tools/test_keys/rsa2048.pub" diff --git a/src/drivers/stub_keystore/CMakeLists.txt b/src/drivers/stub_keystore/CMakeLists.txt index da58ec3079..ecbac32daa 100644 --- a/src/drivers/stub_keystore/CMakeLists.txt +++ b/src/drivers/stub_keystore/CMakeLists.txt @@ -36,34 +36,33 @@ px4_add_library(keystore_backend stub_keystore.c) target_include_directories(keystore_backend PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -if(DEFINED ENV{PUBLIC_KEY0}) - add_definitions(-DPUBLIC_KEY0=$ENV{PUBLIC_KEY0}) -endif() +# Parse keyfile locations from boardconfig -if(DEFINED ENV{PUBLIC_KEY1}) - add_definitions(-DPUBLIC_KEY1=$ENV{PUBLIC_KEY1}) -endif() +# If the key file path is defined in environment variable, use it from there +# else, if it is hardcoded in CONFIG_PUBLIC_KEYx, use that -if(DEFINED ENV{PUBLIC_KEY2}) - add_definitions(-DPUBLIC_KEY2=$ENV{PUBLIC_KEY2}) -endif() +file(STRINGS ${BOARD_CONFIG} ConfigContents) +foreach(NameAndValue ${ConfigContents}) +# Strip leading spaces + string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) -if(DEFINED ENV{PUBLIC_KEY3}) - add_definitions(-DPUBLIC_KEY3=$ENV{PUBLIC_KEY3}) -endif() + # Find variable name + string(REGEX MATCH "^CONFIG_PUBLIC_KEY[^=]+" Name ${NameAndValue}) -if(DEFINED ENV{PUBLIC_KEY4}) - add_definitions(-DPUBLIC_KEY4=$ENV{PUBLIC_KEY4}) -endif() + if(Name) + string(REPLACE "${Name}=" "" Value ${NameAndValue}) + string(REPLACE "\"" "" Value ${Value}) -if(DEFINED ENV{PUBLIC_KEY5}) - add_definitions(-DPUBLIC_KEY5=$ENV{PUBLIC_KEY5}) -endif() + # Strip CONFIG_ + string(REPLACE "CONFIG_" "" Name ${Name}) -if(DEFINED ENV{PUBLIC_KEY6}) - add_definitions(-DPUBLIC_KEY6=$ENV{PUBLIC_KEY6}) -endif() + # Get the value from env variable, if set + if(DEFINED ENV{${Name}}) + set(Value $ENV{${Name}}) + endif() -if(DEFINED ENV{PUBLIC_KEY7}) - add_definitions(-DPUBLIC_KEY7=$ENV{PUBLIC_KEY7}) -endif() + if(NOT Value STREQUAL "") + add_definitions(-D${Name}=${Value}) + endif() + endif() +endforeach() diff --git a/src/drivers/stub_keystore/Kconfig b/src/drivers/stub_keystore/Kconfig index b2f1f08185..4681bd7c84 100644 --- a/src/drivers/stub_keystore/Kconfig +++ b/src/drivers/stub_keystore/Kconfig @@ -1,6 +1,24 @@ -menuconfig DRIVERS_STUB_KEYSTORE +menu "stub_keystore configuration" + menuconfig DRIVERS_STUB_KEYSTORE bool "stub_keystore" depends on DRIVERS_SW_CRYPTO default n ---help--- Enable support for stub_keystore + + menuconfig PUBLIC_KEY0 + string "Path to public key 0" + depends on DRIVERS_STUB_KEYSTORE + + menuconfig PUBLIC_KEY1 + string "Path to public key 1" + depends on DRIVERS_STUB_KEYSTORE + + menuconfig PUBLIC_KEY2 + string "Path to public key 2" + depends on DRIVERS_STUB_KEYSTORE + + menuconfig PUBLIC_KEY3 + string "Path to public key 3" + depends on DRIVERS_STUB_KEYSTORE +endmenu