summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/p11tool.c137
-rw-r--r--src/p11tool.h13
2 files changed, 60 insertions, 90 deletions
diff --git a/src/p11tool.c b/src/p11tool.c
index d800e46bea..beeaa5ab93 100644
--- a/src/p11tool.c
+++ b/src/p11tool.c
@@ -76,7 +76,7 @@ cmd_parser (int argc, char **argv)
{
int ret, debug = 0;
common_info_st cinfo;
- unsigned int action = 1, pkcs11_type = -1, key_type = GNUTLS_PK_UNKNOWN;
+ unsigned int pkcs11_type = -1, key_type = GNUTLS_PK_UNKNOWN;
const char* url = NULL;
unsigned int detailed_url = 0, optct;
unsigned int login = 0, bits = 0;
@@ -150,128 +150,111 @@ cmd_parser (int argc, char **argv)
if (HAVE_OPT(LOAD_PUBKEY))
cinfo.pubkey = OPT_ARG(LOAD_PUBKEY);
+
+ if (ENABLED_OPT(DETAILED_URL))
+ detailed_url = 1;
+
+ if (ENABLED_OPT(LOGIN))
+ login = 1;
+
+ if (HAVE_OPT(LABEL))
+ {
+ label = OPT_ARG(LABEL);
+ }
+
+ if (HAVE_OPT(BITS))
+ {
+ bits = OPT_VALUE_BITS;
+ }
+
+ if (HAVE_OPT(SEC_PARAM))
+ {
+ sec_param = OPT_ARG(SEC_PARAM);
+ }
+
+ if (debug > 0)
+ {
+ fprintf(stderr, "Private: %s\n", ENABLED_OPT(PRIVATE)?"yes":"no");
+ fprintf(stderr, "Trusted: %s\n", ENABLED_OPT(TRUSTED)?"yes":"no");
+ fprintf(stderr, "Login: %s\n", ENABLED_OPT(LOGIN)?"yes":"no");
+ fprintf(stderr, "Detailed URLs: %s\n", ENABLED_OPT(DETAILED_URL)?"yes":"no");
+ fprintf(stderr, "\n");
+ }
+ /* handle actions
+ */
if (HAVE_OPT(LIST_TOKENS))
- action = ACTION_PKCS11_TOKENS;
+ pkcs11_token_list (outfile, detailed_url, &cinfo);
else if (HAVE_OPT(LIST_MECHANISMS))
- action = ACTION_PKCS11_MECHANISMS;
+ pkcs11_mechanism_list (outfile, url, login,
+ &cinfo);
else if (HAVE_OPT(LIST_ALL))
{
pkcs11_type = PKCS11_TYPE_ALL;
- action = ACTION_PKCS11_LIST;
+ pkcs11_list (outfile, url, pkcs11_type,
+ login, detailed_url, &cinfo);
}
else if (HAVE_OPT(LIST_ALL_CERTS))
{
pkcs11_type = PKCS11_TYPE_CRT_ALL;
- action = ACTION_PKCS11_LIST;
+ pkcs11_list (outfile, url, pkcs11_type,
+ login, detailed_url, &cinfo);
}
else if (HAVE_OPT(LIST_CERTS))
{
pkcs11_type = PKCS11_TYPE_PK;
- action = ACTION_PKCS11_LIST;
+ pkcs11_list (outfile, url, pkcs11_type,
+ login, detailed_url, &cinfo);
}
else if (HAVE_OPT(LIST_ALL_PRIVKEYS))
{
pkcs11_type = PKCS11_TYPE_PRIVKEY;
- action = ACTION_PKCS11_LIST;
+ pkcs11_list (outfile, url, pkcs11_type,
+ login, detailed_url, &cinfo);
}
else if (HAVE_OPT(LIST_ALL_TRUSTED))
{
pkcs11_type = PKCS11_TYPE_TRUSTED;
- action = ACTION_PKCS11_LIST;
+ pkcs11_list (outfile, url, pkcs11_type,
+ login, detailed_url, &cinfo);
}
else if (HAVE_OPT(EXPORT))
{
- action = ACTION_PKCS11_EXPORT_URL;
+ pkcs11_export (outfile, url, login, &cinfo);
}
else if (HAVE_OPT(WRITE))
- action = ACTION_PKCS11_WRITE_URL;
+ pkcs11_write (outfile, url, label,
+ ENABLED_OPT(TRUSTED), ENABLED_OPT(PRIVATE), login, &cinfo);
else if (HAVE_OPT(INITIALIZE))
- action = ACTION_PKCS11_TOKEN_INIT;
+ pkcs11_init (outfile, url, label, &cinfo);
else if (HAVE_OPT(DELETE))
- action = ACTION_PKCS11_DELETE_URL;
+ pkcs11_delete (outfile, url, 0, login, &cinfo);
else if (HAVE_OPT(GENERATE_ECC))
{
key_type = GNUTLS_PK_EC;
- action = ACTION_PKCS11_GENERATE;
+ pkcs11_generate (outfile, url, key_type, get_bits(key_type, bits, sec_param),
+ label, ENABLED_OPT(PRIVATE), detailed_url, login,
+ &cinfo);
}
else if (HAVE_OPT(GENERATE_RSA))
{
key_type = GNUTLS_PK_RSA;
- action = ACTION_PKCS11_GENERATE;
+ pkcs11_generate (outfile, url, key_type, get_bits(key_type, bits, sec_param),
+ label, ENABLED_OPT(PRIVATE), detailed_url, login,
+ &cinfo);
}
else if (HAVE_OPT(GENERATE_DSA))
{
key_type = GNUTLS_PK_DSA;
- action = ACTION_PKCS11_GENERATE;
+ pkcs11_generate (outfile, url, key_type, get_bits(key_type, bits, sec_param),
+ label, ENABLED_OPT(PRIVATE), detailed_url, login,
+ &cinfo);
}
else
{
USAGE(1);
}
- if (ENABLED_OPT(DETAILED_URL))
- detailed_url = 1;
-
- if (ENABLED_OPT(LOGIN))
- login = 1;
-
- if (HAVE_OPT(LABEL))
- {
- label = OPT_ARG(LABEL);
- }
-
- if (HAVE_OPT(BITS))
- {
- bits = OPT_VALUE_BITS;
- }
-
- if (HAVE_OPT(SEC_PARAM))
- {
- sec_param = OPT_ARG(SEC_PARAM);
- }
-
- if (debug > 0)
- {
- fprintf(stderr, "Private: %s\n", ENABLED_OPT(PRIVATE)?"yes":"no");
- fprintf(stderr, "Trusted: %s\n", ENABLED_OPT(TRUSTED)?"yes":"no");
- fprintf(stderr, "Login: %s\n", ENABLED_OPT(LOGIN)?"yes":"no");
- fprintf(stderr, "Detailed URLs: %s\n", ENABLED_OPT(DETAILED_URL)?"yes":"no");
- fprintf(stderr, "\n");
- }
-
- switch (action)
- {
- case ACTION_PKCS11_LIST:
- pkcs11_list (outfile, url, pkcs11_type,
- login, detailed_url, &cinfo);
- break;
- case ACTION_PKCS11_TOKENS:
- pkcs11_token_list (outfile, detailed_url, &cinfo);
- break;
- case ACTION_PKCS11_MECHANISMS:
- pkcs11_mechanism_list (outfile, url, login,
- &cinfo);
- break;
- case ACTION_PKCS11_EXPORT_URL:
- pkcs11_export (outfile, url, login, &cinfo);
- break;
- case ACTION_PKCS11_WRITE_URL:
- pkcs11_write (outfile, url, label,
- ENABLED_OPT(TRUSTED), ENABLED_OPT(PRIVATE), login, &cinfo);
- break;
- case ACTION_PKCS11_TOKEN_INIT:
- pkcs11_init (outfile, url, label, &cinfo);
- break;
- case ACTION_PKCS11_DELETE_URL:
- pkcs11_delete (outfile, url, 0, login, &cinfo);
- break;
- case ACTION_PKCS11_GENERATE:
- pkcs11_generate (outfile, url, key_type, get_bits(key_type, bits, sec_param),
- label, ENABLED_OPT(PRIVATE), detailed_url, login,
- &cinfo);
- break;
- }
fclose (outfile);
#ifdef ENABLE_PKCS11
diff --git a/src/p11tool.h b/src/p11tool.h
index 7506751adc..d8de31ef44 100644
--- a/src/p11tool.h
+++ b/src/p11tool.h
@@ -30,17 +30,4 @@ pkcs11_generate (FILE * outfile, const char *url, gnutls_pk_algorithm_t type,
#define PKCS11_TYPE_ALL 4
#define PKCS11_TYPE_PRIVKEY 5
-
-enum
-{
- ACTION_PKCS11_LIST,
- ACTION_PKCS11_TOKENS,
- ACTION_PKCS11_EXPORT_URL,
- ACTION_PKCS11_WRITE_URL,
- ACTION_PKCS11_DELETE_URL,
- ACTION_PKCS11_TOKEN_INIT,
- ACTION_PKCS11_MECHANISMS,
- ACTION_PKCS11_GENERATE,
-};
-
#endif