在區域網路内實作https安全通路
準備原料
伺服器 resin (當然也可以是tomcat,這裡以resin為例)
安裝jdk
域名 (随便寫一個就行,因為是内網使用,不會被校驗)
生成證書
- 第一步:為伺服器生成證書
keytool -genkey -alias resin -keypass 123456 -keyalg RSA -keysize 1024 -validity 365 -keystore D:/keys/resin.keystore -storepass 123456
- 第二步:為用戶端生成證書
keytool -genkey -alias client1 -keypass 123456 -keyalg RSA -keysize 1024 -validity 365 -storetype PKCS12 -keystore D:/keys/client1.p12 -storepass 123456
- 第三步:讓伺服器信任用戶端證書
keytool -export -alias client1 -keystore D:/keys/client1.p12 -storetype PKCS12 -keypass 123456 -file D:/keys/client1.cer
keytool -import -v -file D:/keys/client1.cer -keystore D:/keys/resin.keystore -storepass 123456
- 第四步:讓用戶端信任伺服器證書
keytool -list -v -keystore D:/keys/resin.keystore
keytool -keystore D:/keys/resin.keystore -export -alias resin -file D:/keys/server.cer
注意:當提示:您的名字與姓氏是什麼? 請輸入你準備的域名比如:www.aclululu.com
其他的按照提示輸入就是了,最後會得到四個檔案如下:
生成用戶端安裝證書
- 輕按兩下server.cer檔案,按預設安裝,直到安裝成功
- 打開IE浏覽器,找到證書
- 選擇導出,導出的證書即可用于其他客戶進行安裝使用。這裡命名為aclululu_client
配置伺服器端resin
早期的版本,因為沒有最新的,是以請見諒!
resin.conf檔案具體需要修改的地方
- 配置https證書
<http address="*" port="443">
<jsse-ssl>
<key-store-type>jks</key-store-type>
<key-store-file>keys/resin.keystore</key-store-file>
<password>123456</password>
</jsse-ssl>
</http>
- 配置更新
<session-config>
<session-timeout>-1</session-timeout>
<enable-url-rewriting>false</enable-url-rewriting>
<reuse-session-id>false</reuse-session-id>
<cookie-secure >true</cookie-secure>
</session-config>
- 配置httpOnly請求
<cookie-http-only>true</cookie-http-only>
- 配置secure屬性
<secure>true</secure>
客戶機安裝證書,修改host檔案(注意客戶機)
打開IE浏覽器,導入證書
按照預設導入剛剛儲存的aclululu_client證書。直到導入成功。
修改host檔案
假如伺服器的ip為:172.16.1.123
方法一:
修改批處理檔案:aclululu_host.bat
@echo off
color 0F
@attrib -r "%windir%\system32\drivers\etc\hosts"
@echo= >>"%windir%\system32\drivers\etc\hosts"
@echo= >>"%windir%\system32\drivers\etc\hosts"
@echo #Fssoft Start >>"%windir%\system32\drivers\etc\hosts"
@echo 172.16.1.123 www.aclululu.com>>"%windir%\system32\drivers\etc\hosts"
@echo #Fssoft End >>"%windir%\system32\drivers\etc\hosts"
@echo= >>"%windir%\system32\drivers\etc\hosts"
@echo= >>"%windir%\system32\drivers\etc\hosts"
@attrib +r "%windir%\system32\drivers\etc\hosts"
然後輕按兩下執行bat即可
方法二:
直接去
C:\Windows\System32\drivers\etc下手動修改
通路
https
就可以安全通路172.16.1.123這台主機上的網頁了