Red Hat Training

A Red Hat training course is available for RHEL 8

65.6. 准备智能卡并将证书和密钥上传到智能卡

按照以下流程,使用 pkcs15-init 工具配置智能卡,该工具可帮助您配置:

  • 擦除智能卡
  • 设置新的 PIN 和可选的 PIN Unblocking Keys(PUKs)
  • 在智能卡上创建新插槽
  • 在插槽存储证书、私钥和公钥
  • 如果需要,请锁定智能卡设置,因为某些智能卡需要这个类型的最终化
注意

pkcs15-init 工具可能无法使用所有智能卡。您必须使用您使用智能卡的工具。

先决条件

  • 已安装 opensc 软件包,其中包括 pkcs15-init 工具。

    如需了解更多详细信息,请参阅 安装用于管理和使用智能卡的工具

  • 该卡插入读卡器并连接到计算机。
  • 您有一个要存储在智能卡上的私钥、公钥和证书。在此流程中,testuser.keytestuserpublic.keytestuser.crt 是用于私钥、公钥和证书的名称。
  • 您有当前的智能卡用户 PIN 和 Security Officer PIN(SO-PIN)。

流程

  1. 擦除智能卡并使用您的 PIN 验证自己:

    $ pkcs15-init --erase-card --use-default-transport-keys
    Using reader with a card: Reader name
    PIN [Security Officer PIN] required.
    Please enter PIN [Security Officer PIN]:

    这个卡已经被清除。

  2. 初始化智能卡,设置您的用户 PIN 和 PUK,以及您的安全响应 PIN 和 PUK:

    $ pkcs15-init --create-pkcs15 --use-default-transport-keys \ --pin 963214 --puk 321478 --so-pin 65498714 --so-puk 784123
    Using reader with a card: Reader name

    pcks15-init 工具在智能卡上创建一个新插槽。

  3. 为插槽设置标签和验证 ID:

    $ pkcs15-init --store-pin --label testuser \ --auth-id 01 --so-pin 65498714 --pin 963214 --puk 321478
    Using reader with a card: Reader name

    标签设置为人类可读的值,在本例中为 testuserauth-id 必须是两个十六进制值,在本例中设为 01

  4. 在智能卡的新插槽中存储并标记私钥:

    $ pkcs15-init --store-private-key testuser.key --label testuser_key \ --auth-id 01 --id 01 --pin 963214
    Using reader with a card: Reader name
    注意

    在存储您的私钥并将证书存储在下一步中时,您为 --id 指定的值必须相同。建议为 --id 指定自己的值,否则它们将更复杂的值由工具计算。

  5. 在智能卡上的新插槽中存储并标记该证书:

    $ pkcs15-init --store-certificate testuser.crt --label testuser_crt \ --auth-id 01 --id 01 --format pem --pin 963214
    Using reader with a card: Reader name
  6. 可选:在智能卡的新插槽中保存并标记公钥:

    $ pkcs15-init --store-public-key testuserpublic.key --label testuserpublic_key --auth-id 01 --id 01 --pin 963214
    Using reader with a card: Reader name
    注意

    如果公钥与私钥或证书对应,请指定与私钥或证书的 ID 相同的 ID。

  7. 可选:某些智能卡要求您通过锁定设置来完成卡:

    $ pkcs15-init -F

    此时您的智能卡在新创建的插槽中包含证书、私钥和公钥。您还创建了您的用户 PIN 和 PUK,以及安全响应 PIN 和 PUK。