Commit Graph

156 Commits

Author SHA1 Message Date
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
Nguyễn Hồng Quân aded490b64 OpenPGP: Use directly binary array of APDUs for ERASE command.
I used a string presentation before and it needed an extra conversion step.
2014-07-14 23:53:44 +08:00
Nguyễn Hồng Quân 7c27cea61f OpenPGP: Make indentation consistent (space -> tab). 2014-07-14 23:53:44 +08:00
Nguyễn Hồng Quân 6aa4896b35 Move declaration to top of block. 2014-07-14 02:02:08 +08:00
Nguyễn Hồng Quân 7ba89893da OpenPGP: Make code neater 2014-07-14 02:02:07 +08:00
Nguyễn Hồng Quân a42eb5e585 OpenPGP: Correct parameter checking. 2014-07-14 02:02:07 +08:00
Nguyễn Hồng Quân a1c8c99858 OpenPGP: Delete key as file, for Gnuk. 2014-07-14 02:02:07 +08:00
Nguyễn Hồng Quân e71906ed23 OpenPGP: Overcome the restriction of even data length of Gnuk.
When write certificate with odd length to Gnuk, we add zero padding to make it even.
2014-07-14 02:02:07 +08:00
Nguyễn Hồng Quân cbc53b9a97 OpenPGP: Support write certificate for Gnuk. 2014-07-14 02:02:07 +08:00
Nguyễn Hồng Quân ebbebb4fa6 OpenPGP: Provide enough buffer to read pubkey from Gnuk. 2014-07-14 02:02:07 +08:00
Nguyễn Hồng Quân 1df3daeb62 OpenPGP: Read some empty DOs from Gnuk.
In Gnuk, some empty DOs are returned as not exist, instead of existing with empty value.
So, we will consider them exist in driver.
2014-07-14 02:02:07 +08:00
Nguyễn Hồng Quân db39041cc1 OpenPGP: Correct building Extended Header List when importing keys. 2014-07-14 02:02:07 +08:00
Nguyễn Hồng Quân 3b8f77882b OpenPGP: Support erasing (reset) card.
Command: openpgp-tool --erase
2014-07-14 02:02:07 +08:00
Nguyễn Hồng Quân c81eab5a70 OpenPGP: Include private DO to filesystem at driver initialization.
In old implementation, the DOs which their access is restricted by
PIN (like DOs 0101 -> 0104) were excluded from the fake filesystem,
leading to that we cannot read their data later, even if we verified PIN.
2014-07-14 02:02:06 +08:00
Nguyễn Hồng Quân 1789cf0345 OpenPGP: Detect and support Gnuk Token.
http://www.fsij.org/gnuk/
2014-07-14 02:02:06 +08:00
Frank Morgner a64326e768 fixed compiler warnings (partially submitted)
Signed-off-by: Frank Morgner <morgner@informatik.hu-berlin.de>

PR-222: commit 0b567dbaa8
partially submitted by Viktor Tarasov
2014-05-03 21:47:15 +02:00
Frank Morgner d21830344f fixed a ton of compiler warnings 2013-08-03 19:15:55 +02:00