From d6befe6edb55c374e4cf59e4d2d6160c88a92ace Mon Sep 17 00:00:00 2001 From: "sangwan.kwon" Date: Wed, 25 Oct 2017 17:33:51 +0900 Subject: [PATCH] Add error code about trust-anchor is not installed [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 --- api/tanchor/error.h | 3 ++- api/tanchor/trust-anchor.h | 1 + examples/launcher.c | 3 +++ src/logic.cpp | 6 ++++++ src/logic.hxx | 1 + src/trust-anchor.cpp | 5 ++++- tests/test-launcher.cpp | 21 +++++++++++++++++++++ 7 files changed, 38 insertions(+), 2 deletions(-) diff --git a/api/tanchor/error.h b/api/tanchor/error.h index 443e50c..7104fe6 100644 --- a/api/tanchor/error.h +++ b/api/tanchor/error.h @@ -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; diff --git a/api/tanchor/trust-anchor.h b/api/tanchor/trust-anchor.h index 40ab82d..ea54c05 100644 --- a/api/tanchor/trust-anchor.h +++ b/api/tanchor/trust-anchor.h @@ -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); diff --git a/examples/launcher.c b/examples/launcher.c index 51320bf..2ded3f0 100644 --- a/examples/launcher.c +++ b/examples/launcher.c @@ -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; } diff --git a/src/logic.cpp b/src/logic.cpp index bada397..bd56ddc 100644 --- a/src/logic.cpp +++ b/src/logic.cpp @@ -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); diff --git a/src/logic.hxx b/src/logic.hxx index f55ef58..52d1155 100644 --- a/src/logic.hxx +++ b/src/logic.hxx @@ -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; diff --git a/src/trust-anchor.cpp b/src/trust-anchor.cpp index 05654b5..aca3b94 100644 --- a/src/trust-anchor.cpp +++ b/src/trust-anchor.cpp @@ -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); diff --git a/tests/test-launcher.cpp b/tests/test-launcher.cpp index 1034c0f..aa5ea39 100644 --- a/tests/test-launcher.cpp +++ b/tests/test-launcher.cpp @@ -27,6 +27,7 @@ #include #include +#include #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); + } +} + -- 2.34.1