From: Nikos Mavrogiannopoulos Date: Mon, 10 May 2010 21:35:33 +0000 (+0200) Subject: Added several helper functions, to allow printing of tokens. X-Git-Tag: gnutls_2_11_3~277 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea433f8343b360edc7f813a897bc2cfda4134c56;p=thirdparty%2Fgnutls.git Added several helper functions, to allow printing of tokens. --- diff --git a/src/certtool.c b/src/certtool.c index 9e806a53cf..075f19c840 100644 --- a/src/certtool.c +++ b/src/certtool.c @@ -1368,7 +1368,7 @@ print_hex_datum (gnutls_datum_t * dat) } -void +static void print_certificate_info (gnutls_x509_crt_t crt, FILE * out, unsigned int all) { gnutls_datum_t cinfo; diff --git a/src/pkcs11.c b/src/pkcs11.c index a2a90ed0ab..55d246b0e0 100644 --- a/src/pkcs11.c +++ b/src/pkcs11.c @@ -348,6 +348,7 @@ void pkcs11_export(FILE* outfile, const char* url) gnutls_pkcs11_crt_t crt; gnutls_x509_crt_t xcrt; int ret; +size_t size; pkcs11_common(); @@ -378,7 +379,14 @@ int ret; exit(1); } - print_certificate_info(xcrt, outfile, 1); + size = buffer_size; + ret = gnutls_x509_crt_export (xcrt, GNUTLS_X509_FMT_PEM, buffer, &size); + if (ret < 0) { + fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret)); + exit(1); + } + fwrite (buffer, 1, size, outfile); + fputs("\n\n", outfile); gnutls_x509_crt_deinit(xcrt); gnutls_pkcs11_crt_deinit(crt); @@ -387,4 +395,73 @@ int ret; +} + +void pkcs11_token_list(FILE* outfile) +{ +int ret; +int i; +char *url; +char buf[128]; +size_t size; + + pkcs11_common(); + + for (i=0;;i++) { + ret = gnutls_pkcs11_token_get_url(i, &url); + if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) + break; + + if (ret < 0) { + fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret)); + exit(1); + } + + fprintf(outfile, "Token %d:\n\tURL: %s\n", i, url); + + size = sizeof(buf); + ret = gnutls_pkcs11_token_get_info(url, GNUTLS_PKCS11_TOKEN_LABEL, buf, &size); + if (ret < 0) { + fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret)); + exit(1); + } + + fprintf(outfile, "\tLabel: %s\n", buf); + + size = sizeof(buf); + ret = gnutls_pkcs11_token_get_info(url, GNUTLS_PKCS11_TOKEN_MANUFACTURER, buf, &size); + if (ret < 0) { + fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret)); + exit(1); + } + + fprintf(outfile, "\tManufacturer: %s\n", buf); + + size = sizeof(buf); + ret = gnutls_pkcs11_token_get_info(url, GNUTLS_PKCS11_TOKEN_MODEL, buf, &size); + if (ret < 0) { + fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret)); + exit(1); + } + + fprintf(outfile, "\tModel: %s\n", buf); + + size = sizeof(buf); + ret = gnutls_pkcs11_token_get_info(url, GNUTLS_PKCS11_TOKEN_SERIAL, buf, &size); + if (ret < 0) { + fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__, gnutls_strerror(ret)); + exit(1); + } + + fprintf(outfile, "\tSerial: %s\n", buf); + fprintf(outfile, "\n\n"); + + gnutls_free(url); + + } + + return; + + + }