利用openssl簽署多域名證書

    openssl自建CA默認簽署的是單域名證書,因爲單臺服務器上有多個https域名,簽署多域名證書能方便很多,今天找了很久,除了一些賣證書的網站上有scr工具能加“使用者備用名稱”,都沒有找到openssl相關的添加方法。

    後來看openssl.cnf找到一個方法,這裏記錄一下:

    !!這個方法比較笨重,如果有其他方法,歡迎留言給我,感激不盡。

    (已找到,詳見使用openssl爲ssl證書增加“使用者備用名稱(DNS)”)

    主要修改在openssl.cnf

        將文件中原來的

commonName                    = Common Name (eg, your name or your server\'s hostname)

commonName_max                = 64

修改爲

0.commonName                    = Common Name (eg, your name or your server\'s hostname)
0.commonName_max                = 64

就是在前面加了個 “0.”,好了,如果要添加其他域名,只需要再增加相同的記錄,前面的序號依次遞增即可:

0.commonName                    = Common Name (eg, your name or your server\'s hostname)
0.commonName_max                = 64
1.commonName                    = other  Common Name

1.commonNAme_max                = 64

......


其他的步驟:

openssl.cnf中會要求部分文件及目錄存在:

[root@localhost]#mkdir -p CA/{certs,crl,newcerts,private}

[root@localhost]# touch CA/index.txt

[root@localhost]#echo 00 > CA/serial


1.生成ca.key並自簽署

openssl req -new -x509 -days 3650 -keyout ca.key -out ca.crt -config openssl.cnf


2.生成server.key(名字不重要)

openssl genrsa -out server.key 2048

3.生成證書籤名請求
openssl req -new -key server.key -out server.csr -config openssl.cnf

Common Name 就是在這一步填寫的,每次一個,如果沒有那麼多,可以直接回車


4.使用自簽署的CA,簽署server.scr

openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config openssl.cnf
#輸入第一步設置的密碼,一直按y就可以了


server.crt server.key就是web服務器中使用的文件。


NGINX 雙向認證

如果要做NGINX客戶端證書驗證的話,重複2、3、4,並執行下面命令生成個人證書

openssl  pkcs12 -export -inkey server.key -in server.crt -out  server.p12

將個人證書導入pc,同時在nginx ssl基礎上增加設置:

ssl_verify_client on;
ssl_client_certificate ca.crt;


另外:nginx的雙向認證是相對獨立的,你可以在驗證server端用你購買的ssl證書,然後在驗證客戶端用自簽名的ca和證書。

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