Commit Graph

6347 Commits

Author SHA1 Message Date
Frank Morgner 7d36bab701 don't force the max buffer size with Le=0
This happens, when we know the size will be smaller, but we still use
Le=0 in case of SM.
2019-01-15 07:31:20 +01:00
Frank Morgner 609e2d89cf added GoID Tool 2019-01-15 07:31:20 +01:00
Frank Morgner 141ec6ab23 added shortcut to update binary via sfid 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 3611b5c9f2 tools: fixed colors if -v is specified 2019-01-15 07:30:46 +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
Frank Morgner 0af46c88b7 added tests for Microsoft CryptoAPI
imported from https://github.com/CardContact/sc-hsm-embedded
2019-01-15 07:30:13 +01:00
Peter Marschall bb6b78937f OpenPGP: harmonize error messages around 'key_id'
* consistently use term "Invalid key ID; must be 1, 2, or 3" in error messages
  about invalid key IDs instead of various alternatives.
* use error type SC_ERROR_INVALID_ARGUMENTS instead of SC_ERROR_INVALID_DATA
  when the key_id was passed to the respective function
* harmonize the checks to consistently use 'key_id < ... || key_id > ...'

In addition, initialize a variable to keep clang & compilers on OSX happy.
2019-01-06 22:34:52 +01:00
Peter Marschall 57e66fd42e OpenPGP: harmonize error messages
Combine sequences
	sc_log(..., "...");
	LOG_FUNC_RETURN(...);
where c_log() prints a constant string
by
	LOG_TEST_RET(..., "...");

This change results in shorter, more concise code as well as
better harmonized error messages.
2019-01-06 22:34:52 +01:00
Peter Marschall 5544418339 OpenPGP: harmonize error messages used in LOG_TEST...() calls
Don't terminate the messages with a period, because they are going to end up
as the first argument to a format string of the form "%s: ...".
I.e. they will be part of a longer string and terminated by a colon anyway.
2019-01-06 22:34:52 +01:00
Peter Marschall b95d936e6c OpenPGP: allow reading large DOs in v3 cards
Set the read buffer size in pgp_read_blob() large enough to contain DOs
with the maximum size defineable in the extended capabilities DO 00C0.
2019-01-06 22:28:14 +01:00
Frank Morgner 5c50dc58da fixed 320270 Dereference after null check 2019-01-04 00:44:45 +01:00
Frank Morgner aa940e8619 iso-sm: avoid allocation of big chunk of data
Use unencrypted APDU's resplen to estimate the size of the required SM
response buffer
2019-01-04 00:43:48 +01:00
Frank Morgner 6f0f42c506 fixed use of uninitialized data
When card->sm_ctx.ops.free_sm_apdu gets called in sc_sm_single_transmit
with a prior transmission error, then `sm_encrypt` still tries to
decrypt the response and hence, accesses the previously uninitialized
`resp`.
2019-01-04 00:43:48 +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 d577802ea7 OpenPGP: emulate SC_PIN_CMD_GET_INFO command for cards not supporting it 2019-01-02 09:06:54 +01:00
Peter Marschall 7092d32830 OpenPGP: get rid of "magic" constants in pgp_gen_key()
Use defined symbolic names for well-known DOs to copy data to a correctly
defined buffer 'apdu_data' using ulong2bebytes() instead of relying on
"magic" constants and C's string semantic.
Also use 'sizeof(apdu_data)' instead of additional magic constants.
2019-01-02 09:05:51 +01:00
Peter Marschall 4c51a53bed OpenPGP: get rid of "magic" constants in gnuk_delete_key()
Use defined symbolic names for well-known DOs to copy data to a correctly
defined buffer 'data' using ulong2bebytes() instead of relying on
"magic" constants and C's string semantic.
Also use 'sizeof(data)' instead of strange strlen() calculations.
2019-01-02 09:05:51 +01:00
Peter Marschall 0a903522b8 OpenPGP: get rid of "magic" constants in pgp_build_extended_header_list()
Use defined symbolic names for well-known DOs to copy data to a correctly
defined buffer 'data' using ulong2bebytes() instead of relying on
"magic" constants.
2019-01-02 09:05:51 +01:00
Jakub Jelen aa7118192a p11test: Use function compatible with OpenSSL 1.0.2 2018-12-31 21:56:45 +01:00
Peter Marschall 391131bb5e OpenPGP: use "hist_bytes" DO 5F52 as args to pgp_parse_hist_bytes()
Fix glitch that crept in during re-factoring.
This should unbreak Yubikeys.
2018-12-31 21:56:18 +01:00
Peter Marschall 1a60cd761f OpenPGP: fix value for EXT_CAP_MSE
enum _ext_caps is a set of bit flags
2018-12-31 21:56:18 +01:00
Peter Marschall bc17e23bd6 OpenPGP: fix spec interpretation error in hist_byte parsing
Command chaining is available with OpenPGP card spec 1.1+, not only with 3.0+
2018-12-31 21:56:18 +01:00
Peter Marschall 54dd9f4878 OpenPGP: revert 4d8b2c12ed
It broke OpenPGP on Yubikey NEOs and maybe other older versions too.

