Compare commits

..

22 commits

Author SHA1 Message Date
Pol Henarejos
16d4d0d26e
Update README with up-to-date info.
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Emulation and test / build (push) Has been cancelled
Emulation and test / test (pkcs11) (push) Has been cancelled
Emulation and test / test (pytest) (push) Has been cancelled
Emulation and test / test (sc-hsm-pkcs11) (push) Has been cancelled
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2026-01-06 21:20:13 +01:00
Pol Henarejos
380ff7afa4
Upgrade to v6.2
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Emulation and test / build (push) Waiting to run
Emulation and test / test (pkcs11) (push) Blocked by required conditions
Emulation and test / test (pytest) (push) Blocked by required conditions
Emulation and test / test (sc-hsm-pkcs11) (push) Blocked by required conditions
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2026-01-05 19:54:07 +01:00
Pol Henarejos
60dafec2e8
Upgrade Pico Keys SDK to v8.2
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2026-01-05 19:51:51 +01:00
Pol Henarejos
3207fe3451
Disable button press by default since LED may not be properly configured until it is commissioned.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2026-01-05 19:40:50 +01:00
Pol Henarejos
6914be4fea
Fix build.
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Emulation and test / build (push) Has been cancelled
Emulation and test / test (pkcs11) (push) Has been cancelled
Emulation and test / test (pytest) (push) Has been cancelled
Emulation and test / test (sc-hsm-pkcs11) (push) Has been cancelled
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-29 20:36:55 +01:00
Pol Henarejos
7d551f6fea
Blink led three times to acknowledge proper commissioning.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-29 20:17:03 +01:00
Pol Henarejos
d3a7ff425a
Fix pimoroni led
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Emulation and test / build (push) Waiting to run
Emulation and test / test (pkcs11) (push) Blocked by required conditions
Emulation and test / test (pytest) (push) Blocked by required conditions
Emulation and test / test (sc-hsm-pkcs11) (push) Blocked by required conditions
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-27 22:03:47 +01:00
Pol Henarejos
97e7303505
Move pointer
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-26 20:00:59 +01:00
Pol Henarejos
e41f2ba712
Releaser is available up to 6.7.0
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-26 19:54:15 +01:00
Pol Henarejos
710eb70af7
Update reamde & usage.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-13 23:36:43 +01:00
Pol Henarejos
9dbd764c8c
Reset by recopying memory file.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-13 21:12:45 +01:00
Pol Henarejos
feec958d10
Not used
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-11 20:05:08 +01:00
Pol Henarejos
9720bcfd4b
Fix build
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-11 19:59:39 +01:00
Pol Henarejos
4bb81f5b25
Build only necessary boards.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-11 19:56:01 +01:00
Pol Henarejos
c9926a71d1
Do not call pytest
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-11 19:48:23 +01:00
Pol Henarejos
10c25b6a3a
Update pointer.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-11 19:36:06 +01:00
Pol Henarejos
629f14ab0d
Revert "Move EDDSA to another branch."
This reverts commit a0faf5308e.
2025-12-11 19:35:27 +01:00
Pol Henarejos
4d6f6e4635
Revert "Move Secure Boot to another branch."
This reverts commit 8978456524.
2025-12-11 19:35:20 +01:00
Pol Henarejos
8e35104695
Update memory.flash for tests
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-10 00:20:28 +01:00
Pol Henarejos
82f4b2201c
Remove printf
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-09 21:38:15 +01:00
Pol Henarejos
8978456524
Move Secure Boot to another branch.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-09 21:37:52 +01:00
Pol Henarejos
a0faf5308e
Move EDDSA to another branch.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-12-09 15:49:20 +01:00
12 changed files with 19 additions and 68 deletions

View file

@ -34,7 +34,7 @@ jobs:
- name: Delete private key
run: rm private.pem
- name: Update nightly release
uses: pyTooling/Actions/releaser@main
uses: pyTooling/Actions/releaser@v6.7.0
with:
tag: nightly-${{ matrix.refs }}
rm: true

View file

