Commit Graph

6347 Commits

Author SHA1 Message Date
Frank Morgner 907c9479e2 replace sc_debug_hex with sc_log_hex 2018-12-06 09:26:42 +01:00
Frank Morgner d4f1a26215 respect SM debug level 2018-12-06 09:26:42 +01:00
Frank Morgner e3dda8894e log errors in verbose 2018-12-06 09:26:42 +01:00
Frank Morgner 00a150f74c replaced SC_FUNC_RETURN with LOG_FUNC_RETURN 2018-12-06 09:26:42 +01:00
Frank Morgner 24b50a4277 replace sc_debug with sc_log 2018-12-06 09:26:42 +01:00
Frank Morgner cf55cdc637 replace SC_FUNC_CALLED with LOG_FUNC_CALLED 2018-12-06 09:26:42 +01:00
Luka Logar 18dc38a618 Fix some pkcs15-init issues
1. pkcs15-init is using XKU but it should use cert KU to check private key usage instead.
2. Don't mark imported keys as ALWAYSSENSITIVE and NEVEREXTRACTABLE as they are not.
3. When importing keys from PKCS#12 files (with several certs inside), use consecutive IDs for additional certificates (instead of starting from 45).
2018-12-05 12:43:08 +01:00
Luka Logar ba77042911 Fix token label formatting
PKCS#15 token label may be padded with spaces, trim it when making a PKCS#11 token label in order not to loose closing parenthesis.
I would actually prefer for the token label to be "myCard (User PIN)" instead of current "User PIN (myCard)"

