mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4
233 字
1 分钟
zerossl获取一年免费泛证书
2024-06-01

环境配置:#

本脚本推荐使用centos stream 8 ,在使用本脚本前,请先更新源,并且安装wget这个插件

开始教程#

首先去zerossl官网注册一个账号Dashboard - ZeroSSL(这个邮箱可以随便填,不会验证)#

新建脚本文件zerossl.sh#

将账号密码替换以下User_Name,User_Pawd字段

#!/bin/bash
# ZeroSSL 证书申请脚本
# 作者: null
# 用户邮箱
User_Name='邮箱'
# 用户密码
User_Pawd='密码'
# 密码编码
User_Pawd_E=$(echo -n "${User_Pawd}"|sha256sum |awk '{print $1}')
# 登录信息
Login_Info=`curl -v -X POST -c cookie.db -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -d "postArray={\"email_address\":\"${User_Name}\",\"password\":\"${User_Pawd_E}\"}" 'https://app.zerossl.com/ajax/public_ajax_handler.php?type=sign_in' 2>&1`
if [[ "${Login_Info}" =~ 'success":1,' ]];then
echo "用户 ${User_Name} 登录成功."
else
echo "用户 ${User_Name} 登录失败."
exit 1
fi
# Cookie
Login_Cpt=`echo "${Login_Info}"|awk -F'[ :=;]+' '/Set-Cookie:[[:space:]]_cpt/ {print $4}'`
User_Login_Cookie(){
curl -s -b cookie.db -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0' "${@}"
}
Login_Auth=`User_Login_Cookie 'https://app.zerossl.com/dashboard'`
if [ -z "${Login_Auth}" ];then
echo "$User_Name 未登录."
exit 1
fi
# 密钥目录
SSL_Key_Dir='ssl_key'
# 检查目录是否存在
if [ ! -d "${SSL_Key_Dir}" ];then
mkdir "${SSL_Key_Dir}"
fi
if [ -z "${1}" ];then
read -ep '请输入域名:' Gen_Domain
else
Gen_Domain="${1}"
fi
# 订阅
Subscription_Plan=`User_Login_Cookie -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -d 'postArray={"plan_id":"512","payment_frequency":"monthly"}' "https://app.zerossl.com/ajax/advanced_ajax_handler.php?type=change_subscription_plan&_cpt=${Login_Cpt}"`
if [[ "${Subscription_Plan}" =~ 'success":1,' ]];then
echo "用户 ${User_Name} 订阅成功."
else
echo "用户 ${User_Name} 订阅失败."
exit 1
fi
# 降级订阅
Downgrade_Plan=`User_Login_Cookie -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -d 'postArray={"plan_id":"477","payment_frequency":"monthly"}' "https://app.zerossl.com/ajax/advanced_ajax_handler.php?type=change_subscription_plan&_cpt=${Login_Cpt}"`
# ZeroSSL API 密钥
User_Token=`User_Login_Cookie 'https://app.zerossl.com/developer' |grep -A 1 '"access_key"'|awk -F'[ ><]+' '/span/ {print $3}'`
if [ -z "${User_Token}" ];then
echo "用户密钥为空"
exit 1
fi
Gen_Domain_D=$(echo "${Gen_Domain}"|sed -r 's/\*\./_/g;s/\./_/g')
echo "域名信息: ${Gen_Domain} ${Gen_Domain_D}"
Domain_Key_Path="${SSL_Key_Dir}/${Gen_Domain_D}.key"
Domain_Csr_Path="${SSL_Key_Dir}/${Gen_Domain_D}_csr.pem"
if [ ! -f "${Domain_Key_Path}" ];then
openssl genrsa -out "${Domain_Key_Path}" 2048
fi
if [ ! -f "${Domain_Csr_Path}" ];then
openssl req -new -key ${Domain_Key_Path} -out ${Domain_Csr_Path} -subj "/C=CN/CN=${Gen_Domain}"
fi
# 格式化
Domain_Csr_Code=$(cat "${Domain_Csr_Path}" | tr -d '\n')
Post_Cert_Code=$(curl -s -X POST -H 'Content-Type: application/json' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0' -d "{\"certificate_domains\": \"${Gen_Domain}\", \"certificate_validity_days\": 365, \"certificate_csr\": \"${Domain_Csr_Code}\", \"strict_domains\": 1}" "http://api.zerossl.com/certificates?access_key=${User_Token}")
if [[ "${Post_Cert_Code}" =~ 'success' ]];then
echo "订单失败: ${Post_Cert_Code}"
else
echo "订单成功: ${Post_Cert_Code}"
fi

使用sh zerossl.sh运行脚本#

随后输入泛域名列如*.xxx.com,普通域名可以直接使用xxx.com,1.xxx.com

image-20240522234024193

此时代表申请成功,我们进入zerossl官网后台,点击进入Draft ---> verify进入配置#

image-20240522234218974

image-20240522234318751

配置dns#

image-20240522234403670

将cname值解析到域名内,这里以腾讯云为例#

image-20240522234617308

回到zerossl后台,点击Verify Domains验证dns#

验证完成后就可以下载pem,cre文件,这时候并没有key,我们回到脚本位置的ssl_sky目录内就可以看到了#

image-20240522234906987

然后将key下载到本地,配置#

image-20240522235257302

分享

如果这篇文章对你有帮助,欢迎分享给更多人!

zerossl获取一年免费泛证书
https://6wd.cn/posts/zerossl-free-wildcard-cert/
作者
技术宅拯救世界!
发布于
2024-06-01
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

目录