replace random_bytes

This commit is contained in:
Frédéric FRANCE 2018-11-15 21:17:59 +01:00
parent 482c6efdd9
commit 7c241620c0
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
3 changed files with 21 additions and 5 deletions

View File

@ -46,7 +46,7 @@ class Swift_Mime_IdGenerator implements Swift_IdGenerator
*/
public function generateId()
{
$idLeft = bin2hex(random_bytes(16)); // set 32 hex values
$idLeft = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
return $idLeft.'@'.$this->idRight;
}

View File

@ -92,7 +92,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
*/
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator)
{
$this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values
$this->cacheKey = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
$this->cache = $cache;
$this->headers = $headers;
$this->idGenerator = $idGenerator;
@ -420,7 +420,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
public function getBoundary()
{
if (!isset($this->boundary)) {
$this->boundary = '_=_swift_'.time().'_'.bin2hex(random_bytes(16)).'_=_';
$this->boundary = '_=_swift_'.time().'_'.md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true)).'_=_';
}
return $this->boundary;
@ -813,7 +813,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
{
$this->headers = clone $this->headers;
$this->encoder = clone $this->encoder;
$this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values
$this->cacheKey = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
$children = array();
foreach ($this->children as $pos => $child) {
$children[$pos] = clone $child;

View File

@ -58,7 +58,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
// extra parameters for our unit cases
$timestamp = func_num_args() > 3 ? func_get_arg(3) : $this->getCorrectTimestamp(bcmul(microtime(true), '1000'));
$client = func_num_args() > 4 ? func_get_arg(4) : random_bytes(8);
$client = func_num_args() > 4 ? func_get_arg(4) : $this->getRandomBytes(8);
// Message 3 response
$this->sendMessage3($response, $username, $password, $timestamp, $client, $agent);
@ -548,6 +548,22 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
return $byte;
}
/**
* Create random bytes.
*
* @param $length
*
* @return string
*/
protected function getRandomBytes($length) : string
{
$bytes = openssl_random_pseudo_bytes($length, $strong);
if (false !== $bytes && true === $strong) {
return $bytes;
}
throw new RuntimeException('OpenSSL did not produce a secure random number.');
}
/** ENCRYPTION ALGORITHMS */
/**