Skip to content

Commit e2d5268

Browse files
committed
Throw a warning when using the example signing/encryption keys
This is automatically disabled for pico-examples, and can be manually disabled by setting PICO_ALLOW_EXAMPLE_KEYS
1 parent b1676c1 commit e2d5268

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

tools/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,28 @@ function(picotool_check_configurable TARGET)
153153
endif()
154154
endfunction()
155155

156+
# Compare 2 key files, used by picotool_check_default_keys
157+
function(picotool_compare_keys TARGET KEY DEFAULT TYPE)
158+
if (KEY)
159+
execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files "${KEY}" "${PICO_SDK_PATH}/tools/example_keys/${DEFAULT}"
160+
RESULT_VARIABLE compare_result
161+
)
162+
if(compare_result EQUAL 0)
163+
message(WARNING "${TARGET} is using a default ${TYPE} key - this must be changed before production")
164+
endif()
165+
endif()
166+
endfunction()
167+
168+
# Check if default signing/encryption keys are being used
169+
function(picotool_check_default_keys TARGET)
170+
get_target_property(picotool_sigfile ${TARGET} PICOTOOL_SIGFILE)
171+
picotool_compare_keys(${TARGET} ${picotool_sigfile} private.pem "signing")
172+
get_target_property(picotool_aesfile ${TARGET} PICOTOOL_AESFILE)
173+
picotool_compare_keys(${TARGET} ${picotool_aesfile} privateaes.bin "encryption")
174+
get_target_property(picotool_enc_sigfile ${TARGET} PICOTOOL_ENC_SIGFILE)
175+
picotool_compare_keys(${TARGET} ${picotool_enc_sigfile} private.pem "encrypted signing")
176+
endfunction()
177+
156178
# Generate pio header and include it in the build
157179
# PICO_CMAKE_CONFIG: PICO_DEFAULT_PIOASM_OUTPUT_FORMAT, Default output format used by pioasm when using pico_generate_pio_header, type=string, default=c-sdk, group=build
158180
function(pico_generate_pio_header TARGET)
@@ -449,6 +471,17 @@ function(picotool_postprocess_binary TARGET)
449471
set_target_properties(${TARGET} PROPERTIES
450472
PICOTOOL_PROCESSING_CONFIGURED true
451473
)
474+
475+
# Allow using the example keys for pico-examples
476+
if ((NOT DEFINED PICO_ALLOW_EXAMPLE_KEYS) AND (DEFINED PICO_EXAMPLES_PATH))
477+
set(PICO_ALLOW_EXAMPLE_KEYS 1)
478+
endif()
479+
480+
# PICO_CMAKE_CONFIG: PICO_ALLOW_EXAMPLE_KEYS, Don't throw warning when using default signing/encryption keys, type=bool, default=0, group=build
481+
if (NOT PICO_ALLOW_EXAMPLE_KEYS)
482+
picotool_check_default_keys(${TARGET})
483+
endif()
484+
452485
# Read target properties
453486
get_target_property(picotool_sign_output ${TARGET} PICOTOOL_SIGN_OUTPUT)
454487
if (picotool_sign_output)

tools/example_keys/private.pem

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-----BEGIN EC PARAMETERS-----
2+
BgUrgQQACg==
3+
-----END EC PARAMETERS-----
4+
-----BEGIN EC PRIVATE KEY-----
5+
MHQCAQEEIAXAdiilH8wT07TESUzWPt+BY9+NcchvYU3xbnpK+CBNoAcGBSuBBAAK
6+
oUQDQgAEYYJtMQFGW4AB94tU3u/Qir5sRcYjBYMqCa+8gxsYd9OwMS3dqWKsnVBz
7+
dyy7bFWdJzXDMb9o20xRRd57Q9xSYw==
8+
-----END EC PRIVATE KEY-----

tools/example_keys/privateaes.bin

128 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)