我有一段代碼將有效負載發送到https端點(或應該)。我也有一個.pem格式的CA鏈,我在代碼中嘗試添加它,並使用它來執行POST。使用httpClient和cert.em發送https請求
HttpClient client = new HttpClient();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String jsonString = gson.toJson(parentData);
Properties systemProps = System.getProperties();
systemProps.put("javax.net.ssl.trustStore", "/Users/kaulk/Downloads/djca-2048.pem");
systemProps.put("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.keyStoreType","pkcs12");
System.setProperties(systemProps);
PostMethod method = new PostMethod("https://beta.fcm.fint.xxx.net/notify/BuildNotification");
StringRequestEntity requestEntity = new StringRequestEntity(
jsonString,
"application/json",
"UTF-8");
method.setRequestEntity(requestEntity);
int statusCode = client.executeMethod(method);
但它失敗,錯誤:
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl) at java.security.Provider$Service.newInstance(Provider.java:1245) at sun.security.jca.GetInstance.getInstance(GetInstance.java:220) at sun.security.jca.GetInstance.getInstance(GetInstance.java:147) at javax.net.ssl.SSLContext.getInstance(SSLContext.java:125) at javax.net.ssl.SSLContext.getDefault(SSLContext.java:68) at javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:102) ... 22 more Caused by: java.io.IOException: Invalid keystore format
任何原因?
trustStoreType應該是什麼? pkcs12或jks? – Scooby
它應該是默認的jks - http://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#Customization –
但它應該取決於您的證書文件格式 - https ://docs.oracle.com/cd/E29585_01/PlatformServices.61x/security/src/tsec_ssl_jsp_pkcs12.html –