57 Commits
v1.0 ... v1.8

Author SHA1 Message Date
Pol Henarejos
bcefdb3c84 Upgrading patcher to HSM SDK 3.4
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-11-25 14:26:06 +01:00
Pol Henarejos
685ee2bbd5 Moving pointer to Pico HSM SDK 3.4
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-11-25 14:25:50 +01:00
Pol Henarejos
6ae2a91e55 More fixes to build tool.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-11-23 11:09:38 +01:00
Pol Henarejos
2373f21994 Fix build tool.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-11-23 11:04:12 +01:00
Pol Henarejos
25bddb7230 Upgrading to version 1.8.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-11-23 11:00:44 +01:00
Pol Henarejos
418fa9c143 Fix patch tool.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-11-23 10:59:08 +01:00
Pol Henarejos
ce9ef47bb2 Using pico_hsm_sdk cmake library.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-08-31 14:18:37 +02:00
Pol Henarejos
603963123b Upgrade pico-hsm-sdk to v3.0
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-08-31 14:12:55 +02:00
Pol Henarejos
79ce35e944 Fix endianness of vid/pid patcher.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-08-31 14:12:26 +02:00
Pol Henarejos
5ddfa6382b Upgrading to new pico-hsm-sdk module.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-08-30 17:48:44 +02:00
Pol Henarejos
9a99baafca Renaming submodule.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-08-30 17:48:02 +02:00
Pol Henarejos
819fb99646 Update README.md
Added clarifications for AES.
2022-06-06 14:51:04 +02:00
Pol Henarejos
35fb97c58f Upgraded to version 1.6
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-06-06 14:40:34 +02:00
Pol Henarejos
3fa5dbccd0 Upgrade patch tool to version 2.0 of Pico CCID.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-06-06 14:40:19 +02:00
Pol Henarejos
b674708955 Added fixes for Pico CCID.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-06-06 14:38:13 +02:00
Pol Henarejos
86b508f2ae Updated README with new Pico CCID stack.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-06-06 01:47:18 +02:00
Pol Henarejos
167b6d9770 Adapted to Pico CCID 2.0.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-06-06 01:01:52 +02:00
Pol Henarejos
d0c167345e Add fmd flag when selecting the applet.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-24 23:31:12 +02:00
Pol Henarejos
ca6affaf5d Adding private identifiers for cardholder certificates.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-20 19:03:22 +02:00
Pol Henarejos
7a77b31760 Adding INS GET NEXT DATA
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-20 19:02:55 +02:00
Pol Henarejos
9f069a7e31 When PUT DATA or GET DATA with previously selected EF (via SELECT or SELECT DATA), it puts/writes the data into the selected EF.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-15 19:48:31 +02:00
Pol Henarejos
a0384f67ca Adding INS A5 to select DO with multiple instances.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-15 19:40:17 +02:00
Pol Henarejos
32c6f60b49 Adding INS F1 to get version.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-15 18:58:35 +02:00
Pol Henarejos
0ab5526dac Adding FMD when selecting app by AID.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-15 18:50:45 +02:00
Pol Henarejos
eb066472b1 Adding AES support for symmetric encryption and decryption. However, there is no any software that supports AES. So, no tested feature.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-13 17:44:09 +02:00
Pol Henarejos
a2d1c5cf22 Adding key import.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-12 23:49:26 +02:00
Pol Henarejos
436c0744d0 Added clarification about Gnuk and Pico OpenPGP.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-09 19:05:50 +02:00
Pol Henarejos
223a1e015b Updated README with new features.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-09 19:03:31 +02:00
Pol Henarejos
1491b9d36d Upgrading version to 1.4.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-09 18:56:14 +02:00
Pol Henarejos
74aa99afa6 Adding Manage Security Environment (INS 22).
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-09 18:54:36 +02:00
Pol Henarejos
c68fe30077 Enabling KDF.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-06 19:44:27 +02:00
Pol Henarejos
21284a9375 When a DO is not found, it should return REFERENCE_NOT_FOUND instead of FILE_NOT_FOUND, which reserved for selecting applet.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-06 19:13:26 +02:00
Pol Henarejos
151f6d134e Adding UIF DO (D6, D7 and D8).
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-05 22:35:17 +02:00
Pol Henarejos
d95d19a85b Adding press-to-confirm when loading a private key.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-05 20:55:41 +02:00
Pol Henarejos
4e2f3ce38d Upgrading pico-ccid.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-05 20:11:56 +02:00
Pol Henarejos
6ddb118bbf Small fix.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-29 15:49:39 +02:00
Pol Henarejos
6c4cb4b12a README uses markdown.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-29 15:47:53 +02:00
Pol Henarejos
456dd24fe5 Script to build Pico OpenPGP releases.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-29 15:47:16 +02:00
Pol Henarejos
e13a4fc121 File for live patching to burn custom VID/PID.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-29 15:47:02 +02:00
Pol Henarejos
49cee088b8 Since we cannot use version of APDU (as it always has to be 3.4 for OpenPGP), we define the version here.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-29 15:46:45 +02:00
Pol Henarejos
74197de147 Adding README
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-29 15:46:10 +02:00
Pol Henarejos
193220e59e Adding DEK to private keys.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-27 20:16:21 +02:00
Pol Henarejos
06745515eb Return SW_OK on VERIFY if user already logged in.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 21:46:13 +02:00
Pol Henarejos
30bb31a9c9 Adding life status for PW1 for PSO:CDS (single or several commands).
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 18:10:27 +02:00
Pol Henarejos
f0e7cdc18d Adding capability to edit PW STATUS.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 18:06:23 +02:00
Pol Henarejos
283289fbc6 Moving retries to PW STATUS.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 18:04:25 +02:00
Pol Henarejos
dc988e2a88 Signature counter is reset on keypair generation.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 16:43:18 +02:00
Pol Henarejos
1594da7533 Fix with signature counter.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 16:39:04 +02:00
Pol Henarejos
2c47816686 Fix logging in with PW 82.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 16:38:50 +02:00
Pol Henarejos
b0b30aff3a Adding increment of signature counter.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 16:38:23 +02:00
Pol Henarejos
30e5f12b25 Added access checks.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 16:03:10 +02:00
Pol Henarejos
3c2bfbc119 Moving some ASN1 stuff to mbedtls.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 12:14:58 +02:00
Pol Henarejos
77842f23e7 Moving signature calls outside.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 12:04:19 +02:00
Pol Henarejos
b67a902eb6 Fixing signature. It uses raw signature instead of heading it with asn1.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-26 09:36:36 +02:00
Pol Henarejos
e2c8d2e0aa Fix ECDH calc secret.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-25 19:41:06 +02:00
Pol Henarejos
d87334bfbc Added INTERNAL AUTHENTICATE.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-25 19:05:22 +02:00
Pol Henarejos
6fef2dd1dc Parsing 0x82 as PW2.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-04-25 17:56:28 +02:00
13 changed files with 1170 additions and 394 deletions

