Skip to content

Urandom and Random using Mcrypt #12

Open

Description

@Beanow

On a lot of Linux servers I noticed that using fopen to get /dev/random or /dev/urandom data does not work because of open_basedir restrictions.

One way of bypassing this is using Mcrypt.
Consider adding a closure that can use this.

Example code:

if(function_exists('mcrypt_create_iv') && defined('MCRYPT_DEV_URANDOM')){
  $str = mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);
  if($str !== false)
    return $str;
}

Activity

  1. ircmaxell commented on Sep 26, 2013

    @ircmaxell
    Owner

    An additional mcrypt source (or two) can definitely be added. I wouldn't "replace" the dev/(u)random sources, but augment them.

    Additionally, if security is a concern, the server wouldn't be running openbasedir, but instead would be running a chroot jail.

  2. Beanow commented on Sep 26, 2013

    @Beanow
    Author

    Yes using it as an augmentation was what I had in mind and is how I implemented it as well. In my case giving priority to the Mcrypt variant, because it's code will be more scrutinized than anything I ever wrote. :P

    I agree the chroot jail would be better than open_basedir as far as security is concerned, but I suggested it mostly with shared hosting in mind where you'll just have to deal with what's available. And often direct reading access to these files is not part of it, while Mcrypt is a requirement for many utilities and requires less configuration so it's likely to be available on shared hosting.

  3. remicollet commented on Nov 16, 2016

    @remicollet

    Everything using "mcryp" is just a bad idea.
    This is now deprecated and will be remove in 7.2

  4. ircmaxell commented on Nov 30, 2016

    @ircmaxell
    Owner

    Honestly, I trust mcrypt more than I do OpenSSL, having read the source code of both. Note: that's not an endorsement of mcrypt, but a hit on OpenSSL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions