summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2012-07-27 15:52:03 -0400
committerStef Walter <stefw@gnome.org>2012-07-28 10:48:29 +0200
commit76180db6b326f8c87aef5b3eded9463432ce8d82 (patch)
tree9c4e77c13f7089a5a5a6d39bf5bbef2ee4a1bfdf
parentc6fc7b3ac4c6d4595f17989cff220d6d6dafe620 (diff)
downloadp11-kit-76180db6b326f8c87aef5b3eded9463432ce8d82.tar.gz
Always encode the "id" attribute in URIs
Per recommendation of the spec. https://bugs.freedesktop.org/show_bug.cgi?id=52606
-rw-r--r--p11-kit/uri.c24
-rw-r--r--tests/uri-test.c2
2 files changed, 15 insertions, 11 deletions
diff --git a/p11-kit/uri.c b/p11-kit/uri.c
index b9e2554..b9eef1f 100644
--- a/p11-kit/uri.c
+++ b/p11-kit/uri.c
@@ -206,7 +206,7 @@ url_decode (const char *value, const char *end,
}
static char*
-url_encode (const unsigned char *value, const unsigned char *end, size_t *length)
+url_encode (const unsigned char *value, const unsigned char *end, size_t *length, int force)
{
char *p;
char *result;
@@ -222,7 +222,7 @@ url_encode (const unsigned char *value, const unsigned char *end, size_t *length
while (value != end) {
/* These characters we let through verbatim */
- if (*value && (isalnum (*value) || strchr ("_-.", *value) != NULL)) {
+ if (*value && !force && (isalnum (*value) || strchr ("_-.", *value) != NULL)) {
*(p++) = *(value++);
/* All others get encoded */
@@ -822,12 +822,12 @@ format_raw_string (char **string, size_t *length, int *is_first,
static int
format_encode_string (char **string, size_t *length, int *is_first,
const char *name, const unsigned char *value,
- size_t n_value)
+ size_t n_value, int force)
{
char *encoded;
int ret;
- encoded = url_encode (value, value + n_value, NULL);
+ encoded = url_encode (value, value + n_value, NULL, force);
return_val_if_fail (encoded != NULL, 0);
ret = format_raw_string (string, length, is_first, name, encoded);
@@ -848,19 +848,21 @@ format_struct_string (char **string, size_t *length, int *is_first,
return 1;
len = p11_kit_space_strlen (value, value_max);
- return format_encode_string (string, length, is_first, name, value, len);
+ return format_encode_string (string, length, is_first, name, value, len, 0);
}
static int
format_attribute_string (char **string, size_t *length, int *is_first,
- const char *name, CK_ATTRIBUTE_PTR attr)
+ const char *name, CK_ATTRIBUTE_PTR attr,
+ int force)
{
/* Not set */;
if (attr == NULL)
return 1;
return format_encode_string (string, length, is_first, name,
- attr->pValue, attr->ulValueLen);
+ attr->pValue, attr->ulValueLen,
+ force);
}
static int
@@ -988,9 +990,11 @@ p11_kit_uri_format (P11KitUri *uri, P11KitUriType uri_type, char **string)
if ((uri_type & P11_KIT_URI_FOR_OBJECT) == P11_KIT_URI_FOR_OBJECT) {
if (!format_attribute_string (&result, &length, &is_first, "id",
- p11_kit_uri_get_attribute (uri, CKA_ID)) ||
+ p11_kit_uri_get_attribute (uri, CKA_ID),
+ 1) ||
!format_attribute_string (&result, &length, &is_first, "object",
- p11_kit_uri_get_attribute (uri, CKA_LABEL))) {
+ p11_kit_uri_get_attribute (uri, CKA_LABEL),
+ 0)) {
return_val_if_reached (P11_KIT_URI_UNEXPECTED);
}
@@ -1003,7 +1007,7 @@ p11_kit_uri_format (P11KitUri *uri, P11KitUriType uri_type, char **string)
if (uri->pin_source) {
if (!format_encode_string (&result, &length, &is_first, "pin-source",
(const unsigned char*)uri->pin_source,
- strlen (uri->pin_source))) {
+ strlen (uri->pin_source), 0)) {
return_val_if_reached (P11_KIT_URI_UNEXPECTED);
}
}
diff --git a/tests/uri-test.c b/tests/uri-test.c
index 16480f6..4780e4e 100644
--- a/tests/uri-test.c
+++ b/tests/uri-test.c
@@ -510,7 +510,7 @@ test_uri_build_with_attributes (CuTest *tc)
CuAssertTrue (tc, strstr (string, "object=The%20Label") != NULL);
CuAssertTrue (tc, strstr (string, "object-type=data") != NULL);
- CuAssertTrue (tc, strstr (string, "id=HELLO") != NULL);
+ CuAssertTrue (tc, strstr (string, "id=%48%45%4c%4c%4f") != NULL);
free (string);
p11_kit_uri_free (uri);