[API Changed] Refine launch, uninstall API 20/138520/2 accepted/tizen/unified/20170726.013008 submit/tizen/20170725.065700 submit/tizen/20170725.091352
authorsangwan.kwon <sangwan.kwon@samsung.com>
Wed, 12 Jul 2017 10:50:55 +0000 (19:50 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Wed, 12 Jul 2017 11:15:24 +0000 (20:15 +0900)
[AS-IS]
- Installer should save data(1):"package-certs-path".
- Launcher should be able to get data(1) for using launch API.
- Installer should be able to get data(1) for using uninstall API.

[TO-BE]
- Installer does not need to save and get data(1).
- Launcher does not need to get data(1).

Change-Id: Ieeec21a62830d5a02e53c592999e041feef1dc5a
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
21 files changed:
CMakeLists.txt
api/tanchor/trust-anchor.h
api/tanchor/trust-anchor.hxx
examples/installer.c
examples/launcher.c
packaging/trust-anchor.spec
src/api.cpp
src/certificate.cpp
src/certificate.hxx
src/environment.hxx
src/file-system.cpp
src/file-system.hxx
src/logic.cpp
src/logic.hxx
src/trust-anchor.cpp
tests/CMakeLists.txt
tests/test-capi-installer.cpp
tests/test-capi-launcher.cpp
tests/test-curl.cpp
tests/test-installer.cpp
tests/test-launcher.cpp

index 2af5a0a00924133b33173dbca0728572b37910f6..06282c44479fbe6c029bc408171df264368dc163 100644 (file)
@@ -37,6 +37,7 @@ ADD_DEFINITIONS("-DTANCHOR_PKG_DIR=\"${TANCHOR_PKG}\"")
 ADD_DEFINITIONS("-DTANCHOR_TEST_DIR=\"${TANCHOR_TEST}\"")
 ADD_DEFINITIONS("-DTANCHOR_BUNDLE=\"${TANCHOR_BUNDLE}\"")
 ADD_DEFINITIONS("-DTANCHOR_SYSCA=\"${TANCHOR_SYSCA}\"")
+ADD_DEFINITIONS("-DTANCHOR_PKG_CERTS=\"${TANCHOR_PKG_CERTS}\"")
 ADD_DEFINITIONS("-DTZ_SYS_CA_CERTS=\"${TZ_SYS_CA_CERTS}\"")
 ADD_DEFINITIONS("-DTZ_SYS_CA_BUNDLE=\"${TZ_SYS_CA_BUNDLE}\"")
 
index a19ac1d6021fcb435b79c6e61fb51561aa69ce1c..40ab82dabf5bdbfad71459aa08fe587548e007af 100644 (file)
@@ -42,8 +42,8 @@ extern "C" {
  * @details Package custom certificates would be installed on system.
  *          This function should be called before trust_anchor_launch().
  * @param[in] package_id Package id
- * @param[in] pkg_certs_path Package custom certificates path
  * @param[in] uid user id
+ * @param[in] pkg_certs_path Package custom certificates path
  * @param[in] with_system_certs Whether system certificates use or not
  * @return #TRUST_ANCHOR_ERROR_NONE on success,
  *         negative on error
@@ -57,8 +57,8 @@ extern "C" {
  * @see trust_anchor_uninstall()
  */
 int trust_anchor_install(const char *package_id,
-                                                const char *pkg_certs_path,
                                                 uid_t uid,
+                                                const char *pkg_certs_path,
                                                 bool with_system_certs);
 
 
@@ -66,7 +66,6 @@ int trust_anchor_install(const char *package_id,
  * @brief Launch trust anchor.
  * @details After lauching trust anchor, package can use custom certificates.
  * @param[in] package_id Package id
- * @param[in] pkg_certs_path Package custom certificates path
  * @param[in] uid user id
  * @return #TRUST_ANCHOR_ERROR_NONE on success,
  *         negative on error
@@ -78,15 +77,12 @@ int trust_anchor_install(const char *package_id,
  * @retval #TRUST_ANCHOR_ERROR_INTERNAL Internal error
  * @see trust_anchor_install()
  */
-int trust_anchor_launch(const char *package_id,
-                                               const char *pkg_certs_path,
-                                               uid_t uid);
+int trust_anchor_launch(const char *package_id, uid_t uid);
 
 
 /**
  * @brief Uninstall trust anchor.
  * @param[in] package_id Package id
- * @param[in] pkg_certs_path Package custom certificates path
  * @param[in] uid user id
  * @return #TRUST_ANCHOR_ERROR_NONE on success,
  *         negative on error
@@ -95,9 +91,7 @@ int trust_anchor_launch(const char *package_id,
  * @retval #TRUST_ANCHOR_ERROR_INTERNAL Internal error
  * @see trust_anchor_install()
  */
-int trust_anchor_uninstall(const char *package_id,
-                                                  const char *pkg_certs_path,
-                                                  uid_t uid);
+int trust_anchor_uninstall(const char *package_id, uid_t uid);
 
 
 #ifdef __cplusplus
index 01dba2e22d2e0cbeb5223d5405aaf1b2f813170c..015a92d0678c5f54e564741b1b949dc369edf2ff 100644 (file)
@@ -38,9 +38,7 @@ namespace tanchor {
 
 class TANCHOR_API TrustAnchor {
 public:
-       explicit TrustAnchor(const std::string &packageId,
-                                                const std::string &certsDir,
-                                                uid_t uid) noexcept;
+       explicit TrustAnchor(const std::string &packageId, uid_t uid) noexcept;
        virtual ~TrustAnchor(void);
 
        TrustAnchor(const TrustAnchor &) = delete;
@@ -48,7 +46,7 @@ public:
        TrustAnchor &operator=(const TrustAnchor &) = delete;
        TrustAnchor &operator=(TrustAnchor &&) = delete;
 
-       int install(bool withSystemCerts) noexcept;
+       int install(const std::string &pkgCertsPath, bool withSystemCerts) noexcept;
        int uninstall(void) noexcept;
        int launch(void) noexcept;
 
index f4b26f1deeebd860f81444bda4de50efffd83121..e2dea7d4dd90ddebc3e1eb68266afbbda1615abf 100644 (file)
@@ -35,7 +35,7 @@ int main()
        bool with_sys = false;
        uid_t uid = -1;
 
-       int ret = trust_anchor_install("pkgid", "/pkg_certs_path", uid, with_sys);
+       int ret = trust_anchor_install("pkgid", uid, "/pkg_certs_path", with_sys);
        if (ret != TRUST_ANCHOR_ERROR_NONE) {
                printf("Failed to install operation");
                return -1;
@@ -44,7 +44,7 @@ int main()
        /*
         * When app uninstalled trust_anchor_uninstall() should be called once.
         */
-       ret = trust_anchor_uninstall("pkgid", "/pkg_certs_path", uid);
+       ret = trust_anchor_uninstall("pkgid", uid);
        if (ret != TRUST_ANCHOR_ERROR_NONE) {
                printf("Failed to uninstall operation");
                return -1;
index b193da8bea4e6bd5179119919cf77bb6f214d43f..51320bfb00c2b28719845903ae066ed9254171a9 100644 (file)
@@ -38,7 +38,7 @@ int main()
         */
        uid_t uid = -1;
 
-       int ret = trust_anchor_launch("pkgid", "/pkg_certs_path", uid);
+       int ret = trust_anchor_launch("pkgid", uid);
        if (ret != TRUST_ANCHOR_ERROR_NONE) {
                printf("Failed to launch operation");
                return -1;
index 931cad3e68f4d2b3e67cda3b9ac04229f849e5f1..3c0c53ff7d29ac910c6fb1e1732cdd3ca59fb0b6 100644 (file)
@@ -16,17 +16,18 @@ BuildRequires: ca-certificates-devel
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 
-%global lib_name        tanchor
-%global user_name       security_fw
-%global group_name      security_fw
-%global smack_label     System
-
-%global tanchor_base    %{TZ_SYS_DATA}/%{lib_name}
-%global tanchor_pkg     %{tanchor_base}/pkg
-%global tanchor_bundle  %{tanchor_base}/ca-bundle.pem
-%global tanchor_sysca   %{tanchor_base}/.sysca
-%global tanchor_test    %{tanchor_base}/test
-%global tanchor_example %{tanchor_base}/example
+%global lib_name         tanchor
+%global user_name        security_fw
+%global group_name       security_fw
+%global smack_label      System
+
+%global tanchor_base     %{TZ_SYS_DATA}/%{lib_name}
+%global tanchor_pkg      %{tanchor_base}/pkg
+%global tanchor_bundle   %{tanchor_base}/ca-bundle.pem
+%global tanchor_sysca    %{tanchor_base}/.sysca
+%global tanchor_pkgcerts %{tanchor_base}/.pkgcerts
+%global tanchor_test     %{tanchor_base}/test
+%global tanchor_example  %{tanchor_base}/example
 
 %description
 The package provides trust-anchor which the application can assign
@@ -40,6 +41,7 @@ SSL root certificates for its HTTPS communication.
 %dir %attr(-, %{user_name}, %{group_name}) %{tanchor_base}
 %dir %attr(-, %{user_name}, %{group_name}) %{tanchor_pkg}
 %attr(-, %{user_name}, %{group_name}) %{tanchor_bundle}
+%attr(-, %{user_name}, %{group_name}) %{tanchor_pkgcerts}
 %attr(444 %{user_name}, %{group_name}) %{tanchor_sysca}
 
 %prep
@@ -63,6 +65,7 @@ SSL root certificates for its HTTPS communication.
                 -DTANCHOR_PKG=%{tanchor_pkg} \
                 -DTANCHOR_BUNDLE=%{tanchor_bundle} \
                 -DTANCHOR_SYSCA=%{tanchor_sysca} \
+                -DTANCHOR_PKG_CERTS=%{tanchor_pkgcerts} \
                 -DTANCHOR_TEST=%{tanchor_test} \
                 -DTANCHOR_EXAMPLE=%{tanchor_example} \
                 -DTZ_SYS_CA_CERTS=%{TZ_SYS_CA_CERTS} \
@@ -79,6 +82,7 @@ mkdir -p %{buildroot}%{tanchor_pkg}
 
 touch %{buildroot}%{tanchor_bundle}
 touch %{buildroot}%{tanchor_sysca}
+touch %{buildroot}%{tanchor_pkgcerts}
 
 %post -p /sbin/ldconfig
 
index a9ecc8d4c0160dbaba8e2b0467a52bec53d16bf1..55313bbbca83ed9163af4d250cd1c5d2d3a3b097 100644 (file)
@@ -28,28 +28,24 @@ using namespace tanchor;
 
 TANCHOR_API
 int trust_anchor_install(const char *package_id,
-                                                const char *pkg_certs_path,
                                                 uid_t uid,
+                                                const char *pkg_certs_path,
                                                 bool with_system_certs)
 {
-       TrustAnchor ta(package_id, pkg_certs_path, uid);
-       return ta.install(with_system_certs);
+       TrustAnchor ta(package_id, uid);
+       return ta.install(pkg_certs_path, with_system_certs);
 }
 
 TANCHOR_API
-int trust_anchor_launch(const char *package_id,
-                                               const char *pkg_certs_path,
-                                               uid_t uid)
+int trust_anchor_launch(const char *package_id, uid_t uid)
 {
-       TrustAnchor ta(package_id, pkg_certs_path, uid);
+       TrustAnchor ta(package_id, uid);
        return ta.launch();
 }
 
 TANCHOR_API
-int trust_anchor_uninstall(const char *package_id,
-                                                  const char *pkg_certs_path,
-                                                  uid_t uid)
+int trust_anchor_uninstall(const char *package_id, uid_t uid)
 {
-       TrustAnchor ta(package_id, pkg_certs_path, uid);
+       TrustAnchor ta(package_id, uid);
        return ta.uninstall();
 }
index d3d5fa78d288846e0326243c3e666d2cdda4df92..103c8643561f0add0f02a41661e2b5c7c6f59ad4 100644 (file)
 #include "certificate.hxx"
 
 #include <cstdio>
+#include <memory>
 #include <vector>
+
+#include "file-system.hxx"
 #include "exception.hxx"
 
 #include <openssl/pem.h>
@@ -42,20 +45,21 @@ const int HASH_LENGTH = 8;
 
 } // namespace anonymous
 
-Certificate::Certificate(const std::string &path) :
-       m_fp(FilePtr(::fopen(path.c_str(), "rb"), ::fclose))
+Certificate::Certificate(const std::string &path) : m_path(path)
 {
-       if (this->m_fp == nullptr)
-               throw std::invalid_argument("Failed to open [" + path + "].");
 }
 
 std::string Certificate::getSubjectNameHash() const
 {
-       X509Ptr x509(::PEM_read_X509(this->m_fp.get(), NULL, NULL, NULL),
+       FilePtr fp = FilePtr(::fopen(this->m_path.c_str(), "rb"), ::fclose);
+       if (fp == nullptr)
+               throw std::invalid_argument("Failed to open [" + this->m_path + "].");
+
+       X509Ptr x509(::PEM_read_X509(fp.get(), NULL, NULL, NULL),
                                 ::X509_free);
        if (x509 == nullptr) {
-               ::rewind(this->m_fp.get());
-               x509 = X509Ptr(::PEM_read_X509_AUX(this->m_fp.get(), NULL, NULL, NULL),
+               ::rewind(fp.get());
+               x509 = X509Ptr(::PEM_read_X509_AUX(fp.get(), NULL, NULL, NULL),
                                           ::X509_free);
        }
 
@@ -71,15 +75,7 @@ std::string Certificate::getSubjectNameHash() const
 
 std::string Certificate::getCertificateData() const
 {
-       std::fseek(this->m_fp.get(), 0L, SEEK_END);
-       unsigned int fsize = std::ftell(this->m_fp.get());
-       std::rewind(this->m_fp.get());
-
-       std::string content(fsize, 0);
-       if (fsize != std::fread(static_cast<void*>(&content[0]), 1, fsize,
-                                                       this->m_fp.get()))
-               throw std::logic_error("Failed to read certificate from fp.");
-
+       std::string content = File::read(this->m_path);
        return this->parseData(content);
 }
 
index 6ecc2aa6b58aa8a9afbe7513e3abb0dee379d2d6..dcc695eb6dcfaebafc6008634de3417cb35258f8 100644 (file)
 #pragma once
 
 #include <string>
-#include <memory>
-#include <cstdio>
 
 namespace tanchor {
 
-using FilePtr = std::unique_ptr<FILE, decltype(&::fclose)>;
-
 class Certificate {
 public:
        explicit Certificate(const std::string &path);
@@ -45,7 +41,7 @@ public:
 private:
        std::string parseData(const std::string &data) const;
 
-       FilePtr m_fp;
+       std::string m_path;
 };
 
 } // namespace tanchor
index 60558bb81da5ad56253a0194dccbbcd54a660d16..0aedbb4d7ab3fcd98619c608eb39b534a6612208 100644 (file)
@@ -30,6 +30,7 @@ const std::string SYS_BUNDLE_PATH(TZ_SYS_CA_BUNDLE);
 
 const std::string TANCHOR_SYSCA_PATH = TANCHOR_SYSCA;
 const std::string TANCHOR_BUNDLE_PATH = TANCHOR_BUNDLE;
+const std::string TANCHOR_PKG_CERTS_PATH = TANCHOR_PKG_CERTS;
 
 const std::string MOUNT_POINT_CERTS(TZ_SYS_CA_CERTS);
 const std::string MOUNT_POINT_BUNDLE(TZ_SYS_CA_BUNDLE);
index 190b2f900864aec7415220dda00ec52a843ec167..ec1ab6d015d39ae8450543307a91d2a18cc324f9 100644 (file)
@@ -24,6 +24,7 @@
 #include <climits>
 #include <cerrno>
 #include <unistd.h>
+#include <cstdio>
 
 #include <vector>
 
@@ -37,6 +38,22 @@ void File::linkTo(const std::string &src, const std::string &dst)
                ThrowErrno(errno, "Failed to link " + src + " -> " + dst);
 }
 
+std::string File::read(const std::string &path)
+{
+       FilePtr fp = FilePtr(::fopen(path.c_str(), "rb"), ::fclose);
+       if (fp == nullptr)
+               throw std::invalid_argument("Failed to open [" + path + "].");
+
+       std::fseek(fp.get(), 0L, SEEK_END);
+       unsigned int fsize = std::ftell(fp.get());
+       std::rewind(fp.get());
+
+       std::string buff(fsize, 0);
+       if (fsize != std::fread(static_cast<void*>(&buff[0]), 1, fsize, fp.get()))
+               throw std::logic_error("Failed to read [" + path + "]");
+       return buff;
+}
+
 std::string File::readLink(const std::string &path)
 {
        std::vector<char> buf(PATH_MAX);
index 4bd3c94f78ac1ed936f004563c0af34c7785ba31..ce1df387bc397ff5fb3324bdd44f2694b66e92f2 100644 (file)
 #pragma once
 
 #include <string>
+#include <memory>
 
 namespace tanchor {
 
+using FilePtr = std::unique_ptr<FILE, decltype(&::fclose)>;
+
 class File {
 public:
        static void linkTo(const std::string &src, const std::string &dst);
        static std::string readLink(const std::string &path);
        static std::string getName(const std::string &path);
+       static std::string read(const std::string &path);
 };
 
 } // namespace tanchor
index bc3779d74a09470f4abb8d28005ca41448c17d27..c6889115129299551f4ffc3ab58099bc9dfdf1e9 100644 (file)
@@ -39,8 +39,7 @@
 
 namespace tanchor {
 
-Logic::Logic(const std::string &pkgCertsPath, const std::string &basePath) :
-       m_pkgCertsPath(pkgCertsPath),
+Logic::Logic(const std::string &basePath) :
        m_customBasePath(basePath),
        m_customCertsPath(m_customBasePath + "/certs"),
        m_customBundlePath(m_customBasePath + "/bundle"),
@@ -91,7 +90,7 @@ void Logic::makeCustomCerts(void)
        }
 
        // link pkg certificates to the custom directory as subjectNameHash
-       runtime::DirectoryIterator iter(this->m_pkgCertsPath), end;
+       runtime::DirectoryIterator iter(this->getPkgCertsPath()), end;
        while (iter != end) {
                Certificate cert(iter->getPath());
                std::string uName = this->getUniqueCertName(cert.getSubjectNameHash());
@@ -124,7 +123,7 @@ void Logic::makeCustomBundle(void)
 
        if (this->m_customCertsData.empty()) {
                DEBUG("System certificates is changed after TrustAnchor installation.");
-               runtime::DirectoryIterator iter(this->m_pkgCertsPath), end;
+               runtime::DirectoryIterator iter(this->getPkgCertsPath()), end;
                while (iter != end) {
                        Certificate cert(iter->getPath());
                        this->m_customCertsData.emplace_back(cert.getCertificateData());
@@ -143,9 +142,9 @@ void Logic::makeCustomBundle(void)
        INFO("Success to make pkg custom bundle.");
 }
 
-bool Logic::isPkgCertsValid(void) const
+bool Logic::isPkgCertsValid(const std::string &path) const
 {
-       runtime::File file(this->m_pkgCertsPath);
+       runtime::File file(path);
 
        if (!file.exists())
                ThrowExc(TRUST_ANCHOR_ERROR_NO_SUCH_FILE,
@@ -158,6 +157,33 @@ bool Logic::isPkgCertsValid(void) const
        return file.isDirectory();
 }
 
+void Logic::setPkgCertsPath(const std::string &path) const
+{
+       if (!this->isPkgCertsValid(path))
+               throw std::invalid_argument("Pkg certs dir should be directory.");
+
+
+       runtime::File tanchorPkgCerts(path::TANCHOR_PKG_CERTS_PATH);
+       tanchorPkgCerts.copyTo(this->m_customBasePath);
+
+       runtime::File pkgCertsPath(this->m_customBasePath + "/" +
+                                                          File::getName(path::TANCHOR_PKG_CERTS_PATH));
+       pkgCertsPath.open(O_RDWR | O_APPEND);
+       pkgCertsPath.lock();
+       pkgCertsPath.write(path.c_str(), path.length());
+       pkgCertsPath.unlock();
+
+       DEBUG("Success to set package certificates path : " << path);
+}
+
+std::string Logic::getPkgCertsPath(void) const
+{
+       std::string path = File::read(this->m_customBasePath + "/" +
+                                                                 File::getName(path::TANCHOR_PKG_CERTS_PATH));
+       DEBUG("Package certificates path : " << path);
+       return path;
+}
+
 void Logic::setSystemCertsUsed(void) const
 {
        runtime::File tanchorSysCA(path::TANCHOR_SYSCA_PATH);
index a543363eeb81f6d4643690c1dd85e4c33504cfb7..f55ef588e15bdf4912246ed543cc820d8c8ce1a9 100644 (file)
@@ -29,7 +29,7 @@ namespace tanchor {
 
 class Logic {
 public:
-       explicit Logic(const std::string &pkgCertsPath, const std::string &basePath);
+       explicit Logic(const std::string &basePath);
        virtual ~Logic(void) = default;
 
        Logic(const Logic &) = delete;
@@ -43,7 +43,8 @@ public:
        void makeCustomCerts(void);
        void makeCustomBundle(void);
 
-       bool isPkgCertsValid(void) const;
+       void setPkgCertsPath(const std::string &path) const;
+       std::string getPkgCertsPath(void) const;
 
        bool isSystemCertsUsed(void) const;
        bool isSystemCertsModified(void) const;
@@ -55,8 +56,8 @@ public:
 
 private:
        std::string getUniqueCertName(const std::string &name) const;
+       bool isPkgCertsValid(const std::string &path) const;
 
-       std::string m_pkgCertsPath;
        std::string m_customBasePath;
        std::string m_customCertsPath;
        std::string m_customBundlePath;
index e08ae573079b4260c78e61d9805572f0b2224059..4c1a1542a58749218e202fe2fb2582d80225a1be 100644 (file)
@@ -31,12 +31,10 @@ namespace tanchor {
 
 class TrustAnchor::Impl {
 public:
-       explicit Impl(const std::string &packageId,
-                                 const std::string &certsDir,
-                                 uid_t uid) noexcept;
+       explicit Impl(const std::string &packageId, uid_t uid) noexcept;
        virtual ~Impl(void) = default;
 
-       int install(bool withSystemCerts) noexcept;
+       int install(const std::string &pkgCertsPath, bool withSystemCerts) noexcept;
        int uninstall(void) const noexcept;
        int launch(void) noexcept;
        int rollback(void) const noexcept;
@@ -48,11 +46,8 @@ private:
        Logic m_logic;
 };
 
-TrustAnchor::Impl::Impl(const std::string &packageId,
-                                               const std::string &certsDir,
-                                               uid_t uid) noexcept :
-       m_logic(certsDir,
-                       path::BASE_PKG_PATH + "/" +
+TrustAnchor::Impl::Impl(const std::string &packageId, uid_t uid) noexcept :
+       m_logic(path::BASE_PKG_PATH + "/" +
                        std::to_string(static_cast<int>(uid)) + "/" +
                        packageId)
 {
@@ -62,18 +57,17 @@ TrustAnchor::Impl::Impl(const std::string &packageId,
 void TrustAnchor::Impl::preInstall(void)
 {
        this->m_logic.init();
-
-       if (!this->m_logic.isPkgCertsValid())
-               throw std::invalid_argument("Pkg certs dir should be directory.");
        DEBUG("Success to pre-install stage.");
 }
 
-int TrustAnchor::Impl::install(bool withSystemCerts) noexcept
+int TrustAnchor::Impl::install(const std::string &pkgCertsPath,
+                                                          bool withSystemCerts) noexcept
 {
        EXCEPTION_GUARD_START
 
        this->preInstall();
 
+       this->m_logic.setPkgCertsPath(pkgCertsPath);
        if (withSystemCerts)
                this->m_logic.setSystemCertsUsed();
 
@@ -118,7 +112,7 @@ void TrustAnchor::Impl::preLaunch(void)
        DEBUG("This package use system certificates.");
        if (this->m_logic.isSystemCertsModified()) {
                WARN("System certificates be changed. Do re-install for refresh.");
-               this->install(true);
+               this->install(this->m_logic.getPkgCertsPath(), true);
        }
        DEBUG("Success to pre-launch stage.");
 }
@@ -139,19 +133,18 @@ int TrustAnchor::Impl::launch() noexcept
        EXCEPTION_GUARD_END
 }
 
-TrustAnchor::TrustAnchor(const std::string &packageId,
-                                                const std::string &certsDir,
-                                                uid_t uid) noexcept :
-       m_pImpl(new Impl(packageId, certsDir, uid)) {}
+TrustAnchor::TrustAnchor(const std::string &packageId, uid_t uid) noexcept :
+       m_pImpl(new Impl(packageId, uid)) {}
 
 TrustAnchor::~TrustAnchor(void) = default;
 
-int TrustAnchor::install(bool withSystemCerts) noexcept
+int TrustAnchor::install(const std::string &pkgCertsPath,
+                                                bool withSystemCerts) noexcept
 {
        if (this->m_pImpl == nullptr)
                return TRUST_ANCHOR_ERROR_OUT_OF_MEMORY;
 
-       int ret = this->m_pImpl->install(withSystemCerts);
+       int ret = this->m_pImpl->install(pkgCertsPath, withSystemCerts);
 
        if (ret != TRUST_ANCHOR_ERROR_NONE) {
                ERROR("Failed to intall ACTA. Remove custom directory for rollback.");
index 289ef721972ffb621d2cfa5828ddc0e0ca137f8e..c1db1df6996dad074bf05e9883ffcfae4d5af6fa 100644 (file)
@@ -57,6 +57,8 @@ SET(CAPI_LAUNCHER_SRCS main.cpp
 SET(INTERNAL_SRCS main.cpp
                                  test-util.cpp
                                  test-certificate.cpp
+                                 ${TANCHOR_SRC}/exception.cpp
+                                 ${TANCHOR_SRC}/file-system.cpp
                                  ${TANCHOR_SRC}/certificate.cpp)
 SET(SSL_SRCS main.cpp
                         test-curl.cpp
index 546cc6bf6ea929cef16d7ed3153aeba4c423b2c7..a29f504a1554d04855d9d3dcfe41540d61128aee 100644 (file)
 
 TESTCASE(CAPI_TRUST_ANCHOR_INSTALL_POSITIVE)
 {
-       int ret = trust_anchor_install(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID, false);
+       int ret = trust_anchor_install(DUMMY_PKG_ID, DUMMY_UID, PKG_CERTS_DIR, false);
        TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 }
 
 TESTCASE(CAPI_TRUST_ANCHOR_INSTALL_WITH_SYS_POSITIVE)
 {
-       int ret = trust_anchor_install(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID, true);
+       int ret = trust_anchor_install(DUMMY_PKG_ID, DUMMY_UID, PKG_CERTS_DIR, true);
        TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 }
 
 TESTCASE(CAPI_TRUST_ANCHOR_INSTALL_NEGATIVE)
 {
-       int ret = trust_anchor_install(DUMMY_PKG_ID, DUMMY_CERTS_DIR, DUMMY_UID, false);
+       int ret = trust_anchor_install(DUMMY_PKG_ID, DUMMY_UID, DUMMY_CERTS_DIR, false);
        TEST_EXPECT(false, ret == TRUST_ANCHOR_ERROR_NONE);
 }
 
 TESTCASE(CAPI_TRUST_ANCHOR_INSTALL_WITH_SYS_NEGATIVE)
 {
-       int ret = trust_anchor_install(DUMMY_PKG_ID, DUMMY_CERTS_DIR, DUMMY_UID, true);
+       int ret = trust_anchor_install(DUMMY_PKG_ID, DUMMY_UID, DUMMY_CERTS_DIR, true);
        TEST_EXPECT(false, ret == TRUST_ANCHOR_ERROR_NONE);
 }
 
 TESTCASE(CAPI_TRUST_ANCHOR_UNINSTALL_POSITIVE)
 {
-       int ret = trust_anchor_install(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID, false);
+       int ret = trust_anchor_install(DUMMY_PKG_ID, DUMMY_UID, PKG_CERTS_DIR, false);
        TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 
-       ret = trust_anchor_uninstall(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID);
+       ret = trust_anchor_uninstall(DUMMY_PKG_ID, DUMMY_UID);
        TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 }
 
 TESTCASE(CAPI_TRUST_ANCHOR_UNINSTALL_NEGATIVE)
 {
-       int ret = trust_anchor_uninstall(DUMMY_PKG_ID, DUMMY_CERTS_DIR, DUMMY_UID);
+       int ret = trust_anchor_uninstall(DUMMY_PKG_ID, DUMMY_UID);
        TEST_EXPECT(false, ret == TRUST_ANCHOR_ERROR_NONE);
 }
index 2953953039979d08ff204d46bdc78ed97071f111..53b87f5ffb86e1160c873955df4f6866e83c8e7a 100644 (file)
@@ -35,13 +35,13 @@ TESTCASE(CAPI_TRUST_ANCHOR_LAUNCH)
        auto beforeLs = test::util::ls(TZ_SYS_RO_CA_CERTS);
        auto beforeCat = test::util::cat(TZ_SYS_RO_CA_BUNDLE);
 
-       int ret = trust_anchor_install(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID, true);
+       int ret = trust_anchor_install(DUMMY_PKG_ID, DUMMY_UID, PKG_CERTS_DIR, true);
 
        // pre-condition
        int pid = fork();
 
        if (pid == 0) {
-               ret = trust_anchor_launch(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID);
+               ret = trust_anchor_launch(DUMMY_PKG_ID, DUMMY_UID);
                TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 
                auto afterLsChild = test::util::ls(TZ_SYS_RO_CA_CERTS);
index a3764fd2835ef8155c78f21c648660be2c0a63d6..338b9b5bc20dcb5dd4ac98c6e12412a7b7ad144b 100644 (file)
@@ -42,8 +42,8 @@ TESTCASE(CONNECT_SSL)
 
 TESTCASE(TRUST_ANCHOR_LAUNCH)
 {
-       tanchor::TrustAnchor ta(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID);
-       int ret = ta.install(false);
+       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_UID);
+       int ret = ta.install(PKG_CERTS_DIR, false);
        TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 
        std::cout << "##########################################" << std::endl;
@@ -79,8 +79,8 @@ TESTCASE(TRUST_ANCHOR_LAUNCH)
 
 TESTCASE(TRUST_ANCHOR_LAUNCH_WITH_SYS)
 {
-       tanchor::TrustAnchor ta(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID);
-       int ret = ta.install(true);
+       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_UID);
+       int ret = ta.install(PKG_CERTS_DIR, true);
        TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 
        std::cout << "##########################################" << std::endl;
index b75d632cc2f1bbc5c292e2e710de5fa5fb0c41a1..12c564beda0211077ead8c826f649503b5b2c6df 100644 (file)
 
 TESTCASE(TRUST_ANCHOR_INSTALL_POSITIVE)
 {
-       tanchor::TrustAnchor ta(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID);
-       int ret = ta.install(false);
+       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_UID);
+       int ret = ta.install(PKG_CERTS_DIR, false);
        TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 }
 
 TESTCASE(TRUST_ANCHOR_INSTALL_WITH_SYS_POSITIVE)
 {
-       tanchor::TrustAnchor ta(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID);
-       int ret = ta.install(true);
+       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_UID);
+       int ret = ta.install(PKG_CERTS_DIR, true);
        TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 }
 
 TESTCASE(TRUST_ANCHOR_INSTALL_NEGATIVE)
 {
-       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_CERTS_DIR, DUMMY_UID);
-       int ret = ta.install(false);
+       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_UID);
+       int ret = ta.install(DUMMY_CERTS_DIR, false);
        TEST_EXPECT(false, ret == TRUST_ANCHOR_ERROR_NONE);
 }
 
 TESTCASE(TRUST_ANCHOR_INSTALL_WITH_SYS_NEGATIVE)
 {
-       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_CERTS_DIR, DUMMY_UID);
-       int ret = ta.install(true);
+       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_UID);
+       int ret = ta.install(DUMMY_CERTS_DIR, true);
        TEST_EXPECT(false, ret == TRUST_ANCHOR_ERROR_NONE);
 }
 
 TESTCASE(TRUST_ANCHOR_UNINSTALL_POSITIVE)
 {
-       tanchor::TrustAnchor ta(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID);
-       int ret = ta.install(false);
+       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_UID);
+       int ret = ta.install(PKG_CERTS_DIR, false);
        TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 
        ret = ta.uninstall();
@@ -72,7 +72,7 @@ TESTCASE(TRUST_ANCHOR_UNINSTALL_POSITIVE)
 
 TESTCASE(TRUST_ANCHOR_UNINSTALL_NEGATIVE)
 {
-       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_CERTS_DIR, DUMMY_UID);
+       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_UID);
        int ret = ta.uninstall();
        TEST_EXPECT(false, ret == TRUST_ANCHOR_ERROR_NONE);
 }
index 96e1aa86b1b525c67eca9916a0736dff405b07ca..1034c0fd9dfc6acaacf38c319ddfa2bd9fcf194f 100644 (file)
@@ -37,8 +37,8 @@ TESTCASE(TRUST_ANCHOR_LAUNCH)
        auto beforeLs = test::util::ls(TZ_SYS_RO_CA_CERTS);
        auto beforeCat = test::util::cat(TZ_SYS_RO_CA_BUNDLE);
 
-       tanchor::TrustAnchor ta(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID);
-       int ret = ta.install(false);
+       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_UID);
+       int ret = ta.install(PKG_CERTS_DIR, false);
        TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 
        // pre-condition
@@ -73,8 +73,8 @@ TESTCASE(TRUST_ANCHOR_LAUNCH_WITH_SYS)
        auto beforeLs = test::util::ls(TZ_SYS_RO_CA_CERTS);
        auto beforeCat = test::util::cat(TZ_SYS_RO_CA_BUNDLE);
 
-       tanchor::TrustAnchor ta(DUMMY_PKG_ID, PKG_CERTS_DIR, DUMMY_UID);
-       int ret = ta.install(true);
+       tanchor::TrustAnchor ta(DUMMY_PKG_ID, DUMMY_UID);
+       int ret = ta.install(PKG_CERTS_DIR, true);
        TEST_EXPECT(true, ret == TRUST_ANCHOR_ERROR_NONE);
 
        // pre-condition