使用 CloudHSM CLI 共享和取消共享密钥 - AWS CloudHSM

使用 CloudHSM CLI 共享和取消共享密钥

使用本主题中的命令在 CloudHSM CLI 中共享和取消共享密钥。在 AWS CloudHSM 中,创建密钥的加密用户(CU)将拥有密钥。所有者可以使用 key sharekey unshare 命令,与其他 CU 共享和取消共享密钥。密钥的共享用户可在加密操作中使用密钥,但无法导出或删除密钥,也无法与其他用户共享密钥。

要共享密钥,您必须以拥有该密钥的加密用户(CU)的身份登录到 HSM。

示例:共享和取消共享密钥

以下示例演示了如何与加密用户(CU)alice 共享密钥和与其取消共享。除 key sharekey unshare 命令外,共享和取消共享命令还需要使用 CloudHSM CLI 密钥筛选器的特定密钥以及要与之共享或取消共享密钥的用户的特定用户名。

  1. 首先,使用筛选器运行 key list 命令以返回特定的密钥,然后查看密钥已与谁共享。

    aws-cloudhsm > key list --filter attr.label="rsa_key_to_share" --verbose { "error_code": 0, "data": { "matched_keys": [ { "key-reference": "0x00000000001c0686", "key-info": { "key-owners": [ { "username": "cu3", "key-coverage": "full" } ], "shared-users": [ { "username": "cu2", "key-coverage": "full" }, { "username": "cu1", "key-coverage": "full" }, { "username": "cu4", "key-coverage": "full" }, { "username": "cu5", "key-coverage": "full" }, { "username": "cu6", "key-coverage": "full" }, { "username": "cu7", "key-coverage": "full" }, ], "cluster-coverage": "full" }, "attributes": { "key-type": "rsa", "label": "rsa_key_to_share", "id": "", "check-value": "0xae8ff0", "class": "private-key", "encrypt": false, "decrypt": true, "token": true, "always-sensitive": true, "derive": false, "destroyable": true, "extractable": true, "local": true, "modifiable": true, "never-extractable": false, "private": true, "sensitive": true, "sign": true, "trusted": false, "unwrap": true, "verify": false, "wrap": false, "wrap-with-trusted": false, "key-length-bytes": 1219, "public-exponent": "0x010001", "modulus": "0xa8855cba933cec0c21a4df0450ec31675c024f3e65b2b215a53d2bda6dcd191f75729150b59b4d86df58254c8f518f7d000cc04d8e958e7502c7c33098e28da4d94378ef34fb57d1cc7e042d9119bd79be0df728421a980a397095157da24cf3cc2b6dab12225d33fdca11f0c6ed1a5127f12488cda9a556814b39b06cd8373ff5d371db2212887853621b8510faa7b0779fbdec447e1f1d19f343acb02b22526487a31f6c704f8f003cb4f7013136f90cc17c2c20e414dc1fc7bcfb392d59c767900319679fc3307388633485657ce2e1a3deab0f985b0747ef4ed339de78147d1985d14fdd8634219321e49e3f5715e79c298f18658504bab04086bfbdcd3b", "modulus-size-bits": 2048 } } ], "total_key_count": 1, "returned_key_count": 1 } }
  2. 查看 shared-users 输出以确定当前与谁共享密钥。

  3. 要与加密用户(CU)alice 共享此密钥,请输入以下命令:

    aws-cloudhsm > key share --filter attr.label="rsa_key_to_share" attr.class=private-key --username alice --role crypto-user { "error_code": 0, "data": { "message": "Key shared successfully" } }

    请注意,除了 key share 命令外,此命令还使用密钥的唯一标签和将与之共享密钥的用户的姓名。

  4. 再次运行 key list 命令以确认已与 alice 共享该密钥:

    aws-cloudhsm > key list --filter attr.label="rsa_key_to_share" --verbose { "error_code": 0, "data": { "matched_keys": [ { "key-reference": "0x00000000001c0686", "key-info": { "key-owners": [ { "username": "cu3", "key-coverage": "full" } ], "shared-users": [ { "username": "cu2", "key-coverage": "full" }, { "username": "cu1", "key-coverage": "full" }, { "username": "cu4", "key-coverage": "full" }, { "username": "cu5", "key-coverage": "full" }, { "username": "cu6", "key-coverage": "full" }, { "username": "cu7", "key-coverage": "full" }, { "username": "alice", "key-coverage": "full" } ], "cluster-coverage": "full" }, "attributes": { "key-type": "rsa", "label": "rsa_key_to_share", "id": "", "check-value": "0xae8ff0", "class": "private-key", "encrypt": false, "decrypt": true, "token": true, "always-sensitive": true, "derive": false, "destroyable": true, "extractable": true, "local": true, "modifiable": true, "never-extractable": false, "private": true, "sensitive": true, "sign": true, "trusted": false, "unwrap": true, "verify": false, "wrap": false, "wrap-with-trusted": false, "key-length-bytes": 1219, "public-exponent": "0x010001", "modulus": "0xa8855cba933cec0c21a4df0450ec31675c024f3e65b2b215a53d2bda6dcd191f75729150b59b4d86df58254c8f518f7d000cc04d8e958e7502c7c33098e28da4d94378ef34fb57d1cc7e042d9119bd79be0df728421a980a397095157da24cf3cc2b6dab12225d33fdca11f0c6ed1a5127f12488cda9a556814b39b06cd8373ff5d371db2212887853621b8510faa7b0779fbdec447e1f1d19f343acb02b22526487a31f6c704f8f003cb4f7013136f90cc17c2c20e414dc1fc7bcfb392d59c767900319679fc3307388633485657ce2e1a3deab0f985b0747ef4ed339de78147d1985d14fdd8634219321e49e3f5715e79c298f18658504bab04086bfbdcd3b", "modulus-size-bits": 2048 } } ], "total_key_count": 1, "returned_key_count": 1 } }
  5. 要取消与 alice 共享同一密钥,请运行以下 unshare 命令:

    aws-cloudhsm > key unshare --filter attr.label="rsa_key_to_share" attr.class=private-key --username alice --role crypto-user { "error_code": 0, "data": { "message": "Key unshared successfully" } }

    请注意,除了 key unshare 命令外,此命令还使用密钥的唯一标签和将与之共享密钥的用户的姓名。

  6. 再次运行 key list 命令并确认已取消与加密用户 alice 共享该密钥:

    aws-cloudhsm > key list --filter attr.label="rsa_key_to_share" --verbose { "error_code": 0, "data": { "matched_keys": [ { "key-reference": "0x00000000001c0686", "key-info": { "key-owners": [ { "username": "cu3", "key-coverage": "full" } ], "shared-users": [ { "username": "cu2", "key-coverage": "full" }, { "username": "cu1", "key-coverage": "full" }, { "username": "cu4", "key-coverage": "full" }, { "username": "cu5", "key-coverage": "full" }, { "username": "cu6", "key-coverage": "full" }, { "username": "cu7", "key-coverage": "full" }, ], "cluster-coverage": "full" }, "attributes": { "key-type": "rsa", "label": "rsa_key_to_share", "id": "", "check-value": "0xae8ff0", "class": "private-key", "encrypt": false, "decrypt": true, "token": true, "always-sensitive": true, "derive": false, "destroyable": true, "extractable": true, "local": true, "modifiable": true, "never-extractable": false, "private": true, "sensitive": true, "sign": true, "trusted": false, "unwrap": true, "verify": false, "wrap": false, "wrap-with-trusted": false, "key-length-bytes": 1219, "public-exponent": "0x010001", "modulus": "0xa8855cba933cec0c21a4df0450ec31675c024f3e65b2b215a53d2bda6dcd191f75729150b59b4d86df58254c8f518f7d000cc04d8e958e7502c7c33098e28da4d94378ef34fb57d1cc7e042d9119bd79be0df728421a980a397095157da24cf3cc2b6dab12225d33fdca11f0c6ed1a5127f12488cda9a556814b39b06cd8373ff5d371db2212887853621b8510faa7b0779fbdec447e1f1d19f343acb02b22526487a31f6c704f8f003cb4f7013136f90cc17c2c20e414dc1fc7bcfb392d59c767900319679fc3307388633485657ce2e1a3deab0f985b0747ef4ed339de78147d1985d14fdd8634219321e49e3f5715e79c298f18658504bab04086bfbdcd3b", "modulus-size-bits": 2048 } } ], "total_key_count": 1, "returned_key_count": 1 } }

相关 主题