Remove services open-for and app-permissions.
[platform/core/security/security-server.git] / src / include / security-server.h
1 /*
2  *  security-server
3  *
4  *  Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd All Rights Reserved
5  *
6  *  Contact: Bumjin Im <bj.im@samsung.com>
7  *
8  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  you may not use this file except in compliance with the License.
10  *  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *  Unless required by applicable law or agreed to in writing, software
15  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  See the License for the specific language governing permissions and
18  *  limitations under the License
19  *
20  */
21
22 #ifndef SECURITY_SERVER_H
23 #define SECURITY_SERVER_H
24
25 #include <sys/types.h>
26 #include <privilege-control.h>
27
28 /**
29  * @file    security-server.h
30  * @version 1.0
31  * @brief   This file contains APIs of the Security Server
32 */
33
34 /**
35  * @defgroup SecurityFW
36  * @{
37  *
38  * @defgroup SECURITY_SERVER Security Server
39  * @version  1.0
40  * @brief    Security Server client library functions
41  *
42 */
43
44 /**
45  * @addtogroup SECURITY_SERVER
46  * @{
47 */
48
49 /*
50  * ====================================================================================================
51  * <tt>
52  *
53  * Revision History:
54  *
55  *  -- Company Name -- | Modification Date | Description of Changes
56  *  -----------------------------------------------------------------------
57  *   --- Samsung ------ | --- 2010-07-25 -- | First created
58  *
59  *    </tt>
60  */
61
62 /**
63  * \name Return Codes
64  * exported by the foundation API.
65  * result codes begin with the start error code and extend into negative direction.
66  * @{
67 */
68 #define SECURITY_SERVER_API_SUCCESS 0
69 /*! \brief   indicating the result of the one specific API is successful */
70 #define SECURITY_SERVER_API_ERROR_SOCKET -1
71
72 /*! \brief   indicating the socket between client and Security Server has been failed  */
73 #define SECURITY_SERVER_API_ERROR_BAD_REQUEST -2
74
75 /*! \brief   indicating the response from Security Server is malformed */
76 #define SECURITY_SERVER_API_ERROR_BAD_RESPONSE -3
77
78 /*! \brief   indicating requesting object is not exist */
79 #define SECURITY_SERVER_API_ERROR_NO_SUCH_OBJECT -6
80
81 /*! \brief   indicating the authentication between client and server has been failed */
82 #define SECURITY_SERVER_API_ERROR_AUTHENTICATION_FAILED -7
83
84 /*! \brief   indicating the API's input parameter is malformed */
85 #define SECURITY_SERVER_API_ERROR_INPUT_PARAM -8
86
87 /*! \brief   indicating the output buffer size which is passed as parameter is too small */
88 #define SECURITY_SERVER_API_ERROR_BUFFER_TOO_SMALL -9
89
90 /*! \brief   indicating system  is running out of memory state */
91 #define SECURITY_SERVER_API_ERROR_OUT_OF_MEMORY -10
92
93 /*! \brief   indicating the access has been denied by Security Server */
94 #define SECURITY_SERVER_API_ERROR_ACCESS_DENIED -11
95
96 /*! \brief   indicating Security Server has been failed for some reason */
97 #define SECURITY_SERVER_API_ERROR_SERVER_ERROR -12
98
99 /*! \brief   indicating given cookie is not exist in the database  */
100 #define SECURITY_SERVER_API_ERROR_NO_SUCH_COOKIE -13
101
102 /*! \brief   indicating there is no phone password set  */
103 #define SECURITY_SERVER_API_ERROR_NO_PASSWORD -14
104
105 /*! \brief   indicating password exists in system  */
106 #define SECURITY_SERVER_API_ERROR_PASSWORD_EXIST -15
107
108 /*! \brief   indicating password mismatch  */
109 #define SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH -16
110
111 /*! \brief   indicating password retry timeout is not occurred yet  */
112 #define SECURITY_SERVER_API_ERROR_PASSWORD_RETRY_TIMER -17
113
114 /*! \brief   indicating password retry timeout is not occurred yet  */
115 #define SECURITY_SERVER_API_ERROR_PASSWORD_MAX_ATTEMPTS_EXCEEDED -18
116
117 /*! \brief   indicating password retry timeout is not occurred yet  */
118 #define SECURITY_SERVER_API_ERROR_PASSWORD_EXPIRED -19
119
120 /*! \brief   indicating password retry timeout is not occurred yet  */
121 #define SECURITY_SERVER_API_ERROR_PASSWORD_REUSED -20
122
123 /*! \brief   indicating getting smack label from socket failed  */
124 #define SECURITY_SERVER_API_ERROR_GETTING_SOCKET_LABEL_FAILED -21
125
126 /*! \brief   indicating getting smack label from file failed  */
127 #define SECURITY_SERVER_API_ERROR_GETTING_FILE_LABEL_FAILED -22
128
129 /*! \brief   indicating setting smack label for file failed  */
130 #define SECURITY_SERVER_API_ERROR_SETTING_FILE_LABEL_FAILED -23
131
132 /*! \brief   indicating file already exists  */
133 #define SECURITY_SERVER_API_ERROR_FILE_EXIST -24
134
135 /*! \brief   indicating file does not exist  */
136 #define SECURITY_SERVER_API_ERROR_FILE_NOT_EXIST -25
137
138 /*! \brief   indicating file open error  */
139 #define SECURITY_SERVER_API_ERROR_FILE_OPEN_FAILED -26
140
141 /*! \brief   indicating file creation error  */
142 #define SECURITY_SERVER_API_ERROR_FILE_CREATION_FAILED -27
143
144 /*! \brief   indicating file deletion error  */
145 #define SECURITY_SERVER_API_ERROR_FILE_DELETION_FAILED -28
146
147 /*! \brief   indicating the error with unknown reason */
148 #define SECURITY_SERVER_API_ERROR_UNKNOWN -255
149 /** @}*/
150
151
152 #ifdef __cplusplus
153 extern "C" {
154 #endif
155
156
157
158 /**
159  * \par Description:
160  * Retreives Linux group ID from object name which is passed by parameter
161  *
162  * \par Purpose:
163  * This API may be used before security_server_check_privilege() API by middleware daemon to get group ID of a specific object.
164  *
165  * \par Typical use case:
166  * In middleware daemon, before checking privilege of a service the daemon need to know the GID of the service. This API support the functionality.
167  *
168  * \par Method of function operation:
169  * Opens /etc/group file and searches the object name as group name. If there is matching result, returns GID as integer
170  *
171  * \par Sync (or) Async:
172  * This is a Synchronous API.
173  *
174  * \par Important notes:
175  * - This API is only allowed to be called by pre-defined middleware daemon
176  *
177  * \param[in] object Name of the object which is kwnown by the caller.
178  *
179  * \return matching gid (positive integer) on success, or negative error code on error.
180  *
181  * \par Prospective clients:
182  * Inhouse middleware
183  *
184  * \par Known issues/bugs:
185  * None
186  *
187  * \pre None
188  *
189  * \post None
190  *
191  * \see /etc/group,
192  * security_server_get_object_name(), security_server_check_privilege()
193  *
194  * \remarks None
195  *
196  * \par Sample code:
197  * \code
198  * #include <security-server.h>
199  * ...
200  * int retval;
201  *
202  * // You have to make sure that  the input param '*object' is defined in the platform
203  * retval = security_server_get_gid("telephony_makecall");
204  * if(retval < 0)
205  * {
206  *      printf("%s", "Error has occurred\n");
207  *      exit(0);
208  * }
209  * ...
210  * \endcode
211  *
212  * Access to this function requires SMACK rule: "<app_label> security-server::api-get-gid w"
213 */
214 int security_server_get_gid(const char *object);
215
216 /**
217  * \par Description:
218  * Request cookie to the Security Server. Cookie is a random bit stream which is used as ticket for user space object.
219  *
220  * \par Purpose:
221  * This API may be used by application and client middleware process to get access to middleware daemons.
222  *
223  * \par Typical use case:
224  * When an application process wants to get access to some middleware object, first call this API to get cookie value. Then it calls the service API to get service with the cookie value.
225  *
226  * \par Method of function operation:
227  * Caller process just send request message. Security Server checks proc file system to get list of gIDs the caller belongs, then create a random cookie and responds to caller.
228  *
229  * \par Sync (or) Async:
230  * This is a Synchronous API.
231  *
232  * \par Important notes:
233  * Cookie needs to be stored relatively secure.
234  *
235  * \param[out] cookie Place holder for cookie value.
236  * \param[in] max_cookie Allocated byte size of parameter "cookie".
237  *
238  * \return 0 on success, or negative error code on error.
239  *
240  * \par Prospective clients:
241  * Any process
242  *
243  * \par Known issues/bugs:
244  * None
245  *
246  * \pre output parameter cookie must be malloced before calling this API not to make memory curruption
247  * Size of the cookie can be retrieved by security_server_get_cookie_size() API.
248  *
249  * \post None
250  *
251  * \see security_server_check_privilege(), security_server_get_cookie_size()
252  *
253  * \remarks None
254  *
255  * \par Sample code:
256  * \code
257  * #include <security-server.h>
258  * ...
259  * int retval;
260  * size_t cookie_size;
261  * cookie_size = security_server_get_cookie_size();
262  * unsigned char cookie[cookie_size];
263  *
264  * // Call the API
265  * retval = security_server_request_cookie(cookie, cookie_size);
266  * if(retval < 0)
267  * {
268  *      printf("%s", "Error has occurred\n");
269  *      exit(0);
270  * }
271  * ...
272  * \endcode
273  *
274  * Access to this function not requires SMACK rule
275 */
276 int security_server_request_cookie(char *cookie, size_t bufferSize);
277
278
279
280 /**
281  * \par Description:
282  * This API gets the cookie's byte size which is issued by Security Server.
283  *
284  * \par Purpose:
285  * This API may be used by application and middleware process to get size of cookie before getting and storing cookie value.
286  *
287  * \par Typical use case:
288  * When an application process wants to get access to some middleware object, first call this API to get cookie value. Then it calls the service API to get service with the cookie value.
289  *
290  * \par Method of function operation:
291  * This API just returns pre-defined integer value as cookie size.
292  *
293  * \par Sync (or) Async:
294  * This is a Synchronous API.
295  *
296  * \par Important notes:
297  * None
298  *
299  * \return Always returns byte size of the cookie.
300  *
301  * \par Prospective clients:
302  * Any process
303  *
304  * \par Known issues/bugs:
305  * None
306  *
307  * \pre None
308  *
309  * \post None
310  *
311  * \see security_server_request_cookie()
312
313  * \remarks None
314  *
315  * \par Sample code:
316  * \code
317  * #include <security-server.h>
318  * ...
319  * int retval;
320  * size_t cookie_size;
321  *
322  * // API calling
323  * cookie_size = security_server_get_cookie_size();
324  * unsigned char cookie[cookie_size];
325  *
326  * char objectname[20];
327  * retval = security_server_request_cookie(cookie, cookie_size);
328  * if(retval < 0)
329  * {
330  *      printf("%s", "Error has occurred\n");
331  *      exit(0);
332  * }
333  * ...
334  * \endcode
335  *
336  * Access to this function not requires SMACK rule
337 */
338 int security_server_get_cookie_size(void);
339
340
341
342 /**
343  * \par Description:
344  * This API checks the cookie is allowed to access to given object.
345  *
346  * \par Purpose:
347  * This API may be used by middleware process to ask the client application has privilege for the given object.
348  *
349  * \par Typical use case:
350  * When middleware server receives request message from client application process with cookie value, it calls this API to ask to Security Server that the client application has privilege to access the service. If yes, then the middleware daemon can continue service, if not, it can return error to client application.
351  *
352  * \par Method of function operation:
353  * When Security Server receives this request, it searches cookie database and check the cookie is there, if there is matching cookie, then it checks the cookie has the privilege. It returns success if there is match, if not, it returns error.
354  *
355  * \par Sync (or) Async:
356  * This is a Synchronous API.
357  *
358  * \par Important notes:
359  * Cookie value needs to be stored relatively secure\n
360  * Privilege should be pre-defined by Platform design.
361  *
362  * \param[in] cookie Received cookie value from client application
363  * \param[in] privilege Object group ID which the client application wants to access
364  *
365  * \return 0 on success, or negative error code on error.
366  *
367  * \par Prospective clients:
368  * Only pre-defiend middleware daemons
369  *
370  * \par Known issues/bugs:
371  * None
372  * \pre None
373  *
374  * \post None
375  *
376  * \see security_server_request_cookie(), security_server_get_gid(), security_server_get_cookie_size()
377  *
378  * \remarks None
379  *
380  * \par Sample code:
381  * \code
382  * #include <security-server.h>
383  * ...
384  * int retval;
385  * size_t cookie_size;
386  * int call_gid;
387  * cookie_size = security_server_get_cookie_size();
388  * unsigned char recved_cookie[cookie_size];
389  *
390  * ... // Receiving request with cookie
391  *
392  * call_gid = security_server_get_gid("telephony_makecall");
393  * retval = security_server_check_privilege(recved_cookie, (gid_t)call_gid);
394  * if(retval < 0)
395  * {
396  *      if(retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED)
397  *      {
398  *              printf("%s", "access has been denied\n");
399  *              return;
400  *      }
401  *      printf("%s", "Error has occurred\n");
402  * }
403  * ...
404  *
405  * \endcode
406  *
407  * Access to this function requires SMACK rule: "<app_label> security-server::api-cookie-check w"
408 */
409 int security_server_check_privilege(const char *cookie, gid_t privilege);
410
411 int security_server_check_privilege_by_cookie(const char *cookie,
412                                               const char *object,
413                                               const char *access_rights);
414
415 /**
416  * \par Description:
417  * This API searchs a cookie value and returns PID of the given cookie.
418  *
419  * \par Purpose:
420  * This API may be used by middleware process to ask the client application has privilege for the given object.
421  *
422  * \par Typical use case:
423  * In some cases, a middleware server wants to know PID of the application process. But if the middleware server uses non-direct IPC such as dbus, it's nearly impossible to know and guarantee peer PID. By using this API, the middleware server can retrieve a PID of the requesting process.
424  *
425  * \par Method of function operation:
426  * When Security Server receives this request, it searches cookie database and check the cookie is there, if there is matching cookie, then it returns corresponding PID for the cookie.
427  *
428  * \par Sync (or) Async:
429  * This is a Synchronous API.
430  *
431  * \par Important notes:
432  * Cookie value needs to be stored relatively secure\n
433  * This API is abled to be called only by pre-defined middleware servers.
434  *
435  * \param[in] cookie Received cookie value from client application. Cookie is not a null terminated human readable string. Make sure you're code doesn't have any string related process on the cookie.
436  *
437  * \return positive integer on success meaning the PID, 0 means the cookie is for root process, negative integer error code on error.
438  *
439  * \par Prospective clients:
440  * Only pre-defined middleware daemons
441  *
442  * \par Known issues/bugs:
443  * None
444  *
445  * \pre None
446  *
447  * \post None
448  *
449  * \see security_server_request_cookie(), security_server_get_cookie_size()
450  *
451  * \remarks the cookie is not a null terminated string. Cookie is a BINARY byte stream of such length which can be retrieved by security_server_get_cookie_size() API.
452  * Therefore, please do not use strcpy() family to process cookie value. You MUST use memcpy() function to process cookie value.
453  * You also have to know that the cookie value doesn't carry any null terminator. So you don't need to allocate 1 more byte of the cookie size.
454  *
455  * \par Sample code:
456  * \code
457  * #include <security-server.h>
458  * ...
459  * int peerpid;
460  * size_t cookie_size;
461  * gid_t call_gid;
462  * cookie_size = security_server_get_cookie_size();
463  * unsigned char recved_cookie[cookie_size];
464  *
465  * ... // Receiving request with cookie
466  *
467  * peerpid = security_server_get_cookie_pid(recved_cookie);
468  * if(peerpid < 0)
469  * {
470  *      printf("%s", "Error has occurred\n");
471  * }
472  * ...
473  *
474  * \endcode
475  *
476  * Access to this function requires SMACK rule: "<app_label> security-server::api-cookie-check w"
477 */
478 int security_server_get_cookie_pid(const char *cookie);
479
480
481
482 /**
483  * \par Description:
484  * This API checks phone validity of password, to check existance, expiration, remaining attempts.
485  *
486  * \par Purpose:
487  * This API should be used by applications which needs phone password check. Caller application should behave properly after this API call.
488  *
489  * \par Typical use case:
490  * Lock screen can call this API before it shows unlock screen, if there is password, lock screen can show password input UI, if not, lock screen can show just unlock screen
491  *
492  * \par Method of function operation:
493  * Sends a validate request to security server and security server replies with password information.
494  *
495  * \par Sync (or) Async:
496  * This is a Synchronous API.
497  *
498  * \par Important notes:
499  * Password file should be stored safely. The password file will be stored by security server and only allowed itself to read/write, and data is will be securely hashed\n
500  *
501  * \param[out] current_attempts Number of password check missed attempts.
502  * \param[out] max_attempts Number of maximum attempts that the password locks. 0 means infinite
503  * \param[out] valid_secs Remaining time in second which represents this password will be expired. 0xFFFFFFFF means infinite
504  *
505  * \return 0 if there is no password set, other negative integer error code on error.
506  *
507  * \par Prospective clients:
508  * Applications which can unlock UI
509  *
510  * \par Known issues/bugs:
511  * None
512  *
513  * \pre None
514  *
515  * \post None
516  *
517  * \see security_server_set_pwd(), security_server_chk_pwd()
518  *
519  * \remarks If password file is corrupted or accidentally deleted, this API may not synchronized with security-server, but security-server will check file status on next request.
520  *
521  * \par Sample code:
522  * \code
523  * #include <security-server.h>
524  * ...
525  * int ret;
526  * unsigned int attempt, max_attempt, expire_sec;
527  *
528  * ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
529  * if(is_pwd_set == SECURITY_SERVER_API_ERROR_NO_PASSWORD)
530  * {
531  *      printf("%s", "There is no password exists\n");
532  * }
533  * else if(is_pwd_set == SECURITY_SERVER_API_SUCCESS && expire_sec > 0 && attempt < max_attempts)
534  * {
535  *      printf("%s", "Password is valid by now\n");
536  * }
537  * else
538  * {
539  *      printf("%s", "Something wrong\n");
540  * }
541  * ...
542  *
543  * \endcode
544  *
545  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-check w"
546 */
547 int security_server_is_pwd_valid(unsigned int *current_attempts,
548                                  unsigned int *max_attempts,
549                                  unsigned int *valid_secs);
550
551
552
553 /**
554  * \par Description:
555  * This API sets phone password only if current password matches.
556  *
557  * \par Purpose:
558  * This API should be used by setting application when the user changes his/her phone password.
559  *
560  * \par Typical use case:
561  * Setting application calls this API to change phone password. Caller needs current password to grant the change.
562  *
563  * \par Method of function operation:
564  * Sends current password with new password to security-server, security-server checks current password and set new password to current only when current password is correct. Caller application can determine maximum number of attempts and expiration time in days
565  *
566  * \par Sync (or) Async:
567  * This is a Synchronous API.
568  *
569  * \par Important notes:
570  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
571  *
572  * \param[in] cur_pwd Null terminated current password string. It can be NULL pointer if there is no password set yet - by calling security_server_is_pwd_empty()
573  * \param[in] new_pwd Null terminated new password string. It must not a NULL pointer.
574  * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
575  * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
576  *
577  * \return 0 on success, negative integer error code on error.
578  *
579  * \par Prospective clients:
580  * Platform's THE ONLY setting application and some dedicated privileged processes
581  *
582  * \par Known issues/bugs:
583  * None
584  *
585  * \pre None
586  *
587  * \post None
588  *
589  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
590  *
591  * \remarks Only setting application can call this API. The password file will be access controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file corruption.
592  * \remarks If current password exists and it's expired, or max attempts reached, you cannot call this API. You have to call security_server_reset_pwd() API.
593  *
594  * \par Sample code:
595  * \code
596  * #include <security-server.h>
597  * ...
598  * int ret;
599  * unsigned int attempt, max_attempt, expire_sec;
600  *
601  * ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
602  * if(is_pwd_set == SECURITY_SERVER_API_ERROR_NO_PASSWORD)
603  * {
604  *      printf("%s", "There is no password exists\n");
605  *      ret = security_server_set_pwd(NULL, "this_is_new_pwd", 20, 365);
606  *      if(ret != SECURITY_SERVER_API_SUCCESS)
607  *      {
608  *              printf("%s", "we have error\n");
609  *              ...
610  *      }
611  * }
612  * else if(is_pwd_set == SECURITY_SERVER_API_SUCCESS && expire_sec > 0 && attempt < max_attempts)
613  * {
614  *      printf("%s", "Password is valid by now\n");
615  *      ret = security_server_set_pwd("this_is_current_pwd", "this_is_new_pwd", 20, 365);
616  *      if(ret != SECURITY_SERVER_API_SUCCESS)
617  *      {
618  *              printf("%s", "we have error\n");
619  *              ...
620  *      }
621  * }
622  * else
623  * {
624  *      printf("%s", "Something wrong\n");
625  * }
626  * ...
627  *
628  * \endcode
629  *
630  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
631 */
632 int security_server_set_pwd(const char *cur_pwd,
633                             const char *new_pwd,
634                             const unsigned int max_challenge,
635                             const unsigned int valid_period_in_days);
636
637
638 /**
639  * \par Description:
640  * This API sets validity period for currently setup password.
641  *
642  * \par Purpose:
643  * This API should be used by Enterprise authorities to modify password policy. To be used only with valid password setup.
644  *
645  * \par Typical use case:
646  * Authorized application calls this API to change current passwords validity when password policy needs to be changed.
647  *
648  * \par Method of function operation:
649  * Function attempts to find currently set password and changes its current validity to passed number of days. Retry counter for the password is reset to zero.
650  * If there is no password set, function returns proper error code.
651  *
652  * \par Sync (or) Async:
653  * This is a Synchronous API.
654  * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
655  *
656  * \return 0 on success, negative integer error code on error.
657  *
658  * \par Prospective clients:
659  * Platform's THE ONLY setting application and some dedicated privileged processes
660  *
661  * \par Known issues/bugs:
662  * Identifying calling peer is not ready yet, should be based on SMACK somehow.
663  *
664  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
665  *
666  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
667  */
668 int security_server_set_pwd_validity(const unsigned int valid_period_in_days);
669
670
671 /**
672  * \par Description:
673  * This API sets maximum number of attempts for currently setup password.
674  *
675  * \par Purpose:
676  * This API should be used by Enterprise authorities to modify password policy. To be used only with valid password setup.
677  *
678  * \par Typical use case:
679  * Authorized application calls this API to change current passwords max attempt number when password policy needs to be changed.
680  *
681  * \par Method of function operation:
682  * Function attempts to find currently set password and changes its max attempt number to passed one. Retry counter for the password is reset to zero.
683  * If there is no password set, function returns proper error code.
684  *
685  * \par Sync (or) Async:
686  * This is a Synchronous API.
687  * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
688  *
689  * \return 0 on success, negative integer error code on error.
690  *
691  * \par Prospective clients:
692  * Platform's THE ONLY setting application and some dedicated privileged processes
693  *
694  * \par Known issues/bugs:
695  * Identifying calling peer is not ready yet, should be based on SMACK somehow.
696  *
697  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
698  *
699  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
700  */
701 int security_server_set_pwd_max_challenge(const unsigned int max_challenge);
702
703 /**
704  * \par Description:
705  * This API sets phone password without performing any checks connected with provided password. It
706  * should be used only if current password is invalid or user forgot the password.
707  *
708  * \par Purpose:
709  * This API should be used by setting application or dedicated processes when the user changes his/her phone password.
710  *
711  * \par Typical use case:
712  * User forgets the password. He calls emergency manager(auto or manual)  for reset password. Emergency manager calls this API and reset phone password.
713  *
714  * \par Method of function operation:
715  * Resetting phone password with input string without any matching current password. Function does
716  * no checks before password replacement (expiration time check, currently set password checks,
717  * history check and attempt count check are skipped).
718  *
719  * \par Sync (or) Async:
720  * This is a Synchronous API.
721  *
722  * \par Important notes:
723  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
724  *
725  * \param[in] new_pwd Null terminated new password string. It must not a NULL pointer.
726  * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
727  * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
728  *
729  * \return 0 on success, negative integer error code on error.
730  *
731  * \par Prospective clients:
732  * Platform's THE ONLY setting application and some dedicated privileged processes
733  *
734  * \par Known issues/bugs:
735  * None
736  *
737  * \pre None
738  *
739  * \post None
740  *
741  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_set_pwd()
742  *
743  * \remarks Only dedicated applications can call this API. The password file will be access controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file corruption.
744  *
745  * \par Sample code:
746  * \code
747  * #include <security-server.h>
748  * ...
749  * int ret;
750  *
751  *      ret = security_server_reset_pwd("this_is_new_pwd", 20, 365);
752  *      if(retval != SECURITY_SERVER_API_SUCCESS)
753  *      {
754  *              printf("%s", "we have error\n");
755  *              ...
756  *      }
757  * ...
758  *
759  * \endcode
760  *
761  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-reset w"
762 */
763 int security_server_reset_pwd(const char *new_pwd,
764                               const unsigned int max_challenge,
765                               const unsigned int valid_period_in_days);
766
767 /**
768  * \par Description:
769  * This API compares stored phone password with challenged input value.
770  *
771  * \par Purpose:
772  * This API should be used by applications which has phone UI lock capability.
773  *
774  * \par Typical use case:
775  * Lock screen calls this API after user typed phone password and pressed okay.
776  *
777  * \par Method of function operation:
778  * Sends challenged password to security-server, security-server compares hashed current password and hashed challenged password.
779  *
780  * \par Sync (or) Async:
781  * This is a Synchronous API.
782  *
783  * \par Important notes:
784  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
785  *
786  * \param[in] challenge Null terminated challenged password string. It must not a NULL pointer.
787  * \param[out] current_attempts Number of password check missed attempts.
788  * \param[out] max_attempts Number of maximum attempts that the password locks. 0 means infinite
789  * \param[out] valid_secs Remaining time in second which represents this password will be expired. 0xFFFFFFFF means infinite
790  *
791  * \return 0 on success, negative integer error code on error.
792  *
793  * \par Prospective clients:
794  * Applications which has phone UI lock feature.
795  *
796  * \par Known issues/bugs:
797  * None
798  *
799  * \pre None
800  *
801  * \post None
802  *
803  * \see security_server_is_pwd_valid(), security_server_set_pwd()
804  *
805  * \remarks The password file will be acces controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file curruption.
806  *
807  * \par Sample code:
808  * \code
809  * #include <security-server.h>
810  * ...
811  * int retval;
812  * unsigned int attempt, max_attempt, expire_sec;
813  *
814  * retval = security_server_chk_pwd("is_this_password", &attmpt, &max_attempt, &expire_sec);
815  * if(retval == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH)
816  * {
817  *      printf("%s", "Oh you typed wrong password\n");
818  *      ...
819  * }
820  * else if(retval == SECURITY_SERVER_API_SUCCESS)
821  * {
822  *      printf("%s", "You remember your password.\n");
823  *      ...
824  * }
825  * ...
826  *
827  * \endcode
828  *
829  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-check w"
830 */
831 int security_server_chk_pwd(const char *challenge,
832                             unsigned int *current_attempt,
833                             unsigned int *max_attempt,
834                             unsigned int *valid_secs);
835
836
837 /**
838  * \par Description:
839  * This API set the number of password history which should be maintained. Once this number set, user cannot reuse recent number of passwords which is described in this history value
840  *
841  * \par Purpose:
842  * This API should be used only by dedicated process in the platform.
843  *
844  * \par Typical use case:
845  * Enterprise manager calls this API when the enterprise wants to enforce harder password policy.
846  *
847  * \par Method of function operation:
848  * When enterprise manager (MDM) is trying to change the security policy for phone password, it calls this API background to change the history policy.
849  *
850  * \par Sync (or) Async:
851  * This is a Synchronous API.
852  *
853  * \par Important notes:
854  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
855  *
856  * \param[in] history_size Number of history to be checked when user tries to change password. Maximum is currently 50
857  *
858  * \return 0 on success, negative integer error code on error.
859  *
860  * \par Prospective clients:
861  * MDM client, Enterprise manager.
862  *
863  * \par Known issues/bugs:
864  * None
865  *
866  * \pre None
867  *
868  * \post None
869  *
870  * \see security_server_set_pwd()
871  *
872  * \remarks The password file will be access controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file curruption.
873  *
874  * \par Sample code:
875  * \code
876  * #include <security-server.h>
877  * ...
878  * int retval;
879  *
880  * ret = security_server_set_pwd_history(100);
881  *      if(ret != SECURITY_SERVER_API_SUCCESS)
882  *      {
883  *              printf("%s", "You have error\n");
884  *              ...
885  *      }
886  * ...
887  *
888  * \endcode
889  *
890  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
891 */
892 int security_server_set_pwd_history(int history_size);
893
894 /*
895  * This function allows to get process SMACK label by passing cookie assigned
896  * to process. Function returns pointer to allocated buffer with label.
897  * User has to free the buffer after using.
898  *
899  * \param[in] Pointer to cookie
900  *
901  * \return Pointer to SMACK label or NULL
902  *
903  * \par For free label use free(), label allocated by calloc()
904  *      User responsibility is to free resource.
905  *
906  * Access to this function requires SMACK rule: "<app_label> security-server::api-cookie-check w"
907  */
908 char *security_server_get_smacklabel_cookie(const char *cookie);
909
910 /*
911  * This function allows to get process SMACK label by passing socket descriptor.
912  * Function returns pointer to allocated buffer with label.
913  * User has to free the buffer after using.
914  *
915  * \param[in] Socket descriptor
916  *
917  * \return Pointer to SMACK label or NULL
918  *
919  * \par For free label use free(), label allocated by calloc().
920  *      User responsibility is to free resource.
921  *
922  * Access to this function not requires SMACK rule
923  */
924 char *security_server_get_smacklabel_sockfd(int fd);
925
926 /*
927  * This function will give permissions "rwxat" from
928  * (subject) customer_label to caller process (object).
929  * Object label will be extracted from socket.
930  *
931  * \param[in] CUSTOMER_LABEL execute label of the process that should have access to caller.
932  * \param[in] CUSTOMER_PID all rules applied by this function should be removed from system
933  *                         when process with CUSTOMER_PID dies.
934  *
935  * \return SECURITY_SERVER_API_SUCCESS on success
936  * \return SECURITY_SERVER_API_ERROR_GETTING_SOCKET_LABEL_FAILED
937  * \return SECURITY_SERVER_API_ERROR_ACCESS_DENIED
938  * \return SECURITY_SERVER_API_ERROR_BAD_REQUEST input params were rejected by security-server
939  * \return SECURITY_SERVER_API_ERROR_INPUT_PARAM input params were rejected by client library
940  * \return SECURITY_SERVER_API_ERROR_SOCKET connection to security server failed.
941  *
942  * Important: In current implementation CUSTOMER_PID is ignored! This mean that rules applied
943  * by this function won't be revoke until device reset!
944  *
945  * Access to this function requires SMACK rule: "<app_label> security-server::api-data-share w"
946  * */
947 int security_server_app_give_access(const char *customer_label, int customer_pid);
948
949 /*
950  * This function allows middleware to check privileges of process with specified PID or socket
951  * file descriptor.
952  * Service is able to check process access to the specified object label with specified
953  * access rights.
954  *
955  * \param[in] PID id of process or SOCKFD socket file descriptor to be checked
956  * \param[in] SMACK object label
957  * \param[in] SMACK access rights to be checked
958  *
959  * \return Privilege confirm or error code
960  * \return SECURITY_SERVER_API_SUCCESS - on succes
961  *
962  * Access to this function requires SMACK rule: "<app_label> security-server::api-privilege-by-pid w"
963  */
964 int security_server_check_privilege_by_pid(int pid, const char *object, const char *access_rights);
965
966 int security_server_check_privilege_by_sockfd(int sockfd,
967                                               const char *object,
968                                               const char *access_rights);
969
970 #ifdef __cplusplus
971 }
972 #endif
973
974 /**
975  * @}
976 */
977
978 /**
979  * @}
980 */
981
982 #endif