1 Star 0 Fork 0

葛绍飞/lesson --- ip_https_cert

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
gen_ip_https_cert.sh 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
葛绍飞 提交于 2024-10-27 16:43 . update
#! /bin/bash
echo "请输入服务器IP地址"
read ip
echo "请输入证书年限"
read year
year=$(expr $year + 0)
days=$(expr $year \* 365)
# echo $days
# 生成私钥
openssl genrsa -out ca.key 2048
# 生成公钥
openssl req -new -x509 -days $days -key ca.key -out ca.crt -subj "//C=CN/C=CN/ST=BJ/L=SJS/O=GuFei/OU=dev/CN=jiehuo.com"
# 创建 openssl.cnf 配置文件
cat << EOF > openssl.cnf
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
[req_distinguished_name]
countryName = Country Name (2 letter code)
countryName_default = US
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = NY
localityName = Locality Name (eg, city)
localityName_default = NYC
organizationalName = Organizational Name (eg, section)
organizationalName_default = gufei
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = dev
commonName = Common Name (eg, your name or your server's hostname)
commonName_max = 64
[v3_req]
# Extensions to add to a certificate request
basicConstraints = CA:TRUE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
[alt_names]
IP.1 = $ip
EOF
# 创建v3.ext文件
cat << EOF > v3.ext
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage=digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName=@alt_names
[alt_names]
IP.1 = $ip
EOF
# 服务器证书私钥
openssl genrsa -out server.key 2048
# 服务器证书公钥
openssl req -new -days $days -key server.key -out server.csr -config openssl.cnf -subj //C=CN/C=CN/ST=BJ/L=SJS/O=GuFei/OU=dev/CN=jiehuo.com
# 用自己的 CA 给自己的服务器公钥签名
openssl x509 -days $days -req -sha256 -extfile v3.ext -CA ca.crt -CAkey ca.key -CAcreateserial -in server.csr -out server.crt
rm {ca.key,ca.srl,server.csr,openssl.cnf,v3.ext}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/andyge/ip_https_cert.git
git@gitee.com:andyge/ip_https_cert.git
andyge
ip_https_cert
lesson --- ip_https_cert
master

搜索帮助