thewca / tnoodle-lib

scrambling code portion of TNoodle
GNU General Public License v3.0
39 stars 15 forks source link

Couldn't get SecureRandomInstance #13

Open jdediegomrt opened 5 years ago

jdediegomrt commented 5 years ago

Hi! On android library when I make a scramble I see this exception:

E/Puzzle: Couldn't get SecureRandomInstance java.security.NoSuchProviderException: SUN at java.security.SecureRandom.getInstance(SecureRandom.java:186) at net.gnehzr.tnoodle.scrambles.Puzzle.getSecureRandom(Puzzle.java:124) at net.gnehzr.tnoodle.scrambles.Puzzle.<init>(Puzzle.java:120) at puzzle.MegaminxPuzzle.<init>(MegaminxPuzzle.java:65) at java.lang.reflect.Constructor.newInstance(Native Method) at net.gnehzr.tnoodle.utils.LazyInstantiator.newInstance(LazyInstantiator.java:85) at net.gnehzr.tnoodle.utils.LazyInstantiator.cachedInstance(LazyInstantiator.java:104)

I see this when I call the cached instance of a LazyIntantiator:

LazyInstantiator<Puzzle> lazyPuzzle = Constants.getInstance().WCA_PUZZLES.get(shortName); try { puzzle = lazyPuzzle.cachedInstance(); } catch (LazyInstantiatorException e) { Log.wtf("ScrambleConfig", e); }

Could you help me please? I'm not sure why is this happening.

This seems not to affect the scramble but I'm a little worried of the impact in production.

Thank you!

jfly commented 5 years ago

It looks like the code first tries to do a SecureRandom.getInstance("SHA1PRNG", "SUN"), and then falls back to a getInstance("SHA1PRNG") if that fails. I think it makes sense that the SUN algorithm wouldn't exist on Android, which it sounds like is what you're using.

It looks like I added this fallback in https://github.com/thewca/tnoodle/commit/9c9469116c333dc4cae30c82e9ca0606283a7939, but didn't leave much of an explanation about what was going on there.

I think this is safe to ignore. It doesn't seem valuable to me to be logging at level SEVERE, though. If you want to send in a PR removing that log message, I'd be ok with that!