Commit Graph

81 Commits

Author SHA1 Message Date
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
vtarasov 0bf12aa1f4 card-piv: avoid warning 'differs in levels of indirection from' ...
when compiling with VS


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4908 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-06 08:30:00 +00:00
dengert c2fe4609a9 Modifications to support EC and ECDSA for
emulated cards. True PKCS#15 cards with EC 
will need additional changes. 

Main changes are in framework-pkcs15.c, mechanism.c,
padding.c, pkcs15-algo.c and pkcs15-sec.c 
where switch statements for key type, and testing
of flags was modified to make it easier to add 
additional key types in the future. 

The code was tested using RSA and ECDSA using a PIV card 
from pkcs11-tool, OpenSSL and Thunderbird with 
modifications to NSS-3.12.7 to get ECDSA to sign e-mail. 

Only named curves are supported for ECDSA, ECDH is still 
needed. pkcs11-tool has only minimal changes need to work 
with the -O option to list EC keys. 

One additional line was added to pkcs15-sec.c which 
should get GOSTR sign to work. 

libp11 and engine do not yet have EC support. 

 --This line, and those below, will be ignored--

M    src/tools/piv-tool.c
M    src/tools/pkcs11-tool.c
M    src/pkcs11/framework-pkcs15.c
M    src/pkcs11/mechanism.c
M    src/pkcs11/pkcs11-object.c
M    src/libopensc/pkcs15-prkey.c
M    src/libopensc/card-piv.c
M    src/libopensc/padding.c
M    src/libopensc/cardctl.h
M    src/libopensc/pkcs15-algo.c
M    src/libopensc/libopensc.exports
M    src/libopensc/pkcs15-piv.c
M    src/libopensc/pkcs15-sec.c


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4904 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-01 20:08:42 +00:00
dengert a569bf9646 Fix test code so will work with card with real history object.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4807 c6295689-39f2-0310-b995-f0e70906c6a9
2010-10-14 19:55:57 +00:00
dengert 0f2a44b33e sc_pkcs15_pubkey_from_cert now uses parse_x509_cert without OpenSSL.
sc_pkcs15_cert now has pointer to sc_pkcs15_pubkey, allowing it to 
be removed and used separatly.  
sc_pkcs15_pubkey now has pointer to sc_algorithm_id to faclitate
addition of other key algorithms and their parameters. 
Various code changes to free these structures and references
to the structures have been changed. 



git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4805 c6295689-39f2-0310-b995-f0e70906c6a9
2010-10-12 15:26:45 +00:00
dengert e9d1f10084 PIV support for NIST 800-73-3 objects,
PIV driver client can build and run without OpenSSL,
(admin functions and piv-tool still need OpenSSL)
define PIV specific ctrl codes and structures.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4767 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-24 20:37:22 +00:00