6
.gitmodules vendored
View File

@@ -1,3 +1,3 @@
[submodule "pico-ccid"] [submodule "pico-hsm-sdk"]
path = pico-ccid path = pico-hsm-sdk
url = https://github.com/polhenarejos/pico-ccid.git url = ../pico-hsm-sdk

View File

@@ -28,74 +28,25 @@ pico_sdk_init()
add_executable(pico_openpgp) add_executable(pico_openpgp)
if (NOT DEFINED USB_VID)
set(USB_VID 0xFEFF)
endif()
add_definitions(-DUSB_VID=${USB_VID})
if (NOT DEFINED USB_PID)
set(USB_PID 0xFCFD)
endif()
add_definitions(-DUSB_PID=${USB_PID})
target_sources(pico_openpgp PUBLIC target_sources(pico_openpgp PUBLIC
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/ccid/ccid2040.c
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/openpgp.c ${CMAKE_CURRENT_LIST_DIR}/src/openpgp/openpgp.c
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/files.c ${CMAKE_CURRENT_LIST_DIR}/src/openpgp/files.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/usb/usb_descriptors.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/fs/file.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/fs/flash.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/fs/low_flash.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/rng/random.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/rng/neug.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/ccid/crypto_utils.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/ccid/eac.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/sha256.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/aes.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/sha512.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/rsa.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/bignum.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/platform_util.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/md.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/oid.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/rsa_alt_helpers.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/constant_time.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/ecdsa.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/ecp.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/ecp_curves.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/asn1write.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/hmac_drbg.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/md5.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/ripemd160.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/sha1.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/ecdh.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/cmac.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/cipher.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/cipher_wrap.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/chachapoly.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/camellia.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/chacha20.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/aria.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/poly1305.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/gcm.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/ccm.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/des.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/nist_kw.c
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library/hkdf.c
) )
target_include_directories(pico_openpgp PUBLIC target_include_directories(pico_openpgp PUBLIC
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/fs
${CMAKE_CURRENT_LIST_DIR}/src/openpgp ${CMAKE_CURRENT_LIST_DIR}/src/openpgp
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/ccid )
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/rng
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/src/usb set(HSM_DRIVER "ccid")
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/include include(pico-hsm-sdk/pico_hsm_sdk_import.cmake)
${CMAKE_CURRENT_LIST_DIR}/pico-ccid/mbedtls/library
target_compile_options(pico_openpgp PUBLIC
-Wall
-Werror
) )
pico_add_extra_outputs(pico_openpgp) pico_add_extra_outputs(pico_openpgp)
#target_compile_definitions(pico_openpgp PRIVATE MBEDTLS_ECDSA_DETERMINISTIC=1) #target_compile_definitions(pico_openpgp PRIVATE MBEDTLS_ECDSA_DETERMINISTIC=1)
target_link_libraries(pico_openpgp PRIVATE pico_stdlib tinyusb_device tinyusb_board pico_multicore hardware_flash hardware_sync hardware_adc pico_unique_id hardware_rtc) target_link_libraries(pico_openpgp PRIVATE pico_hsm_sdk pico_stdlib tinyusb_device tinyusb_board pico_multicore hardware_flash hardware_sync hardware_adc pico_unique_id hardware_rtc)

