Commit Graph

174 Commits

Author SHA1 Message Date
Frank Morgner 5f9085fedb
Merge pull request #1960 from Jakuje/eddsa
Add support for (X)EdDSA keys in OpenPGP driver
2021-03-22 15:36:59 +01:00
Vincent JARDIN 4119b2c3e7 ASN1 lax bit string decoding
Some ASN1 objects stored on some smartcards (for instance the
IASECC/CPX ones) do not comply strictly with the rules
8.6.2.3 and 8.6.2.3 from the ITU.

Since these rules are not some strict ones, let's have a loose
decoding option that can be displayed by the command:
opensc-explorer
  asn1 7001 # for instance

Fix: issue #2224
2021-03-17 10:58:20 +01:00
Jakub Jelen cb8c7647ca asn1: Do not crash on invalid arguments 2021-03-01 15:43:28 +01:00
Jakub Jelen fb83cd0439 asn1: Improve logging 2020-12-04 09:30:10 +01:00
Doug Engert 52d5370c1e asn1.c don't use strict mode
see:
https://github.com/OpenSC/OpenSC/issues/1995#issuecomment-607490809

 On branch cardos-5.3
 Changes to be committed:
	modified:   asn1.c
2020-05-09 23:59:51 +02:00
Jakub Jelen 4c4237f8a3 tests: Cover asn1_put_tag() 2020-05-07 02:32:46 +02:00
Frank Morgner 723176d62f avoid calling memcpy with length 0 2020-02-04 13:56:53 +01:00
Jakub Jelen 8ddfafe057 asn1: Empty bit string requires empty zero-bits indicator 2020-01-07 14:50:48 +01:00
Jakub Jelen 2c913155a2 asn1: Do not accept non-minimal encoding of OBJECT IDs 2020-01-07 14:50:48 +01:00
Jakub Jelen aaa302ca35 asn1: Allow non-strict INTEGER parsing for other code paths (FCI parsing) 2020-01-07 14:50:47 +01:00
Jakub Jelen fefff2e462 asn1: Simplify the OID decoding 2020-01-07 14:50:47 +01:00
Jakub Jelen 4faf517af4 asn1: Handle more corner cases of OBJECT ID parsing 2020-01-07 14:50:47 +01:00
Jakub Jelen c449aa4430 asn1: Reject integers with bogus zero/non-zero bytes on left 2020-01-07 14:50:47 +01:00
Jakub Jelen d3e9b55223 asn1: Distinguish error codes for invalid objects from implementation limitation (integer size) 2020-01-07 14:50:47 +01:00
Jakub Jelen 1271299955 ans1: Verify the padding in BIT STRING contains only zero bits 2020-01-07 14:50:47 +01:00
Jakub Jelen c1814571bd asn1: Avoid invalid unused bits values 2020-01-07 14:50:47 +01:00
Jakub Jelen 61af2c1d0a asn1: Add support for encoding large values in OIDs 2020-01-07 14:50:47 +01:00
Jakub Jelen 19501715d7 asn1: Correctly handle OIDs with second octet > 39 2020-01-07 14:50:47 +01:00
carblue 5dd9fcb25c Fix asn1.c:print_tags_recursive 2020-01-07 10:18:46 +01:00
Jakub Jelen cc917b541f asn1: Avoid calling malloc with 0 argument
Caused problems reported by oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18758
2019-11-11 22:02:41 +01:00
Jakub Jelen cd51430ba7 asn1: Avoid malloc(0) also from BIT STRING and GENERALIZED TIME structures 2019-11-11 22:02:30 +01:00
Frank Morgner 3c286b3cb1 fixed Null-dereference READ
https://oss-fuzz.com/testcase-detail/5734505646391296

Thanks to OSS-Fuzz
2019-10-26 23:50:11 +02:00
Jakub Jelen cc466eea94 asn1: Avoid undefined shifts by adding explicit cast
The error was:
asn1.c:681:23: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
	    #0 0x5e9b11 in decode_bit_field opensc/src/libopensc/asn1.c:681:23

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18487
2019-10-25 20:19:50 +02:00
Jakub Jelen 0d091c8e0c asn1: Avoid integer overflow
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18475
2019-10-23 13:50:52 +02:00
Jakub Jelen 1be013d08e asn1: Fix undefined shift in OID parser
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16618
2019-10-22 09:42:18 +02:00
Jakub Jelen 6ef0ac6e67 asn1: Correctly parse negative integers
The negative integers were parsed uterly wrong, resulting in undefined
shift overflows as reported by oss-fuzz.

The current implementation takes negated values (properly masked) and
calculates two's complement in the end, which results in correct values
and correct data handling.

https://oss-fuzz.com/testcase-detail/5125815506829312
2019-10-22 09:33:46 +02:00
Jakub Jelen 544d576b00 asn1: Do not pass null argument to memcpy
Reported by clang analyzer:

src/libopensc/asn1.c:1080:2: note: Null pointer passed as an argument to a 'nonnull' parameter

        memcpy(p, data, datalen);
2019-10-22 09:15:49 +02:00
Jakub Jelen 889d598bcd asn1: Initialize values to avoid comparison with garbage
Reported by clang analyzer:

src/libopensc/asn1.c:2115:14: warning: The right operand of '<' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]

        if (halflen < r_len || halflen < s_len)   {
2019-10-22 09:15:36 +02:00
Frank Morgner f621305140 fixed undefined behavior when parsing negative ASN.1 Integer 2019-08-30 23:45:40 +02:00
Frank Morgner 9b4b080be7 fixed compiler warning 2019-08-27 15:27:15 +02:00
Frank Morgner a3fc7693f3 Fixed out of bounds access in ASN.1 Octet string
Credit to OSS-Fuzz
2019-08-27 15:21:46 +02:00
Frank Morgner 412a6142c2 fixed out of bounds access of ASN.1 Bitstring
Credit to OSS-Fuzz
2019-08-27 15:19:22 +02:00
Frank Morgner 45dfc14573 fixed memory leak 2019-07-26 15:23:02 +02:00
Frank Morgner 3c83a80b57 fixed printing non primitive tag
fixes undefined bitshift
2019-05-21 19:34:46 +02:00
Frank Morgner 7f7bcbff52 fixed misuse of realloc
calling it with size 0 leads to a free, which eventually may lead to a
double free corruption.
2019-01-30 21:57:59 +01:00
Frank Morgner ffe38fd87f sc_asn1_read_tag: fixed tracking of consumed bytes
fixes return buffers that are outside the allocated memory space
2018-08-14 15:50:13 +02:00
Frank Morgner 8fe377e93b fixed out of bounds reads
Thanks to Eric Sesterhenn from X41 D-SEC GmbH
for reporting and suggesting security fixes.
2018-08-14 15:50:13 +02:00
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