ADD_SUBDIRECTORY(lib)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tests)
+ADD_SUBDIRECTORY(examples)
#include <stddef.h>
+#include <stdbool.h>
#include <sys/types.h>
--- /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 CMakeLists.txt
+# @author Sangwan kwon (sangwan.kwon@samsung.com)
+#
+
+INCLUDE_DIRECTORIES(SYSTEM ${TANCHOR_INCLUDE})
+
+FUNCTION(BUILD_EXAMPLE EXAMPLE_NAME EXAMPLE_SRCS)
+ # just for build test
+ ADD_EXECUTABLE(${EXAMPLE_NAME} ${EXAMPLE_SRCS})
+ TARGET_LINK_LIBRARIES(${EXAMPLE_NAME} ${TARGET_TANCHOR_LIB})
+ INSTALL(FILES ${EXAMPLE_SRCS}
+ DESTINATION ${TANCHOR_EXAMPLE})
+ENDFUNCTION(BUILD_EXAMPLE)
+
+BUILD_EXAMPLE("tanchor-example-installer" installer.c)
+BUILD_EXAMPLE("tanchor-example-launcher" launcher.c)
--- /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 installer.c
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @version 0.1
+ * @brief Installer API example
+ */
+
+#include <tanchor/trust-anchor.h>
+#include <tanchor/error.h>
+
+#include <stdio.h>
+
+int main()
+{
+ /*
+ * When app installed trust_anchor_global_install() should be called once.
+ * If app is user-app, call trust_anchor_usr_install() with uid.
+ *
+ * [pre-condition]
+ * 1. Get with_sys_certs information from App configuration.
+ */
+ bool with_sys = false;
+
+ int ret = trust_anchor_global_install("pkgid", "/app_certs_path", with_sys);
+ if (ret != TRUST_ANCHOR_ERROR_NONE) {
+ printf("Failed to install operation");
+ return -1;
+ }
+
+ /*
+ * When app uninstalled trust_anchor_global_uninstall() should be called once.
+ * If app is user-app, call trust_anchor_usr_uninstall() with uid.
+ */
+ ret = trust_anchor_global_uninstall("pkgid", "/app_certs_path");
+ if (ret != TRUST_ANCHOR_ERROR_NONE) {
+ printf("Failed to uninstall operation");
+ return -1;
+ }
+
+ return 0;
+}
--- /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 launcher.c
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @version 0.1
+ * @brief Launcher API example
+ */
+
+#include <tanchor/trust-anchor.h>
+#include <tanchor/error.h>
+
+#include <stdio.h>
+
+int main()
+{
+ /*
+ * When app launched trust_anchor_global_launch() should be called once.
+ * If app is user-app, call trust_anchor_usr_launch() with uid.
+ *
+ * [caution]
+ * Since trust anchor launch operation disassocaite namespace,
+ * other mount tasks should be done before trust_anchor_usr_launch() called.
+ *
+ * [pre-condition]
+ * 1. Launcher should have CAP_SYS_ADMIN.
+ * 2. Get with_sys_certs information.(It should be saved when app installed.)
+ */
+ bool with_sys = false;
+
+ int ret = trust_anchor_global_launch("pkgid", "/app_certs_path", with_sys);
+ if (ret != TRUST_ANCHOR_ERROR_NONE) {
+ printf("Failed to launch operation");
+ return -1;
+ }
+
+ return 0;
+}
%global tanchor_global %{tanchor_base}/global
%global tanchor_bundle %{tanchor_base}/ca-bundle.pem
%global tanchor_test %{tanchor_base}/test
+%global tanchor_example %{tanchor_base}/example
%description
The package provides trust-anchor which the application can assign
-DTANCHOR_GLOBAL=%{tanchor_global} \
-DTANCHOR_BUNDLE=%{tanchor_bundle} \
-DTANCHOR_TEST=%{tanchor_test} \
+ -DTANCHOR_EXAMPLE=%{tanchor_example} \
-DTZ_SYS_CA_CERTS=%{TZ_SYS_CA_CERTS} \
-DTZ_SYS_CA_BUNDLE=%{TZ_SYS_CA_BUNDLE} \
-DTZ_SYS_RO_CA_CERTS=%{TZ_SYS_RO_CA_CERTS} \
## Test Package ##############################################################
%package -n trust-anchor-test
Summary: Trust Anchor API test
-Group: Development/Libraries
+Group: Security/Development
BuildRequires: pkgconfig(libcurl)
%description -n trust-anchor-test
%{_bindir}/%{lib_name}-test-clauncher
%{_bindir}/%{lib_name}-test-internal
%{_bindir}/%{lib_name}-test-init.sh
-%{TZ_SYS_DATA}/%{lib_name}/test
-%{TZ_SYS_DATA}/%{lib_name}/test/certs
+%{tanchor_test}
+%{tanchor_test}/certs
+
+## Example Package ############################################################
+%package -n trust-anchor-example
+Summary: Trust Anchor API example
+Group: Security/Other
+
+%description -n trust-anchor-example
+Examples for trust anchor library
+
+%files -n trust-anchor-example
+%{tanchor_example}/installer.c
+%{tanchor_example}/launcher.c