tomcat 配置https + 數字證書認證

生成服務端證書
keytool -genkey -alias tomcat -keypass 123456 -keyalg RSA -keysize 1024 -validity 365 -keystore D:/keys/tomcat.keystore -storepass 123456
客戶端證書
keytool -genkey -alias client -keypass 123456 -keyalg RSA -keysize 1024 -validity 365 -storetype PKCS12 -keystore D:/keys/client.p12 -storepass 123456
客戶端證書導出爲一個單獨的CER文件
keytool -export -alias client -keystore D:/keys/client.p12 -storetype PKCS12 -keypass 123456 -file D:/keys/client.cer
服務端添加客戶端信任
keytool -import -v -file D:/keys/client.cer -keystore D:/keys/tomcat.keystore
查看證書內容
keytool -list -v -keystore D:/keys/tomcat.keystore
導出服務端公鑰
keytool -keystore D:/keys/tomcat.keystore -export -alias tomcat -file D:/keys/server.cer

<Connector  
port="8443"
protocol="org.apache.coyote.http11.Http11NioProtocol" 
SSLEnabled="true"
maxThreads="150"
scheme="https"
secure="true"
clientAuth="true"
sslProtocol="TLS"
keystoreFile="D:/keys/tomcat.keystore"
keystorePass="123456"
truststoreFile="D:/keys/tomcat.keystore"
truststorePass="123456" />

</welcome- file-list> 後面加上這

<login-config>   
<!-- Authorization setting for SSL -->   
<auth-method>CLIENT-CERT</auth-method>   
<realm-name>Client Cert Users-only Area</realm-name>   
</login-config>   
<security-constraint>   
<!-- Authorization setting for SSL -->   
<web-resource-collection >   
<web-resource-name >SSL</web-resource-name>   
<url-pattern>/*</url-pattern>    
</web-resource-collection>   
<user-data-constraint>   
<transport-guarantee>CONFIDENTIAL</transport-guarantee>   
</user-data-constraint>   
</security-constraint>
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章