[pkg-opensc-commit] [opensc] 02/50: tools: print OpenSC package version

Eric Dorland eric at moszumanska.debian.org
Sat May 28 03:35:45 UTC 2016


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository opensc.

commit 4b51d70969450a946ab3a9e2e6f4efe6bbf6d9d1
Author: Viktor Tarasov <viktor.tarasov at gmail.com>
Date:   Mon Mar 28 20:41:19 2016 +0200

    tools: print OpenSC package version
---
 doc/tools/pkcs15-crypt.1.xml |  6 +++++
 doc/tools/pkcs15-init.1.xml  |  6 +++++
 doc/tools/pkcs15-tool.1.xml  |  6 +++++
 src/tools/pkcs15-crypt.c     | 14 +++++++++-
 src/tools/pkcs15-init.c      | 10 +++++++
 src/tools/pkcs15-tool.c      | 64 +++++++++++++++++++++++++++-----------------
 6 files changed, 80 insertions(+), 26 deletions(-)

diff --git a/doc/tools/pkcs15-crypt.1.xml b/doc/tools/pkcs15-crypt.1.xml
index 5418d4b..9200330 100644
--- a/doc/tools/pkcs15-crypt.1.xml
+++ b/doc/tools/pkcs15-crypt.1.xml
@@ -34,6 +34,12 @@
 		<title>Options</title>
 		<para>
 			<variablelist>
+                                <varlistentry>
+                                        <term>
+                                                <option>--version</option>,
+                                        </term>
+                                        <listitem><para>Print the OpenSC package release version.</para></listitem>
+                                </varlistentry>
 				<varlistentry>
 					<term>
 						<option>--aid</option> <replaceable>aid</replaceable>
diff --git a/doc/tools/pkcs15-init.1.xml b/doc/tools/pkcs15-init.1.xml
index c21d35a..8f396c2 100644
--- a/doc/tools/pkcs15-init.1.xml
+++ b/doc/tools/pkcs15-init.1.xml
@@ -239,6 +239,12 @@
 		<title>Options</title>
 		<para>
 			<variablelist>
+                                <varlistentry>
+                                        <term>
+                                                <option>--version</option>,
+                                        </term>
+                                        <listitem><para>Print the OpenSC package release version.</para></listitem>
+                                </varlistentry>
 				<varlistentry>
 					<term>
 						<option>--card-profile</option> <replaceable>name</replaceable>,
diff --git a/doc/tools/pkcs15-tool.1.xml b/doc/tools/pkcs15-tool.1.xml
index 79b0e50..8eb25ca 100644
--- a/doc/tools/pkcs15-tool.1.xml
+++ b/doc/tools/pkcs15-tool.1.xml
@@ -38,6 +38,12 @@
 			<variablelist>
                                 <varlistentry>
                                         <term>
+                                                <option>--version</option>,
+                                        </term>
+                                        <listitem><para>Print the OpenSC package release version.</para></listitem>
+                                </varlistentry>
+                                <varlistentry>
+                                        <term>
 						<option>--aid</option> <replaceable>aid</replaceable>
 					</term>
                                         <listitem><para>Specify in a hexadecimal form the AID of the on-card PKCS#15
