Ticket #429 (closed Bug: fixed)

Opened 10 months ago

Last modified 10 months ago

Windows and Mcrypt ('MCRYPT_DEV_URANDOM' and 'MCRYPT_DEV_RANDOM')

Reported by: canglan Owned by: Shadowhand
Priority: minor Milestone: 2.1.2
Component: Libraries Version: SVN HEAD
Keywords: mcrypt windows encrypt Cc:

Description

Windows does not support the use of MCRYPT_DEV_URANDOM or MCRYPT_DEV_RANDOM, however these constants do exist on Windows platforms.

Using the encryption library on Windows will cause fatal error.

Here is the original code found in ./system/libraries/Encrypt.php (start at line 81)

if (self::$rand === NULL)
{
	if (defined('MCRYPT_DEV_URANDOM'))
	{
		// Use /dev/urandom
		self::$rand = MCRYPT_DEV_URANDOM;
	}
	elseif (defined('MCRYPT_DEV_RANDOM'))
	{
		// Use /dev/random
		self::$rand = MCRYPT_DEV_RANDOM;
	}
	else
	{
		// Use the system random number generator
		self::$rand = MCRYPT_RAND;
	}
}

Proposed fix:

if (self::$rand === NULL)
{
	if (@$_ENV["OS"] == 'Windows_NT')
	{
		// Use the system random number generator
		self::$rand = MCRYPT_RAND;
	}
	elseif (defined('MCRYPT_DEV_URANDOM'))
	{
		// Use /dev/urandom
		self::$rand = MCRYPT_DEV_URANDOM;
	}
	elseif (defined('MCRYPT_DEV_RANDOM'))
	{
		// Use /dev/random
		self::$rand = MCRYPT_DEV_RANDOM;
	}
	else
	{
		// Use the system random number generator
		self::$rand = MCRYPT_RAND;
	}
}

Change History

Changed 10 months ago by Shadowhand

  • keywords encrypt added
  • owner changed from - No owner - to Shadowhand
  • status changed from new to assigned

Fix

Changed 10 months ago by Shadowhand

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in r2146.

Note: See TracTickets for help on using tickets.