Add error code about trust-anchor is not installed 30/157730/1
authorsangwan.kwon <sangwan.kwon@samsung.com>
Wed, 25 Oct 2017 08:33:51 +0000 (17:33 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Thu, 26 Oct 2017 04:44:30 +0000 (13:44 +0900)
[Background]
- Launcher-pad cannot get information of the package
  which trust-anchor is installed or not.

[Solution]
- Add new error code (TRUST_ANCHOR_ERROR_NOT_INSTALLED)

Change-Id: I45543949a96bcdaac3d0b933cc87ace20866f5df
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
api/tanchor/error.h
api/tanchor/trust-anchor.h
examples/launcher.c
src/logic.cpp
src/logic.hxx
src/trust-anchor.cpp
tests/test-launcher.cpp

index 443e50cdd2b610ce4ab1ee2f08477f62e4a8e889..7104fe6bbf1f7f89ed7c682d9d75b649e2a249fa 100644 (file)
@@ -45,7 +45,8 @@ typedef enum {
        TRUST_ANCHOR_ERROR_OUT_OF_MEMORY = -ENOMEM,
        TRUST_ANCHOR_ERROR_PERMISSION_DENIED = -EACCES,
        TRUST_ANCHOR_ERROR_NO_SUCH_FILE = -ENOENT,
-       TRUST_ANCHOR_ERROR_INTERNAL = TRUST_ANCHOR_ERROR_BASE | 0x01
+       TRUST_ANCHOR_ERROR_INTERNAL = TRUST_ANCHOR_ERROR_BASE | 0x01,
+       TRUST_ANCHOR_ERROR_NOT_INSTALLED = TRUST_ANCHOR_ERROR_BASE | 0x02
 } trust_anchor_error_e;
 
 
index 40ab82dabf5bdbfad71459aa08fe587548e007af..ea54c05d9d27a628dc858383d30aa163524a9125 100644 (file)
@@ -75,6 +75,7 @@ int trust_anchor_install(const char *package_id,
  * @retval #TRUST_ANCHOR_ERROR_PERMISSION_DENIED Permission denied error
  * @retval #TRUST_ANCHOR_ERROR_NO_SUCH_FILE No such file or directory error
  * @retval #TRUST_ANCHOR_ERROR_INTERNAL Internal error
+ * @retval #TRUST_ANCHOR_ERROR_NOT_INSTALLED Not installed error
  * @see trust_anchor_install()
  */
 int trust_anchor_launch(const char *package_id, uid_t uid);
index 51320bfb00c2b28719845903ae066ed9254171a9..2ded3f07acb14efd93d5c61a262ef5e893c4990c 100644 (file)
@@ -40,6 +40,9 @@ int main()
 
        int ret = trust_anchor_launch("pkgid", uid);
        if (ret != TRUST_ANCHOR_ERROR_NONE) {
+               if (ret == TRUST_ANCHOR_ERROR_NOT_INSTALLED)
+                       printf("This package is not installed with trsut-anchor.");
+
                printf("Failed to launch operation");
                return -1;
        }
index bada39700aa4206fac936a0ca0532d02c376c221..bd56ddc98b558197c9a3df181d8e90ce9677095a 100644 (file)
@@ -144,6 +144,12 @@ void Logic::makeCustomBundle(void)
        INFO(SINK, "Success to make pkg custom bundle.");
 }
 
+bool Logic::isCustomBaseValid(void) const
+{
+       runtime::File customBaseDir(this->m_customBasePath);
+       return customBaseDir.exists();
+}
+
 bool Logic::isPkgCertsValid(const std::string &path) const
 {
        runtime::File file(path);
index f55ef588e15bdf4912246ed543cc820d8c8ce1a9..52d11559ea4b4288036a273f1483f51327b0e8dc 100644 (file)
@@ -42,6 +42,7 @@ public:
 
        void makeCustomCerts(void);
        void makeCustomBundle(void);
+       bool isCustomBaseValid(void) const;
 
        void setPkgCertsPath(const std::string &path) const;
        std::string getPkgCertsPath(void) const;
index 05654b5cc2580b33362933be9f4e65760ee8bbd2..aca3b949c79858617133db342fc85b1cff7d00c3 100644 (file)
@@ -106,10 +106,13 @@ int TrustAnchor::Impl::uninstall(void) const noexcept
 
 void TrustAnchor::Impl::preLaunch(void)
 {
+       if (!this->m_logic.isCustomBaseValid())
+               ThrowExc(TRUST_ANCHOR_ERROR_NOT_INSTALLED, "Base directory does not exist.");
+
        if (!this->m_logic.isSystemCertsUsed())
                return;
 
-       DEBUG(SINK, "This package use system certificates.");
+       DEBUG(SINK, "This package uses system certificates.");
        if (this->m_logic.isSystemCertsModified()) {
                WARN(SINK, "System certificates be changed. Do re-install for refresh.");
                this->install(this->m_logic.getPkgCertsPath(), true);
index 1034c0fd9dfc6acaacf38c319ddfa2bd9fcf194f..aa5ea3993d59bcbdc58c55e41c2ff890d4fe849b 100644 (file)
@@ -27,6 +27,7 @@
 #include <unistd.h>
 
 #include <iostream>
+#include <thread>
 
 #include "test-util.hxx"
 #include "test-resource.hxx"
@@ -103,3 +104,23 @@ TESTCASE(TRUST_ANCHOR_LAUNCH_WITH_SYS)
                TEST_EXPECT(true, beforeCat == afterCatParent);
        }
 }
+
+TESTCASE(TRUST_ANCHOR_LAUNCH_NOT_INSTALLED)
+{
+       std::this_thread::sleep_for(std::chrono::seconds(1));
+       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_UID);
+       int ret = ta.uninstall();
+       TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
+
+       // pre-condition
+       int pid = fork();
+       TEST_EXPECT(true, pid >= 0);
+
+       if (pid == 0) {
+               ret = ta.launch();
+               TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NOT_INSTALLED);
+
+               exit(0);
+       }
+}
+