自己生成一個ssl證書,因為是自己生成的所以該證書,不被瀏覽器信任(具體表現https前面有個X)
[root@centos apache-tomcat-6.0.37]# keytool -genkey -alias tomcat -keyalg RSA -keystore /root/tomcat/apache-tomcat-6.0.37/conf/.keystore 輸入keystore密碼: 再次輸入新密碼: 您的名字與姓氏是什么? [Unknown]: free4lab 您的組織單位名稱是什么? [Unknown]: free4lab 您的組織名稱是什么? [Unknown]: free4lab 您所在的城市或區域名稱是什么? [Unknown]: beijing 您所在的州或省份名稱是什么? [Unknown]: beijing 該單位的兩字母國家代碼是什么 [Unknown]: CN CN=free4lab, OU=free4lab, O=free4lab, L=beijing, ST=beijing, C=CN 正確嗎? [否]: y 輸入<tomcat>的主密碼 (如果和 keystore 密碼相同,按回車): [root@centos apache-tomcat-6.0.37]# cat conf/.keystore
然后修改tomcat配置文件server.xml
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" keystoreFile="/root/tomcat/apache-tomcat-6.0.37/conf/.keystore" keystorePass="yourpassword" sslProtocol="TLS" />
通過curl訪問,就忽略驗證證書這一步
[root@f0 huahui]# curl --insecure https://192.168.1.190:8443/
hello huahuiyang
ssl https
這樣瀏覽器訪問就相對安全了,瀏覽器和服務端進行了非對稱加密的握手,然后協商對稱加密的密鑰,然后進行相對快速的對稱加密傳輸。
即時密文在網絡傳輸中被截獲,因為無法獲知對稱密鑰,所以這個http api就是安全的!