public function Kitchen::tasteData in Bakery Single Sign-On System 8.2
Validate signature and decrypt data.
Parameters
string $data: String of Bakery data, base64 encoded.
string|null $type: Optional string defining the type of data this is.
Return value
array|bool Unserialized data or FALSE if invalid.
Throws
\Drupal\bakery\Exception\MissingKeyException Thrown if the site key isn't configured yet.
1 call to Kitchen::tasteData()
- Kitchen::taste in src/
Kitchen.php - Check that the given cookie exists and doesn't taste funny.
File
- src/
Kitchen.php, line 171
Class
Namespace
Drupal\bakeryCode
public function tasteData(string $data, string $type = NULL) {
$key = $this->config
->get('bakery_key');
if (empty($key)) {
throw new MissingKeyException();
}
$data = base64_decode($data);
$signature = substr($data, 0, 64);
$encrypted_data = substr($data, 64);
if ($signature !== hash_hmac('sha256', $encrypted_data, $key)) {
return FALSE;
}
$decrypted_data = unserialize($this
->decrypt($encrypted_data));
// Prevent one cookie being used in place of another.
if ($type !== NULL && $decrypted_data['type'] !== $type) {
return FALSE;
}
if ($decrypted_data['timestamp'] + (int) $this->config
->get('bakery_freshness') >= $this->time
->getRequestTime()) {
return $decrypted_data;
}
return FALSE;
}