javiersantos/PiracyChecker

Crashes on License Verification on first launch when installed from play store.

dipendrapkrl opened this issue · 5 comments

Hi there, Thanks for the awesome library.
I am noticing a strange crash that can't even be caught. It happens when license check is enabled and the app has been launched for the very first time when installed from play store(doesn't happen if installed outside of play store). The crash never happens afterwards however.

You can find the logs here:
https://pastebin.com/NpN8DSvZ

Any help would be highly appreciated.

Please next time post only the relevant part of the logs. Here it is:

07-22 23:21:09.556 10228 10228 E AndroidRuntime: FATAL EXCEPTION: main
07-22 23:21:09.556 10228 10228 E AndroidRuntime: Process: np.pro.dipendra.triviavision, PID: 10228
07-22 23:21:09.556 10228 10228 E AndroidRuntime: java.lang.IllegalArgumentException: java.security.spec.InvalidKeySpecException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: Error parsing public key
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.github.javiersantos.licensing.LibraryChecker.a(SourceFile:129)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.github.javiersantos.licensing.LibraryChecker.<init>(SourceFile:98)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.github.javiersantos.piracychecker.PiracyChecker.b(SourceFile:321)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.github.javiersantos.piracychecker.PiracyChecker.b(SourceFile:298)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at np.pro.dipendra.hqvision.r.a(SourceFile:145)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at np.pro.dipendra.hqvision.LauncherActivity.r(SourceFile:92)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at np.pro.dipendra.hqvision.LauncherActivity.a(SourceFile:148)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at np.pro.dipendra.hqvision.LauncherActivity.a(SourceFile:24)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at np.pro.dipendra.hqvision.a.a$1.a(SourceFile:46)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.google.firebase.database.zzp.a(Unknown Source:7)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.google.android.gms.internal.firebase_database.zzfc.a(Unknown Source:13)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.google.android.gms.internal.firebase_database.zzgx.a(Unknown Source:2)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.google.android.gms.internal.firebase_database.zzhd.run(Unknown Source:71)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:790)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:164)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6494)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: Caused by: java.security.spec.InvalidKeySpecException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: Error parsing public key
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.android.org.conscrypt.OpenSSLKey.getPublicKey(OpenSSLKey.java:272)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.android.org.conscrypt.OpenSSLRSAKeyFactory.engineGeneratePublic(OpenSSLRSAKeyFactory.java:54)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at java.security.KeyFactory.generatePublic(KeyFactory.java:357)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.github.javiersantos.licensing.LibraryChecker.a(SourceFile:120)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	... 19 more
07-22 23:21:09.556 10228 10228 E AndroidRuntime: Caused by: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: Error parsing public key
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.android.org.conscrypt.NativeCrypto.EVP_parse_public_key(Native Method)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	at com.android.org.conscrypt.OpenSSLKey.getPublicKey(OpenSSLKey.java:270)
07-22 23:21:09.556 10228 10228 E AndroidRuntime: 	... 22 more

Now, regarding the issue, it seems that the key is incorrectly set or encrypted which is leading to this issue. Please be sure to get the right key from Google Play Console, as this issue isn't really related to the library.

I'll keep this issue open in case you want to add more relevant information, otherwise I'll close it in 2 days.

I have provided the license key as is by grabbing from play store.
The interesting fact is that it only crashes once. The very first time license based check is done.
Another interesting fact is that this crash is never present when the app is sideloaded. It happens only when you happen to install via play store.
Next time onward it works well. Now I am disabling this check for first few times so the app would not crash when user open the app for first few times.

This issue is legit. Please tell me what info I need to provide.

I just doubt you're using the right key, since the issue clearly states InvalidKeySpecException and that means you're using an incorrectly encrypted license key. Most likely you're getting the incorrect one. Go to Google Play Developer Console -> Select your app -> Development Tools -> API and Services -> License Key .... It usually starts with something like: MIIBIjANB it also must not contain any spaces.

@jahirfiquitiva hello Im facing the same problem although I am sure that my key is correct here is my error log from firebase

`Fatal Exception: android.view.ViewRootImpl$CalledFromWrongThreadException
Only the original thread that created a view hierarchy can touch its views.
android.view.ViewRootImpl.checkThread (ViewRootImpl.java:7352)
androidx.appcompat.app.AppCompatActivity.setContentView (Unknown Source)
standalone.smartkids.com.activities.WelcomeActivity.access$000 (Unknown Source)
standalone.smartkids.com.activities.WelcomeActivity$2.allow (Unknown Source)
com.github.javiersantos.piracychecker.PiracyChecker$callback$1.allow (Unknown Source)
com.github.javiersantos.piracychecker.PiracyChecker.blockIfUnauthorizedAppUninstalled (Unknown Source)
com.github.javiersantos.piracychecker.PiracyChecker.blockIfUnauthorizedAppUninstalled (Unknown Source)
com.github.javiersantos.piracychecker.PiracyChecker$verify$1.allow$13462e (Unknown Source)
com.github.javiersantos.licensing.LibraryValidator.handleResponse (Unknown Source)
com.github.javiersantos.licensing.LibraryChecker$ResultListener$2.run (Unknown Source)

This only happens when running for the first time and after downloading from google play store.