管理 CA 证书 - Amazon IoT Core
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

管理 CA 证书

本节介绍管理您自己的证书颁发机构 (CA) 证书的常见任务。

Amazon IoT 如果您使用的是由 Amazon IoT 无法识别的 CA 签名的客户端证书,则可以向注册证书颁发机构 (CA)。

如果您希望客户端在首次连接 Amazon IoT 时自动向其注册其客户端证书,则必须向注册签署客户端证书的 CA Amazon IoT。否则,您不需要注册对客户端证书签发的 CA 证书。

注意

DEFAULT 模式下,一个 CA 证书只能由一个区域中的一个账户注册。在 SNI_ONLY 模式下,一个 CA 证书可以由一个区域中的多个账户注册。

创建 CA 证书

如果没有 CA 证书,则可以使用 OpenSSL v1.1.1i 工具创建一个。

注意

您无法在 Amazon IoT 控制台中执行此过程。

使用 OpenSSL v1.1.1i 工具创建 CA 证书
  1. 生成密钥对。

    openssl genrsa -out root_CA_key_filename.key 2048
  2. 使用密钥对中的私有密钥生成 CA 证书。

    openssl req -x509 -new -nodes \ -key root_CA_key_filename.key \ -sha256 -days 1024 \ -out root_CA_cert_filename.pem

注册 CA 证书

这些程序描述了如何注册来自非亚马逊 CA 的证书颁发机构 (CA) 的证书。 Amazon IoT Core 使用 CA 证书验证证书的所有权。要使用由非亚马逊 CA 的 CA 签名的设备证书,您必须向注册 CA 证书, Amazon IoT Core 这样它才能验证设备证书的所有权。

注册 CA 证书(控制台)

注意

若要在控制台中注册 CA 证书,请在控制台中的 Register CA certificate(注册 CA 证书)处开始注册。您可以在多账户模式下注册您的 CA,而无需提供验证证书或访问私有密钥的权限。在多账户模式下,多个 Amazon Web Services 账户 可以在同一个 Amazon Web Services 区域中注册 CA。您可以通过提供验证证书和 CA 私有密钥的所有权证明,在单账户模式下注册您的 CA。在多账户模式下,一个 Amazon Web Services 账户 可以在一个 Amazon Web Services 区域中注册 CA。

注册 CA 证书 (CLI)

您可以在 DEFAULT 模式或 SNI_ONLY 模式下注册 CA 证书。CA 可以一对一 Amazon Web Services 账户 地在DEFAULT模式下注册 Amazon Web Services 区域。一个 CA 可以在同一个SNI_ONLY模式下通过多个 Amazon Web Services 账户 CA 进行注册 Amazon Web Services 区域。有关 CA 证书模式的更多信息,请参阅 certificateMode

注意

我们建议您在 SNI_ONLY 模式下注册 CA。您无需提供验证证书或访问私钥的权限,并且可以在同一个证书 Amazon Web Services 账户 中多次注册 CA Amazon Web Services 区域。

在 SNI_ONLY 模式下注册 CA 证书(CLI)- 建议

先决条件

