e65114d152d370fb78b80b32d093433f45d83ab3
[platform/core/security/key-manager.git] / src / manager / service / ocsp-service.cpp
1 /*
2  *  Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
15  *
16  *
17  * @file        ocsp-service.cpp
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @version     1.0
20  * @brief       OCSP service implementation.
21  */
22
23 #include <protocols.h>
24
25 #include <dpl/serialization.h>
26 #include <dpl/log/log.h>
27
28 #include <ocsp-service.h>
29 #include <ocsp-logic.h>
30
31 namespace {
32 const CKM::InterfaceID SOCKET_ID_OCSP = 0;
33 } // namespace anonymous
34
35 namespace CKM {
36
37 OCSPService::OCSPService()
38   : m_logic(new OCSPLogic())
39 {}
40
41 OCSPService::~OCSPService() {
42     delete m_logic;
43 }
44
45 void OCSPService::Start() {
46     Create();
47 }
48
49 void OCSPService::Stop() {
50     Join();
51 }
52
53 GenericSocketService::ServiceDescriptionVector OCSPService::GetServiceDescription()
54 {
55     return ServiceDescriptionVector {
56         {SERVICE_SOCKET_OCSP, "http://tizen.org/privilege/internet", SOCKET_ID_OCSP}
57     };
58 }
59
60 bool OCSPService::ProcessOne(
61     const ConnectionID &conn,
62     ConnectionInfo &info,
63     bool allowed)
64 {
65     LogDebug ("process One");
66
67     Try {
68         if (!info.buffer.Ready())
69             return false;
70
71         auto &buffer = info.buffer;
72
73         int commandId = 0;
74         RawBufferVector chainVector;
75         buffer.Deserialize(commandId, chainVector);
76
77         RawBuffer response = m_logic->ocspCheck(commandId, chainVector, allowed);
78         m_serviceManager->Write(conn, response);
79
80         return true;
81     } Catch (MessageBuffer::Exception::Base) {
82         LogError("Broken protocol. Closing socket.");
83     } catch (const std::string &e) {
84         LogError("String exception(" << e << "). Closing socket");
85     } catch (...) {
86         LogError("Unknown exception. Closing socket.");
87     }
88
89     m_serviceManager->Close(conn);
90     return false;
91 }
92
93 } // namespace CKM
94