Commit Graph

39 Commits

Author SHA1 Message Date
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
Doug Engert 483e153182 ASN1 cleanup part 1
ASN1 tags are represented in two many ways within OpenSC.
This is a trivial change to simplify one aspect of this.
It also makes the code more readable.

SC_ASN1_CLASS_MASK, SC_ASN1_APP, SC_ASN1_CTX, SC_ASN1_PRV,
SC_ASN1_CONS are changed, and SC_ASN1_CLASS_MASK is added.

These then align with the bits defined by SC_ASN1_TAG_CLASS,
SC_ASN1_TAG_APPLICATION, SC_ASN1_TAG_CONTEXT, SC_ASN1_TAG_PRIVATE,
and SC_ASN1_TAG_CONSTRUCTED.

(SC_ASN1_UNI and SC_ASN1_TAG_UNIVERSAL are both 0x00 thus no change
is needed).

(No sign of a right shift of SC_ASN1_CTX or SC_ASN1_PRV causeing
problems has been seen in the code.) If found, can be solved.)

Close examination of the OpenSC code base shows all uses of tags
used by routines and sc_asn1_entry use the defines.

This could allows 26 lines of code in sc_asn1_skip_tag used to test
the 3 CLASS and CONSTRUCTED bits to be replaced by:

	if (((cla << 24) | tag) != tag_in)
		return NULL;

The 26 lines still work as will any other code in OpenSC
that tests the bits using the defines. It also allows new code
to be simplified.

Problem identified while looking at better way to check response
on GET_DATA (0xCB) that returns TLV as used in card-piv.c

Changes tested using pkcs11-tool --test --login with PIV, SC_HSM
and OpenPGP cards.
2020-11-25 08:50:13 +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
Frank Morgner 45dfc14573 fixed memory leak 2019-07-26 15:23:02 +02: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
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 80c496671f helper functions to change format of ECDSA signature 2015-02-20 14:20:19 +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
Andreas Schwier ffb20e5916 sc-hsm: Added sc-hsm-tool with DKEK support and key wrap / unwrap 2012-11-11 12:53:03 +01:00
Viktor Tarasov 0518ced8e0 asn1: export 'asn1-write-element' function
... used by OpenPGP driver
2012-07-29 13:09:00 +02: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
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
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 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
aj b3ad2f9dd2 convert to utf-8.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3084 c6295689-39f2-0310-b995-f0e70906c6a9
2006-12-19 21:31:17 +00:00
nils 01f72933af add support to parse the seInfo TokenInfo entry, improve aid support in opensc-explorer
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3045 c6295689-39f2-0310-b995-f0e70906c6a9
2006-10-30 18:51:48 +00:00
nils e8c05ca648 use more opensc specific names for ASN.1 tags to avoid name conflicts
with other ASN.1 libraries


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2815 c6295689-39f2-0310-b995-f0e70906c6a9
2006-01-20 20:52:36 +00:00
nils 45a9d05830 cleanup, mostly signed/unsigned issues
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2469 c6295689-39f2-0310-b995-f0e70906c6a9
2005-08-08 10:22:14 +00:00
aet c1b0626cdd - Cleanup, typo fix
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2123 c6295689-39f2-0310-b995-f0e70906c6a9
2005-02-02 10:21:10 +00:00
aet c0c3c339d7 SC -> OPENSC, old legacy from the libsc days
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1409 c6295689-39f2-0310-b995-f0e70906c6a9
2003-09-03 17:59:08 +00:00
okir 98907b68f1 - fixed endianness problem with encoding/deconding of bit fields
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1034 c6295689-39f2-0310-b995-f0e70906c6a9
2003-04-16 20:52:26 +00:00
okir 542e12deb3 - pubkey asn.1 encoding fix
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@893 c6295689-39f2-0310-b995-f0e70906c6a9
2003-02-03 12:17:12 +00:00
aet 3dccd63989 - C++ support. Compiles with gcc/g++ for Linux, otherwise
completely untested.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@574 c6295689-39f2-0310-b995-f0e70906c6a9
2002-04-19 14:23:31 +00:00
okir f49cb6b0f1 - implemented encoding of OBJECT IDENTIFIER
- enhanced support for encoding/decoding of CHOICE
- moved encoding/decoding of AlgorithmIdentifier to separate file,
  and added encoding/decoding of algorithm parameters


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@526 c6295689-39f2-0310-b995-f0e70906c6a9
2002-04-17 08:54:36 +00:00
jey 22636c2df9 - Added SC_ERROR_FILE_ALREADY_EXISTS
- Changed call convention for reader finish()
- CT-API driver now frees its resources correctly
- Added year 2002 to some of the copyright statements
- sc_pkcs15_decipher() and sc_pkcs15_compute_signature()
  now select only the parent DF of the private key file


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@463 c6295689-39f2-0310-b995-f0e70906c6a9
2002-04-05 14:46:44 +00:00
aet 076a26bbac Rework the header structure
Currently fails to compile, unless you symlink
all the necessary headers to src/include/opensc
by yourself.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@459 c6295689-39f2-0310-b995-f0e70906c6a9
2002-04-05 13:48:00 +00:00
aet d81d10ba90 Upgrade sources to use new headers, part #1
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@458 c6295689-39f2-0310-b995-f0e70906c6a9
2002-04-05 10:44:51 +00:00
jey 3416461c4b - Added X.509 algorithm id decoding and encoding to asn1.c
- Implemented a generic ATR matching helper function
- Made signing much smarter (should even work now)
- Added info about supported crypto algorithms to struct sc_card


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@276 c6295689-39f2-0310-b995-f0e70906c6a9
2002-03-08 05:59:57 +00:00
jey 6b07ff64f6 - Reworked PKCS #15 structure a bit (MANY THINGS
WILL BREAK)
- Added support for public key DFs (not tested yet)


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@251 c6295689-39f2-0310-b995-f0e70906c6a9
2002-03-03 00:32:28 +00:00
jey 20adb4b39c - continued to improve PKCS #15 generation
- fixed a few problems in sc_set_security_env
- started to implement Better (tm) object handling for
  PKCS #15 objects


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@167 c6295689-39f2-0310-b995-f0e70906c6a9
2002-01-16 23:59:18 +00:00
jey 9dc7054919 - added preliminary ASN.1 encoding support
- modified ASN.1 decoding to make it easier to
  port decoder structures to the encoder
