Add url decoding for 'uri' attribute of signatures 68/34368/6
authorsung-su.kim <sung-su.kim@samsung.com>
Wed, 4 Feb 2015 02:08:46 +0000 (11:08 +0900)
committersung-su.kim <sung-su.kim@samsung.com>
Sat, 7 Feb 2015 04:04:47 +0000 (13:04 +0900)
The value of URI attribute of signature files can be encoded uri.
But, SignatureValidator can't recongize encoded 'uri'.
Add url decoding routine to SignatureParser.

Change-Id: Ifec7b04b2a591bddca15fbe3cdafa90d2a0964c5

src/signature/signature_parser.cc

index c216fbb..749c0c8 100644 (file)
@@ -13,6 +13,7 @@
 #include <libxml/xpathInternals.h>
 #include <libxml/xmlreader.h>
 
+#include <cstdlib>
 #include <cstring>
 #include <list>
 #include <set>
@@ -121,6 +122,31 @@ std::string XmlStringToStdString(const xmlChar* xmlstring) {
     return "";
 }
 
+std::string DecodeProcent(const std::string& path) {
+  std::vector<int> input(path.begin(), path.end());
+  std::vector<char> output;
+  int i = 0;
+  while (i < input.size()) {
+    if ('%' == input[i]) {
+      if (i + 2 >= input.size())
+        return std::string();
+      char str[3] = {"\0",};
+      str[0] = input[i + 1];
+      str[1] = input[i + 2];
+      int result = strtol(str, NULL, 16);
+      // RFC 1738 - octets 80 to FF are not allowed
+      if (result >= 128)
+        return std::string();
+      output.push_back(static_cast<char>(result));
+      i += 3;
+    } else {
+      output.push_back(static_cast<char>(input[i]));
+      ++i;
+    }
+  }
+  return std::string(output.begin(), output.end());
+}
+
 }  // namespace
 
 namespace common_installer {
@@ -175,6 +201,12 @@ bool ParseSignedInfoElement(
       LOG(ERROR) << "Missing URI attribute.";
       return false;
     }
+    std::string decoded_uri = DecodeProcent(uri);
+    if (!decoded_uri.empty()) {
+      uri = decoded_uri;
+    } else {
+      LOG(WARNING) << "Failing to decode URI.";
+    }
     reference_set.insert(uri);
   }
   data->set_reference_set(reference_set);