网络安全检测|网络安全服务|网络安全扫描-香港墨客投资移动版

主页 > 业界资讯 > 网络安全预防措施

linux:Nginx+https双向验证(数字安全证书)(2)

 

最后附上自动添加客户端证书的脚本,其中省去了交互功能,因为如果给100个人生成证书,多大好几百个交互过程,这个过程会让人崩溃的,所以使用了expect自动传入参数。脚本内容如下:
#!/bin/bash 
#write by yayun 2013-05-29
#batch add client certificate for nginx https
 
base="/data/nginx/ca" 
 
fori in $(awk -F "@" '{print $1}' name.txt)
do
mkdir -p $base/$i/
opensslgenrsa -out $base/$i/$i.key 2048
 
Country=cn
State=guangdong
Locality=guangzhou
Organization=mbook
Common=*.mbook.cn
[email protected]
[email protected]
 
expect -c "
spawnopensslreq -new -key $base/$i/$i.key -out $base/$i/$i.csr
expect {
                \"*XX*\" {send \"$Country\r\"; exp_continue}
                \"*full name*\" {send \"$State\r\"; exp_continue}
                \"*Default City*\" {send \"$Locality\r\"; exp_continue}
                \"Organization*\" {send \"$Organization\r\"; exp_continue}
                \"Organizational*\" {send \"$Organization\r\"; exp_continue}
                \"*hostname*\" {send \"$Common\r\"; exp_continue}
                \"Email*\" {send \"$Email\r\"; exp_continue}
                \"*password*\" {send \"\r\"; exp_continue}
                \"*company name*\" {send \"\r\"; exp_continue}
        }
"
expect -c "
spawnopensslca -in $base/$i/$i.csr -cert $base/private/ca.crt -keyfile $base/private/ca.key -out $base/$i/$i.crt -config "/data/nginx/ca/conf/openssl.conf"
expect {
                \"*certificate?*\" {send \"y\r\"; exp_continue}
                \"*commit?*\" {send \"y\r\"; exp_continue}
        }
"
expect -c "
spawnopenssl pkcs12 -export -clcerts -in $base/$i/$i.crt -inkey $base/$i/$i.key -out $base/$i/$i.p12
expect {
                \"Enter*Password:\" {send \"$Passwd\r\"; exp_continue}
                \"Verifying*Password:\" {send \"$Passwd\r\"; exp_continue}
        }
"
done
其中name.txt记录了用户名,邮箱,脚本自动循环读取。整个过程结束!
 

转载请注明linux系统运维:

(责任编辑:admin)