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 にある4つの 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分
- マージ済み PR(30日)
- 35
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 1週間以上 初心者へのやさしさ 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
-
benchmark-review
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
メンテナーはふだん 1 日以内に返信
-
area:filesystem bug need-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Captions panel does not offer to show an existing transcript対応中かも @thedavidweng が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
CapSoftware/Cap#4276 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
libracoder/kiri#364 ·
メンテナーはふだん 1 日以内に返信