美文网首页
Paho Mqtt SSL连接时常见异常问题以及解决方案

Paho Mqtt SSL连接时常见异常问题以及解决方案

作者: 花生草 | 来源:发表于2021-02-23 15:28 被阅读0次

    在使用Mqtt的SSL方式连接时遇到了如下问题:

    java.security.cert.CertificateException: No name matching *** found

    说明使用SSL连接配置中的TrustManager里的server验证失败,即服务端证书签名时用的host和现在签名的host不是同一个。如果是HTTPS,可以通过重写hostNameVerifyer的方法来解决问题,网上有很多攻略
    对于Mqtt连接时遇到这个问题,应该检查是否pom.xml中依赖的版本有冲突。经实际验证,paho的版本使用较新版本时会遇到这个问题(无论证书是正确/错误,均优先报no name mathing错误,推测是较低版本的校验机制较弱)因此可以参考下面的搭配,使用较低版本跳过这个错误。因为暂未找到mqtt ssl连接时忽略host验证的方法

    java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors

    对于Mqtt连接时遇到这个问题,应该检查是否现在所使用的证书,和服务器端的证书不是同一个。这一次就栽在这个问题上了

    连接时org.eclipse.paho.client.mqttv3.MqttSecurityException: Not authorized to connect .
    检查clientId是否是有效的

    pom.xml文件中的依赖:

       <dependency>
                <groupId>org.eclipse.paho</groupId>
                <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
                <version>1.2.0</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
            <dependency>
                <groupId>org.bouncycastle</groupId>
                <artifactId>bcpkix-jdk15on</artifactId>
                <version>1.64</version>
            </dependency>
    

    相关文章

      网友评论

          本文标题:Paho Mqtt SSL连接时常见异常问题以及解决方案

          本文链接:https://www.haomeiwen.com/subject/duwrfltx.html