froger-me / wp-remote-users-sync

Synchronise users across WordPress websites
GNU General Public License v3.0
71 stars 34 forks source link

Payload error - Syntax error #25

Closed benjaminisawolfe closed 3 years ago

benjaminisawolfe commented 3 years ago

Hello!

I'm trying to get WP RUS working between two pre-existing sites with plugins and users, etc.

I've checked that the URLs are correct and match the WordPress and Site address in the General settings.

I am getting the following error:

Error contacting the remote site: Payload error - Syntax error

Here's the log from https://prfnul.wpengine.com/ :

2020-12-22 20:09:25 - Alert - Failed to create token - invalid payload
2020-12-22 20:09:26 - Alert - Unauthorized access (invalid token)
2020-12-22 20:09:44 - Alert - Failed to create token - invalid payload
2020-12-22 20:09:45 - Alert - Failed to create token - invalid payload
2020-12-22 20:09:46 - Alert - Unauthorized access (invalid token)
2020-12-22 20:09:56 - Alert - Failed to create token - invalid payload
2020-12-22 20:09:56 - Alert - Failed to create token - invalid payload
2020-12-22 20:09:57 - Alert - Unauthorized access (invalid token)
2020-12-22 20:11:25 - Info - Renewing token for https://prfnul.wpengine.com/
2020-12-22 20:11:26 - Warning - Failed to renew token for https://prfnul.wpengine.com/ - retrying...
2020-12-22 20:11:29 - Alert - Failed to renew token for https://prfnul.wpengine.com/
2020-12-22 20:11:29 - Info - Response data received from the remote site:
        Array
(
    [0] => Array
        (
            [headers] => Array
                (
                    [server] => nginx
                    [date] => Tue, 22 Dec 2020 20:11:29 GMT
                    [content-type] => text/html; charset=UTF-8
                    [content-length] => 0
                    [set-cookie] => PHPSESSID=c284a131417da4d609f2d842e828b856; path=/
                    [expires] => Thu, 19 Nov 1981 08:52:00 GMT
                    [cache-control] => no-store, no-cache, must-revalidate
                    [pragma] => no-cache
                    [x-newrelic-app-data] => PxQGVFBVCgoFR1VSDwECVVYDAhFORDQHUjZKA1ZLVVFHDFYPbU5mEA1qGAgIB11LHhQJEhUdB0hUAQYDUkpRTAFXDlYIFBkDH0cKA1IDV1MGBwVQUAENAVNSQ05RUFsVAWw=
                    [x-powered-by] => WP Engine
                )

            [response_code] => 200
            [response_message] => OK
            [body] => 
        )

)

2020-12-22 20:11:29 - Alert - Failed to renew token for https://prfnul.wpengine.com/
2020-12-22 20:11:29 - Info - A WordPress error was triggered:
        Array
(
    [0] => http_request_failed cURL error 28: Operation timed out after 1001 milliseconds with 0 bytes received
)

2020-12-22 20:11:31 - Alert - Error contacting the remote site: Payload error - Syntax error
2020-12-22 20:11:31 - Info - Response data received from the remote site:
        Array
(
    [0] => Array
        (
            [headers] => Array
                (
                    [server] => nginx
                    [date] => Tue, 22 Dec 2020 20:11:31 GMT
                    [content-type] => text/html; charset=UTF-8
                    [content-length] => 0
                    [set-cookie] => PHPSESSID=07d835ecf606da1425d366a486c79338; path=/
                    [expires] => Thu, 19 Nov 1981 08:52:00 GMT
                    [cache-control] => no-store, no-cache, must-revalidate
                    [pragma] => no-cache
                    [x-newrelic-app-data] => PxQGVFBVCgoFR1VSDwECVVYDAhFORDQHUjZKA1ZLVVFHDFYPbU5mEA1qGAgIB11LHhQJEhUdB0hUAQYDUkpSTAlSC1UMFBkDH0cLWAJVA1JWUlQCVwIOCwJQQ05RUFsVAWw=
                    [x-powered-by] => WP Engine
                )

            [response_code] => 200
            [response_message] => OK
            [body] => 
        )

)

It's running the CityGov theme, and the following plugins:

