天天看點

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

前言

今天一個朋友讓我幫他做一下tomcat的https配置,中間遇到了标題中這個錯誤,是以記錄了一下過程,伺服器、域名、證書、tomcat都已經準備好,就是需要配置一下即可,用的是阿裡雲的證書服務,也是通過阿裡雲的證書服務生成的證書檔案。

配置步驟

  • 通過阿裡雲控制台下載下傳tomcat的https證書檔案,證書檔案很多,這裡是點選tomcat選項下的下載下傳按鈕。
    javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
  • 把證書檔案傳到linux伺服器,如

    21xxxxx.zip

  • 進入tomcat安裝目錄,比如

    /opt/tomcat-8.0

    ,并建立cert目錄(這個目錄名可任意設定,用來存放證書),并把證書的壓縮包移到此檔案夾中,解壓。
#進入tomcat目錄
cd /opt/tomcat-8.0
#建立cert目錄
mkdir cert
#進入cert目錄
cd cert
#移動證書檔案至目前目錄
mv /home/user1/21xxxxx.zip ./
#解壓證書檔案
unzip 21xxxxx.zip
           
  • 進入tomcat的配置檔案目錄,修改server.xml配置檔案。
cd /opt/tomcat-8.0/conf
vi server.xml
           
  • 重新開機tomcat伺服器

https方式通路tomcat報錯

初始時的tomcat的配置檔案:

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

由于沒有配置過tomcat的https目錄,是以就直接按照阿裡雲的幫助文檔來配置了,檔案如下:

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

https是443端口,是以将圖中的端口改為443,并将證書名和密碼字段修改即可。

重新開機tomcat伺服器,啟動成功,通過http方式通路正常,但是通過https通路時tomcat控制台出現标題中的這個錯誤:

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

由于是第一次配置tomcat的證書,以往都是通過其他方式,是以也不是十分确定錯誤在哪裡,tomcat版本?或者是jdk版本?腦海中閃過幾個原因,但是通過http通路沒問題,證明隻是和剛剛的https配置有關。

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

解決方案

是以在網絡上查了半天,但是都沒有找到确切的答案,也沒解決掉問題,一段時間無果後,又看了一遍錯誤,

protocol is disabled or cipher suites are inappropriate

,就感覺是不是protocol或者cipher參數配置有問題,然後就開始針對幾個參數做了幾次修改,最終可以正常通過https通路網站了。

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

修改後的配置如下:

<Connector port="443"
    protocol="org.apache.coyote.http11.Http11NioProtocol"
    SSLEnabled="true"
    scheme="https"
    secure="true"
    #證書檔案目錄
    keystoreFile="cert/21xxxxxxx.pfx"
    keystoreType="PKCS12"
    #密碼
    keystorePass="21xxxxxxx"
    clientAuth="false"
    SSLProtocol="TLSv1+TLSv1.1+TLSv1.2"
/>
           

與阿裡雲給出的配置有些不同,protocol參數由"HTTP/1.1"修改為"org.apache.coyote.http11.Http11NioProtocol",ciphers參數删除了,SSLCipherSuite也删除了,可以通過https方式正常通路了。

我曾七次鄙視自己的靈魂:

第一次,當它本可進取時,卻故作謙卑;

第二次,當它空虛時,用愛欲來填充;

第三次,在困難和容易之間,它選擇了容易;

第四次,它犯了錯,卻借由别人也會犯錯來寬慰自己;

第五次,它自由軟弱,卻把它認為是生命的堅韌;

第六次,當它鄙夷一張醜惡的嘴臉時,卻不知那正是自己面具中的一副;

第七次,它側身于生活的污泥中雖不甘心,卻又畏首畏尾。

繼續閱讀