|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
<?php |
|
|
|
|
declare(strict_types=1); |
|
|
|
|
/** |
|
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
|
|
|
* |
|
|
|
@ -40,7 +41,7 @@ class CsrfToken { |
|
|
|
|
/** |
|
|
|
|
* @param string $value Value of the token. Can be encrypted or not encrypted. |
|
|
|
|
*/ |
|
|
|
|
public function __construct($value) { |
|
|
|
|
public function __construct(string $value) { |
|
|
|
|
$this->value = $value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -50,9 +51,9 @@ class CsrfToken { |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
public function getEncryptedValue() { |
|
|
|
|
public function getEncryptedValue(): string { |
|
|
|
|
if($this->encryptedValue === '') { |
|
|
|
|
$sharedSecret = random_bytes(strlen($this->value)); |
|
|
|
|
$sharedSecret = random_bytes(\strlen($this->value)); |
|
|
|
|
$this->encryptedValue = base64_encode($this->value ^ $sharedSecret) . ':' . base64_encode($sharedSecret); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -65,9 +66,9 @@ class CsrfToken { |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
public function getDecryptedValue() { |
|
|
|
|
public function getDecryptedValue(): string { |
|
|
|
|
$token = explode(':', $this->value); |
|
|
|
|
if (count($token) !== 2) { |
|
|
|
|
if (\count($token) !== 2) { |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
$obfuscatedToken = $token[0]; |
|
|
|
|