]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added gnutls_pkcs11_privkey_status().
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 25 Feb 2013 21:05:42 +0000 (22:05 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 25 Feb 2013 21:05:42 +0000 (22:05 +0100)
NEWS
lib/includes/gnutls/pkcs11.h
lib/pkcs11_privkey.c

diff --git a/NEWS b/NEWS
index 945bbcb6c98e3b051560b6fccedb051368172b0f..9c695498f16bf37c8dd1c954b5e6a71f7c54642d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,9 @@ alternative name. Reported by James Cloos.
 ** libgnutls: gnutls_pkcs11_reinit() will reinitialize all PKCS #11
 modules, and not only the ones loaded via p11-kit.
 
+** libgnutls: Added function to check whether the private key is
+still available (inserted).
+
 ** API and ABI modifications:
 gnutls_handshake_set_random: Added
 gnutls_transport_set_int2: Added
@@ -22,6 +25,7 @@ gnutls_transport_get_int2: Added
 gnutls_transport_get_int: Added
 gnutls_record_cork: Exported
 gnutls_record_uncork: Exported
+gnutls_pkcs11_privkey_status: Added
 
 
 * Version 3.1.8 (released 2013-02-10)
index 5d2e01e07a635742cfd4da33dd77288886e5b065..51bcab968509e11c79431cc66eec6691a7ffb452 100644 (file)
@@ -304,6 +304,7 @@ int gnutls_pkcs11_privkey_import_url (gnutls_pkcs11_privkey_t pkey,
 int gnutls_pkcs11_privkey_export_url (gnutls_pkcs11_privkey_t key,
                                      gnutls_pkcs11_url_type_t detailed,
                                      char **url);
+int gnutls_pkcs11_privkey_status (gnutls_pkcs11_privkey_t key);
 
 int gnutls_pkcs11_privkey_generate (const char* url,
                                    gnutls_pk_algorithm_t pk,
index 4bc205330ce4101ebbe4f38f2610f433a12d2fe6..a6f73e1e7c6f4025e276beef71bd97f70d889054 100644 (file)
@@ -311,6 +311,55 @@ cleanup:
   return ret;
 }
 
+/**
+ * gnutls_pkcs11_privkey_status:
+ * @key: Holds the key
+ *
+ * Checks the status of the private key token.
+ *
+ * Returns: this function will return non-zero if the token 
+ * holding the private key is still available (inserted), and zero otherwise.
+ * 
+ * Since: 3.1.9
+ *
+ **/
+int
+gnutls_pkcs11_privkey_status (gnutls_pkcs11_privkey_t key)
+{
+  ck_rv_t rv;
+  int ret;
+  struct pkcs11_session_info _sinfo;
+  struct pkcs11_session_info *sinfo;
+  ck_object_handle_t obj;
+  struct ck_session_info session_info;
+
+  if (key->sinfo.init != 0)
+    {
+      sinfo = &key->sinfo;
+      obj = key->obj;
+    }
+  else
+    {
+      sinfo = &_sinfo;
+      memset(sinfo, 0, sizeof(*sinfo));
+      FIND_OBJECT (sinfo, &key->pin, obj, key);
+    }
+  
+  rv = (sinfo->module)->C_GetSessionInfo (sinfo->pks, &session_info);
+  if (rv != CKR_OK)
+    {
+      ret = 0;
+      goto cleanup;
+    }
+  ret = 1;
+
+cleanup:
+  if (sinfo != &key->sinfo)
+    pkcs11_close_session (sinfo);
+
+  return ret;
+}
+
 /**
  * gnutls_pkcs11_privkey_import_url:
  * @pkey: The structure to store the parsed key