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