summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsangwan.kwon <sangwan.kwon@samsung.com>2016-05-11 10:25:56 +0900
committersangwan.kwon <sangwan.kwon@samsung.com>2016-05-11 14:35:31 +0900
commit93a4383419a348cb773f638776062648b5dc71d2 (patch)
tree7eb7977324f924d63cf27d052237949f797655de /src
parent6b884475b0cedb1bf67d438fd4bb01d1ac2e0680 (diff)
downloadcert-checker-93a4383419a348cb773f638776062648b5dc71d2.tar.gz
cert-checker-93a4383419a348cb773f638776062648b5dc71d2.tar.bz2
cert-checker-93a4383419a348cb773f638776062648b5dc71d2.zip
Implement on-demand style about client-side
[AS-IS] * cert-checker was daemon. [TO-BE] * Change to on-demand style. * Add client library. Change-Id: Ia318bc8a724db1f50a50bd42aa4c8c94b078e287
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/client/CMakeLists.txt60
-rw-r--r--src/client/error.h33
-rw-r--r--src/client/ocsp-client.cpp54
-rw-r--r--src/client/ocsp-client.h49
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/command-id.h31
-rw-r--r--src/common/dispatcher.cpp53
-rw-r--r--src/common/dispatcher.h70
-rw-r--r--src/common/serialization.h15
-rw-r--r--src/common/socket.cpp2
-rw-r--r--src/service/logic.h5
-rw-r--r--src/service/ocsp-service.cpp14
13 files changed, 376 insertions, 12 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 36e35c4..420b5ff 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -87,5 +87,6 @@ INSTALL(TARGETS ${TARGET_CERT_CHECKER} DESTINATION ${BIN_DIR})
ADD_SUBDIRECTORY(main)
ADD_SUBDIRECTORY(service)
ADD_SUBDIRECTORY(common)
+ADD_SUBDIRECTORY(client)
ADD_SUBDIRECTORY(po)
ADD_SUBDIRECTORY(ui)
diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt
new file mode 100644
index 0000000..cd3d78d
--- /dev/null
+++ b/src/client/CMakeLists.txt
@@ -0,0 +1,60 @@
+# Copyright (c) 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 CMakeLists.txt
+# @author Sangwan Kwon (sangwan.kwon@samsung.com)
+# @brief Make client library for ocsp-service.
+#
+PKG_CHECK_MODULES(${TARGET_CERT_CHECKER_CLIENT}_DEP
+ REQUIRED
+ libsystemd-journal
+)
+
+SET(${TARGET_CERT_CHECKER_CLIENT}_SRCS
+ ${CERT_CHECKER_SRC_PATH}/client/ocsp-client.cpp
+)
+
+INCLUDE_DIRECTORIES(SYSTEM
+ ${${TARGET_CERT_CHECKER_CLIENT}_DEP_INCLUDE_DIRS}
+ ${CERT_CHECKER_SRC_PATH}/
+ ${CERT_CHECKER_SRC_PATH}/include/
+ ${DPL_CORE_PATH}/include/
+ ${DPL_DB_PATH}/include/
+)
+
+ADD_LIBRARY(${TARGET_CERT_CHECKER_CLIENT}
+ SHARED ${${TARGET_CERT_CHECKER_CLIENT}_SRCS}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_CERT_CHECKER_CLIENT}
+ PROPERTIES
+ COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=default"
+ LINKER_LANGUAGE CXX
+ SOVERSION ${API_VERSION}
+ VERSION ${VERSION}
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_CERT_CHECKER_CLIENT}
+ ${${TARGET_CERT_CHECKER_CLIENT}_DEP_LIBRARIES}
+ ${TARGET_CERT_CHECKER_COMMON}
+)
+
+INSTALL(TARGETS ${TARGET_CERT_CHECKER_CLIENT} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(
+ FILES
+ ocsp-client.h
+ error.h
+ DESTINATION
+ ${INCLUDE_INSTALL_DIR}/cchecker
+)
diff --git a/src/client/error.h b/src/client/error.h
new file mode 100644
index 0000000..7504350
--- /dev/null
+++ b/src/client/error.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 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 error.h
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @version 1.0
+ * @brief Error codes of ocsp service.
+ */
+#pragma once
+
+namespace CCHECKER {
+namespace Client {
+
+using CCerr = int;
+
+const CCerr E_CC_NONE = 0;
+const CCerr E_CC_INTERNAL = -1;
+
+} // namespace Client
+} // namespace CCHECKER
diff --git a/src/client/ocsp-client.cpp b/src/client/ocsp-client.cpp
new file mode 100644
index 0000000..77484fc
--- /dev/null
+++ b/src/client/ocsp-client.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 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 ocsp-client.cpp
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @version 1.0
+ * @brief Client request OcspService with dispatcher in it
+ */
+#include "client/ocsp-client.h"
+#include "client/error.h"
+#include "common/command-id.h"
+
+#include <cchecker/log.h>
+
+namespace CCHECKER {
+namespace Client {
+
+OcspClient::OcspClient() :
+ m_address(SERVICE_STREAM)
+{
+ m_dispatcher.reset(new Dispatcher(m_address));
+}
+
+OcspClient::~OcspClient()
+{
+}
+
+CCerr OcspClient::request()
+{
+ LogDebug("Request to oscp service.");
+ auto ret = m_dispatcher->methodCall<CommandId>(CommandId::CC_OCSP_SYN);
+
+ LogDebug("Response ret : " << static_cast<int>(ret));
+ if(ret == CommandId::CC_OCSP_ACK)
+ return E_CC_NONE;
+ else
+ return E_CC_INTERNAL;
+}
+
+} // namespace Client
+} // namespace CCHECKER
diff --git a/src/client/ocsp-client.h b/src/client/ocsp-client.h
new file mode 100644
index 0000000..e1f29bb
--- /dev/null
+++ b/src/client/ocsp-client.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 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 ocsp-client.h
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @version 1.0
+ * @brief Client request to ocsp service
+ */
+#pragma once
+
+#include <string>
+#include <memory>
+
+#include "common/dispatcher.h"
+#include "client/error.h"
+
+namespace CCHECKER {
+namespace Client {
+
+class OcspClient {
+public:
+ OcspClient();
+ virtual ~OcspClient();
+
+ OcspClient(const OcspClient &) = delete;
+ OcspClient &operator=(const OcspClient &) = delete;
+
+ CCerr request();
+
+private:
+ std::string m_address;
+ std::unique_ptr<Dispatcher> m_dispatcher;
+};
+
+} // namespace Client
+} // namespace CCHECKER
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index fbfd9ff..dcd149d 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -27,6 +27,7 @@ SET(COMMON_PATH ${CERT_CHECKER_SRC_PATH}/common)
SET(${TARGET_CERT_CHECKER_COMMON}_SRCS
${COMMON_PATH}/binary-queue.cpp
${COMMON_PATH}/connection.cpp
+ ${COMMON_PATH}/dispatcher.cpp
${COMMON_PATH}/mainloop.cpp
${COMMON_PATH}/service.cpp
${COMMON_PATH}/socket.cpp
diff --git a/src/common/command-id.h b/src/common/command-id.h
new file mode 100644
index 0000000..e154e1a
--- /dev/null
+++ b/src/common/command-id.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 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 command-id.h
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+#pragma once
+
+namespace CCHECKER {
+
+enum class CommandId : int {
+ CC_OCSP_SYN = 0x01,
+ CC_OCSP_ACK = 0x02
+};
+
+} // namespace CCHECKER
diff --git a/src/common/dispatcher.cpp b/src/common/dispatcher.cpp
new file mode 100644
index 0000000..9b46493
--- /dev/null
+++ b/src/common/dispatcher.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 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 dispatcher.cpp
+ * @author Jaemin Ryu (jm77.ryu@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+#include "common/dispatcher.h"
+
+#include <utility>
+
+#include "common/socket.h"
+
+namespace CCHECKER {
+
+Dispatcher::Dispatcher(const std::string &path) : m_address(path)
+{
+}
+
+Dispatcher::~Dispatcher()
+{
+ disconnect();
+}
+
+void Dispatcher::connect()
+{
+ m_connection = std::make_shared<Connection>(Socket::connect(m_address));
+}
+
+void Dispatcher::disconnect()
+{
+}
+
+bool Dispatcher::isConnected()
+{
+ return m_connection ? true : false;
+}
+
+} // namespace CCHECKER
diff --git a/src/common/dispatcher.h b/src/common/dispatcher.h
new file mode 100644
index 0000000..def73ed
--- /dev/null
+++ b/src/common/dispatcher.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 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 dispatcher.h
+ * @author Jaemin Ryu (jm77.ryu@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+#pragma once
+
+#include <string>
+
+#include "common/connection.h"
+#include "common/binary-queue.h"
+
+namespace CCHECKER {
+
+class Dispatcher {
+public:
+ Dispatcher(const std::string &path);
+ virtual ~Dispatcher();
+
+ Dispatcher(const Dispatcher &) = delete;
+ Dispatcher &operator=(const Dispatcher &) = delete;
+ Dispatcher(Dispatcher &&) = delete;
+ Dispatcher &operator=(Dispatcher &&) = delete;
+
+ template<typename Type, typename ...Args>
+ Type methodCall(Args &&...args);
+
+private:
+ bool isConnected(void);
+ void connect(void);
+ void disconnect(void);
+
+ std::string m_address;
+ ConnShPtr m_connection;
+};
+
+template<typename Type, typename ...Args>
+Type Dispatcher::methodCall(Args &&...args)
+{
+ if (!isConnected())
+ connect();
+
+ m_connection->send(BinaryQueue::Serialize(std::forward<Args>(args)...).pop());
+
+ BinaryQueue q;
+ q.push(m_connection->receive());
+
+ Type response;
+ q.Deserialize(response);
+
+ return response;
+}
+
+} // namespace CCHECKER
diff --git a/src/common/serialization.h b/src/common/serialization.h
index 7f0ee84..04bd89d 100644
--- a/src/common/serialization.h
+++ b/src/common/serialization.h
@@ -32,6 +32,8 @@
#include <set>
#include <memory>
+#include "common/command-id.h"
+
namespace CCHECKER {
namespace Common {
@@ -147,6 +149,11 @@ struct Serialization {
stream.write(sizeof(*value), value);
}
+ static void Serialize(IStream &stream, const CommandId value)
+ {
+ Serialize(stream, static_cast<int>(value));
+ }
+
// std::string
template <typename T, typename R, typename A>
static void Serialize(IStream &stream, const std::basic_string<T, R, A> &str)
@@ -399,6 +406,14 @@ struct Deserialization {
{
stream.read(sizeof(value), &value);
}
+
+ static void Deserialize(IStream &stream, CommandId &value)
+ {
+ int val;
+ Deserialize(stream, val);
+ value = static_cast<CommandId>(val);
+ }
+
static void Deserialize(IStream &stream, bool *&value)
{
value = new bool;
diff --git a/src/common/socket.cpp b/src/common/socket.cpp
index a829484..30c2edc 100644
--- a/src/common/socket.cpp
+++ b/src/common/socket.cpp
@@ -135,7 +135,7 @@ Socket Socket::connect(const std::string &path)
std::error_code(errno, std::generic_category()),
"socket connect failed!");
- LogInfo("Connect to CSR server success with fd:" << fd);
+ LogInfo("Connect to OCSP service success with fd:" << fd);
return Socket(fd);
}
diff --git a/src/service/logic.h b/src/service/logic.h
index dca58b7..7d48124 100644
--- a/src/service/logic.h
+++ b/src/service/logic.h
@@ -61,11 +61,6 @@ enum pkgmgr_event_t {
EVENT_UNINSTALL
};
-enum class CommandId : int {
- CC_OCSP_SYN = 0x01,
- CC_OCSP_ACK = 0x02
-};
-
class Logic {
public:
Logic(void);
diff --git a/src/service/ocsp-service.cpp b/src/service/ocsp-service.cpp
index 7bb0ea1..8743de2 100644
--- a/src/service/ocsp-service.cpp
+++ b/src/service/ocsp-service.cpp
@@ -20,6 +20,7 @@
* @brief
*/
#include "service/ocsp-service.h"
+#include "common/command-id.h"
#include <cchecker/log.h>
@@ -40,10 +41,11 @@ void OcspService::onMessageProcess(const ConnShPtr &connection)
auto in = connection->receive();
connection->send(this->process(connection, in));
+
if (m_logic.setup() != NO_ERROR)
throw std::logic_error("Cannot setup logic.");
- LogDebug("Start to process message on ocsp service.");
+ LogDebug("Finish processing message on ocsp service.");
}
RawBuffer OcspService::process(const ConnShPtr &, RawBuffer &data)
@@ -51,14 +53,14 @@ RawBuffer OcspService::process(const ConnShPtr &, RawBuffer &data)
BinaryQueue q;
q.push(data);
- int cmd;
- q.Deserialize(cmd);
+ CommandId cid;
+ q.Deserialize(cid);
LogInfo("Request dispatch on ocsp-service.");
- switch (static_cast<CommandId>(cmd)) {
+ switch (cid) {
case CommandId::CC_OCSP_SYN: {
- // TODO(sangwan.kwon) : set protocol with client
- return BinaryQueue::Serialize(1).pop();
+ LogDebug("Success to get SYN cmd. reply ACK cmd.");
+ return BinaryQueue::Serialize(CommandId::CC_OCSP_ACK).pop();
}
case CommandId::CC_OCSP_ACK:
default: