Rev 8 | Rev 10 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8 | Rev 9 | ||
---|---|---|---|
Line 56... | Line 56... | ||
56 | private static function getOpenTransFileName($ip_target, $random) { |
56 | private static function getOpenTransFileName($ip_target, $random) { |
57 | $dir = defined('VTS_CS_OPEN_TRANS_DIR') ? VTS_CS_OPEN_TRANS_DIR : __DIR__.'/cache'; |
57 | $dir = defined('VTS_CS_OPEN_TRANS_DIR') ? VTS_CS_OPEN_TRANS_DIR : __DIR__.'/cache'; |
58 | if ($dir == '') $dir = '.'; /** @phpstan-ignore-line */ |
58 | if ($dir == '') $dir = '.'; /** @phpstan-ignore-line */ |
59 | 59 | ||
60 | // First, delete challenges which were never completed |
60 | // First, delete challenges which were never completed |
61 | $files = glob($dir.'/*.tmp'); |
61 | $files = glob($dir.'/vts_client_challenge_*.tmp'); |
62 | $expire = strtotime('-3 DAYS'); |
62 | $expire = strtotime('-3 DAYS'); |
63 | foreach ($files as $file) { |
63 | foreach ($files as $file) { |
64 | if (!is_file($file)) continue; |
64 | if (!is_file($file)) continue; |
65 | if (filemtime($file) > $expire) continue; |
65 | if (filemtime($file) > $expire) continue; |
66 | @unlink($file); |
66 | @unlink($file); |
67 | } |
67 | } |
68 | 68 | ||
69 | return $dir.'/'.self::sha3_512($ip_target.'/'.$random).'.tmp'; |
69 | return $dir.'/vts_client_challenge_'.self::sha3_512($ip_target.'/'.$random).'.tmp'; |
70 | } |
70 | } |
71 | 71 | ||
72 | public static function checkValidation($client_response, $max_time=10, $server_secret) { |
72 | public static function checkValidation($client_response, $max_time=10, $server_secret) { |
73 | list($starttime, $ip_target, $challenge, $answer, $challenge_integrity) = $client_response; |
73 | list($starttime, $ip_target, $challenge, $answer, $challenge_integrity) = $client_response; |
74 | $open_trans_file = self::getOpenTransFileName($ip_target, $answer); |
74 | $open_trans_file = self::getOpenTransFileName($ip_target, $answer); |
Line 82... | Line 82... | ||
82 | } else if ($challenge !== self::sha3_512($starttime.'/'.$ip_target.'/'.$answer)) { |
82 | } else if ($challenge !== self::sha3_512($starttime.'/'.$ip_target.'/'.$answer)) { |
83 | throw new \Exception('Wrong answer'); |
83 | throw new \Exception('Wrong answer'); |
84 | } else if (!file_exists($open_trans_file)) { |
84 | } else if (!file_exists($open_trans_file)) { |
85 | throw new \Exception('Challenge submitted twice or transaction missing'); |
85 | throw new \Exception('Challenge submitted twice or transaction missing'); |
86 | } else { |
86 | } else { |
87 | unlink($open_trans_file); |
87 | @unlink($open_trans_file); |
88 | return true; |
88 | return true; |
89 | } |
89 | } |
90 | } |
90 | } |
91 | 91 | ||
92 | public static function createChallenge($complexity=50000, $server_secret) { |
92 | public static function createChallenge($complexity=50000, $server_secret) { |