PKG_CHECK_MODULES(KEY_MANAGER_DEP
REQUIRED
dlog
+ glib-2.0
openssl
libsmack
libcrypto
security-manager
cynara-client-async
cynara-creds-socket
+ capi-appfw-package-manager
)
FIND_PACKAGE(Threads REQUIRED)
${KEY_MANAGER_PATH}/service/access-control.cpp
${KEY_MANAGER_PATH}/service/ckm-service.cpp
${KEY_MANAGER_PATH}/service/ckm-logic.cpp
+ ${KEY_MANAGER_PATH}/service/glib-service.cpp
+ ${KEY_MANAGER_PATH}/service/glib-logic.cpp
${KEY_MANAGER_PATH}/service/key-provider.cpp
${KEY_MANAGER_PATH}/service/ocsp.cpp
${KEY_MANAGER_PATH}/service/crypto-logic.cpp
#include <ckm-service.h>
#include <ocsp-service.h>
#include <encryption-service.h>
+#include <glib-service.h>
#include <crypto-init.h>
#include <key-provider.h>
REGISTER_SOCKET_SERVICE(manager, CKM::CKMService);
REGISTER_SOCKET_SERVICE(manager, CKM::OCSPService);
REGISTER_SOCKET_SERVICE(manager, CKM::EncryptionService);
+ REGISTER_SOCKET_SERVICE(manager, CKM::GLIBService);
manager.MainLoop();
}
#pragma once
#include <memory>
+#include <string>
#include <credentials.h>
#include <ckm/ckm-type.h>
int error;
};
-typedef CommunicationManager<MsgKeyRequest, MsgKeyResponse> CommMgr;
+struct MsgRemoveAppData {
+ explicit MsgRemoveAppData(std::string pkgIdT)
+ : pkgId(std::move(pkgIdT))
+ {}
+
+ std::string pkgId;
+};
+
+typedef CommunicationManager<MsgKeyRequest, MsgKeyResponse, MsgRemoveAppData> CommMgr;
} /* namespace CKM */
* @version 1.0
* @brief Implementation of SocketManager.
*/
-
-#include <set>
-
#include <signal.h>
#include <sys/select.h>
#include <sys/signalfd.h>
auto &desc = CreateDefaultReadSocketDescription(m_notifyMe[0], false);
desc.service = new DummyService;
+ m_serviceVector.push_back(desc.service);
// std::thread bases on pthread so this should work fine
sigset_t set;
LogInfo("SignalService mounted on " << filefd << " descriptor");
}
+ if (signalService)
+ m_serviceVector.push_back(signalService);
+
// We cannot create Cynara earlier because descriptors are not initialized!
m_cynara.reset(new Cynara(this));
}
SocketManager::~SocketManager()
{
m_cynara.reset(nullptr);
- std::set<GenericSocketService*> serviceMap;
-
- // Find all services. Set is used to remove duplicates.
- // In this implementation, services are not able to react in any way.
- for (size_t i=0; i < m_socketDescriptionVector.size(); ++i)
- if (m_socketDescriptionVector[i].isOpen())
- serviceMap.insert(m_socketDescriptionVector[i].service);
// Time to destroy all services.
- for (auto service : serviceMap) {
+ for (auto service : m_serviceVector) {
LogDebug("delete " << (void*)(service));
if (service)
service->Stop();
service->SetSocketManager(this);
service->SetCommManager(&m_commMgr);
auto serviceVector = service->GetServiceDescription();
+ m_serviceVector.push_back(service);
Try {
for (auto iter = serviceVector.begin(); iter != serviceVector.end(); ++iter)
CreateDomainSocket(service, *iter);
std::priority_queue<Timeout> m_timeoutQueue;
CommMgr m_commMgr;
std::unique_ptr<Cynara> m_cynara;
+ std::vector<GenericSocketService*> m_serviceVector;
};
} // namespace CKM
}
}
+void CKMService::ProcessMessage(MsgRemoveAppData msg) {
+ LogDebug("Call removeApplicationData. pkgId: " << msg.pkgId);
+ m_logic->removeApplicationData(msg.pkgId);
+}
+
void CKMService::CustomHandle(const ReadEvent &event)
{
LogDebug("Read event");
class CKMLogic;
-class CKMService : public ThreadMessageService<MsgKeyRequest> {
+class CKMService : public ThreadMessageService<MsgKeyRequest, MsgRemoveAppData> {
public:
CKMService();
CKMService(const CKMService &) = delete;
MessageBuffer &buffer);
virtual void ProcessMessage(MsgKeyRequest msg);
+ virtual void ProcessMessage(MsgRemoveAppData msg);
CKMLogic *m_logic;
};
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2016 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 glib-logic.cpp
+ * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version 1.0
+ * @brief Dbus listener implementation as service.
+ */
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <glib.h>
+#include <package_manager.h>
+
+#include <dpl/log/log.h>
+#include <glib-logic.h>
+
+namespace CKM {
+
+GLIBLogic::GLIBLogic()
+ : m_commMgr(nullptr)
+{
+ LogDebug("Allocation g_main_loop");
+ m_gMainLoop = g_main_loop_new(nullptr, FALSE);
+}
+
+void GLIBLogic::LoopStart() {
+ package_manager_h request;
+ package_manager_create(&request);
+ LogDebug("Register uninstalledApp event callback start");
+ if (0 != package_manager_set_global_event_cb(request, packageEventCallbackStatic, this)) {
+ LogError("Error in package_manager_set_event_cb");
+ }
+ LogDebug("Starting g_main_loop");
+ g_main_loop_run(m_gMainLoop);
+ LogDebug("...g_main_loop ended");
+}
+
+void GLIBLogic::LoopStop() {
+ LogDebug("Closing g_main_loop");
+ g_main_loop_quit(m_gMainLoop);
+}
+
+GLIBLogic::~GLIBLogic() {
+ LogDebug("Destroying g_main_loop");
+ g_main_loop_unref(m_gMainLoop);
+}
+
+void GLIBLogic::SetCommManager(CommMgr *manager) {
+ m_commMgr = manager;
+}
+
+void GLIBLogic::packageEventCallbackStatic(
+ uid_t uid,
+ const char *type,
+ const char *package,
+ package_manager_event_type_e eventType,
+ package_manager_event_state_e eventState,
+ int progress,
+ package_manager_error_e error,
+ void *userData)
+{
+ LogDebug("Some event was caught");
+
+ if (!userData)
+ return;
+
+ static_cast<GLIBLogic*>(userData)->packageEventCallback(
+ uid,
+ type,
+ package,
+ eventType,
+ eventState,
+ progress,
+ error);
+}
+
+void GLIBLogic::packageEventCallback(
+ uid_t uid,
+ const char *type,
+ const char *package,
+ package_manager_event_type_e eventType,
+ package_manager_event_state_e eventState,
+ int progress,
+ package_manager_error_e error)
+{
+ (void) uid;
+ (void) type;
+ (void) progress;
+ (void) error;
+
+ if (eventType != PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL
+ || eventState != PACKAGE_MANAGER_EVENT_STATE_COMPLETED
+ || package == NULL)
+ {
+ return;
+ }
+
+ LogDebug("PackageUninstalled Callback. Uninstalation of: " << package);
+ m_commMgr->SendMessage(MsgRemoveAppData(std::string(package)));
+}
+
+} // namespace CKM
+
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2016 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 glib-logic.h
+ * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version 1.0
+ * @brief Dbus listener implementation as service.
+ */
+#pragma once
+
+#include <glib.h>
+
+#include <noncopyable.h>
+#include <package_manager.h>
+#include <service-messages.h>
+
+namespace CKM {
+
+class GLIBLogic {
+public:
+ GLIBLogic();
+
+ NONCOPYABLE(GLIBLogic);
+
+ void LoopStart();
+ void LoopStop();
+ void SetCommManager(CommMgr *manager);
+ virtual ~GLIBLogic();
+protected:
+ static void packageEventCallbackStatic(
+ uid_t uid,
+ const char *type,
+ const char *package,
+ package_manager_event_type_e eventType,
+ package_manager_event_state_e eventState,
+ int progress,
+ package_manager_error_e error,
+ void *userData);
+
+ void packageEventCallback(
+ uid_t uid,
+ const char *type,
+ const char *package,
+ package_manager_event_type_e eventType,
+ package_manager_event_state_e eventState,
+ int progress,
+ package_manager_error_e error);
+
+ CommMgr *m_commMgr;
+ GMainLoop *m_gMainLoop;
+};
+
+} // namespace CKM
+
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2016 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 glib-service.cpp
+ * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version 1.0
+ * @brief Dbus listener implementation as service.
+ */
+
+#include <thread>
+
+#include <dpl/log/log.h>
+
+#include <glib-service.h>
+#include <glib-logic.h>
+
+namespace CKM {
+
+GLIBService::GLIBService()
+ : m_state(State::NoThread)
+ , m_logic(new GLIBLogic())
+{}
+
+void GLIBService::Event(const AcceptEvent &) {}
+void GLIBService::Event(const WriteEvent &) {}
+void GLIBService::Event(const ReadEvent &) {}
+void GLIBService::Event(const CloseEvent &) {}
+void GLIBService::Event(const SecurityEvent &) {}
+
+void GLIBService::Start(){
+ LogDebug("Starting thread!");
+ assert(m_state == State::NoThread);
+ m_thread = std::thread(ThreadLoopStatic, this);
+ m_state = State::Work;
+}
+
+void GLIBService::Stop(){
+ LogDebug("Stopping thread!");
+ assert(m_state == State::Work);
+ m_logic->LoopStop();
+ m_thread.join();
+ m_state = State::NoThread;
+ LogDebug("Thread for glib joined!");
+}
+
+GLIBService::~GLIBService(){
+ delete m_logic;
+}
+
+GLIBService::ServiceDescriptionVector GLIBService::GetServiceDescription() {
+ return ServiceDescriptionVector();
+}
+
+void GLIBService::ThreadLoopStatic(GLIBService *ptr) {
+ ptr->ThreadLoop();
+}
+
+void GLIBService::ThreadLoop() {
+ m_logic->LoopStart();
+}
+
+void GLIBService::SetCommManager(CommMgr *manager) {
+ m_commMgr = manager;
+ m_logic->SetCommManager(manager);
+}
+
+} // namespace CKM
+
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2016 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 glib-service.h
+ * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version 1.0
+ * @brief Dbus listener implementation as service.
+ */
+#pragma once
+
+#include <thread>
+
+#include <noncopyable.h>
+#include <generic-socket-manager.h>
+
+namespace CKM {
+
+class GLIBLogic;
+
+class GLIBService : public CKM::GenericSocketService {
+public:
+ enum class State {
+ NoThread,
+ Work,
+ };
+
+ GLIBService();
+ NONCOPYABLE(GLIBService);
+
+ // This service does not provide any socket for communication so no events will be supported
+ virtual void Event(const AcceptEvent &);
+ virtual void Event(const WriteEvent &);
+ virtual void Event(const ReadEvent &);
+ virtual void Event(const CloseEvent &);
+ virtual void Event(const SecurityEvent &);
+
+ virtual void Start();
+ virtual void Stop();
+
+ virtual ~GLIBService();
+
+ virtual ServiceDescriptionVector GetServiceDescription();
+ virtual void SetCommManager(CommMgr *manager);
+protected:
+ static void ThreadLoopStatic(GLIBService *ptr);
+ void ThreadLoop();
+
+ State m_state;
+ std::thread m_thread;
+ GLIBLogic *m_logic;
+};
+
+} // namespace CKM
+