sync with tizen_2.0
[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);
72
73         /**
74          * Initializes an instance of _PrivilegeInfo and sets its base information using stored 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         result Construct(const Tizen::App::AppId& appId, const Tizen::Base::String& encryptedPrivileges, const Tizen::Base::String& checksum, const Tizen::Base::String& encryptedVisibiliity, const Tizen::Base::String& visibilityChecksum);
86
87         /**
88          * Initializes an instance of _PrivilegeInfo and sets its base information using _PrivilegeInfo instance.
89          *
90          * @since               2.0
91          * @return              An error code
92          * @param[in]   privilegeInfo                   An instance of _PrivilegeInfo.
93          * @exception   E_SUCCESS                               The method is successful.
94          * @exception   E_AUTHENTICATION                The authentication has failed.
95          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
96          */
97         result Construct(const _PrivilegeInfo& privilegeInfo);
98
99         /**
100          * CCreates and returns a polymorphic copy of _PrivilegeInfo instance.
101          *
102          * @return      The clone of this instance
103          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
104          */
105
106         _PrivilegeInfo* CloneN(void) const;
107
108         /**
109          * Gets the application ID.
110          *
111          * @since               2.0
112          * @return              The application id
113          */
114         const Tizen::Base::String GetAppId(void) const;
115
116         /**
117          * Gets the bitwise privilege information.
118          *
119          * @since               2.0
120          * @return              An error code
121          * @param[out]  pBitwisePrivilege       The bitwise privilege information.
122          * @exception   E_SUCCESS                       The method is successful.
123          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
124          */
125         result GetBitwisePrivilegeN(byte*& pBitwisePrivilege) const;
126
127         /**
128          * Gets the encrypted string of bitwise privilege information.
129          *
130          * @since               2.0
131          * @return              An error code
132          * @param[out]  encryptedPrivileges     A string containing encrypted privilege information.
133          * @exception   E_SUCCESS                       The method is successful.
134          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
135          * @exception   E_SYSTEM                        An unexpected system error occurred.
136          */
137         result GetEncryptedBitwise(Tizen::Base::String& encryptedPrivileges) const;
138
139         /**
140          * Gets the checksum of bitwise privilege information.
141          *
142          * @since               2.0
143          * @return              An error code
144          * @param[out]  checksum                        A string containing checksum of privilege information.
145          * @exception   E_SUCCESS                       The method is successful.
146          * @exception   E_SYSTEM                        An unexpected system error occurred.
147          */
148         result GetChecksum(Tizen::Base::String& checksum) const;
149
150         /**
151          * Checks whether the application has a privilege to invoke.
152          *
153          * @since               2.0
154          * @return              A boolean value of the result
155          * @param[int]  privilege               A value of enumerator of the specified privilege group.
156          */
157         bool HasPrivilege(_Privilege privilege) const;
158
159 private:
160         /**
161          * Verify the checksum string.
162          *
163          * @since               2.0
164          * @return              E_SUCCESS if the checksum is normal
165          * @param[in]   appId                                   The application ID.
166          * @param[int]  targetBitwisePrivilege  The bitwise privilege information.
167          * @param[in]   storedChecksum                  The stored checksum.
168          * @param[out]  pResult                                 A boolean value of the result.
169          * @exception   E_SUCCESS                               The method is successful.
170          * @exception   E_INVALID_ARG                   The checksum is abnormal.
171          * @exception   E_OUT_OF_MEMORY                 The memory is insufficient.
172          * @exception   E_SYSTEM                                An unexpected system error occurred.
173          */
174         result VerifyIntegrity(const Tizen::App::AppId& appId, const byte* targetBitwisePrivilege, const Tizen::Base::String& storedChecksum, int length);
175         result VerifyIntegrityEx(const Tizen::App::AppId& appId, const byte* targetBitwisePrivilege, const Tizen::Base::String& storedChecksum, int length);
176         result VerifyIntegrity(const Tizen::App::AppId& appId, const byte* targetBitwisePrivilege, const Tizen::Base::String& storedChecksum, int length, int visibility, const Tizen::Base::String& storedVisibilityChecksum);
177
178         _PrivilegeInfo(const _PrivilegeInfo& rhs);
179         _PrivilegeInfo& operator =(const _PrivilegeInfo& rhs);
180
181 private:
182         Tizen::App::AppId __appId;
183         int __apiVisibility;
184         byte __bitwisePrivilege[MAX_BITWISE_PRIV_SIZE];
185         int __bitwiseLength;
186
187 };  // _PrivilegeInfo
188
189 }} // Tizen::Security
190
191 #endif // _FSEC_INTERNAL_PRIVILEGE_INFO_H_