星期一, 7月 11, 2011

[Java] 實作HTTPS Request

最近的專案為了確保網路資料傳輸的安全性,使用了SSL來加密,
原本實作的RESTful Client(Java HttpsURLConnection)模擬request時,伺服器回應了以下錯誤:

javax.servlet.ServletException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
 com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:418)
 com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
 com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Google了一下找到了這篇文章:



http://smilelifes.blogspot.com/2007/04/unable-to-find-valid-certification-path.html
由於系統加上了SSL加密機制且Certificate是自已作的,導致Java無法得知去哪裡找到Certificate?
所以需要將當初建立的ca certificate 匯入到JDK內部的cacerts中即可解決!!

keytool -import -file myca.cert -keystore %JAVA_HOME%\jre\lib\security\cacerts -file myca.cert -alias tomcat

2 則留言:

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails