Commit Graph

145 Commits

Author SHA1 Message Date
Jakub Jelen 9d1a214340 pkcs11: Undefine internal typedef and remove its usage 2021-06-02 15:46:00 +02:00
Marco Trevisan (Treviño) 845eac4250 pkcs11-global: Obey to the tokenPresent parameter on C_GetSlotList
Since commit dba0f56 the tokenPresent parameter is ignored in case the
slot has been already seen.

This breaks the API expectations as we may return a slot that has no
token inserted.

So, only consider the SC_PKCS11_SLOT_FLAG_SEEN if tokenPresent is false
2021-03-22 15:35:55 +01:00
Doug Engert 1b4e9f1d4a C_Initialize may be called by multiple threads
While trying to setup an OpenSC context, the global_locking
and detect cards, it is possible that multiple threads may
call C_Initialize. The current code tries to prevent this using
"if (context == NULL)"  but this is not a mutex, and
multiple threads may endup overwrite contexts and global locking and
cause additional problems, with pcsc and segfault.

FireFox appears to do this see #2032

The PR adds a mutex or Critical section to make sure only one
thread creates the context sets the global_locking  and does
the initial detect cards, etc.

This allows the global_lock (if requested) to be setup
which is then used for other calls.

All but the first call to C_Initialize will return with CKR_OK,
others will return CKR_CRYPTOKI_ALREADY_INITIALIZED.

 Date:      Mon Jan 11 12:47:12 2021 -0600
 Changes to be committed:
	modified:   src/pkcs11/pkcs11-global.c
2021-01-26 12:50:39 +01:00
Jakub Jelen 47151e9335 pkcs11: Implement getInterface() for accessing PKCS #11 3.0 functions 2021-01-11 14:49:22 +01:00
Jakub Jelen e58e7e1428 Standardize PKCS #11 version to 2.20 systematically 2021-01-11 14:49:22 +01:00
Frank Morgner 36247d85b0 pkcs11: fixed notifying twice in case of an attached reader
before 14e396273 sc_wait_for_event() only notified in case of a new
reader, but didn't add it to the internal list of readers. That's why
PKCS#11 needed to bail out early in this case (and the application had
to call C_WaitForSlotEvent a second time to actually get the related
slot). Since sc_wait_for_event() can now handle insertion correctly, we
can now immediately check (and reset) the events on the slots.
2020-06-09 12:07:04 +02:00
Frank Morgner f1bcadfbe9 pkcs11: don't try to allocate 0 byte with calloc
fixes #1978
2020-03-10 12:15:04 +01:00
Frank Morgner dba0f56722 pkcs11: fixed state tracking
- when listing the slots, we don't have a hotplug slot anymore with
slot->reader == NULL. Instead, we're now using this state for any left
over slots when a reader is removed. So we don't need to include this in
the slot list

