tomcat https/ssl 服務配置(帶有雙向驗證,windows,linux平台驗證通過)

來源:互聯網
上載者:User

標籤:


1. 建立伺服器密鑰,其密鑰庫為 /home/gr/server.ks

    PS1: 注意keypass和storepass保持一致,它們分別代表 密鑰密碼和密鑰庫密碼,
    PS2: 注意 CN=localhost 中,localhost表示要配置SSL的主機名稱,不能任意指定
    
    ~$keytool -genkey -v -alias serverKey -dname "CN=192.168.10.101" -keyalg RSA -keypass 123456 -keystore server.ks -storepass 123456
    
2.  建立用戶端密鑰,其密鑰庫為  /home/gr/client.p12,注意這個密鑰庫的尾碼名,注意密鑰庫類型PKCS12

    ~$keytool -genkey -v -alias clientKey -dname "CN=SomeOne" -keyalg RSA -keypass 654321 -keystore client.p12 -storepass 654321 -storetype PKCS12
    
3.  將用戶端密鑰匯出為認證檔案(在下一步要用到這裡產生的檔案)

    ~$keytool -export -alias clientKey -file client.cer -keystore client.p12 -storepass 654321 -storetype PKCS12
    
4.  將上述用戶端密鑰檔案匯入伺服器憑證庫,並設定為信任認證

    PS: 注意會問你是否信任該認證,回答 y 即可
    
    ~$keytool -import -v -alias client -file client.cer -keystore server.ks -storepass 123456
    
5. 為了在瀏覽器中進行SSL訪問,請在瀏覽器中匯入 用戶端密鑰庫檔案client.p12

    5.1 linux平台
        chrome :        設定--進階--HTTPS/SSL--管理憑證--您的認證,匯入 client.p12
        firefox:        喜好設定--進階--認證--查看認證--您的認證,匯入 client.p12
    5.2 windows平台
        IE:            Internet選項--內容--認證--個人,匯入 client.p12
        chrome:        選項--進階--認證--查看認證--您的認證,匯入 client.p12
        firefox:        設定--進階--HTTPS/SSL--管理憑證--個人,匯入 client.p12

6.  配置TOMCAT伺服器,以支援SSL認證,編輯檔案:%tomcat_home%/conf/server.xml

    6.1 下面這段配置代碼本來是被屏蔽的,現在請取消其屏蔽,並相應增加密鑰庫的配置,其中clientAuth="true" 用以啟動雙向認證,否則,只有用戶端證明伺服器-單向

    6.2 修改後的內容是

        <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
            maxThreads="150" scheme="https" secure="true"
            clientAuth="true" sslProtocol="TLS"
            keystoreFile="/home/gr/server.ks" keystorePass="123456"
            truststoreFile="/home/gr/server.ks" truststorePass=" 123456" />
            
    6.3 屬性說明
    
        clientAuth:設定是否雙向驗證,預設為false,設定為true代表雙向驗證
        keystoreFile:伺服器憑證檔案路徑
        keystorePass:伺服器憑證密碼
        truststoreFile:用來驗證用戶端認證的根憑證,此例中就是伺服器憑證
        truststorePass:根憑證密碼
            

7. 啟動 TOMCAT,然後在IE瀏覽器中訪問:https://localhost:8443/項目名稱


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

tomcat https/ssl 服務配置(帶有雙向驗證,windows,linux平台驗證通過)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.