Commit Graph

256 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
Frank Morgner e3649fb7de fixed even more compiler warnings 2013-08-02 15:43:25 +02:00
Ludovic Rousseau 9ca47cded6 Fix a memory leak
Do not forget to also free data in case of error.

Coverity: Resource leak (RESOURCE_LEAK)
Calling allocation function "calloc".
2012-08-25 19:15:27 +02:00
Ludovic Rousseau ed959004dd Fix a potential memory leak
If tlvblock is not stored then the value is lost and the allocated
mempry is leaked.

Coverity: Resource leak (RESOURCE_LEAK)
Calling allocation function "pgp_build_tlv" on "tlvblock".
2012-08-25 19:15:27 +02:00
Nguyễn Hồng Quân 1adbb3fae7 OpenPGP: Set write access more restrictive for pubkey blobs.
marschap: "The WRITE_ALWAYS ACL tells anyone can write to this file at any time."
2012-08-12 15:57:03 +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 30e61d9fbf OpenPGP: Handle access on dummy files, which is assumed to exist by pkcs15init.
OpenPGP: Update card algorithms after importing key.

OpenPGP: Add SC_ALGORITHM_ONBOARD_KEY_GEN flag to card algorithms.
2012-07-29 13:09:08 +02:00
Nguyễn Hồng Quân 7123638454 OpenPGP: Correct access condition for some pubkey blobs.
OpenPGP: Don't really delete pubkeys blobs.
2012-07-29 13:09:08 +02:00
Viktor Tarasov 0518ced8e0 asn1: export 'asn1-write-element' function
... used by OpenPGP driver
2012-07-29 13:09:00 +02:00
Nguyễn Hồng Quân 42ad3c1dff OpenPGP: Add support for key import at driver level.
OpenPGP: Some indentations need to be tab-size-independent.

OpenPGP: Check for null data when storing fingerprints.

OpenPGP: Allow to provide creation time to store (when gen/import key).
Old: Only store current time.
New: Can provide time to store, not only calculate current time.

OpenPGP: Correct setting content of pubkey blobs after key generation.

cardctl: Add definitions to support key import in OpenPGP.

OpenPGP: Add support for key import at driver level.
2012-07-29 12:48:59 +02:00
Nguyễn Hồng Quân 50e37aa849 OpenPGP: Correct the way to set output after generating key.
Correct the way to parse response data.
Updated wrong blob for pubkey info <~~ Fix.

OpenPGP: Store creation time after generating keys.

OpenPGP: Put_data: Handle the case that DO exists but its blob does not.
When checking DO before writing, relying on blobs only will miss the case that DO exists but its blob does not, when DO is non-readable.

OpenPGP: Set algorithm attributes before generating key.

OpenPGP: Add dependency of OpenSSL.

OpenPGP: Calculate and store fingerprint.
Calculate and store fingerprint after generating key.

OpenPGP: Update blob of pubkey info.
Update blob holding pubkey info after generating key.

