Commit Graph

6604 Commits

Author SHA1 Message Date
Frank Morgner c5e40127d0 Coverity fixes (#1012)
card-cac.c
 * CLANG_WARNING: The left operand of '<' is a garbage value
card-coolkey.c
 * CLANG_WARNING: overwriting variable
 * CPPCHECK_WARNING: memory leak / overwrite variable
 * CLANG_WARNING: null pointer dereference
 * UNUSED_VALUE: unused return value
card-gids.c
 * CLANG_WARNING: Branch condition evaluates to a garbage value
 * SIZEOF_MISMATCH: suspicious_sizeof
card-myeid.c
 * RESOURCE_LEAK: Variable "buf" going out of scope leaks the storage it points to.
 * CLANG_WARNING: overwriting variable
 * (rewrite not to confuse coverity)
pkcs15-cac.c
 * RESOURCE_LEAK: Variable "cert_out" going out of scope leaks the storage it points to.
pkcs15-coolkey.c
 * UNUSED_VALUE: unused return value
pkcs15-piv.c
 * RESOURCE_LEAK: Variable "cert_out" going out of scope leaks the storage it points to.
pkcs15-sc-hsm.c
 * DEADCODE
pkcs11/framework-pkcs15.c
 * RESOURCE_LEAK: Variable "p15_cert" going out of scope leaks the storage it points to.
pkcs15init/pkcs15-lib.c
 * CLANG_WARNING: Assigned value is garbage or undefined
pkcs15init/pkcs15-myeid.c
 * UNREACHABLE: Probably wrong placement of code block
tests/p15dump.c
 * IDENTICAL_BRANCHES
pkcs15-init.c
 * CLANG_WARNING: Potential leak of memory pointed to by 'args.der_encoded.value'
pkcs15-tool.c
 * RESOURCE_LEAK: Variable "cert" going out of scope leaks the storage it points to.
 * MISSING_BREAK: The above case falls through to this one.
sc-hsm-tool.c
 * CLANG_WARNING: Potential leak of memory pointed to by 'sp'
westcos-tool.c
 * FORWARD_NULL: Passing null pointer "pin" to "unlock_pin", which dereferences it.
 * (rewrite not to confuse coverity)
card-cac.c
* Avoid malloc with 0 argument
gids-tool.c
* FORWARD_NULL -- copy&paste error
scconf.c
* CLANG_WARNING: Call to 'malloc' has an allocation size of 0 bytes

closes #982
2017-04-03 13:43:30 +02:00
Frank Morgner 013bdcb264 macOS: added support for access via CryptoTokenKit
Binaries still need to be signed with the com.apple.security.smartcard
entitlement. The command should look something like this:

codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" target/Library/OpenSC/bin/*
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" target/Library/OpenSC/lib/*.dylib
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" --deep target/Library/OpenSC/lib/opensc-pkcs11.bundle
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" --deep target/Library/Security/tokend/OpenSC.tokend
2017-04-03 12:30:03 +02:00
Frank Morgner 70313512ad recognize T=0 limitation of sending 255 bytes
fixes https://github.com/OpenSC/OpenSC/issues/1009
2017-04-03 09:08:40 +02:00
Frank Morgner f21fe1de8d win32 installer: skip license agreement
in accordance to
https://www.gnu.org/licenses/old-licenses/gpl-2.0-faq.html#ClickThrough
2017-03-28 14:24:30 +02:00
Frank Morgner 8da29d4a1e pkcs15-tool: documentated `--clear-cache` 2017-03-28 14:24:13 +02:00
Frank Morgner 752e5afd49 log exit of sc_single_transmit in case of SM 2017-03-28 14:24:13 +02:00
Frank Morgner 0a254dc2bb fixed compiler warnings 2017-03-28 12:51:24 +02:00
Maciej S. Szmigiero 428b134776 Minidriver CardReadFile() parameters are optional
According to minidriver specs CardReadFile() method output parameters are
optional so don't return SCARD_E_INVALID_PARAMETER when they are NULL.

Also, use this opportunity to walk through this function helpers to make
sure they correctly return error status.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:09:38 +02:00
Maciej S. Szmigiero d203ad76a4 Minidriver CardGetChallenge() parameters are output only
According to minidriver specs CardGetChallenge() method parameters
are purely for output and do not have a meaning of requested challenge
length, so remove a misleading log line.

There is also no need to have a special case for pcbChallengeData being
NULL since in this case the function would have exited early anyway with
SCARD_E_INVALID_PARAMETER (also, it was just dereferenced in the previous
code line).

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 56f880613a Fix minidriver log messages format and parameter issues flagged by GCC
Since last commit GCC warns us about problems with format strings and their
arguments in minidriver, so let's fix these warnings just as we did in rest
of the OpenSC code.

Most of these warnings were about DWORDs being printed as ints, there were
also some format directives and size_t size specifiers missing and various
misc format / parameter disagreements.

Attempt was made to keep log strings as-is, only the most obvious typos
were fixed.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 1a073d5683 Add GCC format checking attributes to minidriver logging function
Commit "Add GCC format checking attributes to log functions" added format
and parameter checking to OpenSC log functions.
Minidriver, however, logs most of its output via a dedicated log function,
so this function needs such attributes, too.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero da6815d542 Use built-in formatted output functions on mingw
Mingw currently links to msvcrt.dll as C runtime.
This library is documented by Microsoft as off-limits to applications and
its feature set vary between Windows versions.

Due to this, presence of particular printf() format string directives
depends on which Windows version the code is run.

This is, naturally, bad, so mingw developers introduced ability to replace
formatted output functions with built-in equivalents with defined feature
set by setting "__USE_MINGW_ANSI_STDIO" macro to 1.
There are, however, no built-in equivalents for "_s" suffixed functions.
Fortunately, they are used only a few times in minidriver so let's simply
replace them with equivalent code using standard functions.

This also allows skipping "MINGW_HAS_SECURE_API" macro definition so any
future uses will be caught by compiler.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 58c4de26a7 Fix cases of log function format strings not being a string literal
Looks like Travis CI build server found a few cases of log function format
string not being a string literal (now that log functions have necessary
attributes to check for such things).
Some instances clearly aren't a real problem, but to be future-proof and to
avoid compiler warnings let's fix all of them (that I was able to find in
code).

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +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
Maciej S. Szmigiero 2e75198181 Add GCC format checking attributes to log functions
GCC can check format and parameter correctness in printf()-like functions
for us so let's add necessary attributes to our log functions to emit a
warning where their way of being called is likely in need to be inspected
for correctness.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 1c40426421 Support PIN unblocking in minidriver via PUK as response to challenge
Minidriver currently has basic support for unblocking card PIN by providing
PUK as an administrator password to CardUnblockPin() function.

