Commit Graph

86 Commits

Author SHA1 Message Date
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
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
Doug Engert 5fb4db6373 Use OpenSSL versions OpenSSL-0.9.7 to 1.1.0a for OpenSC
OpenSSL-1.1.0 was released 8/25/2016
OpenSSL-1.1.0a was released 9/22/2016

  https://www.openssl.org/news/openssl-1.1.0-notes.html

Changes to allow the OpenSC code base to work with OpenSSL versions from
0.9.7 to 1.1.0 with few changes.

This is an update and rebased version of my prep-openssl-1.1.0-pre6 branch.

No attempt was made to back port any OpenSSL features. These changes
just allow an updated OpenSC code base to use what is in the various OpenSSL
releases.

A new header libopensc/sc-ossl-compat.h contains extra defines
to reduce the need for so many #if OPENSSL_VERSION_NUMBER statements
in the source code.

The OpenSC source can now use the OpenSSL 1.1 API. The libopensc/sc-ossl-compat.h
has defines for the new API for use with older versions of OpenSSL.

sc-ossl-compat.h is included by libopensc/internal.h so all OpenSC
library routines can take advantage of it. For the tools, which do not use
libopensc/internal.h, libopensc/sc-ossl-compat.h is included by the tools.

The OpenSC source has been modified to use OpenSSL functions to access
hidden structures, such X509, BIGNUM, EVP_CIPHER_CTX, and use XXX_new
functions to allocate structures which must use pointer such as
BIGNUM and EVP_CIPHER_CTX.

For backward compatability sc-ossl-compat.h now defines inline routines
to emulate the RSA and DSA  access routines in OpenSSL-1.1.0. Thus
the same OpenSC source code can be used with openSSL versions from
0.9.7 to 1.1.0.

Inline routines were chosen, because using macros does not work on all platforms.
Having OpenSC versions of these routines in libopensc would be a posibility,
but they are only used for older version of OpenSSL, and could be removed in
the future.
 Changes to be committed:
	modified:   src/libopensc/card-entersafe.c
	modified:   src/libopensc/card-epass2003.c
	modified:   src/libopensc/card-gids.c
	modified:   src/libopensc/card-gpk.c
	modified:   src/libopensc/card-oberthur.c
	modified:   src/libopensc/card-piv.c
	modified:   src/libopensc/card-westcos.c
	modified:   src/libopensc/cwa-dnie.c
	modified:   src/libopensc/cwa14890.c
	modified:   src/libopensc/internal.h
	modified:   src/libopensc/p15card-helper.c
	modified:   src/libopensc/pkcs15-itacns.c
	modified:   src/libopensc/pkcs15-prkey.c
	modified:   src/libopensc/pkcs15-pubkey.c
	new file:   src/libopensc/sc-ossl-compat.h
	modified:   src/pkcs11/openssl.c
	modified:   src/pkcs15init/pkcs15-lib.c
	modified:   src/pkcs15init/pkcs15-oberthur-awp.c
	modified:   src/pkcs15init/pkcs15-oberthur.c
	modified:   src/pkcs15init/pkcs15-oberthur.h
	modified:   src/pkcs15init/pkcs15-westcos.c
	modified:   src/tools/cryptoflex-tool.c
	modified:   src/tools/gids-tool.c
	modified:   src/tools/netkey-tool.c
	modified:   src/tools/piv-tool.c
	modified:   src/tools/pkcs11-tool.c
	modified:   src/tools/pkcs15-init.c
	modified:   src/tools/sc-hsm-tool.c
	modified:   src/tools/westcos-tool.c
2016-10-08 06:15:06 -05:00
Doug Engert bb2d863e4f piv: add a piv_card_reader_lock_obtained function
When sc_lock obtains a reader lock  this function is called
If the card was reset the PIV AID is seletcted and logged_in is reset.
This is need for some PIV cards where the default AID is not the PIV AID
and some other process has reset the card.

