]> granicus.if.org Git - p11-kit/commitdiff
Added support for pin-value PKCS#11 URI element
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 23 Dec 2014 07:04:18 +0000 (09:04 +0200)
committerStef Walter <stefw@redhat.com>
Fri, 20 Feb 2015 20:17:24 +0000 (21:17 +0100)
https://bugs.freedesktop.org/show_bug.cgi?id=87582

p11-kit/uri.c
p11-kit/uri.h

index 2aa4e837dc42992d2e2c2c8778f836c11d067d99..df7d1492857e6b210977e74beaf5d189ebf350a5 100644 (file)
@@ -144,6 +144,7 @@ struct p11_kit_uri {
        CK_TOKEN_INFO token;
        CK_ATTRIBUTE *attrs;
        char *pin_source;
+       char *pin_value;
 };
 
 static char *
@@ -539,6 +540,39 @@ p11_kit_uri_any_unrecognized (P11KitUri *uri)
        return uri->unrecognized;
 }
 
+/**
+ * p11_kit_uri_get_pin_value:
+ * @uri: The URI
+ *
+ * Get the 'pin-value' part of the URI. This is used by some applications to
+ * read the PIN for logging into a PKCS\#11 token.
+ *
+ * Returns: The pin-value or %NULL if not present.
+ */
+const char*
+p11_kit_uri_get_pin_value (P11KitUri *uri)
+{
+       return_val_if_fail (uri != NULL, NULL);
+       return uri->pin_value;
+}
+
+/**
+ * p11_kit_uri_set_pin_value:
+ * @uri: The URI
+ * @pin: The new pin-value
+ *
+ * Set the 'pin-value' part of the URI. This is used by some applications to
+ * specify the PIN for logging into a PKCS\#11 token.
+ */
+void
+p11_kit_uri_set_pin_value (P11KitUri *uri, const char *pin)
+{
+       return_if_fail (uri != NULL);
+       free (uri->pin_value);
+       uri->pin_value = pin ? strdup (pin) : NULL;
+}
+
+
 /**
  * p11_kit_uri_get_pin_source:
  * @uri: The URI
@@ -859,6 +893,14 @@ p11_kit_uri_format (P11KitUri *uri, P11KitUriType uri_type, char **string)
                }
        }
 
+       if (uri->pin_value) {
+               if (!format_encode_string (&buffer, &is_first, "pin-value",
+                                          (const unsigned char*)uri->pin_value,
+                                          strlen (uri->pin_value), 0)) {
+                       return_val_if_reached (P11_KIT_URI_UNEXPECTED);
+               }
+       }
+
        return_val_if_fail (p11_buffer_ok (&buffer), P11_KIT_URI_UNEXPECTED);
        *string = p11_buffer_steal (&buffer, NULL);
        return P11_KIT_URI_OK;
@@ -1091,6 +1133,13 @@ parse_extra_info (const char *name, const char *start, const char *end,
                free (uri->pin_source);
                uri->pin_source = (char*)pin_source;
                return 1;
+       } else if (strcmp (name, "pin-value") == 0) {
+               pin_source = p11_url_decode (start, end, P11_URL_WHITESPACE, NULL);
+               if (pin_source == NULL)
+                       return P11_KIT_URI_BAD_ENCODING;
+               free (uri->pin_value);
+               uri->pin_value = (char*)pin_source;
+               return 1;
        }
 
        return 0;
@@ -1153,6 +1202,8 @@ p11_kit_uri_parse (const char *string, P11KitUriType uri_type,
        uri->unrecognized = 0;
        free (uri->pin_source);
        uri->pin_source = NULL;
+       free (uri->pin_value);
+       uri->pin_value = NULL;
 
        for (;;) {
                spos = strchr (string, ';');
@@ -1213,6 +1264,7 @@ p11_kit_uri_free (P11KitUri *uri)
 
        p11_attrs_free (uri->attrs);
        free (uri->pin_source);
+       free (uri->pin_value);
        free (uri);
 }
 
index 64a8ec3b8c67a8d5f477cba804ae8e0b528a8f0b..0c20d855a04451ab89299d87e0fa8992075fe0ef 100644 (file)
@@ -122,6 +122,11 @@ int                 p11_kit_uri_match_attributes            (P11KitUri *uri,
                                                              CK_ATTRIBUTE_PTR attrs,
                                                              CK_ULONG n_attrs);
 
+const char*         p11_kit_uri_get_pin_value              (P11KitUri *uri);
+
+void                p11_kit_uri_set_pin_value              (P11KitUri *uri,
+                                                             const char *pin);
+
 const char*         p11_kit_uri_get_pin_source              (P11KitUri *uri);
 
 void                p11_kit_uri_set_pin_source              (P11KitUri *uri,