前言

Google Cloud 在上个月也发布了使用 Automatic Certificate Management Environment 实现的自动化证书管理服务。这也就是说我们现在可以免费申请到和 Let's Encrypt 一样的 Google 公共证书了。

  • 支持多域名以及通配符证书(通配符证书目前需要通过 DNS 验证)
  • 支持申请 ECC 和 RSA 证书
  • 支持申请 IP 证书(目前只能该 IP Block 的所有者进行验证)
  • 证书最长有效期 90 天
  • 不支持 IDN 域名
  • OCSP 地址为 ocsp.pki.goog,有国内服务器节点

acme.sh 也很快的更新了脚本,于是我就写个小教程。


获取 GCP API Key

需要注册一个 Google Cloud Platform(GCP)的账号。

申请内测功能

目前(2022 年 4 月 15 日)仍处于内测阶段,需要填写一个表单申请该功能:这里申请,否则直接申请的话会提示错误

其中需要填写你的 Google Cloud Project ID *,可以在你的控制台面板菜单栏左上角点击你的项目名查看:

点击左上角那个地方

收到邮件 可能当天就好,或着等几天邮件就来了

获取 API Key

1. 登录你的 GCP 控制台面板,进入 Public Certificate Authority API 管理页面(这里)点击启动

或者直接使用 Cloud Shell 中使用下面的命令启动也可以:

gcloud services enable publicca.googleapis.com

2. 使用 Cloud Shell ,输入下面内容选中项目,如果你只有一个项目的话可以跳过这步,会自动设置为唯一项目:

gcloud config set project [project ID] <-项目 ID

3. 获取 API Key:

gcloud beta publicca external-account-keys create

中途弹窗点击 授权 之后会返回下列格式的信息,记得保存下来 acme.sh 要用的:

Created an external account key
[b64MacKey: xxxxxxxxxxxxxxxxxxxxxxx
 keyId: xxxxxxxxxxxxxxx]

申请证书

安装 acme.sh

curl  https://get.acme.sh | sh

生成证书

使用 Dnspod 的 API 为例,通过 DNS 验证申请通配符证书。

1. 获取 API 密钥 ,获取到 API 后注意保存,然后导入:

export DP_Id="xxx" #图上的ID
export DP_Key="xxx" #图上的Token

2. 设置 API:

acme.sh  --register-account -m [邮箱] --server google \
    --eab-kid [申请到的 keyId] \
    --eab-hmac-key [申请到的 b64MacKey]

3. 设置默认 CA,如果你一台服务器上有多个域名的 acme 任务,则可能自动更新失败,因此这里推荐使用 --accountconf 指定一个配置文件:

acme.sh --set-default-ca --server google --accountconf /root/.acme.sh/account-custom.conf

4. 签发证书:

acme.sh --issue --dns dns_dp -d mydomain.com -d *.mydomain.com --accountconf /root/.acme.sh/account-custom.conf

* 签发 ECC 证书:

acme.sh --issue --dns dns_cf -d mydomain.com -d *.mydomain.com --keylength ec-256 --accountconf /root/.acme.sh/account-custom.conf

5. 最后将证书安装到 Nginx 下:

acme.sh --install-cert -d mydomain.com \
--key-file       /path/to/ssl/private.key  \
--fullchain-file /path/to/ssl/fullchain.pem \
--reloadcmd     "service nginx restart"

* 安装 ECC 证书:

acme.sh --install-cert -d mydomain.com --ecc \
--key-file       /path/to/ssl/ecc_private.key  \
--fullchain-file /path/to/ssl/ecc_fullchain.pem \
--reloadcmd     "service nginx restart"

参考

https://www.zatp.com/post/issue-free-google-public-cert

https://ethanblog.com/tech/configure-and-anto-renew-let-s-encrypt-free-certificate-using-acme-sh-and-dnspod.html

「世界に忘れられた」
最后更新于 2023-07-11