Let's-encrypt 通配符证书相关介绍

2018-03-14 2549点热度 0人点赞

Let's-encrypt 于今日终于发布了通配符证书,这回收费的通配符证书要受到冲击了。


1 、 Lets-encrypt 通配符证书简介

https://community.letsencrypt.org/t/acme-v2-production-environment-wildcards/55578

用户可以使用以下节点 URL,开始使用 ACME v2 兼容客户端 颁发可信的通配符证书:https://acme-v02.api.letsencrypt.org/directory 切记:您必须使用 ACME v2 兼容客户端才能访问此节点。

*.example.com 不能包含 example.com 这个根域名的证书,所以要么一起申请 (输两次 DNS 很麻烦),要么分开申请 (做两个证书) 。


2 、安装 Lets-encrypt 通配符证书

之前 ACMEv1 的证书申请已经非常容易了,所以只讲解 ACMEv2 中通配符的证书申请 (Certbot 版本大于 0.22.0)

2.1 、手动申请 Lets-encrypt 通配符证书

首先是安装的命令,除了域名需要修改,其他的不用变。

certbot certonly --agree-tos --preferred-challenges dns-01 --manual -d *.example.com --server https://acme-v02.api.letsencrypt.org/directory

其中

--agree-tos 代表同意使用说明
--server 字段代表使用指定的 ACME 服务器
--preferred-challenges 字段代表使用指定的服务器验证此通配符域名的 DNS
--manual 代表交互式认证
-d *.example.com 代表要验证的域名

关于通配符证书,比如 *.example.com 可以代表所有的除根域名以外的所有域名,

其他的,比如 m*.example.com 能代表 m1.example.commeo.example.com 但是不能代表 m1.qwe.example.com


安装期间,首先会提示,你的服务器 IP 将被记录,问你是否同意?(选是)

-------------------------------------------------------------------------------
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.

Are you OK with your IP being logged?
-------------------------------------------------------------------------------

然后会让你在 DNS 中添加一个_acme-challenge 字段的 TXT 记录,内容为下面的字段如本例为 24de856eSb53F0304866c6acWs1-a862-cbeed44900 。添加好后,等待一段时间 DNS 刷新,大约 30 秒左右,然后继续。

-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.example.com with the following value:

24de856eSb53F0304866c6acWs1-a862-cbeed44900

Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue

当正确读取到 TXT 记录时,则会生成证书

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
 /etc/letsencrypt/live/example.com/fullchain.pem
 Your key file has been saved at:
 /etc/letsencrypt/live/example.com/privkey.pem
 Your cert will expire on 2018-06-12. To obtain a new or tweaked
 version of this certificate in the future, simply run certbot
 again. To non-interactively renew *all* of your certificates, run
 "certbot renew"
 - If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
 Donating to EFF: https://eff.org/donate-le

此方法安装完毕后,暂时无法自动重生成证书。


2.2 、使用自动认证的方式获取 Lets-encrypt 通配符证书

首先在 CentOS 上安装 Certbot-dns-Cloudflare 插件

yum install -y python2-certbot-dns-cloudflare

然后我们需要获得 Cloudflare 的全局 API(请注意 API 泄露将导致不可知风险)[ 链接 ]

Global API Key 的选项右侧点击 View API Key  获得 API 密码

接着我们需要创建一个文件把你的 API 信息输入到一个文件中 (本例写入到~/.cloudflare.ini 中)
建议将此文件权限改为 400 防止其他人读取和修改。

# Cloudflare API credentials used by Certbot
dns_cloudflare_email = [email protected]
dns_cloudflare_api_key = 0123456789abcdef0123456789abcdef01234567

接着我们输入以下命令(此为一条命令,用 \ 符号进行断点输入)

certbot certonly --agree-tos --email [email protected] \
 --server https://acme-v02.api.letsencrypt.org/directory \
 --dns-cloudflare \
 --dns-cloudflare-credentials ~/.cloudflare.ini \
 --dns-cloudflare-propagation-seconds 10 \
 -d example.com -d *.example.com

--agree-tos 代表同意使用说明
--server 字段代表使用指定的 ACME 服务器
--dns-cloudflare  字段代表使用指定的 cloudflare 扩展进行检查
--dns-cloudflare-credentials 字段代表读取的 API 信息路径
--dns-cloudflare-propagation-seconds 字段代表 DNS 验证等待时间
-d *.example.com 代表要验证的域名

输入完毕后即可直接获得证书,后期可以用 certbot renew 自动续期


3 、相关链接

Certbot 官方的使用教程

https://certbot.eff.org/docs/using.html#dns-plugins

https://certbot-dns-cloudflare.readthedocs.io/en/latest


使用 GCP 公共 CA 签发证书 [ 链接 ]

GTS 证书 支持 IP 地址,但是仅允许该 IP 地址块的所有者进行验证;(Let’s Encrypt 暂不支持)

StarryVoid

Have a good time