码迷,mamicode.com
首页 > 其他好文 > 详细

生成证书

时间:2020-09-17 18:01:27      阅读:42      评论:0      收藏:0      [点我收藏+]

标签:etc   The   ace   end   合并   ofo   work   gre   pem   

#!/bin/bash
#Name:
#Version:1.0
#Ctime:2020-09-05
#Mtime:
#Author:Jack Wangbr/>#QQ-mail:2891133657@qq.com
#Work-For:
#Update-Explain:
###################################################################################
#$@所有参数单个列出 $*所有参数合并为字符 $#参数的个数 $0脚本路径本身 $1位置参数
###################################################################################
END="\033[0m"
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
PUR="\033[35m"
DEEPG="\033[36m"
WHITE="\033[37m"
###################################################################################
#生成密钥文件:(umask 066;openssl genrsa -out private/cakey.pem 2048)
#生成密钥文件:(umask 066;openssl genrsa -out master.key 2048)
#可以不做以上两步

. /etc/init.d/functions
declare -A CT
CT=( [sub0]="/O=kin/CN=ca.kin.com" \
[keyfile0]="cakey.pem" \
[crtfile0]="cacert.pem" \
[key0]=2048 \
[exp0]=3650 \
[serial0]=0 \
[sub1]="/C=CN/ST=hubei/L=xiangyang/O=wolong/CN=master.wolong.com" \
[keyfile1]="master.key" \
[crtfile1]="master.crt" \
[key1]=2048 \
[exp1]=365
[serial1]=1 \
[csrfile1]="master.csr" \
[sub2]="/C=CN/ST=hubei/L=xiangyang/O=wolong/CN=slave.wolong.com" \
[keyfile2]="slave.key" \
[crtfile2]="slave.crt" \
[key2]=2048 \
[exp2]=365 \
[serial2]=2 \
[csrfile2]="slave.csr" )

COLOR="echo -e \E[1;32m"
END="\E[0m"
DIR=/crt
cd $DIR

for i in {0..2};do
if [ $i -eq 0 ] ;then
openssl req -x509 -newkey rsa:${CT[key${i}]} -subj ${CT[sub${i}]} \
-set_serial ${CT[serial${i}]} -keyout ${CT[keyfile${i}]} -nodes \
-days ${CT[exp${i}]} -out ${CT[crtfile${i}]} &>/dev/null

else 
    openssl req -newkey rsa:${CT[key${i}]} -nodes -subj ${CT[sub${i}]}         -keyout ${CT[keyfile${i}]}   -out ${CT[csrfile${i}]} &>/dev/null

    openssl x509 -req -in ${CT[csrfile${i}]}  -CA ${CT[crtfile0]}     -CAkey ${CT[keyfile0]}  -set_serial ${CT[serial${i}]}      -days ${CT[exp${i}]} -out ${CT[crtfile${i}]} &>/dev/null
fi
$COLOR"**************************************生成证书信息**************************************"$END
openssl x509 -in ${CT[crtfile${i}]} -noout -subject -dates -serial
echo 

done
chmod 600 *.key
action "证书生成完成"
$COLOR"**生成证书文件如下**"$END
echo "证书存放目录: "$DIR
echo "证书文件列表: "ls $DIR

生成证书

标签:etc   The   ace   end   合并   ofo   work   gre   pem   

原文地址:https://blog.51cto.com/13434656/2529754

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!