PluginProbe
The WP Remote WordPress Plugin / 4.81
The WP Remote WordPress Plugin v4.81
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 | account.php +32 -17 6.484.81 View file →
@@ -5,12 +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 - private static $default_credential = array();
12 -
12 +
13 13 public function __construct($settings, $public, $secret) {
14 14 $this->settings = $settings;
15 15 $this->public = $public;
16 16 $this->secret = $secret;
@@ -21,15 +21,9 @@
21 21 if (array_key_exists($public, $accounts) && isset($accounts[$public]['secret'])) {
22 22 $secret = $accounts[$public]['secret'];
23 23 }
24 24 if (empty($secret) || (strlen($secret) < 32)) {
25 - if (!empty(self::$default_credential) && array_key_exists($public, self::$default_credential)
26 - && strlen($public) >= 32) {
27 - $secret = self::$default_credential[$public];
28 - self::addAccount($settings, $public, $secret);
29 - } else {
30 - return null;
31 - }
25 + return null;
32 26 }
33 27 return new self($settings, $public, $secret);
34 28 }
35 29
@@ -42,9 +36,9 @@
42 36
43 37 $str = "";
44 38 $size = strlen($chars);
45 39 for( $i = 0; $i < $length; $i++ ) {
46 - $str .= $chars[rand(0, $size - 1)]; // phpcs:ignore WordPress.WP.AlternativeFunctions.rand_rand
40 + $str .= $chars[rand(0, $size - 1)];
47 41 }
48 42 return $str;
49 43 }
50 44
@@ -60,12 +54,8 @@
60 54 public static function updateApiPublicKey($settings, $pubkey) {
61 55 $settings->updateOption(self::$api_public_key, $pubkey);
62 56 }
63 57
64 - public static function getDefaultPublicKey() {
65 - return WPRHelper::arrayKeyFirst(self::$default_credential);
66 - }
67 -
68 58 public static function getApiPublicKey($settings) {
69 59 return $settings->getOption(self::$api_public_key);
70 60 }
71 61
@@ -119,10 +109,9 @@
119 109 public static function accountsByPattern($settings, $search_key, $search_pattern) {
120 110 $accounts = self::allAccounts($settings);
121 111 $accounts_by_pattern = array();
122 112 foreach ($accounts as $pubkey => $value) {
123 - if (array_key_exists($search_key, $value) &&
124 - WPRHelper::safePregMatch($search_pattern, $value[$search_key]) == 1) {
113 + if (array_key_exists($search_key, $value) && preg_match($search_pattern, $value[$search_key]) == 1) {
125 114 $accounts_by_pattern[$pubkey] = $value;
126 115 }
127 116 }
128 117 return $accounts_by_pattern;
@@ -169,10 +158,36 @@
169 158 }
170 159
171 160 public function info() {
172 161 return array(
173 - "public" => substr($this->public, 0, 6)
162 + "public" => substr($this->public, 0, 6),
163 + "sigmatch" => substr($this->sig_match, 0, 6)
174 164 );
165 + }
166 +
167 + public static function getSigMatch($request, $secret) {
168 + $method = $request->method;
169 + $time = $request->time;
170 + $version = $request->version;
171 + if ($request->is_sha1) {
172 + $sig_match = sha1($method.$secret.$time.$version);
173 + } else {
174 + $sig_match = md5($method.$secret.$time.$version);
175 + }
176 + return $sig_match;
177 + }
178 +
179 + public function authenticate($request) {
180 + $time = $request->time;
181 + if ($time < intval($this->settings->getOption('bvLastRecvTime')) - 300) {
182 + return false;
183 + }
184 + $this->sig_match = self::getSigMatch($request, $this->secret);
185 + if ($this->sig_match !== $request->sig) {
186 + return false;
187 + }
188 + $this->settings->updateOption('bvLastRecvTime', $time);
189 + return 1;
175 190 }
176 191
177 192 public function updateInfo($info) {
178 193 $accounts = self::allAccounts($this->settings);