OpenPGP: Add step to update card algorithms.
Update card algorithms after generating key. However, this step is not implemented yet, because of suspection about wrong data (see code comment).
2012-07-29 12:48:21 +02:00
Nguyễn Hồng Quân 0b469ed31e OpenPGP: Add an explanation when building APDU. 2012-07-07 19:00:35 +02:00
Peter Marschall 34541e95c4 OpenPGP: add LOG_FUNC_CALLED() for "symmetric" logging 2012-06-17 10:49:00 +02:00
Nguyễn Hồng Quân 8db8f76bad OpenPGP: Change whitespace. 2012-06-16 15:43:51 +02:00
Nguyễn Hồng Quân ccb1067d75 OpenPGP: Correct the APDU preparation step for key generation. 2012-06-16 15:43:09 +02:00
Nguyễn Hồng Quân 5e295ba08d OpenPGP: Remove unused constants. 2012-06-15 14:40:14 +02:00
Viktor Tarasov 9466891752 openpgp: coverity scan warning MISSING_RETURN
Coverity Scan CID: 709045
2012-06-11 18:51:06 +02:00
Peter Marschall a09f304817 OpenPGP: clean up & fix pgp_delete_file()
* use LOG_FUNC_CALLED() .. LOG_FUNC_RETURN for "symmetric" logging
* don't zero-fill the DO's contents but empty it
* get rid of unnecessary variables
* select parent DF after deletion (required by to ISO 7816-9)
* don't try to delete MF
2012-06-09 13:48:09 +02:00
Peter Marschall 2aa4cf57ed OpenPGP: simplify pgp_update_binary() even more
Fail on idx > 0 in order to avoid the requirement to read from the DO.
The DO may be read-protected, and this might either fail or produce
wrong results.
2012-06-09 13:48:09 +02:00
Peter Marschall d7f58f7ea7 OpenPGP: cleanup & fix pgp_update_binary()
* use LOG_FUNC_CALLED() .. LOG_FUNC_RETURN for "symmetric" logging
* update comment
* check that blob->data is defined
* fix writing new data to the correct offset
* use calloc() instead of malloc() & memset()
* align pgp_ops function pointer list
2012-06-09 13:48:09 +02:00
Peter Marschall c8e802eab6 OpenPGP: simplify & clean up pgp_put_data()
* make sure variables of type u8 do only get passed fitting data
* use LOG_FUNC_CALLED() .. LOG_FUNC_RETURN for "symmetric" logging
* leave most of the spcial casing in ADPU handling to sc_adpu_transmit()
* use SC_ADPU_CASE_1 for empty buffer (avoids special casing Lc=0)
* clean up log strings & comments
2012-06-09 13:48:09 +02:00
Peter Marschall 0010fcbe6b OpenPGP: make pgp_set_blob() a bit more resilient
* use calloc() instead of malloc() to have defined contents
* only copy from passed data when it is not NULL
2012-06-09 13:48:09 +02:00
Nguyễn Hồng Quân 73387d4b84 OpenPGP: Correct ACL key_ref
Correct ACL key_ref after redefining conventional OpenPGP key-ref (0x81-0x83 -> 1-3).
2012-06-09 08:04:19 +02:00
Peter Marschall 9e04ae46bb OpenPGP: implement pgp_find_blob()
Replace the "one-trick-pony" pgp_do_iswritable() with a more generic
function returning the blob matching the passed tag.

This way we can get rid of the one-line function pgp_blob_iswritable() too.
comparisons like these can be done in the caller.
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 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
hongquan df39590aa4 OpenPGP: Correct adding read access to ACL. 2012-06-08 20:17:35 +02:00
hongquan e269907e1d OpenPGP: support key generation in driver. 2012-06-08 20:17:35 +02:00
Nguyễn Hồng Quân 9dd5a64d43 OpenPGP: Support another variant of PUT DATA to write to Extended Header list. 2012-06-08 20:17:35 +02:00
Nguyễn Hồng Quân fefe8bf2e6 OpenPGP: Check data size in pgp_put_data. 2012-06-08 20:17:35 +02:00
Nguyễn Hồng Quân f188a5dda3 OpenPGP: Implement pgp_update_binary() to update file content. 2012-06-08 20:17:35 +02:00
Nguyễn Hồng Quân 935a7505d7 OpenPGP: Add Access Control List for emulated files. 2012-06-08 20:17:35 +02:00
Nguyễn Hồng Quân c891544990 OpenPGP: Use command chaining to send large data if extended APDU is not supported. 2012-06-08 20:17:35 +02:00
Nguyễn Hồng Quân 5673d13c15 OpenPGP: implement pgp_delete_file() 2012-06-08 20:17:35 +02:00
Nguyễn Hồng Quân 72088b6eeb OpenPGP: implement pgp_strip_path()
Strip away the non-existant DF 5015 from paths passed the driver.
2012-06-08 20:17:35 +02:00
Nguyễn Hồng Quân f7785ad1ec OpenPGP: correct use of pin_reference 2012-06-08 20:17:34 +02:00
Nguyễn Hồng Quân 3ac834e277 OpenPGP: implement pgp_put_data() 2012-06-08 20:17:34 +02:00
Nguyễn Hồng Quân a1ed22b6fd OpenPGP: implement pgp_do_iswritable() 2012-06-08 20:17:34 +02:00
Nguyễn Hồng Quân d8d6902699 OpenPGP: implement pgp_seek_blob() 2012-06-08 20:17:34 +02:00
Nguyễn Hồng Quân 7e24102f2b OpenPGP: Make DO 7F21 treated as simple DO
Make DO 7F21 treated as simple DO, to make certificate contained in it visible.
2012-06-08 20:17:34 +02:00
Peter Marschall d38d615025 OpenPGP: parse more (extended) capabilities on init
* parse more extened capabilities & features into a private enum
* for v2.0 cards, always parse the "historical bytes" DO
  reason: ATR may be static and thus cannot reflect the state
