Search code examples
androidsentry

Sentry-android self signed SSL certificate (SSLPeerUnverifiedException)


With Sentry Android SDK (io.sentry:sentry-android:5.0.1) - is there any way to pass custom HostnameVerifier or SHA-256/SHA-1 of SSL cert to authorize the usage of self-signed certs?

Currently I'm getting:

javax.net.ssl.SSLPeerUnverifiedException: Hostname xxxx not verified:
certificate: sha1/xxxx
DN: CN=xxxx
subjectAltNames: []

I already passed SHA-256 for that domain in my networkSecurityConfig XML file however it seems like it doesn't take that into account.


Solution

  • You can set one in through the options:

    https://github.com/getsentry/sentry-java/blob/1f704cb3e630cb753ce0ac3390b6da5377c9e6ea/sentry/src/main/java/io/sentry/SentryOptions.java#L1193-L1195

    SentryAndroid.init(o -> {
      o.setHostnameVerifier(...);
      o.setDsn(...);
      // other options
    });
    

    Note that if you're going to initialize programatically as I suggest above, you shouldn't add the configuration via the AndroidManifest.xml meta-data anymore.

    Docs about this are here: https://docs.sentry.io/platforms/android/configuration/manual-init/