#include <klay/exception.h>
+#include "logger.hxx"
+
namespace tanchor {
int exceptionGuard(const std::function<int()> &func)
errStr = "Internal error.";
break;
}
- ERROR(errStr + e.what());
+ ERROR(SINK, errStr + e.what());
return e.error();
} catch (const runtime::Exception &e) {
- ERROR(e.what());
+ ERROR(SINK, e.what());
return TRUST_ANCHOR_ERROR_INTERNAL;
} catch (const std::invalid_argument &e) {
- ERROR(e.what());
+ ERROR(SINK, e.what());
return TRUST_ANCHOR_ERROR_INVALID_PARAMETER;
} catch (const std::logic_error &e) {
- ERROR(e.what());
+ ERROR(SINK, e.what());
return TRUST_ANCHOR_ERROR_INTERNAL;
} catch (const std::exception &e) {
- ERROR(e.what());
+ ERROR(SINK, e.what());
return TRUST_ANCHOR_ERROR_INTERNAL;
} catch (...) {
- ERROR("Unknown exception occurred.");
+ ERROR(SINK, "Unknown exception occurred.");
return TRUST_ANCHOR_ERROR_INTERNAL;
}
}
m_message(FORMAT("[" << file << ":" << line << " " <<
function << "()]" << message))
{
- ERROR(this->m_message);
+ ERROR(SINK, this->m_message);
}
const char *Exception::what() const noexcept
#include <string>
#include <exception>
-#include <klay/audit/logger.h>
+#include "logger.hxx"
#define EXCEPTION_GUARD_START return tanchor::exceptionGuard([&]() {
#define EXCEPTION_GUARD_END });
* @version 1.0
* @brief Init global configuration for library
*/
-
-#include <klay/audit/logger.h>
#include <klay/audit/dlog-sink.h>
#include <memory>
+#include "logger.hxx"
+
namespace tanchor {
namespace {
public:
InitLib()
{
- audit::Logger::setBackend(new audit::DlogLogSink());
- audit::Logger::setTag("TRUST_ANCHOR");
+ this->m_sink.reset(new audit::DlogLogSink("TRUST_ANCHOR"));
};
~InitLib() = default;
+
+ std::unique_ptr<audit::DlogLogSink> m_sink = nullptr;
};
static std::unique_ptr<InitLib> init(new(std::nothrow)(InitLib));
} // namespace anonymous
+
+audit::LogSink *SINK = dynamic_cast<audit::LogSink*>((init->m_sink).get());
+
} // namespace tanchor
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/*
+ * @file logic.hxx
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+#pragma once
+
+#include <klay/audit/logger.h>
+
+namespace tanchor {
+
+extern audit::LogSink *SINK;
+
+} // namespace tanchor
#include <sys/stat.h>
#include <klay/filesystem.h>
-#include <klay/audit/logger.h>
+#include "logger.hxx"
#include "certificate.hxx"
#include "file-system.hxx"
#include "exception.hxx"
{
runtime::File customBaseDir(this->m_customBasePath);
if (customBaseDir.exists()) {
- WARN("Pkg custom directory is already exist. remove it!");
+ WARN(SINK, "Pkg custom directory is already exist. remove it!");
customBaseDir.remove(true);
}
customBaseDir.makeDirectory(true);
runtime::File customBundleDir(this->m_customBundlePath);
customBundleDir.makeDirectory();
- DEBUG("Success to init[" << this->m_customBasePath << "]");
+ DEBUG(SINK, "Success to init[" << this->m_customBasePath << "]");
}
void Logic::deinit(bool isRollback) const
else if (!isRollback)
throw std::invalid_argument("tanchor is never installed before.");
- DEBUG("Success to deinit[" << this->m_customBasePath << "]");
+ DEBUG(SINK, "Success to deinit[" << this->m_customBasePath << "]");
}
void Logic::makeCustomCerts(void)
this->m_customCertNameSet.emplace(File::getName(iter->getPath()));
++iter;
}
- DEBUG("Success to migrate system certificates.");
+ DEBUG(SINK, "Success to migrate system certificates.");
}
// link pkg certificates to the custom directory as subjectNameHash
this->m_customCertsData.emplace_back(cert.getCertificateData());
++iter;
}
+
+ INFO(SINK, "Success to make pkg custom certs.");
}
void Logic::makeCustomBundle(void)
runtime::File customBundle(this->m_customBundlePath + "/" +
File::getName(path::SYS_BUNDLE_PATH));
if (customBundle.exists()) {
- WARN("Pkg custom bundle is already exist. remove it!");
+ WARN(SINK, "Pkg custom bundle is already exist. remove it!");
customBundle.remove();
}
- DEBUG("Start to migrate previous bundle.");
+ DEBUG(SINK, "Start to migrate previous bundle.");
if (this->isSystemCertsUsed()) {
runtime::File sysBundle(path::SYS_BUNDLE_PATH);
sysBundle.copyTo(this->m_customBundlePath);
runtime::File tanchorBundle(path::TANCHOR_BUNDLE_PATH);
tanchorBundle.copyTo(this->m_customBundlePath);
}
- DEBUG("Finish migrating previous bundle.");
+ DEBUG(SINK, "Finish migrating previous bundle.");
if (this->m_customCertsData.empty()) {
- DEBUG("System certificates is changed after TrustAnchor installation.");
+ DEBUG(SINK, "System certificates is changed after TrustAnchor installation.");
runtime::DirectoryIterator iter(this->getPkgCertsPath()), end;
while (iter != end) {
Certificate cert(iter->getPath());
}
}
- DEBUG("Start to add pkg's certificate to bundle.");
+ DEBUG(SINK, "Start to add pkg's certificate to bundle.");
customBundle.open(O_RDWR | O_APPEND);
for (const auto &cert : this->m_customCertsData) {
customBundle.write(cert.c_str(), cert.length());
customBundle.write(newLine.c_str(), newLine.length());
}
- INFO("Success to make pkg custom bundle.");
+ INFO(SINK, "Success to make pkg custom bundle.");
}
bool Logic::isPkgCertsValid(const std::string &path) const
pkgCertsPath.write(path.c_str(), path.length());
pkgCertsPath.unlock();
- DEBUG("Success to set package certificates path : " << path);
+ DEBUG(SINK, "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);
+ DEBUG(SINK, "Package certificates path : " << path);
return path;
}
{
runtime::File tanchorSysCA(path::TANCHOR_SYSCA_PATH);
tanchorSysCA.copyTo(this->m_customBasePath);
- DEBUG("Success to set SYSCA flag.");
+ DEBUG(SINK, "Success to set SYSCA flag.");
}
bool Logic::isSystemCertsUsed(void) const
runtime::File customSysCA(this->m_customBasePath + "/" +
File::getName(path::TANCHOR_SYSCA_PATH));
- DEBUG("Wheter system certificates use or not : " << customSysCA.exists());
+ DEBUG(SINK, "Wheter system certificates use or not : " << customSysCA.exists());
return customSysCA.exists();
}
if (::stat(customBundle.c_str(), &customAttr))
ThrowErrno(errno, customBundle);
- DEBUG("System bundle mtime : " << ::ctime(&systemAttr.st_mtime) << ", " <<
+ DEBUG(SINK, "System bundle mtime : " << ::ctime(&systemAttr.st_mtime) << ", " <<
"Custom bundle mtime : " << ::ctime(&customAttr.st_mtime));
return systemAttr.st_mtime > customAttr.st_mtime;
if (::mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL))
ThrowErrno(errno, "Failed to mount.");
- DEBUG("Success to disassociate namespace.");
+ DEBUG(SINK, "Success to disassociate namespace.");
}
void Logic::mountCustomCerts(void) const
*/
#include "tanchor/trust-anchor.hxx"
-#include <klay/audit/logger.h>
-
#include "logic.hxx"
+#include "logger.hxx"
#include "exception.hxx"
#include "environment.hxx"
std::to_string(static_cast<int>(uid)) + "/" +
packageId)
{
- INFO("Start tanchor about uid[" << uid << "], pkg[" << packageId << "]");
+ INFO(SINK, "Start tanchor about uid[" << uid <<
+ "], pkg[" << packageId << "]");
}
void TrustAnchor::Impl::preInstall(void)
{
this->m_logic.init();
- DEBUG("Success to pre-install stage.");
+ DEBUG(SINK, "Success to pre-install stage.");
}
int TrustAnchor::Impl::install(const std::string &pkgCertsPath,
this->m_logic.makeCustomCerts();
this->m_logic.makeCustomBundle();
- INFO("Success to install.");
+ INFO(SINK, "Success to install.");
return TRUST_ANCHOR_ERROR_NONE;
EXCEPTION_GUARD_END
this->m_logic.deinit(true);
- INFO("Success to rollback.");
+ INFO(SINK, "Success to rollback.");
return TRUST_ANCHOR_ERROR_NONE;
EXCEPTION_GUARD_END
this->m_logic.deinit(false);
- INFO("Success to uninstall.");
+ INFO(SINK, "Success to uninstall.");
return TRUST_ANCHOR_ERROR_NONE;
EXCEPTION_GUARD_END
if (!this->m_logic.isSystemCertsUsed())
return;
- DEBUG("This package use system certificates.");
+ DEBUG(SINK, "This package use system certificates.");
if (this->m_logic.isSystemCertsModified()) {
- WARN("System certificates be changed. Do re-install for refresh.");
+ WARN(SINK, "System certificates be changed. Do re-install for refresh.");
this->install(this->m_logic.getPkgCertsPath(), true);
}
- DEBUG("Success to pre-launch stage.");
+ DEBUG(SINK, "Success to pre-launch stage.");
}
int TrustAnchor::Impl::launch() noexcept
this->m_logic.mountCustomCerts();
this->m_logic.mountCustomBundle();
- INFO("Success to launch.");
+ INFO(SINK, "Success to launch.");
return TRUST_ANCHOR_ERROR_NONE;
EXCEPTION_GUARD_END
int ret = this->m_pImpl->install(pkgCertsPath, withSystemCerts);
if (ret != TRUST_ANCHOR_ERROR_NONE) {
- ERROR("Failed to intall ACTA. Remove custom directory for rollback.");
+ ERROR(SINK, "Failed to intall ACTA. Remove custom directory for rollback.");
if (this->m_pImpl->rollback() != TRUST_ANCHOR_ERROR_NONE)
- ERROR("Failed to rollback ACTA.");
+ ERROR(SINK, "Failed to rollback ACTA.");
}
return ret;
test-util.cpp
test-certificate.cpp
${TANCHOR_SRC}/exception.cpp
+ ${TANCHOR_SRC}/init-lib.cpp
${TANCHOR_SRC}/file-system.cpp
${TANCHOR_SRC}/certificate.cpp)
SET(SSL_SRCS main.cpp
* @brief Implemetation of testbench driver
*/
-#include <klay/audit/logger.h>
-
#include <klay/testbench.h>
#include <curl/curl.h>
int main(int /*argc*/, char** /*argv*/)
{
- audit::Logger::setLogLevel(audit::LogLevel::Trace);
-
curl_global_init(CURL_GLOBAL_DEFAULT);
testbench::Testbench::runAllTestSuites();