However, this doesn't work for example when trying to unblock PIN via
system smartcard PIN unblock screen accessible after pressing Ctrl+Alt+Del
as it wants to use challenge / response authentication.
MS Smart Card Minidriver specification (version 7.07) explicitly says that
challenge / response is the only authentication mode that Windows uses to
authenticate an administrator.
Unfortunately, this way of unblocking PIN seems to not be widely supported
by cards.

However, we can simply treat the provided response to challenge as PUK.
Because (at least) Ctrl+Alt+Del PIN unblock screen accepts only hex string,
every PUK digit X has to be input as '3X' (without quotes) there.
Also the response string is not hidden behind asterisks on this screen as
it should been.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero f91fc3d338 Remove logprintf() mingw hack in minidriver
Minidriver contained a hack since commit 7ef766b785 in 2010 to print to
debug file directly under mingw (instead of using normal OpenSC logging
system), as there was problem with "%S" format specifier then.

However, on recent mingw versions "%S" format works fine so let's remove
this hack.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 5877fd260d Add ptrdiff_t (pointer difference) printf length modifier
Some of existing code prints pointer differences, but without taking into
account that printf length modifier required for this differs between
systems.
Add SC_FORMAT_LEN_PTRDIFF_T macro for this, just as we have for size_t
variables.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 1479c4cb3b Add reset operation to opensc-tool
Add "--reset" parameter with optional argument to opensc-tool which
resets a card in reader. Both cold or warm resets are possible
(cold is default).

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero df35d739ee Add session handle uniqueness check to PKCS#11 C_OpenSession()
C_OpenSession() creates a long int session handle from address of allocated
session struct, however it has to be taken into consideration that on Win64
long int is still 32-bit, so the address is going to be truncated and
because of that not guaranteed to be unique.

Add session handle uniqueness check to catch when there is already a
session with the same handle present.

This also fixes a warning when building on 64-bit mingw.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 20f781de28 Move SM test in configure.ac after LIB_PRE and DYN_LIB_EXT assignment
SM test in configure.ac makes use of LIB_PRE and DYN_LIB_EXT variables so
let's move it further down in this file, just after these variables are
assigned.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 7f778ccff8 Fix most of warnings shown when building on Linux and mingw
This commit fixes most of warnings shown by GCC on 64-bit Linux, 32-bit and
64-bit mingw builds (with SM and OpenSSL enabled).

These warnings were mostly caused by missing casts.

In minidriver there was also a bit of unused variables and dead code.

Remaining warnings on mingw are mostly caused by GCC not recognizing on
this platform "ll" size specifier (present at least since
Visual Studio 2005, also in mingw own CRT) and "z" size specifier (this one
will be fixed in next commits).

