]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
PIN callback function was made more generic than PKCS #11.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 16 Jul 2012 17:51:01 +0000 (19:51 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 16 Jul 2012 17:51:01 +0000 (19:51 +0200)
lib/includes/gnutls/gnutls.h.in
lib/includes/gnutls/pkcs11.h
lib/pkcs11.c
lib/pkcs11_int.h
lib/pkcs11_privkey.c
lib/pkcs11_write.c

index f39813a09432e55f77af928f70ca90c3efe8b428..4e2281edfefcf7ba73c5b064e4a98876538ba632 100644 (file)
@@ -1742,6 +1742,67 @@ int gnutls_load_file(const char* filename, gnutls_datum_t * data);
 
 int gnutls_url_is_supported (const char* url);
 
+  /* PIN callback */
+/**
+ * gnutls_pin_flag_t:
+ * @GNUTLS_PKCS11_PIN_USER: The PIN for the user.
+ * @GNUTLS_PKCS11_PIN_SO: The PIN for the security officer.
+ * @GNUTLS_PKCS11_PIN_CONTEXT_SPECIFIC: The PIN is for a specific action and key like signing.
+ * @GNUTLS_PKCS11_PIN_FINAL_TRY: This is the final try before blocking.
+ * @GNUTLS_PKCS11_PIN_COUNT_LOW: Few tries remain before token blocks.
+ * @GNUTLS_PKCS11_PIN_WRONG: Last given PIN was not correct.
+ *
+ * Enumeration of different PIN flags.
+ */
+typedef enum
+  {
+    GNUTLS_PKCS11_PIN_USER = (1 << 0),
+    GNUTLS_PKCS11_PIN_SO = (1 << 1),
+    GNUTLS_PKCS11_PIN_FINAL_TRY = (1 << 2),
+    GNUTLS_PKCS11_PIN_COUNT_LOW = (1 << 3),
+    GNUTLS_PKCS11_PIN_CONTEXT_SPECIFIC = (1 << 4),
+    GNUTLS_PKCS11_PIN_WRONG = (1 << 5),
+  } gnutls_pin_flag_t;
+
+/**
+ * gnutls_pin_callback_t:
+ * @userdata: user-controlled data from gnutls_pkcs11_set_pin_function().
+ * @attempt: pin-attempt counter, initially 0.
+ * @token_url: PKCS11 URL.
+ * @token_label: label of PKCS11 token.
+ * @flags: a #gnutls_pin_flag_t flag.
+ * @pin: buffer to hold PIN, of size @pin_max.
+ * @pin_max: size of @pin buffer.
+ *
+ * Callback function type for PKCS#11 PIN entry.  It is set by
+ * gnutls_pkcs11_set_pin_function().
+ *
+ * The callback should provides the PIN code to unlock the token with
+ * label @token_label, specified by the URL @token_url.
+ *
+ * The PIN code, as a NUL-terminated ASCII string, should be copied
+ * into the @pin buffer (of maximum size @pin_max), and return 0 to
+ * indicate success.  Alternatively, the callback may return a
+ * negative gnutls error code to indicate failure and cancel PIN entry
+ * (in which case, the contents of the @pin parameter are ignored).
+ *
+ * When a PIN is required, the callback will be invoked repeatedly
+ * (and indefinitely) until either the returned PIN code is correct,
+ * the callback returns failure, or the token refuses login (e.g. when
+ * the token is locked due to too many incorrect PINs!).  For the
+ * first such invocation, the @attempt counter will have value zero;
+ * it will increase by one for each subsequent attempt.
+ *
+ * Returns: %GNUTLS_E_SUCCESS (0) on success or a negative error code on error.
+ *
+ * Since: 2.12.0
+ **/
+typedef int (*gnutls_pin_callback_t) (void *userdata, int attempt,
+                                             const char *token_url,
+                                             const char *token_label,
+                                            unsigned int flags,
+                                             char *pin, size_t pin_max);
+
   /* Gnutls error codes. The mapping to a TLS alert is also shown in
    * comments.
    */
index e1dd8412100d5143ab970db8ee3193ffff93cded..729b4c461af87f32464c4bfdeb6839badc8a5035 100644 (file)
@@ -57,65 +57,6 @@ typedef int (*gnutls_pkcs11_token_callback_t) (void *const userdata,
                                                const char *const label,
                                                unsigned retry);
 
