Commit Graph

56 Commits

Author SHA1 Message Date
Peter Marschall 16c889cf7d spelling fixes
Fix various spelling errors, mostly in comments but also in texts displayed.

Errors found & interactively fixed using 'codespell', with additional manual
checks after the fixes.
2020-08-30 10:35:14 +02:00
Timo Teräs 3f832ca6da MyEID: implement support for 4K RSA keys (MyEID 4.5+)
MyEID starting version 4.5 supports 4K RSA keys. The card also
now supports proper APDU chainging (for sending large APDUs) and
receiving large responses via GET_RESPONSE splitting.

This updates the following:
* detection code properly announces 3K and 4K RSA support
  when available
* APDU chaining is used when possible
* use ISO GET_RESPONSE handling for large responses
* max_recv_size is set to 256 which it always was supposed to be
  as the old cards respond with that large responses too
* use the 2K signing kludge only on cards that need it
* unwrap and decipher code paths unified to the extent possible

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
2019-04-25 14:53:10 +02:00
Frank Morgner 85485eb9b0 fixed unused assignments 2019-02-14 09:22:23 +01:00
Hannu Honkanen 7f91b6e07f MyEID: add AES algorithms to tokenInfo as supported during init. It is better to do it already in init, because adding them in C_UnwrapKey operations would require SO-PIN which is inconvenient.
pkcs15: added function to get a specific supported algorithm, checking also OID.
This is needed because for AES there are different OIDs for each key length.
2018-11-20 11:52:54 +01:00
Hannu Honkanen f74150b53d Proprietary attribute bits in FCP had to be adjusted due to conflicts with existing attributes. The needed changes were made to both card and OpenSC code. 2018-10-31 10:27:03 +02:00
Hannu Honkanen 2487bc18d1 When creating symmetric keys, use CKK_ definitions (key type) rather than CKM_ definitions (mechanism) to specify the key type. 2018-10-31 10:24:19 +02:00
Hannu Honkanen 9d6ac01c27 pkcs15init: Handle user_consent and set new proprietary information flags in myeid_create_key(). 2018-10-31 10:24:19 +02:00
Jakub Jelen bce43e6855 Remove dead code 2018-10-01 23:07:34 +02:00
Jakub Jelen b8133c2545 pkcs15-myeid: Return value checking 2018-10-01 23:07:34 +02:00
Jakub Jelen 8e0078a6f9 pkcs15-myeid: Do not confuse coverity with potential double-free 2018-10-01 23:07:34 +02:00
Frank Morgner 45ad44e311 fixed handling SC_ASN1_TAG_EOC from sc_asn1_read_tag
We can't check for `tag == SC_ASN1_TAG_EOC` directly, because this
would also be true for a tag of 0x80 (with `class ==
SC_ASN1_CLASS_CONSTRUCTED`). So what we do is we check for the output
buffer to be NULL!

fixes https://github.com/OpenSC/OpenSC/issues/1273
2018-03-30 08:28:51 +02:00
Timo Teräs 023216c755 add algorithm references for AES keys 2017-06-13 10:40:36 +02:00
Timo Teräs 94973809c2 Support SKDF and secret key upload for MyEID cards 2017-06-13 10:40:36 +02:00
Hannu Honkanen 8cf68bce1a Improved creation of key files so that the correct security attributes are set and keys can be created under specific PINs. Previously keys were always created under PIN 1. Changed description of myeid_create_key function. 2017-04-19 10:57:54 +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
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
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
Hannu Honkanen 6cd28cfc7c myeid: fix to ECDH implementation
fixing #756
rebased by VTA
2016-08-13 20:50:01 +02:00
Hannu Honkanen 2de41f4a6d Added support for 521 bit ECC keys
Includes ECC related bux fixes.
2016-03-04 17:20:20 +01:00
Frank Morgner e7316b60e3 pkcs15-myeid.c: fixed potential resource leak 2015-10-30 12:15:06 +01:00
Viktor Tarasov ac84d282b1 myeid: fixed resource leak
pkcs15-myeid: fix memory leakage
myeid: fix memory leakage
2015-05-08 09:11:40 +02:00
Frank Morgner c8a7c8bc7a fixed typo 2015-04-21 01:04:18 +02:00
Hannu Honkanen 2fffbce65c myeid: update EC support for MyEID-v4 card 2015-03-14 17:47:44 +01:00
Viktor Tarasov 08eb700b97 revert or partially revert some of recent commits
b94c163 - invalid, non-tested
11881a6 -- src/libopensc/card-iasecc.c -- return from select has to be ignored,
3a92bf7 -- src/pkcs11/slot.c -- SEGFAULT issue #373
3a92bf7 -- src/tools/piv-tool.c -- confirmed by author
6759c04 -- src/pkcs15init/pkcs15-lib.c -- file instantiation error has to be ignored
2015-02-07 19:31:17 +01:00
Frank Morgner 11881a61b8 removed/fixed dead code 2015-02-05 01:38:41 +01:00
Frank Morgner b1b99ce7e5 fixed integer underflow 2015-01-28 06:03:52 +01:00
Frank Morgner 7a34c204c1 fixed dereference before null check
silence warnings reported by coverity-scan
2015-01-22 20:29:33 +01:00
Viktor Tarasov efa6e852c2 myeid: support of EC key is broken,
waiting for specification and card from Aventra (VTA)
2014-02-09 18:49:58 +01:00
Viktor Tarasov 0efe1ec05e coding style: remove trailing spaces 2014-01-19 19:19:17 +01:00
Doug Engert 03c196eeaf ECC ecpointQ Fixes
The original ECC code in OpenSC stored the ecpointQ as a DER encoded OCTET STRING.
Shortly before 0.13.0, code changes where made to store the ecpointQ as raw data
without the DER encoding.

