Commit Graph

5310 Commits

Author SHA1 Message Date
Frank Morgner
89f9d9e85d add compatibility implementation for strnlen
fixes https://github.com/OpenSC/OpenSC/issues/660
2016-01-20 10:47:27 +01:00
Chris Elledge
f01a8ad22e pkcs11-tool: Switched some printfs to fprintfs to allow pipes to work. 2016-01-19 14:54:02 -05:00
Frank Morgner
a0c0087446 Merge pull request #637 from germanblanco/sm_get_response_loop_fix
Stop reading a file when an error happened *or* all data requested was read.

Fixes https://github.com/OpenSC/OpenSC/issues/632 , but may need adjustments when used with SM
2016-01-15 10:32:46 +01:00
Frank Morgner
75c14ce815 Fixed possible NULL dereference
fixes https://github.com/OpenSC/OpenSC/issues/656
2016-01-14 05:02:28 +01:00
Lukas Wunner
d7559f1546 card-gemsafeV1: Support signing SHA256
GemSAFE V1 cards support signing 36 bytes of free form data.
When signing a hash, the hash must be prepended by the DigestInfo
header. The PKCS#1 padding is done on the card. The 36 bytes limit
is sufficient for MD5 (16 + 18 bytes for the header), SHA1 and
RIPEMD160 (both use 20 + 15 bytes for the header) and MD5_SHA1
(16 + 20 bytes, no header). The algorithm reference ("cryptographic
mechanism reference" in ISO 7816 parlance) for signing free form data
is 0x12.

GemSAFE V3 cards changed the algorithm reference for signing free
form data to 0x02. In addition, they gained the ability to sign SHA256.
Since SHA256 exceeds the 36 bytes limit (32 + 19 bytes for the header),
it must be sent to the card *without* DigestInfo header. The header
will be prepended by the card and it is instructed to do so by sending
algorithm reference 0x42.

This scheme is also supported for SHA1, the algorithm reference is
0x12 in this case. However using this is not necessary as SHA1 fits
within the 36 bytes limit, including the header.

Supporting SHA256 is straightforward, we just add it to the flags
before adding the RSA algorithms. When sc_pkcs15_compute_signature()
calls sc_get_encoding_flags(), the input will be "iFlags 0x202, card
capabilities 0x8000021A" and the output will be "pad flags 0x0, secure
algorithm flags 0x202". I.e. the hash is neither prepended by the
DigestInfo header nor PKCS#1 padded and the hash algorithm is passed
to gemsafe_set_security_env() which can send the appropriate algorithm
reference 0x42 to the card.

However there's a catch: Once we add SHA256 to the flags, PKCS#11
applications will be unable to use the other hashes like SHA1 or
RIPEMD160. That's because register_mechanisms() checks if the card
supports no hashes, and if so, adds all of them:

		if (!(rsa_flags & SC_ALGORITHM_RSA_HASHES)) {
			rsa_flags |= SC_ALGORITHM_RSA_HASHES;
		}

We cannot add these missing hashes to the flags like we did with SHA256
because like SHA256, they would be sent to the card *without* DigestInfo
header. What we want is to send all hashes *with* DigestInfo header,
*except* for SHA256.

We can achieve that by registering a fake RSA algorithm which includes
the missing hashes in its flags. This fake algorithm is never used
because sc_card_find_rsa_alg() searches the algorithm list in-order
and we register the fake algorithm *after* the real algorithms.

The fake algorithm persuades register_mechanisms() to register the
missing hashes because it ORs the flags of all RSA algorithms together:

	num = card->algorithm_count;
	while (num--) {
		switch (alg_info->algorithm) {
			case SC_ALGORITHM_RSA:
				rsa_flags |= alg_info->flags;
				break;
		}
	}

So when signing e.g. a RIPEMD160 hash and sc_pkcs15_compute_signature()
calls sc_get_encoding_flags(), the input will be "iFlags 0x102, card
capabilities 0x8000021A" and the output will be "pad flags 0x100, secure
algorithm flags 0x2". This will result in the hash being prepended by
the DigestInfo header, which is what we want.
2016-01-14 04:55:23 +01:00
Frank Morgner
e8d8f9f2bb Merge pull request #650 from vletoux/pkcs11-crash-when-read-public-key-fails
fix a pkcs11 crash when the public key reading fails

fixes #649
2016-01-06 07:30:15 +01:00
Frank Morgner
611e5200b1 Merge pull request #647 from vletoux/visual-studio-warning
remove visual studio compilation error
2016-01-06 07:28:56 +01:00
LE TOUX Vincent
6e5ae841eb fix a pkcs11 crash when the public key reading fails 2016-01-02 09:31:36 +01:00
LE TOUX Vincent
56275c6993 remove visual studio compilation error
quote:
avoid error C4703: potentially uninitialized local pointer variable 'obj' used line 1414
2015-12-31 18:09:45 +01:00
Frank Morgner
e96d3ccf66 Merge pull request #642 from mouse07410/master
Fix public key access and attributes
2015-12-28 00:48:40 +01:00
Frank Morgner
47835f719f Merge pull request #643 from dengert/piv-pubkey-auth_id
PIV pubkey auth_id fix
2015-12-23 21:06:44 +01:00
Uri Blumenthal
76ed06981b Made sure attribute CKA_TOKEN is set to TRUE. 2015-12-22 13:31:42 -05:00
Doug Engert
aa4b089a41 PIV pubkey auth_id fix
pkcs15-piv.c was setting the auth_id of the public keys
which would cause some appications to require a login to access
a public key. The public keys are obtained from the certificates
which do not require the PIN to read.

Very early drafts of NIST 800-73 did require the PIN to access the
certificates, and the auth_id  was removed in the opensc code for
certificates many years ago, but not from the public keys.
2015-12-22 09:41:39 -06:00
Uri Blumenthal
2b6b0ee05a According to PKCS#11 standard, public key should not have the
attribute CKA_SENSITIVE set to TRUE. This attribute is for
private and secret keys only.
2015-12-21 12:11:48 -05:00
Uri Blumenthal
25dae28ab5 Access to public key should not be PIN-authenticated. Especially
since access to certificate (from which one can get public key)
is not currently PIN-authenticated.
2015-12-21 12:10:46 -05:00
Frank Morgner
2fd32fdd73 Merge pull request #638 from ibpl/master-IB#1047758
Fix smartcard certificate removal and update
2015-12-16 08:21:03 +01:00
Pawel Boguslawski
de42deaae1 Fix smartcard certificate removal and update
This patch fixes bug found in opensc 0.14.0-2 (Debian 8) that blocks
certificate update and removal on Athena ASEPCOS smartcard with error

    Failed to update certificate: Security status not satisfied

OpenSC tries to get the parent's 'DELETE' access before cert removal
and leaves path variable pointing to dir not file to be removed.

Author-Change-Id: IB#1047758
2015-12-15 20:09:03 +01:00
German Blanco
e9f94d7818 Align end of the loop with comment in previous line (exit when 90 00 or length completed). 2015-12-15 10:43:48 +01:00
Frank Morgner
200b09b89f Merge pull request #622 from germanblanco/dnie_memory_leaks_2
Removing memory leaks in DNIe

Refactoring pending. Continued from #606
2015-12-14 20:50:45 +01:00
Andreas Schwier
06f296b978 sc-hsm: implement logout function
- re-selection of the applet resets the applet's state
- removes path in key object and fixes #631
2015-12-12 02:28:23 +01:00
vletoux
57e05d3359 minidriver: use sc_logout for CardDeauthenticate 2015-12-12 02:28:01 +01:00
Frank Morgner
5129c5a060 Fixed memory leaks 2015-12-09 08:22:45 +01:00
Frank Morgner
36ceb890ab Avoid duplicated code of handling security environment 2015-12-06 10:44:08 +01:00
Frank Morgner
ee65ab85ce Avoid duplicated code by unifying key usage 2015-12-06 10:43:30 +01:00
Frank Morgner
5ed3df9024 extend PIN-revalidation to key preparation 2015-12-06 10:42:45 +01:00
Frank Morgner
3384113616 reset login_user with reset_login_state 2015-12-06 10:42:45 +01:00
Frank Morgner
b43ea19320 reset login_user on CKR_USER_NOT_LOGGED_IN 2015-12-06 10:42:45 +01:00
Frank Morgner
43a844c949 cardos 4.3+: enable logout command 2015-12-06 10:42:45 +01:00
Frank Morgner
83ef753799 Implemented atomic PKCS#11 transactions 2015-12-06 10:42:45 +01:00
Wouter Verhelst
5de1ec4518 Allow ASN.1 decoding if the file seems incomplete
Some cards (e.g., BELPIC) have a hardcoded file length that does not
match the actual file length (e.g., 65535 bytes), and simply return the
data that is actually on the card when asked.

It is useful to still be able to do an ASN.1 decode in that case.

Signed-off-by: Wouter Verhelst <w@uter.be>
2015-12-01 16:20:17 +01:00
Frank Morgner
56d52afb17 Merge pull request #617 from mtrojnar/os_locking
Enable OS locking
2015-12-01 11:21:35 +01:00
Michał Trojnara
fa9da7ad01 configurable OS thread locking 2015-12-01 09:19:03 +01:00
Frank Morgner
b6856e8dbf don't use unicode ticks 2015-11-30 01:33:11 +01:00
Flavio Medeiros
b9adbae5f0 Avoiding conditional directives that split up parts of statements. 2015-11-28 11:33:38 -03:00
German Blanco
d1a1830115 Removing all memory leaks in DNIe but one. Refactoring pending. 2015-11-27 11:32:33 +01:00
Michał Trojnara
f9e614890d Fix a buffer overflow in thread mutex create 2015-11-26 12:32:47 +01:00
Frank Morgner
a454dd7fc9 Merge pull request #605 from germanblanco/dnie_ui_depends_on_ssl_2
DNIe UI moved into card-dnie.c

closes #362
2015-11-21 19:22:07 +01:00
Frank Morgner
d9fc49daa5 reader-pcsc: get tlv properties only when supported 2015-11-17 00:52:49 +01:00
Frank Morgner
641a71a2f4 Merge pull request #601 from frankmorgner/coverity
Some more fixes for problems reported by Coverity scan
2015-11-16 12:29:57 +01:00
German Blanco
1596ca4244 DNIe user interface moved into card-dnie.c. 2015-11-10 12:10:56 +01:00
Frank Morgner
f13da8abfa removed unsupported opensc_pkcs11_install.js 2015-11-02 23:51:28 +01:00
Frank Morgner
622b71970f add compat_report_rangecheckfailure.c to libcompat 2015-11-01 21:02:34 +01:00
Frank Morgner
d6cea60500 Merge pull request #600 from vletoux/patch_openSSL
win32: link OpenSSL statically again
2015-11-01 20:59:49 +01:00
Frank Morgner
613d698d3d fixed potential NULL dereference 2015-11-01 17:13:24 +01:00
vletoux
8a47f238de win32: link OpenSSL statically again 2015-11-01 13:35:05 +01:00
Frank Morgner
681e8aef98 Fixed accessing Application label
regression of 78018a2b49
2015-11-01 13:22:26 +01:00
Frank Morgner
218a9eb52c make casting explicit 2015-11-01 13:18:39 +01:00
Frank Morgner
98d7578113 ctbcs.c: fixed out of bounds write 2015-11-01 11:33:40 +01:00
Frank Morgner
a649d66b02 card-westcos.c: fixed dead code 2015-11-01 10:49:19 +01:00
Frank Morgner
a34d1f7dcd sc-hsm-tool.c: fixed potential resource leak 2015-11-01 10:44:24 +01:00
Frank Morgner
4ca7daf31c pkcs15-tool.c: fixed potential resource leak 2015-11-01 10:44:24 +01:00
Frank Morgner
5399c264fb cryptoflex-tool.c: fixed potential resource leak 2015-11-01 10:44:23 +01:00
Frank Morgner
c2ff4f090a pkcs15-pubkey.c: fixed potential resource leak 2015-11-01 10:44:23 +01:00
Frank Morgner
0f9645587a cwa14890.c: fixed potential resource leak 2015-11-01 10:44:23 +01:00
Frank Morgner
21a8e7e5f9 Merge pull request #591 from vletoux/isoApplet
isoApplet: fix card not recognized by minidriver
2015-10-31 02:28:21 +01:00
Frank Morgner
451386886d Merge pull request #573 from frankmorgner/coverity
Fix some more memory leaks reported by Coverity
2015-10-31 02:24:51 +01:00
Frank Morgner
8e7049c2fa removed unused variables 2015-10-30 18:21:40 +01:00
Frank Morgner
fa9ffb7b90 fixed uninitialized variable
regression of baab26d871
2015-10-30 18:21:40 +01:00
Frank Morgner
9f0087d968 fixed missing includes 2015-10-30 18:21:40 +01:00
Frank Morgner
ad5d16927c fixed cflags for onepin module 2015-10-30 16:45:22 +01:00
Frank Morgner
00ea7a68be Removes unused variables 2015-10-30 12:18:04 +01:00
Frank Morgner
7e29fcd26c pkcs15-authentic.c: fixed potential resource leak 2015-10-30 12:18:04 +01:00
Frank Morgner
f9a73c0b20 pkcs15-sc-hsm.c: fixed potential resource leak 2015-10-30 12:18:04 +01:00
Frank Morgner
0853ecd887 pkcs15-pubkey.c: fixed potential resource leak 2015-10-30 12:18:04 +01:00
Frank Morgner
98b9b37e12 card-openpgp.c: fixed potential resource leak 2015-10-30 12:18:04 +01:00
Frank Morgner
9e1a5447d4 profile.c: fixed potential resource leak 2015-10-30 12:15:06 +01:00
Frank Morgner
fd904fbcb8 pkcs15-oberthur-awp.c: fixed potential resource leak 2015-10-30 12:15:06 +01:00
Frank Morgner
e7316b60e3 pkcs15-myeid.c: fixed potential resource leak 2015-10-30 12:15:06 +01:00
Frank Morgner
baab26d871 pkcs15-lib.c: fixed potential resource leak 2015-10-30 12:15:06 +01:00
Frank Morgner
4f4c4aa5ec pkcs15-iasecc.c: fixed potential resource leak 2015-10-30 12:15:06 +01:00
Frank Morgner
34b6d95ec6 card-westcos.c: fixed potential resource leak 2015-10-30 12:15:06 +01:00
Frank Morgner
ecf147099a card-epass2003.c: fixed potential resource leak 2015-10-30 12:15:06 +01:00
Frank Morgner
2963588887 card-authentic.c: fixed potential resource leak 2015-10-30 12:15:06 +01:00
Frank Morgner
b96ba14aae added fall through comment 2015-10-30 12:15:06 +01:00
Andreas Schwier
0caf0d1dd6 sc-hsm: Add missing include introduced by #580 2015-10-29 14:09:01 +01:00
Frank Morgner
decd5ab987 Merge pull request #580 from frankmorgner/select
Fix issues related to selecting a file
2015-10-29 13:30:37 +01:00
Frank Morgner
c50a951337 Merge pull request #566 from vletoux/ecc_minidriver
First ECC support for the minidriver
2015-10-24 23:32:42 +02:00
vletoux
206eb7124a isoApplet: fix card not recognized by minidriver 2015-10-23 23:03:25 +02:00
Petr Spacek
52b6505909 export all C_* symbols
Header files distributed with PKCS#11 v2.30 define all functions as
extern and some applications (like BIND 9.10) do not work without all
functions.
2015-10-22 18:07:26 +02:00
Frank Morgner
249f258ff2 Merge pull request #584 from marschap/card-openpgp-cleanup2
OpenPGP card cleanup
2015-10-17 17:36:40 +02:00
Frank Morgner
4ddf2cc042 Merge pull request #579 from dengert/piv-cac
Do not expose access to PIV emulated files from utilities
2015-10-17 17:34:39 +02:00
Frank Morgner
0ca46910f7 use tabs only for indenting 2015-10-16 09:58:01 +02:00
vletoux
35175a814c minidriver: fix according to frank's comments 2015-10-15 22:40:36 +02:00
Peter Marschall
6109a8792d OpenPGP: add additional manufacturers 2015-10-15 16:43:10 +02:00
Peter Marschall
a0ca6b2ef0 OpenPGP: set card's version in pgp_init() 2015-10-15 16:43:10 +02:00
Peter Marschall
7078fbd505 OpenPGP: cleanup pgp_init()
- use LOG_FUNC_RETURN instead of return for symmetry with LOG_FUNC_CALLED
2015-10-15 16:43:10 +02:00
Peter Marschall
e1db96b73b OpenPGP: extend pgp_match_card()
- explicitly check for supported versions
- log successful matches by AID with their type
- log detection of unsupported OpenPGP-type cards
2015-10-15 16:43:09 +02:00
Peter Marschall
7c2adb1fc8 OpenPGP: 1st preparations for newer versions
- add references to new specs
- add new enum _version constants
2015-10-15 16:43:09 +02:00
Peter Marschall
69b482dce6 OpenPGP: cleanup pgp_get_card_features()
- bug fix: re-initialize index to start searching at the right place
- get rid of unnecessary variable
- add some line breaks & comemnts for easier understanding
2015-10-15 16:42:58 +02:00
Peter Marschall
2a269c5267 OpenPGP: cleanup pgp_build_tlv()
- get rid of intermediate variable
- clarify check in while() loop
- line breaks for easier reading
2015-10-15 16:17:22 +02:00
Peter Marschall
3d492ae376 OpenPGP: cleanup pgp_erase_card()
- get rid of unnecessary variable
- use easily understandable hex representation of APDUs
- auto-calculate APDU length based on hex representation
- restrict scope of some variables
- use sc_log() instead of directly writing to console
- line breaks & comments for easier reading/understanding
- fix typo in log message
2015-10-15 16:17:22 +02:00
Peter Marschall
3d4fbd776d OpenPGP: harmonize coding style
- 2 line breaks between functions for easier reading
- function type on separate line
- mark each function as 'ABI' or 'Internal'
- slightly doxygen-ize comments introducing functions
- fix typos in comments
- break over-long comment lines
- break comment lines at sensible places
- consistent calling style for DRVDATA()

- no code change
2015-10-15 16:17:22 +02:00
Peter Marschall
7ba47fd5a9 OpenPGP: consistently use card->ctx in pgp_put_data_plain()
- get rid of unnecessary variable
- harmonize coding style: adapt to prevailing use of card->ctx
2015-10-15 16:17:22 +02:00
Peter Marschall
1a05f968bd OpenPGP: simplify gnuk_write_certificate()
- get rid of unnecessary variables
- use for-loop to initialize/check/increase run variable in one place
- restrict variables to the necessary scope
- use ternary operator inside a statement instead of if...else...
2015-10-15 16:17:22 +02:00
Peter Marschall
d2b1c8228f OpenPGP: set apdu_case on declaration
- use ternary operator to set apdu_case immediately on declaration
  for the GNUK and non-GNUK case
2015-10-15 16:17:22 +02:00
Peter Marschall
3341c5bb8f OpenPGP: make logical structure clearer
- one line per sub-term in the condition of the conditional statement
2015-10-15 16:17:11 +02:00
Frank Morgner
e316bf3140 Merge pull request #582 from marschap/openpgp-tool-fixes
Openpgp tool fixes
2015-10-15 13:13:18 +02:00
Peter Marschall
6498721076 piv: fix typos in usage & man page 2015-10-15 12:51:19 +02:00
Peter Marschall
7de373b3b9 OpenPGP: mark do_erase as an action in openpgp-tool
- avoid the unintended output of user info when only erasing was requested
2015-10-15 12:51:10 +02:00
Peter Marschall
524ad56146 OpenPGP: remove unnecessary semicolons in openpgp-tool
- this is C, not a shell script
2015-10-15 12:51:10 +02:00