Commit Graph

161 Commits

Author SHA1 Message Date
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
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 13a42de128 pkcs11 tool: fix messages
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4593 c6295689-39f2-0310-b995-f0e70906c6a9
2010-07-21 09:50:10 +00:00
viktor.tarasov 1090d19d30 #60: pkcs11-tool: print key sizes from CK_MECHANISM_INFO
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4513 c6295689-39f2-0310-b995-f0e70906c6a9
2010-07-05 14:43:31 +00:00
viktor.tarasov 3c813ce57b pkcs15-init tool: use Ctrl-C sensible 'getpass'
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4252 c6295689-39f2-0310-b995-f0e70906c6a9
2010-04-18 09:45:44 +00:00
viktor.tarasov a10bf0e356 pkcs11-tool: #120: use 'getpass' sensible to Ctrl-C, thanks to Andreas
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4251 c6295689-39f2-0310-b995-f0e70906c6a9
2010-04-18 08:32:35 +00:00
viktor.tarasov f7575879cc pkcs11-tool: useless assignment
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4248 c6295689-39f2-0310-b995-f0e70906c6a9
2010-04-18 07:30:21 +00:00
viktor.tarasov ce485e4895 pkcs11-tool: fix #124; thanks to Thomas Harnings: for the signature tests cannot be used private key without corresponding public key or certificate
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4247 c6295689-39f2-0310-b995-f0e70906c6a9
2010-04-17 19:59:32 +00:00
viktor.tarasov 741d8fc0b8 pkcs11-tool: #75: key for signature can be selected by object_id
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4214 c6295689-39f2-0310-b995-f0e70906c6a9
2010-04-11 17:44:39 +00:00
ludovic.rousseau 6add573782 Do not cast to a possibly different type size.
Would fail on PowerPC in 64-bits for example.

Fix pkcs11-tool.c:2954: warning: dereferencing type-punned pointer will
break strict-aliasing rules


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4174 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-28 20:40:13 +00:00
ludovic.rousseau 5be62d9d67 Use a "const char *" to store a const C-string ptr.
Fix
pkcs11-tool.c:1899: warning: assignment discards qualifiers from pointer target type
pkcs11-tool.c:1902: warning: assignment discards qualifiers from pointer target type
pkcs11-tool.c:1906: warning: assignment discards qualifiers from pointer target type
pkcs11-tool.c:1910: warning: assignment discards qualifiers from pointer target type
pkcs11-tool.c:1914: warning: assignment discards qualifiers from pointer target type
pkcs11-tool.c:1918: warning: assignment discards qualifiers from pointer target type
pkcs11-tool.c:1922: warning: assignment discards qualifiers from pointer target type


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4173 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-28 20:30:25 +00:00
ludovic.rousseau 30b7888c34 Remove unused variables. Fix warning: unused variable
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4157 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-28 11:43:17 +00:00
viktor.tarasov 42b90f8ada pkcs11-tool: to be compiled without OpenSSL
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4136 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-18 10:49:53 +00:00
aj 84934adab9 don't complain about missing "--slot" parameter, when you don't
need it (if you only "--list-slots").


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4122 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-16 14:59:20 +00:00
aj 5972022ffc Add code to write pubkey objects to pkcs11-tool.
By: Jaroslav Benkovský <jaroslav.benkovsky@nic.cz>

Slightly modified by me.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4121 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-16 14:11:39 +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 875fe4a50f pkcs11-tool: test hotplug partial commit fix + make a slot ID mandatory and parse it as an unsigned long, not int.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3911 c6295689-39f2-0310-b995-f0e70906c6a9
2010-01-15 09:36:00 +00:00
martin c5effc32c3 pkcs11-tool: test hotplugging and events (C_GetSlotList/C_WaitForSlotEvent) before others tests and only if --hotplug is given
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3910 c6295689-39f2-0310-b995-f0e70906c6a9
2010-01-15 09:33:27 +00:00
martin cc5c03197d pkcs11-tool: Check for CKA_ALWAYS_AUTHENTICATE and CKU_CONTEXT_SPECIFIC login for --test operations.
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3909 c6295689-39f2-0310-b995-f0e70906c6a9
2010-01-15 09:27:17 +00:00
martin e595042474 pkcs11-tool: Call C_Finalize when a fatal error happens. (Otherwise OSX pcsc locks up)
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3908 c6295689-39f2-0310-b995-f0e70906c6a9
2010-01-15 09:22:03 +00:00
viktor.tarasov e2dae6b97b Unlock User PIN with PKCS#11:
One of the three unblock methods can be activated from the 'opensc-pkcs11' section of opensc.conf:
- C_SetPin() in the unlogged sesssion;
- C_SetPin() in the CKU_SPECIFIC_CONTEXT session;
- C_InitPin() in CKU_SO session (inspired by Pierre Ossman).
-- This last one works, for a while, only for the pkcs15 cards without SOPIN auth object.
   For the pkcs15 cards with SOPIN, this method will be useful for the cards 
   that do not have then modes '00' and '01' of ISO command 'RESET RETRY COUNTER'.

Test commands:
# pkcs11-tool --module ./opensc-pkcs11.so --slot 0 --unlock-pin --puk "123456" --new-pin "9999"
# pkcs11-tool --module ./opensc-pkcs11.so --slot 0 --unlock-pin -l --login-type context-specific --puk "123456" --new-pin "9999"
# pkcs11-tool --module ./opensc-pkcs11.so --slot 0 --init-pin -l --new-pin "9999"



git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3901 c6295689-39f2-0310-b995-f0e70906c6a9
2010-01-08 15:41:07 +00:00
s e4780e82ec add to pkcs11-tool: GOST mechanisms and GOSTR3410 key to show objects on token
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3869 c6295689-39f2-0310-b995-f0e70906c6a9
2009-11-27 11:15:33 +00:00
martin f2d6ec2c76 Always print the slot description (reader name in case of OpenSC)
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3867 c6295689-39f2-0310-b995-f0e70906c6a9
2009-11-25 18:01:30 +00:00
martin 56fb57603b Merge [3758:3783/trunk]
git-svn-id: https://www.opensc-project.org/svnp/opensc/branches/martin/0.12@3785 c6295689-39f2-0310-b995-f0e70906c6a9
2009-10-22 09:18:16 +00:00
martin 6a48771ce1 Implement CKA_ALWAYS_AUTHENTICATE
git-svn-id: https://www.opensc-project.org/svnp/opensc/branches/martin/0.12@3722 c6295689-39f2-0310-b995-f0e70906c6a9
2009-09-14 08:51:53 +00:00