summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Baptiste Dubois <jean-baptiste.dubois@parrot.com>2013-10-25 15:23:20 +0200
committerJens Georg <jensg@openismus.com>2013-10-31 01:10:07 +0100
commitd3631e321b106d47e6a3e9fd46149b53b6f68a8b (patch)
tree3eae3a4bbd14c3af70d4ab32aa88d75c739be1f5
parent6cccd5a767ec6f871a3c25ef855cfe987fed10f5 (diff)
downloadrygel-d3631e321b106d47e6a3e9fd46149b53b6f68a8b.tar.gz
server: Use base64url instead of base64
Encoded base64 uris may have '/' chars which cause issues in function HTTPItemURI.from_string https://bugzilla.gnome.org/show_bug.cgi?id=710877
-rw-r--r--src/librygel-server/rygel-http-item-uri.vala26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/librygel-server/rygel-http-item-uri.vala b/src/librygel-server/rygel-http-item-uri.vala
index e1018b68..2b92237b 100644
--- a/src/librygel-server/rygel-http-item-uri.vala
+++ b/src/librygel-server/rygel-http-item-uri.vala
@@ -119,6 +119,22 @@ internal class Rygel.HTTPItemURI : Object {
}
}
+ // Base 64 Encoding with URL and Filename Safe Alphabet
+ // http://tools.ietf.org/html/rfc4648#section-5
+ private string base64_urlencode (string data) {
+ var enc64 = Base64.encode ((uchar[]) data.to_utf8 ());
+ enc64 = enc64.replace ("/", "_");
+
+ return enc64.replace ("+", "-");
+ }
+
+ private uchar[] base64_urldecode (string data) {
+ var dec64 = data.replace ("_", "/");
+ dec64 = dec64.replace ("-", "+");
+
+ return Base64.decode (dec64);
+ }
+
public HTTPItemURI.from_string (string uri,
HTTPServer http_server)
throws HTTPRequestError {
@@ -148,7 +164,8 @@ internal class Rygel.HTTPItemURI : Object {
for (int i = 1; i < parts.length - 1; i += 2) {
switch (parts[i]) {
case "i":
- var data = Base64.decode (Soup.URI.decode (parts[i + 1]));
+ var data = this.base64_urldecode
+ (Soup.URI.decode (parts[i + 1]));
StringBuilder builder = new StringBuilder ();
builder.append ((string) data);
this.item_id = builder.str;
@@ -184,10 +201,9 @@ internal class Rygel.HTTPItemURI : Object {
// there seems to be a problem converting strings properly to arrays
// you need to call to_utf8() and assign it to a variable to make it
// work properly
- var data = this.item_id.to_utf8 ();
- var escaped = Uri.escape_string (Base64.encode ((uchar[]) data),
- "",
- true);
+
+ var data = this.base64_urlencode (this.item_id);
+ var escaped = Uri.escape_string (data, "", true);
string path = "/i/" + escaped;
if (this.transcode_target != null) {