继续操作之前,请确保电脑满足以下条件:

  • 根 CA 的证书文件(在以下示例中引用为 root_CA_cert_filename.pem

  • OpenSSL v1.1.1i 或更高版本

要使用SNI_ONLY模式注册 CA 证书 Amazon CLI
  1. 向注册 CA 证书 Amazon IoT。使用 register-ca-certificate 命令,输入 CA 证书文件名。有关更多信息,请参阅《Amazon CLI 命令参考register-ca-certificate中的。

    aws iot register-ca-certificate \ --ca-certificate file://root_CA_cert_filename.pem \ --certificate-mode SNI_ONLY

    如果成功,此命令将返回 certificateId

  2. 此时,CA 证书已注册 Amazon IoT 但处于非活动状态。CA 证书必须处于活跃状态,然后您才能注册由其签发的任何客户端证书。

    此步骤将激活 CA 证书。

    要激活 CA 证书,请使用 update-certificate 命令,如下所示。有关更多信息,请参阅 Amazon CLI 命令参考中的 update-certificate

    aws iot update-ca-certificate \ --certificate-id certificateId \ --new-status ACTIVE

要查看 CA 证书的状态,请使用 describe-ca-certificate 命令。有关更多信息,请参阅《Amazon CLI 命令参考describe-ca-certificate中的。

DEFAULT 模式下注册 CA 证书(CLI)

先决条件

继续操作之前,请确保电脑满足以下条件:

  • 根 CA 的证书文件(在以下示例中引用为 root_CA_cert_filename.pem

  • 根 CA 证书的私有密钥文件(在以下示例中引用为 root_CA_key_filename.key

  • OpenSSL v1.1.1i 或更高版本

要使用DEFAULT模式注册 CA 证书 Amazon CLI
  1. 要从中获取注册码 Amazon IoT,请使用get-registration-code。保存返回的 registrationCode,将其用作私有密钥验证证书的 Common Name。有关更多信息,请参阅《Amazon CLI 命令参考get-registration-code中的。

    aws iot get-registration-code
  2. 为私有密钥验证证书生成密钥对:

    openssl genrsa -out verification_cert_key_filename.key 2048
  3. 为私有密钥验证证书创建证书签名请求 (CSR)。将证书的 Common Name 字段设置为 get-registration-code 返回的 registrationCode

    openssl req -new \ -key verification_cert_key_filename.key \ -out verification_cert_csr_filename.csr

    将提示您输入一些信息,包括证书的Common Name

    You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]: State or Province Name (full name) []: Locality Name (for example, city) []: Organization Name (for example, company) []: Organizational Unit Name (for example, section) []: Common Name (e.g. server FQDN or YOUR name) []:your_registration_code Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
  4. 使用 CSR 创建私有密钥验证证书:

    openssl x509 -req \ -in verification_cert_csr_filename.csr \ -CA root_CA_cert_filename.pem \ -CAkey root_CA_key_filename.key \ -CAcreateserial \ -out verification_cert_filename.pem \ -days 500 -sha256
  5. 向注册 CA 证书 Amazon IoT。将 CA 证书文件名和私有密钥验证证书文件名传递给 register-ca-certificate 命令,如下所示:有关更多信息,请参阅《Amazon CLI 命令参考register-ca-certificate中的。

    aws iot register-ca-certificate \ --ca-certificate file://root_CA_cert_filename.pem \ --verification-cert file://verification_cert_filename.pem

    如果成功,此命令将返回 certificateId

  6. 此时,CA 证书已注册 Amazon IoT 但未激活。CA 证书必须处于活跃状态,然后您才能注册由其签发的任何客户端证书。

    此步骤将激活 CA 证书。

    要激活 CA 证书,请使用 update-certificate 命令,如下所示。有关更多信息,请参阅 Amazon CLI 命令参考中的 update-certificate

    aws iot update-ca-certificate \ --certificate-id certificateId \ --new-status ACTIVE

要查看 CA 证书的状态,请使用 describe-ca-certificate 命令。有关更多信息,请参阅《Amazon CLI 命令参考describe-ca-certificate中的。

创建 CA 验证证书以在控制台中注册 CA 证书

注意

此过程仅适用于从 Amazon IoT 控制台注册 CA 证书的情况。

如果您不是从控制台进入此过程,请在 Amazon IoT 控制台的 Register CA 证书上启动 CA 证书注册过程。

继续操作之前,请确保同一台电脑满足以下条件:

  • 根 CA 的证书文件(在以下示例中引用为 root_CA_cert_filename.pem

  • 根 CA 证书的私有密钥文件(在以下示例中引用为 root_CA_key_filename.key

  • OpenSSL v1.1.1i 或更高版本

使用命令行界面创建 CA 验证证书,以在控制台中注册 CA 证书
  1. verification_cert_key_filename.key 替换为要创建的验证证书密钥文件的文件名(例如 verification_cert.key)。然后运行此命令,为私有密钥验证证书生成密钥对:

    openssl genrsa -out verification_cert_key_filename.key 2048
  2. verification_cert_key_filename.key 替换为在步骤 1 中创建的密钥文件的名称。

    verification_cert_csr_filename.csr 替换为要创建的证书签名请求 (CSR) 文件的名称。例如,verification_cert.csr

    运行此命令以创建 CSR 文件。

    openssl req -new \ -key verification_cert_key_filename.key \ -out verification_cert_csr_filename.csr

    该命令会提示您输入其他信息(稍后说明)。

  3. 在 Amazon IoT 控制台的验证证书容器中,复制注册码。

  4. openssl 命令提示您输入的信息显示在以下示例中。除了 Common Name 字段,您可以在其它字段中输入自己的值或将其留空。

    Common Name 字段中,粘贴您在上一步骤中复制的注册码。

    You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]: State or Province Name (full name) []: Locality Name (for example, city) []: Organization Name (for example, company) []: Organizational Unit Name (for example, section) []: Common Name (e.g. server FQDN or YOUR name) []:your_registration_code Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:

    完成后,命令会创建 CSR 文件。

  5. verification_cert_csr_filename.csr 替换为在上一步骤中使用的 verification_cert_csr_filename.csr

    root_CA_cert_filename.pem 替换为要注册的 CA 证书的文件名。

    root_CA_key_filename.key 替换为 CA 证书的私有密钥文件的文件名。

    verification_cert_filename.pem 替换为要创建的验证证书的文件名。例如,verification_cert.pem

    openssl x509 -req \ -in verification_cert_csr_filename.csr \ -CA root_CA_cert_filename.pem \ -CAkey root_CA_key_filename.key \ -CAcreateserial \ -out verification_cert_filename.pem \ -days 500 -sha256
  6. 完成 OpenSSL 命令后,您应该准备好这些文件,以便在返回控制台时使用。

    • 您的 CA 证书文件(上一条命令中使用的 root_CA_cert_filename.pem

    • 您在上一步骤中创建的验证证书(上一条命令中使用的 verification_cert_filename.pem

停用 CA 证书

启用证书颁发机构 (CA) 证书进行自动客户端证书注册后, Amazon IoT 会检查 CA 证书以确保 CA 已启用ACTIVE。如果 CA 证书是INACTIVE,则 Amazon IoT 不允许注册客户端证书。

通过将 CA 证书设置为 INACTIVE,可防止该 CA 颁发的任何新客户端证书自动注册。

注意

除非您明确吊销由受损的 CA 证书签发的每个已注册客户端证书,否则所有此类证书均将继续工作。

停用 CA 证书(控制台)

使用 Amazon IoT 控制台停用 CA 证书
  1. 登录 Amazon Web Services Management Console 并打开Amazon IoT 控制台

  2. 在左侧的导航窗格中,依次选择安全CA

  3. 在证书颁发机构列表中,找到要停用的证书颁发机构,然后选择省略号图标以打开选项菜单。

  4. 在选项菜单上,选择停用

证书颁发机构应在列表中显示为停用

注意

Amazon IoT 控制台不提供列出由您停用的 CA 签署的证书的方法。有关列出这些证书的 Amazon CLI 选项,请参阅停用 CA 证书 (CLI)

停用 CA 证书 (CLI)

Amazon CLI 提供了停用 CA 证书的update-ca-certificate命令。

aws iot update-ca-certificate \ --certificate-id certificateId \ --new-status INACTIVE

使用 list-certificates-by-ca 命令获取已由指定 CA 签名的所有已注册客户端证书的列表。对于由指定 CA 证书签名的每个客户端证书,请使用 update-certificate 命令吊销该客户端证书以避免使用它。

使用 describe-ca-certificate 命令查看 CA 证书的状态。