2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 * @file ckm-manager-main.cpp
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @brief Implementation of central key manager
25 #include <openssl/ssl.h>
26 #include <openssl/conf.h>
27 #include <openssl/err.h>
28 #include <openssl/evp.h>
30 #include <dpl/log/log.h>
31 #include <dpl/singleton.h>
32 #include <dpl/singleton_safe_impl.h>
34 #include <socket-manager.h>
36 #include <ckm-service.h>
37 #include <ocsp-service.h>
39 #include <key-provider.h>
40 #include <CryptoService.h>
42 IMPLEMENT_SAFE_SINGLETON(CKM::Log::LogSystem);
44 #define REGISTER_SOCKET_SERVICE(manager, service) \
45 registerSocketService<service>(manager, #service)
48 void registerSocketService(CKM::SocketManager &manager, const std::string& serviceName)
54 manager.RegisterSocketService(service);
56 } catch (const CKM::Exception &exception) {
57 LogError("Error in creating service " << serviceName <<
58 ", details:\n" << exception.DumpToString());
59 } catch (const std::exception& e) {
60 LogError("Error in creating service " << serviceName <<
61 ", details:\n" << e.what());
63 LogError("Error in creating service " << serviceName <<
64 ", unknown exception occured");
73 ret = system("/usr/bin/key-manager-listener");
74 LogInfo("system return val : " << ret);
76 UNHANDLED_EXCEPTION_HANDLER_BEGIN
78 CKM::Singleton<CKM::Log::LogSystem>::Instance().SetTag("CKM");
82 sigaddset(&mask, SIGTERM);
83 sigaddset(&mask, SIGPIPE);
84 if (-1 == pthread_sigmask(SIG_BLOCK, &mask, NULL)) {
85 LogError("Error in pthread_sigmask");
88 LogInfo("Init external liblaries SKMM and openssl");
90 SSL_load_error_strings();
92 OpenSSL_add_all_ciphers();
95 CKM::KeyProvider::initializeLibrary();
96 CKM::CryptoService::initialize();
100 CKM::SocketManager manager;
102 REGISTER_SOCKET_SERVICE(manager, CKM::CKMService);
103 REGISTER_SOCKET_SERVICE(manager, CKM::OCSPService);
107 // Manager has been destroyed and we may close external libraries.
108 LogInfo("Deinit SKMM and openssl");
109 CKM::KeyProvider::closeLibrary();
114 UNHANDLED_EXCEPTION_HANDLER_END