check metadata privilege level 99/102799/5 accepted/tizen/3.0/common/20161208.153402 accepted/tizen/3.0/ivi/20161208.062728 accepted/tizen/3.0/mobile/20161208.062428 accepted/tizen/3.0/tv/20161208.062556 accepted/tizen/3.0/wearable/20161208.062638 submit/tizen_3.0/20161207.072901
authorjongmyeongko <jongmyeong.ko@samsung.com>
Tue, 6 Dec 2016 13:03:17 +0000 (22:03 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Wed, 7 Dec 2016 12:30:50 +0000 (21:30 +0900)
Change-Id: I798acae8b829319579f7bbe16bf1a192380a99a3
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
src/common/certificate_validation.cc
src/common/certificate_validation.h
src/common/step/security/step_check_signature.cc
src/common/step/security/step_check_signature.h

index f602696..63fc757 100644 (file)
@@ -279,4 +279,25 @@ bool ValidatePrivilegeLevel(common_installer::PrivilegeLevel level,
   return true;
 }
 
+bool ValidateMetadataPrivilege(common_installer::PrivilegeLevel level,
+    const char* api_version, GList* metadata_list,
+    std::string* error_message) {
+  if (!metadata_list)
+    return true;
+  char* error = nullptr;
+  int status = PRVMGR_ERR_NONE;
+  status = privilege_manager_verify_metadata(api_version, metadata_list,
+          PrivilegeLevelToVisibility(level), &error);
+  if (status != PRVMGR_ERR_NONE) {
+      std::string errnum = boost::str(boost::format("%d") % status);
+      LOG(ERROR) << "Error while verifing metadata privilege: "
+                 << (error ? error : "") << " <" << errnum << ">";
+      *error_message = error;
+      *error_message += ":<" + errnum + ">";
+      free(error);
+      return false;
+  }
+  return true;
+}
+
 }  // namespace common_installer
index cbc36bb..0d3f693 100644 (file)
@@ -41,6 +41,10 @@ bool ValidatePrivilegeLevel(common_installer::PrivilegeLevel level,
     uid_t uid, const char* api_version, GList* privileges,
     std::string* error_message);
 
+bool ValidateMetadataPrivilege(common_installer::PrivilegeLevel level,
+    const char* api_version, GList* metadata_list,
+    std::string* error_message);
+
 }  // namespace common_installer
 
 #endif  // COMMON_CERTIFICATE_VALIDATION_H_
index 8e184b8..d0722bf 100644 (file)
@@ -100,6 +100,25 @@ Step::Status StepCheckSignature::CheckPrivilegeLevel(PrivilegeLevel level) {
   return Status::OK;
 }
 
+Step::Status StepCheckSignature::CheckMetadataPrivilege(PrivilegeLevel level) {
+  std::string error_message;
+  if (context_->is_readonly_package.get())
+    return Status::OK;
+  manifest_x* manifest = context_->manifest_data.get();
+  for (application_x* app :
+       GListRange<application_x*>(manifest->application)) {
+    if (!ValidateMetadataPrivilege(level, manifest->api_version, app->metadata,
+                                   &error_message)) {
+      if (!error_message.empty()) {
+        LOG(ERROR) << "error_message: " << error_message;
+        on_error(Status::SIGNATURE_ERROR, error_message);
+      }
+      return Status::SIGNATURE_ERROR;
+    }
+  }
+  return Status::OK;
+}
+
 Step::Status StepCheckSignature::process() {
   PrivilegeLevel level = PrivilegeLevel::UNTRUSTED;
   bool check_reference = true;
@@ -139,6 +158,10 @@ Step::Status StepCheckSignature::process() {
   if (status != Status::OK)
     return status;
 
+  status = CheckMetadataPrivilege(level);
+  if (status != Status::OK)
+    return status;
+
   LOG(INFO) << "Signature done";
   return Status::OK;
 }
index 7d5ef52..a9f51be 100644 (file)
@@ -50,6 +50,7 @@ class StepCheckSignature : public Step {
  private:
   Status CheckSignatures(bool check_reference, PrivilegeLevel* level);
   Status CheckSignatureMismatch();
+  Status CheckMetadataPrivilege(PrivilegeLevel level);
 
   STEP_NAME(Signature)
 };