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 /src/pkcs11.c | |
parent | 6199c2271d843e48737557c9c1f6f867ddc4d104 (diff) | |
download | gnutls-6df68aff4c2020983893c9eaaa16c3a40660c092.tar.gz |
p11tool: added --set-id and --set-label options
Diffstat (limited to 'src/pkcs11.c')
-rw-r--r-- | src/pkcs11.c | 53 |
1 files changed, 53 insertions, 0 deletions
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); +} |