Commit Graph

8562 Commits

Author SHA1 Message Date
Jakub Jelen 7d0abdc192 p11test: Remove unnecessary spaces in JSON output 2021-03-24 16:25:08 +01:00
Jakub Jelen 370eda4bd8 framework-pkcs15: Avoid strict aliasing issues 2021-03-24 16:25:08 +01:00
Frank Morgner 5f9085fedb
Merge pull request #1960 from Jakuje/eddsa
Add support for (X)EdDSA keys in OpenPGP driver
2021-03-22 15:36:59 +01:00
Marco Trevisan (Treviño) 845eac4250 pkcs11-global: Obey to the tokenPresent parameter on C_GetSlotList
Since commit dba0f56 the tokenPresent parameter is ignored in case the
slot has been already seen.

This breaks the API expectations as we may return a slot that has no
token inserted.

So, only consider the SC_PKCS11_SLOT_FLAG_SEEN if tokenPresent is false
2021-03-22 15:35:55 +01:00
Vincent JARDIN 40e9a9c830 pkcs15: log HSM capabilities (can_do)
Some Smartcards have some capabilities (for instance the IASECC)
that can influence the can_do cases. In order to track them, it
is useful to log any checks.
2021-03-22 13:15:12 +01:00
Vincent JARDIN b18234a7d9
iasecc: Fix ACLs support when length is 6 (#2264)
* IASECC: offset is a size_t

Let's use a size_t for the offset in order to have a proper logic
along with the related arithmetics.

Fix: part if issue #2262
Suggested-by: Frank Morgner <frankmorgner@gmail.com>

* iasecc: Fix ACLs support when length is 6

ACLs with length < 6 are allowed, depending on the mask of the offset 0.
For instance, when the offset 0 is 0x7B, then length can be up to 7
when the offset 0 is 0x7A, the loop was never performing any access to
the acls[7] thanks to:
  if (!(mask & acls[0]))
    continue;

However, the oss-fuzz tools cannot guess such behavior. So let's have a
robust boundary check.

Fix: issue #2262
Fix: ae1cf0be90 'Prevent stack buffer overflow when empty ACL is returned'

Co-authored-by: Vincent JARDIN <vjardin@free.fr>
Co-authored-by: Frank Morgner <frankmorgner@gmail.com>
2021-03-22 13:08:28 +01:00
Jakub Jelen 5d4daf6c92 oberthur: One more overlooked buffer overflow
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32202
2021-03-21 09:53:13 +01:00
Jakub Jelen 715c17c469 oberthur: Fix memory leaks
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32149
2021-03-18 13:18:10 +01:00
Jakub Jelen d5dea2dd1b tests: Investigate test failure on bionic 2021-03-18 09:58:21 +01:00
Jakub Jelen 16b7c60fd3 Fix more issues with strict aliasing reported by gcc v8
Thanks popoves for reporting this issue
2021-03-18 09:58:21 +01:00
Frank Morgner 05648b0604 oberthur: fixed Heap-buffer-overflow
fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32149
2021-03-18 09:56:46 +01:00
Vincent JARDIN fc0df4e5d5 IASECC/CPX: revert removal of 3F00 from the path
Few years ago, the commit 03628449b7
did squash the 3F00nnnn path to nnnn. For instance, 3F002F00
becomes 2F00. It is an issue such as:
  00000200 [139681798813440] APDU: 00 A4 09 04 02 2F 00
  00029790 [139681798813440] SW: 6A 82

Fix: issue #2231
2021-03-17 10:58:20 +01:00
Vincent JARDIN 76507508d7 IASECC/CPX: code factorization
There are two flavours of CPX cards:
  - contact mode,
  - contactless mode
2021-03-17 10:58:20 +01:00
Vincent JARDIN 4119b2c3e7 ASN1 lax bit string decoding
Some ASN1 objects stored on some smartcards (for instance the
IASECC/CPX ones) do not comply strictly with the rules
8.6.2.3 and 8.6.2.3 from the ITU.

Since these rules are not some strict ones, let's have a loose
decoding option that can be displayed by the command:
opensc-explorer
  asn1 7001 # for instance

Fix: issue #2224
2021-03-17 10:58:20 +01:00
Vincent JARDIN b508349010 IASECC/CPX: opensc-explorer asn1 EF.ATR parsing
Let's the advance users be able to parse the ASN1 contant
for any offset.

OpenSC [3F00]> asn1 2F01 0
Error in decoding.
OpenSC [3F00]> asn1 2F01 1
43 Application 3  (1 byte): decode error, : B8 .
46 Application 6  (4 bytes): decode error: 04 B0 EC C1 ....
47 Application 7  (3 bytes): 94 01 80 ...
4F Application 15 (8 bytes): 80 25 00 00 01 FF 01 00 .%......
E0 Private 0  (16 bytes)
   02 INTEGER (2 bytes): 260
   02 INTEGER (2 bytes): 260
   02 INTEGER (2 bytes): 256
   02 INTEGER (2 bytes): 256
78 Application 24 (8 bytes)
   06 OBJECT IDENTIFIER (6 bytes):  1.3.162.15480.2
82 Context 2  (2 bytes): 36864: 90 00 ..

Fix: issue #2220
2021-03-17 10:58:20 +01:00
Vincent JARDIN 20f359ea04 IASECC/CPX: SC_PATH_TYPE_FILE_ID, wrong APDU
For SC_PATH_TYPE_FILE_ID, P2 should be 0x04, if not,
then we get the following errors:
 [opensc-pkcs11] reader-pcsc.c:324:pcsc_transmit:
Outgoing APDU (7 bytes):
00 A4 02 00 02 A0 01 .......
 [opensc-pkcs11] reader-pcsc.c:242:pcsc_internal_transmit: called
 [opensc-pkcs11] reader-pcsc.c:333:pcsc_transmit:
Incoming APDU (2 bytes):
6A 86 j.
 [opensc-pkcs11] apdu.c:382:sc_single_transmit: returning with: 0 (Success)
 [opensc-pkcs11] apdu.c:535:sc_transmit: returning with: 0 (Success)
 [opensc-pkcs11] card.c:523:sc_unlock: called
 [opensc-pkcs11] iso7816.c:128:iso7816_check_sw: Incorrect parameters P1-P2
 [opensc-pkcs11] card-iasecc.c:1107:iasecc_select_file: iasecc_select_file() check SW failed: -1205 (Incorrect parameters in APDU)
 [opensc-pkcs11] card.c:866:sc_select_file: 'SELECT' error: -1205 (Incorrect parameters in APDU)

when running:
  ./pkcs11-tool --test --login --pin abcd
2021-03-17 10:58:20 +01:00
Vincent JARDIN c581d1b26f IASECC/CPX: opensc-explorer asn1 of EF.ATR objects
Workaround the parsing of EF.ATR objects, for instance:

./opensc-explorer -r 0

OpenSC [3F00]> cat 2F01
00000000: 80 43 01 B8 46 04 04 B0 EC C1 47 03 94 01 80 4F .C..F.....G....O
00000010: 08 80 25 00 00 01 FF 01 00 E0 10 02 02 01 04 02 ..%.............
00000020: 02 01 04 02 02 01 00 02 02 01 00 78 08 06 06 2B ...........x...+
00000030: 81 22 F8 78 02 82 02 90 00                      .".x.....

OpenSC [3F00]> info 2F01
Working Elementary File  ID 2F01, SFI E8

File path:               3F00/2F01
File size:               57 bytes
EF structure:            Transparent
ACL for READ:            NONE
ACL for UPDATE:          SecOx45
ACL for DELETE:          SecOx45
ACL for WRITE:           N/A
ACL for REHABILITATE:    N/A
ACL for INVALIDATE:      N/A
ACL for LIST FILES:      N/A
ACL for CRYPTO:          N/A
Type attributes:         01
Life cycle:              Operational, activated

In order to avoid adding an offset of 1 for such objects on some
  OpenSC [3F00]> asn1 2F01 1
specific cards, then, we get:

OpenSC [3F00]> asn1 2F01
80 Context 0  (0 bytes)
43 Application 3  (1 byte): decode error: B8 .
46 Application 6  (4 bytes): decode error: 04 B0 EC C1 ....
47 Application 7  (3 bytes): 94 01 80 ...
4F Application 15 (8 bytes): 80 25 00 00 01 FF 01 00 .%......
E0 Private 0  (16 bytes)
   02 INTEGER (2 bytes): 260
   02 INTEGER (2 bytes): 260
   02 INTEGER (2 bytes): 256
   02 INTEGER (2 bytes): 256
78 Application 24 (8 bytes)
   06 OBJECT IDENTIFIER (6 bytes):  1.3.162.15480.2
82 Context 2  (2 bytes): 36864: 90 00 ..
OpenSC [3F00]>

which means:
 ef-atr.c:49:sc_parse_ef_atr_content: EF.ATR: card service 0xB8
 ef-atr.c:59:sc_parse_ef_atr_content: EF.ATR: Pre-Issuing data '04B0ECC1'
 ef-atr.c:67:sc_parse_ef_atr_content: EF.ATR: DF selection 94, unit_size 1, card caps 80
 ef-atr.c:95:sc_parse_ef_atr_content: EF.ATR: AID '8025000001FF0100'
 ef-atr.c:106:sc_parse_ef_atr_content: EF.ATR: Issuer data '02020104020201040202010002020100'
 ef-atr.c:111:sc_parse_ef_atr_content: EF.ATR: DER encoded OID 06062B8122F87802
 ef-atr.c:114:sc_parse_ef_atr_content: EF.ATR: OID 2B8122F87802
 ef-atr.c:123:sc_parse_ef_atr_content: EF.ATR: status word 0x9000

Fix: issue #2220
2021-03-17 10:58:20 +01:00
Vincent JARDIN fd83e885f7 IASECC/CPX: parse EF.ATR from ASN1 2F01 object
2F01 is:
./opensc-explorer -r 0
OpenSC [3F00]> cat 2F01
00000000: 80 43 01 B8 46 04 04 B0 EC C1 47 03 94 01 80 4F .C..F.....G....O
00000010: 08 80 25 00 00 01 FF 01 00 E0 10 02 02 01 04 02 ..%.............
00000020: 02 01 04 02 02 01 00 02 02 01 00 78 08 06 06 2B ...........x...+
00000030: 81 22 F8 78 02 82 02 90 00                      .".x.....

so the ASN1 decoder gets confused because it assumes that two bytes are
needed before getting the first tag 43/ISO7816_TAG_II_CARD_SERVICE.
In order to avoid such confusion, whenever the content of the EF.ATR/2F01 starts
with ISO7816_II_CATEGORY_TLV, we skip the first byte in order to parse
the ASN1 payload.

Fix: issue #2220
2021-03-17 10:58:20 +01:00
Vincent JARDIN 6efd7b3029 IASECC: send/recv from EF.ATR
Log the send/recv data extracted from the EF.ATR (2F01).
2021-03-17 10:58:20 +01:00
Vincent JARDIN 41edcaa413 IASECC/CPX: proper set of RSA support
The previous commit was over simplified. According to the known
mechanism, we should have the following scope:

./pkcs11-tool --module ../lib/onepin-opensc-pkcs11.so -M
Using slot 0 with a present token (0x0)
Supported mechanisms:
  SHA-1, digest
  SHA224, digest
  SHA256, digest
  SHA384, digest
  SHA512, digest
  MD5, digest
  RIPEMD160, digest
  GOSTR3411, digest
  RSA-X-509, keySize={512,2048}, hw, decrypt, sign, verify
  RSA-PKCS, keySize={512,2048}, hw, decrypt, sign, verify
  SHA1-RSA-PKCS, keySize={512,2048}, sign, verify
  SHA256-RSA-PKCS, keySize={512,2048}, sign, verify
  RSA-PKCS-PSS, keySize={512,2048}, hw, sign, verify
  SHA1-RSA-PKCS-PSS, keySize={512,2048}, sign, verify
  SHA256-RSA-PKCS-PSS, keySize={512,2048}, sign, verify

do not use the default flags yet:
  _sc_card_add_rsa_alg(card, 1024, IASECC_CARD_DEFAULT_FLAGS, 0x10001);
  _sc_card_add_rsa_alg(card, 2048, IASECC_CARD_DEFAULT_FLAGS, 0x10001);
  _sc_card_add_rsa_alg(card, 512, IASECC_CARD_DEFAULT_FLAGS, 0x10001);

Contactless specific behaviour shall be added later on.
2021-03-17 10:58:20 +01:00
Vincent JARDIN 7cd713d15d IASECC/CPX: enable RSA algorithms
Without this fix, we get:
./pkcs11-tool --module ../lib/onepin-opensc-pkcs11.so -M
Using slot 0 with a present token (0x0)
Supported mechanisms:
  SHA-1, digest
  SHA224, digest
  SHA256, digest
  SHA384, digest
  SHA512, digest
  MD5, digest
  RIPEMD160, digest
  GOSTR3411, digest

Once we include it, we get:
./pkcs11-tool --module ../lib/onepin-opensc-pkcs11.so -M
Using slot 0 with a present token (0x0)
Supported mechanisms:
  SHA-1, digest
  SHA224, digest
  SHA256, digest
  SHA384, digest
  SHA512, digest
  MD5, digest
  RIPEMD160, digest
  GOSTR3411, digest
  RSA-9796, keySize={1024,2048}, hw, decrypt, sign, verify
  RSA-PKCS, keySize={1024,2048}, hw, decrypt, sign, verify
  SHA1-RSA-PKCS, keySize={1024,2048}, sign, verify
  SHA256-RSA-PKCS, keySize={1024,2048}, sign, verify
  RSA-PKCS-KEY-PAIR-GEN, keySize={1024,2048}, generate_key_pair
2021-03-17 10:58:20 +01:00
Vincent JARDIN fd97f49a84 IASECC: CPX have 2 applications
There are 2 applications: default one (contact mode) and the contactless
mode.
2021-03-17 10:58:20 +01:00
Vincent JARDIN 560692221b IASECC/CPX: file selection and app enumeration
Thanks to this commit, we get the full support of:
  - ./opensc-explore
    cd 0001
    asn1 2F00
  - ./pkcs11-tool -O
  - etc.
2021-03-17 10:58:20 +01:00
Vincent JARDIN acb8822444 IASECC: Add support for CPx cards
The French CPx Healthcare cards are designed to support the IASECC
standard.
2021-03-17 10:58:20 +01:00
Jakub Jelen 40c50a3a42 oberthur: Handle more memory issues during initialization
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31540
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31448
2021-03-16 12:02:05 +01:00
Frank Morgner 4512676795 Nightly: in case of conflicts, add "our" changes on top 2021-03-16 11:49:02 +01:00
Frank Morgner 26fac9592d macos: add a tokend postfix for dmg 2021-03-16 11:49:02 +01:00
Raul Metsma b9080c16d6 Make sure that we build always x86_64 openssl on macOS
Signed-off-by: Raul Metsma <raul@metsma.ee>
2021-03-16 11:49:02 +01:00
Frank Morgner aae9254018 Fixed syntax error 2021-03-16 11:49:02 +01:00
Raul Metsma 578128e464 Fix build on travis and with CryptoTokenKit enabled 2021-03-16 11:49:02 +01:00
Frank Morgner 1325d5c333 travis: use newer version of xcode for pushed binaries 2021-03-16 11:49:02 +01:00
Raul Metsma 85c5610d39 Build arm64 on macOS with Xcode 12.2
Signed-off-by: Raul Metsma <raul@metsma.ee>
2021-03-16 11:49:02 +01:00
Frank Morgner 63e6683384 mac: use dedicated entitlements for binaries and scripts
fixes the codesigning issue with the unknown blobs in the entitlements

(missing "/" to complete blob)
2021-03-16 11:49:02 +01:00
Peter Popovec f46b617397 Skip authentication if card access control mechanism is not active.
Depending on the "lifecycle" of the file, we may omit the authentication
operation.  Typically if the card is in initialization or creation state,
the access control mechanism is inactive.  If authentification can be
skiped, the card driver is responsible for setting the "acl_inactive"
variable in sc_file structure.
2021-03-16 10:57:05 +01:00
Frank Morgner 8e614bfe6e Nightly: unencrypt only if encrypted key is in available 2021-03-15 14:16:12 +01:00
Jakub Jelen 8d61d0d20d Use more portable switch for uniq to unbreak osx build 2021-03-15 09:33:55 +01:00
Jakub Jelen 1ef79e99f7 reader-pcsc: Avoid strict aliasing issues 2021-03-09 23:59:58 +01:00
Jakub Jelen 60632100a0 pkcs11: Avoid redefinition of ck_interface (#2243) 2021-03-09 23:59:58 +01:00
Jakub Jelen 63031b2193 pkcs11-tool: Avoid strict-aliasing issues on 32b architectures 2021-03-09 23:59:58 +01:00
Jakub Jelen 544dcc6827 configure: Warn about strict alliasing issues in strict builds 2021-03-09 23:59:58 +01:00
Jakub Jelen 2fa6700599 Remove more issues with strict aliasing
These would demonstrate with gcc11 and can be detected with gcc
flag -Wstrict-aliasing=2 (also with older gcc)
2021-03-09 23:59:58 +01:00
Jakub Jelen 45e262f537 westcos: Avoid strict aliasing violations 2021-03-09 23:59:58 +01:00
Jakub Jelen b5f26051bb Fix build on gcc11
This made most of the applications crashing in Fedora 34 when
smart card was plugged in.

The suggested patch makes the code path more obvious for gcc to
handle.

https://bugzilla.redhat.com/show_bug.cgi?id=1930652
2021-03-09 23:59:58 +01:00
Jakub Jelen b8266a4c86 Revert "fixed atrmask for gnuk"
This reverts commit 98beb86a38.
2021-03-01 15:43:28 +01:00
Jakub Jelen 0ce245a411 p11test: Fix one-off comparison 2021-03-01 15:43:28 +01:00
Jakub Jelen 56af7de137 Change (X)EDDSA EC_PARAMS encoding to OID
This is the current interpretation of the specs after talking with
several members of PKCS #11 TC.
2021-03-01 15:43:28 +01:00
Jakub Jelen c39e31b274 pkcs11: Rewrite ec params to use sc_asn1_put_tag() 2021-03-01 15:43:28 +01:00
Jakub Jelen ae771a135f openpgp: Rewrite decipher/derive to use asn1 functions 2021-03-01 15:43:28 +01:00
Jakub Jelen cb8c7647ca asn1: Do not crash on invalid arguments 2021-03-01 15:43:28 +01:00
Jakub Jelen a020b85d94 unittests: Briefly test asn1_encode 2021-03-01 15:43:28 +01:00