before:
$ pkcs11-tool --list-slots
Available slots:
Slot 0 (0x0): OMNIKEY AG CardMan 3121 00 00
  token label        : User PIN (myCard
...

after:
$ pkcs11-tool --list-slots
Available slots:
Slot 0 (0x0): OMNIKEY AG CardMan 3121 00 00
  token label        : User PIN (myCard)
...
2018-12-05 12:42:30 +01:00
Luka Logar 2552fde05f Fix some pinpad reader related issues (#1540)
1. Show pinpad reader capabilities even for uninitialised tokens. This way pinpad can be used during initialisation.
2. Make possible to create so-pin object during initialisation even if no so-pin was provided (on the command line) but pinpad reader is used and card profile contains so-pin data.
2018-12-05 12:41:58 +01:00
Hannu Honkanen 7d640e62c1 Fixed incorrect conversion fron int to CK_BBOOL when converting PKCS#15 user consent to a PKCS#11 attribute 2018-12-05 12:10:42 +01:00
Hannu Honkanen 9e5a324903 Edited according to PR review: CKA_ALWAYS_AUTHENTICATE only associated with private keys. Defined a custom attribute to achieve same functionality with secret keys. Updated man pages. 2018-12-05 12:10:42 +01:00
Hannu Honkanen ee8c80af4f Implemented handling of CKA_ALWAYS_AUTHENTICATE attribute when importing and generating keys, mapping it to pkcs#15 userConsent field. Added command line options to pkcs11-tool and pkcs15-init tool to use the feature. 2018-12-05 12:10:42 +01:00
Frank Morgner b01ca2dcc9
added support for colors (#1534)
because everyone loves colors
2018-11-25 22:08:36 +01:00
Jakub Jelen f1f98f829c pkcs11-tool: Unbreak signature and verification in pkcs11-tool 2018-11-25 22:07:33 +01:00
Jakub Jelen fd2343f4a2 cac: Dump the data model number, which is useful for the capabilities detection
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
2018-11-25 22:07:33 +01:00
Shahin Hajikhorasani 0fca7df33a Update reader-pcsc.c (#1537)
Error handling extended in case of changing the card reader
2018-11-25 22:05:35 +01:00
Mounir IDRASSI 1ab93312cd SM: fix crash if nested GET RESPONSE issued during sm session fails or returns invalid MAC. 2018-11-21 15:35:53 +01:00
Frank Morgner ad83c2c5a9 use proper debug level for card matching 2018-11-20 12:48:58 +01:00
Doug Engert 764c61446e pkcs15-crypt - Handle keys with user_consent - Fixes #1292
This fixes problem as stated in:
https://github.com/OpenSC/OpenSC/issues/1292#issuecomment-431879472

pkcs15-crypt.c will treat keys with user_consent like PKCS#11 would.
SC_AC_CONTEXT_SPECIFIC is set when doing a verify so a card driver can
take action if needed.

card-piv.c is currently the only driver doing so.
It uses this to hold the card lock so both the VERIFY and following crypto
operations are in the same transaction. The card enforces this restriction.
Without this additional APDUs may be sent before every transaction to test
that the expected applet is selected.

Unlike the circumvention of using ignore_user_consent=true and pin caching
this modification allows a pin pad reader to be used for keys requiring user_consent.

 On branch pkcs15-context-specific
 Changes to be committed:
	modified:   pkcs15-crypt.c
2018-11-20 11:53:57 +01:00
Hannu Honkanen aa8f666f46 Removed unnecessary spaces from framework-pkc15.c as requested.
pkcs15: added explicit comparison when checking return value of sc_compare_oid() to make the logic more obvious.
2018-11-20 11:52:54 +01:00
Hannu Honkanen 7f91b6e07f MyEID: add AES algorithms to tokenInfo as supported during init. It is better to do it already in init, because adding them in C_UnwrapKey operations would require SO-PIN which is inconvenient.
pkcs15: added function to get a specific supported algorithm, checking also OID.
This is needed because for AES there are different OIDs for each key length.
2018-11-20 11:52:54 +01:00
Hannu Honkanen c051ef64dd Convert sequences of four spaces to tabs to fix indentation problems. 2018-11-20 11:52:54 +01:00
Hannu Honkanen 3ec39919c3 pkcs15-lib: Must use keyargs->value_len instead of keyargs->key.data_len * 8 when calling check_key_compatibility(), to get correct result in key unwrap operations. In this case data_len is 0, but value_len contains the key length in bits. 2018-11-20 11:52:54 +01:00
Steve Ross abdbb9d8c0 Enable CoolKey driver to handle 2048-bit keys.
For a problem description, see <https://github.com/OpenSC/OpenSC/issues/1524>.
In a nutshell, for a card with the CoolKey applet and 2048-bit keys,
the command
	pkcs11-tool --test --login
fails to complete all of its tests.

This commit consists of a patch from @dengert.

To avoid triggering an error when the data exceeds 255 bytes, this commit
limits the amount of the payload sent to the CoolKey applet on the card based
on the maximum amount of data that the card can receive, and overhead bytes
(namely, a header and nonce) that accompany the payload.

With this change, the command
	pkcs11-tool --test --login
succeeds.
2018-11-19 12:42:17 +01:00
Frank Morgner ee3fdc6938 fixed missing function stub 2018-11-13 15:50:17 +01:00
Frank Morgner 2cb6f9c94f fixed compilation without OpenSSL
closes https://github.com/OpenSC/OpenSC/pull/1518
2018-11-13 15:50:17 +01:00
Frank Morgner f3a2962358 pkcs11: perform memory cleanup on dll unload 2018-11-13 15:50:17 +01:00
Frank Morgner 447335bc1f md: clean OpenSSL memory when DLL is unloaded 2018-11-13 15:50:17 +01:00
Frank Morgner 027ccad439 allow specifying the size of OpenSSL secure memory
... and set it for builds where we're linking OpenSSL statically (i.e.
Windows and macOS)

fixes https://github.com/OpenSC/OpenSC/issues/1515
2018-11-13 15:50:17 +01:00
Andreas Kemnade eddea6f3c2 fix logic of send/recv sizes in config files
- they are not set if
  SCardControl(card_handle, CM_IOCTL_GET_FEATURE_REQUEST, ...
  fails
- regarding max_send_size the logic is inverted
2018-11-09 08:56:53 +01:00
Frank Morgner c032b2f15d CID 320271 (#1 of 1): Dereference before null check (REVERSE_INULL) 2018-11-06 15:53:17 +01:00
Frank Morgner 3c0a16dc39 CID 321790 (#1 of 1): Resource leak (RESOURCE_LEAK) 2018-11-06 15:53:17 +01:00
Frank Morgner 1e7bb83659 CID 324485 (#1 of 2): Integer overflowed argument (INTEGER_OVERFLOW) 2018-11-06 15:53:17 +01:00
Frank Morgner 609095a4f4 CID 325860 (#1 of 1): Dereference before null check (REVERSE_INULL) 2018-11-06 15:53:17 +01:00
Frank Morgner 54c9d65a48 CID 325861 (#1 of 1): Dereference before null check (REVERSE_INULL) 2018-11-06 15:53:17 +01:00
Peter Marschall c6d252611b openpgp-tool: add missing length check in prettify_name() 2018-11-06 12:41:19 +01:00
Peter Marschall 4e5805dc5d openpgp-tool: don't uppercase hex string 2018-11-06 12:41:19 +01:00
Peter Marschall afda163dc6 openpgp-tool: fix typo 2018-11-06 12:41:19 +01:00
Peter Marschall ec3830fe66 openpgp-tool: use more compatible strftime() format spec
Replace the Single UNIX specific shorthand %T for %H:%M:%S with the latter
to keep MingW happy.
2018-11-06 12:41:19 +01:00
Peter Marschall 85258f2951 openpgp-tool: use key type to indicate key to generate
Instead of only expecting a key length, and implicitly assuming RSA
as the key algorithm, introduce option --key-type to pass the key type
as a string.

When generating the key determine key algorithm and attributes based on
the key type passed.

If no key was given, default to "rsa2048".
2018-11-06 12:41:19 +01:00
Peter Marschall c9f5e05aca openpgp-tool: new option --key-info to display key info 2018-11-06 12:41:19 +01:00
Peter Marschall 1866c3e930 openpgp-tool: new option --card-info to display card info 2018-11-06 12:41:19 +01:00
Frank Morgner 263b945f62 md: added support for PSS 2018-11-06 12:38:57 +01:00
Frank Morgner 99a9029848 md: use constants for AlgId comparison 2018-11-06 12:38:47 +01:00
Frank Morgner 22c8204a2f Merge remote-tracking branch 'upstream/pr/1393'
closes https://github.com/OpenSC/OpenSC/pull/1393
2018-11-06 10:51:24 +01:00
Frank Morgner 13c7574510 PIV: less debugging
- debugging pointers is useless in static log file
- removed double debugging of APDUs
2018-11-06 01:42:41 +01:00
Jakub Jelen eaed345a76 Add missing header file to the tarball 2018-11-05 09:15:20 +01:00
Jakub Jelen 9342f8ad0a padding: Fix error checking in RSA-PSS 2018-11-05 09:15:20 +01:00
Jakub Jelen 0f5d73d816 framework-pkcs15.c: Add SHA224 mechanism for PKCS#1.5 2018-11-05 09:15:20 +01:00
Jakub Jelen 8ccc39352a p11test: Do not report incomplete key pairs 2018-11-05 09:15:20 +01:00
Jakub Jelen d2671ee05b framework-pkcs15.c: Add PKCS#1 mechanisms also if SC_ALGORITHM_RSA_HASH_NONE is defined 2018-11-05 09:15:20 +01:00
Jakub Jelen 7e0ef7c16c framework-pkcs15.c: Reformat
* Reasonable line lengths
 * Correct indentation
 * Add missing SHA224 mechanism
2018-11-05 09:15:20 +01:00
Jakub Jelen 7cced08a88 coolkey: Check return values from list initialization (coverity)
>>>     CID 324484:  Error handling issues  (CHECKED_RETURN)
>>>     Calling "list_init" without checking return value (as is done elsewhere 8 out of 9 times).
2018-11-05 09:15:20 +01:00
Jakub Jelen f276f7f8f4 coverity: Add allocation check
*** CID 323588:  Uninitialized variables  (UNINIT)
/src/libopensc/sc.c: 873 in sc_mem_secure_alloc()
2018-11-05 09:15:20 +01:00
Hannu Honkanen 351e0d2bd6 Merge remote-tracking branch 'upstream/master' into wrapping-rebased and resolve conflicts 2018-11-02 13:42:41 +02:00
Hannu Honkanen b35fb19ec4 Resolved conflict in pkcs15_create_secret_key 2018-11-02 13:28:51 +02:00
Peter Marschall 26025b2f5d pkcs15-tool: list & dump cleanups
* when listing public keys, do not cut object labels in compact mode
* when listing private keys in compact mode, left align labels
* make hex codes at least 2 chars wide by changing "0x%X" to "0x%02X"
2018-11-01 12:25:04 +01:00
Frank Morgner c70888f9ab allow compilation with --disable-shared 2018-11-01 00:17:22 +01:00
Frank Morgner 54cb1099a0 fixed warnings about precision loss 2018-11-01 00:17:22 +01:00
Frank Morgner 5c7b7bb0b1 fixed minor XCode documentation warnings 2018-11-01 00:17:22 +01:00
Hannu Honkanen f88419bc63 Removed pointless curly brackets 2018-10-31 10:36:50 +02:00
Hannu Honkanen 7bb53423a1 Code cleanup and minor corrections according to review. pkcs15-lib: Extractable keys are now marked as native. Check return value of check_key_compatibility in more explicit way to avoid misunderstandings. 2018-10-31 10:36:41 +02:00
Hannu Honkanen 90ec7123ba Corrections and code cleanup as requested in review. Changed value to void* in sc_sec_env_param_t, because param_type defines type of the value. Fixed handling of secret key length in framework-pkcs15 and pkcs15-lib: CKA_VALUE_LEN from PKCS#11 is in bytes, PKCS#15 objects need key length in bits. Rebased on top of upstream/master and resolved merge conflicts. 2018-10-31 10:27:03 +02:00
Lars Silvén 84317f4e9d Fixing missing call to sc_unlock. 2018-10-31 10:27:03 +02:00
Hannu Honkanen 8ebb43d440 Removed #ifdef USE_PKCS15_INIT around __pkcs15_create_secret_key_object. This function is now used also when reading and parsing a card, not only when creating new objects. 2018-10-31 10:27:03 +02:00
Hannu Honkanen ec297b618f sc_pkcs15_wrap: Fixed checking target key type. (checked partly from wrapping key) 2018-10-31 10:27:03 +02:00
Hannu Honkanen e636b64377 Fixed: Return OK by PKCS#11 convention if NULL out buffer is provided, when caller wants to query required buffer size. 2018-10-31 10:27:03 +02:00
Hannu Honkanen f2c041d290 card-myeid: Removed NULL out buffer assertion to allow caller to query required buffer size.
mechanism.c: Bug fix to sc_pkcs11_wrap. Wrong operation was stopped in end of the function.
2018-10-31 10:27:03 +02:00
Hannu Honkanen 287a63c704 Fixes to key wrapping and unwrapping code: Set IV correctly in symmetric unwrap. Correctly distinguish symmetric and asymmetric operation when building APDUs. Check CKA_TOKEN from the pkcs15 object in framework_pkcs15. Updated some comments. 2018-10-31 10:27:03 +02:00
Hannu Honkanen 861d8b308b Fixed myeid_unwrap with symmetric keys: set correct p2 and no padding indicator byte. 2018-10-31 10:27:03 +02:00
Hannu Honkanen 4ce7e5289b Fixed setting secret key length. CKA_VALUE_LEN comes as number of bytes, so multiply it by 8 to set correct bit length to the key file. 2018-10-31 10:27:03 +02:00
Hannu Honkanen eba75ead20 framework-pkcs15: set CKA_EXTRACTABLE into pkcs#15 secret key object's access flags when set. pkcs15-sec: Return needed buffer size correctly when an insufficient buffer is provided. 2018-10-31 10:27:03 +02:00
Hannu Honkanen f74150b53d Proprietary attribute bits in FCP had to be adjusted due to conflicts with existing attributes. The needed changes were made to both card and OpenSC code. 2018-10-31 10:27:03 +02:00
Hannu Honkanen c891ad2aad Fixed version check for key wrapping functionality. Return needed buffer size in myeid_wrap_key, if no buffer or too small buffer is provided. 2018-10-31 10:27:03 +02:00
Lars Silvén 6b8c284d3e Fixing pointer conversion that is invalid on some architectures. 2018-10-31 10:27:03 +02:00
Hannu Honkanen 550d4eb030 Small fixes to key wrapping and unwrapping. Handle target file ref using sc_sec_env_param type. Transmit initialization vector in symmetric key operations from PKCS#11 layer (mechanism param) to the card driver level, allow setting it in sc_set_security_env. 2018-10-31 10:27:03 +02:00
Hannu Honkanen 2487bc18d1 When creating symmetric keys, use CKK_ definitions (key type) rather than CKM_ definitions (mechanism) to specify the key type. 2018-10-31 10:24:19 +02:00
Hannu Honkanen 7454133272 Added flags to distinguish AES ECB and CBC modes. Added SC_ALGORIHM_UNDEFINED definition to be used with CKK_GENERIC_SECRET type keys. Added sc_sec_env_param type, which can be used to define additional parameters when settings security environment. This is now used for setting IV in symmetric crypto and target EF in key wrapping/unwrapping. 2018-10-31 10:24:19 +02:00
Hannu Honkanen a2156da044 Fix encoding of SC_ASN1_CHOICE entry "parameters" in c_asn1_algorithm_info. Format only the selected entry of the choice. 2018-10-31 10:24:19 +02:00
Hannu Honkanen ae5675ca22 Fixed MSE for unwrap operation. Fixed wrong P1 when formatting APDU in myeid_unwrap_key. 2018-10-31 10:24:19 +02:00
Hannu Honkanen aa814fd8e8 Implemented C_Wrap into PKCS#11 interface. Added support for wrapping and unwrapping with secret keys into framework-pkcs15.c and all the way to the card driver level. 2018-10-31 10:24:19 +02:00
Hannu Honkanen a9ee85452e Resolved a merge conflict. Included both changes manually. 2018-10-31 10:24:19 +02:00
Hannu Honkanen c217b254fc MyEID: Initial implementation of key wrapping and unwrapping operations, and the related additions to myeid_set_security_env. 2018-10-31 10:24:19 +02:00
Hannu Honkanen edd48b3200 pkcs15init:
- Added session_object flag to sc_pkcs15init_skeyargs to enable on-card session objects.
- Corrections to handling native and extractable flags
- Allow creating an empty secret key EF for receiving an unwrapped key later.
2018-10-31 10:24:19 +02:00
Hannu Honkanen 9d6ac01c27 pkcs15init: Handle user_consent and set new proprietary information flags in myeid_create_key(). 2018-10-31 10:24:19 +02:00
Hannu Honkanen 1c09fa8a22 Handle AES algorithm. Doesn't set any flags, but check for AES is needed to avoid SC_ERROR_NOT_SUPPORTED. 2018-10-31 10:24:19 +02:00
Hannu Honkanen 7fc6c52f81 Set native=1 as default when decoding. Check supported algorithms and set PKCS#11 key type, if key supports AES. 2018-10-31 10:22:16 +02:00
Hannu Honkanen 9772edc7d1 Handle -u option (x509-usage) when storing secret keys. 2018-10-31 10:22:16 +02:00
Hannu Honkanen a10480d50e Continued implementation of unwrap: Creation of a target key object on card to receive an unwrapped key. Setting target key path in sc_security_env_t. 2018-10-31 10:22:16 +02:00
Hannu Honkanen 5f51d5d315 Added implementation of C_UnwrapKey all the way from PKCS#11 interface to the card driver level.
Not yet complete, but can be run with CKA_TOKEN=FALSE set in the target object. Currently unwrapping emulated
with a decrypt operation in card-myeid.c. To be improved.
2018-10-31 10:22:16 +02:00
Jakub Jelen e2b1fb81e0 Restore minimal CAC1 driver for legacy cards (#1502)
* Add minimal CAC1 driver for legacy cards.

It is using the same pkcs15 backend as the CAC2 cards as well as some of
the CAC2 driver methods.

The separation is made mostly for easier card matching or disabling.
2018-10-30 17:27:28 +01:00
Frank Morgner c3bef7d527 fixed compilation with XCode 10
fixes https://github.com/OpenSC/OpenSC/issues/1485
2018-10-24 10:34:43 +02:00
Frank Morgner 5095e29ae3 gio: avoid unneccessary unitialization 2018-10-22 21:44:07 +02:00
Doug Engert 2fd8e278f5 pkcs11/openssl.c - add missing mechanisms fixes #1497
On branch pkcs11-openssl-c
 Changes to be committed:
	modified:   ../pkcs11/openssl.c
2018-10-19 08:27:47 +02:00
Vadim Penzin 195d53b8a2 Fix division by zero in SimCList when appending to an empty list. 2018-10-16 12:10:04 +02:00
Frank Morgner 8c535c184f removed duplicate code for adding padding
Fixes padding handling of SC_ALGORITHM_RSA_PAD_NONE introduced with
e5707b545e
2018-10-15 15:21:52 +02:00
Jakub Jelen 46c99e769d ctx: Move coolkey driver up after improving the matching
Fixes #1483
2018-10-15 12:14:22 +02:00
Jakub Jelen f220d0b77d coolkey: Improve card matching to avoid mismatches in muscle 2018-10-15 12:14:22 +02:00
Jakub Jelen 55a8478ed6 cac: These functions do not have to be exposed 2018-10-15 12:14:22 +02:00
Frank Morgner ac276b1202
starcos: fixed decipher with 2.3 (#1496)
closes https://github.com/OpenSC/OpenSC/issues/765
fixes https://github.com/OpenSC/OpenSC/issues/1495
2018-10-11 22:50:37 +02:00
Luka Logar d517d8e18d Fix minidriver padding
Commit e5707b545e broke signing using minidriver on Windows.

More specifically changing #define SC_ALGORITHM_RSA_PAD_NONE from 0x00000000 to 0x00000001 caused a call to sc_pkcs1_encode() to fail as the padding algorithm was not specified anywhere in the CardSignData() implementation. It kind of worked as long as SC_ALGORITHM_RSA_PAD_NONE was 0x00000000, but the above mentioned commit broke this.

Now padding algorithm has to be explicitly specified, otherwise a call to sc_pkcs1_encode() will fail.
2018-10-11 12:47:48 +02:00
Peter Marschall 550665b906 OpenPGP: refactor pgp_get_card_features()
Use pgp_parse_alog_attr_blob() to get the algorithm attribute DO's contents.
2018-10-10 14:52:29 +02:00
Peter Marschall 8a564107a8 OpenPGP: introduce gpg_parse_algo_attr_blob()
Introduce a central function to parse the algorithm atributes in DOs C1 - C3.
2018-10-10 14:52:29 +02:00
Peter Marschall 248ece23c6 OpenPGP: bail out on non-RSA key generation/import
Also add the necessary algorithm info where necessary.
2018-10-10 14:52:29 +02:00
Peter Marschall c2f02f72bd OpenPGP: adapt data structures to support RSA alternatives
* update callers to use the adapted structures.
2018-10-10 14:52:29 +02:00
Peter Marschall 772d20969a OpenPGP: first steps to support key types beyond RSA
- rename 'keytype' in some OpenPGP-specific types to 'key_id'
  because they key ID was what the field was used for
- introduce field 'algorithm' in the structures above
  to indicate the key's algorithm: RSA, ...
- define constant SC_OPENPGP_KEYALGO_RSA and use it
- rename constants SC_OPENPGP_KEYFORMAT_* to SC_OPENPGP_KEYFORMAT_RSA_*
  because they are RSA specific
2018-10-10 14:52:29 +02:00
Peter Marschall f1ae31aea4 OpenPGP: expose additional algorithms only with EXT_CAP_ALG_ATTR_CHANGEABLE
List additional algorithms & attributes as supported only when the card
supports changing the algorithms attributes DOs and exposes this by having
the EXT_CAP_ALG_ATTR_CHANGEABLE capability set.

Using different algorithms and attributes requires changing the algorithm
attributes DOs. If that is not supported - as indicated by a missing
EXT_CAP_ALG_ATTR_CHANGEABLE capability - then only those algorithms
described by the current algorithms attributes DOs' contents can be used.

In addition simplify setting the flags.
2018-10-10 14:52:29 +02:00
Peter Marschall 44d6116c59 OpenPGP: slight cleanups
* use variables if they are already there
* be a bit more explicit in logging
* more consistent tag format: %04X
* cleanup flag setting for _sc_card_add_rsa_alg()
2018-10-10 14:52:29 +02:00
Frank Morgner ea6f7cfe1d
Added memory locking for secrets (#1491)
When caching a PIN in memory or using an OpenSSL private key this data should not be swapped to disk.
2018-10-10 14:52:01 +02:00
gabrielmuller 6bf67f7917 onepin option also needs PIN to CREATE
I previously changed the default option but forgot to make the same change for onepin.
2018-10-08 21:35:23 +02:00
Peter Marschall a8db9cb4f0 openpgp-tool: harmonize error messages
* use symbolic constants for errors & success
* use util_error() to show errors
* print error messages to stderr
2018-10-04 09:41:31 +02:00
Peter Marschall e4a0b09968 openpgp-tool: remove unnecessary variable
* 'opt_keylen' was only set, but never used => remove
* passing the key length is not an action => do not mark it as such
2018-10-04 09:41:31 +02:00
Jakub Jelen a5daaaff0c piv-tool: Error checking 2018-10-01 23:07:34 +02:00
Jakub Jelen ef724e1e57 pkcs15-authentic: Do not confuse static analyzers 2018-10-01 23:07:34 +02:00
Jakub Jelen 52959df9f6 pkcs15-oberthur: Avoid memory leaks on failures 2018-10-01 23:07:34 +02:00
Jakub Jelen a1dfdbbdbc pkcs15-oberthur-awp: Do not confuse cppcheck 2018-10-01 23:07:34 +02:00
Jakub Jelen e920ef8eb8 opensc-explorer: Make static analyzers happy 2018-10-01 23:07:34 +02:00
Jakub Jelen 16c5a352a4 piv-tool: Avoid memory leaks on realloc failure 2018-10-01 23:07:34 +02:00
Jakub Jelen 9a690a96e0 sc-hsm-tool: Avoid memory leak 2018-10-01 23:07:34 +02:00
Jakub Jelen bce43e6855 Remove dead code 2018-10-01 23:07:34 +02:00
Jakub Jelen 74105300bf card-iasecc: Avoid memory leaks on failure 2018-10-01 23:07:34 +02:00
Jakub Jelen 674e5e8b3d ctx: Require dll parameter otherwise we are leaking it 2018-10-01 23:07:34 +02:00
Jakub Jelen a85a4a8b48 pkcs15-authentic: Avoid memory leak on failure 2018-10-01 23:07:34 +02:00
Jakub Jelen 65e1cd2df7 muscle: Check return values 2018-10-01 23:07:34 +02:00
Jakub Jelen a2ab2071bb piv: Check return value of sc_lock() 2018-10-01 23:07:34 +02:00
Jakub Jelen b8133c2545 pkcs15-myeid: Return value checking 2018-10-01 23:07:34 +02:00
Jakub Jelen 8e0078a6f9 pkcs15-myeid: Do not confuse coverity with potential double-free 2018-10-01 23:07:34 +02:00
Jakub Jelen e5da6b66b9 iso7816: Replace asserts with explicit length checks to make coverity happy 2018-10-01 23:07:34 +02:00
Jakub Jelen b9e33a3c64 Coverity warnings
card-piv.c
	make sure the string is null terminated before passing it
	to hex_to_bin routine, which expects it
pkcs15-cac.c
	free cn_name on failure
pkcs11-tool.c
	make sure the string is null terminated before passing it to
	parse_certificate(), which expects it
2018-10-01 23:07:34 +02:00
Raul Metsma 83b188c950 Remove long expired EstEID 1.0/1.1 card support
Signed-off-by: Raul Metsma <raul@metsma.ee>
2018-09-30 21:25:13 +02:00
Jakub Jelen e456e609a6 Avoid memory leaks during verification 2018-09-30 21:23:27 +02:00
Jakub Jelen 424d828627 slot: Switch cleanup steps to avoid segfaults on errors
and some more sanity checking

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
2018-09-30 21:23:27 +02:00
Jakub Jelen 9a853176b8 pkcs11-tool: Support for signature verification
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
2018-09-30 21:23:27 +02:00
Nicholas Wilson e5707b545e Add support for PSS padding to RSA signatures
A card driver may declare support for computing the padding on the card,
or else the padding will be applied locally in padding.c.  All five
PKCS11 PSS mechanisms are supported, for signature and verification.

There are a few limits on what we choose to support, in particular I
don't see a need for arbitrary combinations of MGF hash, data hash, and
salt length, so I've restricted it (for the user's benefit) to the only
cases that really matter, where salt_len = hash_len and the same hash is
used for the MGF and data hashing.

------------------------------------------------------------------------
Reworked and extended in 2018 by Jakub Jelen <jjelen@redhat.com> against
current OpenSC master, to actually work with existing PIV cards:
 * extended of missing mechanisms (SHA224, possibility to select MGF1)
 * compatibility with OpenSSL 1.1+
 * Removed the ANSI padding
 * Formatting cleanup, error checking

Based on the original work from

https://github.com/NWilson/OpenSC/commit/42f3199e66

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
2018-09-30 21:23:27 +02:00
Jakub Jelen be2cc38565 p11test: Add missing CKM_SHA224_RSA_PKCS_PSS
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
2018-09-30 21:23:27 +02:00
Gabriel Müller 551fcccb90 Changed outdated "STARCOS SPK 2.3" name to "STARCOS".
modified:   src/libopensc/pkcs15-infocamere.c
    modified:   src/libopensc/pkcs15-starcert.c
    modified:   src/pkcs15init/pkcs15-lib.c

Changed isf_acl to also need SO PIN for CREATE.
    modified:   src/pkcs15init/starcos.profile
2018-09-28 16:50:39 +02:00
Frank Morgner 496a9b571d fixed error handling 2018-09-25 12:13:57 +02:00
Frank Morgner 0ae825f8d9 fixed error checking
closes https://github.com/OpenSC/OpenSC/pull/1343
2018-09-25 11:09:07 +02:00
konstantinpersidskiy 0c3412bb37 Fix C_SetAttributeValue for CKA_VALUE for data obj 2018-09-25 10:51:10 +02:00
konstantinpersidskiy ccdb314d49 Fix C_GetAttributeValue for attr with 0 length 2018-09-25 10:51:10 +02:00
konstantinpersidskiy c9d6c30a83 Fix data object with empty value creation 2018-09-25 10:51:10 +02:00
Peter Marschall 3cc2670f3e opensc-explorer: avoid warnings on readline-less builds 2018-09-24 00:03:13 +02:00
Peter Marschall 14a31a3c42 opensc-explorer: refactor main()
* localize variables
* print errors to stderr
* release allocated resources
* return error code on error - improve non-interactive use
* do not show help on unknown commands when used non-interactively
2018-09-24 00:03:13 +02:00
Peter Marschall 9616ad4d94 opensc-explorer: fix&clarify handling of interactive mode
* make 'interactive' a global variable
* set it when opensc was called with the SCRIPT argument
* document the behaviour in the manual page

Make interactive a global variable and set it in main.
2018-09-24 00:03:13 +02:00
Peter Marschall c5679bfe39 opensc-explorer: refactor read_cmdline()
* add comments
* simplify #ifdef logic
* increase commandline buffer in non-interactive / non-readline case
2018-09-24 00:03:13 +02:00
Peter Marschall ca9538761b opensc-explorer: refactor parse_cmdline()
* add comments
* always terminate argv[] with a NULL element
* fail if number of arguments is too large
2018-09-24 00:03:13 +02:00
Peter Marschall c9db3f7385 opensc-explorer: allow arguments for 'help'
When arguments are given, compare them like ambguous_match() does,
and show the matching ones only.

Add documentation of the 'help' command to the manual page.

In main loop on multiple matches, show help on matching commands only.
2018-09-24 00:03:13 +02:00
Peter Marschall c817be8faa opensc-explorer: refactor ambiguous_match()
* most importantly: immediately return success on exact match
  - this allows one command to be a prefix of another one
  - it fixes the long-standing breakage between 'find' and 'find_tags'
* fail on second prefix-only match instead of waiting until the end
* check all parameters
* add comments
* inform caller on whether the match was ambiguous or there was no match
* move printing error messages to processing loopt in main()
2018-09-24 00:03:13 +02:00
Peter Marschall 593a90f64e opensc-explorer: write error messages to stderr
Clarify the distinction between error messages and status messages or prompts.
Prepare for better non-interactive support.
2018-09-24 00:03:13 +02:00
Peter Marschall 77297f7965 opensc-explorer: check length of argument to option --mf
* fail when it is too long
* replace a magic numerical constant
2018-09-24 00:03:13 +02:00
Peter Marschall 9d501766b4 opensc-explorer: extend 'random' to allow writing to a file
Accept a file name as a second argument to the 'random' command
to allow storing the generated random bytes to the file given.

Forbid writing binary data to stdout in interactive mode.
2018-09-24 00:03:13 +02:00
Peter Marschall 7a4a9f1951 opensc-explorer: refactor do_put() slightly
Avoid misunderstandings by renaming a variable that refers to an
input file handle from 'outf' to 'inf'.
2018-09-24 00:03:13 +02:00
Peter Marschall 1245b617d1 opensc-explorer: refactor do_apdu() slightly
* limit buffer to SC_MAX_EXT_APDU_BUFFER_SIZE
* fix buffer length calculation to correctly calculate the available space
* add length checks when parsing passed data into buffer
2018-09-24 00:03:13 +02:00
Peter Marschall 58da74bc32 opensc-explorer: refactor do_put_data() slightly
* increase input buffer size
* avoid magic number
* notify caller on error details when parsing fails
2018-09-24 00:03:13 +02:00
Peter Marschall aed4b00145 opensc-explorer: harmonize display of command arguments
* consistently show ellipsis for repeatable arguments as 3 dots
* embrace alternative mandatory arguments with curly braces
* use hyphens instead of spaces within non-literal arguments
  for improved alignment with the manual page
2018-09-24 00:03:13 +02:00
Peter Marschall c69f10c2ab opensc-explorer: add command 'pin_info'
Get information on a PIN or key from the card via sc_pin_cmd()'s
SC_PIN_CMD_GET_INFO functionality.
2018-09-24 00:03:13 +02:00
Jakub Jelen 9d44adbc4e Missing header release tarball 2018-09-14 22:39:57 +02:00
Frank Morgner 00d1501ae6 pkcs11: fail in C_CreateObject/C_DestroyObject if write protected 2018-09-14 08:23:08 +02:00
Frank Morgner 129946ca96 pkcs11: CKF_WRITE_PROTECTED based on card's read_only flag
uses `md_read_only` as `read_only` for both, PKCS#11 and Minidriver
2018-09-14 08:23:08 +02:00
Frank Morgner db4ed9f4a2 export _sc_match_atr_block 2018-09-14 08:23:08 +02:00
Frank Morgner e36c1468e5 md: derive md_read_only from PKCS#15 profile 2018-09-14 08:23:08 +02:00
Priit Laes 1f06a76b1a openssl: Bump openssl requirement to 0.9.8 2018-09-14 08:21:40 +02:00
Frank Morgner 3750d70106 pgp: detect gnuk with newer fw
closes https://github.com/OpenSC/OpenSC/issues/1475
2018-09-13 13:46:27 +02:00
Frank Morgner 66fe060363 fixed gcc 8 compiler waring
closes https://github.com/OpenSC/OpenSC/pull/1474
2018-09-12 13:10:06 +02:00
Raul Metsma 430a9b3f5a Commit c463985fed broke EstEID PIN verify
Signed-off-by: Raul Metsma <raul@metsma.ee>
2018-09-12 12:30:05 +02:00
Alon Bar-Lev d8a2a7bf88 reader-ctapi: ctapi_connect: remove unused variable
from day 1 return value of _sc_parse_atr was ignored.
2018-09-09 14:55:28 +02:00
alex-nitrokey 083c18045e Make deciphering with AUT-key possible for OpenPGP Card >v3.2 (fixes #1352) (#1446) 2018-09-06 10:57:23 +02:00
alex-nitrokey 748234b7cc Fix SM algorithm in extended capabilities 2018-09-05 23:42:14 +02:00
Frank Morgner 39bd1ddd58 fixed wrong condition
fixes https://github.com/OpenSC/OpenSC/issues/1465
2018-09-04 13:51:40 +02:00
alex-nitrokey b572b383b2 Add supported algorithms for OpenPGP Card (Fixes #1432) (#1442) 2018-08-31 14:38:14 +02:00
asc 2b60a0db0f Add support for SmartCard-HSM 4K (V3.0) 2018-08-31 13:42:44 +02:00
Frank Morgner db438f61c1 ias/ecc: fixed GET CHALLENGE 2018-08-24 13:59:03 +02:00
Frank Morgner 94f9fdf145 ias/ecc: fixed card detection
regression of 439a95f2d
2018-08-24 13:51:15 +02:00
Frank Morgner 5daec17e32 ias/ecc: ignore missing serial on card initialization
fixes problem in card detection introduced in
50b000047c
2018-08-24 13:50:53 +02:00
Raul Metsma 336b282324 Reuse gp_select_aid
Signed-off-by: Raul Metsma <raul@metsma.ee>
2018-08-23 20:37:38 +02:00
Doug Engert 719ec39b3e Use sc_asn1_read_tag to read first tag of partially block (#1454)
Sc_asn1_read_tag can return SC_ERROR_ASN1_END_OF_CONTENTS
which indicates the tag and length are OK, but any value
is not completely contained in the buffer supplied. card-piv.c
can use this when reading just the beginning of a object to
determine the size of a buffer needed to hold the object.
2018-08-23 20:35:24 +02:00
Frank Morgner 97f0a341b0 fixed typo 2018-08-23 10:14:25 +02:00
Frank Morgner 70c4813f30 fixed Dereference before null check 2018-08-23 09:59:45 +02:00
Frank Morgner 67fbf15741 fixed NULL dereference 2018-08-23 09:51:04 +02:00
Priit Laes 45f407c021 Mark driver-specific global sc_atr_table structures as const
As most of the drivers do not modify these, we can mark them as const.
Two drivers that we cannot convert are dnie and masktech.

section                 size
.data                  35232 ->   25472
.data.rel.ro           36928 ->   46688
2018-08-22 22:50:30 +02:00
Priit Laes 2eae5e70f5 Mark atr table argument as const in match_atr_table and _sc_match_atr functions
This allows us to mark driver-specific atr tables as constants.
2018-08-22 22:50:30 +02:00
Frank Morgner fcd719d30f
Merge pull request #1447 from Jakuje/x41sec-merge
Security issues idefnitifed by fuzzing. For more information, see the blog post:

https://www.x41-dsec.de/lab/blog/smartcards/
2018-08-20 15:11:51 +02:00
Frank Morgner ff8ec86f26 avoid looping forever in GET CHALLENGE
fixes https://github.com/OpenSC/OpenSC/issues/1440
2018-08-20 14:37:20 +02:00
Frank Morgner fcf00e66cd Starcos: added ATR for 2nd gen. eGK
fixes https://github.com/OpenSC/OpenSC/issues/1451
2018-08-20 14:27:02 +02:00
Jakub Jelen 5ec26573da coolkey: Do not overflow allocated buffer 2018-08-14 16:13:22 +02:00
Jakub Jelen 79c0dbaa4e cac: Avoid OOB reads for inconsistent TLV structures 2018-08-14 16:13:22 +02:00
Frank Morgner 50b000047c ias/ecc: disable iccsn parsing
if someone wants to implement this with memory bounds checking, please
raise your hands
2018-08-14 16:13:22 +02:00
Frank Morgner 0b44793900 tcos: use ISO7816 fci parser 2018-08-14 16:13:22 +02:00
Frank Morgner 30fe0ad453 pgp: fixed integer underflow 2018-08-14 16:13:22 +02:00
Frank Morgner 92a98cb3bb mcrd: converted assert to proper error handling 2018-08-14 16:13:22 +02:00
Frank Morgner 78f0055338 fixed uninitialized use of variable 2018-08-14 16:13:22 +02:00
Frank Morgner 03628449b7 iasecc: fixed unbound recursion 2018-08-14 16:13:22 +02:00
Frank Morgner 5807368ed4 fixed bad memory access 2018-08-14 16:13:22 +02:00
Doug Engert 384626533e PIV Security Changes
Add return code if "out" is smaller then received data.

Remove extra blanks.
2018-08-14 16:13:22 +02:00
Doug Engert 3e5a9a42c3 Remove in PIV driver need for aid_file
Remove aid_file and aidfile variables in card-piv.c. These are not needed
as piv_select_aid parses the returned data from a SELECT AID command.

In response to e-mail from X41 group on 6/11/2018.

 On branch x41-piv-2
 Changes to be committed:
	modified:   card-piv.c
2018-08-14 16:13:22 +02:00
Jakub Jelen d5d15105dd cac: Ignore end of content errors (#7)
The CAC buffers are split to separate TL and V buffers so we need to ignore this error
2018-08-14 15:50:13 +02:00
Frank Morgner 83f45cda2a Added bounds checking to sc_simpletlv_read_tag()
- Logic is identical to sc_asn1_read_tag()
- Fixes out of bounds access e.g. in cac_parse_CCC
2018-08-14 15:50:13 +02:00
Frank Morgner ffe38fd87f sc_asn1_read_tag: fixed tracking of consumed bytes
fixes return buffers that are outside the allocated memory space
2018-08-14 15:50:13 +02:00
Frank Morgner 360e95d45a fixed out of bounds writes
Thanks to Eric Sesterhenn from X41 D-SEC GmbH
for reporting the problems.
2018-08-14 15:50:13 +02:00
Frank Morgner 8fe377e93b fixed out of bounds reads
Thanks to Eric Sesterhenn from X41 D-SEC GmbH
for reporting and suggesting security fixes.
2018-08-14 15:50:13 +02:00