]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added several helper functions, to allow printing of tokens.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 10 May 2010 21:35:33 +0000 (23:35 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 3 Jun 2010 17:52:30 +0000 (19:52 +0200)
src/certtool.c
src/pkcs11.c

index 9e806a53cfe81644c8145c4f280f8373e680a12e..075f19c8402d97c1abe79a6f6826db28545e65d1 100644 (file)
@@ -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;
index a2a90ed0ab418b0a54208984f2075f64c9f237c4..55d246b0e0cf676b186657588f03ab73409b95f3 100644 (file)
@@ -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;
+
+
+
 }