Commit Graph

385 Commits

Author SHA1 Message Date
Pavel Cherezov ecb1656b91 sensitive flag added to generate key with CKA_SENSITIVE flag.
pull request issues fix: replace spaces with tabs and fix description of the argument.
2017-09-15 00:11:49 +02:00
Pavel Cherezov 2cf0a119f4 sensitive flag added to generate key with CKA_SENSITIVE flag 2017-09-15 00:11:49 +02:00
Mouse f0e703be49 Fix bug in pkcs11-tool (did not ASN.1-encode ECDSA-SHA-2 signature) 2017-08-29 12:05:16 +02:00
Mouse 1efc73fa2f Fix typo in ECDSA-SHA384 for pkcs11-tool 2017-08-28 21:17:03 +02:00
Frank Morgner 172f320c9a win32: Dedicated md/pkcs11 installation folders
Don't install non-permanent files (md/pkcs11) to system folder anymore.
2017-08-22 23:41:29 +02:00
Jakub Jelen 41796ff0ed [pkcs11-tool] Add SHA2 HMAC mechanisms 2017-08-17 12:02:28 +03:00
Jakub Jelen d5647fe53d [pkcs11-tool] Properly define RSA-PSS mechanisms 2017-08-17 12:02:28 +03:00
Jakub Jelen e2fe24d56a clang static analyzer reports
tools/pkcs15-tool.c:
	Dead assignment: Value stored to 'c' is never read
tools/pkcs11-tool.c:
	Dead assignment: Value stored to 'n' is never read
	Dead assignment: Value stored to 'rv' is never read
libopensc/card-cac.c:
	Dead assignemnt: Value stored to 'tl_head_len' is never read
	Dead increment: Value stored to 'outp' is never read
common/libpkcs11.c:
	Memory leak in case of C_UnloadModule() fails
libopensc/pkcs15-pubkey.c:
	Potential memory leaks
pkcs11/mechanism.c:
	Potential memory leak
pkcs11/framework-pkcs15.c:
	Potential memory leaks
	Dereference of null pointer
	Dead assignments
tools/sc-hsm-tool.c:
	Function call argument is an uninitialized value
	Dead assignment: Value stored to 'r' is never read
libopensc/card-openpgp.c:
	Dead assignment: ignoring the errors in case of sc_pkcs15_encode_pubkey() failed
libopensc/pkcs15-cac.c:
	Dead assignments: ignoring return values
libopensc/pkcs15-coolkey.c:
	Dead assignments: ignoring return values
libopensc/card-sc-hsm.c:
	Dereference of undefined pointer value: Properly check the file allocation
pkcs11/slot.c:
	Dead assignment
pkcs15init/pkcs15-cflex.c:
	Dereference of null pointer
	Uninitialized argument values
2017-07-18 22:40:20 +02:00
Jakub Jelen 12fe5b5e67 [pkcs11-tool] Do not use modLenBytes before validating 2017-07-11 12:55:38 +02:00
Frank Morgner 828de113e8 pkcs11-tool: respect CKA_ALWAYS_AUTHENTICATE
Quoting from PKCS#11:

The CKA_ALWAYS_AUTHENTICATE attribute can be used to force re-authentication (i.e. force the user to provide a PIN) for each use of a private key. “Use” in this case means a cryptographic operation such as sign or decrypt. This attribute may only be set to CK_TRUE when CKA_PRIVATE is also CK_TRUE.

Re-authentication occurs by calling C_Login with userType set to CKU_CONTEXT_SPECIFIC immediately after a cryptographic operation using the key has been initiated (e.g. after C_SignInit).

Closes https://github.com/OpenSC/OpenSC/pull/1066
2017-06-15 23:43:37 +02:00
Frank Morgner e894bd175b Revert "pkcs11-tool: always authenticate when pinpad is in use"
This reverts commit 423375c6f8.

