Browse Source

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 <jukkax@ssrc.tii.ae>
master
Jukka Laitinen 3 years ago committed by Daniel Agar
parent
commit
c2cbab1e98
  1. 5
      boards/px4/fmu-v5/cryptotest.px4board
  2. 47
      src/drivers/stub_keystore/CMakeLists.txt
  3. 20
      src/drivers/stub_keystore/Kconfig

5
boards/px4/fmu-v5/cryptotest.px4board

@ -0,0 +1,5 @@ @@ -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"

47
src/drivers/stub_keystore/CMakeLists.txt

@ -36,34 +36,33 @@ px4_add_library(keystore_backend stub_keystore.c) @@ -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()

20
src/drivers/stub_keystore/Kconfig

@ -1,6 +1,24 @@ @@ -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

Loading…
Cancel
Save