7. Key 对象
- Key 对象
COSE Key 结构建立在 CBOR map 之上. 可出现在 COSE Key 中的 common parameters 集合见 IANA "COSE Key Common Parameters" registry [COSE.KeyParameters] (见 Section 11.2). 针对特定 key type 定义的附加参数见 IANA "COSE Key Type Parameters" registry [COSE.KeyTypes].
COSE Key Set 使用 CBOR array object 作为其底层类型. array 元素的值是 COSE Keys. COSE Key Set MUST 在 array 中至少有一个元素. COSE Key Sets 示例见 Appendix C.7.
COSE Key Set 中的每个元素 MUST 独立处理. 如果 COSE Key Set 中某个元素格式错误, 或使用了应用程序不理解的 key, 则忽略该 key, 并正常处理其他 key.
元素 "kty" 是 COSE_Key map 中的必需元素.
描述 COSE_Key 和 COSE_KeySet 的 CDDL grammar 为:
COSE_Key = {
1 => tstr / int, ; kty
? 2 => bstr, ; kid
? 3 => tstr / int, ; alg
? 4 => [+ (tstr / int) ], ; key_ops
? 5 => bstr, ; Base IV
* label => values
}
COSE_KeySet = [+COSE_Key]
7.1. COSE Key Common Parameters
本文档为 COSE Key object 定义一组 common parameters. Table 4 汇总了本节定义的参数. 另有一些参数是为特定 key type 定义的. key-type-specific parameters 见 [RFC9053].
+=========+=======+========+============+====================+
| Name | Label | CBOR | Value | 描述 |
| | | Type | Registry | |
+=========+=======+========+============+====================+
| kty | 1 | tstr / | COSE Key | key type 的标识 |
| | | int | Types | |
+---------+-------+--------+------------+--------------------+
| kid | 2 | bstr | | Key identification |
| | | | | value -- 与消息中 |
| | | | | 的 "kid" 匹配 |
+---------+-------+--------+------------+--------------------+
| alg | 3 | tstr / | COSE | 将 key usage 限制 |
| | | int | Algorithms | 到此 algorithm |
+---------+-------+--------+------------+--------------------+
| key_ops | 4 | [+ | | 限制允许的操作集合 |
| | | (tstr/ | | |
| | | int)] | | |
+---------+-------+--------+------------+--------------------+
| Base IV | 5 | bstr | | 要与 Partial IVs |
| | | | | xor-ed 的 Base IV |
+---------+-------+--------+------------+--------------------+
Table 4: Key Map Labels
kty: 此参数用于识别该结构的 key family, 因而也识别要查找的 key-type-specific parameters 集合. 本文档定义的值集合见 [COSE.KeyTypes]. 此参数 MUST 出现在 key object 中. 实现 MUST 验证 key type 适合正在处理的 algorithm. key type MUST 作为 trust-decision process 的一部分包含进去.
alg: 此参数用于限制与该 key 一起使用的 algorithm. 如果此参数出现在 key structure 中, 应用程序 MUST 验证该 algorithm 与此 key 正在用于的 algorithm 相匹配. 如果 algorithm 不匹配, 则此 key object MUST NOT 用于执行 cryptographic operation. 注意, 同一个 key 可以位于另一个 key structure 中, 并指定不同 algorithm 或不指定 algorithm; 但是, 这被认为是不良安全实践.
kid: 此参数用于给出 key 的 identifier. 该 identifier 没有结构, 可以是用户提供的 byte string, 也可以是根据 key 的 public portion 计算得到的值. 此字段用于与消息中的 "kid" parameter 匹配, 以缩小需要检查的 key 集合. identifier 的值不是唯一值, 即使对于不同 key, 它也可以出现在其他 key object 中.
key_ops: 此参数定义为限制 key 可用于的操作集合. 字段值是由 Table 5 中的值组成的 array. algorithm 定义允许出现并且特定操作所需的 key ops 值. 该值集合与 [RFC7517] 和 [W3C.WebCrypto] 中的集合匹配.
Base IV: 此参数定义为承载 IV 的 base portion. 它设计为与 Section 3.1 中定义的 Partial IV header parameter 一起使用. 此字段提供将 Base IV 与 key 关联的能力, 随后可基于每条消息用 Partial IV 修改它.
在应用中使用 Base IV 时需要极其谨慎. 如果同一个 IV 被使用两次, 许多 encryption algorithms 会失去安全性.
如果为每个 sender 派生不同 key, 从相同 Base IV 开始很可能满足此条件. 如果多个 sender 使用同一个 key, 则应用需要提供一种方法, 在 sender 之间划分 IV space. 这可以通过提供不同的起始 base point 或不同的起始 Partial IV, 并限制重新生成 key 前可发送的消息数量来完成.
+=========+=======+==============================================+
| Name | Value | 描述 |
+=========+=======+==============================================+
| sign | 1 | 该 key 用于创建 signatures. |
| | | 需要 private key fields. |
+---------+-------+----------------------------------------------+
| verify | 2 | 该 key 用于验证 signatures. |
+---------+-------+----------------------------------------------+
| encrypt | 3 | 该 key 用于 key transport encryption. |
+---------+-------+----------------------------------------------+
| decrypt | 4 | 该 key 用于 key transport decryption. |
| | | 需要 private key fields. |
+---------+-------+----------------------------------------------+
| wrap | 5 | 该 key 用于 key wrap encryption. |
| key | | |
+---------+-------+----------------------------------------------+
| unwrap | 6 | 该 key 用于 key wrap decryption. |
| key | | 需要 private key fields. |
+---------+-------+----------------------------------------------+
| derive | 7 | 该 key 用于派生 keys. 需要 private key |
| key | | fields. |
+---------+-------+----------------------------------------------+
| derive | 8 | 该 key 用于派生不作为 key 使用的 bits. |
| bits | | 需要 private key fields. |
+---------+-------+----------------------------------------------+
| MAC | 9 | 该 key 用于创建 MACs. |
| create | | |
+---------+-------+----------------------------------------------+
| MAC | 10 | 该 key 用于验证 MACs. |
| verify | | |
+---------+-------+----------------------------------------------+
Table 5: Key Operation Values