wultra / ssl-pinning-android

Android SDK for our dynamic SSL pinning
Apache License 2.0
60 stars 8 forks source link

Crash during initial setup of library #53

Closed ankush2016 closed 3 years ago

ankush2016 commented 3 years ago

Code

private fun sslPinningImplementation() {
        val publicKey:ByteArray = Base64.decode(MY_KEY, Base64.NO_WRAP)
        val configuration = CertStoreConfiguration.Builder(
            serviceUrl = URL(MY_URL),
            publicKey = publicKey)
            .build()
        val certStore = CertStore.powerAuthCertStore(configuration = configuration, context = applicationContext)
        certStore.update(UpdateMode.DEFAULT, object : DefaultUpdateObserver() {
            override fun onUpdateStarted(type: UpdateType) {
                super.onUpdateStarted(type)
            }

            override fun onUpdateFinished(type: UpdateType, result: UpdateResult) {
                super.onUpdateFinished(type, result)
            }
            override fun continueExecution() {
                // Certstore is likely up-to-date, you can resume execution of your code.
            }

            override fun handleFailedUpdate(type: UpdateType, result: UpdateResult) {
                // There was an error during the update, present an error to the user.
            }

        })

        val url = URL(MY_URL)
        val urlConnection = url.openConnection() as javax.net.ssl.HttpsURLConnection
        urlConnection.connect()

        val serverCert = urlConnection.serverCertificates[0]
        val validationResult = certStore.validateCertificate(serverCert as X509Certificate)
        if (validationResult != ValidationResult.TRUSTED) {
            //throw javax.net.ssl.SSLException()
            Toast.makeText(this, "Not valid", Toast.LENGTH_SHORT).show()
        }
    }

Crash Logs

java.lang.NoClassDefFoundError: Failed resolution of: Lio/getlime/security/powerauth/keychain/KeychainFactory;
        at com.wultra.android.sslpinning.integration.powerauth.PowerAuthSecureDataStore.<init>(PowerAuthSecureDataStore.kt:45)
        at com.wultra.android.sslpinning.integration.powerauth.PowerAuthSecureDataStore.<init>(PowerAuthSecureDataStore.kt:38)
        at com.wultra.android.sslpinning.integration.powerauth.PowerAuthIntegrationKt.powerAuthCertStore(PowerAuthIntegration.kt:40)
        at com.wultra.android.sslpinning.integration.powerauth.PowerAuthIntegrationKt.powerAuthCertStore$default(PowerAuthIntegration.kt:38)
        at com.yt.view.booster.activity.HomeActivity.sslPinningImplementation(HomeActivity.kt:66)
        at com.yt.view.booster.activity.HomeActivity.onCreate(HomeActivity.kt:56)
        at android.app.Activity.performCreate(Activity.java:7893)
        at android.app.Activity.performCreate(Activity.java:7880)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3283)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3457)
petrdvorak commented 3 years ago

You are using powerAuthCertStore and hence have to provide PowerAuth SDK as dependency in your pom.xml.