Unify CKMLogic methods and fix PKCS12 support
[platform/core/security/key-manager.git] / src / manager / service / access-control.h
1 /*
2  *  Copyright (c) 2000 - 2014 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        access-control.h
18  * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
19  * @version     1.0
20  * @brief       DB access control layer.
21  */
22 #pragma once
23
24 #include <string>
25 #include <ckm/ckm-type.h>
26 #include <ckm/ckm-raw-buffer.h>
27 #include <db-row.h>
28 #include <permission.h>
29 #include <generic-socket-manager.h>
30
31 namespace CKM {
32
33 class AccessControl {
34 public:
35         AccessControl();
36         /**
37          * return true if client uid is from the system services uid space
38          */
39         bool isSystemService(const uid_t uid) const;
40         bool isSystemService(const CKM::Credentials &cred) const;
41
42         /**
43          * check if given data can be saved by current accessor
44          * @return CKM_API_SUCCESS if access is allowed, otherwise negative error code
45          */
46         int canSave(const CKM::Credentials &accessorCred,
47                                 const ClientId &owner) const;
48
49         /**
50          * check if given row can be read (for internal use)
51          * @return CKM_API_SUCCESS if access is allowed, otherwise negative error code
52          */
53         int canRead(const CKM::Credentials &accessorCred,
54                                 const PermissionMask &existingPermission) const;
55
56         /**
57          * check if given row can be exported (data provided to the client)
58          * @return CKM_API_SUCCESS if access is allowed, otherwise negative error code
59          */
60         int canExport(const CKM::Credentials &accessorCred,
61                                   const DB::Row &row,
62                                   const PermissionMask &existingPermission) const;
63
64         /**
65          * check if given accessor can delete owner's items.
66          * @return CKM_API_SUCCESS if access is allowed, otherwise negative error code
67          */
68         int canDelete(const CKM::Credentials &accessorCred,
69                                   const PermissionMask &existingPermission) const;
70
71         void updateCCMode();
72         bool isCCMode() const;
73
74 private:
75         bool m_ccMode;
76 };
77
78 } // namespace CKM