Commit Graph

81 Commits

Author SHA1 Message Date
Peter Marschall 16c889cf7d spelling fixes
Fix various spelling errors, mostly in comments but also in texts displayed.

Errors found & interactively fixed using 'codespell', with additional manual
checks after the fixes.
2020-08-30 10:35:14 +02:00
Jakub Jelen f49162af04 Avoid memory leaks when initializing tokeninfo in various drivers
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22578
2020-06-09 13:02:27 +02:00
Peter Marschall d628022673 OpenPGP: add additional vendors
Taken from git.gnupg.org
2020-03-10 09:19:31 +01:00
Peter Marschall 8e466ad568 OpenPGP: add 3 more OpenPGP card vendors
* taken from GnuPG's git
2020-02-10 00:41:02 +01:00
Jakub Jelen b79db82ae7 openpgp: Workaround non-compliant Yubikey 5 OpenPGP applets
Fixes #1850
2019-11-12 03:38:09 +01:00
Raul Metsma 63fd71c245 Remove unused sc_pkcs15emu_opt_t structure
Only usage was removed SC_PKCS15EMU_FLAGS_NO_CHECK flag

Signed-off-by: Raul Metsma <raul@metsma.ee>
2019-05-02 10:08:46 +02:00
Raul Metsma bbec50bfdb Remove unused SC_PKCS15EMU_FLAGS_NO_CHECK flag
Fixes #1634