2012-05-30 09:39:12 +02:00
Peter Marschall 458517783c OpenPGP: fix access conditions for DOs
Follow the specs.
2012-05-30 09:39:11 +02:00
Martin Paljak 7535f30738 OpenPGP: add the v1.0 spec URL as well to source code comments.
Even though it is obsolete, it makes it more complete;)
2012-05-16 17:01:09 +02:00
Martin Paljak fb772cccf8 OpenPGP: use actual references in PKCS#15 emulation code for PIN codes. Only v1.1 has 3 PIN codes. 2012-05-16 17:01:09 +02:00
Peter Marschall 4939432304 OpenPGP: unlink blob from blob tree in pgp_free_blob()
Remove links pointing to the blob to be deleted from other blobs in the
blob tree structure, so that removing a subordinate blob does not hurt
its parent or siblings.

Signed-off-by: Peter Marschall <peter@adpm.de>
2011-06-11 09:30:46 +02:00
Peter Marschall da5a223e26 OpenPGP: use pgp_new_blob() to setup MF blob
Use the standard way to create blobs, pgp_new_blob(), also for the MF.

Signed-off-by: Peter Marschall <peter@adpm.de>
2011-06-11 09:30:46 +02:00
Peter Marschall 4ddec5d384 OpenPGP: add DO info entries for MF
For consistency, add DO info entries for the MF 3F00.

Signed-off-by: Peter Marschall <peter@adpm.de>
2011-06-11 09:30:46 +02:00
Peter Marschall 961a27c921 OpenPGP: update pgp_list_files()
* fail if buffer passed as parameter is too small
* only list readable objects

Signed-off-by: Peter Marschall <peter@adpm.de>
2011-06-11 09:30:46 +02:00
Peter Marschall 2e7406922f OpenPGP: re-factor gpg_new_blob()
* get file as parameter & fail if it is NULL
* allow parent to be NULL
* do not rely on DO info to be passed as parameter,
  search it yourself using the global DO info list for the card.
* infer file type automatically from DO info matching the file ID.

Signed-off-by: Peter Marschall <peter@adpm.de>
2011-06-11 09:30:46 +02:00
Peter Marschall b6ee0e3d75 OpenPGP: immediately quit on allocation errors in init
Signed-off-by: Peter Marschall <peter@adpm.de>
2011-06-11 09:30:46 +02:00
Peter Marschall e3fca4ac11 OpenPGP: remove DO info entry for DO FF
DO FF is a "catch-all" DO that returns all the infos contained in the other
DOs in one hierarchy.
It is hence duplicate and not necessary.

Signed-off-by: Peter Marschall <peter@adpm.de>
2011-06-11 09:30:46 +02:00
Peter Marschall 01e63424f5 OpenPGP: fix algorithms & key lengths calculation
Also include forgotten DO C3 in keylength calculation.
It contains the parameters for the authentication key.

Signed-off-by: Peter Marschall <peter@adpm.de>
2011-06-11 09:30:46 +02:00
andre bbcb867a8f card-openpgp.c: In function ‘pgp_enumerate_blob’:
card-openpgp.c:584: warning: comparison between signed and unsigned
card-openpgp.c: In function ‘pgp_card_ctl’:
card-openpgp.c:1036: warning: unused variable ‘priv’
card-openpgp.c: In function ‘pgp_init’:
card-openpgp.c:272: warning: ‘child’ may be used uninitialized in this function


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5504 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-27 08:49:43 +00:00
martin 4899f70b4e OpenPGP: use updated ushort2bebytes() in pgp_get_pubkey()
Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5499 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:33:50 +00:00
martin fa259c63d5 OpenPGP: re-factor pgp_list_files()
Use ushort2bebytes instead of calculating the mapping to IDs ourselves.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5497 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:33:38 +00:00
martin e422a57449 OpenPGP: re-factor pgp_get_blob()
Instead of jumping out of the loop when the correct child is found,
and checking afterwards again if we found the correct object,
do everything directly in the loop and return from there.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5496 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:33:33 +00:00
martin 782b4efa73 OpenPGP: get flags & algorithms in pgp_get_card_features()
Extend pgp_get_card_features() to get card's flags & supported algorithms
from the card:
* get algorith values from "algorithm attributes" DOs 0x00c1 - 0x00c3

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5495 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:33:27 +00:00
martin c46152d89b OpenPGP: extend pgp_get_card_features()
Extend pgp_get_card_features() with these features:
* get SC_CARD_CAP_RNG capability from "extended capabilities" DO 0x00c0
* for OpenPGP 2.0 cards get max_send_size / max_recv_size values
  from "extended capabilities" DI 0x00c0
