News for hackers. Stuff that matters.
Re:Google confirms Java and OpenSSL crypto PRNG on Android a... by marshray on Thursday August 15, 2013 @12:17AM (#6216129)
(cross post from other article)

I thought OpenSSL's default code already pulled from /dev/[u]random at initialization?

Re:Google confirms Java and OpenSSL crypto PRNG on Android a... by rwg on Thursday August 15, 2013 @04:17AM (#6216686)
The short answer is yes:

The first call to ssleay_rand_bytes() (which is what RAND_bytes() calls eventually become with the default RAND_METH) will call RAND_poll(), which on Unix-but-not-OpenBSD-or-VOS will try reading ENTROPY_NEEDED (32) bytes from /dev/urandom, /dev/random, and /dev/srandom (in that order). Then, for grins, it throws getpid(), getuid(), and time() into the pool.

The longer answer is maybe:

• RAND_poll() relies on a #define named DEVRANDOM to figure out where to go looking for random devices. If DEVRANDOM is undefined, e_os.h will define it to "/dev/urandom","/dev/random","/dev/srandom". If DEVRANDOM is defined but empty, then the code in rand_unix.c's RAND_poll() ends up skipping seeding from random devices entirely and only tosses getpid(), getuid(), and time() into the pool.

• If something changes OpenSSL's default RAND_METH so it's not RAND_SSLeay(), all bets are off.

Despite staring at all of the code between Android's SecureRandom.java and their OpenSSL tree's crypto/rand directory for three hours, I can't figure out how they screwed this up.

Re:Google confirms Java and OpenSSL crypto PRNG on Android a... by benmmurphy on Thursday August 15, 2013 @09:57AM (#6217757)
my theory:

trace what can happen if reading from /dev/urandom, etc fails.

i think:

a) if the RAND_seed has already been called it is possible to fail reading from /dev/random and not get a subsequent failure from RAND_bytes because RAND_bytes will believe there is enough entropy in the pool. this can happen even if YOU don't explicitly seed the SecureRandom you are using because the state of all SecureRandom instances are shared :)

b) there is this lols method called throwExceptionIfNecessary in the native crypto code. RAND_bytes checks the return code and if the return code is bad it calls throwExceptionIfNecessary. however, throwExceptionIfNecessary does not always throw an exception. there are some conditions where it won't throw an exception (malloc failure...). however, i'm not sure if these conditions are possible on android openssl.

c) sharing of state between forks. not sure if openssl is initialized in zygote before forking.

Re:Google confirms Java and OpenSSL crypto PRNG on Android a... by marshray on Thursday August 15, 2013 @04:27AM (#6216705)
Complexity kills.

Thank you for staring at the code for three hours BTW. :-)

Re:Google confirms Java and OpenSSL crypto PRNG on Android a... by rwg on Thursday August 15, 2013 @05:02AM (#6216805)
As an added fun bonus, it looks like the NativeCrypto Java wrapper around OpenSSL wrongly assumes that RAND_bytes() returns 0 on failure and not-zero on success. In reality, it returns 1 on success, 0 on failure, and -1 on super ultra mega failure.
Re:Google confirms Java and OpenSSL crypto PRNG on Android a... by marshray on Thursday August 15, 2013 @05:32AM (#6216866)
That evil API has bitten so many projects.
Re:Google confirms Java and OpenSSL crypto PRNG on Android a... by benmmurphy on Thursday August 15, 2013 @10:00AM (#6217772)
this is probably the problem :)
Re:Google confirms Java and OpenSSL crypto PRNG on Android a... by rwg on Thursday August 15, 2013 @04:59AM (#6216799)
After staring at convoluted Java code and OpenSSL's code for three hours, I need a stiff drink...
Re:Google confirms Java and OpenSSL crypto PRNG on Android a... by Maxious on Thursday August 15, 2013 @12:47AM (#6216217)
The developers that used this flawed API thought so too. Mea culpa.