closes #842
2016-08-15 13:34:50 +02:00
Viktor Tarasov eb21c41e53 piv: coding style, use short log calls 2016-07-24 20:40:58 +02:00
Doug Engert 9c7f67309f piv: logout place holder
Until a full logout function can be implemented, return SC_ERROR_NOT_SUPPORTED

closes #832
2016-07-24 20:40:44 +02:00
Viktor Tarasov cee092a930 piv: change driver's short name to 'PIV-II'
closes #828
2016-07-19 15:27:26 +02:00
Doug Engert edf24d0e2e PIV and PIV-Want-To-Be Issues
Not all PIV cards follow the  NIST 800-73-3 standard. This commit is designed to address some
of the issues.  OpenSC developers don't have access to all the different versions of devices
or access to release notes for the devices to see when a bug was introduced and when it is fixed.

To make OpenSC code changes easier,  the code is divided into four sections:

(1) Identify the card/token as best possible by looking at the "Historical bytes" in the ATR.
For the Yubico devices read their version number and log it via sc_debug.

(2) Define the card_issues  CI_* defines in card-piv.c. There are 8 of them at the moment.
See below.

(3) based on the card->type and possibly Yubico version set the priv->card_issues flags that
apply to  current card or device.

(4) Implement in the code changes needed for each issue.

Other issues can be added. As more info is obtained (3) can be updated using the version
number as needed.

The card issues are:

CI_VERIFY_630X - VERIFY "tries left" returns 630X rather then 63CX

CI_VERIFY_LC0_FAIL - VERIFY Lc=0 never returns 90 00 if PIN not needed. Will also test after
first PIN verify if protected object can be used instead

CI_CANT_USE_GETDATA_FOR_STATE - No object to test verification in place of VERIFY Lc=0

CI_LEAKS_FILE_NOT_FOUND - GET DATA of empty object returns 6A 82 even if PIN not verified

CI_OTHER_AID_LOSE_STATE - Other drivers match routines may reset our security state and lose AID

CI_NFC_EXPOSE_TOO_MUCH - PIN, crypto and objects exposed over NFS in violation of 800-73-3

CI_NO_RSA2048 - does not have RSA 2048

CI_NO_EC384 - does not have EC 384

The piv_card_match and piv_init interactions were cleaned up.

 Changes to be committed:
	modified:   card-piv.c
	modified:   cards.h
2016-07-19 15:17:28 +02:00
Frank Morgner 9f0087d968 fixed missing includes 2015-10-30 18:21:40 +01:00
Doug Engert 65bc754b8b Do not expose access to PIV emulated files from utilities
PIV cards uses get/put data not select file and read_binary.
To allow access via pkcs15 emulation card-piv.c emulates
select_file and read_binary but only when used with the path as
created by the piv emulation.

There are no MF.DIR or ED.DIR files.
opensc-tool and opensc-explorer will not work with this emulation.

Patch removes code that caused problems with opensc-tooland opensc-explorer.
2015-10-14 15:27:58 -05:00
Doug Engert 0b268f789a Allow PIV driver to use cards where default application in not PIV
card-piv.c was not selecting the PIV AID correctly from piv_find_aid.
This cause a CAC card that also has the PIV application to fail a VERIFY command
of the pin would use a VERIFY  APDU P2 where P2 for PIV is 80, but for CAC was 00.

A CAC card could work if the caller requested the serial number of the card
which did call piv_select_aid. All the OpenSC tools, minidriver and
PKCS#11 do this, but Tokend does not.

This is a partial fix for https://github.com/OpenSC/OpenSC/issues/570.
Tokend in later MacOS versions still has other issues.

A  more complete solution is needed for cards with multiple applications.

I do not have a CAC card or MAC to do any testing.

