From: Nikos Mavrogiannopoulos Date: Mon, 25 Feb 2013 21:05:42 +0000 (+0100) Subject: Added gnutls_pkcs11_privkey_status(). X-Git-Tag: gnutls_3_1_9~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7e1b0d936e90c932376cdb9dc86f2fff604dcb65;p=thirdparty%2Fgnutls.git Added gnutls_pkcs11_privkey_status(). --- 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 @@ -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