Skip to content

Commit

Permalink
p11-kit tool: Support --provider option
Browse files Browse the repository at this point in the history
This adds --provider option to p11-kit subcommands which loads PKCS#11
modules.  The option would be useful for testing a specific module
without installing it on the system.

Signed-off-by: Daiki Ueno <ueno@gnu.org>
  • Loading branch information
ueno committed Dec 28, 2023
1 parent 966a161 commit 7ca8016
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 2 deletions.
13 changes: 13 additions & 0 deletions p11-kit/add-profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "tool.h"

#include <assert.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -147,13 +148,15 @@ p11_kit_add_profile (int argc,
p11_dict *profile_nicks = NULL;
bool login = false;
p11_tool *tool = NULL;
const char *provider = NULL;

enum {
opt_verbose = 'v',
opt_quiet = 'q',
opt_help = 'h',
opt_profile = 'p',
opt_login = 'l',
opt_provider = CHAR_MAX + 2,
};

struct option options[] = {
Expand All @@ -162,13 +165,15 @@ p11_kit_add_profile (int argc,
{ "help", no_argument, NULL, opt_help },
{ "profile", required_argument, NULL, opt_profile },
{ "login", no_argument, NULL, opt_login },
{ "provider", required_argument, NULL, opt_provider },
{ 0 },
};

p11_tool_desc usages[] = {
{ 0, "usage: p11-kit add-profile --profile profile pkcs11:token" },
{ opt_profile, "specify the profile to add" },
{ opt_login, "login to the token" },
{ opt_provider, "specify the module to use" },
{ 0 },
};

Expand Down Expand Up @@ -207,6 +212,9 @@ p11_kit_add_profile (int argc,
case opt_login:
login = true;
break;
case opt_provider:
provider = optarg;
break;
case '?':
goto cleanup;
default:
Expand Down Expand Up @@ -239,6 +247,11 @@ p11_kit_add_profile (int argc,
goto cleanup;
}

if (!p11_tool_set_provider (tool, provider)) {
p11_message (_("failed to allocate memory"));
goto cleanup;
}

p11_tool_set_login (tool, login);

ret = add_profile (tool, profile);
Expand Down
13 changes: 13 additions & 0 deletions p11-kit/delete-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "tool.h"

#include <assert.h>
#include <limits.h>
#include <stdlib.h>

#ifdef ENABLE_NLS
Expand Down Expand Up @@ -99,25 +100,29 @@ p11_kit_delete_object (int argc,
int opt, ret = 2;
bool login = false;
p11_tool *tool = NULL;
const char *provider = NULL;

enum {
opt_verbose = 'v',
opt_quiet = 'q',
opt_help = 'h',
opt_login = 'l',
opt_provider = CHAR_MAX + 2,
};

struct option options[] = {
{ "verbose", no_argument, NULL, opt_verbose },
{ "quiet", no_argument, NULL, opt_quiet },
{ "help", no_argument, NULL, opt_help },
{ "login", no_argument, NULL, opt_login },
{ "provider", required_argument, NULL, opt_provider },
{ 0 },
};

p11_tool_desc usages[] = {
{ 0, "usage: p11-kit delete-object pkcs11:token" },
{ opt_login, "login to the token" },
{ opt_provider, "specify the module to use" },
{ 0 },
};

Expand All @@ -126,6 +131,9 @@ p11_kit_delete_object (int argc,
case opt_login:
login = true;
break;
case opt_provider:
provider = optarg;
break;
case opt_verbose:
p11_kit_be_loud ();
break;
Expand Down Expand Up @@ -162,6 +170,11 @@ p11_kit_delete_object (int argc,
goto cleanup;
}

if (!p11_tool_set_provider (tool, provider)) {
p11_message (_("failed to allocate memory"));
goto cleanup;
}

p11_tool_set_login (tool, login);

ret = delete_object (tool);
Expand Down
13 changes: 13 additions & 0 deletions p11-kit/delete-profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "tool.h"

#include <assert.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -147,13 +148,15 @@ p11_kit_delete_profile (int argc,
p11_dict *profile_nicks = NULL;
bool login = false;
p11_tool *tool = NULL;
const char *provider = NULL;

enum {
opt_verbose = 'v',
opt_quiet = 'q',
opt_help = 'h',
opt_profile = 'p',
opt_login = 'l',
opt_provider = CHAR_MAX + 2,
};

struct option options[] = {
Expand All @@ -162,13 +165,15 @@ p11_kit_delete_profile (int argc,
{ "help", no_argument, NULL, opt_help },
{ "profile", required_argument, NULL, opt_profile },
{ "login", no_argument, NULL, opt_login },
{ "provider", required_argument, NULL, opt_provider },
{ 0 },
};

p11_tool_desc usages[] = {
{ 0, "usage: p11-kit delete-profile --profile profile pkcs11:token" },
{ opt_profile, "specify the profile to delete" },
{ opt_login, "login to the token" },
{ opt_provider, "specify the module to use" },
{ 0 },
};

Expand Down Expand Up @@ -207,6 +212,9 @@ p11_kit_delete_profile (int argc,
case opt_login:
login = true;
break;
case opt_provider:
provider = optarg;
break;
case '?':
goto cleanup;
default:
Expand Down Expand Up @@ -239,6 +247,11 @@ p11_kit_delete_profile (int argc,
goto cleanup;
}

if (!p11_tool_set_provider (tool, provider)) {
p11_message (_("failed to allocate memory"));
goto cleanup;
}

p11_tool_set_login (tool, login);

ret = delete_profile (tool, profile);
Expand Down
12 changes: 12 additions & 0 deletions p11-kit/export-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,25 +493,29 @@ p11_kit_export_object (int argc,
int opt, ret = 2;
bool login = false;
p11_tool *tool = NULL;
const char *provider = NULL;

enum {
opt_verbose = 'v',
opt_quiet = 'q',
opt_help = 'h',
opt_login = 'l',
opt_provider = CHAR_MAX + 2,
};

struct option options[] = {
{ "verbose", no_argument, NULL, opt_verbose },
{ "quiet", no_argument, NULL, opt_quiet },
{ "help", no_argument, NULL, opt_help },
{ "login", no_argument, NULL, opt_login },
{ "provider", required_argument, NULL, opt_provider },
{ 0 },
};

p11_tool_desc usages[] = {
{ 0, "usage: p11-kit export-object pkcs11:token" },
{ opt_login, "login to the token" },
{ opt_provider, "specify the module to use" },
{ 0 },
};

Expand All @@ -529,6 +533,9 @@ p11_kit_export_object (int argc,
case opt_login:
login = true;
break;
case opt_provider:
provider = optarg;
break;
case '?':
return 2;
default:
Expand Down Expand Up @@ -556,6 +563,11 @@ p11_kit_export_object (int argc,
goto cleanup;
}

if (!p11_tool_set_provider (tool, provider)) {
p11_message (_("failed to allocate memory"));
goto cleanup;
}

p11_tool_set_login (tool, login);

ret = export_object (tool);
Expand Down
13 changes: 13 additions & 0 deletions p11-kit/generate-keypair.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#endif

#include <assert.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -324,6 +325,7 @@ p11_kit_generate_keypair (int argc,
CK_MECHANISM mechanism = { CKA_INVALID, NULL_PTR, 0 };
bool login = false;
p11_tool *tool = NULL;
const char *provider = NULL;

enum {
opt_verbose = 'v',
Expand All @@ -334,6 +336,7 @@ p11_kit_generate_keypair (int argc,
opt_bits = 'b',
opt_curve = 'c',
opt_login = 'l',
opt_provider = CHAR_MAX + 2,
};

struct option options[] = {
Expand All @@ -345,6 +348,7 @@ p11_kit_generate_keypair (int argc,
{ "bits", required_argument, NULL, opt_bits },
{ "curve", required_argument, NULL, opt_curve },
{ "login", no_argument, NULL, opt_login },
{ "provider", required_argument, NULL, opt_provider },
{ 0 },
};

Expand All @@ -356,6 +360,7 @@ p11_kit_generate_keypair (int argc,
{ opt_bits, "number of bits for key generation" },
{ opt_curve, "name of the curve for key generation" },
{ opt_login, "login to the token" },
{ opt_provider, "specify the module to use" },
{ 0 },
};

Expand Down Expand Up @@ -388,6 +393,9 @@ p11_kit_generate_keypair (int argc,
case opt_login:
login = true;
break;
case opt_provider:
provider = optarg;
break;
case opt_verbose:
p11_kit_be_loud ();
break;
Expand Down Expand Up @@ -427,6 +435,11 @@ p11_kit_generate_keypair (int argc,
goto cleanup;
}

if (!p11_tool_set_provider (tool, provider)) {
p11_message (_("failed to allocate memory"));
goto cleanup;
}

p11_tool_set_login (tool, login);

ret = generate_keypair (tool, label, mechanism, bits, ec_params, ec_params_len);
Expand Down
12 changes: 12 additions & 0 deletions p11-kit/import-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ p11_kit_import_object (int argc,
char *file = NULL;
bool login = false;
p11_tool *tool = NULL;
const char *provider = NULL;

enum {
opt_verbose = 'v',
Expand All @@ -501,6 +502,7 @@ p11_kit_import_object (int argc,
opt_label = 'L',
opt_file = 'f',
opt_login = 'l',
opt_provider = CHAR_MAX + 2,
};

struct option options[] = {
Expand All @@ -510,6 +512,7 @@ p11_kit_import_object (int argc,
{ "label", required_argument, NULL, opt_label },
{ "file", required_argument, NULL, opt_file },
{ "login", no_argument, NULL, opt_login },
{ "provider", required_argument, NULL, opt_provider },
{ 0 },
};

Expand All @@ -519,6 +522,7 @@ p11_kit_import_object (int argc,
{ opt_label, "label to be associated with imported object" },
{ opt_file, "object data to import" },
{ opt_login, "login to the token" },
{ opt_provider, "specify the module to use" },
{ 0 },
};

Expand All @@ -533,6 +537,9 @@ p11_kit_import_object (int argc,
case opt_login:
login = true;
break;
case opt_provider:
provider = optarg;
break;
case opt_verbose:
p11_kit_be_loud ();
break;
Expand Down Expand Up @@ -574,6 +581,11 @@ p11_kit_import_object (int argc,
goto cleanup;
}

if (!p11_tool_set_provider (tool, provider)) {
p11_message (_("failed to allocate memory"));
goto cleanup;
}

p11_tool_set_login (tool, login);

ret = import_object (tool, file, label);
Expand Down
Loading

0 comments on commit 7ca8016

Please sign in to comment.