| @@ -5,11 +5,12 @@ | ||
| 5 | 5 | class WPRAccount { |
| 6 | 6 | public $settings; |
| 7 | 7 | public $public; |
| 8 | 8 | public $secret; |
| 9 | + public $sig_match; | |
| 9 | 10 | public static $api_public_key = 'bvApiPublic'; |
| 10 | 11 | public static $accounts_list = 'bvAccountsList'; |
| 11 | - | |
| 12 | + | |
| 12 | 13 | public function __construct($settings, $public, $secret) { |
| 13 | 14 | $this->settings = $settings; |
| 14 | 15 | $this->public = $public; |
| 15 | 16 | $this->secret = $secret; |
| @@ -158,10 +159,36 @@ | ||
| 158 | 159 | } |
| 159 | 160 | |
| 160 | 161 | public function info() { |
| 161 | 162 | return array( |
| 162 | - "public" => substr($this->public, 0, 6) | |
| 163 | + "public" => substr($this->public, 0, 6), | |
| 164 | + "sigmatch" => substr($this->sig_match, 0, 6) | |
| 163 | 165 | ); |
| 166 | + } | |
| 167 | + | |
| 168 | + public static function getSigMatch($request, $secret) { | |
| 169 | + $method = $request->method; | |
| 170 | + $time = $request->time; | |
| 171 | + $version = $request->version; | |
| 172 | + if ($request->is_sha1) { | |
| 173 | + $sig_match = sha1($method.$secret.$time.$version); | |
| 174 | + } else { | |
| 175 | + $sig_match = md5($method.$secret.$time.$version); | |
| 176 | + } | |
| 177 | + return $sig_match; | |
| 178 | + } | |
| 179 | + | |
| 180 | + public function authenticate($request) { | |
| 181 | + $time = $request->time; | |
| 182 | + if ($time < intval($this->settings->getOption('bvLastRecvTime')) - 300) { | |
| 183 | + return false; | |
| 184 | + } | |
| 185 | + $this->sig_match = self::getSigMatch($request, $this->secret); | |
| 186 | + if ($this->sig_match !== $request->sig) { | |
| 187 | + return false; | |
| 188 | + } | |
| 189 | + $this->settings->updateOption('bvLastRecvTime', $time); | |
| 190 | + return 1; | |
| 164 | 191 | } |
| 165 | 192 | |
| 166 | 193 | public function updateInfo($info) { |
| 167 | 194 | $accounts = self::allAccounts($this->settings); |