小新 的 BLOG
            
            -=java、Web编程=-

让ibmjdk1.3.1也支持jsse

让ibmjdk1.3.1也支持jsse
还好我没有放弃最初的方案,找出替代方案,但是原先的方案还有一线希望,竟然可以了,终于跨过了这个小山坡!


这个ibmjdk1.3版本让我上个星期也够郁闷的了,搞好久。原以为,都是一样的接口,谁实现都一样,可是就是不一样,在ibm的jdk上配置sun的jsse就是不行,死活不行。
不过ibm也是够恶心的,官方网站上根本没有提供JSSE包的下载,反倒有也是指向sun公司的下载地址,误导了我好长时间!最后实在是没有办法了,抱着试试看的心态找看看ibm的jsse。自己的机器也没有安装websphere,想websphere应该有jsse相关的包,通过友人获取该包,并部署在jvm/lib/ext目录下,竟然成功了!

状态1-》n、使用sun的jsse类包,汗,尝试n种方法以失败告终!

java.net.MalformedURLException: unknown protocol: https  

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

java.net.SocketException: Algorithm SSL not available            使用ibmjsse.jar
------------------------
状态n+1、unknown certificate系统已经成功配置了JSSE环境,缺乏证书
异常消息:
javax.net.ssl.SSLHandshakeException: unknown certificate
 at com.ibm.jsse.bf.a(Unknown Source)
 at com.ibm.jsse.bf.startHandshake(Unknown Source)
 at com.ibm.net.ssl.www.protocol.https.b.n(Unknown Source)
 at com.ibm.net.ssl.www.protocol.https.p.connect(Unknown Source)
 at com.ibm.net.ssl.www.protocol.http.bw.getOutputStream(Unknown Source)
 at com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection.getOutputStream(Unknown Source)
 at com.longtop.security.URLReader.main(URLReader.java:29)
Exception in thread "main"
解决方法:
1、往信任库里添加证书
keytool -import -noprompt -keystore cacerts -storepass changeit -alias xyhuang-longtop-ks -file xyhuang.cer
2、修改实现自动接受证书(安全风险)X509TrustManager


以下为最终的连接代码
  System.setProperty("java.protocol.handler.pkgs",
    "com.ibm.net.ssl.internal.www.protocol");
  if (Security.getProvider("com.ibm.jsse.IBMJSSEProvider") == null)
   Security.addProvider(new IBMJSSEProvider());
  URL url = new URL("https://msxyhuang.xyhuang.com:443/cas1/index.asp");
  String poststr = "name=new&ccc=ddd";
  URLConnection conn = url.openConnection();
  if (conn == null) {
   return;
  }
  conn.setDoOutput(true);

  PrintStream pout = new PrintStream(conn.getOutputStream());
  pout.print(poststr);
  pout.close();

  BufferedReader reader = new BufferedReader(new InputStreamReader(conn
    .getInputStream()));
  String line = null;
  while ((line = reader.readLine()) != null) {
   System.out.println(line);
  }
  reader.close();

输出结果:huangxinyi

asp的代码
<%@ Language=VBScript %>
<%
Dim name
Set name = Request.Form("name")
if name = "new" then
 Response.write "huangxinyi"
elseif name = null or name = "" then
 Response.write "null"
else
 Response.write "bluelover"
end if

%>

标签集:TAGS:
回复Comments()点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}
  用户登录
用户名
密 码
选 项:
 
  我的日历
  分类日志
  访问计数
  获取 RSS
bluelover 最新的 20 条日志
  最新评论
  友情链接
  联系我
                  GMail:bluelover@gmail.com
MSN:xini_huang@hotmail.com
QQ:85364603
Modified by blueloverPowered by 5DBlog.com