Commit Graph

172 Commits

Author SHA1 Message Date
Frank Morgner 439a95f2d2
If card initialization fails, return SC_ERROR_INVALID_CARD (#1251)
fixes https://github.com/OpenSC/OpenSC/issues/946
2018-05-18 23:49:29 +02:00
Peter Marschall 5abe99d228 fix typos
Mass-typo fixing, almost exclusively in comments and text strings.

While at it also fixed a few (very few) grammar errors.
2018-04-15 09:34:45 +02:00
Mouse b7dc5a0890 Retrieve OpenPGP applet version from OpenPGP applet on YubiKey token (#1262) 2018-04-04 21:41:39 +02:00
Frank Morgner 45ad44e311 fixed handling SC_ASN1_TAG_EOC from sc_asn1_read_tag
We can't check for `tag == SC_ASN1_TAG_EOC` directly, because this
would also be true for a tag of 0x80 (with `class ==
SC_ASN1_CLASS_CONSTRUCTED`). So what we do is we check for the output
buffer to be NULL!

fixes https://github.com/OpenSC/OpenSC/issues/1273
2018-03-30 08:28:51 +02:00
Vadim Penzin e1d6f0869b Add missing initialisation of variables to pacify Clang.
1. src/libopensc/card-openpgp.c:pgp_store_key().
2. src/libopensc/cwa14890.c:cwa_verify_icc_certificates().
3. src/libopensc/cwa14890.c:cwa_prepare_external_auth().
4. src/libopensc/pkcs15-itacns.c:itacns_check_and_add_keyset().

(Discovered by Clang 4.0.0 on OpenBSD 6.2.)
2018-03-19 09:48:21 +01:00
Frank Morgner 8ee2c61932 Return SC_SUCCESS in openpgp_card_reader_lock_obtained
prevents locking the card forever in case of a problem
2018-02-12 09:45:36 +01:00
Frank Morgner 50a35c1bae OpenPGP: Workaround for change in Extended Capabilities
The maximum length for sending and receiving data can now be found in DO
7F66. For now, we just use the default values for short/extended length
capabiliites.
2018-02-12 09:45:36 +01:00
Frank Morgner 87cdfcb08c OpenPGP: Implemented "keep alive" command 2018-02-07 11:57:48 +01:00
Frank Morgner d719977d14 Reselect PKI-Applets after card reset
PKI-Applets may not be active if the card has been reset or unpowered.
The SELECT command used to activate the applet, is identical to the one
used during card matching or initialization.
2018-02-07 11:57:48 +01:00
Frank Morgner 490e825a65 OpenPGP: implemented GET CHALLENGE 2018-01-22 15:26:44 +01:00
Frank Morgner 449f6c2b94 OpenPGP: Added support for PIN logout and status 2018-01-22 15:26:44 +01:00
Frank Morgner 995845b002 openpgp: factory reset is possible if LCS is supported 2018-01-22 15:26:44 +01: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 16354f11af OpenPGP: fixed selecting Applet
fixes https://github.com/OpenSC/OpenSC/issues/1230
2018-01-22 15:26:44 +01:00
Jakub Jelen e2fe24d56a clang static analyzer reports
tools/pkcs15-tool.c:
	Dead assignment: Value stored to 'c' is never read
tools/pkcs11-tool.c:
	Dead assignment: Value stored to 'n' is never read
	Dead assignment: Value stored to 'rv' is never read
libopensc/card-cac.c:
	Dead assignemnt: Value stored to 'tl_head_len' is never read
	Dead increment: Value stored to 'outp' is never read
common/libpkcs11.c:
	Memory leak in case of C_UnloadModule() fails
libopensc/pkcs15-pubkey.c:
	Potential memory leaks
pkcs11/mechanism.c:
	Potential memory leak
pkcs11/framework-pkcs15.c:
	Potential memory leaks
	Dereference of null pointer
	Dead assignments
tools/sc-hsm-tool.c:
	Function call argument is an uninitialized value
	Dead assignment: Value stored to 'r' is never read
libopensc/card-openpgp.c:
	Dead assignment: ignoring the errors in case of sc_pkcs15_encode_pubkey() failed
libopensc/pkcs15-cac.c:
	Dead assignments: ignoring return values
libopensc/pkcs15-coolkey.c:
	Dead assignments: ignoring return values
libopensc/card-sc-hsm.c:
	Dereference of undefined pointer value: Properly check the file allocation
pkcs11/slot.c:
	Dead assignment
pkcs15init/pkcs15-cflex.c:
	Dereference of null pointer
	Uninitialized argument values
2017-07-18 22:40:20 +02:00
Maciej S. Szmigiero 62cbda6cd9 Fix log messages format and parameter issues flagged by GCC
Since "Add GCC format checking attributes to log functions" commit GCC
warns us about problems with format strings and their arguments provided
to OpenSC message logging functions.

This commit fixes all cases where GCC warned about incorrect format on
64-bit Linux, 32-bit and 64-bit mingw builds (with SM and OpenSSL enabled).
Well, almost all since on mingw GCC does not recognize "ll" size specifier
(present at least since Visual Studio 2005, also in mingw own CRT) so these
(few) warnings about it remain.

In most cases format size specifier for size_t type was missing (usually
size was left at default int level, with is different on 64-bit x86).
Some formats had too few / too many arguments.
In some cases pointers were printed as integers.
Some long variables were missing "l" prefix (especially with regard to %x
format).

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Michał Trojnara 645780e6d4 NULL parameter check moved to sc_file_free()
This fixes numerous issues where the check is *not* performed,
and also simplifies the code.
2017-01-10 12:46:44 +01:00
Maciej S. Szmigiero dc476a9f33 Improve handling of OpenPGP card PIN change and unblock commands
"CHANGE REFERENCE DATA" (PIN change) and "RESET RETRY COUNTER"
(PIN unblock) commands in OpenPGP card have various limitations.
These also depend on whether the card is version 1.x or 2.x.

Provide helpful debug messages for user in case he is trying to do
a PIN command in a way that isn't supported by the card.

Also, take into account that version 2.x cards don't support references to
PW1-mode 2 (82) in these commands - change them to PW1 (81).

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2016-08-30 23:30:43 +02:00
Maciej S. Szmigiero 3e3528bb68 OpenPGP card doesn't support raw RSA so don't set such algo flag
According to descriptions of commands "PSO: COMPUTE DIGITAL SIGNATURE",
"PSO: DECIPHER" and "INTERNAL AUTHENTICATE" in OpenPGP card spec (versions
1.1 and 2.1.1) the card adds / strips and checks PKCS#1 padding
automatically.
There is no documented way to perform raw RSA operations on this card so
SC_ALGORITHM_RSA_RAW flag shouldn't be set.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2016-08-30 23:30:43 +02:00
Frank Morgner 98b9b37e12 card-openpgp.c: fixed potential resource leak 2015-10-30 12:18:04 +01:00
Peter Marschall a0ca6b2ef0 OpenPGP: set card's version in pgp_init() 2015-10-15 16:43:10 +02:00
Peter Marschall 7078fbd505 OpenPGP: cleanup pgp_init()
- use LOG_FUNC_RETURN instead of return for symmetry with LOG_FUNC_CALLED
2015-10-15 16:43:10 +02:00
Peter Marschall e1db96b73b OpenPGP: extend pgp_match_card()
- explicitly check for supported versions
- log successful matches by AID with their type
- log detection of unsupported OpenPGP-type cards
2015-10-15 16:43:09 +02:00
Peter Marschall 7c2adb1fc8 OpenPGP: 1st preparations for newer versions
- add references to new specs
- add new enum _version constants
2015-10-15 16:43:09 +02:00
Peter Marschall 69b482dce6 OpenPGP: cleanup pgp_get_card_features()
- bug fix: re-initialize index to start searching at the right place
- get rid of unnecessary variable
- add some line breaks & comemnts for easier understanding
2015-10-15 16:42:58 +02:00
Peter Marschall 2a269c5267 OpenPGP: cleanup pgp_build_tlv()
- get rid of intermediate variable
- clarify check in while() loop
- line breaks for easier reading
2015-10-15 16:17:22 +02:00
Peter Marschall 3d492ae376 OpenPGP: cleanup pgp_erase_card()
- get rid of unnecessary variable
- use easily understandable hex representation of APDUs
- auto-calculate APDU length based on hex representation
- restrict scope of some variables
- use sc_log() instead of directly writing to console
- line breaks & comments for easier reading/understanding
- fix typo in log message
2015-10-15 16:17:22 +02:00
Peter Marschall 3d4fbd776d OpenPGP: harmonize coding style
- 2 line breaks between functions for easier reading
- function type on separate line
- mark each function as 'ABI' or 'Internal'
- slightly doxygen-ize comments introducing functions
- fix typos in comments
- break over-long comment lines
- break comment lines at sensible places
- consistent calling style for DRVDATA()

- no code change
2015-10-15 16:17:22 +02:00
Peter Marschall 7ba47fd5a9 OpenPGP: consistently use card->ctx in pgp_put_data_plain()
- get rid of unnecessary variable
- harmonize coding style: adapt to prevailing use of card->ctx
2015-10-15 16:17:22 +02:00
Peter Marschall 1a05f968bd OpenPGP: simplify gnuk_write_certificate()
- get rid of unnecessary variables
- use for-loop to initialize/check/increase run variable in one place
- restrict variables to the necessary scope
- use ternary operator inside a statement instead of if...else...
2015-10-15 16:17:22 +02:00
Peter Marschall d2b1c8228f OpenPGP: set apdu_case on declaration
- use ternary operator to set apdu_case immediately on declaration
  for the GNUK and non-GNUK case
2015-10-15 16:17:22 +02:00
Peter Marschall 3341c5bb8f OpenPGP: make logical structure clearer
- one line per sub-term in the condition of the conditional statement
2015-10-15 16:17:11 +02:00
Frank Morgner 9e500e0b9a fixed bad typecast 2015-10-04 12:52:49 +02:00
Frank Morgner 7120a9b549 Merge pull request #554 from frankmorgner/fixes
Some more fixes for problems reported by Coverity scan
2015-09-25 11:13:17 +02:00
Frank Morgner ba3890f8e0 Checks result of calloc 2015-09-17 22:24:33 +02:00
Frank Morgner d20290d2b3 openpgp: match application, not ATR
fixes #391
closes #507
2015-09-16 09:48:23 +02:00
Robert Ou b28c48afe0 Fix OpenPGP driver to work correctly with YubiKey NEO 2015-09-16 09:48:23 +02:00
Nguyễn Hồng Quân a64bbc55aa [OpenPGP] Fix building without OpenSSL. 2015-08-31 22:24:16 +08: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
Nguyễn Hồng Quân 6409202c2f [OpenPGP] Fix warnings about type conversion. 2015-08-08 14:17:12 +08:00
Nguyễn Hồng Quân d0e3d1be3d Fix tab & spaces 2015-07-04 00:21:38 +08:00
Frank Morgner bcb5fc15e5 honour HAVE_CONFIG_H 2015-04-22 23:55:33 +02:00
vletoux 8ea328ff7f Minor code quality improvements.
Basically checks that the memory allocation succeed.

The ctbcs.c change improve the readability
because count = 0 and len > 254 does not add any value.

VTA: added few coding style changes
2015-04-05 13:15:57 +02:00
Frank Morgner 5cafbe0f4b fixed undefined shift behaviour 2015-02-04 08:50:19 +01:00
Frank Morgner 2e04fa99c1 fixed pointless array comparisons 2015-01-28 07:39:35 +01:00
Nguyễn Hồng Quân 99b5cb53e1 OpenPGP: Remove unused variables and fix type cast. 2014-12-10 04:01:06 +08:00
george 8d21cea7fc hardcode->defines for DO's 2014-11-11 16:16:15 +01:00
Nguyễn Hồng Quân 901c7952c1 Replace hardcode. 2014-11-09 15:58:40 +07:00
Nguyễn Hồng Quân 7c9bc4d283 OpenPGP: Fix crash after accessing inexistent file. 2014-07-14 23:58:28 +08:00
Nguyễn Hồng Quân c71934af67 OpenPGP: Rename private "blob" type to avoid confusing with variable name.
This name has been used for both data type and variable name of that
type.
2014-07-14 23:58:28 +08:00