CA證書

hash(哈希,單向散列算法)
校驗數據完整性、不可逆、無論信息多長多短hash值的長度固定不變
md5:信息摘要算法
sha1:安全哈希算法
md5sum和sha1sumlinux

CA認證中心(ssl/tls)

httpd+ssl=https
CA:私鑰,數字證書(CA私鑰、簽名、CA的證書請求)
http:私鑰、數字證書(CA私鑰、簽名、http的證書請求)
client:CA數字證書驗證http數字證書nginx

證書安裝

yum install openssl
配置文件:/etc/pki/tls/openssl.cnf
178行:basicConstraints=CA:FALSE改成:
basicConstraints=CA:TRUE 自簽署的證書可使用
進入/etc/pki/CA執行:
/etc/pki/tls/misc/CA -newca 生成一個新的CA機構
會生成CA的私鑰
須要填寫身份信息
A challenge password :
Enter pass phrase for ../../CA/private/./cakey.pem: 使用私鑰自簽名
在/etc/pki/CA/private目錄下會生成CA私鑰:cakey.pem
在/etc/pki/CA目錄下會生成:
cacert.pem CA證書
careq.pem 證書請求算法

配置httpd:

yum install mod_ssl 安裝ssl模塊支持https
ls /etc/httpd/modules/mod_ssl.so 安裝完成後模塊位置
openssl genrsa -des -out /tmp/server.key 生成私鑰並用des保護私鑰
openssl req -new -key /tmp/server.key -out /tmp/server.csr 利用私鑰生成證書請求,在生成證書請求時所輸入的信息必須和上面CA機構中的信息一致
將證書請求發給CA機構:
scp /tmp/server.csr 192.168.2.102:/tmp/
在CA機構上使用CA的私鑰和證書進行數字簽名:
openssl ca -keyfile /etc/pki/CA/private/cakey.pem -cert /etc/pki/CA/cacert.pem -in /tmp/server.csr -out /tmp/server.crt
將生成http的數字證書發給http服務器:
scp /tmp/server.crt 192.168.2.104:/tmp/
編輯http上的ssl配置文件/etc/httpd/conf.d/ssl.conf
112行:SSLCertificateFile /tmp/server.crt 指定http數字證書的位置
119行:SSLCertificateKeyFile /tmp/server.key 指定http私鑰的位置apache

重啓apache服務,在重啓的時候須要輸入http私鑰的密碼
客戶端測試:
將CA的證書發給客戶端進行驗證
scp /etc/pki/CA/cacert.pem 192.168.2.200:/tmp/
將cacert.pem導入瀏覽器瀏覽器

 

配置nginx:

yum install openssl-devel -y
編譯時須要安裝 --with-http_ssl_module 模塊
cd /usr/local/nginx/conf/
openssl genrsa -des3 -out nginx.key 1024 //此時會讓你設置一個密碼
openssl req -new -key nginx.key -out nginx.csr
將nginx.csr拷貝到ca服務器安全

在ca服務器上使用CA的私鑰和證書進行數字簽名:
openssl ca -keyfile /etc/pki/CA/private/cakey.pem -cert /etc/pki/CA/cacert.pem -in nginx.csr -out nginx.crt
將生成的數字證書發給nginx服務器:
scp nginx.crt "nginx服務器"服務器

修改nginx服務器上的配置:測試

server{
listen 443;
ssl on;
ssl_certificate /usr/local/nginx/conf/nginx.crt;
ssl_certificate_key /usr/local/nginx/conf/nginx.key;
}server

將80端口重定向到443
server{
listen 80;
server_name "name";
rewrite ^(.*) https://$server_name$1 permanent;
}
重啓nginx服務並輸入上面設置的密碼md5

 

haproxy配置:

yum install openssl-devel -y
安裝haproxy,增長SSL模塊,進入解壓目錄:
make TARGET=linux26 CPU=x86_64 PREFIX=/usr/local/haprpxy USE_OPENSSL=1 ADDLIB=-lz
檢查ssl庫是否正常:
ldd haproxy | grep ssl
make install PREFIX=/usr/local/haprpxy

製做key文件:
openssl genrsa -des3 -out /tmp/haproxy.key 1024 //此時會讓你設置一個密碼
openssl req -new -key /tmp/haproxy.key -out /tmp/haproxy.csr
將haproxy.csr拷貝到ca服務器


在ca服務器上使用CA的私鑰和證書進行數字簽名:
openssl ca -keyfile /etc/pki/CA/private/cakey.pem -cert /etc/pki/CA/cacert.pem -in /tmp/haproxy.csr -out /tmp/haproxy.crt //須要輸入證書服務器CA私鑰(cakey.pem)的密碼
將生成的數字證書發給haproxy服務器:
scp /tmp/haproxy.crt "haproxy服務器"

生成.pem文件:
cat /tmp/haproxy.crt /tmp/haproxy.key | tee /tmp/haproxy.pem


修改haproxy配置文件:
添加:
bind :443 ssl crt /tmp/haproxy.pem //pem文件的路徑
redirect scheme https if !{ ssl_fc } //當訪問80端口時自動跳轉到443端口

重啓haproxy服務,須要輸入建立haproxy.key時設置的密碼

相關文章
相關標籤/搜索