2 * Copyright (c) 2014 Samsung Electronics Co.
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 ocsp-service.cpp
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @brief OCSP service implementation.
22 #include <service-thread.h>
23 #include <generic-socket-manager.h>
24 #include <connection-info.h>
25 #include <message-buffer.h>
26 #include <protocols.h>
28 #include <dpl/serialization.h>
29 #include <dpl/log/log.h>
31 #include <ocsp-service.h>
32 #include <ocsp-logic.h>
35 const CKM::InterfaceID SOCKET_ID_OCSP = 0;
36 } // namespace anonymous
40 OCSPService::OCSPService()
41 : m_logic(new OCSPLogic())
44 OCSPService::~OCSPService() {
48 GenericSocketService::ServiceDescriptionVector OCSPService::GetServiceDescription()
50 return ServiceDescriptionVector {
51 {SERVICE_SOCKET_OCSP, "ckm::api-ocsp", SOCKET_ID_OCSP}
55 void OCSPService::accept(const AcceptEvent &event) {
56 LogDebug("Accept event");
57 auto &info = m_connectionInfoMap[event.connectionID.counter];
58 info.interfaceID = event.interfaceID;
59 info.credentials = event.credentials;
62 void OCSPService::write(const WriteEvent &event) {
63 LogDebug("Write event (" << event.size << " bytes )");
66 void OCSPService::process(const ReadEvent &event) {
67 LogDebug("Read event");
68 auto &info = m_connectionInfoMap[event.connectionID.counter];
69 info.buffer.Push(event.rawBuffer);
70 while(processOne(event.connectionID, info));
73 bool OCSPService::processOne(
74 const ConnectionID &conn,
77 LogDebug ("process One");
80 if (!info.buffer.Ready())
83 auto &buffer = info.buffer;
86 RawBufferVector chainVector;
87 Deserialization::Deserialize(buffer, commandId);
88 Deserialization::Deserialize(buffer, chainVector);
90 RawBuffer response = m_logic->ocspCheck(commandId, chainVector);
91 m_serviceManager->Write(conn, response);
94 } Catch (MessageBuffer::Exception::Base) {
95 LogError("Broken protocol. Closing socket.");
96 } catch (const std::string &e) {
97 LogError("String exception(" << e << "). Closing socket");
99 LogError("Unknown exception. Closing socket.");
102 m_serviceManager->Close(conn);
106 void OCSPService::close(const CloseEvent &event) {
107 LogDebug("Close event");
108 m_connectionInfoMap.erase(event.connectionID.counter);