2014-09-12 57 views
1

我已經寫了這個代碼EJBCA(JBoss的5.1.0.GA-JDK6和EJBCA 4.0.10和OpenJDK的-6-jdk的。)通信服務器:Java異常客戶端身份驗證TLS:密碼不能爲空

CryptoProviderTools.installBCProvider();  
String urlstr = "https://ejbca05:8443/ejbca/ejbcaws/ejbcaws?wsdl"; 

System.setProperty("javax.net.ssl.trustStore","C:\\Users\\l.\\keystore.jks"); 
System.setProperty("javax.net.ssl.trustStorePassword","provae); 
System.setProperty("javax.net.ssl.keyStore","C:\\Users\\l.\\keystore.jks"); 
System.setProperty("javax.net.sslews.keyStorePassword","provae"); 
QName qname = new QName("http://ws.protocol.core.ejbca.org/", "EjbcaWSService"); 
EjbcaWSService service = null; 
try { 
    service = new EjbcaWSService(new URL(urlstr),qname); 
} catch (MalformedURLException e) { 
    // TODO Auto-generated catch block 
    System.out.println("errore nell'url"); 
} 
EjbcaWS ejbcaraws = service.getEjbcaWSPort(); 

但是我有此異常:

Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: https://ejbca05:8443/ejbca/ejbcaws/ejbcaws?wsdl. It failed with: 
    Got java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext) while opening stream from https://ejbca05:8443/ejbca/ejbcaws/ejbcaws?wsdl. 
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:173) 
.......... 
....... 
Caused by: java.security.UnrecoverableKeyException: Password must not be null 
    at sun.security.provider.JavaKeyStore.engineGetKey(JavaKeyStore.java:124) 
    at sun.security.provider.JavaKeyStore$JKS.engineGetKey(JavaKeyStore.java:55) 
    at java.security.KeyStore.getKey(KeyStore.java:792) 

的密鑰庫superadmin.p12轉換在JKS ....我還試圖與EJBCA或與密鑰工具創建的其他密鑰庫,但我得到同樣的錯誤。 任何人都知道爲什麼?

+0

您不應該對密鑰庫和信任庫使用相同的文件。你的代碼不能編譯。 – EJP 2017-11-14 06:42:07

回答

0

使用此代碼似乎工作

String urlstr = "https://ejbca05.prv:8443/ejbca/ejbcaws/ejbcaws?wsdl"; 
     System.setProperty("javax.net.ssl.trustStore","C:/Users/l./Downloads/truststore.jks"); 
     System.setProperty("javax.net.ssl.trustStorePassword","provae"); 
     System.setProperty("javax.net.ssl.keyStore","C:/Users/l./Downloads/superadmin.p12"); 
     System.setProperty("javax.net.ssl.keyStoreType", "pkcs12"); 
     System.setProperty("javax.net.ssl.keyStorePassword","provae"); 

也許轉換P12爲JKS密鑰庫而不能正常工作。

編輯:有可能convervet使用此命令

keytool -importkeystore -srckeystore [MY_FILE.p12] -srcstoretype pkcs12 
-srcalias [ALIAS_SRC] -destkeystore [MY_KEYSTORE.jks] 
-deststoretype jks -deststorepass [PASSWORD_JKS] -destalias [ALIAS_DEST] 
2

貌似屬性已設置錯誤的JKS

錯誤:

System.setProperty("javax.net.sslews.keyStorePassword","provae"); 

正確的:

System.setProperty("javax.net.ssl.keyStorePassword","provae");