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