Thanks to https://github.com/mouse07410 who has a CAC card, and a Mac,
and has tested this fix.
2015-10-11 19:14:02 -05: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
Doug Engert 24a3999386 Fix indentation for readability 2015-09-17 19:03:44 -05:00
Frank Morgner be073396be Fixes warnings about unused variables/functions 2015-09-17 22:24:33 +02:00
Frank Morgner 59254d9d88 Checks on errors for ftell and fseek 2015-09-17 22:24:33 +02:00
Nicholas Wilson 2897e6fb5c Leniently interpret the ISO7816 return codes in card-piv.c
This adds support for the Yubikey NEO. I'm not sure whether it breaks
the specification, or follows some other version of the spec, but in my
testing it returns SW1=0x63, SW2=0x0N for N PIN tries remaining.
Ignoring the top nibble seems a harmless change to the behaviour to
support this device.
2015-08-25 15:53:32 +01:00
Doug Engert c7af08c68a PIV - read just length of object to get size
card-piv.c tries to read the first 8 bytes of an object to get object size
so it can allocate a buffer. It then reads the whole object. apdu.c has changed
over the years, and apdu.c will keep reading as long as the card returns
status of 61 XX  thus apdu.c will read the whole object while discarding
the extra data and returning to the caller only the first part of the data.
This in effect causes a double read of objects.

This patch sets SC_APDU_FLAGS_NO_GET_RESP to tell apdu to stop doing the
extra get-response commands thus avoiding most of the extra overhead.

This in not an optimal patch as it only works with T=1 cards/readers
but the patch is confined to just card-piv.c.
A better patch is in the works.

Fixes #462
2015-05-13 09:24:46 +02:00
Viktor Tarasov 3e0356b170 register CKM_ECDSA and CKM_ECDSA_SHA1 depending on card capabilities
fix #429
2015-05-08 20:45:56 +02:00
Philip Wendland 4142456c74 PIV, sc-hsm, myeid: register ECDH card capabilites
Prior to 066132327c71300188aa66180fde2fb3d90c5140, CKM_ECDH1_DERIVE and
CKM_ECDH1_COFACTOR_DERIVE were always registered for cards that support
SC_ALGORITHM_ECDSA_RAW.
The mentioned commit changed this behavior, so that the ECDH mechanisms
are only registered for cards that set the SC_ALGORITHM_ECDH_CDH_RAW
capability flag.
To keep the existing behavior for the cards, they need to set this flag
in the card driver.
2015-05-08 20:45:37 +02:00
Frank Morgner bcb5fc15e5 honour HAVE_CONFIG_H 2015-04-22 23:55:33 +02:00
Viktor Tarasov fa923831f8 introduce EC curve OID into algorithm info data
needed to store information about EC curve supported by card.
Primary usage is when importing/generating key to get know if particular curve is supported by card.
2015-02-20 13:49:18 +01:00
Doug Engert d7475c8180 Add brackets in card-piv.c 2015-02-16 10:43:19 -06:00
Doug Engert 981a0fbbaf Fix-up changes caused by Coverity scan
piv-tool.c add  /* fall through */ to avoif false warning
card-piv.c - clean up if sc_lock fails.
2015-02-11 13:39:59 -06:00
Frank Morgner 6759c04b26 don't ignore errors 2015-01-28 04:45:08 +01:00
Frank Morgner 2e04fa99c1 fixed pointless array comparisons 2015-01-28 07:39:35 +01:00
Doug Engert 4dbfba3102 Use correct bit when writing PIV certificate object with gzipped certificate
NIST 800-73 clarified the CertInfo flag for gzipped certificate is 0x01
piv-tool was writting 0x80.
OpenSC card-piv.c continues to accept both.
2014-11-07 19:49:36 -06:00
Doug Engert cb89a870ae Merge pull request #280 from shootingatshadow/aes-support
Remove hardcodes from Mutual Authenticate
2014-09-18 16:32:21 -05:00
Frank Morgner 5d6c4b391d Merge pull request #253 from github-frankmorgner/remove-deadcode
card-asepcos: removed dead code
card-authentic: removed dead code
card-belpic: removed dead code
card-epass2003: removed dead code
card-flex: removed dead code
card-gpk: removed dead code
card-oberthur: removed dead code
card-piv: removed dead code
card-setcos: removed dead code
ctbcs: removed dead code
cwa14890: removed dead code
muscle: removed dead code
pkcs15-atrust-acos: removed dead code
pkcs15-gemsafeV1: removed dead code
pkcs15-skey: removed dead code
reader-ctapi: removed dead code
framework-pkcs15: removed dead code
pkcs11-object: removed dead code
pkcs15-asepcos: removed dead code
pkcs15-cardos: removed dead code
pkcs15-jcop: removed dead code
pkcs15-lib: removed dead code
pkcs15-oberthur: removed dead code
parse: removed dead code
sclex: removed dead code
sm-card-authentic: removed dead code
sm-card-iasecc: removed dead code
sm-cwa14890: removed dead code
sm-global-platform: removed dead code
sc-test: removed dead code
pkcs11-tool: removed dead code
pkcs15-tool: removed dead code
2014-09-07 21:22:43 +02:00
William Roberts 3a0ca5aa7d Remove hardcodes from Mutual Authenticate
Support nonces that are not only 8 bytes in
Mutual Authenticate. Use the witness length
to determine the nonce size, thus existing
systems using 8 bytes will continue to use 8
bytes. However, with AES 256, the nonces could
be a single block size of 16 bytes or greater.
2014-09-03 10:53:30 -07:00
William Roberts 295c523e4e Add AES support for PIV General Authenticate
This adds algorithm IDs 0xA, 0xA, 0xC which as documented
by the NIST PIV specification is algorithms AES-128, AES-192
and AES-256 respectively.

