# Use the HiveMQ Mqtt client without certificate validation?

**URL:** <https://community.hivemq.com/t/use-the-hivemq-mqtt-client-without-certificate-validation/3734>\
**Category:** HiveMQ Client Library\
**Created:** [April 15, 2025, 3:07pm UTC](https://community.hivemq.com/t/use-the-hivemq-mqtt-client-without-certificate-validation/3734 "2025-04-15T15:07:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdutz](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@cdutz](https://community.hivemq.com/u/cdutz)\
**Post date:** [April 15, 2025, 3:07pm UTC](https://community.hivemq.com/t/use-the-hivemq-mqtt-client-without-certificate-validation/3734/1 "2025-04-15T15:07:13Z")

</div>

I am currently just doing some research on MQTT usage in a demo environment.  
As the certificates seem to keep on changing almost on a daily basis, I would love to simply accept all certificates until it’s time to move to a production setup.

However this seems a tad challenging, specially as it seems the API changed quite a bit and a lot of the information on the web is no longer valid … Is there any example on how to set this up?

---

<div class="post-metadata">

**Author:** ![pglombardo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/pglombardo/32/588_2.png) [@pglombardo](https://community.hivemq.com/u/pglombardo)\
**Post date:** [April 18, 2025, 11:46am UTC](https://community.hivemq.com/t/use-the-hivemq-mqtt-client-without-certificate-validation/3734/2 "2025-04-18T11:46:33Z")

</div>

Hi @cdutz - which MQTT client are you using?

Most have an option to allow invalid certificates. [Here are the docs](https://hivemq.github.io/hivemq-mqtt-client-dotnet/docs/how-to/allow-invalid-certs) for the C#/.NET MQTT library as an example.

Best,  
Peter

---

<div class="post-metadata">

**Author:** ![cdutz](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@cdutz](https://community.hivemq.com/u/cdutz)\
**Post date:** [April 22, 2025, 6:15am UTC](https://community.hivemq.com/t/use-the-hivemq-mqtt-client-without-certificate-validation/3734/3 "2025-04-22T06:15:59Z")

</div>

I fixed the problem by using this trust manager:

```auto
 // Custom TrustManagerFactory that trusts all certificates
    private static class TrustAllTrustManagerFactory extends TrustManagerFactory {
        protected TrustAllTrustManagerFactory() {
            super(new TrustManagerFactorySpi() {
                @Override
                protected void engineInit(KeyStore keyStore) {
                }

                @Override
                protected void engineInit(ManagerFactoryParameters managerFactoryParameters) {
                }

                @Override
                protected javax.net.ssl.TrustManager[] engineGetTrustManagers() {
                    return new javax.net.ssl.TrustManager[]{
                            new javax.net.ssl.X509TrustManager() {
                                @Override
                                public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
                                }

                                @Override
                                public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
                                }

                                @Override
                                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                                    return new java.security.cert.X509Certificate[0];
                                }
                            }
                    };
                }
            }, null, "TrustAll");
        }
    }

```

And using it like this:

```auto
        // Create an SslContext that trusts all certificates.
        MqttClientSslConfig sslConfig = MqttClientSslConfig.builder()
                .trustManagerFactory(new TrustAllTrustManagerFactory())
                .build();

```