3D FlipBook - Lite Edition bbPress Better Search Replace Booked BuddyPress BuddyPress Simple Terms And Conditions Buttons Shortcode And Widgets CB Change Mail Sender Chatra Live Chat, Chatbots and Cart Saver Classic Editor Colorlib Login Customizer Contact Form 7 Essential Grid Flow-Flow Lite Google Analytics for WordPress by MonsterInsights HTML5 jQuery Audio Player Jetpack LH Buddypress Export Xprofile Data Loco Translate MC4WP Peter's Login Redirect Portfolio Filter Gallery Post Expirator Remove Dashboard Access Restrict User Access Shortcodes Ultimate Slider Revolution SM Replace Howdy Social Icons Widget & Block by WPZOOM Stream String Locator The Events Calendar ThemeREX Donations ThemeREX Updater ThemeREX Utilities Unbounce Landing Pages Woo Custom Emails Per Product WooCommerce WooCommerce Shipping & Tax WooCommerce Stripe Gateway WordPress Importer WordPress Users & WooCommerce Customers Import Export(BASIC) WP Cloudy WP GDPR Compliance WP Remote Users Sync WP Voting Contest WPBakery Page Builder WPZOOM Instagram Widget Yoast Duplicate Post

And here is the log from https://prfnul.wpengine.com/:

2020-12-22 20:09:24 - Warning - Failed to renew token for http://prfntdev.wpengine.com/ - retrying...
2020-12-22 20:09:25 - Alert - Failed to renew token for http://prfntdev.wpengine.com/
2020-12-22 20:09:25 - Info - Response data received from the remote site:
        Array
(
    [0] => Array
        (
            [headers] => Array
                (
                    [server] => nginx
                    [date] => Tue, 22 Dec 2020 20:09:25 GMT
                    [content-type] => text/html; charset=UTF-8
                    [content-length] => 0
                    [x-newrelic-app-data] => PxQGVFBVCgoFR1JbBgQAX1YCAhFORDQHUjZKA1ZLVVFHDFYPbU5mEA1qGAgIB11LHhQJEhUdB0hUAQYDUkpTTAhXD1IJFBkDH0cNBAZZCwBVDw5QV1sJClVXQ05RUFsVAWw=
                    [x-powered-by] => WP Engine
                )

            [response_code] => 200
            [response_message] => OK
            [body] => 
        )

)

2020-12-22 20:09:25 - Alert - Failed to renew token for http://prfntdev.wpengine.com/
2020-12-22 20:09:25 - Info - A WordPress error was triggered:
        Array
(
    [0] => http_request_failed cURL error 28: Operation timed out after 1000 milliseconds with 0 bytes received
)

2020-12-22 20:09:26 - Alert - Error contacting the remote site: Payload error - Syntax error
2020-12-22 20:09:26 - Info - Response data received from the remote site:
        Array
(
    [0] => Array
        (
            [headers] => Array
                (
                    [server] => nginx
                    [date] => Tue, 22 Dec 2020 20:09:26 GMT
                    [content-type] => text/html; charset=UTF-8
                    [content-length] => 0
                    [x-newrelic-app-data] => PxQGVFBVCgoFR1JbBgQAX1YCAhFORDQHUjZKA1ZLVVFHDFYPbU5mEA1qGAgIB11LHhQJEhUdB0hUAQYDUkpTTAlTCFIPFBkDH0cBUlIEAlIFV1RXVVJaBgAAQ05RUFsVAWw=
                    [x-powered-by] => WP Engine
                )

            [response_code] => 200
            [response_message] => OK
            [body] => 
        )

)

2020-12-22 20:09:43 - Info - Renewing token for http://prfntdev.wpengine.com/
2020-12-22 20:09:44 - Warning - Failed to renew token for http://prfntdev.wpengine.com/ - retrying...
2020-12-22 20:09:45 - Alert - Failed to renew token for http://prfntdev.wpengine.com/
2020-12-22 20:09:45 - Info - Response data received from the remote site:
        Array
(
    [0] => Array
        (
            [headers] => Array
                (
                    [server] => nginx
                    [date] => Tue, 22 Dec 2020 20:09:45 GMT
                    [content-type] => text/html; charset=UTF-8
                    [content-length] => 0
                    [x-newrelic-app-data] => PxQGVFBVCgoFR1JbBgQAX1YCAhFORDQHUjZKA1ZLVVFHDFYPbU5mEA1qGAgIB11LHhQJEhUdB0hUAQYDUkpTTAhWClALFBkDH0cMUwEDCwdWBg9RVVNaCwVSQ05RUFsVAWw=
                    [x-powered-by] => WP Engine
                )

            [response_code] => 200
            [response_message] => OK
            [body] => 
        )

)