This patch also addresses some of the hardcodes that prevented
nonces greater than the single byte TLV length tags would allow.
It was explicitly tested with AES-256 and 256 byte nonces.

Signed-off-by: William Roberts <w2.roberts@samsung.com>
2014-08-25 18:27:13 -07: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
Viktor Tarasov 12d362fc73 PIV: fix segfault and valgrind issue
prototype of 'get-guid' has been changed;

valgrind issue:
Conditional jump or move depends on uninitialised value(s)
   at 0x5A0159B: vfprintf (vfprintf.c:1629)
   by 0x5AC04BF: __vsnprintf_chk (vsnprintf_chk.c:65)
   by 0x522A665: sc_do_log_va.part.0 (stdio2.h:78)
   by 0x522A819: sc_do_log (log.c:52)
   by 0x529462F: piv_card_ctl (card-piv.c:1794)
   by 0x5232E2F: sc_card_ctl (card.c:772)
   by 0x52E561D: sc_pkcs15emu_piv_init (pkcs15-piv.c:626)
2014-02-09 18:49:58 +01:00
Viktor Tarasov f7b5a6b6af PIV: pickup card driver from the SM branch
... where it was tested by Douglas.
2012-05-30 19:40:05 +02:00
ludovic.rousseau 38e420bec3 Fix compiler warning
card-piv.c: In function 'piv_write_binary':
card-piv.c:1364: warning: signed and unsigned type in conditional expression

