Blame SOURCES/opensc-0.16.0-hexadecimal-mechanism.patch

4e5208
From 74885fb1c174468cc0a505cd7404e228d465efd8 Mon Sep 17 00:00:00 2001
4e5208
From: AnthonyA <ascanio.alba7@gmail.com>
4e5208
Date: Tue, 27 Mar 2018 00:48:05 +0000
4e5208
Subject: [PATCH] pkcs11-tool: allow mechanism to be specified in hexadecimal
4e5208
4e5208
To support vendor mechanisms, let -m accept hexadecimal strings,
4e5208
e.g., -m 0x80001234
4e5208
---
4e5208
 doc/tools/pkcs11-tool.1.xml | 3 ++-
4e5208
 src/tools/pkcs11-tool.c     | 5 ++++-
4e5208
 2 files changed, 6 insertions(+), 2 deletions(-)
4e5208
4e5208
diff --git a/doc/tools/pkcs11-tool.1.xml b/doc/tools/pkcs11-tool.1.xml
4e5208
index f8d638b45..e78570b10 100644
4e5208
--- a/doc/tools/pkcs11-tool.1.xml
4e5208
+++ b/doc/tools/pkcs11-tool.1.xml
4e5208
@@ -231,7 +231,8 @@
4e5208
 					</term>
4e5208
 					<listitem><para>Use the specified <replaceable>mechanism</replaceable>
4e5208
 					for token operations. See <option>-M</option> for a list
4e5208
-					of mechanisms supported by your token.</para></listitem>
4e5208
+					of mechanisms supported by your token. The mechanism can also be specified in
4e5208
+					hexadecimal, e.g., <replaceable>0x80001234</replaceable>.</para></listitem>
4e5208
 				</varlistentry>
4e5208
 
4e5208
 				<varlistentry>
4e5208
diff --git a/src/tools/pkcs11-tool.c b/src/tools/pkcs11-tool.c
4e5208
index 63e5c5f7f..484c019d8 100644
4e5208
--- a/src/tools/pkcs11-tool.c
4e5208
+++ b/src/tools/pkcs11-tool.c
4e5208
@@ -234,7 +234,7 @@ static const char *option_help[] = {
4e5208
 	"Hash some data",
4e5208
 	"Derive a secret key using another key and some data",
4e5208
 	"Derive ECDHpass DER encoded pubkey for compatibility with some PKCS#11 implementations",
4e5208
-	"Specify mechanism (use -M for a list of supported mechanisms)",
4e5208
+	"Specify mechanism (use -M for a list of supported mechanisms), or by hexadecimal, e.g., 0x80001234",
4e5208
 
4e5208
 	"Log into the token first",
4e5208
 	"Specify login type ('so', 'user', 'context-specific'; default:'user')",
4e5208
@@ -6076,6 +6076,9 @@ static CK_MECHANISM_TYPE p11_name_to_mechanism(const char *name)
4e5208
 {
4e5208
 	struct mech_info *mi;
4e5208
 
4e5208
+	if (strncasecmp("0x", name, 2) == 0) {
4e5208
+		return strtoul(name, NULL, 0);
4e5208
+	}
4e5208
 	for (mi = p11_mechanisms; mi->name; mi++) {
4e5208
 		if (!strcasecmp(mi->name, name)
4e5208
 		 || (mi->short_name && !strcasecmp(mi->short_name, name)))
4e5208