* get max_pin_len from "CHV status bytes" DO 0x00c4

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5494 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:33:15 +00:00
martin 1342648a89 OpenPGP: new function to get card's features
Add a new function pgp_get_card_features() to get the card's capabilities,
algorithms, features, ... instead of doing it all in pgp_init():
* get SC_CARD_CAP_APDU_EXT capability from ATR
* for openPGP 2.0 cards, if not found in ATR,
  get SC_CARD_CAP_APDU_EXT capability from "historical bytes" DO 0x5f52

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5493 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:33:04 +00:00
martin ee446adf09 OpenPGP: check for get_fn != NULL in pgp_read_blob()
In pgp_read_blob(), check if the pointer to the function we want to call
is defined.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5492 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:32:59 +00:00
martin 19142ee9af OpenPGP: deal with DOs depending on card version
Have separate copies of pgp_objects[] data elements specific to the card's
version, and extend these structures with additional information:
* Some spec changes cannot be compatibly expressed in one common
  simple data structure without making it too complex.
* depending on specification version, only deal with those DOs
  that are legal within that version
* add information or read & write access conditions
* add information for non-toplevel and/or write-only DOs
* use symbolic names for constants

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5491 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:32:54 +00:00
martin 88e88d9317 OpenPGP: read BCD version from card
Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5490 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:32:49 +00:00
martin cf3a34cbef OpenPGP: re-factor pgp_select_file()
* remove unnecessary copy operations with a temporary path object,
  instead increase the start index.
* addd comments

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5489 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:32:43 +00:00
martin 4a3df98450 OpenPGP: comment use of "current"
Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5488 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:32:36 +00:00
martin 101cf28766 OpenPGP: clean up with pgp_finish()
Use pgp_finish() wherever possible to clean up.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5487 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:32:31 +00:00
martin 9aa7342000 OpenPGP: re-factor pgp_finish()
Re-structure pgp_finish() for easier reading.
While at it, check for priv != NULL before free()ing it.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5486 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:32:26 +00:00
martin ec1f1bd812 OpenPGP: sprinkle with LOG_... macros
Instrument functions used in the card operations table pgp_ops[]
with log macros to ease debugging.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5485 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:32:21 +00:00
martin 9c26b8f7d3 OpenPGP: briefly document each function
Write a short comment at the beginning of each function,
shortly sketching what the function does.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5484 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:32:10 +00:00
martin 70fa98232a OpenPGP: remove unused element from structure
The element size in struct do_info is never used. Get rid of it.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5483 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:32:05 +00:00
martin 9765eda21c OpenPGP: implement card_ctl() command SC_CARDCTL_GET_SERIALNR
Implement card_ctl(), crrently restricted only to SC_CARDCTL_GET_SERIALNR.
The card's serial number is copied from the respective bytes in the AID.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5482 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:32:00 +00:00
martin 6e04d7f6bf OpenPGP: free memory when selecting the application fails
free() the memory already reserved when the file identifying the OpenPGP
application fails & reset the pointers in the card strcuture back to NULL.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5481 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:31:55 +00:00
martin 56f6718bf2 OpenPGP: allow extended APDUs in all functions
Depending on the card's capabilities and the necessity (requested response
size > 256) allow extended APDUs in all functions talking to the card.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5480 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:31:50 +00:00
martin f32a8ff59c OpenPGP: use card "extended Lc/Le" capabilities
adapt pgp_get_pubkey() and pgp_read_blob() to make use of the information
about the "extended Lc/Le" capabilities.

This allows reading OpenPGP Card v2.0 keys!

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5479 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:31:45 +00:00
martin 1911db7532 OpenPGP: update card capabilities from historical bytes
According to OpenPGP card specs 1.1 & 2.0 historical bytes in the ATR
indicate capabilities:
* bit 0x40 of the 3rd byte of the compact-TLV entry with TL 0x73 tells
  whether the card supports extended Lc/Le fields in APDUs.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5478 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:31:39 +00:00
