cms: CHOICE types in `SET OF` are ordered as `SEQUENCE OF INTEGER`, not by their bytes
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- rust
- Área
- cryptography
Línea de trabajo
El issue menciona las cuatro implementaciones de ValueOrd en cert.rs, enveloped_data.rs, revocation.rs y signed_data.rs. Lee cómo compara cada una las codificaciones DER y comprueba el orden según la comparación de cadenas de bytes descrita en el issue. El trabajo estará hecho cuando los conjuntos CMS afectados se ordenen por sus bytes codificados y la decodificación seguida de una nueva codificación conserve el orden DER.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Rust
- Estrellas
- 347
- Forks
- 200
- Merge medio
- 20 h 27 min
- PR fusionados (30 d)
- 35
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de RustCrypto/formats
-
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)Posiblemente ocupada @choksi2212 la tomó hace 23 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
RustCrypto/formats#2486 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
IssuingDistributionPoint has the wrong AssociatedOid (id-pe-subjectInfoAccess)Posiblemente ocupada @eyusd la tomó hace 101 días. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 86/100
RustCrypto/formats#2389 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
RustCrypto/formats#2366 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
RustCrypto/formats#2533 ·
Los mantenedores suelen responder en 1 día
-
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 v1Posiblemente ocupada @choksi2212 la tomó hace 23 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 61/100
RustCrypto/formats#2487 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de RustCrypto/formats
Issues similares
-
benchmark-review
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
Los mantenedores suelen responder en 1 día
-
area:filesystem bug need-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Captions panel does not offer to show an existing transcriptPosiblemente ocupada @thedavidweng la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
CapSoftware/Cap#4276 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
libracoder/kiri#364 ·
Los mantenedores suelen responder en 1 día