- fixed a recently introduced bug in card driver handling
- opensc-explorer will now allow only DF's to be cd'd into


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@156 c6295689-39f2-0310-b995-f0e70906c6a9
2002-01-10 12:33:56 +00:00
jey 9197babe53 - renamed sc_asn1_parse to sc_asn1_decode
- added capabilities and flags fields to struct sc_card
- added a mutex to sc_context for future use


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@148 c6295689-39f2-0310-b995-f0e70906c6a9
2002-01-07 18:23:34 +00:00
jey 68928ae520 - changed \\e back to \e in sc_log.c
- changed function prototypes in sc-asn1.c (int --> size_t)


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@126 c6295689-39f2-0310-b995-f0e70906c6a9
2002-01-01 18:25:11 +00:00
jey 3e96a893ec - ported certificate reading to new ASN.1 code
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@119 c6295689-39f2-0310-b995-f0e70906c6a9
2001-12-29 19:03:46 +00:00
jey 9989c11a6d - remembered ChangeLog
- moved some functions from sc.c to sc-iso7816-4.c
- added fancy colors to log output =)
- removed global sc_debug variable, moved it to sc_context
- fixed new ASN.1 code (possibly still unstable)


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@83 c6295689-39f2-0310-b995-f0e70906c6a9
2001-12-19 21:58:04 +00:00
jey 5e00917fcc - bumped version number up to 0.4.0
- improved ASN.1 decoding _lots_


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@80 c6295689-39f2-0310-b995-f0e70906c6a9
2001-12-16 18:46:32 +00:00
jey 584f5e5cb8 - PAM module is semi-working now
- added sc_asn1_put_tag() and sc_restore_security_env() functions
- preliminary support for CREATE FILE and DELETE FILE commands


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@42 c6295689-39f2-0310-b995-f0e70906c6a9
2001-11-17 00:11:29 +00:00
jey 18bab373b8 - changed license to LGPL
- moved ASN.1 function definitions from sc.h to sc-asn1.h


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@36 c6295689-39f2-0310-b995-f0e70906c6a9
2001-11-06 18:34:19 +00:00
jey c57e2e266d - moved libsc to its own directory
- added non-working MIME plugin for "text/x-text-to-sign"
- added pseudo-random number generator support
- split hst-test.c into smaller files


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@31 c6295689-39f2-0310-b995-f0e70906c6a9
2001-11-01 15:43:20 +00:00