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