martin 1bb69cb847 OpenPGP: catch calloc() errors in pgp_new_blob()
Detect and react on out of memory errors in pgp_new_blob() and its callers.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5477 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:31:31 +00:00
martin 6b7906f0a2 OpenPGP: use symbolic names for errors/success
Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5476 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:31:24 +00:00
martin 75a89e7c25 OpenPGP: add some comments
Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5475 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:31:18 +00:00
martin 4892af32c4 OpenPGP: re-factor pgp_set_blob()
* NULL-ify freed data pointer
* avoid unnecessary malloc() calls
* cope with malloc() errors
* do not rely on blob->file for be set

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5474 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:31:09 +00:00
martin ea64ba24af OpenPGP: NULL-ify free()'d pointer
Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5473 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:31:02 +00:00
martin d248026abc OpenPGP: implement function to free the fake file system
* pgp_iterate_blobs(): walk through the blob tree
* pgp_free_blob(): free a blob

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5472 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:30:56 +00:00
martin 03381a2594 OpenPGP: re-factor pgp_enumerate_blob()
Leverage the fact that OpenPGP cards use TLV encoding according to
ASN.1 BER-encoding rules and use sc_asn1_read_tag() as the workhorse
within pgp_enumerate_blob().

There's one peculiarity though:
OpenPGP cards expect 'cla' to be merged into 'tag'.
This is done manually after calling sc_asn1_read_tag().

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5471 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:30:49 +00:00
martin 61bbb0f904 OpenPGP: try to match flags with specification
Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5470 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:30:42 +00:00
martin e5bee33260 OpenPGP: add indication of 2048 RSA agorithm for OpenPGP 2.0 cards
Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5469 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:30:36 +00:00
martin 223f704b83 OpenPGP: fix top-level DOs according to spec
Added:
* 00c4: new top-level DO in 2.0
        can also be found inside constructed DOs 006E/0073 in 2.0 & 1.1
* 0101: new optional top-level DO starting in 1.1
        for private use
        max 254 bytes;
        access: read - always; write - verify CHV2
* 0102: new optional top-level DO starting in 1.1
        for private use
        max 254 bytes;
        access: read - always; write - verify CHV3
* 5f52: new top-level DO in 2.0
        can also be found inside constructed DOs 006E in 2.0
* 7f21: new optional top-level DO in 2.0
        use: card holder certificate (e.g. X.509) for the AUT key in the card
Removed:
* 0073: never a top-level DO, but part of top-level constructed DO 006E
Changed:
* 005e: not a constructed DO, but a simple/primitive DO

Note:
Trying to read non-existent top-level DOs or top-level DOs that weren't defined
in a spec version later than the current card's version does not hurt.
They are returned as empty.

Signed-off-by: Peter Marschall <peter@adpm.de>

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5468 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-23 17:29:09 +00:00
vtarasov 3efe35d246 libopensc: avoid the using of not completely initialized 'sc_path' variables
to be continued...


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5103 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-17 19:00:52 +00:00
martin 75c1254e22 Initial modifications to support OpenPGP v2.0 (CryptoStick)
* Correct naming: openpgp not opengpg
 * Set the card name from ATR table
 * Add card type enums
 * Currently OpenPGP is read-only.

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5072 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-09 10:17:16 +00:00
ludovic.rousseau f47416d60e Do not cast the return value of malloc(3) and calloc(3)
From http://en.wikipedia.org/wiki/Malloc#Casting_and_type_safety
" Casting and type safety

malloc returns a void pointer (void *), which indicates that it is a
pointer to a region of unknown data type. One may "cast" (see type
conversion) this pointer to a specific type, as in

int *ptr = (int*)malloc(10 * sizeof (int));

When using C, this is considered bad practice; it is redundant under the
C standard. Moreover, putting in a cast may mask failure to include the
header stdlib.h, in which the prototype for malloc is found. In the
absence of a prototype for malloc, the C compiler will assume that
malloc returns an int, and will issue a warning in a context such as the
above, provided the error is not masked by a cast. On certain
architectures and data models (such as LP64 on 64 bit systems, where
long and pointers are 64 bit and int is 32 bit), this error can actually
result in undefined behavior, as the implicitly declared malloc returns
a 32 bit value whereas the actually defined function returns a 64 bit
value. Depending on calling conventions and memory layout, this may
result in stack smashing.

