d7fd311d207035f26ab71dcf6629f4c660ff27b3
[platform/framework/native/appfw.git] / src / security / FSec_PrivilegeInfo.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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 /**
18  * @file        FSec_PrivilegeManagerInfo.h
19  * @brief       This is the header file for the FSec_PrivilegeInfo.
20  * This header file contains the declarations of the FSec_PrivilegeInfo.
21  */
22
23 #ifndef _FSEC_INTERNAL_PRIVILEGE_INFO_H_
24 #define _FSEC_INTERNAL_PRIVILEGE_INFO_H_
25
26 #include <FOspConfig.h>
27 #include "FSec_AccessControlTypes.h"
28
29 namespace Tizen { namespace Security
30 {
31
32 class ISecretKey;
33
34 /**
35  * @class       _PrivilegeInfo
36  * @brief       This class provides a basic information of privilege manager.
37  * @since       2.0
38  *
39  * This class provides a basic information of privilege manager.
40  *
41  */
42 class _PrivilegeInfo
43         : public Tizen::Base::Object
44 {
45
46 public:
47         /**
48          * This is the default constructor for this class.      @n
49          * This method creates an uninitialized instance of _PrivilegeCache.
50          *
51          * @since       2.0
52          */
53         _PrivilegeInfo(void);
54
55         /**
56          * This is the destructor for this class.
57          *
58          * @since       2.0
59          */
60         virtual ~_PrivilegeInfo(void);
61
62         /**
63          * Initializes an instance of _PrivilegeInfo and sets its base information directly.
64          *
65          * @since               2.0
66          * @return              An error code
67          * @param[in]   appId                           The application ID.
68          * @param[in]   pBitwisePrivilege       The bitwise privilege information.
69          * @exception   E_SUCCESS                       The method is successful.
70          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
71          */
72         result Construct(const Tizen::App::AppId& appId, const byte* pBitwisePrivilege, const Tizen::Base::Collection::ArrayList* pPrivilegeStringList);
73
74         /**
75          * Initializes an instance of _PrivilegeInfo and sets its base information using stored privilege information.
76          *
77          * @since               2.0
78          * @return              An error code
79          * @param[in]   appId                                   The application ID.
80          * @param[in]   encryptedPrivileges             A string containing encrypted privilege information.
81          * @param[in]   checksum                                A string containing checksum of privilege information.
82          * @exception   E_SUCCESS                               The method is successful.
83          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
84          */
85         result Construct(const Tizen::App::AppId& appId, const Tizen::Base::String& encryptedPrivileges, const Tizen::Base::String& checksum,
86                         const Tizen::Base::Collection::ArrayList* pPrivilegeStringList);
87
88         /**
89          * Initializes an instance of _PrivilegeInfo and sets its base information using stored privilege and visibility information.
90          *
91          * @since               2.0
92          * @return              An error code
93          * @param[in]   appId                                   The application ID.
94          * @param[in]   encryptedPrivileges             A string containing encrypted privilege information.
95          * @param[in]   checksum                                A string containing checksum of privilege information.
96          * @exception   E_SUCCESS                               The method is successful.
97          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
98          */
99         result Construct(const Tizen::App::AppId& appId, const Tizen::Base::String& encryptedPrivileges, const Tizen::Base::String& checksum,
100                         const Tizen::Base::String& encryptedVisibiliity, const Tizen::Base::String& visibilityChecksum, const Tizen::Base::Collection::ArrayList* pPrivilegeStringList);
101
102         /**
103          * Initializes an instance of _PrivilegeInfo and sets its base information using _PrivilegeInfo instance.
104          *
105          * @since               2.0
106          * @return              An error code
107          * @param[in]   privilegeInfo                   An instance of _PrivilegeInfo.
108          * @exception   E_SUCCESS                               The method is successful.
109          * @exception   E_AUTHENTICATION                The authentication has failed.
110          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
111          */
112         result Construct(const _PrivilegeInfo& privilegeInfo);
113
114         /**
115          * CCreates and returns a polymorphic copy of _PrivilegeInfo instance.
116          *
117          * @return      The clone of this instance
118          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
119          */
120
121         _PrivilegeInfo* CloneN(void) const;
122
123         /**
124          * Gets the application ID.
125          *
126          * @since               2.0
127          * @return              The application id
128          */
129         const Tizen::Base::String GetAppId(void) const;
130
131         /**
132          * Gets the bitwise privilege information.
133          *
134          * @since               2.0
135          * @return              An error code
136          * @param[out]  pBitwisePrivilege       The bitwise privilege information.
137          * @exception   E_SUCCESS                       The method is successful.
138          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
139          */
140         result GetBitwisePrivilegeN(byte*& pBitwisePrivilege) const;
141
142         /**
143          * Gets the encrypted string of bitwise privilege information.
144          *
145          * @since               2.0
146          * @return              An error code
147          * @param[out]  encryptedPrivileges     A string containing encrypted privilege information.
148          * @exception   E_SUCCESS                       The method is successful.
149          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
150          * @exception   E_SYSTEM                        An unexpected system error occurred.
151          */
152         result GetEncryptedBitwise(Tizen::Base::String& encryptedPrivileges) const;
153
154         /**
155          * Gets the checksum of bitwise privilege information.
156          *
157          * @since               2.0
158          * @return              An error code
159          * @param[out]  checksum                        A string containing checksum of privilege information.
160          * @exception   E_SUCCESS                       The method is successful.
161          * @exception   E_SYSTEM                        An unexpected system error occurred.
162          */
163         result GetChecksum(Tizen::Base::String& checksum) const;
164
165         /**
166          * Checks whether the application has a privilege to invoke.
167          *
168          * @since               2.0
169          * @return              A boolean value of the result
170          * @param[int]  privilege               A value of enumerator of the specified privilege.
171          */
172         bool HasPrivilege(_Privilege privilege) const;
173
174         /**
175          * Checks whether the application has a privilege to invoke. @n
176          * Unlike HasPrivilege, HasPrivilegeEx does not print the log.
177          *
178          * @since               2.1
179          * @return              A boolean value of the result
180          * @param[int]  privilege               A value of enumerator of the specified privilege.
181          */
182         bool HasPrivilegeEx(_Privilege privilege) const;
183
184         /**
185          * Checks whether the application has a privilege to invoke.
186          *
187          * @since               2.1
188          * @return              A boolean value of the result
189          * @param[in]   privilege               A string of the specified privilege.
190          */
191         bool HasPrivilege(const Tizen::Base::String& privilege) const;
192
193 private:
194
195         result VerifyIntegrity(const Tizen::App::AppId& appId, const byte* targetBitwisePrivilege, const Tizen::Base::String& storedChecksum, int length);
196         result VerifyIntegrity(const Tizen::App::AppId& appId, const byte* targetBitwisePrivilege, const Tizen::Base::String& storedChecksum, int length, int visibility, const Tizen::Base::String& storedVisibilityChecksum);
197         result VerifyIntegrityEx(const Tizen::App::AppId& appId, const byte* targetBitwisePrivilege, const Tizen::Base::String& storedChecksum, int length);
198
199         static ISecretKey* GetDeviceUniqueKeyN(void);
200
201         _PrivilegeInfo(const _PrivilegeInfo& rhs);
202         _PrivilegeInfo& operator =(const _PrivilegeInfo& rhs);
203
204 private:
205         Tizen::App::AppId __appId;
206         int __apiVisibility;
207         byte __bitwisePrivilege[MAX_BITWISE_PRIV_SIZE];
208         int __bitwiseLength;
209         Tizen::Base::Collection::ArrayList __privilegeList;
210
211 };  // _PrivilegeInfo
212
213 }} // Tizen::Security
214
215 #endif // _FSEC_INTERNAL_PRIVILEGE_INFO_H_