diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2015-03-11 16:02:21 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2015-03-11 16:12:30 +0100 |
commit | 6df68aff4c2020983893c9eaaa16c3a40660c092 (patch) | |
tree | 71d765b6b3f11c7015641d774a7bd26318e9e77d | |
parent | 6199c2271d843e48737557c9c1f6f867ddc4d104 (diff) | |
download | gnutls-6df68aff4c2020983893c9eaaa16c3a40660c092.tar.gz |
p11tool: added --set-id and --set-label options
-rw-r--r-- | src/p11tool-args.def | 14 | ||||
-rw-r--r-- | src/p11tool.c | 4 | ||||
-rw-r--r-- | src/p11tool.h | 8 | ||||
-rw-r--r-- | src/pkcs11.c | 53 |
4 files changed, 79 insertions, 0 deletions
diff --git a/src/p11tool-args.def b/src/p11tool-args.def index c90c7f1681..88ae8b4cd7 100644 --- a/src/p11tool-args.def +++ b/src/p11tool-args.def @@ -136,6 +136,20 @@ flag = { }; flag = { + name = set-id; + descrip = "Set the CKA_ID in the specified by the URL object"; + doc = "Sets the CKA_ID in the specified by the URL object. The ID should be specified in hexadecimal format."; + arg-type = string; +}; + +flag = { + name = set-label; + descrip = "Set the CKA_LABEL in the specified by the URL object"; + doc = "Sets the CKA_LABEL in the specified by the URL object"; + arg-type = string; +}; + +flag = { name = label; arg-type = string; descrip = "Sets a label for the write operation"; diff --git a/src/p11tool.c b/src/p11tool.c index 8fbdbd545b..fff8542ee6 100644 --- a/src/p11tool.c +++ b/src/p11tool.c @@ -306,6 +306,10 @@ static void cmd_parser(int argc, char **argv) flags, &cinfo); } else if (HAVE_OPT(EXPORT_PUBKEY)) { pkcs11_export_pubkey(outfile, url, detailed_url, flags, &cinfo); + } else if (HAVE_OPT(SET_ID)) { + pkcs11_set_id(outfile, url, detailed_url, flags, &cinfo, OPT_ARG(SET_ID)); + } else if (HAVE_OPT(SET_LABEL)) { + pkcs11_set_label(outfile, url, detailed_url, flags, &cinfo, OPT_ARG(SET_LABEL)); } else { USAGE(1); } diff --git a/src/p11tool.h b/src/p11tool.h index 422d680840..13baaeab75 100644 --- a/src/p11tool.h +++ b/src/p11tool.h @@ -54,6 +54,14 @@ void pkcs11_generate(FILE * outfile, const char *url, void pkcs11_export_pubkey(FILE * outfile, const char *url, int detailed, unsigned int flags, common_info_st * info); +void pkcs11_set_id(FILE * outfile, const char *url, int detailed, + unsigned int flags, common_info_st * info, + const char *id); + +void pkcs11_set_label(FILE * outfile, const char *url, int detailed, + unsigned int flags, common_info_st * info, + const char *label); + #define PKCS11_TYPE_CRT_ALL 1 #define PKCS11_TYPE_TRUSTED 2 #define PKCS11_TYPE_PK 3 diff --git a/src/pkcs11.c b/src/pkcs11.c index e6cb677778..8b527b3e96 100644 --- a/src/pkcs11.c +++ b/src/pkcs11.c @@ -1018,3 +1018,56 @@ pkcs11_get_random(FILE * outfile, const char *url, unsigned bytes, return; } + +static +void pkcs11_set_val(FILE * outfile, const char *url, int detailed, + unsigned int flags, common_info_st * info, + gnutls_pkcs11_obj_info_t val_type, const char *val) +{ + int ret; + gnutls_pkcs11_obj_t obj; + + pkcs11_common(info); + + FIX(url, outfile, detailed, info); + CHECK_LOGIN_FLAG(flags); + + ret = gnutls_pkcs11_obj_init(&obj); + if (ret < 0) { + fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, + gnutls_strerror(ret)); + exit(1); + } + + ret = gnutls_pkcs11_obj_import_url(obj, url, flags); + if (ret < 0) { + fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, + gnutls_strerror(ret)); + exit(1); + } + + ret = + gnutls_pkcs11_obj_set_info(obj, val_type, val, strlen(val), flags); + if (ret < 0) { + fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, + gnutls_strerror(ret)); + exit(1); + } + gnutls_pkcs11_obj_deinit(obj); + + return; +} + +void pkcs11_set_id(FILE * outfile, const char *url, int detailed, + unsigned int flags, common_info_st * info, + const char *id) +{ + return pkcs11_set_val(outfile, url, detailed, flags, info, GNUTLS_PKCS11_OBJ_ID_HEX, id); +} + +void pkcs11_set_label(FILE * outfile, const char *url, int detailed, + unsigned int flags, common_info_st * info, + const char *label) +{ + return pkcs11_set_val(outfile, url, detailed, flags, info, GNUTLS_PKCS11_OBJ_LABEL, label); +} |