cms: CHOICE types in `SET OF` are ordered as `SEQUENCE OF INTEGER`, not by their bytes
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust
- 领域
- cryptography
调研方向
issue 列出了 cert.rs、enveloped_data.rs、revocation.rs 和 signed_data.rs 中的四个 ValueOrd 实现。阅读每个实现如何比较 DER 编码,并根据 issue 中描述的字节串比较来检查排序。完成的标准是:受影响的 CMS 集合按其编码后的字节排序,解码后再重新编码仍能保留 DER 顺序。
由索引模型根据 Issue 内容生成。
描述
Found it while playing with EST server implementation and parsing example certs from RFC 7030 Appendix A.1 for /cacerts response. I encountered it in cert.rs, but same thing happens in enveloped_data.rs, revocation.rs and signed_data.rs.
Tl;dr: The comparison starts from correctly comparing headers, but if they're the same (same length certs) it tries to compare values of CHOICE and there it treats the whole blob (header included) as SEQUENCE OF INTEGER, makes a new, wrong header that can lie about length because bytes >=0x80 will get long encoding and then sorting falls apart.
The ValueOrd impls of CertificateChoices, RevocationInfoChoice, RecipientInfo and SignerIdentifier encode both values and compare the results with der_cmp:
self.to_der()?.der_cmp(&other.to_der()?)
to_der() returns Vec<u8>, and Vec<u8> gets DerOrd from the Vec<T> SEQUENCE OF impl, with each u8 as an INTEGER. So this compares the two encodings as if they were SEQUENCE OF INTEGER values. X.690 11.6 orders SET OF elements by comparing their encodings as octet strings, which for complete DER TLVs is Vec<u8>::cmp.
The two disagree:
use core::cmp::Ordering;
use der::DerOrd;
let a = vec![0x00u8, 0x80];
let b = vec![0x01u8, 0x00];
assert_eq!(a.cmp(&b), Ordering::Less);
assert_eq!(a.der_cmp(&b).unwrap(), Ordering::Less); // fails: Greater
As SEQUENCE OF INTEGER, a becomes 30 07 02 01 00 02 02 00 80 and b becomes 30 06 02 01 01 02 01 00. der_cmp compares these new headers first and gives wrong order.
SetOfVec sorts with this order when it is built and when it is decoded. So cms encodes CertificateSet, RevocationInfoChoices, RecipientInfos and SignerInfos (SignerInfo's derived ordering compares sid) in an order that is not DER, and decoding a correctly ordered set and encoding it again can change its bytes.
Example: the /cacerts response in RFC 7030 Appendix A.1 has four certificates. Decoded with cms, SignedData.certificates comes out as
NwN, OwO, OwN, NwO
The byte order is
OwO, NwN, NwO, OwN
(The RFC's own encoding uses neither order, so it isn't DER either.)
OwO and NwN are both 767 bytes, and NwO and OwN are both 775, yet each pair comes out swapped: their SEQUENCE OF INTEGER lengths differ (OwO 2599, NwN 2594, NwO 2640, OwN 2626).
Changing the four impls to Ok(self.to_der()?.cmp(&other.to_der()?)) fixes it. PR to follow.
- 主要语言
- Rust
- 星标
- 347
- 派生
- 200
- 平均合并
- 20 小时 27 分钟
- 30 天内合并 PR
- 35
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
RustCrypto/formats 的其他 Issue
-
pem-rfc7468: a lone CR before -----BEGIN is refused as Error::Preamble, so a CR-terminated multi-certificate PEM fails load_pem_chain (RFC 7468 eol = CRLF / CR / LF)可能已有人在做 @choksi2212 于 23 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 77/100
RustCrypto/formats#2486 · 1 条评论 ·
维护者通常 1 天内回复
-
IssuingDistributionPoint has the wrong AssociatedOid (id-pe-subjectInfoAccess)可能已有人在做 @eyusd 于 101 天前认领。 未关闭
难度 1/5 1-3 小时 新手友好度 86/100
RustCrypto/formats#2389 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
RustCrypto/formats#2366 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
RustCrypto/formats#2533 ·
维护者通常 1 天内回复
-
x509-cert 0.3.0 declares RFC 5914's TrustAnchorInfo v1 as 0, so it encodes v1 as INTEGER 0 and reads a written version 0 as v1可能已有人在做 @choksi2212 于 23 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 61/100
RustCrypto/formats#2487 · 2 条评论 ·
维护者通常 1 天内回复
查看 RustCrypto/formats 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
matrix-org/matrix-rust-sdk#7495 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
yantrikos/yantrik-os#1272 ·
维护者通常 1 天内回复
-
crate: spate-kafka priority: low tech-debt
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
macOS 菜单栏托盘图标保留橙色,与系统单色图标风格不一致可能已有人在做 @xhugoliu 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
YizhengWw/HachimoDock#56 · 1 条评论 ·