SecurePreferences Version: v0.1.4
Target Device: Emulator with Image API 18, Google APIs Intel x86, rev. 5
Gradle Android Plugin Version: v2.2.2
When using the Android Gradle plugin shrinker, a NoSuchAlgorithmException
is thrown when trying to instantiate a new SecurePreferences object on the target device specified above. It works fine when run on a device on API 23.
The stack trace:
java.security.NoSuchAlgorithmException: SecureRandom SHA1PRNG implementation not found
at java.security.SecureRandom.<init>(SecureRandom.java:100)
at com.tozny.crypto.android.AesCbcWithIntegrity$PrngFixes.installLinuxPRNGSecureRandom(AesCbcWithIntegrity.java:760)
at com.tozny.crypto.android.AesCbcWithIntegrity$PrngFixes.apply(AesCbcWithIntegrity.java:684)
at com.tozny.crypto.android.AesCbcWithIntegrity.fixPrng(AesCbcWithIntegrity.java:347)
at com.tozny.crypto.android.AesCbcWithIntegrity.generateKeyFromPassword(AesCbcWithIntegrity.java:184)
at com.tozny.crypto.android.AesCbcWithIntegrity.generateKeyFromPassword(AesCbcWithIntegrity.java:167)
at com.securepreferences.SecurePreferences.generateAesKeyName(SecurePreferences.java:202)
at com.securepreferences.SecurePreferences.<init>(SecurePreferences.java:118)
at com.securepreferences.SecurePreferences.<init>(SecurePreferences.java:92)
at com.whatever.Session.<init>(Session.java:45)
Where line 45 of Session.java is
preferences = new SecurePreferences(context, "", SHARED_PREF_FILENAME);
As far as I've noticed, this only happens when enabling the Gradle plugin shrinker, and happens with and without Instant Run enabled. Using proguard to shrink works fine as well.
So, it looks like the Gradle shrinker is pulling out more than it needs to. Checking out the apks in Classyshark confirms this.
Resolution
Although the readme says no proguard config is necessary for v0.1.4, the resolution is to add -keep class com.tozny.crypto.android.AesCbcWithIntegrity$PrngFixes$* { *; }
to the proguard file and the Gradle plugin shrinker will behave.
Perhaps we should add a consumer proguard file with this rule to support the Gradle Android plugin shrinker.