Commit Graph

1470 Commits

Author SHA1 Message Date
Frank Morgner 6aa5410e73 goid-tool: live with short length APDUs 2019-03-18 13:59:11 +01:00
Frank Morgner d953998aa3 npa-tool: force default card driver 2019-03-13 12:01:09 +01:00
alegon01 31831c300b Remove the call to OPENSSL_init_crypto() which is not needed. I have a segmentation fault when the process exits. 2019-03-12 08:52:06 +01:00
Frank Morgner 6472027848 tools: release context when card connection fails 2019-03-07 22:18:54 +02:00
Scott Gayou 0d79675497 Small memory leak fix (CVE-2019-6502 in #1586)
CVE-2019-6502 was assigned to what appears to be a very minor
memory leak that only occurs on an error-case in a CLI tool.
If util_connect_card fails, we still need to release the sc
context previously allocated by sc_context_create else memory
will leak.
2019-03-06 19:51:43 +01:00
alegon01 728d099a53 FIX typo OpenSSL vs OpenSsl. 2019-03-06 11:35:11 +01:00
alegon01 b327b76134 FIX use pseudo_randomize() for a proper initialization of orig_data in encrypt_decrypt(). 2019-03-06 10:26:05 +01:00
Frank Morgner 070370895f fixed 333707 Dereference before null check 2019-03-06 00:42:38 +01:00
Frank Morgner ba185954c5 fixed 333709 Unchecked return value 2019-03-06 00:42:38 +01:00
Frank Morgner 9abe44f03c fixed 333715 Dereference after null check 2019-03-06 00:42:38 +01:00
Frank Morgner e876cf62eb fixed 333711 Dereference before null check 2019-03-06 00:42:38 +01:00
Frank Morgner b1a58c7925 removed dead code 2019-03-06 00:42:38 +01:00
Frank Morgner 27526de021 implemented sc_format_apdu_ex 2019-03-05 13:54:13 +01:00
alegon01 7271fe610b Add support for the OpenSsl signature format for the signature verification. 2019-02-18 16:03:41 +01:00
Frank Morgner f4fccfd94e fixed undefined bitshift 2019-02-14 09:22:23 +01:00
Frank Morgner c858d4b3d1 fixed argument checking 2019-02-14 09:22:23 +01:00
Frank Morgner 6fdb29a470 fixed use of uninitialized values 2019-02-14 09:22:23 +01:00
Frank Morgner 01d515a026 fixed use of garbage value 2019-02-14 09:22:23 +01:00
Frank Morgner 32e1995300 fixed dead assignment 2019-02-14 09:22:23 +01:00
Frank Morgner e4a01643a6 fixed possible NULL pointer dereference 2019-02-14 09:22:23 +01:00
Frank Morgner 85485eb9b0 fixed unused assignments 2019-02-14 09:22:23 +01:00
Frank Morgner fdb0e6d581 Fixed Potential leak of memory 2019-02-14 09:22:23 +01:00
alegon01 9ae507c5f8 Fix indentation. 2019-02-12 14:09:26 +01:00
alegon01 b63a868e68 Fix build when EVP_PKEY_CTX_set_rsa_oaep_md is not defined. 2019-02-12 10:42:39 +01:00
Frank Morgner 72cdc9d82e goid-tool: fixed confusion about always/never acl 2019-02-08 15:08:03 +01:00
Frank Morgner aca9d79f6d fixed parsing SoCManager info 2019-02-07 16:56:33 +01:00
alegon01 973625773b Fix encrypt_decrypt() for CKM_RSA_PKCS_OAEP. It is working fine now with OpenSsl 1.1.1a. 2019-02-07 10:42:48 +01:00
alegon01 084624f340 Fix CKM_RSA_PKCS in encrypt_decrypt(). 2019-02-05 12:03:51 +01:00
alegon01 9aa413bd7e Fix CKM_RSA_X_509 encrypt_decrypt(). Improve the code for CKM_RSA_PKCS and CKM_RSA_PKCS_OAEP. For these alogs, only CKM_SHA_1 is supported. 2019-02-05 11:35:42 +01:00
alegon01 d25fbe3cec Remove 2 useless comments in encrypt_decrypt(). 2019-02-05 11:24:33 +01:00
Frank Morgner 928fbf2f03 goid-tool: implented PIN/FP verification for PAccess 2019-02-04 16:01:56 +01:00
alegon01 3d09823df0 Fix build when OPENSSL_NO_RIPEMD and OPENSSL_NO_CAST are defined. Fix formatting. 2019-02-04 14:26:02 +01:00
alegon01 f030aa2c25 Add support for CKM_RSA_X_509 in encrypt_decrypt() and decrypt_data(). 2019-02-04 14:23:13 +01:00
alegon01 9b7605ff3c Add support for CKM_RSA_PKCS_OAEP in encrypt_decrypt(). Only set the OAEP params for CKM_RSA_PKCS_OAEP, I had an issue with a variable not initialized. 2019-02-01 15:27:55 +01:00
alegon01 cf617da4bd Before calling encrypt_decrypt() make sure that the mechanism is for RSA and supports decryption, otherwise skip it. 2019-02-01 11:37:47 +01:00
alegon01 2be799f739 Add support for CKM_RSA_PKCS_OAEP in encrypt_decrypt(). fix mechanism value in call to util_fatal(). fix formatting. 2019-02-01 11:35:25 +01:00
alegon01 16ca73ae40 Add support for CKM_RSA_PKCS_OAEP in encrypt_decrypt(). fix mechanism value in call to util_fatal(). 2019-02-01 11:19:33 +01:00
alegon01 968bfa8444 Add support for CKM_RSA_PKCS_OAEP in encrypt_decrypt(). 2019-02-01 09:16:59 +01:00
alegon01 ff3448fb18 Fix build when OPENSSL_NO_RIPEMD and OPENSSL_NO_CAST are defined. 2019-02-01 09:13:21 +01:00
alegon01 f412995811 Bug fix in verify_signature() when the buffer to verify is larger than 1025 bytes. In this case, the signature length given to C_VerifyFinal() was incorrect. 2019-02-01 09:10:02 +01:00
opensignature 84f0a88edb Remove postecert and infocamere support because no longer issued (#1584)
* Remove postecert and infocamere support because no longer issued

* Remove wrong changes

* reset NEWS

* EC_POINT_set_affine_coordinates_GFp and EC_POINT_get_affine_coordinates_GFp are
deprecated, use EC_POINT_set_affine_coordinates and EC_POINT_get_affine_coordinates

* If OPENSSL API version is < 3 use old functions EC_POINT_[sg]et_affine_coordinates_GFp

* Move the OpenSSL compatibility stuff to src/libopensc/sc-ossl-compat.h
2019-01-30 22:01:24 +01:00
Alexander Paetzelt 09a594d0f0 OpenPGP Card v3 ECC support (#1506)
* pgp: initialize ecc keys for OPC3

* Add supported ECC algorithms by card version

* Add tasks identified so far

* pgp: Recognize ECC set on card

* pgp: get_pubkey_pem read ECC pubkey from card

* pgp: minor code changes for ECC compatibility

* pgp: expand sc_cardctl_openpgp_keygen_info to hold ec info

* Fix segfault problem in pkcs15-pubkey.c

* pgp: enable key generation with pkcs15-init and ECC

* pgp: adapt calculate_and_store_fingerprint to accept ECC

* pgp: adapt rest of pgp_gen_key and subfunctions to accept ECC

* pgp: add kdf parameters for ECDH fingerprint calculation

* pgp: enable key import with pkcs15-init and ECC

* pkcs15-pubkey: fix_ec_parameters onlz accpets explicit data or named_curve

* Fix some mistakes during merge

* More clean up for PR

* Fix some ugly alignments

* Improve code readability

* Prevent unitialized variable by using FUNC_RETURN

* OpenPGP: add length check

* pgp: save exponent length in bits for sc_cardctl_openpgp_keystore_info_t

* pgp: length checks and reallocations

* pgp: oid init added

* OpenPGP: slightly re-factor pgp_update_new_algo_attr()

* replace loop copy with memcpy()
* use ushort2bebytes() to set RSA modulus & exponent
* use symbolic name SC_OPENPGP_KEYFORMAT_RSA_STD for the key import format

* OpenPGP: slighly re-factor pgp_parse_and_set_pubkey_output()

* check for RSA modulus & exponent lengths not being a multiple of 8
* make sure RSA modulus & exponent lengths are always set
* remove a left-over RSA setting from the EC code

* pgp: adding BYTES4BITS

* pgp: initialization of values in pgp_build_extended_header_list based on key type

* pgp: add BYTES4BITS and remove unnecessary tests

* Fix broken pgp_update_new_algo_attr

* pgp: fix the ecpoint_len variable
2019-01-30 22:00:36 +01:00
Frank Morgner 993f6f5cc6 Use opensc-pkcs11.so for static build of pkcs11-tool
Statically link opensc-pkcs11 into pkcs11-tool with --disable-shared
2019-01-30 21:57:59 +01:00
Frank Morgner 83c4ebe9d6 goid-tool: reset authentication status 2019-01-30 13:00:14 +01:00
Frank Morgner fc08d89247 goid-tool: differ PAccess and SoCManager usage 2019-01-30 09:35:16 +01:00
Frank Morgner a8c84d490a handle multiple verifications when changing secret 2019-01-30 09:35:11 +01:00
Frank Morgner 6bf7c0d219 don't hide global variables 2019-01-20 23:02:21 +01:00
Frank Morgner 3fe198f21e treat records with size_t 2019-01-20 23:02:21 +01:00
Frank Morgner 4b30858092 pkcs11-tool: fixed argument type
reported by lgtm
2019-01-20 23:02:21 +01:00
Frank Morgner d806ee3245 fixed unsafe usage of gmtime
reported by lgtm
2019-01-20 23:02:21 +01:00
Frank Morgner b8b4f7c36f goid-tool: added error checking for verify/change 2019-01-18 23:02:36 +01:00
Martin Paljak c3a9837b10 Add mechanisms used by SoftHSM2
/Library/OpenSC/bin/pkcs11-tool --module /usr/local/lib/softhsm/libsofthsm2.so -M

will not show any more numeric mechanisms.

Source: https://www.cryptsoft.com/pkcs11doc/STANDARD/include/v240e01/pkcs11t.h
2019-01-15 13:07:58 +02:00
Raul Metsma 3c1d425eb9 Remove unused include
Signed-off-by: Raul Metsma <raul@metsma.ee>
2019-01-15 12:48:26 +02:00
Mat e19fe680c4 Add object type "secrkey" to help of --type switch in pkcs11-tool (#1575)
* Add object type "secrkey" to help of --type switch in pkcs11-tool

Reading an object with pkcs11-tool requires the `--type` switch. The help for that switch is currently incomplete as it is missing the (not very friendly named" *secrkey* option used to read out a secret key object.

I have added this information to the help description.

* Update man page

Describe secrkey option of pkcs11-tool's --type switch in man page
2019-01-15 07:32:41 +01:00
Frank Morgner 609e2d89cf added GoID Tool 2019-01-15 07:31:20 +01:00
Frank Morgner 1eda4c1795 sc-hsm-tool: add support for initializing biometry 2019-01-15 07:31:20 +01:00
Frank Morgner fbb4d1f843 tools: use consistent behavior of -v
-v switches to debug output to stderr in OpenSC tools regardless of the opensc.conf setting
2019-01-15 07:30:46 +01:00
Peter Marschall a6ee84f13d opensc-explorer: fix 'pin_info' command
Correctly treat 'data.pin1.logged_in' as tristate instead of boolean.
While at it, fix visual glitch to not wrap around a stand-alone period.
2019-01-02 09:08:00 +01:00
Peter Marschall dc505be808 openpgp-tool: use binary OR for calculating 32-bit integers from byte
Also avoid potential unintended sign extension (SIGN_EXTENSION).
2018-12-27 14:13:41 +01:00
Frank Morgner b11cc3871e tools: harmonize card initialization 2018-12-18 14:50:45 +01:00
Frank Morgner 907c9479e2 replace sc_debug_hex with sc_log_hex 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
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
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
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
Frank Morgner 3c0a16dc39 CID 321790 (#1 of 1): Resource leak (RESOURCE_LEAK) 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
Hannu Honkanen 351e0d2bd6 Merge remote-tracking branch 'upstream/master' into wrapping-rebased and resolve conflicts 2018-11-02 13:42:41 +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
Hannu Honkanen 9772edc7d1 Handle -u option (x509-usage) when storing secret keys. 2018-10-31 10:22:16 +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 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 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 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 9a853176b8 pkcs11-tool: Support for signature verification
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
2018-09-30 21:23:27 +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