需要预置CA中心的根证书(多个),然后验证这些CA中心发的证书。根证书都是公开的,可以从CA中心的网站下载

解决方案 »

  1.   

    http://blog.sina.com.cn/s/blog_51a7b40e010100kn.html别人的代码你搜索“ java 证书链”
      

  2.   

    如果我想在发url链接的时候来验证证书的合法性呢?也就是浏览器端验证我该如何做?我该如何修改下面的代码?
    SSLContextBuilder builder = new SSLContextBuilder();
    builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());  //这里自签名信任了。
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    CloseableHttpClient client = HttpClients.custom().setSSLSocketFactory(sslsf).build();
    HttpPost httpPost = new HttpPost(url);
    CloseableHttpResponse httpResp = client.execute(httpPost);
    try {
    code = httpResp.getStatusLine().getStatusCode();
    HttpEntity entity = httpResp.getEntity();
    if (entity != null) {
    resp = EntityUtils.toString(entity);
    }
    } finally {
    httpResp.close();
    client.close();
    }
    如果我想在上面的代码验证证书改如何做?