- when listing the slots, we need to remember which slots the
application has seen already, to not shrink the list of slots (which is
allowed in PKCS#11 v2.2, but NSS can't handle this)
2020-03-04 21:06:43 +01:00
Frank Morgner 7e7458edce pkcs11: restore creating 4 virtual slots for each reader
fixes old token slot ids
(https://github.com/OpenSC/OpenSC/pull/1970#issuecomment-594400562)
2020-03-04 14:25:08 +01:00
Doug Engert 8d519ed3c4 Add calls to DEBUG_VSS
On branch PKCS11-SLOTS-2
 Changes to be committed:
	modified:   pkcs11-global.c
	modified:   slot.c
2020-03-04 13:39:12 +01:00
Frank Morgner 5b9af96851 pkcs11: reclaim unused slots based on reader description
When a reader is removed and reattached, this re-uses the old slot
without relying on the fact that the sc_reader_t is unchanged.
2020-03-03 22:55:27 +01:00
Frank Morgner d54f346937 pkcs11: simpify reader removal
- reader (slot) description is already initialized init_slot_info()
- objects and logins are already released in slot_token_removed
2020-03-03 22:55:27 +01:00
Frank Morgner 8f4a6c703b align comment with implementation order 2020-02-20 01:42:18 +01:00
Frank Morgner 31d8c2dfd1 Revert "pkcs11: fixed slotIDs when a new slot list is requested"
This reverts commit 7fb72ccf7b.
2020-02-19 16:09:20 +01:00
Jakub Jelen 0ea11523a3 Improve logging of exit codes 2019-11-01 15:50:34 +01:00
Frank Morgner 7fb72ccf7b pkcs11: fixed slotIDs when a new slot list is requested
fixes https://github.com/OpenSC/OpenSC/issues/1706

regression of 24b7507a69
2019-06-30 10:24:11 +02:00
Frank Morgner 7449b00768 pkcs11: avoid double initialization of notify 2019-04-26 23:51:37 +02:00
Frank Morgner 0abe9d11c7 pkcs11: (de-) initialize notifications on load
fixes https://github.com/OpenSC/OpenSC/issues/1507
fixes https://github.com/OpenSC/pkcs11-helper/issues/16
2019-04-04 11:04:50 +02:00
Frank Morgner f3a2962358 pkcs11: perform memory cleanup on dll unload 2018-11-13 15:50:17 +01: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
Frank Morgner 654ca69c47 initialize notifications in PKCS#11 and tools
... and don't panic when they are not initialized
2017-11-21 13:01:12 +01:00
Jakub Jelen e0eb5bf888 Do not call list_init() twice (amend 6bfb39454) 2017-08-11 23:06:21 +02:00
Frank Morgner 6bfb39454b Fix missing error handling of memory allocation (#1020)
* libopensc: handle allocation errors
* handle more faults during memory allocation

fixes several situations that cause segmentation fault
2017-04-20 21:08:49 +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
Frank Morgner 24b7507a69 pkcs11: don't shrink the number of slots
... as required by PKCS#11 2.30, if the application doesn't call
`C_GetSlotList` with `NULL`.

Fixes ghost tokens in Firefox when detaching a reader that contained a
card.

Fixes https://github.com/OpenSC/OpenSC/issues/629
2017-01-09 08:35:42 +01:00
Frank Morgner 7e6dc25c40 remove all login states when the token was removed 2017-01-09 08:35:42 +01:00
Jakub Jelen 3cb24ebc79 Restore blocking WaitForSlotEvent functionality for recent PCSC-Lite versions
* Add configure-time dependency on pcsclite (required version from comments in reader-pcsc.c)
 * The functionality is already supported in PCSC-Lite
 * For older PCSC-Lite versions still return CKR_FUNCTION_NOT_SUPPORTED

 # closes #899
2016-11-20 19:36:03 +01:00
viktorTarasov a5550f980b Merge pull request #706 from frankmorgner/npa-generic
generic changes from #611
2016-03-10 11:04:12 +01:00
Viktor Tarasov 1fb741338a pkcs11: remove hot-plug-anb-play
updated version of PR #687

Discussion and motivation in PR #687 and PR #704

Fix #687
Fix #704
2016-03-10 10:43:18 +01:00
Frank Morgner 415f15e3e2 use autoconf metadata for PKCS#11 library 2016-03-07 10:39:42 +01:00
Frank Morgner 5129c5a060 Fixed memory leaks 2015-12-09 08:22:45 +01:00
Frank Morgner 83ef753799 Implemented atomic PKCS#11 transactions 2015-12-06 10:42:45 +01:00
Michał Trojnara fa9da7ad01 configurable OS thread locking 2015-12-01 09:19:03 +01:00
Frank Morgner f252277fab Add configuration for sloppy PKCS#11 initialization 2015-10-01 12:44:41 +02:00
Frank Morgner 3307dd6f45 implemented sloppy initialization for C_GetSlotInfo
Makes things work for Java and closes #523
2015-10-01 12:44:41 +02:00
Frank Morgner d7d64ee8d4 Merge pull request #494 from frankmorgner/fork
After a fork do not release resources shared with parent
2015-08-04 10:32:01 +02:00
Frank Morgner b3dc5ea32a fixed segfault for uninitialized IsoApplet
fixes #400
2015-07-27 18:43:51 +02:00
Frank Morgner 7cec500e54 added flags to sc_context_t
- is initialized in sc_context_create with parm->flags
- removes members paranoid_memory and enable_default_driver
2015-07-22 17:30:21 +02:00
Frank Morgner edc839e072 restrict access to card handles after fork
fixes #333
closes #493
2015-07-22 16:46:04 +02:00
Doug Engert b48fa70308 sc_pkcs11_card improvements
This is name change only fix.

    The variable name "card" was being used to refer to a struct sc_card or a struct sc_pkcs11_card
    in some files including sc_pkcs11.h. In other files the variable name "p11card" is used for struct sc_pkcs11_card.
    This creates hard to read code, such as: slot->card->card.

    All definitations of sc_pkcs11_card *card now use p11card as the variable name.

Fix #471
2015-05-24 11:41:29 +02:00
Frank Morgner 7a34c204c1 fixed dereference before null check
silence warnings reported by coverity-scan
2015-01-22 20:29:33 +01:00
Raul Metsma 8e13acf51e Restore pkcs11 onepin module for Firefox usage 2014-05-31 21:15:19 +02:00
Viktor Tarasov 95b6b4ccd3 pkcs11: changes in framework API
to prepare future enhancements and in the sake of uniformity
in 'struct sc_pkcs11_framework_ops'
the 'struct sc_pkcs11_card' argument of 'init_token' handler is changed for 'struct sc_pkcs11_slot'

coding style issues
2013-12-29 19:46:56 +01:00
Martin Paljak 32ed309037 pkcs11: use calloc instead of malloc; remove obsolete malloc.h references. 2013-03-15 23:02:02 +02:00
Martin Paljak 3b4f7b9ff7 pkcs11: Don't touch readers or inserted cards in C_Initialize in 2.20 mode
This significantly speeds up calling C_Initialize.
Thanks to Nikos Mavrogiannopoulos for the tip.
2013-03-15 23:01:16 +02:00
Martin Paljak c2b6a0d500 pkcs11: report the library version based on plug-n-play feature. 2013-03-15 21:28:29 +02:00
Viktor Tarasov 20bf3f5484 pkcs11: use short form of log messages
Change-Id: Ice298552238da9eeb0b646fc1ddfaf4d7a8ee4bb
2012-05-13 00:27:38 +02:00
Viktor Tarasov cb13633634 remove trailing whitespaces
inspired by
http://www.opensc-project.org/pipermail/opensc-devel/2012-March/017883.html

Change-Id: If170e830d8d9587a31742feffb6fff54cfdf75b4
2012-04-03 00:00:56 +02:00
vtarasov b3cbf5453e pkcs11: resolve problem 'change 5421 breaks MIT Kerberos login', thanks to Douglas.
http://www.opensc-project.org/pipermail/opensc-devel/2011-June/016734.html


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5537 c6295689-39f2-0310-b995-f0e70906c6a9
2011-06-02 17:20:10 +00:00
vtarasov dc55351767 pkcs11: hide empty slots ...
The list of slots returned by C_GetSlotList() contains:
 - if present, virtual hotplug slot;
 - any slot with token;
 - without token(s), one empty slot per reader;


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5421 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-04 07:17:28 +00:00