公司今天一個登陸的地方要修改,需要加一個SSL安全登陸,于是查些資料并總結如下,希望對有用的著的朋友有幫助
文件打包地址:http://m.tkk7.com/Files/lifenote/tomcat配置ssl.rar
一下為幫助說明:
1.1. 安全登錄 SSL
1.1.1 WebLogic下面SSL配置:
1.生成 keystoreFile:
* keystoreFile 文件的生成:
%Java_Home%\bin\keytool -genkey -alias localhost-weblogic -keyalg RSA -validity 365 -keystore ./testKey.jks
* csr 文件的生成:
%Java_Home%\bin\keytool -certreq -alias localhost-weblogic -sigalg MD5withRSA -file ./testServer.csr -keystore ./testKey.jks
* 注意: http 的默認端口是80,https 的默認端口是433,ftp 的默認端口是21。
2.部署keystore 文件
在 <http://hostname:7001/console> 中配置剛才生成的 testKey.jks 文件。
1.1.2 Tomcat 下面SSL配置
1.生成 keystoreFile:
* keystoreFile 文件的生成:
%Java_Home%\bin\keytool -genkey -alias localhost-weblogic -keyalg RSA -validity 365 -keystore ./testKey.jks
Example for inner test:
[root@localhost ~]#
/home/tomcat/jdk1.5.0_12/bin/keytool -genkey -alias localhost-tomcat -keyalg RSA -validity 365 -keystore /home/tomcat/apache-tomcat-5.5.23/conf/VCMarketKey.jks
Enter keystore password: someday2007
What is your first and last name?
[Unknown]: lifenote
What is the name of your organizational unit?
[Unknown]: Java
What is the name of your organization?
[Unknown]: Sunxc
What is the name of your City or Locality?
[Unknown]: Beijing
What is the name of your State or Province?
[Unknown]: Beijing
What is the two-letter country code for this unit?
[Unknown]: ZH
Is CN=lifenote, OU=Java, O=Sunxc, L=Beijing, ST=Beijing, C=ZH correct?
[no]: y
Enter key password for <localhost-tomcat>
(RETURN if same as keystore password): someday2007
[root@localhost ~]#
* csr 文件的生成:
%Java_Home%\bin\keytool -certreq -alias localhost-weblogic -sigalg MD5withRSA -file ./testServer.csr -keystore ./testKey.jks
* 注意: http 的默認端口是80,https 的默認端口是433,ftp 的默認端口是21。
2.部署keystore 文件
打開 server.xml 文件,修改內容如下:
* 只需去掉 server.xml 中對SSL定義的注釋,在加上 keystoreFile、keystorePass 這兩個屬性即可。
<Service
name="Catalina">
<Connector
port="8080"
...
</Connector>
<!-- Define a SSL HTTP/1.1 Connector on port 8443 --------------------- 要加入的內容在這里 -->
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="e:/temp_E/ssl/testKey.jks"
keystorePass="aaaaaa"/>
<Connector
port="8009"
...
</Connector>
...
Example for inner test:
<Connector port="443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/home/tomcat/apache-tomcat-5.5.23/conf/VCMarketKey.jks"
keystorePass="password"/>
注意需默認要使用 443 而不是 8443,要使用8443要在apache中配置,保證從apache請求tomcat 采用 <https://ip:8443/>... 的格式。
1.1.3 使用http訪問WebService s的客戶端配置
Servlet服務器配置好SSL之后,客戶端可以使用https訪問了。
對于用戶使用瀏覽器訪問https的方式,瀏覽器會彈出安裝證書的對話框,確認之后可以正常使用https訪問。
對于WebService 通過https方式訪問,按照一下步驟:
1. WebService客戶端要先取得keyStore文件;
2. 虛擬機系統使用 System.setProperties(…) 設置keyStore信息;
3. 使用 url=<https://ip:port/...> 訪問WebService服務