private static void applyOpenSSLFix ( ) throws SecurityException { if ( ( Build . VERSION . SDK_INT < VERSION_CODE_JELLY_BEAN ) || ( Build . VERSION . SDK_INT > VERSION_CODE_JELLY_BEAN_MR2 ) ) { // No need to apply the fix return ; } try { // Mix in the device- and invocation-specific seed. Class . forName ( "org.apache.harmony.xnet.provider.jsse.NativeCrypto" ) . getMethod ( "RAND_seed" , byte [ ] . class ) . invoke ( null , ( Object ) generateSeed ( ) ) ; // Mix output of Linux PRNG into OpenSSL's PRNG int bytesRead = ( Integer ) Class . forName ( "org.apache.harmony.xnet.provider.jsse.NativeCrypto" ) . getMethod ( "RAND_load_file" , String . class , long . class ) . invoke ( null , "/dev/urandom" , 1024 ) ; if ( bytesRead != 1024 ) { throw new IOException ( "Unexpected number of bytes read from Linux PRNG: " + bytesRead ) ; } } catch ( Exception e ) { throw new SecurityException ( "Failed to seed OpenSSL PRNG" , e ) ; } }
Applies the fix for OpenSSL PRNG having low entropy . Does nothing if the fix is not needed .