PluginProbe
The WP Remote WordPress Plugin / 6.36
The WP Remote WordPress Plugin v6.36
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
← All changes | callback/request.php +47 -32 5.226.36 View file →
@@ -11,8 +11,9 @@
11 11 public $is_debug;
12 12 public $account;
13 13 public $settings;
14 14 public $sig;
15 + public $sighshalgo;
15 16 public $time;
16 17 public $version;
17 18 public $is_sha1;
18 19 public $bvb64stream;
@@ -20,9 +21,15 @@
20 21 public $checksum;
21 22 public $error = array();
22 23 public $pubkey_name;
23 24 public $bvprmsmac;
25 + public $bvboundry;
24 26
27 + private static $SIG_HASH_ALGO_MAP = array(
28 + '1' => OPENSSL_ALGO_SHA1,
29 + '7' => OPENSSL_ALGO_SHA256
30 + );
31 +
25 32 public function __construct($account, $in_params, $settings) {
26 33 $this->params = array();
27 34 $this->account = $account;
28 35 $this->settings = $settings;
@@ -31,8 +38,9 @@
31 38 $this->is_afterload = array_key_exists('afterload', $in_params);
32 39 $this->is_admin_ajax = array_key_exists('adajx', $in_params);
33 40 $this->is_debug = array_key_exists('bvdbg', $in_params);
34 41 $this->sig = $in_params['sig'];
42 + $this->sighshalgo = !empty($in_params['sighshalgo']) ? $in_params['sighshalgo'] : '1';
35 43 $this->time = intval($in_params['bvTime']);
36 44 $this->version = $in_params['bvVersion'];
37 45 $this->is_sha1 = array_key_exists('sha1', $in_params);
38 46 $this->bvb64stream = isset($in_params['bvb64stream']);
@@ -40,8 +48,9 @@
40 48 $this->checksum = array_key_exists('checksum', $in_params) ? $in_params['checksum'] : false;
41 49 $this->pubkey_name = !empty($in_params['pubkeyname']) ?
42 50 WPRAccount::sanitizeKey($in_params['pubkeyname']) : 'm_public';
43 51 $this->bvprmsmac = !empty($in_params['bvprmsmac']) ? WPRAccount::sanitizeKey($in_params['bvprmsmac']) : "";
52 + $this->bvboundry = !empty($in_params['bvboundry']) ? $in_params['bvboundry'] : "";
44 53 }
45 54
46 55 public function isAPICall() {
47 56 return array_key_exists('apicall', $this->params);
@@ -46,38 +55,25 @@
46 55 public function isAPICall() {
47 56 return array_key_exists('apicall', $this->params);
48 57 }
49 58
50 - public function curlRequest($url, $body) {
51 - $ch = curl_init($url);
52 - curl_setopt($ch, CURLOPT_POST, 1);
53 - curl_setopt($ch, CURLOPT_TIMEOUT, 15);
54 - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
55 - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
56 - return curl_exec($ch);
57 - }
59 + public function http_request($url, $body) {
60 + $body = http_build_query($body);
61 + $response = wp_remote_post($url, array(
62 + 'body' => $body,
63 + 'timeout' => 15,
64 + 'headers' => array(
65 + 'Content-Type' => 'application/x-www-form-urlencoded',
66 + ),
67 + ));
58 68
59 - public function fileGetContentRequest($url, $body) {
60 - $options = array(
61 - 'http' => array(
62 - 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
63 - 'method' => 'POST',
64 - 'content' => http_build_query($body)
65 - )
66 - );
69 + if (is_wp_error($response)) {
70 + return false;
71 + }
67 72
68 - $context = stream_context_create($options);
69 - return file_get_contents($url, false, $context);
73 + return wp_remote_retrieve_body($response);
70 74 }
71 75
72 - public function http_request($url, $body) {
73 - if (in_array('curl', get_loaded_extensions())) {
74 - return $this->curlRequest($url, $body);
75 - } else {
76 - return $this->fileGetContentRequest($url, $body);
77 - }
78 - }
79 -
80 76 public function get_params_via_api($params_key, $apiurl) {
81 77 $res = $this->http_request($apiurl, array('bvkey' => $params_key));
82 78
83 79 if ($res === FALSE) {
@@ -133,9 +129,13 @@
133 129 }
134 130 }
135 131
136 132 if (array_key_exists('bvprms', $in_params) && isset($in_params['bvprms'])) {
137 - $calculated_mac = hash_hmac('SHA1', $in_params['bvprms'], $this->account->secret);
133 + if (!empty($in_params['bvprmshshalgo']) && $in_params['bvprmshshalgo'] === 'sha256') {
134 + $calculated_mac = hash_hmac('SHA256', $in_params['bvprms'], $this->account->secret);
135 + } else {
136 + $calculated_mac = hash_hmac('SHA1', $in_params['bvprms'], $this->account->secret);
137 + }
138 138
139 139 if ($this->compare_mac($this->bvprmsmac, $calculated_mac) === true) {
140 140
141 141 if (array_key_exists('b64', $in_params)) {
@@ -177,8 +177,9 @@
177 177 }
178 178
179 179 if (array_key_exists('memset', $in_params)) {
180 180 $val = intval($in_params['memset']);
181 + // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged -- Required for memory limit adjustment
181 182 @ini_set('memory_limit', $val.'M');
182 183 }
183 184
184 185 return $params;
@@ -224,9 +225,9 @@
224 225 return false;
225 226 }
226 227
227 228 $data = $this->method.$this->account->secret.$this->time.$this->version.$this->bvprmsmac;
228 - if (!$this->verify($data, base64_decode($this->sig))) {
229 + if (!$this->verify($data, base64_decode($this->sig), $this->sighshalgo)) {
229 230 return false;
230 231 }
231 232 $this->settings->updateOption('bvLastRecvTime', $this->time);
232 233
@@ -232,20 +233,28 @@
232 233
233 234 return 1;
234 235 }
235 236
236 - public function verify($data, $sig) {
237 + public function verify($data, $sig, $sighshalgo) {
237 238 if (!function_exists('openssl_verify') || !function_exists('openssl_pkey_get_public')) {
238 239 $this->error["message"] = "OPENSSL_FUNCS_NOT_FOUND";
239 240 return false;
240 241 }
241 242
242 - $key_file = dirname( __FILE__ ) . '/../public_keys/' . $this->pubkey_name . '.pub';
243 + $openssl_algo = array_key_exists($sighshalgo, self::$SIG_HASH_ALGO_MAP) ? self::$SIG_HASH_ALGO_MAP[$sighshalgo] : null;
244 + if ($openssl_algo === null) {
245 + $this->error["message"] = "UNSUPPORTED_HASH_ALGORITHM: " . $sighshalgo;
246 + return false;
247 + }
248 +
249 + $key_file = dirname( __DIR__ ) . '/public_keys/' . $this->pubkey_name . '.pub';
243 250 if (!file_exists($key_file)) {
244 251 $this->error["message"] = "PUBLIC_KEY_NOT_FOUND";
245 252 return false;
246 253 }
247 - $public_key_str = file_get_contents($key_file);
254 +
255 + $public_key_str = WPRWPFileSystem::getInstance()->getContents($key_file);
256 +
248 257 $public_key = openssl_pkey_get_public($public_key_str);
249 258 if (!$public_key) {
250 259 $this->error["message"] = "UNABLE_TO_LOAD_PUBLIC_KEY";
251 260 return false;
@@ -250,9 +259,9 @@
250 259 $this->error["message"] = "UNABLE_TO_LOAD_PUBLIC_KEY";
251 260 return false;
252 261 }
253 262
254 - $verify = openssl_verify($data, $sig, $public_key);
263 + $verify = openssl_verify($data, $sig, $public_key, $openssl_algo);
255 264 if ($verify === 1) {
256 265 return true;
257 266 } elseif ($verify === 0) {
258 267 $this->error["message"] = "INCORRECT_SIGNATURE";
@@ -276,8 +285,9 @@
276 285
277 286 public function authFailedResp() {
278 287 $api_public_key = WPRAccount::getApiPublicKey($this->settings);
279 288 $default_secret = WPRRecover::getDefaultSecret($this->settings);
289 + $default_account_pubkey = WPRAccount::getDefaultPublicKey();
280 290 $bvinfo = new WPRInfo($this->settings);
281 291 $resp = array(
282 292 "request_info" => $this->info(),
283 293 "bvinfo" => $bvinfo->info(),
@@ -282,10 +292,15 @@
282 292 "request_info" => $this->info(),
283 293 "bvinfo" => $bvinfo->info(),
284 294 "statusmsg" => "FAILED_AUTH",
285 295 "api_pubkey" => substr($api_public_key, 0, 8),
296 + "def_key_status" => WPRRecover::getSecretStatus($this->settings),
286 297 "def_sigmatch" => substr(hash('sha1', $this->method.$default_secret.$this->time.$this->version), 0, 8)
287 298 );
299 +
300 + if (is_string($default_account_pubkey) && strlen($default_account_pubkey) >= 32) {
301 + $resp["default_account_pubkey"] = substr($default_account_pubkey, 0, 8);
302 + }
288 303
289 304 if ($this->account) {
290 305 $resp["account_info"] = $this->account->info();
291 306 $resp["sigmatch"] = substr(hash('sha1', $this->method.$this->account->secret.$this->time.$this->version), 0, 6);