File inc/ssh.inc.php changed (mode: 100644) (index 6c072f4..60f67ef) |
... |
... |
function rg_ssh_repo($db, $uid, $paras) |
56 |
56 |
rg_log('ssh_repo: ' . rg_array2string($paras)); |
rg_log('ssh_repo: ' . rg_array2string($paras)); |
57 |
57 |
|
|
58 |
58 |
if (empty($paras)) { |
if (empty($paras)) { |
59 |
|
echo 'Please specify the repo name.' . "\n"; |
|
|
59 |
|
fwrite(STDERR, 'Please specify the repo name.' . "\n"); |
60 |
60 |
exit(0); |
exit(0); |
61 |
61 |
} |
} |
62 |
62 |
|
|
|
... |
... |
function rg_ssh_repo($db, $uid, $paras) |
64 |
64 |
|
|
65 |
65 |
$ri = rg_repo_info($db, 0, $uid, $repo_name); |
$ri = rg_repo_info($db, 0, $uid, $repo_name); |
66 |
66 |
if ($ri['exists'] != 1) { |
if ($ri['exists'] != 1) { |
67 |
|
echo 'Error: unknown repo.' . "\n"; |
|
|
67 |
|
fwrite(STDERR, 'Error: unknown repo.' . "\n"); |
68 |
68 |
exit(0); |
exit(0); |
69 |
69 |
} |
} |
70 |
70 |
|
|
|
... |
... |
function rg_ssh_repo($db, $uid, $paras) |
112 |
112 |
. $reason . "\n"; |
. $reason . "\n"; |
113 |
113 |
} |
} |
114 |
114 |
} else { |
} else { |
115 |
|
echo 'Error: cannot get info about the lock status!' . "\n"; |
|
|
115 |
|
fwrite(STDERR, 'Error: cannot get info about the' |
|
116 |
|
. ' lock status!' . "\n"); |
116 |
117 |
} |
} |
117 |
118 |
} |
} |
118 |
119 |
|
|
|
... |
... |
function rg_ssh_totp_verify_ip($db, $uid, $ip) |
125 |
126 |
while (1) { |
while (1) { |
126 |
127 |
$r = rg_totp_verify_ip($db, $uid, $ip); |
$r = rg_totp_verify_ip($db, $uid, $ip); |
127 |
128 |
if ($r['ok'] !== 1) { |
if ($r['ok'] !== 1) { |
128 |
|
echo 'Error: ' . rg_totp_error() . ".\n"; |
|
|
129 |
|
fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); |
129 |
130 |
break; |
break; |
130 |
131 |
} |
} |
131 |
132 |
|
|
|
... |
... |
function rg_ssh_totp_verify_ip($db, $uid, $ip) |
135 |
136 |
} |
} |
136 |
137 |
|
|
137 |
138 |
if (empty($r['ip_list'])) { |
if (empty($r['ip_list'])) { |
138 |
|
echo 'Error: ' . rg_totp_error() . ".\n"; |
|
|
139 |
|
fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); |
139 |
140 |
break; |
break; |
140 |
141 |
} |
} |
141 |
142 |
|
|
|
... |
... |
function rg_ssh_totp($db, $ip, $uid, $paras) |
163 |
164 |
|
|
164 |
165 |
$r = rg_totp_enroll($db, $uid, 'SSH', $secret, $ip, 'f'); |
$r = rg_totp_enroll($db, $uid, 'SSH', $secret, $ip, 'f'); |
165 |
166 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
166 |
|
echo 'Error: ' . rg_totp_error() . ".\n"; |
|
|
167 |
|
fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); |
167 |
168 |
break; |
break; |
168 |
169 |
} |
} |
169 |
170 |
|
|
|
... |
... |
function rg_ssh_totp($db, $ip, $uid, $paras) |
180 |
181 |
|
|
181 |
182 |
$v = rg_totp_device_verify($db, $uid, $token); |
$v = rg_totp_device_verify($db, $uid, $token); |
182 |
183 |
if ($v['token_valid'] != 1) { |
if ($v['token_valid'] != 1) { |
183 |
|
echo 'Error: ' . rg_totp_error() . ".\n"; |
|
|
184 |
|
fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); |
184 |
185 |
break; |
break; |
185 |
186 |
} |
} |
186 |
187 |
|
|
|
... |
... |
function rg_ssh_totp($db, $ip, $uid, $paras) |
211 |
212 |
|
|
212 |
213 |
$v = rg_totp_verify_any($db, $uid, $token); |
$v = rg_totp_verify_any($db, $uid, $token); |
213 |
214 |
if ($v['token_valid'] != 1) { |
if ($v['token_valid'] != 1) { |
214 |
|
echo 'Error: ' . rg_totp_error() . ".\n"; |
|
|
215 |
|
fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); |
215 |
216 |
break; |
break; |
216 |
217 |
} |
} |
217 |
218 |
|
|
|
... |
... |
function rg_ssh_totp($db, $ip, $uid, $paras) |
220 |
221 |
gmdate('d') + $days, gmdate('Y')); |
gmdate('d') + $days, gmdate('Y')); |
221 |
222 |
$r = rg_totp_add_ip($db, $uid, $v['id'], $ip, $expire_ts); |
$r = rg_totp_add_ip($db, $uid, $v['id'], $ip, $expire_ts); |
222 |
223 |
if ($r === FALSE) { |
if ($r === FALSE) { |
223 |
|
echo 'Error: ' . rg_totp_error() . ".\n"; |
|
|
224 |
|
fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); |
224 |
225 |
break; |
break; |
225 |
226 |
} |
} |
226 |
227 |
|
|
|
... |
... |
function rg_ssh_totp($db, $ip, $uid, $paras) |
248 |
249 |
|
|
249 |
250 |
$v = rg_totp_verify_any($db, $uid, $token); |
$v = rg_totp_verify_any($db, $uid, $token); |
250 |
251 |
if ($v['token_valid'] != 1) { |
if ($v['token_valid'] != 1) { |
251 |
|
echo 'Error: ' . rg_totp_error() . ".\n"; |
|
|
252 |
|
fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); |
252 |
253 |
break; |
break; |
253 |
254 |
} |
} |
254 |
255 |
|
|
255 |
256 |
$r = rg_totp_unenroll($db, $uid); |
$r = rg_totp_unenroll($db, $uid); |
256 |
257 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
257 |
|
echo'Error: ' . rg_totp_error() . ".\n"; |
|
|
258 |
|
fwrite(STDERR< 'Error: ' . rg_totp_error() . ".\n"); |
258 |
259 |
break; |
break; |
259 |
260 |
} |
} |
260 |
261 |
|
|
|
... |
... |
function rg_ssh_totp($db, $ip, $uid, $paras) |
266 |
267 |
|
|
267 |
268 |
$v = rg_totp_device_verify($db, $uid, $token); |
$v = rg_totp_device_verify($db, $uid, $token); |
268 |
269 |
if ($v['token_valid'] != 1) { |
if ($v['token_valid'] != 1) { |
269 |
|
echo 'Error: ' . rg_totp_error() . ".\n"; |
|
|
270 |
|
fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); |
270 |
271 |
break; |
break; |
271 |
272 |
} |
} |
272 |
273 |
|
|
273 |
274 |
$a = array($v['id'] => ''); |
$a = array($v['id'] => ''); |
274 |
275 |
$r = rg_totp_remove($db, $uid, $a); |
$r = rg_totp_remove($db, $uid, $a); |
275 |
276 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
276 |
|
echo 'Error: ' . rg_totp_error() . ".\n"; |
|
|
277 |
|
fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); |
277 |
278 |
break; |
break; |
278 |
279 |
} |
} |
279 |
280 |
|
|
|
... |
... |
function rg_ssh_totp($db, $ip, $uid, $paras) |
282 |
283 |
|
|
283 |
284 |
case 'inval': |
case 'inval': |
284 |
285 |
if (empty($paras)) { |
if (empty($paras)) { |
285 |
|
echo 'Error: Please specify the IP address or \'all\'.' . "\n"; |
|
|
286 |
|
fwrite(STDERR, 'Error: Please specify the IP address' |
|
287 |
|
. ' or \'all\'.' . "\n"); |
286 |
288 |
break; |
break; |
287 |
289 |
} |
} |
288 |
290 |
|
|
|
... |
... |
function rg_ssh_totp($db, $ip, $uid, $paras) |
293 |
295 |
|
|
294 |
296 |
$r = rg_totp_del_ip($db, $uid, $del_ip); |
$r = rg_totp_del_ip($db, $uid, $del_ip); |
295 |
297 |
if ($r['found'] != 1) { |
if ($r['found'] != 1) { |
296 |
|
echo 'Error: ' . rg_totp_error() . ".\n"; |
|
|
298 |
|
fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); |
297 |
299 |
break; |
break; |
298 |
300 |
} |
} |
299 |
301 |
|
|
|
... |
... |
function rg_ssh_totp($db, $ip, $uid, $paras) |
301 |
303 |
break; |
break; |
302 |
304 |
|
|
303 |
305 |
default: |
default: |
304 |
|
echo 'Posible TOTP commands:' . "\n"; |
|
305 |
|
echo ' enroll <token> - adds a new device in the system' . "\n"; |
|
306 |
|
echo ' val [X(w|d|h|m|s)] <token> - adds your IP to the allow list for X time' . "\n"; |
|
307 |
|
echo ' the default is 1 hour; X is a number; defauls is \'minutes\';' . "\n"; |
|
308 |
|
echo ' w=weeks, d=days, h=hours, m=minutes, and s for seconds' . "\n"; |
|
309 |
|
echo ' list-val - lists the already validated IPs' . "\n"; |
|
310 |
|
echo ' inval ip|all - invalidates IP address(es)' . "\n"; |
|
311 |
|
echo ' remove-device <token> - removes a device from TOTP system' . "\n"; |
|
312 |
|
echo ' unenroll <token> - removes all devices and scratch codes from TOTP system' . "\n"; |
|
313 |
|
echo "\n"; |
|
314 |
|
echo 'Notes:' . "\n"; |
|
315 |
|
echo ' - <token> means a code generated by mobile device or a scratch code' . "\n"; |
|
|
306 |
|
fwrite(STDERR, "\n" |
|
307 |
|
. 'Posible TOTP commands:' . "\n" |
|
308 |
|
. ' enroll <token> - adds a new device in the system' . "\n" |
|
309 |
|
. ' val [X(w|d|h|m|s)] <token> - adds your IP to the allow list for X time' . "\n" |
|
310 |
|
. ' the default is 1 hour; X is a number; defauls is \'minutes\';' . "\n" |
|
311 |
|
. ' w=weeks, d=days, h=hours, m=minutes, and s=seconds' . "\n" |
|
312 |
|
. ' list-val - lists the already validated IPs' . "\n" |
|
313 |
|
. ' inval ip|all - invalidates IP address(es)' . "\n" |
|
314 |
|
. ' remove-device <token> - removes a device from TOTP system' . "\n" |
|
315 |
|
. ' unenroll <token> - removes all devices and scratch codes from TOTP system' . "\n" |
|
316 |
|
. "\n" |
|
317 |
|
. 'Notes:' . "\n" |
|
318 |
|
. ' - <token> means a code generated by mobile device or a scratch code' . "\n" |
|
319 |
|
); |
316 |
320 |
break; |
break; |
317 |
321 |
} |
} |
318 |
322 |
|
|
|
... |
... |
function rg_ssh_dispatch($db, $ip, $uid, $orig_cmd) |
382 |
386 |
$r = rg_totp_verify_ip($db, $uid, $ip); |
$r = rg_totp_verify_ip($db, $uid, $ip); |
383 |
387 |
if (($r['ok'] !== 1) |
if (($r['ok'] !== 1) |
384 |
388 |
|| ($r['enrolled'] && empty($r['ip_list']))) { |
|| ($r['enrolled'] && empty($r['ip_list']))) { |
385 |
|
echo 'Error: ' . rg_totp_error() . ".\n"; |
|
|
389 |
|
fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); |
386 |
390 |
return TRUE; // = we must exit' |
return TRUE; // = we must exit' |
387 |
391 |
} |
} |
388 |
392 |
break; |
break; |
|
... |
... |
function rg_ssh_dispatch($db, $ip, $uid, $orig_cmd) |
396 |
400 |
case 'totp': rg_ssh_totp($db, $ip, $uid, $paras); return TRUE; |
case 'totp': rg_ssh_totp($db, $ip, $uid, $paras); return TRUE; |
397 |
401 |
case 'api': rg_ssh_api($db, $ip, $uid, $paras); return TRUE; |
case 'api': rg_ssh_api($db, $ip, $uid, $paras); return TRUE; |
398 |
402 |
case '': |
case '': |
399 |
|
echo "Available commmands:\n" |
|
400 |
|
. " status - show some status about the user\n" |
|
401 |
|
. " repos - list repos and information about them\n" |
|
402 |
|
. " repo - list info about a repo\n" |
|
403 |
|
. " totp - two-factor authentication commands\n" |
|
404 |
|
. " api - API calls\n"; |
|
|
403 |
|
fwrite(STDERR, "\n" |
|
404 |
|
. 'Available commmands:' . "\n" |
|
405 |
|
. ' status - show some status about the user' . "\n" |
|
406 |
|
. ' repos - list repos and information about them' . "\n" |
|
407 |
|
. ' repo - list info about a repo' . "\n" |
|
408 |
|
. ' totp - two-factor authentication commands' . "\n" |
|
409 |
|
. ' api - API calls' . "\n"); |
405 |
410 |
return TRUE; |
return TRUE; |
406 |
411 |
} |
} |
407 |
412 |
|
|
File tests/ssh.php changed (mode: 100644) (index 6c9518d..ec2a99a) |
... |
... |
rg_log(''); |
44 |
44 |
$list = array('', 'status', 'repos', 'repo', 'totp'); |
$list = array('', 'status', 'repos', 'repo', 'totp'); |
45 |
45 |
foreach ($list as $s) { |
foreach ($list as $s) { |
46 |
46 |
rg_log('Connecting for [' . $s . ']'); |
rg_log('Connecting for [' . $s . ']'); |
47 |
|
$r = shell_exec($cmd . ' ' . $s . ' 2>&1'); |
|
48 |
|
if (!strstr($r, "Welcome to RocketGit")) { |
|
49 |
|
rg_log('r=' . $r); |
|
50 |
|
rg_log("Trying to get the help detected missing welcome!"); |
|
|
47 |
|
$r = rg_exec($cmd . ' ' . $s, '', FALSE, FALSE); |
|
48 |
|
if ($r['ok'] != 1) { |
|
49 |
|
rg_log_ml('error: ' . $r['stderr']); |
51 |
50 |
exit(1); |
exit(1); |
52 |
51 |
} |
} |
53 |
|
if (strstr($r, 'Error: .')) { |
|
54 |
|
rg_log('r=' . $r); |
|
55 |
|
rg_log('Error is empty for \'' . $s . '\'! Not good!'); |
|
|
52 |
|
if (!strstr($r['stderr'], "Welcome to RocketGit")) { |
|
53 |
|
rg_log_ml('stderr: ' . $r['stderr']); |
|
54 |
|
rg_log("Trying to get the help detected missing welcome!"); |
56 |
55 |
exit(1); |
exit(1); |
57 |
56 |
} |
} |
58 |
57 |
} |
} |
|
... |
... |
foreach ($list as $s) { |
60 |
59 |
$list = array('remove-device', 'unenroll'); |
$list = array('remove-device', 'unenroll'); |
61 |
60 |
foreach ($list as $s) { |
foreach ($list as $s) { |
62 |
61 |
rg_log('Connecting for [totp ' . $s . ']'); |
rg_log('Connecting for [totp ' . $s . ']'); |
63 |
|
$r = shell_exec($cmd . ' totp ' . $s . ' 2>&1'); |
|
64 |
|
if (strstr($r, 'Error: .')) { |
|
65 |
|
rg_log('r=' . $r); |
|
66 |
|
rg_log('Error is empty for \'' . $s . '\'! Not good!'); |
|
|
62 |
|
$r = rg_exec($cmd . ' totp ' . $s, '', FALSE, FALSE); |
|
63 |
|
if ($r['ok'] != 1) { |
|
64 |
|
rg_log_ml('error: ' . $r['stderr']); |
67 |
65 |
exit(1); |
exit(1); |
68 |
66 |
} |
} |
69 |
67 |
} |
} |
|
... |
... |
foreach ($list as $s) { |
71 |
69 |
|
|
72 |
70 |
rg_log(''); |
rg_log(''); |
73 |
71 |
rg_log_enter('Testing wrong command'); |
rg_log_enter('Testing wrong command'); |
74 |
|
$r = shell_exec($cmd . ' wrongcmd ' . ' 2>&1'); |
|
75 |
|
if (!strstr($r, "nknown command")) { |
|
76 |
|
rg_log('r=' . $r); |
|
|
72 |
|
$r = rg_exec($cmd . ' wrongcmd', '', FALSE, FALSE); |
|
73 |
|
if ($r['ok'] != 0) { |
|
74 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
75 |
|
rg_log('We should receive error code 0 not ' . $r['ok'] . '!'); |
|
76 |
|
exit(1); |
|
77 |
|
} |
|
78 |
|
if (!strstr($r['stderr'], "nknown command")) { |
|
79 |
|
rg_log('stderr: ' . $r['stderr']); |
77 |
80 |
rg_log("Wrong answer for a wrong command!"); |
rg_log("Wrong answer for a wrong command!"); |
78 |
81 |
exit(1); |
exit(1); |
79 |
82 |
} |
} |
|
... |
... |
rg_log_exit(); |
82 |
85 |
|
|
83 |
86 |
rg_log(''); |
rg_log(''); |
84 |
87 |
rg_log('Testing enroll procedure'); |
rg_log('Testing enroll procedure'); |
85 |
|
$r = shell_exec($cmd . ' totp enroll'); |
|
86 |
|
$t = explode('enter the following code: ', $r); |
|
|
88 |
|
$r = rg_exec($cmd . ' totp enroll', '', FALSE, FALSE); |
|
89 |
|
$t = explode('enter the following code: ', $r['data']); |
87 |
90 |
$t = explode('.', $t[1]); |
$t = explode('.', $t[1]); |
88 |
91 |
$key = trim($t[0]); |
$key = trim($t[0]); |
89 |
92 |
rg_log("key=$key"); |
rg_log("key=$key"); |
90 |
93 |
|
|
91 |
94 |
$tc = intval(time() / 30) - 1; // we try one in the past |
$tc = intval(time() / 30) - 1; // we try one in the past |
92 |
95 |
$token = rg_totp_compute($key, $tc, 6); |
$token = rg_totp_compute($key, $tc, 6); |
93 |
|
$r = shell_exec($cmd . ' totp enroll ' . $token); |
|
94 |
|
if (!strstr($r, 'Success!')) { |
|
95 |
|
rg_log('r=' . $r); |
|
|
96 |
|
$r = rg_exec($cmd . ' totp enroll ' . $token, '', FALSE, FALSE); |
|
97 |
|
if ($r['ok'] != 1) { |
|
98 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
99 |
|
exit(1); |
|
100 |
|
} |
|
101 |
|
if (!strstr($r['data'], 'Success!')) { |
|
102 |
|
rg_log('data: ' . $r['data']); |
96 |
103 |
rg_log('Cannot enroll!'); |
rg_log('Cannot enroll!'); |
97 |
104 |
exit(1); |
exit(1); |
98 |
105 |
} |
} |
|
... |
... |
rg_log(''); |
102 |
109 |
rg_log('Testing \'val\' command'); |
rg_log('Testing \'val\' command'); |
103 |
110 |
$tc = intval(time() / 30); |
$tc = intval(time() / 30); |
104 |
111 |
$token = rg_totp_compute($key, $tc, 6); |
$token = rg_totp_compute($key, $tc, 6); |
105 |
|
$r = shell_exec($cmd . ' totp val ' . $token . ' 2m'); |
|
106 |
|
if (!strstr($r, 'Success!')) { |
|
107 |
|
rg_log('r=' . $r); |
|
|
112 |
|
$r = rg_exec($cmd . ' totp val ' . $token . ' 2m', '', FALSE, FALSE); |
|
113 |
|
if ($r['ok'] != 1) { |
|
114 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
115 |
|
exit(1); |
|
116 |
|
} |
|
117 |
|
if (!strstr($r['data'], 'Success!')) { |
|
118 |
|
rg_log('data: ' . $r['data']); |
108 |
119 |
rg_log('Cannot validate ip!'); |
rg_log('Cannot validate ip!'); |
109 |
120 |
exit(1); |
exit(1); |
110 |
121 |
} |
} |
111 |
|
$t = explode('valid till ', $r); |
|
|
122 |
|
$t = explode('valid till ', $r['data']); |
112 |
123 |
$t = explode(' (', $t[1]); |
$t = explode(' (', $t[1]); |
113 |
124 |
$exp = trim($t[0]); |
$exp = trim($t[0]); |
114 |
125 |
rg_log('exp=' . $exp); |
rg_log('exp=' . $exp); |
115 |
126 |
|
|
116 |
127 |
rg_log(''); |
rg_log(''); |
117 |
128 |
rg_log('Reuse of the token must be forbidden (device)'); |
rg_log('Reuse of the token must be forbidden (device)'); |
118 |
|
$r = shell_exec($cmd . ' totp val ' . $token . ' 2m'); |
|
119 |
|
if (!strstr($r, 'cannot reuse')) { |
|
120 |
|
rg_log('r=' . $r); |
|
|
129 |
|
$r = rg_exec($cmd . ' totp val ' . $token . ' 2m', '', FALSE, FALSE); |
|
130 |
|
if ($r['ok'] != 1) { |
|
131 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
132 |
|
exit(1); |
|
133 |
|
} |
|
134 |
|
if (!strstr($r['stderr'], 'cannot reuse')) { |
|
135 |
|
rg_log('stderr: ' . $r['data']); |
121 |
136 |
rg_log('we get no error on token reuse!'); |
rg_log('we get no error on token reuse!'); |
122 |
137 |
exit(1); |
exit(1); |
123 |
138 |
} |
} |
|
... |
... |
if (!strstr($r, 'cannot reuse')) { |
125 |
140 |
|
|
126 |
141 |
rg_log(''); |
rg_log(''); |
127 |
142 |
rg_log('Testing \'list-val\' command'); |
rg_log('Testing \'list-val\' command'); |
128 |
|
$r = shell_exec($cmd . ' totp list-val'); |
|
129 |
|
if (!strstr($r, $exp)) { |
|
130 |
|
rg_log('r=' . $r); |
|
|
143 |
|
$r = rg_exec($cmd . ' totp list-val', '', FALSE, FALSE); |
|
144 |
|
if ($r['ok'] != 1) { |
|
145 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
146 |
|
exit(1); |
|
147 |
|
} |
|
148 |
|
if (!strstr($r['data'], $exp)) { |
|
149 |
|
rg_log('data: ' . $r['data']); |
131 |
150 |
rg_log('Invalid output for list-val!'); |
rg_log('Invalid output for list-val!'); |
132 |
151 |
exit(1); |
exit(1); |
133 |
152 |
} |
} |
|
... |
... |
rg_log(''); |
137 |
156 |
rg_log('Testing \'inval\' command - wrong ip'); |
rg_log('Testing \'inval\' command - wrong ip'); |
138 |
157 |
$tc = intval(time() / 30) + 1; // we try one in the future |
$tc = intval(time() / 30) + 1; // we try one in the future |
139 |
158 |
$token = rg_totp_compute($key, $tc, 6); |
$token = rg_totp_compute($key, $tc, 6); |
140 |
|
$r = shell_exec($cmd . ' totp inval 1.1.1.1'); |
|
141 |
|
if (!strstr($r, 'ip not found')) { |
|
142 |
|
rg_log('r=' . $r); |
|
|
159 |
|
$r = rg_exec($cmd . ' totp inval 1.1.1.1', '', FALSE, FALSE); |
|
160 |
|
if ($r['ok'] != 1) { |
|
161 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
162 |
|
exit(1); |
|
163 |
|
} |
|
164 |
|
if (!strstr($r['stderr'], 'ip not found')) { |
|
165 |
|
rg_log('stderr: ' . $r['stderr']); |
143 |
166 |
rg_log('Cannot invalidate ip!'); |
rg_log('Cannot invalidate ip!'); |
144 |
167 |
exit(1); |
exit(1); |
145 |
168 |
} |
} |
|
... |
... |
rg_log(''); |
149 |
172 |
rg_log('Testing \'inval\' command - all'); |
rg_log('Testing \'inval\' command - all'); |
150 |
173 |
$tc = intval(time() / 30) + 1; // we try one in the future |
$tc = intval(time() / 30) + 1; // we try one in the future |
151 |
174 |
$token = rg_totp_compute($key, $tc, 6); |
$token = rg_totp_compute($key, $tc, 6); |
152 |
|
$r = shell_exec($cmd . ' totp inval all'); |
|
153 |
|
if (!strstr($r, 'Success!')) { |
|
154 |
|
rg_log('r=' . $r); |
|
|
175 |
|
$r = rg_exec($cmd . ' totp inval all', '', FALSE, FALSE); |
|
176 |
|
if ($r['ok'] != 1) { |
|
177 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
178 |
|
exit(1); |
|
179 |
|
} |
|
180 |
|
if (!strstr($r['data'], 'Success!')) { |
|
181 |
|
rg_log('data: ' . $r['data']); |
155 |
182 |
rg_log('Cannot invalidate all!'); |
rg_log('Cannot invalidate all!'); |
156 |
183 |
exit(1); |
exit(1); |
157 |
184 |
} |
} |
|
... |
... |
rg_log('Testing \'remove-device\''); |
162 |
189 |
$tc = intval(time() / 30) + 2; |
$tc = intval(time() / 30) + 2; |
163 |
190 |
$token = rg_totp_compute($key, $tc, 6); |
$token = rg_totp_compute($key, $tc, 6); |
164 |
191 |
$_cmd = $cmd . ' totp remove-device ' . $token; |
$_cmd = $cmd . ' totp remove-device ' . $token; |
165 |
|
rg_log('Sending cmd ' . $_cmd); |
|
166 |
|
$r = shell_exec($_cmd); |
|
167 |
|
if (!strstr($r, 'Success!')) { |
|
168 |
|
rg_log('r=' . $r); |
|
|
192 |
|
$r = rg_exec($_cmd, '', FALSE, FALSE); |
|
193 |
|
if ($r['ok'] != 1) { |
|
194 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
195 |
|
exit(1); |
|
196 |
|
} |
|
197 |
|
if (!strstr($r['data'], 'Success!')) { |
|
198 |
|
rg_log('data: ' . $r['data']); |
169 |
199 |
rg_log('Cannot remove device!'); |
rg_log('Cannot remove device!'); |
170 |
200 |
exit(1); |
exit(1); |
171 |
201 |
} |
} |
|
... |
... |
rg_log('Testing \'unenroll\''); |
188 |
218 |
$token = array_pop($sc); |
$token = array_pop($sc); |
189 |
219 |
$token = ltrim($token, '0'); |
$token = ltrim($token, '0'); |
190 |
220 |
$_cmd = $cmd . ' totp unenroll ' . $token; |
$_cmd = $cmd . ' totp unenroll ' . $token; |
191 |
|
rg_log('Sending cmd ' . $_cmd); |
|
192 |
|
$r = shell_exec($_cmd); |
|
193 |
|
if (!strstr($r, 'You are now unenrolled')) { |
|
194 |
|
rg_log('r=' . $r); |
|
|
221 |
|
$r = rg_exec($_cmd, '', FALSE, FALSE); |
|
222 |
|
if ($r['ok'] != 1) { |
|
223 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
224 |
|
exit(1); |
|
225 |
|
} |
|
226 |
|
if (!strstr($r['data'], 'You are now unenrolled')) { |
|
227 |
|
rg_log('data: ' . $r['data']); |
195 |
228 |
rg_log('Cannot unenroll!'); |
rg_log('Cannot unenroll!'); |
196 |
229 |
exit(1); |
exit(1); |
197 |
230 |
} |
} |
|
... |
... |
if (!strstr($r, 'You are now unenrolled')) { |
199 |
232 |
rg_log(''); |
rg_log(''); |
200 |
233 |
rg_log('After enroll we should not be able to use the scratch codes'); |
rg_log('After enroll we should not be able to use the scratch codes'); |
201 |
234 |
$token = array_pop($sc); |
$token = array_pop($sc); |
202 |
|
$r = shell_exec($cmd . ' totp val ' . $token . ' 2m'); |
|
203 |
|
if (strstr($r, 'Success!')) { |
|
204 |
|
rg_log('r=' . $r); |
|
|
235 |
|
$r = rg_exec($cmd . ' totp val ' . $token . ' 2m', '', FALSE, FALSE); |
|
236 |
|
if ($r['ok'] != 1) { |
|
237 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
238 |
|
exit(1); |
|
239 |
|
} |
|
240 |
|
if (strstr($r['data'], 'Success!')) { |
|
241 |
|
rg_log('data: ' . $r['data']); |
205 |
242 |
rg_log('Seems we are able to use scratch codes after unenroll!'); |
rg_log('Seems we are able to use scratch codes after unenroll!'); |
206 |
243 |
exit(1); |
exit(1); |
207 |
244 |
} |
} |
|
... |
... |
rg_log(''); |
214 |
251 |
rg_log('sc: testing \'val\' cmd...'); |
rg_log('sc: testing \'val\' cmd...'); |
215 |
252 |
$token = array_pop($sc); |
$token = array_pop($sc); |
216 |
253 |
$_cmd = $cmd . ' totp val ' . $token . ' 2m'; |
$_cmd = $cmd . ' totp val ' . $token . ' 2m'; |
217 |
|
rg_log('Sending cmd ' . $_cmd); |
|
218 |
|
$r = shell_exec($_cmd); |
|
219 |
|
if (!strstr($r, 'Success!')) { |
|
220 |
|
rg_log('r=' . $r); |
|
|
254 |
|
$r = rg_exec($_cmd, '', FALSE, FALSE); |
|
255 |
|
if ($r['ok'] != 1) { |
|
256 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
257 |
|
exit(1); |
|
258 |
|
} |
|
259 |
|
if (!strstr($r['data'], 'Success!')) { |
|
260 |
|
rg_log('data: ' . $r['data']); |
221 |
261 |
rg_log('Cannot validate ip!'); |
rg_log('Cannot validate ip!'); |
222 |
262 |
exit(1); |
exit(1); |
223 |
263 |
} |
} |
|
... |
... |
if (!strstr($r, 'Success!')) { |
226 |
266 |
rg_log(''); |
rg_log(''); |
227 |
267 |
rg_log('Reuse of the scratch code must be forbidden (sc)'); |
rg_log('Reuse of the scratch code must be forbidden (sc)'); |
228 |
268 |
$_cmd = $cmd . ' totp val ' . $token . ' 2m'; |
$_cmd = $cmd . ' totp val ' . $token . ' 2m'; |
229 |
|
rg_log('Sending cmd ' . $_cmd); |
|
230 |
|
$r = shell_exec($_cmd); |
|
231 |
|
if (!strstr($r, 'invalid token')) { |
|
232 |
|
rg_log('r=' . $r); |
|
|
269 |
|
$r = rg_exec($_cmd, '', FALSE, FALSE); |
|
270 |
|
if ($r['ok'] != 1) { |
|
271 |
|
rg_log_ml('error: ' . $r['stderr']); |
|
272 |
|
exit(1); |
|
273 |
|
} |
|
274 |
|
if (!strstr($r['stderr'], 'invalid token')) { |
|
275 |
|
rg_log('stderr: ' . $r['stderr']); |
233 |
276 |
rg_log('we get no error on token reuse!'); |
rg_log('we get no error on token reuse!'); |
234 |
277 |
exit(1); |
exit(1); |
235 |
278 |
} |
} |