-/**
- * gnutls_pkcs11_pin_flag_t:
- * @GNUTLS_PKCS11_PIN_USER: The PIN for the user.
- * @GNUTLS_PKCS11_PIN_SO: The PIN for the security officer.
- * @GNUTLS_PKCS11_PIN_CONTEXT_SPECIFIC: The PIN is for a specific action and key like signing.
- * @GNUTLS_PKCS11_PIN_FINAL_TRY: This is the final try before blocking.
- * @GNUTLS_PKCS11_PIN_COUNT_LOW: Few tries remain before token blocks.
- * @GNUTLS_PKCS11_PIN_WRONG: Last given PIN was not correct.
- *
- * Enumeration of different PIN flags.
- */
-typedef enum
-  {
-    GNUTLS_PKCS11_PIN_USER = (1 << 0),
-    GNUTLS_PKCS11_PIN_SO = (1 << 1),
-    GNUTLS_PKCS11_PIN_FINAL_TRY = (1 << 2),
-    GNUTLS_PKCS11_PIN_COUNT_LOW = (1 << 3),
-    GNUTLS_PKCS11_PIN_CONTEXT_SPECIFIC = (1 << 4),
-    GNUTLS_PKCS11_PIN_WRONG = (1 << 5),
-  } gnutls_pkcs11_pin_flag_t;
-
-/**
- * gnutls_pkcs11_pin_callback_t:
- * @userdata: user-controlled data from gnutls_pkcs11_set_pin_function().
- * @attempt: pin-attempt counter, initially 0.
- * @token_url: PKCS11 URL.
- * @token_label: label of PKCS11 token.
- * @flags: a #gnutls_pkcs11_pin_flag_t flag.
- * @pin: buffer to hold PIN, of size @pin_max.
- * @pin_max: size of @pin buffer.
- *
- * Callback function type for PKCS#11 PIN entry.  It is set by
- * gnutls_pkcs11_set_pin_function().
- *
- * The callback should provides the PIN code to unlock the token with
- * label @token_label, specified by the URL @token_url.
- *
- * The PIN code, as a NUL-terminated ASCII string, should be copied
- * into the @pin buffer (of maximum size @pin_max), and return 0 to
- * indicate success.  Alternatively, the callback may return a
- * negative gnutls error code to indicate failure and cancel PIN entry
- * (in which case, the contents of the @pin parameter are ignored).
- *
- * When a PIN is required, the callback will be invoked repeatedly
- * (and indefinitely) until either the returned PIN code is correct,
- * the callback returns failure, or the token refuses login (e.g. when
- * the token is locked due to too many incorrect PINs!).  For the
- * first such invocation, the @attempt counter will have value zero;
- * it will increase by one for each subsequent attempt.
- *
- * Returns: %GNUTLS_E_SUCCESS (0) on success or a negative error code on error.
- *
- * Since: 2.12.0
- **/
-typedef int (*gnutls_pkcs11_pin_callback_t) (void *userdata, int attempt,
-                                             const char *token_url,
-                                             const char *token_label,
-                                            unsigned int flags,
-                                             char *pin, size_t pin_max);
 
 struct gnutls_pkcs11_obj_st;
 typedef struct gnutls_pkcs11_obj_st *gnutls_pkcs11_obj_t;
@@ -135,13 +76,13 @@ void gnutls_pkcs11_deinit (void);
 void gnutls_pkcs11_set_token_function (gnutls_pkcs11_token_callback_t fn,
                                        void *userdata);
 