count is a size_t and must be casted in an int since the fucntion
returns an int.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5461 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-22 10:10:21 +00:00
vtarasov 28ccae7918 card-piv: store serial number into the 'serialnr' member of sc_card structure ...
... when serial number was asked for the first time.
Then return the stored value for the every next request of serial number.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5348 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-16 17:35:56 +00:00
vtarasov 5102e4d882 card-piv: 'emulate' MF selection by selection of the PIV applet ...
so that, PIV card can be used with the 'opensc-explorer' interactive tool


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5317 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-10 08:47:35 +00:00
vtarasov 86af8eed3d card-pin: make working 'external authenticate' ...
'key-ref' and 'algo' arguments of the piv_general_external_authenticate() function 
were not used


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5315 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-09 19:26:34 +00:00
vtarasov 004c08b6a0 card-piv: invalid arguments for SC_TEST_RET macro
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5314 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-08 15:16:47 +00:00
ludovic.rousseau 902e4b139a Fix compiler warning by commenting dead code
card-piv.c:179: warning: 'oid_prime256v1' defined but not used
card-piv.c:180: warning: 'oid_secp384r1' defined but not used


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5260 c6295689-39f2-0310-b995-f0e70906c6a9
2011-03-23 15:53:15 +00:00
ludovic.rousseau 8ef19c4ad2 typo: dont -> don't
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5243 c6295689-39f2-0310-b995-f0e70906c6a9
2011-03-20 14:50:44 +00:00
dengert 432a89c18b Fix malloc warning by using stdlib.h
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5211 c6295689-39f2-0310-b995-f0e70906c6a9
2011-02-18 20:37:50 +00:00
dengert 6ef7366074 void issues with ssize_t See r5135 and r5195
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5207 c6295689-39f2-0310-b995-f0e70906c6a9
2011-02-17 14:50:33 +00:00
vtarasov d953d4ade4 card-piv: 'ssize_t' is not defined when compiling with Visual Studio
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5195 c6295689-39f2-0310-b995-f0e70906c6a9
2011-02-16 10:31:59 +00:00
ludovic.rousseau 9afa56f740 card-piv.c:564: warning: unused variable ‘buf_len’
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5183 c6295689-39f2-0310-b995-f0e70906c6a9
2011-02-05 22:37:51 +00:00
ludovic.rousseau 8f68f4440d Remove dead code
card-piv.c:614:2: warning: Value stored to 'buf_end' is never read
        buf_end = rp + buf_len;
        ^         ~~~~~~~~~~~~
card-piv.c:1129:3: warning: Value stored to 'r' is never read
                r = 0;
                ^   ~
card-piv.c:1478:2: warning: Value stored to 'q' is never read
        q = rbuf;
        ^   ~~~~
card-piv.c:1628:2: warning: Value stored to 'q' is never read
        q = rbuf;
        ^   ~~~~
card-piv.c:2456:4: warning: Value stored to 'certobjlen' is never read
                        certobjlen = 0;
                        ^            ~


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5170 c6295689-39f2-0310-b995-f0e70906c6a9
2011-02-05 21:54:36 +00:00
ludovic.rousseau a8da1aa886 Fix compiler warning
card-piv.c:2014:7: warning: unused variable 'outp' [-Wunused-variable]
        u8 * outp = out;
             ^


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5138 c6295689-39f2-0310-b995-f0e70906c6a9
2011-02-05 17:47:09 +00:00
ludovic.rousseau b3aee43e96 Fix a bug. read(2) returns a signed value. read(2) errors were not detected in
the previous code.

card-piv.c:833:10: warning: comparison of unsigned expression < 0 is always
      false [-Wsign-compare]
        if (len < 0) {
            ~~~ ^ ~


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5135 c6295689-39f2-0310-b995-f0e70906c6a9
2011-02-05 17:34:29 +00:00
martin f694bbf597 libopensc: correctly use HAVE_MALLOC_H to include malloc.h
See http://www.freebsd.org/cgi/cvsweb.cgi/ports/security/opensc/files/patch-src_libopensc_card-piv.c#rev1.1

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4999 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-29 10:45:08 +00:00
martin 4c2cbeec13 card-piv: remove unused variables.
card-piv.c: In function ‘piv_get_data’:
card-piv.c:879: warning: unused variable ‘filename’
card-piv.c:878: warning: unused variable ‘dataenvname’
card-piv.c:877: warning: unused variable ‘keyenvname’

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4917 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-06 14:18:42 +00:00
martin 98d2d6db39 PIV: amend [4908], Apple has /usr/include/malloc/malloc.h
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4916 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-06 14:18:35 +00:00