2 * Copyright (c) 2009-2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Elementary.h>
18 #include <security-manager.h>
20 #include <vconf-keys.h>
21 #include <sys/socket.h>
27 #include "lock_pwd_util.h"
28 #include "lock_pwd_verification.h"
29 #include "lock_pwd_simple.h"
31 #define PASSWORD_LENGTH_MIN 4
32 #define PASSWORD_LENGTH_MAX 16
40 static struct _s_lock_pwd_verification {
41 unsigned int current_attempt;
42 unsigned int remain_attempt;
43 unsigned int max_attempt;
44 unsigned int expire_sec;
45 unsigned int incorrect_count;
46 } s_lock_pwd_verification = {
56 int lock_pwd_verification_current_attempt_get(void)
58 return s_lock_pwd_verification.current_attempt;
62 int lock_pwd_verification_remain_attempt_get(void)
64 return s_lock_pwd_verification.remain_attempt;
68 static Eina_Bool _pwd_verification_check_pwd(const char *str)
71 int ret = SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH;
72 unsigned int current_attempt = 0;
73 unsigned int max_attempt = 0;
74 unsigned int expire_sec = 0;
76 ret = security_server_chk_pwd(str, ¤t_attempt, &max_attempt, &expire_sec);
77 _D("ret(%d), current_attempt(%d), max_attempt(%d), valid_sec(%d)", ret, current_attempt, max_attempt, expire_sec);
79 s_lock_pwd_verification.current_attempt = current_attempt;
80 s_lock_pwd_verification.max_attempt = max_attempt;
81 s_lock_pwd_verification.expire_sec = expire_sec;
84 case SECURITY_SERVER_API_SUCCESS:
85 case SECURITY_SERVER_API_ERROR_PASSWORD_EXPIRED:
86 _E("Correct password");
88 case SECURITY_SERVER_API_ERROR_PASSWORD_RETRY_TIMER:
89 _E("Timer set! : not saved");
92 _E("Incorrect password");
101 static lock_pwd_type _pwd_verification_check_length(const char *str, int min, int max)
105 retv_if(!str, EMPTY_PWD);
108 retv_if(len == 0, EMPTY_PWD);
110 retv_if(len < min || len > max, OVERLENGTH_PWD);
115 static void _pwd_values_init(void)
117 s_lock_pwd_verification.current_attempt = 0;
118 s_lock_pwd_verification.remain_attempt = PASSWORD_ATTEMPTS_MAX_NUM;
119 s_lock_pwd_verification.max_attempt = PASSWORD_ATTEMPTS_MAX_NUM;
120 s_lock_pwd_verification.incorrect_count = 0;
123 lock_pwd_event_e lock_pwd_verification_verify(const char *password)
125 lock_pwd_type pwd_type = NORMAL_PWD;
127 retv_if(!password, PWD_EVENT_EMPTY);
129 pwd_type = _pwd_verification_check_length(password, PASSWORD_LENGTH_MIN, PASSWORD_LENGTH_MAX);
132 if (_pwd_verification_check_pwd(password)) {
133 _D("Correct Password");
135 return PWD_EVENT_CORRECT;
137 s_lock_pwd_verification.incorrect_count++;
138 s_lock_pwd_verification.remain_attempt--;
139 _D("incorrect_count(%d), remain_attempt(%d)", s_lock_pwd_verification.incorrect_count, s_lock_pwd_verification.remain_attempt);
141 if (s_lock_pwd_verification.remain_attempt == 0) {
143 return PWD_EVENT_INPUT_BLOCK;
145 return PWD_EVENT_INCORRECT;
150 return PWD_EVENT_EMPTY;
153 return PWD_EVENT_OVER;
157 return PWD_EVENT_INCORRECT;
160 void lock_pwd_verification_policy_create(void)
164 unsigned int current_attempt = 0;
165 unsigned int max_attempt = 0;
166 unsigned int expire_sec = 0;
168 ret = security_server_is_pwd_valid(¤t_attempt, &max_attempt, &expire_sec);
169 _D("policy status(%d), current_attempt(%d), max_attempt(%d)", ret, current_attempt, max_attempt);
171 if (ret == SECURITY_SERVER_API_ERROR_NO_PASSWORD ||
172 ret == SECURITY_SERVER_API_ERROR_PASSWORD_EXIST) {
173 s_lock_pwd_verification.current_attempt = current_attempt;
174 s_lock_pwd_verification.max_attempt = max_attempt;
175 s_lock_pwd_verification.expire_sec = expire_sec;
178 s_lock_pwd_verification.remain_attempt = PASSWORD_ATTEMPTS_MAX_NUM;
179 s_lock_pwd_verification.incorrect_count = 0;
185 void lock_pwd_verification_popup_create(lock_pwd_event_e event)
187 char popup_text[BUF_SIZE_512] = { 0, };
188 int remain_attempt = 0;
189 int current_attempt = 0;
191 current_attempt = lock_pwd_verification_current_attempt_get();
192 remain_attempt = lock_pwd_verification_remain_attempt_get();
193 _D("current_attemp(%d), remain_attempt(%d)", current_attempt, remain_attempt);
196 case PWD_EVENT_INCORRECT_WARNING:
197 snprintf(popup_text, sizeof(popup_text), _("IDS_LCKSCN_POP_YOU_HAVE_ATTEMPTED_TO_UNLOCK_THE_DEVICE_INCORRECTLY_P1SD_P1SD_TIMES_YOU_HAVE_P2SD_ATTEMPTS_LEFT_BEFORE_THE_DEVICE_IS_RESET_THE_DEVICE_IS_RESET_TO_FACTORY_MSG"), current_attempt, remain_attempt);
198 lock_pwd_util_popup_create(NULL, popup_text, NULL, 0.0);
200 case PWD_EVENT_INPUT_BLOCK:
201 snprintf(popup_text, sizeof(popup_text), _("IDS_LCKSCN_POP_YOU_HAVE_MADE_P1SD_UNSUCCESSFUL_ATTEMPTS_TO_UNLOCK_YOUR_DEVICE_TRY_AGAIN_IN_P2SD_SECONDS"), PASSWORD_ATTEMPTS_MAX_NUM, PASSWORD_BLOCK_SECONDS);
202 lock_pwd_util_popup_create(_("IDS_LCKSCN_HEADER_UNABLE_TO_UNLOCK_SCREEN_ABB"), popup_text, NULL, 15.0);
204 case PWD_EVENT_INPUT_BLOCK_WARNING:
205 snprintf(popup_text, sizeof(popup_text), _("IDS_LCKSCN_POP_YOU_HAVE_ATTEMPTED_TO_UNLOCK_THE_DEVICE_INCORRECTLY_P1SD_TIMES_YOU_HAVE_P2SD_ATTEMPTS_LEFT_BEFORE_THE_DEVICE_IS_RESET_TO_FACTORY_MSG"), current_attempt, remain_attempt);
206 lock_pwd_util_popup_create(NULL, popup_text, NULL, 0.0);