Https認證:
單向認證:保證服務器是可信任的,可以安全的訪問的!
客戶端拿到服務器的證書,通過CA認證信任,然后取出公鑰,加密對稱密鑰傳給服務器,服務器用自己的私鑰解密得到對稱密鑰,后續使用該對稱密鑰加解密數據!
雙向認證:客戶端和服務器都是可以互相信任的!
安卓smb客戶端、客戶端向服務器發送一個請求時,服務器會把自己的證書,以及一些信息發送過來,客戶端拿到服務器的證書通過CA進行驗證,如果是可靠的,繼續進行,如果不是可靠的,則會彈出警告,告訴客戶端證書有風險。同樣服務器也也要驗證客戶端的證書,如果沒有通過驗證,拒絕連接,如果兩端都通過驗證,則可以進行正常通信,使用對方的公鑰加密對稱密鑰,實現安全通信!
##使用 keytool工具生成管理證書
// 生成服務器證書server.keystore
keytool.exe -genkey -v -alias server -keyalg RSA -keystore D:\home\server.keystore -validity 36500 -ext SAN=ip:192.168.1.1
// 生成客戶端證書client.p12 證書格式PKCS12
破解token驗證,keytool.exe -genkey -v -alias client -keyalg RSA -storetype PKCS12 -keystore D:\home\client.p12 -validity 36500
// 導出客戶端證書client.cer
keytool.exe -export -alias client -keystore D:\home\client.p12 -storetype PKCS12 -rfc -file D:\home\client.cer
// 導出服務器證書server.cer
keytool.exe -keystore D:\home\server.keystore -export -alias server -file D:\home\server.cer -validity 36500
APK一鍵加驗證工具?// 添加客戶端證書為服務器的信任認知
keytool -import -v -file D:\home\client.cer -keystore D:\home\server.keystore
//查看證書 信任列表
keytool -list -keystore D:\home\server.keystore
//刪除信任證書
android?keytool -delete -alias mykey -keystore server.keystore -storepass hz123456
實際操作步驟
1.導入生成客戶端的P12到xshell
2.通過命令生成client.cer
keytool -export -alias client -keystore client.p12 -storetype PKCS12 -rfc -file client.cer
android9、3.加入客戶端證書到服務器信任列表(server.keystore的密碼是ab123456)
keytool -import -v -file client.cer -keystore server.keystore
4.查看服務器證書列表
keytool -list -keystore server.keystore
5.配置tomcat,支持雙向驗證(/usr/tomcat/apache-tomcat-7.0.68)
androidstudio?編輯tomcat服務器的配置,讓其支持雙向驗證
vim server.xml
maxThreads="150" SSLEnabled="true" scheme="https" secure="true" URIEncoding="UTF-8"
keystoreFile="server.keystore" keystorePass="hz123456"
android開發、truststoreFile="server.keystore" truststorePass="hz123456"
clientAuth="true" sslProtocol="TLS" />
6.關閉tomcat進程
ps aux|grep tomcat
查看tomcat進程, kill 1111
android客戶端下載、7.重啟進程
進入bin目錄 ./startup.sh
Android P12 BKS
Android的客戶端證書是BKS格式的,所以需要將P12格式的證書轉換成BKS格式,步驟如下:
1.使用portecle工具轉換:
安卓samba客戶端?[下載鏈接(http://portecle.sourceforge.net/)](http://portecle.sourceforge.net/)
2.命令行打開工具:
java -jar portecle.jar
3.轉換BKS
互相信任
android客戶端是什么?1.客戶端信任服務器:
如果是瀏覽器,將服務器的證書雙擊,配置導入
如果是Android客戶端,只需要將服務器cer證書文件放入assert目錄,相應解析處理,大家可以百度!
2.服務器信任客戶端:
如果是瀏覽器,可以將客戶端是證書加入到服務器的信任證書列表
如果是客戶端,將bks證書放到assert目錄,解析傳到服務器!具體Android端怎么讀取bks證書傳給服務器的,大家可以下去研究一下!
注意:坑
1.生成證書的時候,要指定ip
keytool -genkey -v -alias client -keyalg RSA -storetype PKCS12 -keystore client.p12 -validity 36500
注意:first last name需要指定如下
-ext SAN=ip:xxx.xxx.xxx.xxx
2.P12 BKS 轉換的時候密碼過長,報錯
java.security.KeyStoreException: java.io.IOException: Error initialising store of key store: java.security.InvalidKeyException: Illegal key size
是國外對技術出口的限制,限定了密鑰的長度,需要替換jdk里面的兩個文件(jre\lib\security):local_policy.jar,US_export_policy.jar,要下載jdk版本對應的,不然會出錯!
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态