diff --git a/src/tools/pkcs15-crypt.c b/src/tools/pkcs15-crypt.c
index e4e4375..13e3c3a 100644
--- a/src/tools/pkcs15-crypt.c
+++ b/src/tools/pkcs15-crypt.c
@@ -58,9 +58,11 @@ enum {
 	OPT_MD5,
 	OPT_PKCS1,
 	OPT_BIND_TO_AID,
+	OPT_VERSION,
 };
 
 static const struct option options[] = {
+	{ "version",		0, NULL,		OPT_VERSION },
 	{ "sign",		0, NULL,		's' },
 	{ "decipher",		0, NULL,		'c' },
 	{ "key",		1, NULL,		'k' },
@@ -354,8 +356,9 @@ int main(int argc, char * const argv[])
 	int err = 0, r, c, long_optind = 0;
 	int do_decipher = 0;
 	int do_sign = 0;
+	int do_print_version = 0;
 	int action_count = 0;
-        struct sc_pkcs15_object *key;
+	struct sc_pkcs15_object *key;
 	sc_context_param_t ctx_param;
 
 	while (1) {
@@ -365,6 +368,10 @@ int main(int argc, char * const argv[])
 		if (c == '?')
 			util_print_usage_and_die(app_name, options, option_help, NULL);
 		switch (c) {
+		case OPT_VERSION:
+			do_print_version = 1;
+			action_count++;
+			break;
 		case 's':
 			do_sign++;
 			action_count++;
@@ -430,6 +437,11 @@ int main(int argc, char * const argv[])
 	if (action_count == 0)
 		util_print_usage_and_die(app_name, options, option_help, NULL);
 
+	if (do_print_version)   {
+		printf("%s\n", OPENSC_SCM_REVISION);
+		action_count--;
+	}
+
 	if (!(opt_crypt_flags & SC_ALGORITHM_RSA_HASHES))
 		opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_NONE;
 
diff --git a/src/tools/pkcs15-init.c b/src/tools/pkcs15-init.c
index eb45dde..8abf14f 100644
--- a/src/tools/pkcs15-init.c
+++ b/src/tools/pkcs15-init.c
@@ -139,6 +139,7 @@ enum {
 	OPT_ERASE_APPLICATION,
 	OPT_IGNORE_CA_CERTIFICATES,
 	OPT_UPDATE_EXISTING,
+	OPT_VERSION,
 
 	OPT_PIN1     = 0x10000,	/* don't touch these values */
 	OPT_PUK1     = 0x10001,
@@ -150,6 +151,7 @@ enum {
 };
 
 const struct option	options[] = {
+	{ "version",		0, NULL,			OPT_VERSION },
 	{ "erase-card",		no_argument, NULL,		'E' },
 	{ "create-pkcs15",	no_argument, NULL,		'C' },
 	{ "store-pin",		no_argument, NULL,		'P' },
@@ -211,6 +213,7 @@ const struct option	options[] = {
 	{ NULL, 0, NULL, 0 }
 };
 static const char *		option_help[] = {
+	"Print OpenSC package version",
 	"Erase the smart card",
 	"Creates a new PKCS #15 structure",
 	"Store a new PIN/PUK on the card",
@@ -287,6 +290,7 @@ enum {
 	ACTION_SANITY_CHECK,
 	ACTION_UPDATE_LAST_UPDATE,
 	ACTION_ERASE_APPLICATION,
+	ACTION_PRINT_VERSION,
 
 	ACTION_MAX
 };
@@ -525,6 +529,9 @@ main(int argc, char **argv)
 			printf("About to %s.\n", action_names[action]);
 
 		switch (action) {
+		case ACTION_PRINT_VERSION:
+			printf("%s\n", OPENSC_SCM_REVISION);
+			break;
 		case ACTION_ASSERT_PRISTINE:
 			/* skip printing error message */
 			if ((r = do_assert_pristine(card)) < 0)
@@ -2552,6 +2559,9 @@ handle_option(const struct option *opt)
 	case OPT_UPDATE_EXISTING:
 		opt_update_existing = 1;
 		break;
+	case OPT_VERSION:
+		this_action = ACTION_PRINT_VERSION;
+		break;
 	default:
 		util_print_usage_and_die(app_name, options, option_help, NULL);
 	}
diff --git a/src/tools/pkcs15-tool.c b/src/tools/pkcs15-tool.c
index fe1ca69..595b141 100644
--- a/src/tools/pkcs15-tool.c
+++ b/src/tools/pkcs15-tool.c
@@ -84,6 +84,7 @@ enum {
 	OPT_LIST_SKEYS,
 	OPT_NO_PROMPT,
 	OPT_RAW,
+	OPT_PRINT_VERSION
 };
 
 #define NELEMENTS(x)	(sizeof(x)/sizeof((x)[0]))
@@ -91,6 +92,7 @@ enum {
 static int	authenticate(sc_pkcs15_object_t *obj);
 
 static const struct option options[] = {
+	{ "version",		0, NULL,			OPT_PRINT_VERSION },
 	{ "learn-card",		no_argument, NULL,		'L' },
 	{ "list-applications",	no_argument, NULL,		OPT_LIST_APPLICATIONS },
 	{ "read-certificate",	required_argument, NULL,	'r' },
@@ -103,7 +105,7 @@ static const struct option options[] = {
 	{ "dump",		no_argument, NULL,		'D' },
 	{ "unblock-pin",	no_argument, NULL,		'u' },
 	{ "change-pin",		no_argument, NULL,		OPT_CHANGE_PIN },
-	{ "list-keys",          no_argument, NULL,		'k' },
+	{ "list-keys",		no_argument, NULL,		'k' },
 	{ "list-public-keys",	no_argument, NULL,		OPT_LIST_PUB },
 	{ "read-public-key",	required_argument, NULL,	OPT_READ_PUB },
 #if defined(ENABLE_OPENSSL) && (defined(_WIN32) || defined(HAVE_INTTYPES_H))
@@ -113,7 +115,7 @@ static const struct option options[] = {
 	{ "test-update",	no_argument, NULL,		'T' },
 	{ "update",		no_argument, NULL,		'U' },
 	{ "reader",		required_argument, NULL,	OPT_READER },
-	{ "pin",                required_argument, NULL,	OPT_PIN },
+	{ "pin",		required_argument, NULL,	OPT_PIN },
 	{ "new-pin",		required_argument, NULL,	OPT_NEWPIN },
 	{ "puk",		required_argument, NULL,	OPT_PUK },
 	{ "verify-pin",		no_argument, NULL,		OPT_VERIFY_PIN },
@@ -128,6 +130,7 @@ static const struct option options[] = {
 };
 
 static const char *option_help[] = {
+	"Print OpenSC package version",
 	"Stores card info to cache",
 	"List the on-card PKCS#15 applications",
 	"Reads certificate with ID <arg>",
@@ -241,7 +244,7 @@ static void print_cert_info(const struct sc_pkcs15_object *obj)
 
 	print_access_rules(obj->access_rules, SC_PKCS15_MAX_ACCESS_RULES);
 
-        rv = sc_pkcs15_read_certificate(p15card, cert_info, &cert_parsed);
+	rv = sc_pkcs15_read_certificate(p15card, cert_info, &cert_parsed);
 	if (rv >= 0 && cert_parsed)   {
 		printf("\tEncoded serial : %02X %02X ", *(cert_parsed->serial), *(cert_parsed->serial + 1));
 		util_hex_dump(stdout, cert_parsed->serial + 2, cert_parsed->serial_len - 2, "");
@@ -606,7 +609,7 @@ static void print_pubkey_info(const struct sc_pkcs15_object *obj)
 		"neverExtract", "local"
 	};
 	const unsigned int af_count = NELEMENTS(access_flags);
-        int have_path = (pubkey->path.len != 0) || (pubkey->path.aid.len != 0);
+	int have_path = (pubkey->path.len != 0) || (pubkey->path.aid.len != 0);
 
 	printf("Public %s Key [%.*s]\n", types[7 & obj->type], (int) sizeof obj->label, obj->label);
 	print_common_flags(obj);
@@ -627,11 +630,11 @@ static void print_pubkey_info(const struct sc_pkcs15_object *obj)
 
 	if (pubkey->modulus_length)   {
 		printf("\tModLength      : %lu\n", (unsigned long)pubkey->modulus_length);
-        }
+	}
 	else if (pubkey->field_length)   {
 		printf("\tFieldLength    : %lu\n", (unsigned long)pubkey->field_length);
-        }
-        else if (obj->type == SC_PKCS15_TYPE_PUBKEY_EC && have_path)   {
+	}
+	else if (obj->type == SC_PKCS15_TYPE_PUBKEY_EC && have_path)   {
 		sc_pkcs15_pubkey_t *pkey = NULL;
 		if (!sc_pkcs15_read_pubkey(p15card, obj, &pkey))   {
 			printf("\tFieldLength    : %lu\n", (unsigned long)pkey->u.ec.params.field_length);
@@ -646,7 +649,7 @@ static void print_pubkey_info(const struct sc_pkcs15_object *obj)
 	if (obj->auth_id.len != 0)
 		printf("\tAuth ID        : %s\n", sc_pkcs15_print_id(&obj->auth_id));
 	printf("\tID             : %s\n", sc_pkcs15_print_id(&pubkey->id));
-        if (!have_path || obj->content.len)
+	if (!have_path || obj->content.len)
 		printf("\tDirectValue    : <%s>\n", obj->content.len ? "present" : "absent");
 }
 
@@ -905,7 +908,7 @@ static int read_ssh_key(void)
 		if (!pubkey->u.rsa.modulus.data || !pubkey->u.rsa.modulus.len ||
 				!pubkey->u.rsa.exponent.data || !pubkey->u.rsa.exponent.len)  {
 			fprintf(stderr, "Failed to decode public RSA key.\n");
-                        goto fail2;
+			goto fail2;
 		}
 
 		buf[0]=0;
@@ -963,7 +966,7 @@ static int read_ssh_key(void)
 				!pubkey->u.dsa.g.data || !pubkey->u.dsa.g.len ||
 				!pubkey->u.dsa.pub.data || !pubkey->u.dsa.pub.len)   {
 			fprintf(stderr, "Failed to decode DSA key.\n");
-                        goto fail2;
+			goto fail2;
 		}
 
 		buf[0]=0;
@@ -1139,13 +1142,13 @@ static int verify_pin(void)
 	int r;
 
 	if (!opt_auth_id)   {
-	        struct sc_pkcs15_object *objs[32];
+		struct sc_pkcs15_object *objs[32];
 		int ii;
 
 		r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 32);
 		if (r < 0) {
-                        fprintf(stderr, "PIN code enumeration failed: %s\n", sc_strerror(r));
-                        return -1;
+			fprintf(stderr, "PIN code enumeration failed: %s\n", sc_strerror(r));
+			return -1;
 		}
 
 		for (ii=0;ii<r;ii++)   {
@@ -1610,7 +1613,8 @@ static int read_and_cache_file(const sc_path_t *path)
 		}
 		r = head - buf;
 
-	} else {		
+	}
+	else {
 
 		r = sc_read_binary(card, 0, buf, size, 0);
 		if (r < 0) {
@@ -1692,18 +1696,18 @@ static int test_update(sc_card_t *in_card)
 	sc_apdu_t apdu;
 	static u8 cmd1[2] = { 0x50, 0x15};
 	u8 rbuf[258];
-        int rc;
+	int rc;
 	int r;
 	static u8 fci_bad[] = { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 	static u8 fci_good[] = { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00 };
 
 
 
-        if (strcmp("cardos",in_card->driver->short_name) != 0) {
- 		printf("not using the cardos driver, card is fine.\n");
+	if (strcmp("cardos",in_card->driver->short_name) != 0) {
+		printf("not using the cardos driver, card is fine.\n");
 		rc = 0;
-                goto end;
-        }
+		goto end;
+	}
 
 	/* first select file on 5015 and get fci */
 	sc_format_apdu(in_card, &apdu, SC_APDU_CASE_4_SHORT, 0xa4, 0x08, 0x00);
@@ -1747,7 +1751,7 @@ static int test_update(sc_card_t *in_card)
 
 	{
 		size_t i=0;
-	  	while(i < rbuf[1]) {
+		while(i < rbuf[1]) {
 			if (rbuf[2+i] == 0x86) { /* found our buffer */
 				break;
 			}
@@ -1776,7 +1780,7 @@ static int test_update(sc_card_t *in_card)
 	}
 end:
 	/* 0 = card ok, 1 = card vulnerable, 2 = problem! */
-        return rc;
+	return rc;
 
 bad_fci:
 	util_hex_dump(stdout,rbuf,apdu.resplen," ");
@@ -1836,7 +1840,7 @@ static int update(sc_card_t *in_card)
 	if (apdu.resplen < 1) {
 		printf("get lifecycle failed: lifecycle byte not in response\n");
 		goto end;
-        }
+	}
 
 	if (rbuf[0] != 0x10 && rbuf[0] != 0x20) {
 		printf("lifecycle neither user nor admin, can't proceed\n");
@@ -1890,7 +1894,7 @@ skip_change_lifecycle:
 
 	printf("security update applied successfully.\n");
 end:
-        return 0;
+	return 0;
 }
 
 int main(int argc, char * const argv[])
@@ -1916,6 +1920,7 @@ int main(int argc, char * const argv[])
 	int do_learn_card = 0;
 	int do_test_update = 0;
 	int do_update = 0;
+	int do_print_version = 0;
 	int action_count = 0;
 	sc_context_param_t ctx_param;
 
@@ -1930,6 +1935,10 @@ int main(int argc, char * const argv[])
 		if (c == '?')
 			util_print_usage_and_die(app_name, options, option_help, NULL);
 		switch (c) {
+		case OPT_PRINT_VERSION:
+			do_print_version = 1;
+			action_count++;
+			break;
 		case 'r':
 			opt_cert = optarg;
 			do_read_cert = 1;
@@ -2052,6 +2061,11 @@ int main(int argc, char * const argv[])
 	if (action_count == 0)
 		util_print_usage_and_die(app_name, options, option_help, NULL);
 
+	if (do_print_version)   {
+		printf("%s\n", OPENSC_SCM_REVISION);
+		action_count--;
+	}
+
 	memset(&ctx_param, 0, sizeof(ctx_param));
 	ctx_param.ver      = 0;
 	ctx_param.app_name = app_name;
@@ -2074,7 +2088,7 @@ int main(int argc, char * const argv[])
 	if (verbose)
 		fprintf(stderr, "Trying to find a PKCS#15 compatible card...\n");
 
-        if (opt_bind_to_aid)   {
+	if (opt_bind_to_aid)   {
 		struct sc_aid aid;
 
 		aid.len = sizeof(aid.value);
@@ -2181,7 +2195,7 @@ int main(int argc, char * const argv[])
 		action_count--;
 	}
 	if (do_test_update || do_update) {
- 		err = test_update(card);
+		err = test_update(card);
 		action_count--;
 		if (err == 2) { /* problem */
 			err = 1;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/opensc.git



More information about the pkg-opensc-commit mailing list