

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 為 Texas Instruments CC3220SF-LAUNCHXL 建立程式碼簽署憑證
<a name="ota-code-sign-cert-ti"></a>

**重要**  <a name="deprecation-message"></a>
此參考整合託管在已棄用的 Amazon-FreeRTOS 儲存庫上。我們建議您在建立新專案時從[這裡開始](freertos-getting-started-modular.md)。如果您已經有以現在已棄用之 Amazon-FreeRTOS 儲存庫為基礎的現有 FreeRTOS 專案，請參閱 [Amazon-FreeRTOS Github 儲存庫遷移指南](github-repo-migration.md)。 FreeRTOS 

SimpleLink Wi-Fi CC3220SF Wireless Microcontroller Launchpad Development Kit 支援兩種韌體程式碼簽署的憑證鏈：
+ 生產 (certificate-catalog)

  若要使用生產憑證鏈，您必須購買商業程式碼簽署憑證，並使用 [TI Uniflash 工具](http://www.ti.com/tool/UNIFLASH)來將電路板設為生產模式。
+ 測試及開發 (certificate-playground) 

  遊樂場憑證鏈可讓您嘗試使用自我簽署的程式碼簽署憑證進行 OTA 更新。

使用 AWS Command Line Interface 將程式碼簽署憑證、私有金鑰和憑證鏈匯入至其中 AWS Certificate Manager。如需詳細資訊，請參閱*AWS Command Line Interface *[《 使用者指南》中的安裝 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) 。

下載並安裝最新版的 [SimpleLink CC3220 開發套件](http://www.ti.com/tool/download/SIMPLELINK-CC3220-SDK)。根據預設，您需要檔案所在的位置如下：

`C:\ti\simplelink_cc32xx_sdk_version\tools\cc32xx_tools\certificate-playground` (Windows) 

`/Applications/Ti/simplelink_cc32xx_version/tools/cc32xx_tools/certificate-playground` (macOS)

SimpleLink CC3220 SDK 中的憑證格式為 DER 格式。若要建立自我簽署的程式碼簽署憑證，您必須將其轉換為 PEM 格式。

請依照下列步驟建立連結至 Texas Instruments 遊樂場憑證階層的程式碼簽署憑證，並符合 AWS Certificate Manager 和 Code Signing for AWS IoT criteria。

**注意**  
若要建立程式碼簽署的憑證，請在您的機器上安裝 [OpenSSL](https://www.openssl.org/)。在安裝 OpenSSL 後，請確保將 `openssl` 指派給命令提示字元或終端機環境中的 OpenSSL 可執行檔。

**建立自我簽署的程式碼簽署憑證**

1. 使用管理員許可來開啟命令提示字元或終端機。

1. 在您的工作目錄中，使用以下文字來建立名為 `cert_config.txt` 的檔案。將 *test\$1signer@amazon.com* 取代為您的電子郵件地址。

   ```
   [ req ]
   prompt             = no
   distinguished_name = my dn
   
   [ my dn ]
   commonName = test_signer@amazon.com
   
   [ my_exts ]
   keyUsage         = digitalSignature
   extendedKeyUsage = codeSigning
   ```

1. 建立私有金鑰及憑證簽署請求 (CSR)：

   ```
   openssl req -config cert_config.txt -extensions my_exts -nodes -days 365 -newkey rsa:2048 -keyout tisigner.key -out tisigner.csr
   ```

1. 將 Texas Instruments 遊樂場根 CA 私有金鑰從 DER 格式轉換成 PEM 格式。

   TI 遊樂場根 CA 私有金鑰的所在位置如下：

   `C:\ti\simplelink_cc32xx_sdk_version\tools\cc32xx_tools\certificate-playground\dummy-root-ca-cert-key` (Windows) 

   `/Applications/Ti/simplelink_cc32xx_sdk_version/tools/cc32xx_tools/certificate-playground/dummy-root-ca-cert-key` (macOS)

   ```
   openssl rsa -inform DER -in dummy-root-ca-cert-key -out dummy-root-ca-cert-key.pem
   ```

1. 將 Texas Instruments 遊樂場根 CA 憑證從 DER 格式轉換成 PEM 格式。

   TI 遊樂場根憑證的所在位置如下：

   `C:\ti\simplelink_cc32xx_sdk_version\tools\cc32xx_tools\certificate-playground/dummy-root-ca-cert` (Windows) 

   `/Applications/Ti/simplelink_cc32xx_sdk_version/tools/cc32xx_tools/certificate-playground/dummy-root-ca-cert` (macOS)

   ```
   openssl x509 -inform DER -in dummy-root-ca-cert -out dummy-root-ca-cert.pem
   ```

1. 使用 Texas Instruments 根 CA 簽署 CSR：

   ```
   openssl x509 -extfile cert_config.txt -extensions my_exts  -req -days 365 -in tisigner.csr -CA dummy-root-ca-cert.pem -CAkey dummy-root-ca-cert-key.pem -set_serial 01 -out tisigner.crt.pem -sha1
   ```

1. 將您的程式碼簽署憑證 (`tisigner.crt.pem`) 轉換成 DER 格式：

   ```
   openssl x509 -in tisigner.crt.pem -out tisigner.crt.der -outform DER
   ```
**注意**  
您會在稍後將 `tisigner.crt.der` 憑證寫入 TI 開發電路板。

1. 將程式碼簽署憑證、私有金鑰和憑證鏈匯入至 AWS Certificate Manager：

   ```
   aws acm import-certificate --certificate fileb://tisigner.crt.pem --private-key fileb://tisigner.key --certificate-chain fileb://dummy-root-ca-cert.pem
   ```

   此命令會顯示您憑證的 ARN。在建立 OTA 更新任務時，您將需要此 ARN。
**注意**  
此步驟的編寫假設您將使用適用於 的程式碼簽署 AWS IoT 來簽署韌體映像。雖然 AWS IoT 建議使用適用於 的程式碼簽署，但您可以手動簽署韌體映像。