Reverting it restores functionality for those Yubikeys.
2018-12-31 21:56:18 +01:00
Doug Engert 075cac482b PIV - Some VA cards have LCS = 0F Terminated
Changes to be committed:
	modified:   card-piv.c
2018-12-27 14:25:45 +01:00
Doug Engert 7fbcd6e920 PIV - test i7e
On branch piv-improved-matching
 Changes to be committed:
	modified:   card-piv.c
2018-12-27 14:25:45 +01:00
Doug Engert a78becb76e PIV - Fix blanks and use returned value
On branch piv-improved-matching
 Changes to be committed:
	modified:   card-piv.c
2018-12-27 14:25:45 +01:00
Doug Engert 1fe1d40e38 PIV - Improved error handling of get_challenge
Random data from PIV card is obtained using GENERAL AUTHENTICATE command
for a request of a Challenge from the card. "00 87 00 9B 04 7C 02 81 00"
Usually 8 bytes are returned.

NIST 800-73-3_PART2, "A.1 Authentication of the PIV Card Application Administrator"
"Table 11. Authentication of PIV Card Application Administrator" shows an example of
how to do this.

Some cards (one I have: 3b:7d:96:00:00:80:31:80:65:b0:83:11:17:d6:83:00:90:00)
will not allow 2 of these commands in a row. (Maybe assuming command is only
used as in Table 11 and is expecting the second command.)

Code was added to card-piv.c so if "6A 80" is returned, try the command one more time.
For any other GENERAL AUTHENTICATE failure, SC_ERROR_NOT_SUPPORTED is returned.
piv_get_challenge may be called within a loop from sc_get_challenge if more random
data is needed thus causing the the 2 commands to sent in a row.

On branch piv-improved-matching
 Changes to be committed:
	modified:   card-piv.c
2018-12-27 14:25:45 +01:00
Doug Engert e13c0b83ef PIV - Improved Card Matching for Dual CAC/PIV and PIVKEY cards.
Not all PIV applets are the same. Different versions of NIST 800-73 and improperly implemented
or not implemented required features of NIST 800-73 cases problems. Have a look at the card_issues
listed in card-piv.c. The PIV driver has tried to detect the differences based on clues found in
the ATR historical bytes and vendor version numbers for some cards.

At the same time it has tried to support the possibility there are multiple applets
on a card that the user may want to use at the same time from different applications.
This has lead to some detection problems with Dual CAC/PIV cards. The same cards
sold by the vendor may have only a PIV applet that may not be the same PIV applet that
is on the Dual PIV/CAC cards.

http://www.cac.mil/Portals/53/Documents/CAC-utilziation-and-variation-matrix-v2.03-20May2016.doc
defines a number of official CAC cards in active service. A table of the ATRs for these is now used
to detect these cards. The PIV version of the CCC is also read to see if any CAC PKI objects
are defined in the CCC, indicating it is a Dual CAC/PIV, even if the ATR is not listed.

A more conservative approach to try and handle multiple applets on a card is used. Based
on issues with the implementation of the PIV applet this may not be possible to do.
So for many cards no additional detection will be done at the start of every transaction,
and the login state can not be detected correctly.