There is also a warning about pointer truncation on Win64 when making
PKCS#11 object handle from pointer to this object.
This is a legitimate warning, since it could result in the same handles
being generated from different pointers and so from different objects.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 10:58:26 +02:00
Maciej S. Szmigiero 1b4c626d78 Make minidriver buildable again on mingw
Currently, minidriver build is broken on mingw. Let's make it work again.

For this, include adapted cardmod-mingw-compat.h with few function argument
decorations from Alon Bar-Lev's old build repository to make mingw build
almost self-contained - still requires cardmod.h from CNG, however.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 10:57:21 +02:00
Maciej S. Szmigiero 64f56b83d0 Make minidriver installer custom action library optional
Minidriver installer custom action library needs WiX SDK to build.

Since installer is an optional component anyway let's detect whether WiX
SDK is present on build platform and then decide whether to build installer
custom action library or not.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 10:57:21 +02:00
Maciej S. Szmigiero b646a306dc Print size_t variables on properly on Windows
OpenSC used SUSv3 "z" printf length modifier for printing size_t variables,
however this modifier is not available on Windows ("I" must be used
instead), at least for now.

Introduce SC_FORMAT_LEN_SIZE_T define for that purpose and convert existing
code to use it when printing size_t variables.

This define can't go into libopensc/internal.h since tools use it, too.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 10:57:21 +02: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
Jakub Jelen 2031735fb1 pkcs11-tool: Polish rough edges of --attr-from use case to verify and convert in all cases 2017-03-27 10:53:44 +02:00
Jakub Jelen 74c6494f19 pkcs11-tool: Do not allow to write PEM encoded certificates to cards
Resolves #834
2017-03-27 10:53:44 +02:00
Christoph Müllner c77cb511d9 pkcs11-tool: Add feature to get random data. (#995)
* pkcs11-tool: Add feature to get random data.

Getting random data is an essential part of the PKCS11 API.
This patch provides a new command line parameter to get
random data from the pkcs11-tool.

Tested with a Yubikey (PIV applet) and the following command line:

$ pkcs11-tool --slot=0 --generate-random=128 | hexdump -C
  00000000  0c 35 85 2e 85 68 ab ce  e8 56 b3 f6 f3 33 e6 37  |.5...h...V...3.7|
  00000010  12 10 eb fd 8a 1e 75 b7  3f 4d fa 61 8f ab d8 bf  |......u.?M.a....|
  00000020  f7 2c 7d ba 07 a5 45 6e  a7 85 1c 47 3b 46 01 2c  |.,}...En...G;F.,|
  00000030  79 18 6e 51 4d c4 ae 20  37 37 1d 7b 7e b0 d5 18  |y.nQM.. 77.{~...|
  00000040  ef a4 3c 09 91 68 db dd  2a a8 fc b9 34 06 2a ee  |..<..h..*...4.*.|
  00000050  5a 86 55 54 11 1f ef 4e  07 73 79 27 0a e4 58 cf  |Z.UT...N.sy'..X.|
  00000060  f4 bd bc 2f ad 27 b1 a7  a4 fa c7 1a 7b 31 de a3  |.../.'......{1..|
  00000070  e8 dc 85 28 18 82 00 45  3c f8 eb 48 a4 20 e4 3b  |...(...E<..H. .;|
  00000080

Signed-off-by: Christoph Müllner <christophm30@gmail.com>

* pkcs11-tool: Add documenation for --generate-random.

Signed-off-by: Christoph Müllner <christophm30@gmail.com>
2017-03-27 10:52:38 +02:00
Frank Morgner 4b99169854 Added information about debugging 2017-03-27 10:43:49 +02:00
Martin Paljak 111ba6f555 Add the final NUL to the CN used for token label
Closes https://github.com/OpenSC/OpenSC/pull/985
2017-03-21 09:31:39 +01:00
HAMANO Tsukasa 638a69a2ab MD: add and read msroots file 2017-03-20 23:05:09 +01:00
Frank Morgner 45a7ea9737 card-npa: moved to internal card drivers 2017-03-20 21:28:48 +01:00
Frank Morgner 40acedcc21 Added support for PIN commands via escape commands
As defined in BSI TR-03119 to issue SCardTransmit (with Uses
Pseudo-APDU) instead of SCardControl (with FEATURE_VERIFY_PIN_DIRECT).
It allows using a very basic PC/SC reader driver without special support
for PIN verification or modification (such as the default CCID driver on
Windows).

Also gets IFD vendor information via escape commands.

PC/SC's Get Uid command is now only triggered if enable_escape = true;
was set by the user to allow disabling wrapped commands on broken
readers (see https://github.com/OpenSC/OpenSC/issues/810)
2017-03-20 21:28:48 +01:00
Frank Morgner a4f64d9439 Added (external) card driver for German ID card
(Imported libcardnpa from https://github.com/frankmorgner/vsmartcard)

- Added generic SM implementation of ISO/IEC 7816-8
- Added implementation of extended access control as defined by
  - BSI TR-03110
  - ICAO Doc 9303
  - ISO/IEC 7501
- Added tool for German ID card (and other EAC tokens)
- renamed folder libsm to sm
2017-03-20 21:28:48 +01:00
Jakuje dae323ea50 License clarification (#988)
* License clarification: Olaf Kirch

> Please refresh my memory; what is the license of the other files in
> pkcs15init and the pkcs11 code that I authored? Any files missing
> license information should use the same.

https://sourceforge.net/p/opensc/mailman/message/35704660/

* License clarificaiton: Vincent Le Toux

> Do whatever you want with it ;-)
https://sourceforge.net/p/opensc/mailman/message/35704731/

* License clarification: Ludovic Rousseau

> So the license should be the same as for pcsc-lite i.e. 3-clause BSD
> license as in, the original,
> https://github.com/LudovicRousseau/PCSC/blob/master/src/PCSC/winscard.h

> I added a license in the strlcpycat.h file for pcsc-lite. See
> https://github.com/LudovicRousseau/PCSC/blob/master/src/strlcpycat.h

https://sourceforge.net/p/opensc/mailman/message/35705399/
2017-03-14 22:47:13 +01:00
Frank Morgner 0bbead5a07 correctly include pthread flags
fixes warning about unused linker flag in clang
2017-03-14 22:44:19 +01:00
Feitian Technologies 45e1732bb5 card-epass2003: Fixed plaintext communication and ATR mask (#967)
The old code only support encrypted communication for ePass2003 USB PKI
Token, now add plaintext communication support, the code now can using
ePass2003 USB PKI Token and ePass2003 PKI applet with java card.

The last mask code has issue, cannot show the OEM ID and SN, not modify
it. the rule made by Feitian only.
2017-03-06 12:40:00 +01:00
Frank Morgner 6850ec7e77 travis: synchronize coverity_scan with master
... allows executing a cron job on coverity_scan for analysis
2017-03-03 14:56:06 +01:00
Frank Morgner 32dd37f391 travis: always kill services.exe
hopefully fixes build issues on coverity branch
2017-03-03 11:05:05 +01:00
HAMANO Tsukasa 51ba288bec md: integrate JPKI (#964)
* set pin_flags
* set dummy serial number
* add CA certificates
* set cert flags
2017-03-03 10:59:56 +01:00
Raul Metsma 890d97816e Use $(xcrun --sdk macosx --show-sdk-path) to parse SDK_PATH
Signed-off-by: Raul Metsma <raul@metsma.ee>
2017-03-03 09:11:08 +01:00
Martin Paljak 1226462f34 pkcs11-tool: show the PIN lengths from token info 2017-03-03 09:08:52 +01:00
Frank Morgner aa0592f025 travis-ci: fixed mingw cross compile build
fixes #906
2017-03-02 23:30:10 +01:00
Jakuje 777e2a3751 adding a CAC support into OpenSC (#841)
* Includes adding support for parsing extensions from a certificate.
* Move lebytes2ushort() to related functions in internals.h
* Adds Simple TLV related functions
2017-02-27 11:05:12 +01:00
Frank Morgner e8b5dcfaa6 macOS: Simplyfy installer
- integrated readme into welcome screen
- removed explicit user consent to LGPL in accordance to
  https://www.gnu.org/licenses/old-licenses/gpl-2.0-faq.html#ClickThrough
2017-02-20 21:37:44 +01:00
Frank Morgner 25f785e482 macOS: Use a better Uninstaller
An apple script converted to an App calls the local
/usr/local/bin/opensc-uninstall
2017-02-20 21:37:44 +01:00
konstantinpersidskiy a0870826a2 card-rtecp: Fix rtecp_change_reference_data (#958)
* card-rtecp: Fix rtecp_change_reference_data (resolves #931)

* Replace filthy comment, move assert

* card-rtecp: Fix rtecp_change_reference_data (resolves #931)
2017-02-20 21:36:55 +01:00
Doug Engert 2a68395d22 Pkcs11-tool.c -t fails to for RSA-X-509 verification
The test_signature routine reuses data array and fails to reset data[0] = 0
when creating a PKCS hash to be pased to OpenSSL.

 Date:	     Mon Feb 13 11:48:00 2017 -0600

 On branch pkcs11-tool-pkcs
 Changes to be committed:
	modified:   tools/pkcs11-tool.c
2017-02-13 20:50:30 +01:00
Nuno Goncalves f1f96a6b40 pkcs15-tool: cast size_t to unsigned long (fix #965) (#966)
Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-02-12 22:47:11 +01:00