From 5c7f2f17f9c471d306955df457c7cab4e5c6ed3b Mon Sep 17 00:00:00 2001 From: Snap Date: Thu, 16 Apr 2015 14:51:26 -0700 Subject: Google's OpenID Connect method $google_client_id & $google_client_secret must be added to db.inc.php! --- .../src/Google/Verifier/Abstract.php | 30 +++++++++ .../src/Google/Verifier/Pem.php | 75 ++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 includes/google-api-php-client-master/src/Google/Verifier/Abstract.php create mode 100644 includes/google-api-php-client-master/src/Google/Verifier/Pem.php (limited to 'includes/google-api-php-client-master/src/Google/Verifier') diff --git a/includes/google-api-php-client-master/src/Google/Verifier/Abstract.php b/includes/google-api-php-client-master/src/Google/Verifier/Abstract.php new file mode 100644 index 0000000..e6c9eeb --- /dev/null +++ b/includes/google-api-php-client-master/src/Google/Verifier/Abstract.php @@ -0,0 +1,30 @@ + + */ +abstract class Google_Verifier_Abstract +{ + /** + * Checks a signature, returns true if the signature is correct, + * false otherwise. + */ + abstract public function verify($data, $signature); +} diff --git a/includes/google-api-php-client-master/src/Google/Verifier/Pem.php b/includes/google-api-php-client-master/src/Google/Verifier/Pem.php new file mode 100644 index 0000000..3d6e0fd --- /dev/null +++ b/includes/google-api-php-client-master/src/Google/Verifier/Pem.php @@ -0,0 +1,75 @@ + + */ +class Google_Verifier_Pem extends Google_Verifier_Abstract +{ + private $publicKey; + + /** + * Constructs a verifier from the supplied PEM-encoded certificate. + * + * $pem: a PEM encoded certificate (not a file). + * @param $pem + * @throws Google_Auth_Exception + * @throws Google_Exception + */ + public function __construct($pem) + { + if (!function_exists('openssl_x509_read')) { + throw new Google_Exception('Google API PHP client needs the openssl PHP extension'); + } + $this->publicKey = openssl_x509_read($pem); + if (!$this->publicKey) { + throw new Google_Auth_Exception("Unable to parse PEM: $pem"); + } + } + + public function __destruct() + { + if ($this->publicKey) { + openssl_x509_free($this->publicKey); + } + } + + /** + * Verifies the signature on data. + * + * Returns true if the signature is valid, false otherwise. + * @param $data + * @param $signature + * @throws Google_Auth_Exception + * @return bool + */ + public function verify($data, $signature) + { + $hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256"; + $status = openssl_verify($data, $signature, $this->publicKey, $hash); + if ($status === -1) { + throw new Google_Auth_Exception('Signature verification error: ' . openssl_error_string()); + } + return $status === 1; + } +} -- cgit v1.2.3