Commit Graph

99 Commits

Author SHA1 Message Date
Pol Henarejos
95a4f7201b Move cmd functions to separate files.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2025-01-08 11:46:49 +01:00
Pol Henarejos
eaa8851719 Move Pico Keys SDK pointer.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-12-27 02:54:07 +01:00
Pol Henarejos
79c69a6617 OTP key is used to mask the DEK.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-11-10 18:56:46 +01:00
Pol Henarejos
4ba5e04080 Add PICO_PRODUCT.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-11-09 00:37:19 +01:00
Pol Henarejos
2747083672 Upgrade pico keys sdk.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-11-09 00:36:21 +01:00
Pol Henarejos
e0779a49e7 Add error if a non-supported key is attempted to be imported.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-09-30 17:04:34 +02:00
Pol Henarejos
57a6458051 Fix unitialized var.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-08-25 20:58:14 +02:00
Pol Henarejos
6780eb3935 Fix select aid to new callback.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-08-25 20:57:56 +02:00
Pol Henarejos
1051690b79 Add support to ESP32.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-08-20 00:23:22 +02:00
Pol Henarejos
1434ef2bd2 Fix for mbedtls 3.6
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-07-15 15:16:36 +02:00
Ming Kuang
886bee5ddc Fix conditional error resetting has_pw1 variable
According to OpenPGP 3.4.1 specifications subsection 4.4.1:
PW status Bytes
1st byte: 00 = PW1 (no. 81) only valid for one PSO:CDS command
          01 = PW1 valid for several PSO:CDS commands

Therefore has_pw1 should be reset to false when the first byte
of the PW status is 0 instead of 1.
2024-07-06 22:09:37 +08:00
Pol Henarejos
b61af665b8 Change size of tag_len() for uint16.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-05-23 18:44:57 +02:00
Pol Henarejos
20387c955e Use latest version of Pico Keys SDK.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-05-23 18:40:24 +02:00
Pol Henarejos
0198386734 Merge branch 'piv' 2024-05-23 18:32:26 +02:00
Pol Henarejos
ce6eb6e8e6 Fix overflow when importing data.
Fixes #12.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-05-23 18:32:15 +02:00
Pol Henarejos
f4c3a75d66 Compute public point on load key.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-03-27 18:45:23 +01:00
Pol Henarejos
f20449fee3 Fix RSA signature.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-03-26 19:38:17 +01:00
Pol Henarejos
e0e1b3758e Added support for dynamic number of maximum retries. 3 by default
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-03-22 20:37:47 +01:00
Pol Henarejos
17d476a9e2 Fix crash on PIN change.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-03-21 22:01:41 +01:00
Pol Henarejos
0b7c8da592 KEK use is optional.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-03-19 17:56:00 +01:00
Pol Henarejos
d96bbb9b4b Use new asn1 structs.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-03-14 23:22:19 +01:00
Pol Henarejos
4cfa2a16bf Added AUTHENTICATE support.
Note that CARD MGM key is NOT encrypted with DEK, since it has to be accessed even without PIN.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2024-03-12 22:04:19 +01:00
Pol Henarejos
7f7e94c639 Use new names and selecting aid.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-11-06 15:23:54 +01:00
Pol Henarejos
865eafb1f3 Fix Curve25519 key import.
For an unknown reason, curve25519 keys are imported in big endian instead of little endian.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-09-05 00:25:39 +02:00
Pol Henarejos
9ea894b60b Use mbedtls read/write keys wrappers.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-08-28 01:25:28 +02:00
Pol Henarejos
b815dc35c8 Fix initializing DEK for pw3.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-05-17 00:04:57 +02:00
Pol Henarejos
5eb6822bf5 Update code style.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-03-04 14:08:47 +01:00
Pol Henarejos
3c7df3aa42 Fix checking length in ECDH.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-04 23:44:55 +01:00
Pol Henarejos
e5871d5791 Fix returning algo attributes for authentication key.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-04 21:07:10 +01:00
Pol Henarejos
7ccbb0103f Fix computing length of algorithm attributes.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-04 21:06:33 +01:00
Pol Henarejos
8e03ce28a3 Fix returning signature in some cases.
In some particular cases where signature has a 0 prepended, mpi is written without that which caused variable length signatures. Now it returns the signature whose length is always the same.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-04 20:28:33 +01:00
Pol Henarejos
b300ed87f3 Fix returning ecdsa response for keys > 512 bits.
In that case, TLV shall contain 81 length.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-04 20:27:20 +01:00
Pol Henarejos
7b17cc7b49 Public point is now computed when private key is imported.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-04 19:44:44 +01:00
Pol Henarejos
abf190f767 Tuned returning public key information for ECDSA.
Despite it was not a bug, it seems some ASN.1 readers do not recognize 0x81/0x82 tags when len < 128.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-04 19:44:00 +01:00
Pol Henarejos
d9ed002af2 Signature counter is only increased on PSO:SIGN and not for authentication.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-04 01:31:34 +01:00
Pol Henarejos
e1407636b8 Fix DEK loading when resetting code is used.
If no pw3, on cmd_reset_retry pw1 is changed without providing the original, since it is done via rc. Thus, there is no way to recover DEK. To solve, another ciphered field is added for loading DEK via rc. In case rc is changed (PUT DATA), DEK is reciphered with new rc.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-04 01:23:03 +01:00
Pol Henarejos
365acbd68b Fix setting RC.
When setting RC it was not hashed and then it was not recognized.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-03 20:21:14 +01:00
Pol Henarejos
f6facc1154 When a private key is imported, a public key is generated and stored.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-03 20:08:26 +01:00
Pol Henarejos
5e257729a3 Some fixes.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-03 19:17:42 +01:00
Pol Henarejos
4a629fe53f Fix returning size of some DO.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-03 17:27:02 +01:00
Pol Henarejos
22689b3784 Fix returning DO.
If the TLV container contains a single DO, the header is removed.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-03 17:25:18 +01:00
Pol Henarejos
4f1cd1f2f8 Fix returning sig counter.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-03 16:55:32 +01:00
Pol Henarejos
c9ef78b3c9 Fix returning app data.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-03 16:52:55 +01:00
Pol Henarejos
cf53fdd903 Adapt select_applet to new call.
Also fixes sex test.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-02-03 16:32:28 +01:00
Pol Henarejos
303116ffea Fix P1P2 on termination check.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2023-01-09 17:10:12 +01:00
Pol Henarejos
23824afc1f Fix importing data with TLV length > 0x7f.
Should fix #3.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-11-29 20:21:47 +01: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
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
7a77b31760 Adding INS GET NEXT DATA
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
2022-05-20 19:02:55 +02:00