1

I would like to ask you something related with Philips Hue Smart Lamps integration with Kotlin. I am working with Hue API v2 and after follow all the steps I was able to connect my mobile with Hue bridge and send orders to lights without problems, at least for me.

After generate the PROD application, some teammates have found problems during the bridge linking, they are receiving the error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

This error happen when Android can’t find the trusted certificated to make the bridge call (This call attacks an IP with HTTPS, so make sense the error), however, I am adding the expected certificated into the network_security_config file (Hue certificate is .crt file) and as I said, this works for me and I tested it on 6 different devices.

The point here is, how is possible that some user have problems to generate the trusted certificate and other don’t have any problems? I checked mobile specs for each use case and I couldn’t find a pattern, OS version isn’t related (mobiles with the same OS works and fails), model is not representative either...

My only option about this... could this be related with user's Wifi? Because when an user said that it is not working, the user can’t do the flow in any device, all of them fails, but, when it works (like my case) I can install and do the flow in all my devices.

I tried to obtain the Hue certificate in differents ways, first time I did this: `

private fun createCertificate(trustedCertificateIS: InputStream): SSLContext? {
    val cf = CertificateFactory.getInstance("X.509")
    val ca: Certificate = trustedCertificateIS.use { trustedCertificateIS ->
        cf.generateCertificate(trustedCertificateIS)
    }

    // creating a KeyStore containing our trusted CAs
    val keyStoreType = KeyStore.getDefaultType()
    val keyStore = KeyStore.getInstance(keyStoreType)
    keyStore.load(null, null)
    keyStore.setCertificateEntry("ca", ca)

    // creating a TrustManager that trusts the CAs in our KeyStore
    val tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm()
    val tmf = TrustManagerFactory.getInstance(tmfAlgorithm)
    tmf.init(keyStore)

    // creating an SSLSocketFactory that uses our TrustManager
    val sslContext = SSLContext.getInstance("TLS")
    sslContext.init(null, tmf.trustManagers, null)
    return sslContext
}

`

This works for me without problems, the app is able to find the Hue file and use it to generate the SSLContext, but, this is not working for some users.

In order to find another solution, I created a network_security_config file, same result.

`

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config>
        <trust-anchors>
            <certificates src="@raw/huecert"/>
            <certificates src="system"/>
        </trust-anchors>
    </base-config>
</network-security-config>

`

At this point, I am not sure what else can I try... so, if you have any feedback or idea about this I would really appreciate it.

Thanks!

David Ares
  • 11
  • 2

0 Answers0