Signed-off-by: Raul Metsma <raul@metsma.ee>
2019-04-25 14:53:25 +02:00
Frank Morgner 9fa1722f73 sc_bin_to_hex returns a Nul terminated string 2019-03-13 21:17:00 +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 24b50a4277 replace sc_debug with sc_log 2018-12-06 09:26:42 +01:00
Peter Marschall 4ec37adea8 OpenPGP: extend manufacturer list in pkcs15-openpgp.c 2018-07-11 10:46:56 +02:00
David Ward 2c167a9982 Address compiler warnings when using --disable-optimization (#1325)
* Handle errors as intended in sc_pkcs15emu_openpgp_add_data()

If a data object can be read, but it cannot be added to the PKCS#15
framework, return from this function with an error; do not continue
reading other data objects. Otherwise, do not return an error from
this function when a data object cannot be read or is empty.

Improve existing comments for clarity.

* Address other compiler warnings when using --disable-optimization

Certain variables that are not initialized when they are declared
prevent the build from completing, when --disable-optimization is
passed to ./configure.
2018-04-15 09:37:43 +02:00
Frank Morgner 3e22daf7b5 OpenPGP: fixed memory leak 2018-04-04 10:02:30 +02:00
Frank Morgner fccc42295d OpenPGP: Added basic support for OpenPGP card V3
partially implements https://github.com/OpenSC/OpenSC/issues/1215

Refactored OpenPGP code so that future versions of the card will be
accessed using the logic for OpenPGP V2. We hope that backward
compatibility of the standard will keep the new versions functional.
2018-01-22 15:26:44 +01:00
Frank Morgner 1d03000222 fixed dead assignment 2017-11-09 12:42:29 +01:00
Maciej S. Szmigiero 1168ca00f3 Set PIN-PUK association for cards that don't have it set
sc_pkcs15_unblock_pin() in libopensc/pkcs15-pin.c wants to associate PIN
to be unblocked with its PUK to check, for example, whether provided PUK
conforms to its policy.

When this function is not able to find a relevant PUK is uses policy for
PIN to be unblocked instead to check provided PUK which causes problems if
PIN and PUK policies differ.

Set PIN-PUK association for cards where it was unset and where this
association was either obvious, described in code or specs or provided
by the community.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 10:57:21 +02:00
Frank Morgner 8d67adb06c Merge pull request #864 from maciejsszmigiero/openpgp-fixes-small
OpenPGP card small fixes
2016-09-20 14:48:20 +02:00
Maciej S. Szmigiero d84ee6c96a Initialize PIN logged_in field for cards that do not support PIN info
Commit 2f10de4f5c ("use sc_pkcs15_get_pin_info in C_GetTokenInfo")
introduced dependency of logged in state returned for session
by C_GetTokenInfo() on logged_in field of that session slot PIN.

This field is updated by sending pin_cmd of type SC_PIN_CMD_GET_INFO to
card.
However, not all cards support such pin_cmd type (in fact, majority of
them don't). In this case logged_in field is usually left zero-initialized
which means SC_PIN_STATE_LOGGED_OUT.

With such logged_in field value C_GetTokenInfo() always returns
CKS_R{O,W}_PUBLIC_SESSION, instead of CKS_R{O,W}_USER_FUNCTIONS when
logged in.

At least Firefox (and probably other NSS-based software, too) is confused
by such value and keeps repeating PIN prompts a few times until it
ultimately considers that logging in to this slot has failed.

Fix this by initializing PIN logged_in field to SC_PIN_STATE_UNKNOWN for
cards that do not support SC_PIN_CMD_GET_INFO pin_cmd.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2016-09-01 02:03:42 +02:00
Maciej S. Szmigiero 0a6c1c4fb3 Make OpenPGP card user/signature PIN order match PKCS#11 framework
_get_auth_object_by_name() in pkcs11/framework-pkcs15.c needs user PIN
to be the first one and then next one can be signature PIN, but OpenPGP
card had it reversed.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2016-08-30 23:30:43 +02:00
Nguyễn Hồng Quân 46d8264f08 pkcs15-openpgp: Change sprintf to snprintf. 2016-07-17 13:22:55 +02:00
Nguyễn Hồng Quân 91fc129f19 PKCS15-OpenPGP: Change error log
Only one DO is supported now.
2016-07-17 13:22:55 +02:00
Viktor Tarasov 9ac4120594 pkcs15: 'aid' argument for emulator init
Allows to PKCS#15 emulator to bind more then one application
2016-04-08 10:48:58 +02:00
Peter Marschall 6109a8792d OpenPGP: add additional manufacturers 2015-10-15 16:43:10 +02:00
Nguyễn Hồng Quân 70890a8f61 Merge branch 'master' into gnuk
Conflicts:
	src/libopensc/card-openpgp.c
	src/tools/openpgp-tool.c
2015-08-31 21:55:14 +08:00
Frank Morgner bcb5fc15e5 honour HAVE_CONFIG_H 2015-04-22 23:55:33 +02:00
Thomas Calderon 91ddcfb514 PKCS15: remove redundant code for access_flags.
* With commit facaf59, access_flags were set for most cards. A closer look
    revealed that this is already done in `sc_pkcs15emu_add_rsa_prkey`.
    Therefore, this removes the duplicated code for cards calling this function.
2015-01-16 10:03:13 +01:00
Thomas Calderon facaf5969b Improve PKCS#11 compliance. Issue #335
* Add default behavior for cards using the PKCS#15 emulation layer.
    Hence, this patch provide a default value for access_flags compatible with
    current OpenSC's behavior while allowing compatible cards to fetch the real
    value from the card (IAS-ECC and AuthentIC).
2014-12-29 13:11:23 +01:00
Nguyễn Hồng Quân 9a2a6e6dc0 PKCS15-OpenPGP: Allow to store data to pkcs15 data object.
Only one DO is supported now.
2014-07-14 02:02:07 +08:00
Nguyễn Hồng Quân 6a55c09793 PKCS15-OpenPGP: Do not show empty DO in pkcs15 emu_init. 2014-07-14 02:02:07 +08:00
Nguyễn Hồng Quân 24e3bdb872 PKCS15-OpenPGP: Declare DATA objects.
Begin to support read/write DATA object for PKCS-OpenPGP binding.
This object is used by TrueCrypt.
2014-07-14 02:02:06 +08:00
Nguyễn Hồng Quân a4d9261087 OpenPGP: Add Gnuk in pkcs15 emulation layer. 2014-07-14 02:02:06 +08:00
Frank Morgner 7a87d947e7 don't require ushort to be present 2013-09-29 19:19:17 +02:00
Nguyễn Hồng Quân e34866f188 OpenPGP: Accept authentication key for S/MIME decrypting.
The card contains only 1 certificate, which can be used for encrypting.
But this certificate is bound with authentication key, so when decrypting,
the authentication key will be presented to check.
This commit allows to bypass the check in driver. However, it is not enough.
The users have to import the same key to "Encryption key" to help the card find
right key to work.

OpenPGP: Add log and comments.

OpenPGP: Pretend to select dummy files.
Some files are needed by pkcs15init, but not exist in OpenPGP card.
We pretend to know these dummy files to make pkcs15init successful.

Compilation error on windows:
when declaring array use explicit size, add pkcs15-openpgp.obj in Makefile.mak
2012-07-29 14:04:08 +02:00
Nguyễn Hồng Quân 8261490ec1 PKCS15-OpenPGP: Change the way emu_init return in error case. 2012-07-29 12:09:56 +02:00
Nguyễn Hồng Quân 4e5ef8f1c9 PKCS15 - OpenPGP: Add more comments. 2012-07-07 19:00:36 +02:00
Peter Marschall db06b043ca PKCS15 - OpenPGP: re-factor certificate object init
restrict scope of some variables.
2012-06-15 14:56:46 +02:00
Nguyễn Hồng Quân 735883d8f6 PKCS15 - OpenPGP: Change way to check certificate object.
Old: If cert is missing, raise error.
New: If cert have data, declare object, otherwise, just ignore it.
2012-06-15 14:45:44 +02:00
Viktor Tarasov 2078654d2b OpenPGP: to be compiled on windows 2012-06-08 20:17:35 +02:00
Peter Marschall f5dc252aa9 OpenPGP: set pin references to 0x01 - 0x03
Set pin references to 0x01 - 0x03 instead of 0x81 - 0x83.
The PINs are referenced as PIN1- PIN3 (resp. PW1 - PW3) in the OpenPGP
card specification.
Technically the APDUs to verify/change the PINs contain the values OR-ed
with 0x80, but this is just a technical detail of the implementation
which the emulated file system can hide in pgp_pin_cmd().

Pros & Cons:
+ consistent PIN naming
+ no trouble entering the correct PIN names in opensc-explorer et.al.
  ("verify CHV1" is way better than "verify CHV129")
- manually entering the correct APDU for VERIFY is a bit more complex.
  (who does this anyway, when there are better functions)

While at it, change if .. elsif ... cascade to switch statement.
2012-06-08 20:17:35 +02:00
hongquan 89c1dd37e4 OpenPGP PKCS#15: Add declaration of certificate object. Allow to read
certificate via PKCS#11 (not writing yet).
2012-06-08 20:17:35 +02:00
hongquan f515ed5be3 OpenPGP: Change the criteria to use ext APDU for put data.
Saner whitespace in logs
Correct spelling
2012-06-08 20:17:35 +02:00
Peter Marschall f04a1c5fef OpenPGP: stricter validity checks in PKCS15 init
Only add private/public keys that habe been defined:
check finger prints & algorithm identifier
2012-05-30 09:39:12 +02:00
Peter Marschall 742186f32f OpenPGP: remove unnecessary call to sc_get_data 2012-05-30 09:39:12 +02:00
Peter Marschall 67136b1781 OpenPGP: revert 7b4532736e
PKCS#15 spec v1.1 says:
TokenInfo.version: This field contains the number of the particular version
of this specification the application is based upon. For this version of this
document, the value of version shall be 0 (v1).

Thanks to Martin Paljak for the finding.
2012-05-30 09:39:12 +02:00
Peter Marschall 26aac71c9f OpenPGP: correct PIN type to UTF-8
OpenPGP card spec v1.1 and v2.0 make it absolutely clear:
"... The format of the CHVs is UTF-8 (case sensitive) ...".
2012-05-30 09:39:11 +02:00
Viktor Tarasov 4b745f51af openpgp: 'ushort' type not defined for WIN32
Change-Id: Ifb28730af2d39440721be9d1e38ea1c6106167a2
2012-05-16 23:14:42 +02:00
Peter Marschall 07d51bea36 OpenPGP: get PKCS#15 token info from preparsed card data
Determine data for sc_pkcs15_card's tokeninfo structure
from sc_pkcs15_card's card structure.
This makes sure the two stay consistent as much as possible.
2012-05-16 17:01:09 +02:00
Peter Marschall 7b4532736e OpenPGP: set version for PKCS#15 2012-05-16 17:01:09 +02:00
Peter Marschall bc0949140d OpenPGP: format paths more nicely 2012-05-16 17:01:09 +02:00
Peter Marschall 0283a6f24e OpenPGP: only add keys with legal algorithm identifier 2012-05-16 17:01:09 +02:00