2010-11-29 95 views
14

我有一個Java應用程序訪問使用StartCom SSL證書的服務。爲此,我需要將StartCom CA證書添加到Java的信任庫,因爲它們尚未默認存在。我已經成功地做到了在Linux上使用這些命令在Windows中導入StartCom CA證書JRE

sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias startcom.ca -file ca.crt 
sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias startcom.ca.sub.class1 -file sub.class1.server.ca.crt 
sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias startcom.ca.sub.class2 -file sub.class2.server.ca.crt 
sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias startcom.ca.sub.class3 -file sub.class3.server.ca.crt 
sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias startcom.ca.sub.class4 -file sub.class4.server.ca.crt 

(從this script

同樣的命令(適當調整),不能在Windows然而工作。我得到:

keytool error: java.lang.RuntimeException: Usage error, trustcacerts is not a legal command 

如何使它工作?

+0

嗨,我仍然得到錯誤.. 如何解決它。苛刻的拉瓦爾。 – 2010-12-06 05:22:05

回答

5

這是一個簡單的錯字。在轉換命令時,我在「trustcacerts」之前忘記了一個短劃線。 :(

0

刪除-trustcacerts

0

是,-trustcacerts是正確的語法

但對於鏈接腳本在Cygwin下工作,你需要從所有keytool行刪除sudo - 。sudo是在Cygwin中不可用

2

在Mac OS X小牛10.9我這樣做:

我總是讓我後來刪除tmp目錄,但你不必:

mkdir ~/tmp 
cd ~/tmp 

然後下載證書:

curl http://www.startssl.com/certs/ca.crt -O 
curl http://www.startssl.com/certs/sub.class1.server.ca.crt -O 
curl http://www.startssl.com/certs/sub.class2.server.ca.crt -O 
curl http://www.startssl.com/certs/sub.class3.server.ca.crt -O 
curl http://www.startssl.com/certs/sub.class4.server.ca.crt -O 

讓您的Java主:

$ /usr/libexec/java_home 
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home 

使用密鑰工具來安裝它:

sudo keytool -import -trustcacerts -keystore /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/securitycacerts -storepass changeit -noprompt -alias startcom.ca -file ca.crt 

sudo keytool -import -trustcacerts -keystore /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/security/cacerts -storepass changeit -noprompt -alias startcom.ca.sub.class1 -file sub.class1.server.ca.crt 

sudo keytool -import -trustcacerts -keystore /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/securitycacerts -storepass changeit -noprompt -alias startcom.ca.sub.class2 -file sub.class2.server.ca.crt 

sudo keytool -import -trustcacerts -keystore /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/securitycacerts -storepass changeit -noprompt -alias startcom.ca.sub.class3 -file sub.class3.server.ca.crt 

sudo keytool -import -trustcacerts -keystore /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/securitycacerts -storepass changeit -noprompt -alias startcom.ca.sub.class4 -file sub.class4.server.ca.crt