<?php
namespace wcf\action;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\user\User;
use wcf\data\user\UserEditor;
use wcf\system\exception\IllegalLinkException;
}
// start auth by redirecting to facebook
- $token = bin2hex(\random_bytes(20));
+ $token = Hex::encode(\random_bytes(20));
WCF::getSession()->register('__facebookInit', $token);
HeaderUtil::redirect("https://www.facebook.com/dialog/oauth?client_id=".StringUtil::trim(FACEBOOK_PUBLIC_KEY). "&redirect_uri=".rawurlencode($callbackURL)."&state=".$token."&scope=email");
$this->executed();
<?php
namespace wcf\action;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\user\User;
use wcf\data\user\UserEditor;
use wcf\system\exception\IllegalLinkException;
}
// start auth by redirecting to github
- $token = bin2hex(\random_bytes(20));
+ $token = Hex::encode(\random_bytes(20));
WCF::getSession()->register('__githubInit', $token);
HeaderUtil::redirect("https://github.com/login/oauth/authorize?client_id=".rawurlencode(StringUtil::trim(GITHUB_PUBLIC_KEY))."&scope=".rawurlencode('user:email')."&state=".$token);
$this->executed();
<?php
namespace wcf\action;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\user\User;
use wcf\data\user\UserEditor;
use wcf\system\exception\IllegalLinkException;
}
// start auth by redirecting to google
- $token = bin2hex(\random_bytes(20));
+ $token = Hex::encode(\random_bytes(20));
WCF::getSession()->register('__googleInit', $token);
HeaderUtil::redirect("https://accounts.google.com/o/oauth2/auth?client_id=".rawurlencode(StringUtil::trim(GOOGLE_PUBLIC_KEY)). "&redirect_uri=".rawurlencode($callbackURL)."&state=".$token."&scope=profile+openid+email&response_type=code");
$this->executed();
<?php
namespace wcf\action;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\user\User;
use wcf\data\user\UserEditor;
use wcf\system\exception\IllegalLinkException;
// fetch access_token
$oauthHeader = [
'oauth_consumer_key' => StringUtil::trim(TWITTER_PUBLIC_KEY),
- 'oauth_nonce' => bin2hex(\random_bytes(20)),
+ 'oauth_nonce' => Hex::encode(\random_bytes(20)),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => TIME_NOW,
'oauth_version' => '1.0',
try {
$oauthHeader = [
'oauth_consumer_key' => StringUtil::trim(TWITTER_PUBLIC_KEY),
- 'oauth_nonce' => bin2hex(\random_bytes(20)),
+ 'oauth_nonce' => Hex::encode(\random_bytes(20)),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => TIME_NOW,
'oauth_version' => '1.0',
$oauthHeader = [
'oauth_callback' => $callbackURL,
'oauth_consumer_key' => StringUtil::trim(TWITTER_PUBLIC_KEY),
- 'oauth_nonce' => bin2hex(\random_bytes(20)),
+ 'oauth_nonce' => Hex::encode(\random_bytes(20)),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => TIME_NOW,
'oauth_version' => '1.0'
<?php
namespace wcf\data\style;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\TDatabaseObjectToggle;
use wcf\data\user\UserAction;
use wcf\data\AbstractDatabaseObjectAction;
if ($file !== null) {
$fileLocation = $file->getLocation();
$extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
- $newName = $type.'-'.\bin2hex(\random_bytes(4)).'.'.$extension;
+ $newName = $type.'-'.Hex::encode(\random_bytes(4)).'.'.$extension;
$newLocation = $style->getAssetPath().$newName;
rename($fileLocation, $newLocation);
$this->parameters['variables'][$type] = $newName;
<?php
namespace wcf\data\user;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\user\avatar\UserAvatarAction;
use wcf\data\user\group\UserGroup;
foreach ($this->objects as $object) {
(new UserAction([$object], 'update', [
'data' => [
- 'emailConfirmed' => bin2hex(\random_bytes(20))
+ 'emailConfirmed' => Hex::encode(\random_bytes(20))
]
]))->executeAction();
}
$action = new UserAction($this->objects, 'update', [
'data' => [
'activationCode' => UserRegistrationUtil::getActivationCode(),
- 'emailConfirmed' => bin2hex(\random_bytes(20)),
+ 'emailConfirmed' => Hex::encode(\random_bytes(20)),
],
'removeGroups' => UserGroup::getGroupIDsByType([UserGroup::USERS])
]);
foreach ($this->objects as $object) {
$action = new UserAction([$object], 'update', [
'data' => [
- 'emailConfirmed' => bin2hex(\random_bytes(20))
+ 'emailConfirmed' => Hex::encode(\random_bytes(20))
]
]);
$action->executeAction();
<?php
namespace wcf\data\user;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\user\group\UserGroup;
use wcf\data\DatabaseObjectEditor;
use wcf\data\IEditableCachedObject;
}
// create accessToken for AbstractAuthedPage
- $parameters['accessToken'] = bin2hex(\random_bytes(20));
+ $parameters['accessToken'] = Hex::encode(\random_bytes(20));
// handle registration date
if (!isset($parameters['registrationDate'])) $parameters['registrationDate'] = TIME_NOW;
public function update(array $parameters = []) {
if (array_key_exists('password', $parameters) && $parameters['password'] !== '') {
$parameters['password'] = self::getPasswordHash($parameters['password']);
- $parameters['accessToken'] = bin2hex(\random_bytes(20));
+ $parameters['accessToken'] = Hex::encode(\random_bytes(20));
// update accessToken
$this->accessToken = $parameters['accessToken'];
<?php
namespace wcf\form;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\user\User;
use wcf\data\user\UserAction;
use wcf\system\email\mime\MimePartFacade;
parent::save();
// generate a new lost password key
- $lostPasswordKey = bin2hex(\random_bytes(20));
+ $lostPasswordKey = Hex::encode(\random_bytes(20));
// save key and request time in database
$this->objectAction = new UserAction([$this->user], 'update', [
<?php
namespace wcf\form;
+use ParagonIE\ConstantTime\Hex;
use wcf\acp\form\UserAddForm;
use wcf\data\blacklist\entry\BlacklistEntry;
use wcf\data\object\type\ObjectType;
if (isset($facebookData['gender']) && User::getUserOptionID('gender') !== null) $saveOptions[User::getUserOptionID('gender')] = ($facebookData['gender'] == 'male' ? UserProfile::GENDER_MALE : UserProfile::GENDER_FEMALE);
if (isset($facebookData['birthday']) && User::getUserOptionID('birthday') !== null) {
- list($month, $day, $year) = explode('/', $facebookData['birthday']);
+ [$month, $day, $year] = explode('/', $facebookData['birthday']);
$saveOptions[User::getUserOptionID('birthday')] = $year.'-'.$month.'-'.$day;
}
if (isset($facebookData['location']) && User::getUserOptionID('location') !== null) $saveOptions[User::getUserOptionID('location')] = $facebookData['location']['name'];
}
// create fake password
- $this->password = bin2hex(\random_bytes(20));
+ $this->password = Hex::encode(\random_bytes(20));
}
$eventParameters = [
$addDefaultGroups = true;
if (!empty($this->blacklistMatches) || (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER && !$registerVia3rdParty) || (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_ADMIN)) {
$activationCode = UserRegistrationUtil::getActivationCode();
- $emailConfirmCode = bin2hex(\random_bytes(20));
+ $emailConfirmCode = Hex::encode(\random_bytes(20));
$this->additionalFields['activationCode'] = $activationCode;
$this->additionalFields['emailConfirmed'] = $emailConfirmCode;
$addDefaultGroups = false;
<?php
namespace wcf\system\cronjob;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\cronjob\Cronjob;
use wcf\data\user\notification\event\UserNotificationEventList;
use wcf\data\user\notification\UserNotification;
// generate token if not present
if (!$user->notificationMailToken) {
- $token = bin2hex(\random_bytes(10));
+ $token = Hex::encode(\random_bytes(10));
$editor = new UserEditor($user);
$editor->update(['notificationMailToken' => $token]);
<?php
namespace wcf\system\email;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\application\ApplicationHandler;
use wcf\system\background\job\AbstractBackgroundJob;
use wcf\system\background\job\EmailDeliveryBackgroundJob;
*/
public function getMessageID() {
if ($this->messageID === null) {
- $this->messageID = bin2hex(\random_bytes(20));
+ $this->messageID = Hex::encode(\random_bytes(20));
}
return '<'.$this->messageID.'@'.self::getHost().'>';
*/
public function getHeaderString() {
return implode("\r\n", array_map(function ($item) {
- list($name, $value) = $item;
+ [$name, $value] = $item;
switch ($name) {
case 'message-id':
<?php
namespace wcf\system\email\mime;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\email\Mailbox;
use wcf\util\StringUtil;
* Sets the multipart boundary.
*/
public function __construct() {
- $this->boundary = "WoltLab_Suite=_".bin2hex(\random_bytes(20));
+ $this->boundary = "WoltLab_Suite=_".Hex::encode(\random_bytes(20));
$this->parts = new \SplObjectStorage();
}
]);
$statement->execute([
+ // We do not use the cache-timing safe class Hex, because we run the
+ // function during the setup.
$signatureSecret = \bin2hex(\random_bytes(20)),
'signature_secret'
]);
\define('SIGNATURE_SECRET', $signatureSecret);
HeaderUtil::setCookie(
'acp_session',
+ // We do not use the cache-timing safe class Hex, because we run the
+ // function during the setup.
CryptoUtil::createSignedString(\hex2bin(WCF::getSession()->sessionID))
);
<?php
namespace wcf\system\session;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\session\Session as LegacySession;
use wcf\data\session\SessionEditor;
use wcf\data\user\User;
return null;
}
- return \bin2hex($compressedSessionId);
+ return Hex::encode($compressedSessionId);
}
return null;
return $sessionID;
}
- return CryptoUtil::createSignedString(\hex2bin($sessionID));
+ return CryptoUtil::createSignedString(Hex::decode($sessionID));
}
/**
$xsrfToken = CryptoUtil::createSignedString(\random_bytes(16));
}
else {
- $xsrfToken = \bin2hex(\random_bytes(16));
+ $xsrfToken = Hex::encode(\random_bytes(16));
}
// We construct the cookie manually instead of using HeaderUtil::setCookie(), because:
* Creates a new session.
*/
protected function create() {
- $this->sessionID = \bin2hex(\random_bytes(20));
+ $this->sessionID = Hex::encode(\random_bytes(20));
// Create new session.
$sql = "INSERT INTO wcf".WCF_N."_".($this->isACP ? 'acp' : 'user')."_session
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = '$1$'.\bin2hex(\random_bytes(6)).'$';
+ $salt = '$1$'.Hex::encode(\random_bytes(6)).'$';
return $this->hashWithSalt($password, $salt);
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
/**
* Implementation of the PHPASS password algorithm.
*/
public function hash(string $password): string {
$settings = '$H$8';
- $settings .= \bin2hex(\random_bytes(4));
+ $settings .= Hex::encode(\random_bytes(4));
return $this->hashPhpass($password, $settings).':';
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\authentication\password\algorithm;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\user\authentication\password\IPasswordAlgorithm;
/**
* @inheritDoc
*/
public function hash(string $password): string {
- $salt = \bin2hex(\random_bytes(20));
+ $salt = Hex::encode(\random_bytes(20));
return $this->hashWithSalt($password, $salt).':'.$salt;
}
<?php
namespace wcf\system\user\notification;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\language\Language;
use wcf\data\user\notification\event\UserNotificationEvent;
use wcf\data\user\notification\UserNotification;
'data' => [
'email' => $username . '@example.com',
'languageID' => $languages[array_rand($languages)]->languageID,
- 'password' => \bin2hex(\random_bytes(16)),
+ 'password' => Hex::encode(\random_bytes(16)),
'registrationDate' => TIME_NOW - 24 * 3600 * random_int(10, 1000),
'username' => $username
]
<?php
namespace wcf\system\user\notification;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\object\type\ObjectType;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\user\notification\event\recipient\UserNotificationEventRecipientList;
// generate token if not present
if (!$user->notificationMailToken) {
- $token = bin2hex(\random_bytes(10));
+ $token = Hex::encode(\random_bytes(10));
$editor = new UserEditor($user);
$editor->update(['notificationMailToken' => $token]);
<?php
namespace wcf\system\worker;
+use ParagonIE\ConstantTime\Hex;
use wcf\data\user\User;
use wcf\data\user\UserAction;
use wcf\data\user\UserEditor;
* @param UserEditor $userEditor
*/
protected function resetPassword(UserEditor $userEditor) {
- $lostPasswordKey = bin2hex(\random_bytes(20));
+ $lostPasswordKey = Hex::encode(\random_bytes(20));
$lastLostPasswordRequestTime = TIME_NOW;
$userAction = new UserAction([$userEditor], 'update', [
'data' => [
<?php
namespace wcf\util;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\exception\SystemException;
use wcf\system\io\File;
use wcf\system\io\GZipFile;
public static function getTemporaryFilename($prefix = 'tmpFile_', $extension = '', $dir = TMP_DIR) {
$dir = self::addTrailingSlash($dir);
do {
- $tmpFile = $dir.$prefix.bin2hex(\random_bytes(20)).$extension;
+ $tmpFile = $dir.$prefix.Hex::encode(\random_bytes(20)).$extension;
}
while (file_exists($tmpFile));
use GuzzleHttp\Exception\TooManyRedirectsException;
use GuzzleHttp\Exception\TransferException;
use GuzzleHttp\Psr7\Request;
+use ParagonIE\ConstantTime\Hex;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
$this->addHeader('content-type', 'application/x-www-form-urlencoded');
}
else {
- $boundary = bin2hex(\random_bytes(20));
+ $boundary = Hex::encode(\random_bytes(20));
$this->addHeader('content-type', 'multipart/form-data; boundary='.$boundary);
// source of the iterators: http://stackoverflow.com/a/7623716/782822
<?php
namespace wcf\util;
+use ParagonIE\ConstantTime\Hex;
use wcf\system\application\ApplicationHandler;
use wcf\system\request\RouteHandler;
use wcf\system\WCF;
* @return string
*/
public static function getRandomID() {
- return \bin2hex(\random_bytes(20));
+ return Hex::encode(\random_bytes(20));
}
/**