效果描述:本地環(huán)境? 兩臺(tái)以上電腦? 可以實(shí)現(xiàn)安裝客戶(hù)端證書(shū)的電腦可以訪(fǎng)問(wèn)springboot啟動(dòng)項(xiàng)目,沒(méi)有安裝客戶(hù)端證書(shū)的電腦無(wú)法訪(fǎng)問(wèn)springboot啟動(dòng)項(xiàng)目
1.操作:需要安裝openssl工具
工具包:Win64OpenSSL_Light-3_3_0.exe 或者Win64OpenSSL_Light-3_3_0.msi?
官網(wǎng):[ Downloads ] - /source/index.html (openssl.org)
驗(yàn)證安裝OK: windows +r 輸入cmd 打開(kāi)dos窗口
輸入openssl -v
出現(xiàn)這個(gè)表示安裝成功
2.在d盤(pán) 目錄 輸入cmd 打開(kāi)dos窗口執(zhí)行一下命令 生成根證書(shū) 服務(wù)端證書(shū)(根證書(shū)簽發(fā)) 客戶(hù)端證書(shū)(根證書(shū)簽發(fā)) 信任庫(kù) ,并將根證書(shū)導(dǎo)入信息庫(kù) 主題-subj可以修改成自己想要的
# 生成根證書(shū)
openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes -key ca.key -subj "/CN=localhost/OU=BESTI/O=DKY/L=SY/ST=LN/C=CN" -days 365 -out ca.crt
# 生成服務(wù)端證書(shū)
openssl genrsa -out server.key 2048
openssl req -new -key server.key -subj "/CN=localhost/OU=BESTI/O=DKY/L=SY/ST=LN/C=CN" -out server.csr
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365
openssl pkcs12 -export -in server.crt -inkey server.key -out server.p12 -name MyServer -password pass:123456
# 生成客戶(hù)端證書(shū)
openssl genrsa -out client.key 2048
openssl req -new -key client.key -subj "/CN=localhost/OU=BESTI/O=DKY/L=SY/ST=LN/C=CN" -out client.csr
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 365
openssl pkcs12 -export -in client.crt -inkey client.key -out client.p12 -name "MyClient" -password pass:123456
# 生成信任庫(kù)并導(dǎo)入根證書(shū)
keytool -import -alias root -file ca.crt -keystore truststore.jks -storepass 123456
3.springboot項(xiàng)目配置
server:
? port: 8081
? ssl:
? ? enabled: true
? ? key-store-password: 123456 ? ? #密鑰存儲(chǔ)密碼
? ? key-store: classpath:server.p12
? ? key-alias: MyServer
? ? client-auth: need # 需要客戶(hù)端證書(shū) ?將服務(wù)器證書(shū)庫(kù)當(dāng)作信任庫(kù)來(lái)使用
? ? trust-store: classpath:truststore.jks
? ? trust-store-password: 123456
? ? trust-store-type: jks
4.在瀏覽器安裝client.p12 客戶(hù)端證書(shū)
5.通過(guò)https協(xié)議訪(fǎng)問(wèn)項(xiàng)目,注意選擇證書(shū)
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-861362.html
就可以訪(fǎng)問(wèn)項(xiàng)目了文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-861362.html
到了這里,關(guān)于springboot整合https使用自簽名證書(shū)實(shí)現(xiàn)瀏覽器和服務(wù)器之間的雙向認(rèn)證的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!