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