5b6221e43f0760345b073768b31f009c82859325
[platform/core/security/key-manager.git] / src / manager / service / ckm-service.h
1 /*
2  *  Copyright (c) 2000 - 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        ckm-service.h
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @version     1.0
20  * @brief       CKM service implementation.
21  */
22 #pragma once
23
24 #include <mutex>
25 #include <message-service.h>
26 #include <message-buffer.h>
27 #include <dpl/exception.h>
28
29 namespace CKM {
30
31 class CKMLogic;
32
33 class CKMService : public ThreadMessageService<MsgKeyRequest>
34 {
35 public:
36     CKMService();
37     CKMService(const CKMService &) = delete;
38     CKMService(CKMService &&) = delete;
39     CKMService& operator=(const CKMService &) = delete;
40     CKMService& operator=(CKMService &&) = delete;
41
42     // Custom add custom support for ReadEvent and SecurityEvent
43     // because we want to bypass security check in CKMService
44     virtual void Event(const ReadEvent &event) {
45         CreateEvent([this, event]() { this->CustomHandle(event); });
46     }
47
48     virtual void Event(const SecurityEvent &event) {
49         CreateEvent([this, event]() { this->CustomHandle(event); });
50     }
51
52     virtual void Start(void);
53     virtual void Stop(void);
54
55     virtual ~CKMService();
56
57     ServiceDescriptionVector GetServiceDescription();
58
59 protected:
60     // CustomHandle is used to bypass security check
61     void CustomHandle(const ReadEvent &event);
62     void CustomHandle(const SecurityEvent &event);
63
64 private:
65     virtual void SetCommManager(CommMgr *manager);
66
67     class Exception {
68     public:
69         DECLARE_EXCEPTION_TYPE(CKM::Exception, Base)
70         DECLARE_EXCEPTION_TYPE(Base, BrokenProtocol)
71     };
72
73     bool ProcessOne(
74         const ConnectionID &conn,
75         ConnectionInfo &info,
76         bool allowed);
77
78     RawBuffer ProcessControl(
79         MessageBuffer &buffer);
80
81     RawBuffer ProcessStorage(
82         Credentials &cred,
83         MessageBuffer &buffer);
84
85     virtual void ProcessMessage(MsgKeyRequest msg);
86
87     CKMLogic *m_logic;
88 };
89
90 } // namespace CKM
91