The returned pointer need not be explicitly cast to a more specific
pointer type, since ANSI C defines an implicit conversion between the
void pointer type and other pointers to objects. An explicit cast of
malloc's return value is sometimes performed because malloc originally
returned a char *, but this cast is unnecessary in standard C
code.[4][5] Omitting the cast, however, creates an incompatibility with
C++, which does require it.

The lack of a specific pointer type returned from malloc is type-unsafe
behaviour: malloc allocates based on byte count but not on type. This
distinguishes it from the C++ new operator that returns a pointer whose
type relies on the operand. (see C Type Safety). "

See also
http://www.opensc-project.org/pipermail/opensc-devel/2010-August/014586.html


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4636 c6295689-39f2-0310-b995-f0e70906c6a9
2010-08-18 15:08:51 +00:00
aj 6545b42c02 cleanup of the debug code:
* reduce to a few, supported functions.
* change all functions to take the debug level as parameter.
* use symbolic names for the debug levels.
* fix tools to pass "verbose"/"opt_debug" as ctx->debug.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4118 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-15 12:17:13 +00:00
aj d22a2483c0 Header file cleanup.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4081 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-04 08:14:36 +00:00
martin d672fde449 Remove sc_error and sc_ctx_suppress_errors_* in favor of sc_debug/fprintf
git-svn-id: https://www.opensc-project.org/svnp/opensc/branches/martin/0.12@3721 c6295689-39f2-0310-b995-f0e70906c6a9
2009-09-14 08:46:59 +00:00
nils 91109128c0 request at most for 256 bytes
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3149 c6295689-39f2-0310-b995-f0e70906c6a9
2007-04-15 17:26:42 +00:00
nils 88bae5c923 remove iso logout function, remove dummy logout functions and remove logout call from sc_unlock()
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2971 c6295689-39f2-0310-b995-f0e70906c6a9
2006-06-17 12:24:04 +00:00
nils dd44fd8234 if the card doesn't support a logout functionality it's not an error
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2940 c6295689-39f2-0310-b995-f0e70906c6a9
2006-05-05 10:10:00 +00:00
nils 9b52eebdda bugfix: Le must be <= buffer size
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2939 c6295689-39f2-0310-b995-f0e70906c6a9
2006-05-05 10:06:38 +00:00
aj e0d645b95b remove unneeded if(1) block.
free temp in error paths.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2716 c6295689-39f2-0310-b995-f0e70906c6a9
2005-12-05 21:39:58 +00:00
nils 47ee84e72d add functions
void sc_ctx_suppress_errors_on(sc_context_t *ctx);
	void sc_ctx_suppress_errors_off(sc_context_t *ctx);
to turn on/off error suppression (to avoid accessing
sc_context_t directly) and use it.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2671 c6295689-39f2-0310-b995-f0e70906c6a9
2005-10-30 19:08:06 +00:00
nils f6c95792fe let src/libopensc/ compile with -Wall -W -Wno-unused-parameter -Werror
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2546 c6295689-39f2-0310-b995-f0e70906c6a9
2005-09-07 08:33:55 +00:00
aet 5beab31402 - Case cleanup
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2195 c6295689-39f2-0310-b995-f0e70906c6a9
2005-02-23 10:39:33 +00:00
aet 32b417cbf3 - First stab towards standardized card types
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2172 c6295689-39f2-0310-b995-f0e70906c6a9
2005-02-10 10:07:13 +00:00
aet ece96aff98 - Add atrmask to sc_atr_table
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2160 c6295689-39f2-0310-b995-f0e70906c6a9
2005-02-09 11:33:37 +00:00
aet 69d2e9014d - Optimize a few cpu cycles from _sc_match_atr_hex
- Replace struct sc_atr_table / _sc_match_atr with
  recently introduced _hex variants
- Rewrote _add_atr
- Introduce int type variable to sc_card_t, so that
  every other card driver won't have to glue around
  with this
- Card driver cleanups, optimize the number of
  sc_match_atr called per card driver. Also
  always try direct match with _sc_match_atr
  first, before relying on eg. historical bytes
  information on some card drivers
- Fixed a memory leak from the miocos driver


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2145 c6295689-39f2-0310-b995-f0e70906c6a9
2005-02-06 19:40:40 +00:00