diff --git a/README.md b/README.md index 0a87357..eaf18e4 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ Supports BIP32 for asymmetric key derivation and SLIP10 for symmetric key deriva ### > One Time Programming (OTP) Storage The OTP securely stores the MKEK (Master Key Encryption Key) and Device Key permanently, making it inaccessible from external interfaces. This ensures that the key is protected against unauthorized access and tampering. -### > Secure Boot +### > Secure Boot Secure Boot ensures only authenticated firmware can run on the device, verifying each firmware’s digital signature to block unauthorized code. ### > Secure Lock @@ -150,7 +150,7 @@ Secure Lock restricts the device to the manufacturer’s firmware only, locking ### > Rescue Interface A built-in rescue interface allows recovery of the device if it becomes unresponsive or undetectable. This feature provides a way to restore the device to operational status without compromising security. - ### > LED Customization +### > LED Customization The LED can be customized to reflect device status and user preferences, offering flexible color and brightness options for an enhanced user experience. [^1]: PKCS11 modules (`pkcs11-tool` and `sc-tool`) do not support CMAC and key derivation. It must be processed through raw APDU command (`opensc-tool -s`). @@ -176,15 +176,15 @@ DKEKs are used during the export and import of private/secret keys and are part In the event that the Pico is stolen, the private and secret key contents cannot be accessed without the PIN, even if the flash memory is dumped. -### RP2350 and ESP32-S3 +### 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 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 device’s 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 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 vendor’s 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. diff --git a/src/hsm/cmd_initialize.c b/src/hsm/cmd_initialize.c index eb61418..5137da7 100644 --- a/src/hsm/cmd_initialize.c +++ b/src/hsm/cmd_initialize.c @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#include "crypto_utils.h" #include "sc_hsm.h" +#include "crypto_utils.h" #include "files.h" #include "random.h" #include "kek.h" @@ -187,6 +187,11 @@ int cmd_initialize() { uint8_t key_id = 0; if (otp_key_2) { ret = mbedtls_ecp_read_key(MBEDTLS_ECP_DP_SECP256K1, &ecdsa, otp_key_2, 32); + if (ret != 0) { + mbedtls_ecdsa_free(&ecdsa); + return SW_EXEC_ERROR(); + } + ret = mbedtls_ecp_mul(&ecdsa.grp, &ecdsa.Q, &ecdsa.d, &ecdsa.grp.G, random_gen, NULL); } else { ret = mbedtls_ecdsa_genkey(&ecdsa, ec_id, random_gen, NULL); diff --git a/tools/pico-hsm-tool.py b/tools/pico-hsm-tool.py index 12c8fac..41e9e08 100644 --- a/tools/pico-hsm-tool.py +++ b/tools/pico-hsm-tool.py @@ -39,7 +39,7 @@ except ModuleNotFoundError: sys.exit(-1) try: - from picohsm import PicoHSM, PinType, DOPrefixes, KeyType, EncryptionMode, utils, APDUResponse, SWCodes, AES + from picohsm import PicoHSM, PinType, DOPrefixes, KeyType, EncryptionMode, utils, APDUResponse, SWCodes, AES, Platform except ModuleNotFoundError: print('ERROR: picohsm module not found! Install picohsm package.\nTry with `pip install pypicohsm`') sys.exit(-1) @@ -228,7 +228,10 @@ def initialize(picohsm, args): print(f'Public Point: {hexlify(Y).decode()}') pbk = base64.urlsafe_b64encode(Y) - data = urllib.parse.urlencode({'pubkey': pbk}).encode() + params = {'pubkey': pbk} + if (picohsm.platform in (Platform.RP2350, Platform.ESP32)): + params['curve'] = 'secp256k1' + data = urllib.parse.urlencode(params).encode() j = get_pki_data('cvc', data=data) print('Device name: '+j['devname']) dataef = base64.urlsafe_b64decode(