Only some of the code was changed to support this but not all, and the comments
that said the ecpointQ was in DER where not changed either.

Some card drivers continued to work, using the original code in all place,
while some cards failed, as they where using a mixture of original code and
0.13.0 code.

This commit fixes these problems.

The ecpointQ is stored in raw format

A new structure type sc_pkcs15_u8 is defined.

The ecpointQ are changed to use the struct sc_pkcs15_u8. This was done to avoid
 the confusion of using struct sc_pkcs15_der to hold non-DER encoded data.
(There may be other uses for this too...)

Comments are change is many places.

sc_pkcs15_decode_pubkey_ec was fixed to store the raw ecpointQ correctly.

sc_pkcs15_pubkey_from_spki was change to get the sc_ec_params from the alg_id
and fix up u.ec.params. Unfortunately the OpenSC code has two places EC parameters
are stored. They can get out of sync, or there may still be code
that looks in the wrng oplace. o(TODO get it to only only place.)

The u.ec.params.field_length is now set in a number of places, as this is need
in many of the PKCS#11 routines.

framework-pkcs15.c will now correctly return the DER encode ecpointQ,
for the CKA_EC_POINT attribute using pubkey->data which has the DER encoding
for the ecpointQ.

framework-pkcs15.c will look for the EC parameters in either the u.ec.params.der,
or in the alg_id->params. (TODO get it to only only place.)

pkcs15-myeid.c has some comments, as it looks like the code is storing a TLV
rather then a DER encoding of the ecpointQ. With the wrong encoding PKCS#11 will
return the wrong attribute for CKA_ECDSA_PARAMS.

pkcs15-piv.c is changed so emulation of a pubkey taken from a certificate will
work correctly.
2013-11-06 16:31:34 -06:00
sjoblomt 457426543d MyEID ECDSA support 2012-12-03 14:37:13 +01:00
Viktor Tarasov 16b4cb6a3f MyEID: always select in mode 'return FCI template'
According to ch.4.2 of MyEID reference manual v1.7.6 the only possible value of P2 of 'SELECT' APDU is '00'.
For this reason, when caller do not request to return 'sc_file' data,
use the non-null dummy 'sc_file' pointer in the call of iso->select_file,
and thus avoid the P2 different from '00'.

Also log calls are replaced by its short forms,
and resolved the 'trailing spaces' issues.
2012-08-14 15:52:39 +02:00
Viktor Tarasov e57d443e86 pkcd15init: remove trailing whitespaces
inspired by
http://www.opensc-project.org/pipermail/opensc-devel/2012-March/017883.html

Change-Id: I817f903e67965942d9cc0c30931dbaea0c5f736e
2012-04-02 23:40:05 +02:00
vtarasov d888b3fd55 pkcs15: use general 'AuthenticationObject' instead of 'PinObject'
now the attributes of the previous 'pin-info' data type are included
as the sub-type attributes of the general 'auth-info' data .
It will allow to include support of the 'biometricTemplate' and 'authKey' authentication types.

http://www.opensc-project.org/pipermail/opensc-devel/2011-May/016655.html


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5550 c6295689-39f2-0310-b995-f0e70906c6a9
2011-06-05 15:46:25 +00:00
vtarasov d673e5f109 pkcs15init myEID: in profile increase size of xDF files, also ...
during initialization add the all xxDF to the ODF


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5344 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-15 17:11:38 +00:00
vtarasov 614e9fa566 pkcs15init: sipmlify the 'delete-object' callaback prototype ...
now it takes 'sc_pkcs15_object' argument instead of two arguments - object's type and object's data.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5343 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-15 16:50:04 +00:00
vtarasov ce116f42b6 pkcs15init: for MyEID card set tokenInfo flags ...
it's a part of demand of the card driver's maintainer
http://www.opensc-project.org/pipermail/opensc-devel/2011-February/015994.html


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5196 c6295689-39f2-0310-b995-f0e70906c6a9
2011-02-16 10:46:06 +00:00
ludovic.rousseau 041a1449f5 Remove dead code
pkcs15-myeid.c:251:4: warning: Value stored to 'type' is never read
          type = SC_PKCS15INIT_USER_PIN;
          ^      ~~~~~~~~~~~~~~~~~~~~~~
