我也使用过 AWS IoT 并且遇到了同样的错误,我找到了解决方案。
错误原因
出现该错误是因为 CA 证书中的 basicConstraints 扩展名,这意味着证书是 CA,因此该证书能够签署其他公钥以生成客户端证书,未设置为 TRUE。
请注意,客户端 X 的证书包含由 CA 的私钥签名的 X 的公钥。其他客户端,例如 Y,可以使用 CA 的公钥验证 X 的公钥。
我认为您在尝试生成 CA 证书时遇到了错误。该错误消息表明不允许 CA 的证书签署其他客户端公钥。
以下是我的做法。
解决方案
我假设您已经生成了 CA 的密钥 rootCA.key。
我们需要一个openssl 配置文件,比如rootCA_openssl.conf。请注意,您可以修改这些值。
[ req ]
distinguished_name = req_distinguished_name
extensions = v3_ca
req_extensions = v3_ca
[ v3_ca ]
basicConstraints = CA:TRUE
[ req_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = KR
countryName_min = 2
countryName_max = 2
organizationName = Organization Name (eg, company)
organizationName_default = Deeply Inc.
然后使用配置文件rootCA_openssl.conf生成CA的证书。
openssl req -new -sha256 -key rootCA.key -nodes -out rootCA.csr -config rootCA_openssl.conf
openssl x509 -req -days 3650 -extfile rootCA_openssl.conf -extensions v3_ca -in rootCA.csr -signkey rootCA.key -out rootCA.pem
现在我们有了 CA 的证书,rootCA.pem。
然后,您可以按照 AWS IoT 文档中的说明进行操作。
例如:
# Get the registration code for the use below:
# $ aws iot get-registration-code
openssl genrsa -out verificationCert.key 2048
openssl req -new -key verificationCert.key -out verificationCert.csr
# Put the registration code in Common Name field
openssl x509 -req -in verificationCert.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out verificationCert.crt -days 500 -sha256