Listener Certificate Authenticator Delegate is not working for Android

Currently, for Android Peer-to-Peer communication, we are using the following library and code:
Library:
com.couchbase.lite:couchbase-lite-android-ee:3.0.12
Working Existing Code:

listenerConfig.setAuthenticator(ListenerCertificateAuthenticator(caCertificates))
val listener = URLEndpointListener(listenerConfig)

We are passing a CA certificate to the ListenerCertificateAuthenticator to verify the incoming client certificate and establish a connection.

However, based on our new requirements, we need to perform additional checks in addition to the certificate verification. Therefore, following the guidelines in the Couchbase documentation, we are delegating authentication to a custom class that implements ListenerCertificateAuthenticatorDelegate. (Please refer to the updated code below.)

Couchbase Documentation:

Updated Code:

class Delegate : ListenerCertificateAuthenticatorDelegate {
    override fun authenticate(certs: List<Certificate>): Boolean {
        val valid = true // Our code eventually returns true.
        return valid
    }
}
 
listenerConfig.setAuthenticator(ListenerCertificateAuthenticator(Delegate()))

Although we return true during authentication, the connection still fails to be established, and we are seeing the following error for the peer device(iOS) which is trying to connect. (Note: similar changes does work for iOS)

“error”: “\nCaused by Object: server rejected the TLS client certificate”

It seems like there might be an issue with the Couchbase Android library. Kindly help

FWIW, 3.0.12 is quite old and is out of maintenance. You might consider upgrading to something more recent. That said, I should think this should work.

There really isn’t a lot to go on, here: one snippet of an error message that wasn’t even generated by CBL. Also, I doubt that the code you show, above, is the code that is actually running: why would you assign a variable only to return its value?

Here’s what I suggest:

  • Print out the list of certs that your authenticator delegate receives.
  • Print out the value that you return from the delegate, immediately before you return it.
  • Use adb logcat to capture the CBL logs from around the time of the failure. This interaction is heavily logged so the logs may well shed light.

If that doesn’t make the solution obvious, add the printouts to this post and I’ll have a look