Support C API only, hide C++ symbols 53/234653/9
authorDariusz Michaluk <d.michaluk@samsung.com>
Wed, 27 May 2020 21:00:32 +0000 (23:00 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 6 Jul 2020 09:59:38 +0000 (11:59 +0200)
Change-Id: I9977834917c6d28b99fa34fc22150f1b221b4f5e

CMakeLists.txt
README.md
dcm-client/CMakeLists.txt
dcm-client/dcm_client.h
dcm-client/dcm_client_p.h
dcm-client/device_certificate_manager.cpp
dcm-client/version_script.lds
packaging/device-certificate-manager.spec
pkgconfig/device-certificate-manager.pc.in
tests/CMakeLists.txt
tests/example_client.cpp [deleted file]

index d58a65806fc860d71630098bf09422b88daa24f8..3ea539c54f1dfa6d01a6f68f1026aff845ce6baa 100644 (file)
@@ -35,7 +35,6 @@ ENDIF()
 INCLUDE(GNUInstallDirs)
 INCLUDE(FindPkgConfig)
 INCLUDE(CheckLibraryExists)
-INCLUDE(GenerateExportHeader)
 
 IF(NOT CMAKE_BUILD_TYPE)
        SET(CMAKE_BUILD_TYPE "RELEASE")
index a0fc71acd5e21d89758cf5f05ed790373237569f..6c5f2aa862defe60a5978fc43d02e02790bf964f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -40,10 +40,9 @@ The DCM daemon does not need to be modified.
 
 ##Testing
 
-There are currently three general testing applications and one KONAI SE specific tool:
+There are currently two general testing applications and one KONAI SE specific tool:
 - *dcm_api_test*
 - *dcm_example_capi*
-- *dcm_example_client*
 All testing applications should be executed after implementing changes to the DCM or to the DCM backend repository.
 
 There is also one KONAI SE specific tool: *dcm_konaise_tool* used to test the KONAI SE backend implementation.
index 0a81a6a97f8bb6bd58f0beb1f573076757f97d3d..4ce16ac4a9a9ab5860b09e5c2eeae548715288c1 100644 (file)
@@ -42,11 +42,6 @@ ADD_LIBRARY(${TARGET_CLIENT}
        ${PROTO_SRCS}
        ${PROTO_HDRS})
 
-GENERATE_EXPORT_HEADER(${TARGET_CLIENT}
-       BASE_NAME       DEVICE_CERTIFICATE_MANAGER
-       PREFIX_NAME     API_)
-
-
 TARGET_LINK_LIBRARIES(${TARGET_CLIENT}
        ${Boost_SYSTEM_LIBRARY}
        ${PROTOBUF_LITE_LIBRARIES}
@@ -55,18 +50,18 @@ TARGET_LINK_LIBRARIES(${TARGET_CLIENT}
        ${CMAKE_THREAD_LIBS_INIT})
 
 SET_PROPERTY(TARGET ${TARGET_CLIENT} APPEND PROPERTY LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/version_script.lds")
-SET_PROPERTY(TARGET ${TARGET_CLIENT} PROPERTY DEFINE_SYMBOL DEVICE_CERTIFICATE_MANAGER_EXPORT)
-SET_PROPERTY(TARGET ${TARGET_CLIENT} PROPERTY VISIBILITY_INLINES_HIDDEN TRUE)
-SET_PROPERTY(TARGET ${TARGET_CLIENT} PROPERTY VERSION 2.0)
-SET_PROPERTY(TARGET ${TARGET_CLIENT} PROPERTY C_VISIBILITY_PRESET hidden)
-SET_PROPERTY(TARGET ${TARGET_CLIENT} PROPERTY CXX_VISIBILITY_PRESET hidden)
+SET_TARGET_PROPERTIES(${TARGET_CLIENT}
+       PROPERTIES
+       VERSION 2.0
+       DEFINE_SYMBOL DEVICE_CERTIFICATE_MANAGER_EXPORT
+       VISIBILITY_INLINES_HIDDEN TRUE
+       C_VISIBILITY_PRESET hidden
+       CXX_VISIBILITY_PRESET hidden)
 
 INSTALL(TARGETS ${TARGET_CLIENT}
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
 
 INSTALL(FILES
-       ${CMAKE_CURRENT_BINARY_DIR}/device_certificate_manager_export.h
-       dcm_client.h
        device_certificate_manager.h
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/device-certificate-manager)
 
index 2649ba1df080563d1b5e006d90d75fa0a6c61562..bd6ce70b2c23e1c72604994fa7eb7d7de30bd925 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************
  *
- * Copyright 2017 - 2018 Samsung Electronics All Rights Reserved.
+ * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved.
  *
  * Author: Jaroslaw Pelczar <j.pelczar@samsung.com>
  *
 #ifndef DCM_CLIENT_DCM_CLIENT_H_
 #define DCM_CLIENT_DCM_CLIENT_H_
 
-#include "device_certificate_manager_export.h"
-
 #include <mbedtls/md.h>
 
 #include <memory>
 #include <vector>
 
-class API_DEVICE_CERTIFICATE_MANAGER_EXPORT dcm_client_connection :
+class dcm_client_connection :
        public std::enable_shared_from_this<dcm_client_connection>
 {
 private:
@@ -36,8 +34,8 @@ private:
        dcm_client_connection& operator = (const dcm_client_connection&) = delete;
 
 protected:
-       dcm_client_connection() API_DEVICE_CERTIFICATE_MANAGER_NO_EXPORT;
-       ~dcm_client_connection() API_DEVICE_CERTIFICATE_MANAGER_NO_EXPORT;
+       dcm_client_connection();
+       ~dcm_client_connection();
 
 public:
        /*!
index f468e398bd40a8b583c0a078fe1d10779ed12330..9fe17491eeac2c85a9cfc15f9483169fe6417adf 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************
  *
- * Copyright 2017 Samsung Electronics All Rights Reserved.
+ * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved.
  *
  * Author: Jaroslaw Pelczar <j.pelczar@samsung.com>
  *
@@ -28,7 +28,7 @@
 #include <array>
 #include <boost/asio.hpp>
 
-class API_DEVICE_CERTIFICATE_MANAGER_NO_EXPORT dcm_client_connection_impl final : public dcm_client_connection
+class dcm_client_connection_impl final : public dcm_client_connection
 {
 public:
        dcm_client_connection_impl();
index dc3ff837b17357c91632d37ab0e8bcd5d2b16b35..bef03c8ed0b88de57b07da0cc3cca6001f15ad99 100644 (file)
@@ -16,7 +16,6 @@
  *
  ******************************************************************/
 
-#include "device_certificate_manager_export.h"
 #include "device_certificate_manager.h"
 #include "dcm_client.h"
 
 #include <vector>
 #include <cstring>
 
+#ifndef API_DEVICE_CERTIFICATE_MANAGER_EXPORT
+#define API_DEVICE_CERTIFICATE_MANAGER_EXPORT __attribute__((visibility("default")))
+#endif
+
 #define LOG_TAG                "DCM_CLIENT"
 #include <dlog.h>
 
index 88ea94d015ae966ba96449b5af9f9c01b17fea7b..9b724fc0943e6c9969cb6e18b26be4b4457ffd60 100644 (file)
@@ -6,10 +6,6 @@ DCMCLIENT_2.0 {
                dcm_get_key_bit_length;
                dcm_get_key_type;
                dcm_create_signature;
-               extern "C++" {
-                       dcm_client_connection::*;
-               };
-
        local:
                *;
 };
index b9c601cb738658e71f1542b6eb543c34e5f964ee..b8791da10c6296892086d0fe2a58b0729a0ff322 100644 (file)
@@ -32,7 +32,6 @@ Device Certificate Manager provides cryptography services for the Iotivity frame
 %package -n device-certificate-manager-devel
 Summary:       Device Certificate Manager (development)
 Group:         Security/Development
-Requires:      pkgconfig(iotivity)
 Requires:      device-certificate-manager = %{version}-%{release}
 
 %description -n device-certificate-manager-devel
@@ -76,19 +75,28 @@ make %{?jobs:-j%jobs}
 %post
 /sbin/ldconfig
 systemctl daemon-reload
-systemctl restart device-certificate-manager.socket
-systemctl restart device-certificate-manager.service
+if [ $1 = 1 ]; then
+       # installation
+       systemctl start device-certificate-manager.socket device-certificate-manager.service
+fi
+
+if [ $1 = 2 ]; then
+       # update
+       systemctl stop device-certificate-manager.service device-certificate-manager.socket
+       systemctl start device-certificate-manager.socket device-certificate-manager.service
+fi
 
 %preun
 if [ $1 = 0 ]; then
-    # unistall
-    systemctl stop device-certificate-manager.service device-certificate-manager.socket
+       # unistall
+       systemctl stop device-certificate-manager.service device-certificate-manager.socket
 fi
 
 %postun
+/sbin/ldconfig
 if [ $1 = 0 ]; then
-    # unistall
-    systemctl daemon-reload
+       # unistall
+       systemctl daemon-reload
 fi
 
 %files
@@ -104,8 +112,6 @@ fi
 %manifest %{name}.manifest
 %license LICENSE
 %{_libdir}/libdevice-certificate-manager.so
-%{_includedir}/device-certificate-manager/device_certificate_manager_export.h
-%{_includedir}/device-certificate-manager/dcm_client.h
 %{_includedir}/device-certificate-manager/device_certificate_manager.h
 %{_libdir}/pkgconfig/device-certificate-manager.pc
 
@@ -122,4 +128,3 @@ fi
 %license LICENSE
 %{_bindir}/dcm_api_test
 %{_bindir}/dcm_example_capi
-%{_bindir}/dcm_example_client
index eb07416453fc967538a1ea89d2d6360c0fabf233..31a81208a30be84e6c465fbaf4520a223394100f 100644 (file)
@@ -6,6 +6,5 @@ includedir=${prefix}/include
 Name: device-certificate-manager
 Description: Device Certificate Manager Package
 Version: @VERSION@
-Requires: iotivity
 Libs: -L${libdir} -ldevice-certificate-manager
 Cflags: -I${includedir}/device-certificate-manager
index eddb159eb8b439e330516b43f6872712664e6c2e..370cbeceafbd651a158ad6df6e52d4a572772a77 100644 (file)
@@ -22,7 +22,7 @@ FIND_PACKAGE(Boost REQUIRED
 
 INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})
 LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
-INCLUDE_DIRECTORIES(../dcm-client ../shared ${CMAKE_BINARY_DIR}/dcm-client)
+INCLUDE_DIRECTORIES(../dcm-client)
 
 ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
 ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)
@@ -30,9 +30,6 @@ ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)
 ADD_EXECUTABLE(dcm_example_capi example_capi.c)
 TARGET_LINK_LIBRARIES(dcm_example_capi device-certificate-manager)
 
-ADD_EXECUTABLE(dcm_example_client example_client.cpp)
-TARGET_LINK_LIBRARIES(dcm_example_client device-certificate-manager)
-
 ADD_EXECUTABLE(dcm_api_test api_test.cpp)
 TARGET_LINK_LIBRARIES(dcm_api_test
        device-certificate-manager
@@ -40,6 +37,5 @@ TARGET_LINK_LIBRARIES(dcm_api_test
 
 INSTALL(TARGETS
        dcm_example_capi
-       dcm_example_client
        dcm_api_test
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/tests/example_client.cpp b/tests/example_client.cpp
deleted file mode 100644 (file)
index 2a0f489..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/******************************************************************
- *
- * Copyright 2017 - 2019 Samsung Electronics 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.
- *
- ******************************************************************/
-
-#include "dcm_client.h"
-#include <iostream>
-#include <iomanip>
-
-int main()
-{
-       std::shared_ptr<dcm_client_connection> connection;
-       try {
-               connection = dcm_client_connection::create();
-       } catch(std::exception& ex) {
-               std::cerr << "Can't create connection: " << ex.what() << std::endl;
-               return -1;
-       }
-
-       if(!connection->create_context("example_client", "test_usage", "")) {
-               std::cerr << "Can't create context" << std::endl;
-               return -1;
-       }
-
-       std::cout << "Using key type " << connection->key_type() << std::endl;
-
-       std::vector<uint8_t> cert;
-       connection->get_certificate_chain(cert);
-
-       std::cout << "Cert is " << cert.size() << " bytes" << std::endl;
-
-       cert.push_back('\0');
-
-       std::cout << "Received cert " << ((const char *)&cert[0]) << std::endl;
-
-       std::cout << "Private key is " << connection->key_length() << " bits" << std::endl;
-       std::cout << "Private key is " << connection->key_type() << std::endl;
-
-       std::vector<uint8_t> signature;
-       if(connection->sign_data(MBEDTLS_MD_SHA256, "12345678901234567890123456789012", 32, signature) == 0) {
-               for(auto v : signature) {
-                       std::cout << std::hex << std::setw(2) << (unsigned int)v << " ";
-               }
-               std::cout << std::endl;
-       } else {
-               std::cerr << "Signing failure" << std::endl;
-       }
-
-       return 0;
-}