-void gnutls_pkcs11_set_pin_function (gnutls_pkcs11_pin_callback_t fn,
+void gnutls_pkcs11_set_pin_function (gnutls_pin_callback_t fn,
                                      void *userdata);
 
 void gnutls_pkcs11_advset_token_function (gnutls_pkcs11_token_callback_t fn,
                                        void *userdata);
 
-void gnutls_pkcs11_advset_pin_function (gnutls_pkcs11_pin_callback_t fn,
+void gnutls_pkcs11_advset_pin_function (gnutls_pin_callback_t fn,
                                      void *userdata);
 
 int gnutls_pkcs11_add_provider (const char *name, const char *params);
@@ -301,7 +242,7 @@ gnutls_pkcs11_token_get_mechanism (const char *url, unsigned int idx,
 int gnutls_pkcs11_token_set_pin (const char *token_url,
                                 const char *oldpin,
                                 const char *newpin,
-                                unsigned int flags  /*gnutls_pkcs11_pin_flag_t */
+                                unsigned int flags  /*gnutls_pin_flag_t */
                                 );
 
 int gnutls_pkcs11_token_get_url (unsigned int seq,
index 907cfbdc374742b3973d6394ecf627d0e72771d0..b35f8de83365546f2b08d7ce559933ebab060a4a 100644 (file)
@@ -74,7 +74,7 @@ static struct gnutls_pkcs11_provider_s providers[MAX_PROVIDERS];
 static unsigned int active_providers = 0;
 static unsigned int initialized_registered = 0;
 
-gnutls_pkcs11_pin_callback_t _gnutls_pin_func;
+gnutls_pin_callback_t _gnutls_pin_func;
 void *_gnutls_pin_data;
 
 gnutls_pkcs11_token_callback_t _gnutls_token_func;
@@ -641,17 +641,17 @@ gnutls_pkcs11_deinit (void)
 
 /**
  * gnutls_pkcs11_set_pin_function:
- * @fn: The PIN callback, a gnutls_pkcs11_pin_callback_t() function.
+ * @fn: The PIN callback, a gnutls_pin_callback_t() function.
  * @userdata: data to be supplied to callback
  *
  * This function will set a callback function to be used when a PIN is
  * required for PKCS 11 operations.  See
- * gnutls_pkcs11_pin_callback_t() on how the callback should behave.
+ * gnutls_pin_callback_t() on how the callback should behave.
  *
  * Since: 2.12.0
  **/
 void
-gnutls_pkcs11_set_pin_function (gnutls_pkcs11_pin_callback_t fn,
+gnutls_pkcs11_set_pin_function (gnutls_pin_callback_t fn,
                                 void *userdata)
 {
   _gnutls_pin_func = fn;
@@ -660,12 +660,12 @@ gnutls_pkcs11_set_pin_function (gnutls_pkcs11_pin_callback_t fn,
 
 /**
  * gnutls_pkcs11_advset_pin_function:
- * @fn: The PIN callback, a gnutls_pkcs11_pin_callback_t() function.
+ * @fn: The PIN callback, a gnutls_pin_callback_t() function.
  * @userdata: data to be supplied to callback
  *
  * This function will set a callback function to be used when a PIN is
  * required for PKCS 11 operations.  See
- * gnutls_pkcs11_pin_callback_t() on how the callback should behave.
+ * gnutls_pin_callback_t() on how the callback should behave.
  * 
  * This function unlike gnutls_pkcs11_set_pin_function() will only
  * set the provided function if it has not previously been set. 
@@ -673,7 +673,7 @@ gnutls_pkcs11_set_pin_function (gnutls_pkcs11_pin_callback_t fn,
  * Since: 3.1.0
  **/
 void
-gnutls_pkcs11_advset_pin_function (gnutls_pkcs11_pin_callback_t fn,
+gnutls_pkcs11_advset_pin_function (gnutls_pin_callback_t fn,
                                 void *userdata)
 {
   if (_gnutls_pin_func == NULL)
index 4da410767066e983dd75b77d233d17c5281ca56d..a77e6101273471eada2fb99f1e878fa47986d5ea 100644 (file)
@@ -34,7 +34,7 @@
 #include <p11-kit/uri.h>
 typedef unsigned char ck_bool_t;
 
-extern gnutls_pkcs11_pin_callback_t _gnutls_pin_func;
+extern gnutls_pin_callback_t _gnutls_pin_func;
 extern void *_gnutls_pin_data;
 
 struct pkcs11_session_info {
index 1cc4d18c6b809def61e98a51a590ca35955e3c95..800a45bd69971110d2e8c37ea5b866d35d7e69ef 100644 (file)
@@ -33,7 +33,7 @@ struct gnutls_pkcs11_privkey_st
   gnutls_pk_algorithm_t pk_algorithm;
   unsigned int flags;
   struct p11_kit_uri *info;
-  gnutls_pkcs11_pin_callback_t pin_func;
+  gnutls_pin_callback_t pin_func;
   void *pin_data;
   
   struct pkcs11_session_info sinfo;
index ca72c8fe782af8bfd7ff699ed6df94c2afe96457..3549213f9c39c03320c5471737512339f2c3fb80 100644 (file)
@@ -755,7 +755,7 @@ gnutls_pkcs11_token_init (const char *token_url,
  * @token_url: A PKCS #11 URL specifying a token
  * @oldpin: old user's PIN
  * @newpin: new user's PIN
- * @flags: one of #gnutls_pkcs11_pin_flag_t.
+ * @flags: one of #gnutls_pin_flag_t.
  *
  * This function will modify or set a user's PIN for the given token. 
  * If it is called to set a user pin for first time the oldpin must