Commit Graph

97 Commits

Author SHA1 Message Date
Peter Marschall 5abe99d228 fix typos
Mass-typo fixing, almost exclusively in comments and text strings.

While at it also fixed a few (very few) grammar errors.
2018-04-15 09:34:45 +02:00
Frank Morgner b643bbbe40 fixed memory in case of a certificate parsing problem 2018-03-22 14:34:02 +01:00
Nathaniel Wesley Filardo 00535f0174 sc_pkcs15_get_bitstring_extension: int, not long long
Use the ASN.1 decoder's SC_ASN1_BIT_FIELD decoder to properly decode
into a machine word.  As _bitstring_extension is used only for the OID
2.5.29.15 by all callers, which is at most 9 bits wide, this is a
reasonable thing to do.
2017-09-12 23:05:27 +02:00
Mouse 13f61eee7b Fix CAC-introduced bug that broke access to certificates (@dengert found it) (#1032)
Regression from 777e2a3751
2017-04-22 17:05:08 +02:00
Frank Morgner e7915ec198 replace assert with error handling 2017-04-04 09:11:35 +02:00
Jakuje 777e2a3751 adding a CAC support into OpenSC (#841)
* Includes adding support for parsing extensions from a certificate.
* Move lebytes2ushort() to related functions in internals.h
* Adds Simple TLV related functions
2017-02-27 11:05:12 +01:00
Doug Engert 65090e814e pkcs15-cert: fix double free issue, memory leak and comment
if no extensions are found, val was uninitialized.
If multiple extensions, val was not freed for non interestinf extensions.
COmments dind not have valid OID values.

 On branch piv-keyusage
 Changes to be committed:
	modified:   pkcs15-cert.c

 # VTA: closes #905
2016-11-20 18:47:37 +01:00
Jakuje 12f4026160 Fix Coverity remarks (#876) 2016-10-10 22:21:46 +02:00
Jakub Jelen e4f5f84512 libopensc: generic parse of certificate extensions
The code attempted to handle extensions assuming extensions were ordered. The
only extension it handled was crl's, but the handling was wrong and I didn't
find any actual use of the crl code. I've changed it to cache all the extensions
and then provided accessors functions to read a specific extension. I needed this
to read the key Usage, but the extension fetching code can work with any extension
(though the caller will need to parse the result. I also added code that parses DN
and returns a specifically requested DN component. I needed this to get the Common
Name for the certificate Subject. This gives the token a 'unique' name rather than
some generic name (like CAC-I or CAC-II). Both of these can be used to enhance the
piv support as well.

rebased by VTA
Closes #852
2016-08-28 16:41:01 +02:00
Frank Morgner bcb5fc15e5 honour HAVE_CONFIG_H 2015-04-22 23:55:33 +02:00
Viktor Tarasov 8871e61596 pkcs15: change names of internal SPKI procedures
sc_pkcs15_pubkey_from_spki_sequence() takes the ASN1 'subjectPublicKeyInfo' data
sc_pkcs15_pubkey_from_spki_fields() takes the ASN1 'subjectPublicKeyInfo' data without outter SEQUENCE tag
2014-02-16 22:35:52 +01:00
German Blanco 4a674b4dfc Improving logging of certificate handling. 2013-05-07 09:43:47 +02:00
Viktor Tarasov 98db49936a pkcs15: 'issuer' and 'subject' have to be DER encoded sequence
'issuer' and 'subject' data have been the non-encoded sequence of rDNs
2013-03-17 13:56:26 +01:00
Viktor Tarasov cc5a171ddc pkcs15: regression in e35febe: compute cert length
parse_x509_cert() reviewed.
Now certificate's DER data are allocated and the DER data length is determined in one place.

https://github.com/OpenSC/OpenSC/pull/114
https://github.com/OpenSC/OpenSC/commit/e35febe
2012-12-25 20:05:45 +01:00
Viktor Tarasov e35febed5b pkcs15: use whe available the pkcs15 object content
when reading certificate, try to get the pkcs15 object's content
before reading the certificate file.
2012-10-21 16:30:06 +02:00
Viktor Tarasov df9a4d0b2c pkcs15: for 'sc_pkcs15_cer's data use the 'der' object type
To hold the raw certificate blob in 'sc_pkcs15_cert' data use the 'sc_pkcs15_der' data type.
also:
; in 'pkcs15-cert.c' use short call of the debug messages;
; in 'destroy-object' pkcs15 framework handler take into account the multi-application cards:
-- when binding card use the application info;
-- when finalizing profile use the application ID.
2012-09-30 22:54:52 +02:00
andre a9eba2b205 libopensc: Remove unused parameter 'file_out' in function 'sc_pkcs15_read_file'.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5546 c6295689-39f2-0310-b995-f0e70906c6a9
2011-06-05 11:08:36 +00:00
vtarasov e7790508f6 pkcs15: when setting object data's path, use, if available, the AID from 'DiscretionaryDataObject'
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5111 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-18 16:31:41 +00:00
martin acb54b965f typo: remove double semicolon which prevents compilation with Visual Studio.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4888 c6295689-39f2-0310-b995-f0e70906c6a9
2010-11-29 08:51:25 +00:00
dengert d1aa716bec Move decoding of subjectPubkeyInfo from pkcs15-cert.c
to pkcs15-pubkey.c and call the new sc_pkcs15_pubkey_from_spki.
Add sc_pkcs15_pubkey_from_spki_filename to allow a file to 
contain the subjectPubkeyInfo, which will be used the the PIV 
driver when EC is implemented. The format of the file, is the
same as an X509 certificate subjectPublicKeyInfo and what 
OpenSSL calls an EVP_PKEY, which includes the algorithm,
any parameters and the public key. 
 


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4874 c6295689-39f2-0310-b995-f0e70906c6a9
2010-11-08 17:05:40 +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
viktor.tarasov 58c1c88efa libopensc: homogenise line ending in the debug messages
continuating r4759


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4774 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-25 20:35:59 +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 bd5c186767 pkcs15/pkcs11: encoding of certificate's attribute 'serialNumber'
Applying patch of Andre Zepezauer. Thanks.



git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4451 c6295689-39f2-0310-b995-f0e70906c6a9
2010-06-21 10:49:58 +00:00
viktor.tarasov fec213ad2e pkcs11: DER encoded value for CKA_SERIAL_NUMBER
discussed in http://www.opensc-project.org/pipermail/opensc-devel/2010-May/014264.html



git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4375 c6295689-39f2-0310-b995-f0e70906c6a9
2010-05-25 08:06:28 +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
martin d672fde449 Remove sc_error and sc_ctx_suppress_errors_* in favor of sc_debug/fprintf
git-svn-id: https://www.opensc-project.org/svnp/opensc/branches/martin/0.12@3721 c6295689-39f2-0310-b995-f0e70906c6a9
2009-09-14 08:46:59 +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
henryk b45617c451 Make absolute paths from all paths read from the PKCS#15 directories by prepending the DF(PKCS#15) path if necessary.
Fixes compatibility with Siemens HiPath SIcurity formatted cards which use relative paths.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3028 c6295689-39f2-0310-b995-f0e70906c6a9
2006-09-26 10:55:02 +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 23802d825e properly initialize sc_asn1_entry elements + some cleanup
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2463 c6295689-39f2-0310-b995-f0e70906c6a9
2005-08-05 07:24:43 +00:00
sth 41889b27a1 Export function parse_x509_cert()
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2458 c6295689-39f2-0310-b995-f0e70906c6a9
2005-08-03 09:07:09 +00:00
bert 2d97002824 API fixup: use defined type instead of struct for exposed structs
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2232 c6295689-39f2-0310-b995-f0e70906c6a9
2005-03-08 20:59:35 +00:00
nils 8673508a43 fix memory leak, cleanup: use object specific release method
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2024 c6295689-39f2-0310-b995-f0e70906c6a9
2004-12-18 14:14:57 +00:00
nils 75b9f0b5de fix (potential) memory leak
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1998 c6295689-39f2-0310-b995-f0e70906c6a9
2004-12-12 17:17:07 +00:00
nils 6281259f04 fix usage of asn1 flags
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1797 c6295689-39f2-0310-b995-f0e70906c6a9
2004-06-18 20:49:54 +00:00
okir ed5d12800d - Read and write CDF entries with directly encoded certificates
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1610 c6295689-39f2-0310-b995-f0e70906c6a9
2003-11-19 20:28:02 +00:00
aet 5616dba08e - Stop using unflexible automake conditionals when
building PC/SC, OpenCT or USBToken support,
  use ifdef's directly in source.
- Because of above, add HAVE_PCSCLITE for winconfig.h
- Remove unnecessary includes for log.h, opensc.h and
  errors.h in libopensc sources, they're already taken
  care by internal.h.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1406 c6295689-39f2-0310-b995-f0e70906c6a9
2003-09-03 09:28:55 +00:00
aet 763fc16704 Rename libopensc specific error/debug to sc_error/sc_debug
We should have done this ages ago.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1392 c6295689-39f2-0310-b995-f0e70906c6a9
2003-08-25 14:21:18 +00:00
sth 55e8c31b12 Fixed: support for X.509 V1 certs
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1094 c6295689-39f2-0310-b995-f0e70906c6a9
2003-05-11 07:22:27 +00:00
okir a5492a32a8 - slightly more verbose error messages when ASN.1 parsing fails
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@871 c6295689-39f2-0310-b995-f0e70906c6a9
2003-01-20 09:56:27 +00:00
okir 3f16e04a8f - sc_pkcs15_read_certificate now uses sc_pkcs15_read_file
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@733 c6295689-39f2-0310-b995-f0e70906c6a9
2002-12-02 13:39:36 +00:00
aet 1d2c9e4c48 Cleanups for initial win32 port, untested.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@696 c6295689-39f2-0310-b995-f0e70906c6a9
2002-10-19 14:04:52 +00:00
jey 4c36cb9641 - Used cert->key instead of key in parse_x509_cert()
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@686 c6295689-39f2-0310-b995-f0e70906c6a9
2002-08-21 10:22:13 +00:00
okir b18d893764 - certificate version is optional (v1)
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@673 c6295689-39f2-0310-b995-f0e70906c6a9
2002-08-06 13:51:08 +00:00
fabled 7635468ed9 - Initial support for win32
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@654 c6295689-39f2-0310-b995-f0e70906c6a9
2002-06-14 12:52:56 +00:00
jey 7c94d7d8d3 - Several patches to fix behaviour on 64-bit architectures (by
Jochen Friedrich)
- Fixed one bug in sc_copy_asn1_entry(), one in
  sc_pkcs15init_add_object() and one in pkcs15-crypt
  (patches also by Jochen)


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@609 c6295689-39f2-0310-b995-f0e70906c6a9
2002-05-26 12:31:23 +00:00
aet f7fcaee513 Extract certificate crlDistributionPoints and store it in sc_pkcs15_cert
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@580 c6295689-39f2-0310-b995-f0e70906c6a9
2002-04-21 18:54:10 +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