Google_Verifier_Pem

Verifies signatures using PEM encoded certificates.

Defined (1)

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

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