阿里云
发表主题 回复主题
  • 476阅读
  • 5回复

求No trusted certificate found解决方案

级别: 小白
发帖
0
云币
-16
调用交通银行支付接口查询

    String srcUrl = "https://ebank.95559.com.cn/corporbank/NsTrans?dse_operationName=cb2202_queryOrderOp&reqData=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22gb2312%22%3F%3E%3CBOCOMB2C%3E%3CopName%3Ecb2202_queryOrderOp%3C%2FopName%3E%3CreqParam%3E%3CmerchantID%3E301440360129520%3C%2FmerchantID%3E%3Cnumber%3E1%3C%2Fnumber%3E%3Cdetail%3E1%3C%2Fdetail%3E%3Corders%3EC20091030000001%3C%2Forders%3E%3C%2FreqParam%3E%3C%2FBOCOMB2C%3E&signData=MIIE%2FgYJKoZIhvcNAQcCoIIE7zCCBOsCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCCA%2BUwggPhMIICyaADAgECAgRMXdLhMA0GCSqGSIb3DQEBBQUAMDUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKEwtCQU5LQ09NTSBDQTEQMA4GA1UEAxMHQk9DT01DQTAeFw0wOTA5MjIwNzMxMzhaFw0xMTA5MjIwNzMxMzhaMIGAMQswCQYDVQQGEwJDTjEUMBIGA1UEChMLQkFOS0NPTU0gQ0ExETAPBgNVBAsTCEJBTktDT01NMRIwEAYDVQQLEwlNZXJjaGFudHMxNDAyBgNVBAMTKzA0MEAwMTQ0MDQwMDAwMDE1MjcxNkBbMzAxNDQwMzYwMTI5NTIwXUAwMDAwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALglwOl2sLwGJ8JiaHp4DtjVygLat2b6ZEvk7qD2heCbpB1CVwhFRvXD8v7Ly%2FQgxjG3G4Z6RuT51f2DLuDACIDTreFTxCvRQIxQA3OYGVnqyq3CC3Qc5kYy6olGGpPYAnoODADchG7jiAFDqU%2FPpvEUuMmhUENoxzIllxQMgSwRAgMBAAGjggEvMIIBKzAfBgNVHSMEGDAWgBTSs9GxOUepN3l34y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3D%3D";



===========================简化后的相关代码==================

import java.io.InputStream;

import java.net.HttpURLConnection;

import java.net.URL;


        HttpURLConnection connection = null;

        InputStream in = null;

          URL url = new URL(srcUrl);

connection = (HttpURLConnection) url.openConnection();

connection.setRequestProperty("User-Agent", "Mozilla/MSIE");

in = connection.getInputStream();

          in.read(,,,,);

===============================================================


以上程序在开发环境(SUN JDK1.5 + Tomcat5.0)上可以正常运行,获得反馈结果。


部署到生产环境(Ibm JDK1.5 + WebSpere),报异常


javax.net.ssl.SSLHandshakeException: com.ibm.jsse2.util.h: No trusted certificate found

at com.ibm.jsse2.n.a(n.java:17)

at com.ibm.jsse2.jc.a(jc.java:541)

at com.ibm.jsse2.db.a(db.java:403)

at com.ibm.jsse2.db.a(db.java:278)

at com.ibm.jsse2.eb.a(eb.java:137)

at com.ibm.jsse2.eb.a(eb.java:157)

at com.ibm.jsse2.db.m(db.java:243)

at com.ibm.jsse2.db.a(db.java:280)

at com.ibm.jsse2.jc.a(jc.java:104)

at com.ibm.jsse2.jc.g(jc.java:470)

at com.ibm.jsse2.jc.a(jc.java:284)

at com.ibm.jsse2.jc.startHandshake(jc.java:172)

at com.ibm.net.ssl.www2.protocol.https.b.afterConnect(b.java:65)

at com.ibm.net.ssl.www2.protocol.https.c.connect(c.java:3)

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:942)

at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:1895)

at java.net.URLConnection.getHeaderFieldInt(URLConnection.java:585)

at java.net.URLConnection.getContentLength(URLConnection.java:480)

at com.ibm.net.ssl.www2.protocol.https.a.getContentLength(a.java:28)



第一修改方案,在执行查询之前,指定Provider、系统属性,结果:失败。异常信息同楼上。


Security.addProvider(new com.ibm.jsse.IBMJSSEProvider());

System.setProperty("java.protocol.handler.pkgs","com.ibm.net.ssl.internal.www.protocol");



第二修改方案,指定密钥库、信任库。结果:失败。异常同顶楼。


public SSLSocketFactory getSSLSocketFactory() {

SSLSocketFactory sslSocketFactory = null;


String keystore = ".....";

String truststore = ".....";

        String keypass="....";


try {

    KeyStore ks = KeyStore.getInstance("JKS\");

    ks.load(new FileInputStream(keystore), keypass.toCharArray());

    KeyManagerFactory kmf = KeyManagerFactory.getInstance("IbmX509");

    kmf.init(ks,keypass.toCharArray());


    KeyStore ts = KeyStore.getInstance("JKS");

    ts.load(new FileInputStream(truststore),trustpass.toCharArray());

    TrustManager[] tm;

    TrustManagerFactory tmf = TrustManagerFactory.getInstance("IbmPKIX");

    tmf.init(ts);

    tm = tmf.getTrustManagers();


    SSLContext sslContext = SSLContext.getInstance("SSL");

    sslContext.init(kmf.getKeyManagers(), tm, null);


    sslSocketFactory = sslContext.getSocketFactory();

} catch (Exception e) {

    e.printStackTrace();

}

return sslSocketFactory;

}


public String sendAndReceive(String srcUrl) {

SSLSocketFactory factory = getSSLSocketFactory();

HttpsURLConnection connection = null;

InputStream in = null;


        URL url = new URL(srcUrl);


connection = (HttpsURLConnection) url.openConnection();

connection.setSSLSocketFactory(factory);


connection.setRequestProperty("User-Agent", "Mozilla/MSIE");

int contentLen = connection.getContentLength();

in = connection.getInputStream();

        in.read(,,,,);



补充说明,已将交行提供的root.cer导入到WebSpere运行依赖的JVM下的cacerts文件中


trusted, found, 解决方案, 调用, 交通






级别: *
发帖
*
云币
*


这问题有点奇怪
级别: *
发帖
*
云币
*


请各位大侠不吝指教,万分感谢
级别: *
发帖
*
云币
*




能分享一下你的问题是怎么解决的吗。。。我现在也出这个问题,查了很多地方也没有有用的信息
级别: *
发帖
*
云币
*


nice job
级别: *
发帖
*
云币
*


等到有建设性的讨论回帖再把我的解决方案拿出来讨论
发表主题 回复主题
« 返回列表
«12345678910»
共10页
上一主题下一主题

限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
验证问题: ECS是阿里云提供的什么服务? 正确答案:云服务器
上一个 下一个
      ×
      全新阿里云开发者社区, 去探索开发者的新世界吧!
      一站式的体验,更多的精彩!
      通过下面领域大门,一起探索新的技术世界吧~ (点击图标进入)

      版权声明

      开发者论坛为你提供“求No trusted certificate found解决方案”的内容,论坛中还有更多关于 urlconnectionjks#jks URLConnection java调用https 的内容供你使用,该内容是网友上传,与开发者论坛无关,如果需要删除请联系zixun-group@service.aliyun.com,工作人员会在5个工作日内回复您。