ATRs for PIVKEY are also in the match table, as these cards have a log of issues.

Other PIV cards in the future or not yet tested may not be covered properly by this patch.
Extra debugging was added with "PIV_MATCH" to help with these other cards.
With "debug = 7;", `grep PIV_MATCH opensc-debug.log` can be used to see how a card
type and card_issues are derived.

On branch piv-improved-matching
 Changes to be committed:
	modified:   card-piv.c
	modified:   cards.h
2018-12-27 14:25:45 +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
Jakub Jelen 4d8b2c12ed card-openpgp: Workaround parsing historical bytes on Yubikey to set correct capabilities 2018-12-18 14:50:08 +01:00
Jakub Jelen 26aed9441a padding: Do not set wrong flags if the raw capability is not available
Thanks Doug Engert for pointing the issue out
2018-12-18 14:50:08 +01:00
Jakub Jelen 070190d72e padding: Resotre the PAD_NONE if nothing else is specified
Patch from Doug Engert
2018-12-18 14:50:08 +01:00
Jakub Jelen f0b47a51d3 p11test: Report key sizes for missing certificates 2018-12-18 14:50:08 +01:00
Jakub Jelen ed6267512c p11test: Do not report usage on incomplete keys 2018-12-18 14:50:08 +01:00
Jakub Jelen 28deeb2a00 p11test: Do not report and try pairs without private key 2018-12-18 14:50:08 +01:00
Jakub Jelen 969e29e663 p11test: Do not talk about multipart encryption 2018-12-18 14:50:08 +01:00
Khem Raj 35cb70b5d6 Remove redundant logging
Same information is printed a few line below in same function, the only
difference is that there it takes care of case when label is NULL pointer
unlike this line

secondly, every function call to cosm_write_tokeninfo() in this file
passes label=NULL, and then it tries to print a null pointer

Fixes errors like
src/libopensc/log.h:48:47: error: '%s' directive argument is null
[-Werror=format-overflow=]

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2018-12-18 13:50:08 +01:00
Peter Marschall b1539545d0 OpenPGP: free() unconditionally in error handling of pgp_store_key() 2018-12-17 09:49:57 +01:00
Peter Marschall c7fc7cc134 OpenPGP: refactor error handling in pgp_calculate_and_store_fingerprint()
* initialize pointers to NULL
* explicitly compare pointers to NULL
* use LOG_TEST_*() macros instead of explicit coding
2018-12-17 09:49:57 +01:00
Peter Marschall bf2a9bc53b OpenPGP: refactor error handling in pgp_build_extended_header_list()
* use LOG_TEST_*() macros instead of explicit coding
2018-12-17 09:49:57 +01:00
Peter Marschall 7916d45857 OpenPGP: refactor error handling in pgp_store_key()
* use LOG_TEST_*() macros instead of explicit coding
* harmonize use of card->ctx: saves one variable
* explictly compare pointers to != NULL
2018-12-17 09:49:57 +01:00
Peter Marschall 08b9f362c0 OpenPGP: refactor error handling in pgp_gen_key()
* use LOG_TEST_*() macros instead of explicit coding
2018-12-17 09:49:57 +01:00
Peter Marschall d3e730b621 OpenPGP: refactor error handling in pgp_put_data_plain()
* use LOG_TEST_*() macros instead of explicit coding
2018-12-17 09:49:57 +01:00
Peter Marschall 738c933609 OpenPGP: a few cleanups for Gnuk
* make sure to remain within buffer size in pgp_read_blob()
* make logic more readable in pgp_get_data()
2018-12-17 09:49:57 +01:00
Peter Marschall 01287e393e framework-pkcs15: fix warning
* fix -Werror=format-truncation= warning in pkcs15_init_slot()
* do not only remove blanks from the end, but all spaces
2018-12-09 23:44:00 +01:00
Frank Morgner f2145eca79 don't debug pointers 2018-12-06 09:26:42 +01:00
Frank Morgner 5474370b17 always log APDUs with SC_LOG_DEBUG_NORMAL 2018-12-06 09:26:42 +01:00
Frank Morgner a899a46b09 replaced SC_TEST_RET with LOG_TEST_RET 2018-12-06 09:26:42 +01:00
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