Fix ACTA directory hierarchy 26/116126/2
authorsangwan.kwon <sangwan.kwon@samsung.com>
Thu, 23 Feb 2017 05:37:53 +0000 (14:37 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Thu, 23 Feb 2017 05:56:32 +0000 (14:56 +0900)
* Add empty bundle for usr app.

Change-Id: I8bb6cdb89ffb17f678633bc984d17ec05b2579b6
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
CMakeLists.txt
packaging/cert-svc.spec
src/transec/AppCustomTrustAnchor.cpp

index 1b06c31a591ebd3f0b392eba3e9b3bb27debd858..4c3700ce0de2e97aba2824509a0908ebd8c21448 100644 (file)
@@ -34,7 +34,9 @@ ADD_DEFINITIONS("-DSERVER_STREAM=\"${SERVER_STREAM}\"")
 
 ADD_DEFINITIONS("-DCERTSVC_SYSTEM_STORE_DB=\"${CERT_SVC_DB_PATH}/certs-meta.db\"")
 ADD_DEFINITIONS("-DCERTSVC_PKCS12_STORAGE_DIR=\"${CERT_SVC_PKCS12}/\"")
-ADD_DEFINITIONS("-DCERTSVC_TRANSEC_DIR=\"${CERT_SVC_TRANSEC}\"")
+ADD_DEFINITIONS("-DCERTSVC_TRANSEC_USR_DIR=\"${CERT_SVC_TRANSEC_USR}\"")
+ADD_DEFINITIONS("-DCERTSVC_TRANSEC_GLOBAL_DIR=\"${CERT_SVC_TRANSEC_GLOBAL}\"")
+ADD_DEFINITIONS("-DCERTSVC_TRANSEC_BUNDLE=\"${CERT_SVC_TRANSEC_BUNDLE}\"")
 
 ADD_DEFINITIONS("-DTZ_SYS_CA_CERTS=\"${TZ_SYS_CA_CERTS}\"")
 ADD_DEFINITIONS("-DTZ_SYS_CA_CERTS_ORIG=\"${TZ_SYS_CA_CERTS_ORIG}\"")
index 0a24a32fe08359880e3028575301c79aa6c23cdd..43a5342dd7cf0e140e60e267612ab18ec88e2f5b 100644 (file)
@@ -48,6 +48,10 @@ Requires: openssl
 %global cert_svc_db_path        %cert_svc_path/dbspace
 %global cert_svc_pkcs12         %cert_svc_path/pkcs12
 %global cert_svc_transec        %cert_svc_path/transec
+%global cert_svc_transec_res    %cert_svc_transec/res
+%global cert_svc_transec_usr    %cert_svc_transec/usr
+%global cert_svc_transec_global %cert_svc_transec/global
+%global cert_svc_transec_bundle %cert_svc_transec_res/ca-bundle.pem
 %global cert_svc_ca_bundle      %cert_svc_path/ca-certificate.crt
 %global cert_svc_examples       %cert_svc_ro_path/examples
 %global cert_svc_tests          %rw_app_dir/cert-svc-tests
@@ -115,7 +119,9 @@ export FFLAGS="$FFLAGS -DTIZEN_EMULATOR_MODE"
          -DCERT_SVC_PATH=%cert_svc_path \
          -DCERT_SVC_RO_PATH=%cert_svc_ro_path \
          -DCERT_SVC_PKCS12=%cert_svc_pkcs12 \
-         -DCERT_SVC_TRANSEC=%cert_svc_transec \
+         -DCERT_SVC_TRANSEC_USR=%cert_svc_transec_usr \
+         -DCERT_SVC_TRANSEC_GLOBAL=%cert_svc_transec_global \
+         -DCERT_SVC_TRANSEC_BUNDLE=%cert_svc_transec_bundle \
          -DCERT_SVC_DB_PATH=%cert_svc_db_path \
          -DCERT_SVC_OLD_DB_PATH=%cert_svc_old_db_path \
          -DUPGRADE_SCRIPT_PATH=%upgrade_script_path \
@@ -135,9 +141,12 @@ make %{?_smp_mflags}
 %install_service sockets.target.wants cert-server.socket
 
 mkdir -p %buildroot%cert_svc_pkcs12
-mkdir -p %buildroot%cert_svc_transec
+mkdir -p %buildroot%cert_svc_transec_res
+mkdir -p %buildroot%cert_svc_transec_usr
+mkdir -p %buildroot%cert_svc_transec_global
 
 touch %buildroot%cert_svc_db_path/certs-meta.db-journal
+touch %buildroot%cert_svc_transec_bundle
 
 ln -sf %TZ_SYS_CA_BUNDLE %buildroot%cert_svc_ca_bundle
 
@@ -178,6 +187,7 @@ fi
 %attr(-, %{user_name}, %{group_name}) %cert_svc_db_path/certs-meta.db
 %attr(-, %{user_name}, %{group_name}) %cert_svc_db_path/certs-meta.db-journal
 %attr(-, %{user_name}, %{group_name}) %cert_svc_ro_path
+%attr(-, %{user_name}, %{group_name}) %cert_svc_transec/*
 
 %attr(755, root, root) %upgrade_script_path/202.cert-svc-db-upgrade.sh
 %attr(755, root, root) %upgrade_script_path/203.cert-svc-disabled-certs-upgrade.sh
index bee507059c35c1ffb95ab875a4fe10407045d303..edd5ac2529e610cc715d52e6ae3607d8b11fad97 100644 (file)
@@ -40,9 +40,9 @@ namespace transec {
 
 namespace {
 
-const std::string BASE_PATH(CERTSVC_TRANSEC_DIR);
-const std::string BASE_CERTS_PATH(BASE_PATH + "/certs");
-const std::string BASE_BUNDLE_PATH(BASE_PATH + "/bundle");
+const std::string BASE_USR_PATH(CERTSVC_TRANSEC_USR_DIR);
+const std::string BASE_GLOBAL_PATH(CERTSVC_TRANSEC_GLOBAL_DIR);
+const std::string TRANSEC_BUNDLE_PATH(CERTSVC_TRANSEC_BUNDLE);
 const std::string SYS_CERTS_PATH(TZ_SYS_CA_CERTS);
 const std::string SYS_BUNDLE_PATH(TZ_SYS_CA_BUNDLE);
 const std::string MOUNT_POINT_CERTS(TZ_SYS_CA_CERTS);
@@ -76,6 +76,7 @@ private:
        std::string m_appCertsPath;
        uid_t m_uid;
 
+       std::string m_customBasePath;
        std::string m_customCertsPath;
        std::string m_customBundlePath;
 
@@ -88,12 +89,11 @@ AppCustomTrustAnchor::Impl::Impl(const std::string &packageId,
        m_packageId(packageId),
        m_appCertsPath(certsDir),
        m_uid(uid),
-       m_customCertsPath(BASE_CERTS_PATH + "/usr/" +
-                                         std::to_string(static_cast<int>(uid)) + "/" +
-                                         packageId),
-       m_customBundlePath(BASE_BUNDLE_PATH + "/usr/" +
-                                          std::to_string(static_cast<int>(uid)) + "/" +
-                                          packageId),
+       m_customBasePath(BASE_USR_PATH + "/" +
+                                        std::to_string(static_cast<int>(uid)) + "/" +
+                                        packageId),
+       m_customCertsPath(m_customBasePath + "/certs"),
+       m_customBundlePath(m_customBasePath + "/bundle"),
        m_customCertNameSet() {}
 
 AppCustomTrustAnchor::Impl::Impl(const std::string &packageId,
@@ -101,8 +101,9 @@ AppCustomTrustAnchor::Impl::Impl(const std::string &packageId,
        m_packageId(packageId),
        m_appCertsPath(certsDir),
        m_uid(-1),
-       m_customCertsPath(BASE_CERTS_PATH + "/global/" + packageId),
-       m_customBundlePath(BASE_BUNDLE_PATH + "/global/" + packageId),
+       m_customBasePath(BASE_GLOBAL_PATH + "/" + packageId),
+       m_customCertsPath(m_customBasePath + "/certs"),
+       m_customBundlePath(m_customBasePath + "/bundle"),
        m_customCertNameSet() {}
 
 std::string AppCustomTrustAnchor::Impl::readLink(const std::string &path) const
@@ -124,19 +125,18 @@ void AppCustomTrustAnchor::Impl::linkTo(const std::string &src,
 
 void AppCustomTrustAnchor::Impl::preInstall(void) const
 {
-       runtime::File customCertsDir(this->m_customCertsPath);
-       if (customCertsDir.exists()) {
-               WARN("App custom certs directory is already exist. remove it!");
-               customCertsDir.remove(true);
+       runtime::File customBaseDir(this->m_customBasePath);
+       if (customBaseDir.exists()) {
+               WARN("App custom directory is already exist. remove it!");
+               customBaseDir.remove(true);
        }
-       customCertsDir.makeDirectory(true);
+       customBaseDir.makeDirectory(true);
+
+       runtime::File customCertsDir(this->m_customCertsPath);
+       customCertsDir.makeDirectory();
 
        runtime::File customBundleDir(this->m_customBundlePath);
-       if (customBundleDir.exists()) {
-               WARN("App custom bundle directory is already exist. remove it!");
-               customBundleDir.remove(true);
-       }
-       customBundleDir.makeDirectory(true);
+       customBundleDir.makeDirectory();
 
        runtime::File appCertsDir(this->m_appCertsPath);
        if (!appCertsDir.exists() || !appCertsDir.isDirectory())
@@ -188,7 +188,7 @@ int AppCustomTrustAnchor::Impl::install(bool withSystemCerts) noexcept
        this->makeCustomBundle(customCertData);
 
        INFO("Success to install[" << this->m_packageId <<
-                "] to " << this->m_customCertsPath);
+                "] to " << this->m_customBasePath);
        return 0;
 
        EXCEPTION_GUARD_END
@@ -198,19 +198,12 @@ int AppCustomTrustAnchor::Impl::uninstall(bool isRollback) noexcept
 {
        EXCEPTION_GUARD_START
 
-       runtime::File customCertsDir(this->m_customCertsPath);
-       if (!customCertsDir.exists() && !isRollback)
-               throw std::invalid_argument("There is no installed certs previous.");
-
-       runtime::File customBundleDir(this->m_customBundlePath);
-       if (!customBundleDir.exists() && !isRollback)
-               throw std::invalid_argument("There is no installed bundle previous.");
-
-       if (customCertsDir.exists())
-               customCertsDir.remove(true);
+       runtime::File customBaseDir(this->m_customBasePath);
+       if (!customBaseDir.exists() && !isRollback)
+               throw std::invalid_argument("There is no installed acta previous.");
 
-       if (!customBundleDir.exists())
-               customBundleDir.remove(true);
+       if (customBaseDir.exists())
+               customBaseDir.remove(true);
 
        INFO("Success to uninstall. : " << this->m_packageId);
        return 0;
@@ -276,7 +269,11 @@ void AppCustomTrustAnchor::Impl::makeCustomBundle(
                                                           BUNDLE_NAME);
        if (!customBundle.exists()) {
                DEBUG("Make bundle only used by app certificates.");
-               customBundle.create(755);
+               // copy transec bundle to the custom path
+               runtime::File transecBundle(TRANSEC_BUNDLE_PATH);
+               if (!transecBundle.exists())
+                       throw std::logic_error("There is no transec bundle file.");
+               transecBundle.copyTo(this->m_customBundlePath);
        }
 
        customBundle.open(O_RDWR | O_APPEND);