Fixes https://github.com/OpenSC/OpenSC/issues/1063
2017-06-13 13:06:46 +02:00
konstantinpersidskiy 083cec8fda pkcs11-tool: add GOSTR3410 keypair generation (#997)
* pkcs11-tool: add GOSTR3410 keypair generation
* Refactor gost3410 generation
2017-06-09 10:30:40 +02:00
Mouse 0cb91fd68c Fix bug in pkcs11-tool.c that prevented it from displaying CKA_DERIVE key usage for EC public keys 2017-04-22 17:12:26 +02:00
Frank Morgner 6bfb39454b Fix missing error handling of memory allocation (#1020)
* libopensc: handle allocation errors
* handle more faults during memory allocation

fixes several situations that cause segmentation fault
2017-04-20 21:08:49 +02:00
Jakub Jelen c496af17d4 pkcs11-tool: Set CKA_PRIVATE=false for new public keys
Keygen should write public keys with explicit CKA_PRIVATE=false by default (possibility to modify by --private switch)

Related to 4df35b92 discussing writing separate objects years ago.
2017-04-17 01:24:03 +02:00
Jakub Jelen 1ca09b8f10 pkcs11-tool: Do not use unitialized data when C_GetTokenInfo() failed 2017-04-13 15:18:54 +02:00
Frank Morgner c2fa66f1fb pkcs11-tool: fixed RSA-X-509 corner case test
For testing RSA-X-509, we are generating random bytes for signing. It
may happen that the modulus is smaller than the random number
generated, which triggers an error in the card. With this change, we
are setting the most significant byte to 0x00 to assure the random
number is smaller than the modulus.
2017-04-03 21:55:59 +02:00
Jakub Jelen 2031735fb1 pkcs11-tool: Polish rough edges of --attr-from use case to verify and convert in all cases 2017-03-27 10:53:44 +02:00
Jakub Jelen 74c6494f19 pkcs11-tool: Do not allow to write PEM encoded certificates to cards
Resolves #834
2017-03-27 10:53:44 +02:00
Christoph Müllner c77cb511d9 pkcs11-tool: Add feature to get random data. (#995)
* pkcs11-tool: Add feature to get random data.

Getting random data is an essential part of the PKCS11 API.
This patch provides a new command line parameter to get
random data from the pkcs11-tool.

Tested with a Yubikey (PIV applet) and the following command line:

$ pkcs11-tool --slot=0 --generate-random=128 | hexdump -C
  00000000  0c 35 85 2e 85 68 ab ce  e8 56 b3 f6 f3 33 e6 37  |.5...h...V...3.7|
  00000010  12 10 eb fd 8a 1e 75 b7  3f 4d fa 61 8f ab d8 bf  |......u.?M.a....|
  00000020  f7 2c 7d ba 07 a5 45 6e  a7 85 1c 47 3b 46 01 2c  |.,}...En...G;F.,|
  00000030  79 18 6e 51 4d c4 ae 20  37 37 1d 7b 7e b0 d5 18  |y.nQM.. 77.{~...|
  00000040  ef a4 3c 09 91 68 db dd  2a a8 fc b9 34 06 2a ee  |..<..h..*...4.*.|
  00000050  5a 86 55 54 11 1f ef 4e  07 73 79 27 0a e4 58 cf  |Z.UT...N.sy'..X.|
  00000060  f4 bd bc 2f ad 27 b1 a7  a4 fa c7 1a 7b 31 de a3  |.../.'......{1..|
  00000070  e8 dc 85 28 18 82 00 45  3c f8 eb 48 a4 20 e4 3b  |...(...E<..H. .;|
  00000080

Signed-off-by: Christoph Müllner <christophm30@gmail.com>

* pkcs11-tool: Add documenation for --generate-random.

Signed-off-by: Christoph Müllner <christophm30@gmail.com>
2017-03-27 10:52:38 +02:00
Martin Paljak 1226462f34 pkcs11-tool: show the PIN lengths from token info 2017-03-03 09:08:52 +01:00
Doug Engert 2a68395d22 Pkcs11-tool.c -t fails to for RSA-X-509 verification
The test_signature routine reuses data array and fails to reset data[0] = 0
when creating a PKCS hash to be pased to OpenSSL.

 Date:	     Mon Feb 13 11:48:00 2017 -0600

 On branch pkcs11-tool-pkcs
 Changes to be committed:
	modified:   tools/pkcs11-tool.c
2017-02-13 20:50:30 +01:00
Frank Morgner 9d5fe7803d silence warning about not logging in 2017-02-08 22:19:02 +01:00
Nuno Goncalves 9eb706ba29 Fix tools interpretation of util_getpass return value
A negative value means a error and not "No PIN entered".

Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-02-04 22:44:26 +01:00
Nuno Goncalves 423375c6f8 pkcs11-tool: always authenticate when pinpad is in use
Authentication might not be required (from pkcs11 side) when
pin cache is used. This can't happen if a pinpad is used.

We were already checking for CKA_ALWAYS_AUTHENTICATE (user_consent),
now also check for CKF_PROTECTED_AUTHENTICATION_PATH (pinpad).

Also encapsulate logic in a function and provide additional checks for
redundant authentication attempts.

Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-02-04 22:44:26 +01:00
Nuno Goncalves b6cb10f768 pkcs11-tool: make login checks consistent in all test functions
Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-02-04 22:44:26 +01:00
Nuno Goncalves 37844fc6c3 Revert "pkcs11-tool: re-login if pincache is disabled or expired"
This reverts commit 1bc09ddafa.

This commit had totally wrong.

Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-02-04 22:44:26 +01:00
Nuno Goncalves bb905ec1ec pkcs11-tool: small format fix (#950)
Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-01-28 00:59:28 +01:00
Frank Morgner dce379b43d pkcs11-tool: fixed missing newline in test output
regression of 4441efa6da
2016-12-14 21:18:58 +01:00
Pieter Naaijkens 13463e2d18 Add missing comma to fix segfault when pkcs11-tool is called without arguments 2016-12-14 19:47:24 +01:00
Doug Engert 3ff7309520 Pkcs11-tool.c changes to accommodate ECDH operations using SoftHSM. (#901)
PKCS#11 v2.20 in not clear on the format of the public key of the other party
pased during ECDH key derivation. Some implementations (OpenSC) pass just the value
of the public key (RAW), while others (SoftHSM) pass an ASN.1 DER encoded OCTET_STRING.

PKCS$11 v2.40 points out this problem and says implementations must support the
RAW format and may also support the DER format.

To allow pkcs11-tool.c to work with ECDH derivation and using the current libSoftHSM2.so
a new parameter was added to pkcs11-tool, --derive-pass-der.

Also added to teh template fot the new key were:

CKA_SENSITIVE = false
CKA_EXTRACTABLE = true
CKA_VALUE_LEN = size of key to be derived.

OpenSC currently only support derivation of ECDH session keys, (CKA_TOKEN = false)
The derived key must be CK_KEY_TYPE = CKK_GENERIC_SECRET
Additional changes could be made to support AES or DES3 keys.

It is not clear if there is a need to support CKA_TOKEN =  true which says the
derived key must be on the hardware token. For ECDH, these keys are short lived.

 On branch pkcs11-tool-simple-ecdh
 Changes to be committed:
	modified:   src/tools/pkcs11-tool.c
2016-11-20 18:28:42 +01:00
Frank Morgner 51c27f57a0 hex_to_bin: don't strip leading null-bytes
fixes https://github.com/OpenSC/OpenSC/issues/838

... and hopefully doesn't have any side effects
2016-10-31 12:34:44 +01:00
Ludovic Rousseau 8b761b830b pkcs11-tool.c: fix compiler warning
pkcs11-tool.c:2992:1: warning: control reaches end of non-void function
      [-Wreturn-type]
}
^
2016-10-14 17:36:19 +02:00
Jakuje 12f4026160 Fix Coverity remarks (#876) 2016-10-10 22:21:46 +02:00
Doug Engert c6dba96f55 Add support for LibreSSL compatability as well as OpenSSL-1.1.0
This commit is based on input from https://github.com/lbschenkel
LibreSSL is based on OpenSSL 1.0.1. API.

 Changes to be committed:
	modified:   libopensc/sc-ossl-compat.h
	modified:   tools/pkcs11-tool.c
	modified:   tools/pkcs15-init.c
	modified:   tools/sc-hsm-tool.c
2016-10-08 06:17:44 -05:00
Doug Engert 5fb4db6373 Use OpenSSL versions OpenSSL-0.9.7 to 1.1.0a for OpenSC
OpenSSL-1.1.0 was released 8/25/2016
OpenSSL-1.1.0a was released 9/22/2016

  https://www.openssl.org/news/openssl-1.1.0-notes.html

Changes to allow the OpenSC code base to work with OpenSSL versions from
0.9.7 to 1.1.0 with few changes.

This is an update and rebased version of my prep-openssl-1.1.0-pre6 branch.

No attempt was made to back port any OpenSSL features. These changes
just allow an updated OpenSC code base to use what is in the various OpenSSL
releases.

A new header libopensc/sc-ossl-compat.h contains extra defines
to reduce the need for so many #if OPENSSL_VERSION_NUMBER statements
in the source code.

The OpenSC source can now use the OpenSSL 1.1 API. The libopensc/sc-ossl-compat.h
has defines for the new API for use with older versions of OpenSSL.

sc-ossl-compat.h is included by libopensc/internal.h so all OpenSC
library routines can take advantage of it. For the tools, which do not use
libopensc/internal.h, libopensc/sc-ossl-compat.h is included by the tools.

The OpenSC source has been modified to use OpenSSL functions to access
hidden structures, such X509, BIGNUM, EVP_CIPHER_CTX, and use XXX_new
functions to allocate structures which must use pointer such as
BIGNUM and EVP_CIPHER_CTX.

For backward compatability sc-ossl-compat.h now defines inline routines
to emulate the RSA and DSA  access routines in OpenSSL-1.1.0. Thus
the same OpenSC source code can be used with openSSL versions from
0.9.7 to 1.1.0.

Inline routines were chosen, because using macros does not work on all platforms.
Having OpenSC versions of these routines in libopensc would be a posibility,
but they are only used for older version of OpenSSL, and could be removed in
the future.
 Changes to be committed:
	modified:   src/libopensc/card-entersafe.c
	modified:   src/libopensc/card-epass2003.c
	modified:   src/libopensc/card-gids.c
	modified:   src/libopensc/card-gpk.c
	modified:   src/libopensc/card-oberthur.c
	modified:   src/libopensc/card-piv.c
	modified:   src/libopensc/card-westcos.c
	modified:   src/libopensc/cwa-dnie.c
	modified:   src/libopensc/cwa14890.c
	modified:   src/libopensc/internal.h
	modified:   src/libopensc/p15card-helper.c
	modified:   src/libopensc/pkcs15-itacns.c
	modified:   src/libopensc/pkcs15-prkey.c
	modified:   src/libopensc/pkcs15-pubkey.c
	new file:   src/libopensc/sc-ossl-compat.h
	modified:   src/pkcs11/openssl.c
	modified:   src/pkcs15init/pkcs15-lib.c
	modified:   src/pkcs15init/pkcs15-oberthur-awp.c
	modified:   src/pkcs15init/pkcs15-oberthur.c
	modified:   src/pkcs15init/pkcs15-oberthur.h
	modified:   src/pkcs15init/pkcs15-westcos.c
	modified:   src/tools/cryptoflex-tool.c
	modified:   src/tools/gids-tool.c
	modified:   src/tools/netkey-tool.c
	modified:   src/tools/piv-tool.c
	modified:   src/tools/pkcs11-tool.c
	modified:   src/tools/pkcs15-init.c
	modified:   src/tools/sc-hsm-tool.c
	modified:   src/tools/westcos-tool.c
2016-10-08 06:15:06 -05:00
Sid-Ali TEIR 01c92fe37f pkcs11-tool: fixed --id for C_GenerateKey, DES and DES3 keygen mechanism
fixed --id for C_GenerateKey, added DES and DES3 keygen mechanism and added ability to delete denerated secret key.

This closes #857
2016-08-27 13:11:21 +02:00
Viktor Tarasov 64ba32f2c6 pkcs11-tool: for WIN32 define STDOUT_FILENO
fix bug introduced in 6cd28cfc7c
2016-08-16 10:34:48 +02:00
Hannu Honkanen 6cd28cfc7c myeid: fix to ECDH implementation
fixing #756
rebased by VTA
2016-08-13 20:50:01 +02:00
Nuno Goncalves 6ad229e9f6 pkcs11-tool: Simplify PIN warnings messages logic
Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2016-08-05 10:13:32 +02:00
Nuno Goncalves 1bc09ddafa pkcs11-tool: re-login if pincache is disabled or expired
Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>

closes #839
2016-07-29 17:26:17 +02:00
carblue 1ab99f3756 pkcs11-tool: in 4rd test use other signature keys
also increase signature buffer in framework-pkcs15

closes #814
2016-07-24 19:26:10 +02:00
Nuno Goncalves 1198197586 pkcs11-tool: use CKF_{SO,USER}_PIN_* flags to provide alerts to the user
rebased by @viktorTarasov
initial version in PR-795
2016-07-17 13:22:55 +02:00
David von Oheimb 4441efa6da pkcs11-tool: various improvements, extensions, fixes, cleanup
========================================
rebased by VTA -- commits are forged to one,
excluding the following chunk
(reason -- if not explicitely indicated, the mechanism has to be found out using the mechanism flags):

@@ -1713,8 +1713,9 @@ static int gen_keypair(CK_SLOT_ID slot, CK_SESSION_HANDLE session,
                        int ii;

                        if (!opt_mechanism_used)
+                               opt_mechanism = CKM_EC_KEY_PAIR_GEN;
                                if (!find_mechanism(slot, CKF_GENERATE_KEY_PAIR, mtypes, mtypes_num, &opt_mechanism))
-                                       util_fatal("Generate EC key mechanism not supported\n");
+                                       util_warn("Generate EC key mechanism not listed as supported");

                        for (ii=0; ec_curve_infos[ii].name; ii++)   {
                                if (!strcmp(ec_curve_infos[ii].name, type + 3))

will close PR #747
2016-06-29 14:18:56 +02:00
Viktor Tarasov 76e0e19460 pkcs11-tool: no error when getting sensitive attr. value
resolves PR #807
2016-06-29 10:34:20 +02:00
Viktor Tarasov 3dbcc0b035 pkcs11-tool: generate secret key
resolve PR #808
2016-06-29 10:32:30 +02:00
Frank Morgner 04825d8d7e avoid using an uninitialized buffer 2016-06-04 01:22:28 +02:00
Viktor Tarasov b8dcf91515 pkcs11-tool: print in hex the code of unknown mechanism 2016-06-03 11:12:03 +02:00
Mouse 2ba87640d2 Fixed bug in derive_key(), where correct execution depended on undefined compiler behavior 2016-05-31 01:59:40 +02:00
Viktor Tarasov 56f2319fcc pkcs11-tool: few named curves more 2016-04-01 18:08:00 +02:00
Viktor Tarasov 998a1e10c5 pkcs11-tool: fix invalid parameter for 'find-mechanism'
Fixes #700
2016-03-04 11:30:51 +01:00
Ludovic Rousseau d929532b63 pkcs11-tool.c: fix 2 compiler warnings
pkcs11-tool.c:2650:25: warning: unused variable 'ecdh_parms' [-Wunused-variable]
        CK_ECDH1_DERIVE_PARAMS ecdh_parms;
                               ^
pkcs11-tool.c:2021:7: warning: unused variable 'is_private' [-Wunused-variable]
                int is_private = opt_object_class == CKO_PRIVATE_KEY;
                    ^
2016-02-29 20:19:42 +01:00
Viktor Tarasov dbca85636f pkcs11-tool: use keygen mech. from cmd arguments
There are can be more then one keygen mechanism for a given
key type.
(ex. CKM_RSA_PKCS_KEY_PAIR_GEN and CKM_RSA_X9_31_KEY_PAIR_GEN)
2016-02-19 16:05:55 +01:00
Aleksey Samsonov 3084b3aa32 pkcs11-tool: fix mask for detect PEM format
Make universal mask for choose input format from PEM or DER.
Input file at PEM may be contain at start:
"-----BEGIN RSA PRIVATE KEY-----"
or
"-----BEGIN PRIVATE KEY-----"
2016-01-24 02:31:19 +03:00
Aleksey Samsonov 0d6ecd750e pkcs11-tool: support write of GOST Public Key object 2016-01-24 02:23:18 +03:00
Chris Elledge f01a8ad22e pkcs11-tool: Switched some printfs to fprintfs to allow pipes to work. 2016-01-19 14:54:02 -05:00
Frank Morgner 5129c5a060 Fixed memory leaks 2015-12-09 08:22:45 +01:00
Frank Morgner 9f0087d968 fixed missing includes 2015-10-30 18:21:40 +01:00
Olaf Kirch f42a1c2563 Replace outdated address okir@lst.de -> okir@suse.de
Signed-off-by: Olaf Kirch <okir@suse.de>
2015-10-05 14:07:28 +02:00
Nicholas Wilson 4df35b922c pkcs11: Fix to CKA_PRIVATE handling pcks11-tool
There's a copy-and-paste bug in there, where the CKA_PRIVATE attribute
is being set on the wrong variables! As well as fixing that, we should
explicitly set CKA_PRIVATE to "false" for certificates and public keys,
since the PKCS#11 spec doesn't specify a default and some drivers use
"private" as the default, making it impossible to add a public key/cert
using pkcs11-tool.
2015-08-23 12:41:38 +02:00
HenryJacques c14be48ed9 really set the --login option when using --pin
Until now, if -p was used without -l, we didn't authenticate to the token (see man pkcs11-tool)
2015-08-11 18:03:31 +02:00
David Woodhouse 8c94662e96 Add --test-fork option to pkcs11-tool
The PKCS#11 Usage Guide, at least up to v2.40, says that calling
C_Initialize() in the child after fork is "considered to be good
Cryptoki programming practice, since it can prevent the existence of
dangling duplicate resources that were created at the time of the fork()
call."

(It neglects to mention that doing so in the child of a multi-threaded
process is a clear violation of POSIX, mind you. Not to mention being
utterly pointless if all you're going to do in the child is exec something
else anyway.)

Regardless of the sagacity of this recommendation, we need to cope when
it happens. Historically, we've been quite bad at that. Let's add a test
to pkcs11-tool in the hope it'll help...

Fixes #464
2015-05-16 12:18:54 +02:00
Frank Morgner e84951a5bf fix resource leaks in while registering PKCS#11 mechanisms
introduces a free_mech_data for sc_pkcs11_mechanism_type_t to clear the
mechanisms private memory
2015-05-08 09:11:55 +02:00
Frank Morgner 2c32575e89 pkcs11-tool: fixed resource leak 2015-05-08 09:11:55 +02:00
Viktor Tarasov f0189e8378 pkcs11-tool: option to 'decrypt some data' 2015-04-30 15:57:44 +02:00
Thomas Calderon 0a754b694e pkcs11-tool: pass key usage flags to created objs
* Command-line parameters were introduced to specify key usage
  (--usage-{sign,decrypt,derive}). However, those are not used when importing
  external objects using C_CreateObject function.

fix #445
2015-04-25 12:28:48 +02:00
Thomas Calderon 23ca1f101d pkcs11-tool: Add support for creating EC privkey
* This patch allows to create EC private keys. The feature re-use the GOST
  parsing function as instanciating an ECDSA key is the same as a GOST key.
2015-04-15 08:58:05 +02:00
Frank Morgner 6e84ee0ba7 pkcs11-tool: honour unsupported signature mechs 2015-04-12 11:28:25 +02:00
Philip Wendland fa045d44ec pkcs11-tool: Let the user choose the ECDSA signature format
Instead of hard-coding the format depending on whether OpenSC was compiled with
OpenSSL or not, the user should be able to choose the format himself.
The default format now is the normal concatenation of R,S both for CKM_ECDSA
and CKM_ECDSA_SHA1.
2015-04-04 22:01:22 +02:00
Philip Wendland 4b51b99748 pkcs11-tool: harmonize supported ECC curves
pkcs15-pubkey.c holds a struct containing supported ECC curves. The contents of
this struct are being harmonized with pkcs11-tool supported curves.
2015-03-29 12:55:54 +02:00
Frank Morgner bff0ea4837 fixed compiler warning 2015-02-20 19:54:40 +01:00
Frank Morgner 3a92bf7af5 fixed resource leaks 2015-02-05 01:38:41 +01:00
Frank Morgner ed9572422f check return values 2015-02-05 01:37:53 +01:00
Frank Morgner 6759c04b26 don't ignore errors 2015-01-28 04:45:08 +01:00
Frank Morgner 2e04fa99c1 fixed pointless array comparisons 2015-01-28 07:39:35 +01:00
Frank Morgner 6641cbf455 fixed potential string overflow 2015-01-24 20:17:26 +01:00
Frank Morgner 3f64d3a805 fixed bad memory allocation 2015-01-24 20:11:16 +01:00
Frank Morgner f143d7b73e Merge pull request #346 from frankmorgner/pkcs11provider
use OpenSC as default PKCS#11 provider
2015-01-20 23:43:48 +01:00
Andreas Schwier 3961275d8c Allow user to overwrite SO-PIN when using PIN-PAD reader 2014-12-29 13:39:37 +01:00
Frank Morgner 291e9dab9e use OpenSC as default PKCS#11 provider
closes #229
2014-12-19 22:27:34 +01:00
Frank Morgner a2ba4d3bae Merge pull request #319 from CardContact/add-sec-k-curves
sc-hsm: Add support for Koblitz curves secp192k1 and secp256k1 (Bitcoin)
2014-12-06 23:22:43 +01:00
Frank Morgner 4459e146c4 use util_get_pin in tools 2014-11-04 22:07:07 +01:00
Andreas Schwier d014056f1d sc-hsm: Add support for Koblitz curves secp192k1 and secp256k1 (Bitcoin) 2014-11-04 17:11:34 +01:00
Doug Engert 9a82a95132 Merge branch 'master' of github.com:OpenSC/OpenSC 2014-10-03 06:50:04 -05:00
Frank Morgner 5d6c4b391d Merge pull request #253 from github-frankmorgner/remove-deadcode
card-asepcos: removed dead code
card-authentic: removed dead code
card-belpic: removed dead code
card-epass2003: removed dead code
card-flex: removed dead code
card-gpk: removed dead code
card-oberthur: removed dead code
card-piv: removed dead code
card-setcos: removed dead code
ctbcs: removed dead code
cwa14890: removed dead code
muscle: removed dead code
pkcs15-atrust-acos: removed dead code
pkcs15-gemsafeV1: removed dead code
pkcs15-skey: removed dead code
reader-ctapi: removed dead code
framework-pkcs15: removed dead code
pkcs11-object: removed dead code
pkcs15-asepcos: removed dead code
pkcs15-cardos: removed dead code
pkcs15-jcop: removed dead code
pkcs15-lib: removed dead code
pkcs15-oberthur: removed dead code
parse: removed dead code
sclex: removed dead code
sm-card-authentic: removed dead code
sm-card-iasecc: removed dead code
sm-cwa14890: removed dead code
sm-global-platform: removed dead code
sc-test: removed dead code
pkcs11-tool: removed dead code
pkcs15-tool: removed dead code
2014-09-07 21:22:43 +02:00
Doug Engert 2de38a1230 pkcs11-tool sets CKA_DECRYPT=true rather then CKA_DERIVE=true when generating EC keys (#277)
RSA and EC keys have different usage attributes. Appropriate attributes are set
When using --keypairgen the user can use the --usage-sign, --usage-decrypt,
and --usage-derive. to get finer control.

 Changes to be committed:
	modified:   tools/pkcs11-tool.c
2014-08-26 09:59:40 -05:00
Henrik Andersson 1df8570a66 Add fence against using EVP_sha256 mech.
Which is only available in >=0.9.8
2014-05-14 22:11:25 +02: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
Nikos Mavrogiannopoulos ba66459f33 When setting pointers to a template, ensure they do not get out of scope prior of being used.
This was causing issues when using pkcs11-tool with opencryptoki:
https://bugzilla.redhat.com/show_bug.cgi?id=1062307

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
2014-04-21 20:47:39 +02:00
Ludovic Rousseau cdc379fa25 pkcs11-tool: check for buffer overflows
Check the subject, issuer and serialNumber will encode in the allocated
space before copying the data.

Thanks to Umberto Rustichelli for the bug report
https://sourceforge.net/p/opensc/mailman/message/32210626/
2014-04-10 16:40:12 +02:00
Viktor Tarasov 1775198ed7 pkcs11-tool: format object info output 2014-02-09 18:49:58 +01:00
Viktor Tarasov 687fdf2a60 pkcs11-tool: more token flags to display 2013-12-29 22:00:28 +01:00
Frank Morgner 1a65ed1ecf use _setmode instead of _set_fmode in windows
now compiles with MinGW-w64
2013-07-10 17:05:17 +02:00
Viktor Tarasov a24ecd0733 pkcs11-tool: ignore CRYPTOKI_ALREADY_INITIALIZED error
https://github.com/OpenSC/OpenSC/pull/118
Print warning and ignore 'Cryptoki library has already been initialized'  error
returned by C_Initialize().
2013-03-10 13:45:32 +01:00
mescheryakov1 f55bb019d9 Update src/tools/pkcs11-tool.c
fixed filling key type attr on writing object

pointer refers to local variable from destroyed stack frame
2013-01-27 18:37:45 +01:00
sjoblomt 457426543d MyEID ECDSA support 2012-12-03 14:37:13 +01:00
Anthony Foiani f63135afab tools: check return value after each call.
It seems that this suffered some copy and paste damage at some point.
Change so that we check each return value immediately after the API
call.

Signed-Off-By: Anthony Foiani <anthony.foiani@gmail.com>
2012-11-20 08:46:27 +01:00
Andreas Schwier fba298c6f4 pksc11: Added ability to indicate hardware and firmware version information at PKCS#11 interface 2012-10-21 15:51:55 +02:00
Andreas Schwier 1619a42375 ecc: Adding more curves 2012-10-01 13:04:02 +02:00
Andreas Schwier 02fe6d474b pkcs11-tool: Fixed issue with ID increment failing on constant data 2012-10-01 13:04:01 +02:00
Viktor Tarasov 628ead7e41 pkcs11-tool: suppress warnings about the missing attributes
when showing an object  do not print warnings about missing 'uncommon' attributes
2012-09-24 11:51:04 +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
Andreas Schwier 0fa6e7f977 pkcs11-tool: Added CKM_SHA256_RSA_PKCS to tests in test_signatures 2012-08-20 11:22:02 +02:00
Andreas Schwier efb4673ec8 Revert change to pkcs11-tool because of upstream changes in RSA signature tests
Fixed a typo that went undetected
2012-08-20 11:22:02 +02:00
Viktor Tarasov 8e8acf1ff6 pkcs11-tool: implement 'find mechanism from the given list'
and use it when testing signature
2012-08-20 11:22:02 +02:00
Andreas Schwier f678b68650 Activated ECDSA for SmartCard-HSM
Fixed issues in pkcs11-tool/test_signature is card has RSA and ECDSA keys
Fixed bug in sc_pkcs11_signature_size that returns the wrong ECDSA signature size
2012-08-20 11:22:02 +02:00
Viktor Tarasov cb54ebf747 pkcs11: #371: Public key create template should not include CKA_MODULUS_BITS
Thanks to 'z22' and Martin.
2012-08-16 16:00:35 +02:00
Viktor Tarasov 7e42c6d97d pkcs11-tool: #407: on Windows use O_BINARY open file mode
https://www.opensc-project.org/opensc/ticket/407
http://msdn.microsoft.com/en-us/library/ee2849wt%28v=VS.71%29.aspx
2012-08-15 23:15:06 +02:00
Viktor Tarasov dfbc3996bf pkcs11: #439: 'SEQUENCE' of 'SET' issue when comparing cert attributes
Thanks to 'crank'.
https://www.opensc-project.org/opensc/ticket/439

Some pkcs11 callers (i.e. netscape) will pass in the ASN.1 encoded SEQUENCE OF SET,
while OpenSC just keeps the SET in the issuer/subject field.
2012-08-15 19:59:09 +02:00
Viktor Tarasov 25f7bc5ac5 pkcs11-tool: implement 'find mechanism from the given list'
and use it when testing signature
2012-08-13 11:34:01 +02:00
Viktor Tarasov 2cff47d9b3 pkcs11-tool: support for secret-key objects
support of 'secret-key' objects
key conversion procedures are now in libopensc library
change name for OPENSC NON-REPUDIATION CKA attribute
2012-06-02 18:25:23 +02:00
Peter Marschall 367ebd94d4 tools: allow arguments to be printed in usage message
Extend util_print_usage_and_die() by a string argument that describes
further arguments to the program.

1st user: opensc-explorer
2012-05-30 09:39:12 +02:00
Viktor Tarasov cb13633634 remove trailing whitespaces
inspired by
http://www.opensc-project.org/pipermail/opensc-devel/2012-March/017883.html

Change-Id: If170e830d8d9587a31742feffb6fff54cfdf75b4
2012-04-03 00:00:56 +02:00
andre 8a5961e970 pkcs11-tool.c: At least CKS_RO_PUBLIC_SESSION is needed.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5563 c6295689-39f2-0310-b995-f0e70906c6a9
2011-06-08 08:50:42 +00:00
vtarasov a479c368a6 pkcs11-tool: allow non-interactive change of User/SO PIN
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5543 c6295689-39f2-0310-b995-f0e70906c6a9
2011-06-02 19:20:11 +00:00
vtarasov 3095f5479f pkcs11-tool: resolve compiler warning '"OPENSSL_VERSION_NUMBER" is not defined', thanks to Ludovic
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5536 c6295689-39f2-0310-b995-f0e70906c6a9
2011-06-02 17:12:12 +00:00
andre 31a56bb374 pkcs11-tool.c: Remove useless parameter 'slot' from a lot of function prototypes.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5533 c6295689-39f2-0310-b995-f0e70906c6a9
2011-06-01 18:51:26 +00:00
vtarasov 185e3f8259 pkcs11-tool: replace 'slot-label' argument with the two new ones -- 'slot-description' and 'token-label'...
the main difference between 'slot-description' and 'token-label' is that 
the first one is unique in any case, 
the second one can be the same for more then one slots.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5528 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-30 14:47:50 +00:00
vtarasov 8931231396 pkcs11-tool: show CKA_VALUE of the GOST public key object
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5527 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-30 13:28:16 +00:00
vtarasov 4d2428378d pkcs11-tool: CKA_VALUE of imported GOST key has to be presented in the little endian order
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5518 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-29 17:55:26 +00:00
andre 4a2dfa6822 pkcs11-tool.c: In function ‘sign_data’:
pkcs11-tool.c:1253: warning: comparison between signed and unsigned
pkcs11-tool.c: In function ‘write_object’:
pkcs11-tool.c:1777: warning: unused variable ‘type’


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5505 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-27 09:24:09 +00:00
vtarasov dd30eb1905 pkcs11-tool: import GOST key; key to import in DER or PEM format
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5465 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-22 10:52:44 +00:00
vtarasov cb39b2dcc9 pkcs11-tool: when doing signature try at first the procedure for the short input data ...
Not all PKCS#11 driver support the C_SignUpdate. 
So, for the short data begin with procedure "C_SignInit & C_Sign".
If no success, try to applicate the procedure "C_SignInit & C_SignUpdate & ... & C_SignFinal".


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5458 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-22 07:13:09 +00:00
martin 6277099a27 pkcs11-tool: correct typos about --login-type option, change id -> ID in help texts.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5448 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-17 13:27:13 +00:00
martin 18baf42780 pkcs11-tool: move --module to the first position in help text and make it mandatory.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5447 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-17 13:27:09 +00:00
andre 85b40a553c pkcs11-tool.c:54: warning: missing initializer
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5425 c6295689-39f2-0310-b995-f0e70906c6a9
2011-05-04 16:45:51 +00:00
vtarasov e430fe9d87 pkcs11-tool: add test procedure for EC keys ...
... for a while it includes key generation and data signing.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5383 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-21 16:18:23 +00:00
vtarasov c2a87ae2b1 pkcs11-tool: prepare 'gen_keypair' procedure to generate also the EC keys ...
... 'prime256v1' and 'secp384r1'


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5381 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-21 14:29:51 +00:00
andre 9026ea6f3f pkcs11-tool.c: Avoid warning:
pkcs11-tool.c:1978: warning: ‘getPUBLIC_EXPONENT’ defined but not used

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5374 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-19 13:03:49 +00:00
andre 6409755bea pkcs11-tool.c: Avoid warning:
pkcs11-tool.c:2000: warning: comparison between signed and unsigned


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5363 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-19 09:18:12 +00:00
vtarasov e8f6a3e407 pkcs11-tool: now it's possible to show only the objects of a given type ...
when 'type' option is used with the 'list-objects' actions


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5325 c6295689-39f2-0310-b995-f0e70906c6a9
2011-04-11 13:00:57 +00:00
andre 02c4f1ec77 pkcs11-tool.c: Avoid compiler warning 'may be used uninitialized in this function'.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4968 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-18 00:44:12 +00:00
andre b7fad04e10 pkcs11-tool.c: Simplifies interface to show_key() and avoids more compiler warnings.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4967 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-17 23:02:03 +00:00
andre 548630971e pkcs11-tool: replaced OPENSSL_NO_EDSA with OPENSSL_NO_ECDSA
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4922 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-06 16:28:26 +00:00
martin b5f329ba7c tools: EC(DSA) requires OpenSSL >= 0.9.8.
This fixes building for OS X 10.5.

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4918 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-06 14:41:15 +00:00
dengert b7f4537031 Test for OPENSSL_NO_EC as some systems build OPENSSL without EC.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4906 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-03 15:15:29 +00:00
dengert c2fe4609a9 Modifications to support EC and ECDSA for
emulated cards. True PKCS#15 cards with EC 
will need additional changes. 

Main changes are in framework-pkcs15.c, mechanism.c,
padding.c, pkcs15-algo.c and pkcs15-sec.c 
where switch statements for key type, and testing
of flags was modified to make it easier to add 
additional key types in the future. 

The code was tested using RSA and ECDSA using a PIV card 
from pkcs11-tool, OpenSSL and Thunderbird with 
modifications to NSS-3.12.7 to get ECDSA to sign e-mail. 

Only named curves are supported for ECDSA, ECDH is still 
needed. pkcs11-tool has only minimal changes need to work 
with the -O option to list EC keys. 

One additional line was added to pkcs15-sec.c which 
should get GOSTR sign to work. 

libp11 and engine do not yet have EC support. 

 --This line, and those below, will be ignored--

M    src/tools/piv-tool.c
M    src/tools/pkcs11-tool.c
M    src/pkcs11/framework-pkcs15.c
M    src/pkcs11/mechanism.c
M    src/pkcs11/pkcs11-object.c
M    src/libopensc/pkcs15-prkey.c
M    src/libopensc/card-piv.c
M    src/libopensc/padding.c
M    src/libopensc/cardctl.h
M    src/libopensc/pkcs15-algo.c
M    src/libopensc/libopensc.exports
M    src/libopensc/pkcs15-piv.c
M    src/libopensc/pkcs15-sec.c


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4904 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-01 20:08:42 +00:00
andre fd11c909bd pkcs11-tool: Completing the output of "Mechanism Information Flags".
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4885 c6295689-39f2-0310-b995-f0e70906c6a9
2010-11-28 23:46:12 +00:00
andre 146041fcee pkcs11-tool: Correcting the behaviour in the case where C_SignUpdate fails. Quotation from PKCS#11:
"A call to C_SignUpdate which results in an error terminates the current signature operation."

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4884 c6295689-39f2-0310-b995-f0e70906c6a9
2010-11-28 22:16:50 +00:00
andre b63a601666 pkcs11-tool: Use attributes MODULUS and PUBLIC_EXPONENT instead of VALUE to retrieve RSA-Public-Key. The first two attributes are valid whereas the latter is not.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4883 c6295689-39f2-0310-b995-f0e70906c6a9
2010-11-28 18:09:30 +00:00
andre bcef13cfd2 In login() the flag CKF_LOGIN_REQUIRED is now ignored. This makes the behaviour of login() more predictable. If parameter --login is specified on the command line, then C_Login() is always called.fixes #220
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4875 c6295689-39f2-0310-b995-f0e70906c6a9
2010-11-18 14:56:26 +00:00
martin 364ba4882d pkcs11-tool: handle non-recognized tokens gracefully.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4803 c6295689-39f2-0310-b995-f0e70906c6a9
2010-10-08 08:36:56 +00:00
martin fad0116fef pkcs11-tool: if no slot is specified on the command line, try to locate a slot with a token.
A modified patch from Andre Zepezauer.

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4802 c6295689-39f2-0310-b995-f0e70906c6a9
2010-10-08 08:36:48 +00:00
martin f339f9ba77 pkcs11-tool: only do hotplug testing before other activities.
Thanks to Andre Zepezauer for noticing.

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4765 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-24 07:24:43 +00:00
martin 3202355fa3 pkcs11-tool: print the token before asking for a PIN code; shorten CKU_CONTEXT_SPECIFIC prompt
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4751 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-21 16:11:49 +00:00
martin 01931d6794 pkcs11-tool: do --test even without a slot, at least hotplug. print a proper error name for C_GetSlotInfo
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4750 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-21 16:11:44 +00:00
martin 294a8bca3d pkcs11-tool: pkcs11-tool --verbose does not affect OpenSC debugging. Document a workaround
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4748 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-21 16:11:36 +00:00
martin 50952cdcba pkcs11-tool: cleanup whitespace and remove unused OpenSSL ERR_* calls.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4747 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-21 16:11:31 +00:00
martin 2dff969e05 pkcs11-tool: better separation between opaqe slot IDs and slot list indexes.
--slot will take the actual CK_SLOT_ID
--slot-label will use the token label to find the correct slot
--slot-index will use the N-th slot from the list returned by C_GetSlotList

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4746 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-21 16:11:26 +00:00
martin 7a66f4e339 pkcs11-tool: recognize user PIN related token flags
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4691 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-05 16:53:02 +00:00