Commit Graph

3128 Commits

Author SHA1 Message Date
Frank Morgner eacb53fc60 added boilerplate for disabling old card driver
currently disabled:
- miocos
- jcop
2017-11-09 12:43:06 +01:00
Frank Morgner 4d5b73d869 fixed accessing garbage value 2017-11-09 12:42:29 +01:00
Frank Morgner 1d03000222 fixed dead assignment 2017-11-09 12:42:29 +01:00
Frank Morgner 9c025280a6 avoid integer underflow 2017-11-09 12:42:29 +01:00
Frank Morgner 3ca6c4b04a fixed possible NULL dereference 2017-11-09 12:42:29 +01:00
Frank Morgner 10101984da fixed dereferencing type-punned pointer 2017-11-09 12:42:29 +01:00
Frank Morgner 3693a96911 win32: don't link static libs into static libs 2017-11-09 12:42:29 +01:00
Frank Morgner 854123c75e fixed binary comparison 2017-11-09 12:42:29 +01:00
Frank Morgner 4251a362b5 fixed potential memory leak 2017-11-09 12:42:29 +01:00
Frank Morgner 1b880b5675 fixed uninitialized buffer 2017-11-09 12:42:29 +01:00
Frank Morgner f4946df4e9 fixed dead assignments 2017-11-09 12:42:29 +01:00
Frank Morgner 251a5f9fef reader-pcsc: use sc_apdu2bytes for PIN APDU 2017-11-09 12:42:29 +01:00
Frank Morgner 04a7075290 fixed compiler warnings 2017-11-09 12:42:29 +01:00
Raul Metsma 189368e49f Fix crash when certificate read failed (#1189)
Fixes https://github.com/OpenSC/OpenSC/issues/1176
2017-11-08 13:24:18 +01:00
Raul Metsma be35d3d026 EstEID ECDSA token support (#1158) 2017-10-27 19:51:33 +02:00
Frank Morgner 594e125f06 Added PKCS#15 emulator for DIN 66291 profile 2017-10-27 19:48:22 +02:00
Frank Morgner bc075d6639 iso7816: don't show error for PIN status on 63C3 2017-10-27 19:48:22 +02:00
Frank Morgner b7b6680f38 starcos: 3.4 supports ISO based PIN status queries 2017-10-27 19:48:22 +02:00
Frank Morgner e54684b9db fixed documentation of GLP encoded PIN 2017-10-27 19:48:22 +02:00
Frank Morgner 4f189a5174 check for digits in case of BCD encoded PIN 2017-10-27 19:48:22 +02:00
Frank Morgner 0502a839c6 unified reading of EF.GDO 2017-10-27 19:48:22 +02:00
Frank Morgner 293d02ea4b removed unused test
test is performed by sc_asn1_read_tag
2017-10-27 19:48:22 +02:00
Frank Morgner 5918e005d7 starcos: added serial number for 3.4 2017-10-27 19:48:22 +02:00
Frank Morgner 498aedd165 Merge remote-tracking branch 'upstream/master' into winui 2017-10-16 15:16:34 +02:00
Feitian Technologies 8d7346406d Add ECC support and solve wrong Length status codes with SM card
Fix #1073
Fix #1115
2017-10-16 14:57:52 +02:00
Maciej S. Szmigiero 0cb654ca78 sc-hsm: fix unused variable warnings in sc_hsm_init()
When building without OpenPACE there are two unused variables in
sc_hsm_init() that cause compiler to emit warnings about them.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-10-16 14:56:01 +02:00
Frank Morgner dfd1838934 fixed building without SM
fixes https://github.com/OpenSC/OpenSC/issues/1155
2017-09-24 22:14:19 +02:00
vletoux 8965ee38dd Gids verified mutual auth 2017-09-17 23:10:28 +02:00
Nathaniel Wesley Filardo 00535f0174 sc_pkcs15_get_bitstring_extension: int, not long long
Use the ASN.1 decoder's SC_ASN1_BIT_FIELD decoder to properly decode
into a machine word.  As _bitstring_extension is used only for the OID
2.5.29.15 by all callers, which is at most 9 bits wide, this is a
reasonable thing to do.
2017-09-12 23:05:27 +02:00
vletoux ab8a51a1ab Fix wrong padding for GIDS admin authentication 2017-09-11 00:25:08 +02:00
Nathaniel Wesley Filardo 5882df745a Use |, not ||, when decoding CAC key_reference
This quiets two compiler warnings and is almost surely what was actually
meant.  However, I do not have a CAC card to test.
2017-09-04 10:58:31 +02:00
Jakub Jelen eeeefecf12 Add newly reported ATR for CardOS 5.3 2017-09-02 00:19:35 +02:00
Jakub Jelen 60dbebf511 Parse the ECC parameters from TokenInfo (CHOICE in AlgorithmInfo)
Fixes #1134
2017-09-02 00:19:35 +02:00
Jakub Jelen eee4964d7f The cardos driver supports also CardOS 5
CardOS M4 is confusing since it refers to the old card versions
2017-09-02 00:19:35 +02:00
Jakub Jelen d018855b9f Get cardholder name from the first certificate 2017-09-02 00:17:15 +02:00
Jakub Jelen 56c8f59b25 Use shorter PIN name for default PIN to accomodate Card Holder name in future 2017-09-02 00:17:15 +02:00
Frank Morgner 555671b54d sc_read_binary may return less bytes than requested
Note, that there are a number of card drivers that still use
`sc_read_binary` in the wrong way. Unfortunately, I don't have the time
to go through all of them.

Fixes https://github.com/OpenSC/OpenSC/issues/1112
2017-08-27 21:21:00 +02:00
Arnaud Fontaine 2765b7b1a0 Support for new MinInt agent card (#1092)
* Support for new MinInt agent card

This card uses the same ATR as the existing card, but the applet installed
does not have the same AID. This card actually works exactly as the
IASECC_SAGEM.

Unify iasecc_init for AMOS/SAGEM and MI cards
2017-08-22 01:13:18 +02:00
Frank Morgner a1466f7395 sc-hsm: better error messages for optional files 2017-08-11 23:07:25 +02:00
Frank Morgner a007ab7820 sc-hsm: New PIN commands for GoID 1.0 2017-08-11 23:07:25 +02:00
Jakub Jelen 0dcf673296 CAC issues (#1120)
* cac: Make the retransmitted APDU valid by restoring the resplen

* cac: Check SWs for all the APDUs and report the errors to underlying layers

* cac: Fallback from CACv1 to CACv2 when CACv1 instruction is not recognized

for the lack of other pointers how to recongnize them

* avoid goto
2017-08-04 08:48:24 +02:00
Frank Morgner 496e2afc9e reader-pcsc: allow no attached reader for notification
Return an error only on OS X, where PnP notification is not supported.
2017-08-02 19:07:16 +02:00
Frank Morgner b2cde0f7fb Windows: Added support for notifications 2017-08-02 19:03:16 +02:00
Frank Morgner cd62c6cdf5 Linux: Added support for notifications 2017-08-02 19:02:21 +02:00
Frank Morgner bf828014e5 macOS: Added support for notifications
- adds framework for user defined message strings
- automatically determine the system's language
2017-08-02 19:02:05 +02:00
HAMANO Tsukasa e25565d851 add public keys 2017-08-02 10:27:06 +02:00
HAMANO Tsukasa da9484bd6b fix trivial leak 2017-08-02 10:27:06 +02:00
HAMANO Tsukasa 977728a5bf jpki: set user_consent flag 2017-08-02 10:27:06 +02:00
Frank Morgner 7a39d6d058 build against OpenSSL 1.1.0 on Windows, by default
- build with AppVeyor's OpenSSL 1.1.0
- updates AppVeyor version of OpenPACE

Fixes https://github.com/OpenSC/OpenSC/issues/1108
2017-07-24 21:39:01 +02:00
Frank Morgner def06389bf sc-hsm: fixed building with --disable-sm
Closes https://github.com/OpenSC/OpenSC/pull/1103
2017-07-19 09:27:24 +02: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
Frank Morgner 93fa520bc9 Cope with incomplete ASN.1 data in sc_asn1_read_tag 2017-07-18 22:35:23 +02:00
Peter Popovec deab9cce73 MyEID support for RAW RSA signature for 2048 bit keys
MyEID does not support RAW RSA signature for 2048 bit key.
(Source:  MyEID reference manual 2.1.4)
This hack uses decipher operation for calculating
RAW 2048 bit signature.
2017-07-18 22:34:41 +02:00
Jakub Jelen e069654f3b [coolkey] Copy labels from certificate objects to the keys 2017-07-18 22:33:17 +02:00
asc 78f15062f8 Fix memory leak #1050 2017-07-18 16:27:56 +02:00
Frank Morgner 805c6b5a30 PIV: workaround for reading public key
closes https://github.com/OpenSC/OpenSC/pull/1069
2017-07-11 10:08:50 +02:00
Jakub Jelen 9d813c075b Simplify differences between CardOS 5 versions and unbreak 5.3 signatures (#1080)
* Simplify CardOS 5.0 support (removing explicit 5.3 marker since the behavior should be the same)

* Restore RSA_PKCS signatures functionality

Closes https://github.com/OpenSC/OpenSC/pull/1079
2017-07-06 22:51:45 +02:00
Peter Popovec a197ba1a99 MyEID - T0 protocol fail for derive operation
apdu.le  must be set minimally to shared key length (pubkey_len / 2),
otherwise sc_get_response() does not read derived shared key from card.
2017-07-06 22:45:49 +02:00
Frank Morgner 4ea2828246 card-piv: Fix Thunderbird and SC_PIN_CMD_GET_INFO
Fixes https://github.com/OpenSC/OpenSC/issues/1071
Closes https://github.com/OpenSC/OpenSC/pull/1072
2017-07-04 10:16:41 +02:00
Jakub Jelen 7e28c1b4e0 [cac] Correctly select APDU CASE to unbreak get_challenge 2017-06-30 22:20:00 +02:00
asc abb45fb9d3 Fix change PIN failure (#1076) 2017-06-24 15:26:04 +02:00
asc 0e8aca8557 Fix maximum CHR length 2017-06-24 15:26:04 +02:00
Frank Morgner 4c654606ea fixed Coverity issues
Fixes https://github.com/OpenSC/OpenSC/issues/1057
2017-06-13 13:07:52 +02:00
Timo Teräs 94973809c2 Support SKDF and secret key upload for MyEID cards 2017-06-13 10:40:36 +02:00
Timo Teräs 3d8cf274ff pkcs15init: add support for secret key upload and generation 2017-06-13 10:40:36 +02:00
Timo Teräs 576e70b70f pkcs15: allow struct sc_pkcs15_prkey to contain secret key
This allows using the existing store_key abstraction to upload
secret keys too.
2017-06-13 10:40:36 +02:00
Timo Teräs 2632b616d9 Imporve SKDF decoding and implement encoding
- fixes decoding of SecretKeyAttributes
- adds support for algorithmReferences
- adds support for algIndependentKeys (PKCS#15 Generic keys)
- implements encoding of SKDF
2017-06-13 10:40:36 +02:00
Timo Teräs becd243fd6 add AES algorithm ID 2017-06-13 10:40:36 +02:00
Timo Teräs 0576ccce0c Add _sc_card_add_generic for registering secret key algorithms 2017-06-13 10:40:36 +02:00
Frank Morgner 32aa51a0f6 avoid logically dead code 2017-06-09 10:33:46 +02:00
Frank Morgner 888215ca7c prevent integer overflow 2017-06-09 10:33:46 +02:00
Frank Morgner 7e5afad630 fixed bad memory access 2017-06-09 10:33:46 +02:00
Frank Morgner 3e5fc896b7 sc-hsm: fixed using GoID with unknown ATR 2017-06-06 00:59:20 +02:00
Frank Morgner 3131282760 sc-hsm: add GoID ATRs
disables forcing sc-hsm for standard JCOP ATRs, see
b7de5888a0 (commitcomment-22258928)
2017-06-06 00:59:20 +02:00
Jakuje 0e70c59aef If the underlying PKCS#15 structure does not provide label for a cert… (#1045) 2017-05-30 00:05:30 +02:00
Frank Morgner b7de5888a0 sc-hsm: fixed forcing a card driver via opensc.conf
- don't use private data on card matching
- instead, return 1 for every known ATR and only select the applet if the ATR is unknown.
- card initialization always selects the applet.

Advantage: decouples memeory management in matching from initializing the card.
Disadvantage: Applet is selected twice in case of an unknown ATR (once for matching and a second time for initializing the card).

Fixes https://github.com/OpenSC/OpenSC/issues/1042
2017-05-22 16:25:08 +02:00
Frank Morgner 7c3bb44cdf minidriver: added support for session pin 2017-05-22 16:25:08 +02:00
Frank Morgner 74ec7b04ff sc-hsm: Add support for SoC
- eac: allow CA without EF.CardSecurity
- sc-hsm: implemented CA based on document PKI
- sc-hsm: adds receive limit for SoC card
- introduces dedicated card type for SoC card
- md: integrate card's PIN pad capabilities
- installer: added SC-HSM SoC card to registry
- pkcs15-tool: Added support for PIN entry on card
- change/unblock PIN: add support for PIN entry on card
- added OpenPACE to macOS build
- travis-ci: install gengetopt/help2man via brew
- sc-hsm: Cache EF.C_DevAut
- sc-hsm: Prevent unnecessary applet selection and state resets
- sc-hsm: added support for session pin
- sc-hsm: avoid multiple AID selection
- sc-hsm: Use the information from match_card for all subsequent selections of the applet
- sc-hsm: cache optional files as empty files (Decoding the files will reveal that they were not existing prior caching. This avoids selecting the file though we have already tried to cache the file before.)
- use dedicated directory for CVC trust anchors
- appveyor: added OpenPACE to windows build
2017-05-22 16:25:08 +02:00
Frank Morgner 7cff9c2810 Force T=1 for contactless cards
Communication defined by ISO/IEC 14443 is identical to T=1, so make
sure we connect in the right mode to the card so that the constructed
APDUs can be handled by the card.
2017-05-19 14:57:56 +02:00
rickyepoderi d9d247e6cd Disable the secure channel at logout (#1048)
Fixes https://github.com/OpenSC/OpenSC/issues/1036
2017-05-13 16:15:08 +02:00
Jakub Jelen 427c175c08 Do not use the hardcoded magic numbers in PIV 2017-05-02 22:27:43 +02:00
Jakub Jelen 20e3836c9e Restore the functionality of CAC usage flags deriving from X509 certificates 2017-05-02 22:27:43 +02:00
Timo Teräs f5aa3f5cc6 build fix for libressl 2.5.3
X509_up_ref is implemented in libressl 2.5.3
2017-04-26 10:59:47 +02:00
Timo Teräs 2114dea687 pkcs15: fix commit 76d59158 auth object regressions
Few conversions of SC_PKCS15_TYPE_AUTH_PIN to SC_PKCS15_TYPE_AUTH
were missed.
2017-04-24 13:14:46 +02:00
Mouse 13f61eee7b Fix CAC-introduced bug that broke access to certificates (@dengert found it) (#1032)
Regression from 777e2a3751
2017-04-22 17:05:08 +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
rickyepoderi 741add2588 Use sc_hex_dump instead of cwa_hexdump. 2017-04-20 11:04:02 +02:00
rickyepoderi ac091b7466 Add dnie_free_apdu_buffers into dnie_sm_free_wrapped_apdu. 2017-04-20 11:04:02 +02:00
Frank Morgner 74f11a32a5 removed obsolete comment 2017-04-20 10:58:54 +02:00
Frank Morgner 9d15326de1 fixed more coverity issues 2017-04-20 10:58:54 +02:00
Frank Morgner fcc8ea5939 reader-pcsc: removed cardmod driver
- pcsc driver takes over all the functionality
- no dedicated reader driver config values for cardmod, use application
  specific blocks to define a different behavior for the pcsc reader if
  needed
- removes legacy code; requiring at least libpcsclite 1.6.5

Fixes https://github.com/OpenSC/OpenSC/issues/892
2017-04-20 10:29:30 +02:00
Hannu Honkanen e6f7373ef0 Added a check to sc_pkcs15_verify_pin to find out if the access condition is already open on card. This check is performed only if this function is called with empty data. This change fixes a problem with pinpad readers, when PIN cache is disabled and prevents unnecessary PIN queries. 2017-04-19 10:57:54 +02:00
Timo Teräs 76d59158fe pkcs15: fix and simplify object type class comparisons 2017-04-13 12:49:13 +02:00
Jakuje 8f33305421 Make CardOS 5.3 working with OpenSC (#1003)
* Set security context for CardOS 5.3 with p1=0x41 (as Coolkey does)

* Do not emulate signatures in CardOS 5.3

Remove the bogus SC_ALGORITHM_NEED_USAGE which prevents using the
actual implementation in cardos_compute_signature().

It might be bogus also in previous version, but I don't have a way
to verify against these cards.

* Do not advertise RSA-X-509 mechanism for CardOS 5.3 (card strips padding)
2017-04-05 09:44:34 +02:00
Frank Morgner e7915ec198 replace assert with error handling 2017-04-04 09:11:35 +02:00
Frank Morgner d757db2ca8 Avoid dnie_transmit_apdu in the dnie driver (#970) (#1013)
closes #975 
closes #972
2017-04-03 18:00:41 +02:00
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 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 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 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 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 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
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
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
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
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
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
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
Nuno Goncalves 4202ea25d0 pteid: order objects by address (supersede #949) (#954)
* pteid: remove OID setting for data objects as they are not defined for this token

Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>

* pteid: order data objects code list by address and rename new objects

The ICAO MRTD specification defines the Security Object Document
abreviation as SOd and not SOD. This is a breaking change since
the labels are case sensitive, but this object was not yet available
on the last stable release.

Trace is also not a acronym or abreviation, so it should be defined with
normal casing. Also a breaking change and also acceptable because it is
unstable code only.

Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-02-09 20:54:06 +01:00
HAMANO Tsukasa 76a524544a login state preservation for JPKI card
also set pin1.logged_in and pin1.tries_left

set correct max_tries
2017-02-06 14:22:14 +01:00
Nuno Goncalves ccc7e2f109 Improve pinpad use detection
Pinpad is used it it is present and if no pin string is provided (pinlen==0).

Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-02-04 22:44:26 +01:00
Nuno Goncalves c6a9201b62 Validate PIN before verification
_validate_pin was not being called at all during a PIN verification.

After this tools report correctly when the PIN length is invalid, even on pkcs11 layer.

Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-02-04 22:44:26 +01:00
rickyepoderi c906c5e375 Use struct sm_cwa_session from sm.h in dnie (#955)
* Use cm_ctx instead of a custom cwa struct. Get rid of sc_reset.


* Use ifd.sn and icc.sn from sm_cwa_session struct too

* Minor typo with sizeof

closes https://github.com/OpenSC/OpenSC/issues/930
2017-02-04 22:32:35 +01:00
Jakub Jelen 92765f612e iso7816: Parse TL using ASN1 parser to avoid (possibly) wrong assumptions about length of both parts 2017-01-28 01:11:54 +01:00
Jakub Jelen 7033510e44 Add ATR to detect CardOS 5.3 2017-01-28 01:11:54 +01:00
Jakub Jelen 6aa52ce753 coolkey: Properly initialize serial length (partially resolves #943) 2017-01-23 13:31:26 +01:00
Jakub Jelen 9fd8a60cfa mcrd: Clean up drv_data in case of failure during initialization (partly resolves #943) 2017-01-23 13:31:26 +01:00
Nuno Goncalves 4b93f447d5 pteid: support iso7816 logged_in
Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-01-13 15:46:05 +01:00
Frank Morgner 81d16fcc27 iso7816: propagate the PIN status on verify/change 2017-01-10 13:00:26 +01:00
Frank Morgner b577e8edbc card-cardos: Support PIN queries for CardOS 5 2017-01-10 13:00:26 +01: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
Jakub Jelen 2c6dadfb44 Fix Coolkey memory management around SimCLists 2017-01-10 12:42:27 +01:00
ricky 42a9df3bd9 Avoid warning because no dnie_match_card 2017-01-08 17:13:13 +01:00
ricky 39f619fbb3 Disable dnie if not defined ENABLE_SM (issue #927) 2017-01-08 17:13:13 +01:00
Jakub Jelen b3f047619d Prevent leaking memory from PIV readers 2017-01-05 16:34:40 +01:00
Viktor Tarasov b4cfb14e4c asn1: print in log part of raw data to decode
closes #926
2017-01-01 13:58:48 +01:00
Hannu Honkanen cd621531be card-dnie: Fix to dnie_ask_user_consent. Undefined flag caused a compilation error. 2017-01-01 13:58:48 +01:00
Hannu Honkanen 7598c822ed myeid: added card capabilities check to ...
... correctly determine which algorithms and key sizes are supported.
2017-01-01 13:58:07 +01:00
Peter Popovec 539c89e581 opensc-explorer: show tag 0x82 for unknown files
For reserved/unknown file type print value of 0x82 tag, instead of "???" string.

closes #918
2016-12-18 12:50:11 +01:00
Frank Morgner e7f118d797 config: added disable_popups for internal UI
closes #916
2016-12-18 12:38:28 +01:00
ricky b97efe1374 cwa-dnie is empty if openssl not defined
closes #914
2016-12-18 12:21:58 +01:00
ricky 06292563bc dnie: force caching of pin if DNIe is version 3.0 2016-12-18 12:21:46 +01:00
ricky e1b4bf4d2c dnie: lost change in the previous pull request ...
... and disable SM mode too.
2016-12-18 12:21:02 +01:00
Viktor Tarasov f0f453781e tools: fix segfault with verbose log into 'stderr'
Issue #824

In Windows, file handles (including 'stderr', 'stdout') can not be shared
between DLL-s, and so, the log handle (File *), defined in one module, cannot
be reused in another.

That is the situation when, for example, the SM is processed
in external, dynamically loadable module as it currently implemented for
IAS/ECC card.

That's for the configuration option 're-open of log file on each message' was
introduced.

This 're-open' logic has not been tested in the particular case of opensc-*
tools used with verbose log into 'stderr' -- in dynamically loaded module the
'stderr' handle, defined in the 'main' module, was not recognized as 'stderr'
and there was an attempt to close it.

closes #910
2016-12-18 11:31:00 +01:00
Jakub Jelen f432caf72c coolkey: Improve return values logging in init_ex() function 2016-11-22 21:21:06 +01:00
Jakub Jelen 365e29caae coolkey: Update to new API, use simplified log functions 2016-11-22 21:21:06 +01:00
Leonardo Brondani Schenkel c7007b0bdc libopensc: allow setting driver via OPENSC_DRIVER environment variable (#882) 2016-11-20 19:38:59 +01:00
ricky 282632f7e6 cwa-14890: little issue in cwa_external_auth
# closes #903
2016-11-20 19:21:03 +01:00
ricky e6dca49169 cwa-14890: force to re-establish the SM when disconnected by another process. 2016-11-20 19:04:29 +01:00