- sslOutputRoot="/etc/apache_ssl"
- if [ $
- sslOutputRoot=$1
- fi
- if [ ! -d ${sslOutputRoot} ]; then
- mkdir -p ${sslOutputRoot}
- fi
- cd ${sslOutputRoot}
- echo "开始创建CA根证书..."
- openssl genrsa -des3 -out ca.key 1024
- openssl req -new -x509 -days 365 -key ca.key -out ca.crt
- echo "CA根证书创建完毕。"
- echo "开始生成服务器证书签署文件及私钥 ..."
- openssl genrsa -des3 -out server.key 1024
- openssl req -new -key server.key -out server.csr
- ls -altrh ${sslOutputRoot}/server.*
- echo "服务器证书签署文件及私钥生成完毕。"
- echo "开始使用CA根证书签署服务器证书签署文件 ..."
- CSR=server.csr
- case $CSR in
- *.csr ) CERT="`echo $CSR | sed -e 's/\.csr/.crt/'`" ;;
- * ) CERT="$CSR.crt" ;;
- esac
- if [ ! -d ca.db.certs ]; then
- mkdir ca.db.certs
- fi
- if [ ! -f ca.db.serial ]; then
- echo '01' >ca.db.serial
- fi
- if [ ! -f ca.db.index ]; then
- cp /dev/null ca.db.index
- fi
- cat >ca.config <<EOT
- [ ca ]
- default_ca = CA_own
- [ CA_own ]
- dir = .
- certs = ./certs
- new_certs_dir = ./ca.db.certs
- database = ./ca.db.index
- serial = ./ca.db.serial
- RANDFILE = ./ca.db.rand
- certificate = ./ca.crt
- private_key = ./ca.key
- default_days = 3650
- default_crl_days = 30
- default_md = md5
- preserve = no
- policy = policy_anything
- [ policy_anything ]
- countryName = optional
- stateOrProvinceName = optional
- localityName = optional
- organizationName = optional
- organizationalUnitName = optional
- commonName = supplied
- emailAddress = optional
- EOT
- echo "CA signing: $CSR -> $CERT:"
- openssl ca -config ca.config -out $CERT -infiles $CSR
- echo "CA verifying: $CERT <-> CA cert"
- openssl verify -CAfile ./certs/ca.crt $CERT
- rm -f ca.config
- rm -f ca.db.serial.old
- rm -f ca.db.index.old
- echo "使用CA根证书签署服务器证书签署文件完毕。"
- echo "去除 apache 启动时必须手工输入密钥密码的限制:"
- cp -f server.key server.key.org
- openssl rsa -in server.key.org -out server.key
- echo "去除完毕。"
- chmod 400 server.key
- echo "Now u can configure apache ssl with following:"
- echo -e "\tSSLCertificateFile ${sslOutputRoot}/server.crt"
- echo -e "\tSSLCertificateKeyFile ${sslOutputRoot}/server.key"
- exit 0
SSL自签署证书生成脚本
最新推荐文章于 2024-06-10 09:46:26 发布