@ -162,10 +162,10 @@ Secure Lock restricts the device to the manufacturers firmware only, locking
Pico HSM also supports ESP32-S3 boards, which add secure storage, flash encryption and secure boot.
### > Dynamic VID/PID
Supports setting VID & PID on-the-fly. Use `pico-hsm-tool.py` or [Pico Commissioner](https://www.picokeys.com/pico-commissioner/ "Pico Commissioner") for specify VID/PID values and reboot the device.
Supports setting VID & PID on-the-fly. U
### > Rescue Pico HSM Tool and Commissioner
Pico HSM Tool implements a new CCID stack to rescue the Pico HSM in case it has wrong VID/PID values and it is not recognized by the OS. It can be accessed through `pico-hsm-tool.py` or [Pico Commissioner](https://www.picokeys.com/pico-commissioner/ "Pico Commissioner").
### > Rescue Pico HSM
Pico HSM Tool implements a new CCID stack to rescue the Pico HSM in case it has wrong VID/PID values and it is not recognized by the OS.
## Security considerations
All secret keys (both asymmetric and symmetric) are encrypted and stored in the flash memory. The MKEK, a 256-bit AES key, is used to protect these private and secret keys. Keys are held in RAM only during signature and decryption operations, and are loaded and cleared each time to avoid potential security vulnerabilities.
@ -179,26 +179,16 @@ In the event that the Pico is stolen, the private and secret key contents cannot
### RP2350 and ESP32-S3
RP2350 and ESP32-S3 microcontrollers are equipped with advanced security features, including Secure Boot and Secure Lock, ensuring that firmware integrity and authenticity are tightly controlled. Both devices support the storage of the Master Key Encryption Key (MKEK) in an OTP (One-Time Programmable) memory region, making it permanently inaccessible for external access or tampering. This secure, non-volatile region guarantees that critical security keys are embedded into the hardware, preventing unauthorized access and supporting robust defenses against code injection or firmware modification. Together, Secure Boot and Secure Lock enforce firmware authentication, while the MKEK in OTP memory solidifies the foundation for secure operations.
### Secure Boot
Secure Boot is a security feature that ensures that only trusted firmware, verified through digital signatures, can be loaded onto the device during the boot process. Once enabled, Secure Boot checks every piece of firmware against a cryptographic signature before execution, rejecting any unauthorized or modified code. This prevents malicious firmware from compromising the devices operation and integrity. With Secure Boot activated, only firmware versions signed by a trusted authority, such as the device manufacturer, will be accepted, ensuring the device remains protected from unauthorized software modifications. **This is irreversible. Once enabled, it CANNOT be disabled.**
**IMPORTANT:** For users wishing to develop and compile custom firmware, a private-public key pair is essential. Activating Secure Boot requires users to generate and manage their own unique private-public key pair. The public key from this pair must be embedded into the device to validate all firmware. Firmware will not boot without a proper digital signature from this key pair. This means that users must sign all future firmware versions with their private key and embed the public key in the device to ensure compatibility.
### Secure Lock
Secure Lock builds on Secure Boot by imposing an even stricter security model. Once activated, Secure Lock prevents any further installation of new boot keys, effectively locking the device to only run firmware that is authorized by the device's primary vendor—in this case, Pico Keys. In addition to preventing additional keys, Secure Lock disables debugging interfaces and puts additional safeguards in place to resist tampering and intrusion attempts. This ensures that the device operates exclusively with the original vendors firmware and resists unauthorized access, making it highly secure against external threats. **This is irreversible. Once enabled, it CANNOT be disabled.**
**IMPORTANT:** Activating Secure Lock not only enables Secure Boot but also invalidates all keys except the official Pico Key. This means that only firmware signed by Pico Key will be recognized, and custom code will no longer be allowed. Once enabled, the Pico Key device will run solely on the official firmware available on the website, with no option for generating or compiling new code for the device.
## Download
**If you own an ESP32-S3 board, go to [ESP32 Flasher](https://www.picokeys.com/esp32-flasher/) for flashing your Pico HSM.**
If you own a Raspberry Pico (RP2040 or RP2350), go to [Download page](https://www.picokeys.com/getting-started/), select your vendor and model and download the proper firmware; or go to [Release page](https://www.github.com/polhenarejos/pico-hsm/releases/) and download the UF2 file for your board.
If you own a Raspberry Pico (RP2040 or RP2350), go to [Download page](https://www.picokeys.com/getting-started/). If your board is mounted with the RP2040, then select Pico. If your board is mounted with the RP2350 or RP2354, select Pico2.
Note that UF2 files are shiped with a dummy VID/PID to avoid license issues (FEFF:FCFD). If you plan to use it with OpenSC or similar tools, you should modify Info.plist of CCID driver to add these VID/PID or use the [Pico Commissioner](https://www.picokeys.com/pico-commissioner/ "Pico Commissioner").
Note that UF2 files are shiped with a dummy VID/PID to avoid license issues (FEFF:FCFD). If you plan to use it with OpenSC or similar tools, you should modify Info.plist of CCID driver to add these VID/PID or use the [PicoKey App](https://www.picokeys.com/picokeyapp/ "PicoKey App").
You can use whatever VID/PID (i.e., 234b:0000 from FISJ), but remember that you are not authorized to distribute the binary with a VID/PID that you do not own.
Note that the pure-browser option [Pico Commissioner](https://www.picokeys.com/pico-commissioner/ "Pico Commissioner") is the most recommended.
Note that the [PicoKey App](https://www.picokeys.com/picokeyapp/ "PicoKey App") is the most recommended.
## Build for Raspberry Pico
Before building, ensure you have installed the toolchain for the Pico and the Pico SDK is properly located in your drive.
@ -345,12 +335,6 @@ Communication with the Pico HSM follows the same protocols and methods used with
For advanced usage scenarios, refer to the documentation and examples provided. Additionally, the Pico HSM supports the SCS3 tool for more sophisticated operations and includes features like multiple key domains. For detailed information on SCS3 usage, refer to [SCS3 documentation](/doc/scs3.md).
### Important
OpenSC relies on PCSC driver, which reads a list (`Info.plist`) that contains a pair of VID/PID of supported readers. In order to be detectable, you have several options:
- Use `pico-hsm-tool.py` to modify VID/PID on-the-fly.
- Use the pure-browser online [Pico Commissioner](https://www.picokeys.com/pico-commissioner/ "Pico Commissioner") that commissions the Pico Key on-the-fly without external tools.
- Build and configure the project with the proper VID/PID with `USB_VID` and `USB_PID` parameters in `CMake` (see [Build section](#build "Build section")). Note that you cannot distribute the patched/compiled binary if you do not own the VID/PID or have an explicit authorization.
## License and Commercial Use
This project is available under two editions:

View file

@ -1,48 +1,25 @@
#!/bin/bash
VERSION_MAJOR="6"
VERSION_MINOR="0"
NO_EDDSA=0
VERSION_MINOR="2"
SUFFIX="${VERSION_MAJOR}.${VERSION_MINOR}"
#if ! [[ -z "${GITHUB_SHA}" ]]; then
# SUFFIX="${SUFFIX}.${GITHUB_SHA}"
#fi
if [[ $1 == "--no-eddsa" ]]; then
NO_EDDSA=1
echo "Skipping EDDSA build"
fi
mkdir -p build_release
mkdir -p release
mkdir -p release_eddsa
rm -rf -- release/*
if [[ $NO_EDDSA -eq 0 ]]; then
rm -rf -- release_eddsa/*
fi
cd build_release
PICO_SDK_PATH="${PICO_SDK_PATH:-../../pico-sdk}"
SECURE_BOOT_PKEY="${SECURE_BOOT_PKEY:-../../ec_private_key.pem}"
board_dir=${PICO_SDK_PATH}/src/boards/include/boards
for board in "$board_dir"/*
boards=("pico" "pico2")
for board_name in "${boards[@]}"
do
board_name="$(basename -- "$board" .h)"
rm -rf -- ./*
PICO_SDK_PATH="${PICO_SDK_PATH}" cmake .. -DPICO_BOARD=$board_name -DSECURE_BOOT_PKEY=${SECURE_BOOT_PKEY}
make -j`nproc`
mv pico_hsm.uf2 ../release/pico_hsm_$board_name-$SUFFIX.uf2
done
# Build with EDDSA
if [[ $NO_EDDSA -eq 0 ]]; then
for board in "$board_dir"/*
do
board_name="$(basename -- "$board" .h)"
rm -rf -- ./*
PICO_SDK_PATH="${PICO_SDK_PATH}" cmake .. -DPICO_BOARD=$board_name -DSECURE_BOOT_PKEY=${SECURE_BOOT_PKEY} -DENABLE_EDDSA=1
make -j`nproc`
mv pico_hsm.uf2 ../release_eddsa/pico_hsm_$board_name-$SUFFIX-eddsa1.uf2
done
fi

View file

@ -28,9 +28,9 @@ PIN=648219
[^1]: `openssl version -a` will return the `OPENSSLDIR`, which contains `openssl.cnf` file and `ENGINESDIR`, which contains the p11 engine.
## Initialization
The first step is to initialize the HSM. To do so, use the `pico-hsm-tool.py` in `tools` folder:
The first step is to initialize the HSM. To do so, use:
```
$ python3 tools/pico-hsm-tool.py --pin 648219 initialize --so-pin 57621880
$ sc-hsm-tool --initialize --so-pin 3537363231383830 --pin 648219
```
The PIN number is used to manage all private keys in the device. It supports three attemps. After the third PIN failure, it gets blocked.
The PIN accepts from 6 to 16 characters.

@ -1 +1 @@
Subproject commit d0dea3d0c5427549ad56c284a2011d5b3eea42e0
Subproject commit 263e554cc6c59a5f168f8589c4bdabe6e1e64c25

View file

@ -47,9 +47,6 @@ int cmd_keypair_gen() {
if (asn1_find_tag(&ctxo, 0x2, &ks) && asn1_len(&ks) > 0) {
key_size = asn1_get_uint(&ks);
}
printf("KEYPAIR RSA %lu (%lx)\n",
(unsigned long) key_size,
(unsigned long) exponent);
mbedtls_rsa_context rsa;
mbedtls_rsa_init(&rsa);
uint8_t index = 0;
@ -74,7 +71,6 @@ int cmd_keypair_gen() {
return SW_WRONG_DATA();
}
mbedtls_ecp_group_id ec_id = ec_get_curve_from_prime(prime.data, prime.len);
printf("KEYPAIR ECC %d\n", ec_id);
if (ec_id == MBEDTLS_ECP_DP_NONE) {
return SW_FUNC_NOT_SUPPORTED();
}
@ -92,7 +88,6 @@ int cmd_keypair_gen() {
}
#endif
}
printf("KEYPAIR ECC %d\r\n", ec_id);
mbedtls_ecdsa_context ecdsa;
mbedtls_ecdsa_init(&ecdsa);
uint8_t index = 0;

View file

@ -305,9 +305,6 @@ int cmd_signature() {
mbedtls_ecp_keypair_free(&hd_context);
return SW_INCORRECT_PARAMS();
}
if (wait_button_pressed() == true) { // timeout
return SW_SECURE_MESSAGE_EXEC_ERROR();
}
md = MBEDTLS_MD_SHA256;
if (mbedtls_ecdsa_write_signature(&hd_context, md, apdu.data, apdu.nc, buf,
MBEDTLS_ECDSA_MAX_LEN,

View file

@ -18,7 +18,7 @@
#ifndef __VERSION_H_
#define __VERSION_H_
#define HSM_VERSION 0x0600
#define HSM_VERSION 0x0602
#define HSM_VERSION_MAJOR ((HSM_VERSION >> 8) & 0xff)
#define HSM_VERSION_MINOR (HSM_VERSION & 0xff)

View file

@ -36,10 +36,6 @@ RUN make install
RUN make clean
RUN ldconfig
WORKDIR /
RUN git clone https://github.com/polhenarejos/pypicohsm.git
WORKDIR /pypicohsm
RUN pip3 install .
WORKDIR /
RUN git clone https://github.com/CardContact/sc-hsm-embedded
WORKDIR /sc-hsm-embedded
RUN autoreconf -fi

Binary file not shown.

View file

@ -37,7 +37,9 @@ gen_and_delete() {
test $? -eq 0 && echo -n "." || exit $?
}
reset() {
python3 tools/pico-hsm-tool.py --pin 648219 initialize --so-pin 57621880 --silent --no-dev-cert > /dev/null 2>&1
#python3 tools/pico-hsm-tool.py --pin 648219 initialize --so-pin 57621880 --silent --no-dev-cert > /dev/null 2>&1
rm -f memory.flash
tar -xf tests/memory.tar.gz
test $? -eq 0 || exit $?
}

View file

@ -2,4 +2,4 @@
source ./tests/startup.sh
pytest tests -W ignore::DeprecationWarning
# pytest tests -W ignore::DeprecationWarning