2020-12-22 20:09:45 - Alert - Failed to renew token for http://prfntdev.wpengine.com/
2020-12-22 20:09:45 - Info - A WordPress error was triggered:
        Array
(
    [0] => http_request_failed cURL error 28: Operation timed out after 1001 milliseconds with 0 bytes received
)

2020-12-22 20:09:46 - Alert - Error contacting the remote site: Payload error - Syntax error
2020-12-22 20:09:46 - Info - Response data received from the remote site:
        Array
(
    [0] => Array
        (
            [headers] => Array
                (
                    [server] => nginx
                    [date] => Tue, 22 Dec 2020 20:09:46 GMT
                    [content-type] => text/html; charset=UTF-8
                    [content-length] => 0
                    [x-newrelic-app-data] => PxQGVFBVCgoFR1JbBgQAX1YCAhFORDQHUjZKA1ZLVVFHDFYPbU5mEA1qGAgIB11LHhQJEhUdB0hUAQYDUkpTTAhWDlQJFBkDH0cKWFRTAVpVVQBVVgYMAQYGQ05RUFsVAWw=
                    [x-powered-by] => WP Engine
                )

            [response_code] => 200
            [response_message] => OK
            [body] => 
        )

)

2020-12-22 20:09:54 - Info - Renewing token for http://prfntdev.wpengine.com/
2020-12-22 20:09:55 - Warning - Failed to renew token for http://prfntdev.wpengine.com/ - retrying...
2020-12-22 20:09:56 - Alert - Failed to renew token for http://prfntdev.wpengine.com/
2020-12-22 20:09:56 - Info - Response data received from the remote site:
        Array
(
    [0] => Array
        (
            [headers] => Array
                (
                    [server] => nginx
                    [date] => Tue, 22 Dec 2020 20:09:56 GMT
                    [content-type] => text/html; charset=UTF-8
                    [content-length] => 0
                    [x-newrelic-app-data] => PxQGVFBVCgoFR1JbBgQAX1YCAhFORDQHUjZKA1ZLVVFHDFYPbU5mEA1qGAgIB11LHhQJEhUdB0hUAQYDUkpTTAhbDFIKFBkDH0dbBFAFA1BVDwFXVVVaUlMHQ05RUFsVAWw=
                    [x-powered-by] => WP Engine
                )

            [response_code] => 200
            [response_message] => OK
            [body] => 
        )

)

2020-12-22 20:09:56 - Alert - Failed to renew token for http://prfntdev.wpengine.com/
2020-12-22 20:09:56 - Info - A WordPress error was triggered:
        Array
(
    [0] => http_request_failed cURL error 28: Operation timed out after 1001 milliseconds with 0 bytes received
)

2020-12-22 20:09:57 - Alert - Error contacting the remote site: Payload error - Syntax error
2020-12-22 20:09:57 - Info - Response data received from the remote site:
        Array
(
    [0] => Array
        (
            [headers] => Array
                (
                    [server] => nginx
                    [date] => Tue, 22 Dec 2020 20:09:57 GMT
                    [content-type] => text/html; charset=UTF-8
                    [content-length] => 0
                    [x-newrelic-app-data] => PxQGVFBVCgoFR1JbBgQAX1YCAhFORDQHUjZKA1ZLVVFHDFYPbU5mEA1qGAgIB11LHhQJEhUdB0hUAQYDUkpTTAdaC1oOFBkDH0cJUABTUFtQB1IDB1MKV1UGQ05RUFsVAWw=
                    [x-powered-by] => WP Engine
                )

            [response_code] => 200
            [response_message] => OK
            [body] => 
        )

)

2020-12-22 20:11:29 - Alert - Failed to create token - invalid payload
2020-12-22 20:11:29 - Alert - Failed to create token - invalid payload
2020-12-22 20:11:31 - Alert - Unauthorized access (invalid token)

It's running the CityGov theme, and the following plugins:

