summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2013-02-25 22:05:42 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2013-02-25 22:05:42 +0100
commit7e1b0d936e90c932376cdb9dc86f2fff604dcb65 (patch)
treecb88ef93cacca8bd74f6db176f878a749871f9d3
parentb95efd09bc4db40c3ee0000c478daf5df8f5ada9 (diff)
downloadgnutls-7e1b0d936e90c932376cdb9dc86f2fff604dcb65.tar.gz
Added gnutls_pkcs11_privkey_status().
-rw-r--r--NEWS4
-rw-r--r--lib/includes/gnutls/pkcs11.h1
-rw-r--r--lib/pkcs11_privkey.c49
3 files changed, 54 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 945bbcb6c9..9c695498f1 100644
--- 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)
diff --git a/lib/includes/gnutls/pkcs11.h b/lib/includes/gnutls/pkcs11.h
index 5d2e01e07a..51bcab9685 100644
--- a/lib/includes/gnutls/pkcs11.h
+++ b/lib/includes/gnutls/pkcs11.h
@@ -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,
diff --git a/lib/pkcs11_privkey.c b/lib/pkcs11_privkey.c
index 4bc205330c..a6f73e1e7c 100644
--- a/lib/pkcs11_privkey.c
+++ b/lib/pkcs11_privkey.c
@@ -312,6 +312,55 @@ cleanup:
}
/**
+ * 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
* @url: a PKCS 11 url identifying the key