Commit Graph

137 Commits

Author SHA1 Message Date
Frank Morgner 148bc25238 fixed coverity issues
- CID 145623 (#1 of 1): Resource leak (RESOURCE_LEAK)
- CID 269069 (#1 of 1): Resource leak (RESOURCE_LEAK)
- CID undefined (#1 of 1): Dereference before null check (REVERSE_INULL)
2018-04-07 12:27:12 +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
Frank Morgner ddeb01ddc1 ISO7816: allow nested CP DOs 2018-01-22 15:26:44 +01:00
Frank Morgner 44447b7801 fixed warnings about uninitialized data 2018-01-17 00:28:42 +01:00
Frank Morgner baa709ff74 print ASN.1 time and ASCII tranlation 2017-11-17 10:03:54 +01:00
Frank Morgner 9468ce7f89 beautify printed ASN.1 output
- fixed printing tags on multiple bytes
- align indenting with raw tags
- use OpenSSL's human readable OID database
- only print the canonical names for universal tags
2017-11-17 10:03:54 +01:00
Frank Morgner 3ca6c4b04a fixed possible NULL dereference 2017-11-09 12:42:29 +01: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 93fa520bc9 Cope with incomplete ASN.1 data in sc_asn1_read_tag 2017-07-18 22:35:23 +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
Viktor Tarasov b4cfb14e4c asn1: print in log part of raw data to decode
closes #926
2017-01-01 13:58:48 +01:00
Viktor Tarasov f98c8cd37c asn1: tagnum size has not exceed 3 bytes
3 bytes is the size of SC_ASN1_TAG_MASK used when composing
the asn1 templates with 'struct sc_asn1_entry'.
With this limitation maximal supported ASN.1 tag number is 2^^14-1 .

Fixed 'dead-code' coverity-scan issue.

Close #707
2016-03-10 10:13:27 +01:00
Philip Wendland 328176d28b ECDSA helper functions: strip zeroes when converting from R,S to sequence
For ECDSA signatures, there are multiple ways to format the signature:
- R|S (R and S filled with zeroes at the most significant bytes)
- ASN1 sequence of R,S integers (e.g. used by OpenSSL).

It is rare that the filling with zeroes is needed.
But if it is, in the second case, the filling zeroes should not be there
or the verification of the signature by OpenSSL will fail.
2015-09-20 22:34:39 +02:00
Frank Morgner b44c98e4d8 asn1: fixed parsing "end of content"
fixes #190
2015-07-28 09:10:54 +02:00
Frank Morgner bcb5fc15e5 honour HAVE_CONFIG_H 2015-04-22 23:55:33 +02:00
Viktor Tarasov 2abe135f97 asn1: re-fix error in EC signature encode helper
see comment for 8cf99a9372
2015-03-07 22:40:43 +01:00
Viktor Tarasov 8cf99a9372 asn1: fix error in EC signature encode helper
The raw format of EC signature was invalid when 'r' and 's' had different length.
https://github.com/OpenSC/OpenSC/pull/381#issuecomment-77016382

According to PKCS#11 v2.20:
"If r and s have different octet length, the shorter of both must
be padded with leading zero octets such that both have the same octet length."
2015-03-04 19:43:15 +01:00
Frank Morgner 236e68b17c fixed NULL dereference 2015-02-20 19:54:40 +01:00
Viktor Tarasov 80c496671f helper functions to change format of ECDSA signature 2015-02-20 14:20:19 +01: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
Philip Wendland 7e7a44acff sc_asn1_put_tag - support larger tags
Enhance sc_asn1_put_tag to support larger tag names and larger tags.
Prior to this, sc_asn1_put_tag did only support tags with a length of at most 127 bytes and tag names of one byte.
2014-12-29 15:37:45 +01: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 f641ebd248 fixed errors reported by cppcheck: part 1
partially applied the pull request #182 from Frank Morgner -- updated the common frameworks source files
2013-09-29 20:28:45 +02:00
Viktor Tarasov 58b4304957 libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....

(*)
This bug reported by Andreas Schwier :
8e75d971cb (commitcomment-1792477)

In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-06 10:47:29 +02:00
Viktor Tarasov 0518ced8e0 asn1: export 'asn1-write-element' function
... used by OpenPGP driver
2012-07-29 13:09:00 +02:00
Viktor Tarasov 6337149ef7 pkcs15: decode 'seInfo', 'profileIndication', 'lastUpdate'
Encode,decode  'lastUpdate', 'seInfo', 'profileIndication' of TokenInfo (CIAInfo).
Trailing whitespaces.
2012-05-30 09:03:27 +02:00
vtarasov ce79a61d30 tools: print value of 'BOOLEAN' asn1 type
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5446 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-16 08:32:07 +00:00
vtarasov 8e75d971cb asn1: when encoding the OID, make sure that unused part of input data is properly initialized
it's a supplement to r5355. 


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5429 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-08 07:59:16 +00:00
vtarasov 38103c64cf pkcs15: new function to encode an OID in DER format
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5380 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-21 14:12:03 +00:00
vtarasov 669a10572a asn1: now sc_der_copy() returns int value
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5379 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-21 13:46:28 +00:00
andre 90ffef6dc9 asn1.c: Check boundaries __before__ accessing memory.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5361 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-18 12:29:47 +00:00
vtarasov caf3789439 asn1: in encode-object-id procedure do not stop on zero -- it's a valid value
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5355 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-17 18:39:01 +00:00
andre d3215b67df asn1.c: Avoid warnings:
asn1.c:747: warning: comparison between signed and unsigned
asn1.c:785: warning: comparison between signed and unsigned


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5297 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-06 15:06:02 +00:00
ludovic.rousseau 9906e5af66 Remove dead code
asn1.c:1321:3: warning: Value stored to 'r' is never read
                r = 0;
                ^   ~


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5155 c6295689-39f2-0310-b995-f0e70906c6a9
2011-02-05 21:03:28 +00:00
vtarasov 71bfc87282 asn1: spelling of the debug messages
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5090 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-13 15:06:12 +00:00
vtarasov 66412d6e53 asn1: accept long tag ...
According to X.690-0207 ch.8.1.2.4


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5088 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-13 13:59:22 +00:00
vtarasov fa9ed3add0 asn1: invalid detection of AID presence in ASN1 path data
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5078 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-10 10:44:52 +00:00
vtarasov 40cb9c99b8 asn1: decode 'extendedPath'
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5077 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-09 17:25:09 +00:00
vtarasov 65cd456256 opensc-explorer: print raw content of 'CONTEXT' tag
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5058 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-07 15:47:58 +00:00
vtarasov e600a1e0ac opensc-explorer: in 'asn1' command print raw content of the ASN1_APPLICATION data
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5055 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-07 09:00:39 +00:00
vtarasov 0761a61a65 libopensc: use 'struct sc_aid' instead of 'u8 *aid, size_t aid_len'
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5048 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-05 15:42:36 +00:00
vtarasov 4b5bc9900c libopensc: asn1: allow empty path
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5022 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-02 14:14:24 +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
viktor.tarasov 006c30c2e0 #245: pkcs15 asn1: 'subjectName' in 'commonPrivateKeyAttributes' is optional
thanks to Jean-Michel


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4518 c6295689-39f2-0310-b995-f0e70906c6a9
2010-07-08 08:09:46 +00:00
viktor.tarasov 3a3c41a6db pkcs15: encode/decode 'AccessControlRules' in 'CommonObjectAttributes'
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4515 c6295689-39f2-0310-b995-f0e70906c6a9
2010-07-06 09:09:04 +00:00
viktor.tarasov b78d7630e7 pkcs15: encode/decode 'subjectName' in 'CommonPrivateKeyAttributes'
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4512 c6295689-39f2-0310-b995-f0e70906c6a9
2010-07-05 13:29:10 +00:00
martin 68f12c881d Fix a segfault leftover from r4118
Thanks to Andre Zepezauer for the report and patch.

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4391 c6295689-39f2-0310-b995-f0e70906c6a9
2010-05-31 16:49:55 +00:00
ludovic.rousseau 0c77a52f37 Remove 2 ugly casts and fix warnings
asn1.c: In function ‘asn1_decode_entry’:
asn1.c:979: warning: dereferencing type-punned pointer will break strict-aliasing rules
asn1.c: In function ‘asn1_encode_entry’:
asn1.c:1263: warning: dereferencing type-punned pointer will break strict-aliasing rules


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4207 c6295689-39f2-0310-b995-f0e70906c6a9
2010-04-02 13:12:53 +00:00
viktor.tarasov f75f539a6f libopensc: export 'sc_asn1_encode_object_id'
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4142 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-22 14:14:51 +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