Buttons Shortcode And Widgets CB Change Mail Sender Classic Editor Colorlib Login Customizer Contact Form 7 Essential Grid Jetpack Loco Translate MC4WP Post Expirator Remove Dashboard Access Shortcodes Ultimate Slider Revolution Social Icons Widget & Block by WPZOOM Stream ThemeREX Updater ThemeREX Utilities Unbounce Landing Pages User Role Editor WordPress Importer WP GDPR Compliance WPBakery Page Builder Yoast Duplicate Post

Please let me know if you need any more details.

Thank you!

benjaminisawolfe commented 3 years ago

Oh, I should also add that I used passphrases for my encryption and action signature keys -- not sure if spaces and special characters would create an issue.

benjaminisawolfe commented 3 years ago

Here's the PHP error I'm getting on both sites:

Wprus_Api_Abstract->decrypt_data on line 192: Could not decrypt data: invalid bundle., referer: https://prfnul.wpengine.com/wprus/login/

benjaminisawolfe commented 3 years ago

I changed the following lines in the class-wprus-api-abstract.php on both sites to get more info:

    public function decrypt_data( $bundle ) {
        $data    = false;
        $payload = false;

        try {
            $payload = Wprus_Crypto::decrypt(
                $bundle,
                self::$encryption_settings['aes_key'],
                self::$encryption_settings['hmac_key']
            );
        } catch ( Exception $e ) {
            Wprus_Logger::log( 'Could not decrypt data: ' . $e->getMessage() . ' : ' . $bundle, 'alert', 'db_log' );
        }

        if ( $payload ) {
            $data = json_decode( $payload, true );
        } else {
            Wprus_Logger::log( __( 'Could not decrypt data: invalid bundle: ' . $bundle, 'wprus' ) );
        }

        return $data;
    }

When I ran the login test from the prfnul to prfndev, it returned the following error:

Wprus_Api_Abstract->decrypt_data on line 192: Could not decrypt data: invalid bundle: 2XnOYHBkM8xn5g20nFxexwQ7WfzyjFMxnPHDAvqj+AgkZwntcZw7v0oz4MlgEh8g5GyQdpetZIyeI7RGjBKVqPbFo4YQLXZjLVytyFP9gtPcxYeq7pbzqSdVtIkJt_1CkcRpDk6VUcWW6ujL_g4RMTJJ2UhLT+nQT68SJEQuv_mt6vAqImAdKrT0BMo0uFiunl2Cjv_1GPeRtVrg5ZE53g==, referer: https://prfnul.wpengine.com/wprus/login/

I don't know if that helps at all, but figure the more information I can provide, the better.

benjaminisawolfe commented 3 years ago

So, interestingly, I made a test to call your functions and ran them on the "invalid bundle" from my last comment with my keys, and here's what it returned:

'{"ping":1,"direction":"incoming","username":"adminusername","base_url":"https:\/\/prfntdev.wpengine.com"}`

Where adminusername is the account name for the account with _userid 1.

I also ran a json_decode on it, and it returned this:

array (
   'ping' => 1,
   'direction' => 'incoming',
   'username' => 'adminusername',
   'base_url' => 'https://prfntdev.wpengine.com',
)

I did some further testing by adding some more output fields to the error log, like so:

    public function decrypt_data( $bundle ) {
        $data    = false;
        $payload = false;

        try {
            $payload = Wprus_Crypto::decrypt(
                $bundle,
                self::$encryption_settings['aes_key'],
                self::$encryption_settings['hmac_key']
            );
        } catch ( Exception $e ) {
            Wprus_Logger::log( 'Could not decrypt data: ' . $e->getMessage() . ' : ' . $bundle, 'alert', 'db_log' );
        }

        if ( $payload ) {
            $data = json_decode( $payload, true );
        } else {
            Wprus_Logger::log( __( 'Could not decrypt data: invalid bundle: payload=' . $payload . ' -- bundle=' . $bundle . ' -- encryption key=' . self::$encryption_settings['aes_key'] . ' -- hmac key=' . self::$encryption_settings['hmac_key'], 'wprus' ) );
        }

        return $data;
    }

Everything came out fine except for $payload. It came out empty, which makes no sense. If the bundle and keys are present, then payload should be?

Anyhow, that's as far as I've gotten in debugging. Hopefully, it helps!

benjaminisawolfe commented 3 years ago

Ack, how embarrassing. The encryption keys mismatched due to a copy/paste error.

It might be useful to add a more informative error message, because it was not clear at all that this was the problem.

That said, it's a great plugin and thank you for your hard work!