Support content type application/octet-stream for passwords

* Older versions of gnome-keyring erroneously set this content type
   for passwords even though they're textual.
 * If we see this content type, then check if the password is textual
   and allow usage as a null-terminated password
This commit is contained in:
Stef Walter 2012-03-25 12:23:29 +02:00
parent 11cc25f4e8
commit 3aa77c6918
3 changed files with 20 additions and 17 deletions

View File

@ -556,7 +556,6 @@ secret_password_lookup_nonpageable_finish (GAsyncResult *result,
{
GSimpleAsyncResult *res;
LookupClosure *closure;
const gchar *content_type;
gchar *password = NULL;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@ -571,12 +570,8 @@ secret_password_lookup_nonpageable_finish (GAsyncResult *result,
if (closure->value == NULL)
return NULL;
content_type = secret_value_get_content_type (closure->value);
if (content_type && g_str_equal (content_type, "text/plain")) {
password = _secret_value_unref_to_password (closure->value);
closure->value = NULL;
}
return password;
}
@ -596,7 +591,6 @@ secret_password_lookup_finish (GAsyncResult *result,
{
GSimpleAsyncResult *res;
LookupClosure *closure;
const gchar *content_type;
gchar *string = NULL;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@ -611,12 +605,8 @@ secret_password_lookup_finish (GAsyncResult *result,
if (closure->value == NULL)
return NULL;
content_type = secret_value_get_content_type (closure->value);
if (content_type && g_str_equal (content_type, "text/plain")) {
string = _secret_value_unref_to_string (closure->value);
closure->value = NULL;
}
return string;
}

View File

@ -219,6 +219,19 @@ secret_value_unref (gpointer value)
}
}
static gboolean
is_password_value (SecretValue *value)
{
if (value->content_type && g_str_equal (value->content_type, "text/plain"))
return TRUE;
/* gnome-keyring-daemon used to return passwords like this, so support this, but validate */
if (!value->content_type || g_str_equal (value->content_type, "application/octet-stream"))
return g_utf8_validate (value->secret, value->length, NULL);
return FALSE;
}
gchar *
_secret_value_unref_to_password (SecretValue *value)
{
@ -227,7 +240,7 @@ _secret_value_unref_to_password (SecretValue *value)
g_return_val_if_fail (value != NULL, NULL);
if (val->content_type && !g_str_equal (val->content_type, "text/plain")) {
if (!is_password_value (value)) {
secret_value_unref (value);
return NULL;
}
@ -259,7 +272,7 @@ _secret_value_unref_to_string (SecretValue *value)
g_return_val_if_fail (value != NULL, NULL);
if (val->content_type && !g_str_equal (val->content_type, "text/plain")) {
if (!is_password_value (value)) {
secret_value_unref (value);
return NULL;
}

View File

@ -164,7 +164,7 @@ test_to_password_bad_content (void)
SecretValue *value;
gchar *password;
value = secret_value_new_full (g_strdup ("wooowhee"), -1,
value = secret_value_new_full (g_strdup ("w\xFFooowhee"), -1,
"application/octet-stream", g_free);
password = _secret_value_unref_to_password (value);