pkcs15-myeid.c:244:4: warning: Value stored to 'type' is never read
          type = SC_PKCS15INIT_SO_PIN;
          ^      ~~~~~~~~~~~~~~~~~~~~


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5148 c6295689-39f2-0310-b995-f0e70906c6a9
2011-02-05 20:50:00 +00:00
vtarasov 8e81e3912b MyEID: pkcs15init: create all xDF files at the stage of the card initialisation ...
it was discussed in 
http://www.opensc-project.org/pipermail/opensc-devel/2011-January/015620.html


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5115 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-19 14:47:54 +00:00
vtarasov 891f98363b pkcs15init: new 'emulation-store-data' operation ...
the first usage is to update the public key PKCS#15 object attributes 
and to encode it's direct value.
(support of the Oberthur's AuthentIC V3.2 card)


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5001 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-30 12:50:35 +00:00
andre 5c6afb6bed Add missing initializers. Left over from r4508.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4952 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-16 01:47:03 +00:00
viktor.tarasov 517878d102 myeid: applied patch for MyEID card profile
provided by Tony (Aventra development), thanks.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4777 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-27 07:50:14 +00:00
viktor.tarasov ec6bb9859d MyEID: For Aventra card applied Toni's patch, enriched by Andre's proposal
see:
http://www.opensc-project.org/pipermail/opensc-devel/2010-August/014662.html


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4686 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-04 20:46:07 +00:00
ludovic.rousseau f47416d60e Do not cast the return value of malloc(3) and calloc(3)
From http://en.wikipedia.org/wiki/Malloc#Casting_and_type_safety
" Casting and type safety

malloc returns a void pointer (void *), which indicates that it is a
pointer to a region of unknown data type. One may "cast" (see type
conversion) this pointer to a specific type, as in

int *ptr = (int*)malloc(10 * sizeof (int));

When using C, this is considered bad practice; it is redundant under the
C standard. Moreover, putting in a cast may mask failure to include the
header stdlib.h, in which the prototype for malloc is found. In the
absence of a prototype for malloc, the C compiler will assume that
malloc returns an int, and will issue a warning in a context such as the
above, provided the error is not masked by a cast. On certain
architectures and data models (such as LP64 on 64 bit systems, where
long and pointers are 64 bit and int is 32 bit), this error can actually
result in undefined behavior, as the implicitly declared malloc returns
a 32 bit value whereas the actually defined function returns a 64 bit
value. Depending on calling conventions and memory layout, this may
result in stack smashing.

The returned pointer need not be explicitly cast to a more specific
pointer type, since ANSI C defines an implicit conversion between the
void pointer type and other pointers to objects. An explicit cast of
malloc's return value is sometimes performed because malloc originally
returned a char *, but this cast is unnecessary in standard C
code.[4][5] Omitting the cast, however, creates an incompatibility with
C++, which does require it.

The lack of a specific pointer type returned from malloc is type-unsafe
behaviour: malloc allocates based on byte count but not on type. This
distinguishes it from the C++ new operator that returns a pointer whose
type relies on the operand. (see C Type Safety). "

See also
http://www.opensc-project.org/pipermail/opensc-devel/2010-August/014586.html


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4636 c6295689-39f2-0310-b995-f0e70906c6a9
2010-08-18 15:08:51 +00:00
ludovic.rousseau 8822668466 Use size_t instead of int to fix a compiler warning
pkcs15-myeid.c: In function ‘myeid_generate_key’:
pkcs15-myeid.c:687: warning: comparison between signed and unsigned


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4202 c6295689-39f2-0310-b995-f0e70906c6a9
2010-04-02 12:15:12 +00:00
ludovic.rousseau 28a2ed6bd1 Fix
pkcs15-myeid.c: In function ‘myeid_new_file’:
pkcs15-myeid.c:321: warning: assignment discards qualifiers from pointer target type
pkcs15-myeid.c:323: warning: assignment discards qualifiers from pointer target type
pkcs15-myeid.c:325: warning: assignment discards qualifiers from pointer target type
pkcs15-myeid.c:327: warning: assignment discards qualifiers from pointer target type


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4201 c6295689-39f2-0310-b995-f0e70906c6a9
2010-04-02 12:13:41 +00:00
ludovic.rousseau ecae106253 Fix warning: missing initializer
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4156 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-28 11:37:13 +00:00
aj 6545b42c02 cleanup of the debug code:
* reduce to a few, supported functions.
* change all functions to take the debug level as parameter.
* use symbolic names for the debug levels.
* fix tools to pass "verbose"/"opt_debug" as ctx->debug.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4118 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-15 12:17:13 +00:00
aj d22a2483c0 Header file cleanup.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4081 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-04 08:14:36 +00:00
viktor.tarasov 4dd6abf41b pkcs15init: in the prototypes of the internal procedures the 'struct sc_card' argument replaced with the 'struct sc_pkcs15_card' one
This patch is not largely tested and it will be followed (hope in a few hours) with another one 
that will replace the using of the static pincache 
with the pincache as the content of the AUTH pkcs15 object.

In the intervention into the card specific part I tried to respect its creator's coding style.
Sorry, if it's not always the case.




git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4057 c6295689-39f2-0310-b995-f0e70906c6a9
2010-02-21 16:21:57 +00:00