【问题标题】:Secure WebSocket with valid Namecheap Certificate - CertPathValidatorException: Trust anchor for certification path not found使用有效的 Namecheap 证书保护 WebSocket - CertPathValidatorException:找不到证书路径的信任锚
【发布时间】:2015-04-17 21:13:09
【问题描述】:

我从 namecheap.com 为我的域 neelo.de 购买了有效的通配符证书。现在我尝试通过 Android 的 WSS 进行连接,但总是得到“javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certificate path not found.”。但我不知道为什么。证书不是自签名的,我从谷歌阅读了文档:https://developer.android.com/training/articles/security-ssl.html

但这些问题只能通过自签名证书调用。我用nodejs试了一下,效果很好:

WebSocket = require "ws"
ws = new WebSocket("wws://api.neelo.de")

ws.on "open", -> console.log "OPEN"
ws.on "close", -> console.log "CLOSE"
ws.on "error", (err) -> console.log err
ws.on "message", (data) -> console.log data

这是我用于加载密钥库的 android 代码:

public WebSocketClient(Context context) throws Exception {
    super(new URI("wss://api.neelo.de"), new Draft_76());
    this.context = context;
    this.messageReceiver = messageReceiver;
    configureKeyStore();
  }

  void configureKeyStore() throws Exception {
    Log.d(TAG, "Configure key store");

    KeyStore ks = KeyStore.getInstance(STORE_TYPE);
    InputStream in = getContext().getResources().openRawResource(R.raw.android_keystore);

    ks.load(in, STORE_PASSWORD.toCharArray());
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    kmf.init(ks, STORE_PASSWORD.toCharArray());
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmf.init(ks);

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

    SSLSocketFactory factory = sslContext.getSocketFactory();

    super.setSocket(factory.createSocket());
    }

有人有想法吗?感谢帮助!这个问题已经花了我 3 天的时间......

【问题讨论】:

    标签: java android websocket ssl-certificate


    【解决方案1】:

    现在我尝试通过 Android 上的 WSS 进行连接,但总是得到 javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found

    我相信你有三个选择。

    首先,在您的 Android 设备上安装 Namecheap 使用的根目录。不幸的是,I can't find the download page for their root ca。他们是在转售别人的warez 吗?

    其次,使用预装了根的 CA 的通配符证书。为此,我推荐Startcom。大多数移动和桌面浏览器都预装并信任他们的 CA。我推荐他们,因为他们提供免费的 1 类证书(如果需要,他们会收取撤销费用)。

    第三,使用自定义信任库。例如,请参阅Using a Custom Certificate Trust Store on Android

    【讨论】:

      猜你喜欢
      • 2017-10-03
      • 2015-05-30
      • 2021-03-18
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 2020-04-25
      • 2014-01-29
      相关资源
      最近更新 更多