137
README.md Normal file
View File

@@ -0,0 +1,137 @@
# Pico OpenPGP
This project aims at transforming your Raspberry Pico into a Smart Card with an OpenPGP applet integrated. The Pico works as a reader with an embedded OpenPGP card, like a USB card.
OpenPGP cards are used to manage PGP keys and do cryptographic operations, such as keypair generation, signing and asymmetric deciphering. Pico OpenPGP follows the [**OpenPGP 3.4.1** specifications](https://gnupg.org/ftp/specs/OpenPGP-smart-card-application-3.4.pdf "**OpenPGP 3.4.1** specifications"), available at [GnuPG](http://gnupg.org "GnuPG").
## Features
Pico OpenPGP has implemented the following features:
- Key generation and encrypted storage.
- RSA key generation from 1024 to 4096 bits.
- ECDSA key generation from 192 to 521 bits.
- ECC curves secp256r1, secp384r1, secp521r1, brainpoolP256r1, brainpoolP384r1, brainpoolP512r1, secp256k1.
- SHA1, SHA224, SHA256, SHA384, SHA512 digests.
- RSA-PKCS and raw RSA signature.
- ECDSA raw and hash signature.
- ECDH key derivation.
- PIN authorization.
- PKCS11 compliant interface.
- HRNG (hardware random number generator).
- Device Encryption Key (DEK).
- USB/CCID support with OpenSC, openssl, etc.
- Extended APDU support.
- Lifecycle card (termination and activation).
- Press-to-confirm button.
- User Interaction Flag for enabling/disabling press-to-confirm button.
- Key Derivation Function (KDF) for PIN.
- Manage Security Environment (MSE).
- DEK for internal safe storage.
- AES key generation.
- AES ciphering and deciphering.
- Cardholder certificates support.
All these features are compliant with the specification. Therefore, if you detect some behaviour that is not expected or it does not follow the rules of specs, please open an issue.
## AES support
There is no known software that supports AES with OpenPGP. Nevertheless, it can be used with customized PKCS11 modules or interfacing with raw APDU packets.
During asymmetric key generation for DEC key, Pico OpenPGP also generates a 32 bits symmetric key for AES operations.
OpenPGP card 3.4 specifications describe the procedure to perform ciphering (encryption and decryption) with AES via PSO:ENCIPHER and PSO:DECIPHER. Both commands are supported by Pico OpenPGP.
### About Gnuk
This project was inspired by [Gnuk](https://wiki.debian.org/GNUK "Gnuk"), a same project but focused on STM32 processor family. Despite the initial idea was to port Gnuk to the Raspberry Pico family, the underlaying architecture is widely different (although boh run on ARM). For instance, the Pico has two ARM cores, with an appropiate SDK able to leverage them. Also, Pico has an internal flash storage, which is farly larger compared to STM32 ROM storage. Finally, the Pico has a complete USB interface based on TinyUSB, which difficults to port Gnuk. These are only few examples of the difficulties of porting Gnuk to the Raspberry Pico.
As a consequence, Pico OpenPGP is designed from zero. Well, not strictly from zero, as it borrows some of the cryptographic operations implemented with MbedTLS library.
Whilst Gnuk is OpenPGP 2.0 with small set of enhancements, Pico OpenPGP aims at being OpenPGP 3.4 compliant, with new features (not present in Gnuk), such as Manage Security Environment (MSE) or UIF.
## Security considerations
All secret keys (asymmetric and symmetric) are stored encrypted in the flash memory of the Raspberry Pico. DEK is used as a 256 bit AES key to protect private and secret keys. Keys are never stored in RAM except for signature and decryption operations and only during the process. All keys (including DEK) are loaded and cleared every time to avoid potential security flaws.
At the same time, DEK is encrypted with doubled salted and hashed PIN. Also, the PIN is hashed in memory during the session. Hence, PIN is never stored in plain text neither in flash nor in memory. Note that PIN is conveyed from the host to the Pico in plain text if no secure channel is provided.
If the Pico is stolen the contents of private and secret keys cannot be read without the PIN, even if the flash memory is dumped.
## Download
Please, go to the [Release page](https://github.com/polhenarejos/pico-openpgp/releases "Release page")) and download the UF2 file for your board.
Note that UF2 files are shiped with a dummy VID/PID to avoid license issues (FEFF:FCFD). If you are planning to use it with OpenSC or similar, you should modify Info.plist of CCID driver to add these VID/PID or use the VID/PID patcher as follows: `./patch_vidpid.sh VID:PID input_openpgp_file.uf2 output_openpgp_file.uf2`
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.
## Build
Before building, ensure you have installed the toolchain for the Pico and the Pico SDK is properly located in your drive.
git clone https://github.com/polhenarejos/pico-openpgp
cd pico-openpgp
mkdir build
cd build
PICO_SDK_PATH=/path/to/pico-sdk cmake .. -DPICO_BOARD=board_type -DUSB_VID=0x1234 -DUSB_PID=0x5678
make
Note that PICO_BOARD, USB_VID and USB_PID are optional. If not provided, pico board and VID/PID FEFF:FCFD will be used.
After make ends, the binary file pico_openpgp.uf2 will be generated. Put your pico board into loading mode, by pushing BOOTSEL button while pluging on, and copy the UF2 to the new fresh usb mass storage Pico device. Once copied, the pico mass storage will be disconnected automatically and the pico board will reset with the new firmware. A blinking led will indicate the device is ready to work.
## Operation time
### Keypair generation
Generating EC keys is almost instant. RSA keypair generation takes some time, specially for 3072 and 4096 bits.
### Keypair generation
Generating EC keys is almost instant. RSA keypair generation takes some time, specially for `3072` and `4096` bits.
| RSA key length (bits) | Average time (seconds) |
| :---: | :---: |
| 1024 | 16 |
| 2048 | 124 |
| 3072 | 600 |
| 4096 | ~1000 |
### Signature and decrypt
| RSA key length (bits) | Average time (seconds) |
| :---: | :---: |
| 1024 | 1 |
| 2048 | 3 |
| 3072 | 7 |
| 4096 | 15 |
## Led blink
Pico OpenPGP uses the led to indicate the current status. Four states are available:
### Press to confirm
The Led is almost on all the time. It goes off for 100 miliseconds every second.
![Press to confirm](https://user-images.githubusercontent.com/55573252/162008917-6a730eac-396c-44cc-890e-802294be30a3.gif)
### Idle mode
In idle mode, the Pico OpenPGP goes to sleep. It waits for a command and it is awaken by the driver. The Led is almost off all the time. It goes on for 500 milliseconds every second.
![Idle mode](https://user-images.githubusercontent.com/55573252/162008980-d5a5caad-072e-400c-98e3-2c606b4b2af9.gif)
### Active mode
In active mode, the Pico OpenPGP is awaken and ready to receive a command. It blinks four times in a second.
![Active](https://user-images.githubusercontent.com/55573252/162008997-1ea8cd7e-5384-4893-9dcb-b473153fc375.gif)
### Processing
While processing, the Pico OpenPGP is busy and cannot receive additional commands until the current is processed. In this state, the Led blinks 20 times in a second.
![Processing](https://user-images.githubusercontent.com/55573252/162009007-df45111e-2473-4a92-97c5-15c3cd19babd.gif)
## Driver
Pico OpenPGP uses the `openpgp` driver provided by [OpenSC](https://github.com/OpenSC/OpenSC/ "OpenSC"). This driver utilizes the standardized PKCS#11 interface to communicate with the user and it can be used with many engines that accept PKCS#11 interface, such as OpenSSL, P11 library or pkcs11-tool.
It also accepts the use of GnuPG programs (`gpg` and `gpg2`) to manipulate the card. For instance, it can be used with the `gpg --edit-card --expert` interface to change the cryptographic keys, generate new keypairs or simply set the cardholder name.
Pico OpenPGP relies on PKCS#15 structure to store and manipulate the internal files (PINs, private keys, certificates, etc.) and directories. Therefore, it accepts the commands from `pkcs15-tool`. For instance, `pkcs15-tool -D` will list all elements stored in the Pico OpenPGP.
The way to communicate is exactly the same as with other cards, such as OpenPGP or similar.
### 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 must patch the UF2 binary (if you just downloaded from the [Release section](https://github.com/polhenarejos/pico-openpgp/releases "Release section")) or 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.
## Credits
Pico OpenPGP uses the following libraries or portion of code:
- MbedTLS for cryptographic operations.
- TinyUSB for low level USB procedures.

1
VERSION Normal file
View File

@@ -0,0 +1 @@
Version=1.4

53
build_pico_openpgp.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/bin/bash
VERSION_MAJOR="1"
VERSION_MINOR="8"
rm -rf release/*
cd build_release
for board in adafruit_feather_rp2040 \
adafruit_itsybitsy_rp2040 \
adafruit_kb2040 \
adafruit_macropad_rp2040 \
adafruit_qtpy_rp2040 \
adafruit_trinkey_qt2040 \
arduino_nano_rp2040_connect \
datanoisetv_rp2040_dsp \
eetree_gamekit_rp2040 \
garatronic_pybstick26_rp2040 \
melopero_shake_rp2040 \
pico \
pico_w \
pimoroni_badger2040 \
pimoroni_interstate75 \
pimoroni_keybow2040 \
pimoroni_motor2040 \
pimoroni_pga2040 \
pimoroni_picolipo_4mb \
pimoroni_picolipo_16mb \
pimoroni_picosystem \
pimoroni_plasma2040 \
pimoroni_servo2040 \
pimoroni_tiny2040 \
pimoroni_tiny2040_2mb \
seeed_xiao_rp2040 \
solderparty_rp2040_stamp \
solderparty_rp2040_stamp_carrier \
solderparty_rp2040_stamp_round_carrier \
sparkfun_micromod \
sparkfun_promicro \
sparkfun_thingplus \
vgaboard \
waveshare_rp2040_lcd_0.96 \
waveshare_rp2040_plus_4mb \
waveshare_rp2040_plus_16mb \
waveshare_rp2040_zero \
wiznet_w5100s_evb_pico
do
rm -rf *
PICO_SDK_PATH=../../pico-sdk cmake .. -DPICO_BOARD=$board
make -kj20
mv pico_openpgp.uf2 ../release/pico_openpgp_$board-$VERSION_MAJOR.$VERSION_MINOR.uf2
done

94
patch_vidpid.sh Executable file
View File

@@ -0,0 +1,94 @@
#!/bin/bash
#
# This file is part of the Pico OpenPGP distribution (https://github.com/polhenarejos/pico-openpgp).
# Copyright (c) 2022 Pol Henarejos.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
VERSION_MAJOR="3" #Version of Pico CCID Core
VERSION_MINOR="4"
echo "----------------------------"
echo "VID/PID patcher for Pico OpenPGP"
echo "----------------------------"
echo ""
if [ "$#" -le 0 ]; then
echo "Usage: $0 VID:PID [input_uf2_file] [output_uf2_file]"
exit 1
fi
IFS=':' read -r -a ARR <<< "$1"
if [ ${#ARR[@]} -ne 2 ]; then
echo "ERROR: Specify vendor and product ids as VID:PID (e.g., $0 CAFE:1234)"
exit 1
fi
VID=${ARR[0]}
PID=${ARR[1]}
if [ ${#VID} -ne 4 ]; then
echo "ERROR: VID length must be 4 hexadecimal characters"
exit 1
fi
if [ ${#PID} -ne 4 ]; then
echo "ERROR: PID length must be 4 hexadecimal characters"
exit 1
fi
if ! [[ $VID =~ ^[0-9A-Fa-f]{1,}$ ]] ; then
echo "ERROR: VID must contain hexadecimal characters"
exit 1
fi
if ! [[ $PID =~ ^[0-9A-Fa-f]{1,}$ ]] ; then
echo "ERROR: PID must contain hexadecimal characters"
exit 1
fi
UF2_FILE_IF="pico_openpgp.uf2"
UF2_FILE_OF="$UF2_FILE_IF"
if [ "$#" -ge 2 ]; then
UF2_FILE_IF="$2"
UF2_FILE_OF="$UF2_FILE_IF"
fi
if [ "$#" -ge 3 ]; then
UF2_FILE_OF="$3"
fi
echo -n "Patching ${UF2_FILE_IF}... "
if [[ ! -f "$UF2_FILE_IF" ]]; then
echo "ERROR: UF2 file ${UF2_FILE_IF} does not exist"
exit 1
fi
if [ "$UF2_FILE_IF" != "$UF2_FILE_OF" ]; then
cp -R $UF2_FILE_IF $UF2_FILE_OF
fi
LITTLE_VID="\x${VID:2:2}\x${VID:0:2}"
LITTLE_PID="\x${PID:2:2}\x${PID:0:2}"
perl -pi -e "s/\xff\xfe\xfd\xfc\x$VERSION_MINOR\x$VERSION_MAJOR\x01\x02\x03\x01/$LITTLE_VID$LITTLE_PID\x$VERSION_MINOR\x$VERSION_MAJOR\x01\x02\x03\x01/" $UF2_FILE_OF
echo "Done!"
echo ""
echo "Patched file was saved in ${UF2_FILE_OF}"

Submodule pico-ccid deleted from cddc3b2dec

1
pico-hsm-sdk Submodule

Submodule pico-hsm-sdk added at c4178fda4b

View File

@@ -54,14 +54,14 @@ uint8_t historical_bytes[] = {
uint8_t extended_capabilities[] = { uint8_t extended_capabilities[] = {
10, 0, 10, 0,
0x74, /* 0x77, /*
* No Secure Messaging supported * No Secure Messaging supported
* GET CHALLENGE supported * GET CHALLENGE supported
* Key import supported * Key import supported
* PW status byte can be put * PW status byte can be put
* No private_use_DO * No private_use_DO
* Algorithm attrs are changable * Algorithm attrs are changable
* No DEC with AES * ENC/DEC with AES
* KDF-DO available * KDF-DO available
*/ */
0, /* Secure Messaging Algorithm: N/A (TDES=0, AES=1) */ 0, /* Secure Messaging Algorithm: N/A (TDES=0, AES=1) */
@@ -126,21 +126,24 @@ file_t file_entries[] = {
/* 39 */ { .fid = EF_PW1, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 39 */ { .fid = EF_PW1, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP },
/* 40 */ { .fid = EF_RC, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 40 */ { .fid = EF_RC, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP },
/* 41 */ { .fid = EF_PW3, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 41 */ { .fid = EF_PW3, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP },
/* 42 */ { .fid = EF_PW1_RETRIES, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 42 */ { .fid = EF_ALGO_PRIV1, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
/* 43 */ { .fid = EF_RC_RETRIES, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 43 */ { .fid = EF_ALGO_PRIV2, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
/* 44 */ { .fid = EF_PW3_RETRIES, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 44 */ { .fid = EF_ALGO_PRIV3, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
/* 45 */ { .fid = EF_ALGO_PRIV1, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP }, /* 45 */ { .fid = EF_PK_SIG, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP },
/* 46 */ { .fid = EF_ALGO_PRIV2, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP }, /* 46 */ { .fid = EF_PK_DEC, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP },
/* 47 */ { .fid = EF_ALGO_PRIV3, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP }, /* 47 */ { .fid = EF_PK_AUT, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP },
/* 48 */ { .fid = EF_PK_SIG, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 48 */ { .fid = EF_PB_SIG, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
/* 49 */ { .fid = EF_PK_DEC, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 49 */ { .fid = EF_PB_DEC, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
/* 50 */ { .fid = EF_PK_AUT, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 50 */ { .fid = EF_PB_AUT, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
/* 51 */ { .fid = EF_PB_SIG, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 51 */ { .fid = EF_PW_PRIV, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
/* 52 */ { .fid = EF_PB_DEC, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 52 */ { .fid = EF_DEK, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE },
/* 53 */ { .fid = EF_PB_AUT, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP }, /* 53 */ { .fid = EF_KDF, .parent = 0, .name = NULL, .type = FILE_TYPE_WORKING_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
/* 54 */ { .fid = EF_CH_1, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE },
/* 55 */ { .fid = EF_CH_2, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE },
/* 56 */ { .fid = EF_CH_3, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE },
/* 54 */ { .fid = 0x0000, .parent = 0, .name = openpgp_aid, .type = FILE_TYPE_WORKING_EF, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_RO }, /* 57 */ { .fid = 0x0000, .parent = 0, .name = openpgp_aid, .type = FILE_TYPE_WORKING_EF, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_RO },
/* 55 */ { .fid = 0x0000, .parent = 0xff, .name = NULL, .type = FILE_TYPE_UNKNOWN, .data = NULL, .ef_structure = 0, .acl = ACL_NONE } //end /* 58 */ { .fid = 0x0000, .parent = 0xff, .name = NULL, .type = FILE_TYPE_UNKNOWN, .data = NULL, .ef_structure = 0, .acl = ACL_NONE } //end
}; };
const file_t *MF = &file_entries[0]; const file_t *MF = &file_entries[0];

View File

@@ -24,18 +24,20 @@
#define EF_PW1 0x1081 #define EF_PW1 0x1081
#define EF_RC 0x1082 #define EF_RC 0x1082
#define EF_PW3 0x1083 #define EF_PW3 0x1083
#define EF_PW1_RETRIES 0x1084
#define EF_RC_RETRIES 0x1085
#define EF_PW3_RETRIES 0x1086
#define EF_ALGO_PRIV1 0x10c1 #define EF_ALGO_PRIV1 0x10c1
#define EF_ALGO_PRIV2 0x10c2 #define EF_ALGO_PRIV2 0x10c2
#define EF_ALGO_PRIV3 0x10c3 #define EF_ALGO_PRIV3 0x10c3
#define EF_PW_PRIV 0x10c4
#define EF_PK_SIG 0x10d1 #define EF_PK_SIG 0x10d1
#define EF_PK_DEC 0x10d2 #define EF_PK_DEC 0x10d2
#define EF_PK_AUT 0x10d3 #define EF_PK_AUT 0x10d3
#define EF_PB_SIG 0x10d4 #define EF_PB_SIG 0x10d4
#define EF_PB_DEC 0x10d5 #define EF_PB_DEC 0x10d5
#define EF_PB_AUT 0x10d6 #define EF_PB_AUT 0x10d6
#define EF_DEK 0x1099
#define EF_CH_1 0x1f21
#define EF_CH_2 0x1f22
#define EF_CH_3 0x1f23
#define EF_EXT_HEADER 0x004d //C #define EF_EXT_HEADER 0x004d //C
#define EF_FULL_AID 0x004f //S #define EF_FULL_AID 0x004f //S
@@ -64,10 +66,12 @@
#define EF_TS_DEC 0x00cf //S #define EF_TS_DEC 0x00cf //S
#define EF_TS_AUT 0x00d0 //S #define EF_TS_AUT 0x00d0 //S
#define EF_RESET_CODE 0x00d3 //S #define EF_RESET_CODE 0x00d3 //S
#define EF_AES_KEY 0x00d5 //S
#define EF_UIF_SIG 0x00d6 //S #define EF_UIF_SIG 0x00d6 //S
#define EF_UIF_DEC 0x00d7 //S #define EF_UIF_DEC 0x00d7 //S
#define EF_UIF_AUT 0x00d8 //S #define EF_UIF_AUT 0x00d8 //S
#define EF_KEY_INFO 0x00de //S #define EF_KEY_INFO 0x00de //S
#define EF_KDF 0x00f9 //C
#define EF_ALGO_INFO 0x00fa //C #define EF_ALGO_INFO 0x00fa //C
#define EF_LANG_PREF 0x5f2d //S #define EF_LANG_PREF 0x5f2d //S
#define EF_SEX 0x5f35 //S #define EF_SEX 0x5f35 //S

File diff suppressed because it is too large Load Diff

View File

@@ -21,7 +21,8 @@
#include "stdlib.h" #include "stdlib.h"
#include <pico/stdlib.h> #include <pico/stdlib.h>
#include "ccid2040.h" #include "hsm.h"
#include "apdu.h"
extern bool has_pw1; extern bool has_pw1;
extern bool has_pw3; extern bool has_pw3;

View File

@@ -23,5 +23,10 @@
#define OPGP_VERSION_MAJOR ((OPGP_VERSION >> 8) & 0xff) #define OPGP_VERSION_MAJOR ((OPGP_VERSION >> 8) & 0xff)
#define OPGP_VERSION_MINOR (OPGP_VERSION & 0xff) #define OPGP_VERSION_MINOR (OPGP_VERSION & 0xff)
#endif
#define PIPGP_VERSION 0x0108
#define PIPGP_VERSION_MAJOR ((PIPGP_VERSION >> 8) & 0xff)
#define PIPGP_VERSION_MINOR (PIPGP_VERSION & 0xff)
#endif