Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. function verify_action( $params ) {
  2. $action = $params[0];
  3. $verify_secret = $params[1];
  4. $state = isset( $params[2] ) ? $params[2] : '';
  5.  
  6. if ( 'authorize' === $action ) {
  7. Jetpack_Options::delete_option( $action );
  8. return $this->error( new Jetpack_Error( 'verify_secrets_expired', 'Verification took too long', 400 ) );
  9. }
  10.  
  11. if ( empty( $verify_secret ) ) {
  12. return $this->error( new Jetpack_Error( 'verify_secret_1_missing', sprintf( 'The required "%s" parameter is missing.', 'secret_1' ), 400 ) );
  13. } else if ( ! is_string( $verify_secret ) ) {
  14. return $this->error( new Jetpack_Error( 'verify_secret_1_malformed', sprintf( 'The required "%s" parameter is malformed.', 'secret_1' ), 400 ) );
  15. }
  16.  
  17. $secrets = Jetpack_Options::get_option( $action );
  18. if ( ! $secrets || is_wp_error( $secrets ) ) {
  19. Jetpack_Options::delete_option( $action );
  20. return $this->error( new Jetpack_Error( 'verify_secrets_missing', 'Verification secrets not found', 400 ) );
  21. }
  22.  
  23. @list( $secret_1, $secret_2, $secret_eol, $user_id ) = explode( ':', $secrets );
  24.  
  25. if ( empty( $secret_1 ) || empty( $secret_2 ) || empty( $secret_eol ) ) {
  26. Jetpack_Options::delete_option( $action );
  27. return $this->error( new Jetpack_Error( 'verify_secrets_incomplete', 'Verification secrets are incomplete', 400 ) );
  28. }
  29.  
  30. if ( $secret_eol < time() ) {
  31. Jetpack_Options::delete_option( $action );
  32. return $this->error( new Jetpack_Error( 'verify_secrets_expired', 'Verification took too long', 400 ) );
  33. }
  34.  
  35. if ( ! hash_equals( $verify_secret, $secret_1 ) ) {
  36. Jetpack_Options::delete_option( $action );
  37. return $this->error( new Jetpack_Error( 'verify_secrets_mismatch', 'Secret mismatch', 400 ) );
  38. }
  39.  
  40. if ( in_array( $action, array( 'authorize', 'register' ) ) ) {
  41. // 'authorize' and 'register' actions require further testing
  42. if ( empty( $state ) ) {
  43. return $this->error( new Jetpack_Error( 'state_missing', sprintf( 'The required "%s" parameter is missing.', 'state' ), 400 ) );
  44. } else if ( ! ctype_digit( $state ) ) {
  45. return $this->error( new Jetpack_Error( 'state_malformed', sprintf( 'The required "%s" parameter is malformed.', 'state' ), 400 ) );
  46. }
  47. if ( empty( $user_id ) || $user_id !== $state ) {
  48. Jetpack_Options::delete_option( $action );
  49. return $this->error( new Jetpack_Error( 'invalid_state', 'State is invalid', 400 ) );
  50. }
  51. }
  52.  
  53. Jetpack_Options::delete_option( $action );
  54.  
  55. return $secret_2;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement