【发布时间】:2019-03-26 13:57:05
【问题描述】:
我正在尝试为 Google Cloud 的 App Engine 配置 SSL。 您可以在 GCP 中上传您自己的自定义 SSL 证书 + 私钥(请参阅screenshot)。
我正在将 Cloudflare 用于 DNS,并希望在 Cloudflare 中使用“完整(严格)”SSL 策略。这意味着我必须在 GCP 中添加由 Cloudflare 创建的证书和密钥(在同一屏幕截图中)。
我已设法将私钥转换为 GCP 可接受的有效 (PEM) 格式。唯一不起作用的是证书部分。
在GCP中同时输入证书和密钥时,点击上传,返回如下错误:
The certificate data is invalid. Please ensure that the private key and public certificate match.
经过一番谷歌搜索,我找到了以下资源on GCP's documentation,说明我需要在证书字段中上传完整的证书链。因此,我尝试的下一件事是concat 我的来自 cloudflare 的证书以及 cloudflare 本身的 root certificate,如 GCP 文档中所述。 所以我运行了以下命令来创建这个链:
cat domain.crt cloudflare-root-ca.crt > concat.crt
...并在证书字段中将其上传到 GCP 中。
这也不起作用,即使私钥和证书链的校验和都匹配为explained by GCP docs,运行:
openssl x509 -noout -modulus -in concat.crt | openssl md5
openssl rsa -noout -modulus -in myserver.key.pem | openssl md5
...并比较 md5 输出。
所以现在我完全没有 Idea。 GCP 的错误信息仅限于上述一条,还有一条说您的 PK 格式无效。
通过 CLI (gcloud) 尝试时遇到同样的问题
通过 cli gcloud 尝试此过程时,我们会遇到相同的错误。
尝试以下命令:
gcloud app ssl-certificates create --display-name example.com --certificate ./cloudflare-concat.crt --private-key cloudflare-pk.key
...产生以下错误:
ERROR: (gcloud.app.ssl-certificates.create)
INVALID_ARGUMENT: Invalid certificate.
`CertificateRawData` must contain a PEM encoded x.509 public key certificate, with header and footer included,
and an unencrypted PEM encoded RSA private key, with header and footer included and with size at most 2048 bits.
The requested private key and public certificate must match.
非常感谢有关在 GCP 中上传有效证书(来自 Cloudflare)和私钥的任何帮助。
更新 1
我发现这个 (cached) paged 描述了 Cloudflare 的所有根证书和中间证书。我已经尝试了其中的几个来连接我的域证书,但到目前为止还没有运气。也不清楚该用哪一个...
更新 2
我开始认为这永远行不通。因为我使用的是 Cloudflare 的“原始证书”,所以我相信这是 Cloudflare 本身的自签名证书,这意味着 App Engine 永远不会认为这是有效的。
我之所以认为是这种情况,是因为我尝试使用 cloudflare 中的 cfssl 工具自动“创建捆绑证书”。我从跑步中得到的回应
cfssl bundle -cert domain.crt
返回以下结果:
[INFO] bundling certificate for {Country:[] Organization:[CloudFlare, Inc.] OrganizationalUnit:[CloudFlare Origin CA] Locality:[] Province:[] StreetAddress:[] PostalCode:[] SerialNumber: CommonName:CloudFlare Origin Certificate Names:[{Type:2.5.4.10 Value:CloudFlare, Inc.} {Type:2.5.4.11 Value:CloudFlare Origin CA} {Type:2.5.4.3 Value:CloudFlare Origin Certificate}] ExtraNames:[]}
{"code":1220,"message":"x509: certificate signed by unknown authority"}
额外信息
- 我正在使用免费的 Cloudflare 订阅。
- 使用 Cloudflare 的“灵活”设置时一切正常,
- 但我想使用“完整(严格)”设置
【问题讨论】:
-
尝试使用在线 ssl 证书验证以查看您正在导入的文件是否有问题:sslshopper.com/certificate-decoder.html
-
@JohnHanley 试过了,一切正常
-
@Andries App Engine 现在支持 Cloudflare Origin CA 证书。 stackoverflow.com/a/37087010/6303504
-
感谢@Andrei 的链接,同时我能够按照我在下面的答案中提到的博文中解释的步骤解决它。
标签: google-app-engine ssl google-cloud-platform openssl cloudflare