|
|
b32e24 |
From f28dc082ad7a7a431d1b66a0de87b5e484fe08b9 Mon Sep 17 00:00:00 2001
|
|
|
b32e24 |
From: Ingo Tuchscherer <ingo.tuchscherer@linux.vnet.ibm.com>
|
|
|
b32e24 |
Date: Tue, 21 Oct 2014 10:00:52 -0500
|
|
|
b32e24 |
Subject: [PATCH 1/2] pkcsep11_migrate: Fixed parameter handling for
|
|
|
b32e24 |
pkcsep11_migrate tool - Hexadecimal values allowed for input
|
|
|
b32e24 |
parameters - Non digit input parameters will be rejected
|
|
|
b32e24 |
- Extended Error messages with ock error strings -
|
|
|
b32e24 |
improved man-page
|
|
|
b32e24 |
|
|
|
b32e24 |
Signed-off-by: Ingo Tuchscherer <ingo.tuchscherer@linux.vnet.ibm.com>
|
|
|
b32e24 |
---
|
|
|
b32e24 |
man/man1/pkcsep11_migrate.1.in | 8 +++++--
|
|
|
b32e24 |
usr/sbin/pkcsep11_migrate/Makefile.am | 4 ++--
|
|
|
b32e24 |
usr/sbin/pkcsep11_migrate/pkcsep11_migrate.c | 36 +++++++++++++++++++---------
|
|
|
b32e24 |
3 files changed, 33 insertions(+), 15 deletions(-)
|
|
|
b32e24 |
|
|
|
b32e24 |
diff --git a/man/man1/pkcsep11_migrate.1.in b/man/man1/pkcsep11_migrate.1.in
|
|
|
b32e24 |
index 0dffb1b..d1b21b0 100644
|
|
|
b32e24 |
--- a/man/man1/pkcsep11_migrate.1.in
|
|
|
b32e24 |
+++ b/man/man1/pkcsep11_migrate.1.in
|
|
|
b32e24 |
@@ -25,8 +25,8 @@ Trusted Key Entry console (TKE) before using this utility.
|
|
|
b32e24 |
.br
|
|
|
b32e24 |
3. Before using this tool make a back-up of the token objects in ep11tok/TOK_OBJ/.
|
|
|
b32e24 |
.br
|
|
|
b32e24 |
-4. After successfully appling the utility and before (re)starting programs
|
|
|
b32e24 |
-using the EP11 token the new master key must be activated using the TKE.
|
|
|
b32e24 |
+4. After successfully execution of the migrate utility and before (re)starting
|
|
|
b32e24 |
+ programs using the EP11 token the new master key must be activated using the TKE.
|
|
|
b32e24 |
|
|
|
b32e24 |
.SH "COMMAND SUMMARY"
|
|
|
b32e24 |
.IP "\fB-slot\fP \fIslot-number\fP" 10
|
|
|
b32e24 |
@@ -35,8 +35,12 @@ specifies the token slot of the EP11 token
|
|
|
b32e24 |
specifies an EP11 adapter ID.
|
|
|
b32e24 |
(Refer to lszcrypt to get a list of installed crypto adapters.
|
|
|
b32e24 |
The adapter ID will be the number xx in 'card\fBxx\fP' from the output.)
|
|
|
b32e24 |
+This value can be provided either in hexadecimal (e.g. 0x0A) or decimal (10)
|
|
|
b32e24 |
+notation.
|
|
|
b32e24 |
.IP "\fB-domain\fP \fIdomain-ID\fP" 10
|
|
|
b32e24 |
specifies the usage domain for the EP11 adapter. (see /sys/bus/ap/ap_domain.)
|
|
|
b32e24 |
+This value can be provided either in hexadecimal (e.g. 0x0B) or decimal (11)
|
|
|
b32e24 |
+notation.
|
|
|
b32e24 |
.IP "\fB-h\fP" 10
|
|
|
b32e24 |
show usage information
|
|
|
b32e24 |
|
|
|
b32e24 |
diff --git a/usr/sbin/pkcsep11_migrate/Makefile.am b/usr/sbin/pkcsep11_migrate/Makefile.am
|
|
|
b32e24 |
index 49deb74..b43756c 100644
|
|
|
b32e24 |
--- a/usr/sbin/pkcsep11_migrate/Makefile.am
|
|
|
b32e24 |
+++ b/usr/sbin/pkcsep11_migrate/Makefile.am
|
|
|
b32e24 |
@@ -1,9 +1,9 @@
|
|
|
b32e24 |
sbin_PROGRAMS=pkcsep11_migrate
|
|
|
b32e24 |
|
|
|
b32e24 |
-pkcsep11_migrate_SOURCES = pkcsep11_migrate.c
|
|
|
b32e24 |
+pkcsep11_migrate_SOURCES = ../../lib/pkcs11/common/p11util.c pkcsep11_migrate.c
|
|
|
b32e24 |
pkcsep11_migrate_CFLAGS = -I ../../include/pkcs11/ -I../../lib/pkcs11/ep11_stdll/ -DLINUX -DPROGRAM_NAME=\"$(@)\"
|
|
|
b32e24 |
pkcsep11_migrate_LDFLAGS = -lc -ldl -lpthread
|
|
|
b32e24 |
-INCLUDES = -I.
|
|
|
b32e24 |
+INCLUDES = -I. -I../../lib/pkcs11/common
|
|
|
b32e24 |
|
|
|
b32e24 |
# Not all versions of automake observe sbinname_CFLAGS
|
|
|
b32e24 |
# AM_CFLAGS = -DLINUX -DPROGRAM_NAME=\"$(@)\"
|
|
|
b32e24 |
diff --git a/usr/sbin/pkcsep11_migrate/pkcsep11_migrate.c b/usr/sbin/pkcsep11_migrate/pkcsep11_migrate.c
|
|
|
b32e24 |
index aa1c3f1..4325b9d 100644
|
|
|
b32e24 |
--- a/usr/sbin/pkcsep11_migrate/pkcsep11_migrate.c
|
|
|
b32e24 |
+++ b/usr/sbin/pkcsep11_migrate/pkcsep11_migrate.c
|
|
|
b32e24 |
@@ -17,6 +17,7 @@
|
|
|
b32e24 |
#include <pkcs11types.h>
|
|
|
b32e24 |
#include <ep11.h>
|
|
|
b32e24 |
#include <ep11adm.h>
|
|
|
b32e24 |
+#include <p11util.h>
|
|
|
b32e24 |
|
|
|
b32e24 |
#define EP11SHAREDLIB "libep11.so"
|
|
|
b32e24 |
#define PKCS11_MAX_PIN_LEN 128
|
|
|
b32e24 |
@@ -180,16 +181,16 @@ check_card_status()
|
|
|
b32e24 |
|
|
|
b32e24 |
if (rc != CKR_OK)
|
|
|
b32e24 |
{
|
|
|
b32e24 |
- fprintf(stderr,"m_get_ep11_info rc %lx, valid apapter/domain %lx/%lx?.\n",
|
|
|
b32e24 |
+ fprintf(stderr,"m_get_ep11_info rc 0x%lx, valid apapter/domain 0x%02lx/%ld?.\n",
|
|
|
b32e24 |
rc,adapter,domain);
|
|
|
b32e24 |
return -1;
|
|
|
b32e24 |
}
|
|
|
b32e24 |
|
|
|
b32e24 |
if (CK_IBM_DOM_COMMITTED_NWK & dinf.flags) {
|
|
|
b32e24 |
- fprintf(stderr,"Card ID %ld, domain ID %ld has committed pending(next) WK\n",
|
|
|
b32e24 |
+ fprintf(stderr,"Card ID 0x%02lx, domain ID %ld has committed pending(next) WK\n",
|
|
|
b32e24 |
adapter, domain);
|
|
|
b32e24 |
} else {
|
|
|
b32e24 |
- fprintf(stderr,"Card ID %ld, domain ID %ld has no committed pending WK\n",
|
|
|
b32e24 |
+ fprintf(stderr,"Card ID 0x%02lx, domain ID %ld has no committed pending WK\n",
|
|
|
b32e24 |
adapter, domain);
|
|
|
b32e24 |
return -1;
|
|
|
b32e24 |
}
|
|
|
b32e24 |
@@ -277,15 +278,27 @@ do_ParseArgs(int argc, char **argv)
|
|
|
b32e24 |
return 0;
|
|
|
b32e24 |
}
|
|
|
b32e24 |
else if (strcmp (argv[i], "-slot") == 0) {
|
|
|
b32e24 |
- SLOT_ID = atoi (argv[i+1]);
|
|
|
b32e24 |
+ if (!isdigit(*argv[i+1])) {
|
|
|
b32e24 |
+ printf("Slot parameter is not numeric!\n");
|
|
|
b32e24 |
+ return -1;
|
|
|
b32e24 |
+ }
|
|
|
b32e24 |
+ SLOT_ID = (int)strtol(argv[i+1], NULL, 0);
|
|
|
b32e24 |
i++;
|
|
|
b32e24 |
}
|
|
|
b32e24 |
else if (strcmp (argv[i], "-adapter") == 0) {
|
|
|
b32e24 |
- adapter = atoi (argv[i+1]);
|
|
|
b32e24 |
+ if (!isdigit(*argv[i+1])) {
|
|
|
b32e24 |
+ printf("Adapter parameter is not numeric!\n");
|
|
|
b32e24 |
+ return -1;
|
|
|
b32e24 |
+ }
|
|
|
b32e24 |
+ adapter = (int)strtol(argv[i+1], NULL, 0);
|
|
|
b32e24 |
i++;
|
|
|
b32e24 |
}
|
|
|
b32e24 |
else if (strcmp (argv[i], "-domain") == 0) {
|
|
|
b32e24 |
- domain = atoi (argv[i+1]);
|
|
|
b32e24 |
+ if (!isdigit(*argv[i+1])) {
|
|
|
b32e24 |
+ printf("Domain parameter is not numeric!\n");
|
|
|
b32e24 |
+ return -1;
|
|
|
b32e24 |
+ }
|
|
|
b32e24 |
+ domain = (int)strtol(argv[i+1], NULL, 0);
|
|
|
b32e24 |
i++;
|
|
|
b32e24 |
}
|
|
|
b32e24 |
else {
|
|
|
b32e24 |
@@ -374,7 +387,7 @@ int main (int argc, char **argv){
|
|
|
b32e24 |
rc = funcs->C_OpenSession(SLOT_ID, flags,
|
|
|
b32e24 |
NULL, NULL, &session );
|
|
|
b32e24 |
if (rc != CKR_OK) {
|
|
|
b32e24 |
- fprintf(stderr,"C_OpenSession() rc = %x\n",rc);
|
|
|
b32e24 |
+ fprintf(stderr,"C_OpenSession() rc = 0x%02x [%s]\n",rc, p11_get_ckr(rc));
|
|
|
b32e24 |
session = CK_INVALID_HANDLE;
|
|
|
b32e24 |
return rc;
|
|
|
b32e24 |
}
|
|
|
b32e24 |
@@ -384,7 +397,7 @@ int main (int argc, char **argv){
|
|
|
b32e24 |
fprintf(stderr,"get_user_pin() failed\n");
|
|
|
b32e24 |
rc = funcs->C_CloseAllSessions(SLOT_ID);
|
|
|
b32e24 |
if (rc != CKR_OK)
|
|
|
b32e24 |
- fprintf(stderr,"C_CloseAllSessions() rc = %x\n",rc);
|
|
|
b32e24 |
+ fprintf(stderr,"C_CloseAllSessions() rc = 0x%02x [%s]\n",rc, p11_get_ckr(rc));
|
|
|
b32e24 |
return rc;
|
|
|
b32e24 |
}
|
|
|
b32e24 |
|
|
|
b32e24 |
@@ -392,7 +405,7 @@ int main (int argc, char **argv){
|
|
|
b32e24 |
rc = funcs->C_Login(session, CKU_USER,
|
|
|
b32e24 |
user_pin, user_pin_len);
|
|
|
b32e24 |
if (rc != CKR_OK) {
|
|
|
b32e24 |
- fprintf(stderr,"C_Login() rc = %x\n",rc);
|
|
|
b32e24 |
+ fprintf(stderr,"C_Login() rc = 0x%02x [%s]\n",rc, p11_get_ckr(rc));
|
|
|
b32e24 |
return rc;
|
|
|
b32e24 |
}
|
|
|
b32e24 |
|
|
|
b32e24 |
@@ -410,7 +423,7 @@ int main (int argc, char **argv){
|
|
|
b32e24 |
|
|
|
b32e24 |
if (rc != CKR_OK)
|
|
|
b32e24 |
{
|
|
|
b32e24 |
- fprintf(stderr,"C_FindObjects() rc = %x\n",rc);
|
|
|
b32e24 |
+ fprintf(stderr,"C_FindObjects() rc = 0x%02x [%s]\n",rc, p11_get_ckr(rc));
|
|
|
b32e24 |
return rc;
|
|
|
b32e24 |
}
|
|
|
b32e24 |
|
|
|
b32e24 |
@@ -443,7 +456,8 @@ int main (int argc, char **argv){
|
|
|
b32e24 |
|
|
|
b32e24 |
if (rc != CKR_OK)
|
|
|
b32e24 |
{
|
|
|
b32e24 |
- fprintf(stderr,"second C_GetAttributeValue failed %x\n",rc);
|
|
|
b32e24 |
+ fprintf(stderr,"second C_GetAttributeValue failed rc = 0x%02x [%s]\n",
|
|
|
b32e24 |
+ rc, p11_get_ckr(rc));
|
|
|
b32e24 |
return rc;
|
|
|
b32e24 |
}
|
|
|
b32e24 |
else
|
|
|
b32e24 |
--
|
|
|
b32e24 |
2.1.0
|
|
|
b32e24 |
|