MonsterInsights_GA_Lib_Verifier_Pem

Verifies signatures using PEM encoded certificates.

Defined (1)

The class is defined in the following location(s).

/assets/lib/google/src/Google/Verifier/Pem.php  
  1. class MonsterInsights_GA_Lib_Verifier_Pem extends MonsterInsights_GA_Lib_Verifier_Abstract 
  2. private $publicKey; 
  3.  
  4. /** 
  5. * Constructs a verifier from the supplied PEM-encoded certificate. 
  6. * $pem: a PEM encoded certificate (not a file). 
  7. * @param $pem 
  8. * @throws MonsterInsights_GA_Lib_Auth_Exception 
  9. * @throws MonsterInsights_GA_Lib_Exception 
  10. */ 
  11. public function __construct($pem) 
  12. if (!function_exists('openssl_x509_read')) { 
  13. throw new MonsterInsights_GA_Lib_Exception('Google API PHP client needs the openssl PHP extension'); 
  14. $this->publicKey = openssl_x509_read($pem); 
  15. if (!$this->publicKey) { 
  16. throw new MonsterInsights_GA_Lib_Auth_Exception("Unable to parse PEM: $pem"); 
  17.  
  18. public function __destruct() 
  19. if ($this->publicKey) { 
  20. openssl_x509_free($this->publicKey); 
  21.  
  22. /** 
  23. * Verifies the signature on data. 
  24. * Returns true if the signature is valid, false otherwise. 
  25. * @param $data 
  26. * @param $signature 
  27. * @throws MonsterInsights_GA_Lib_Auth_Exception 
  28. * @return bool 
  29. */ 
  30. public function verify($data, $signature) 
  31. $hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256"; 
  32. $status = openssl_verify($data, $signature, $this->publicKey, $hash); 
  33. if ($status === -1) { 
  34. throw new MonsterInsights_GA_Lib_Auth_Exception('Signature verification error: ' . openssl_error_string()); 
  35. return $status === 1;