`cms` accepts non-`OCTET STRING` `eContent`, empty `SignedAttributes` sets, and duplicate `message-digest` attributes
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 46/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- rust
- Ambito
- cryptography, security
Direzione di ricerca
Start with cms/src/signed_data.rs to inspect EncapsulatedContentInfo and the attribute set types, then review cms/src/builder/signed_data.rs for SignerInfoBuilder::finalize and SignedDataBuilder::add_digest_algorithm. Run the CMS crate tests and add coverage for invalid tags, empty or duplicate attributes, and duplicate digest algorithms. Done means these inputs are rejected or normalized according to the cited RFC constraints.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Note: This is a low-priority RFC conformance edge case (not a security issue). Sharing it for tracking only — totally up to the maintainers whether it's worth fixing or closing as won't-fix.
Specification
RFC 5652 Section 5.2 defines EncapsulatedContentInfo with eContent typed strictly as [0] EXPLICIT OCTET STRING OPTIONAL:
EncapsulatedContentInfo ::= SEQUENCE { eContentType ContentType, eContent [0] EXPLICIT OCTET STRING OPTIONAL } ContentType ::= OBJECT IDENTIFIERThe fields of type EncapsulatedContentInfo have the following
meanings:eContentType is an object identifier. The object identifier uniquely specifies the content type. eContent is the content itself, carried as an octet string. The eContent need not be DER encoded.
RFC 5652 Section 5.3 constrains both SignedAttributes and UnsignedAttributes to SET SIZE (1..MAX) OF Attribute:
SignerInfo ::= SEQUENCE { version CMSVersion, sid SignerIdentifier, digestAlgorithm DigestAlgorithmIdentifier, signedAttrs [0] IMPLICIT SignedAttributes OPTIONAL, signatureAlgorithm SignatureAlgorithmIdentifier, signature SignatureValue, unsignedAttrs [1] IMPLICIT UnsignedAttributes OPTIONAL } SignerIdentifier ::= CHOICE { issuerAndSerialNumber IssuerAndSerialNumber, subjectKeyIdentifier [0] SubjectKeyIdentifier } SignedAttributes ::= SET SIZE (1..MAX) OF Attribute UnsignedAttributes ::= SET SIZE (1..MAX) OF Attribute
In the field descriptions of RFC 5652 Section 5.3, whenever signedAttrs is present it must contain at least content-type and message-digest:
signedAttrs is a collection of attributes that are signed. The field is optional, but it MUST be present if the content type of the EncapsulatedContentInfo value being signed is not id-data. SignedAttributes MUST be DER encoded, even if the rest of the structure is BER encoded. Useful attribute types, such as signing time, are defined in Section 11. If the field is present, it MUST contain, at a minimum, the following two attributes: A content-type attribute having as its value the content type of the EncapsulatedContentInfo value being signed. Section 11.1 defines the content-type attribute. However, the content-type attribute MUST NOT be used as part of a countersignature unsigned attribute as defined in Section 11.4. A message-digest attribute, having as its value the message digest of the content. Section 11.2 defines the message-digest attribute.
RFC 5652 Section 11.2 further forbids multiple instances of message-digest within SignedAttributes:
The SignedAttributes syntax and AuthAttributes syntax are each
defined as a SET OF Attributes. The SignedAttributes in a signerInfo
MUST include only one instance of the message-digest attribute.
Similarly, the AuthAttributes in an AuthenticatedData MUST include
only one instance of the message-digest attribute.
Code
In signed_data.rs, EncapsulatedContentInfo stores econtent as Option<Any> instead of Option<OctetString>, so [0] EXPLICIT accepts any ASN.1 tag:
#[derive(Clone, Debug, Eq, PartialEq, Sequence)]
#[allow(missing_docs)]
pub struct EncapsulatedContentInfo {
pub econtent_type: ObjectIdentifier,
#[asn1(context_specific = "0", tag_mode = "EXPLICIT", optional = "true")]
pub econtent: Option<Any>,
}
In the same file (signed_data.rs), SignedAttributes and UnsignedAttributes are aliases for x509_cert::attr::Attributes (SetOfVec<Attribute>), which allows empty SET {} values:
/// The `SignerInfo` type is defined in [RFC 5652 Section 5.3].
///
/// ```text
/// SignedAttributes ::= SET SIZE (1..MAX) OF Attribute
/// ```
///
/// [RFC 5652 Section 5.3]: https://www.rfc-editor.org/info/rfc5652#section-5.3
pub type SignedAttributes = Attributes;
/// The `UnsignedAttributes` type is defined in [RFC 5652 Section 5.3].
///
/// ```text
/// UnsignedAttributes ::= SET SIZE (1..MAX) OF Attribute
/// ```
///
/// [RFC 5652 Section 5.3]: https://www.rfc-editor.org/info/rfc5652#section-5.3
pub type UnsignedAttributes = Attributes;
In signed_data.rs under cms/src/builder/, SignerInfoBuilder::finalize hashes content.value() without checking for Tag::OctetString, always initializes self.signed_attributes = Some(vec![]) even when message_digest is None (producing an empty SET {}), and pushes create_message_digest_attribute without checking whether ID_MESSAGE_DIGEST is already present (even though it checks ID_CONTENT_TYPE right below):
fn finalize<S>(&mut self, _signer: &S) -> builder::Result<Vec<u8>>
where
S: Keypair + DynSignatureAlgorithmIdentifier,
S::VerifyingKey: EncodePublicKey,
{
let message_digest = match self.external_message_digest {
Some(external_content_digest) => {
if self.encapsulated_content_info.econtent.is_some() {
// Encapsulated content must be empty, if external digest is given.
return Err(der::Error::from(ErrorKind::Failed).into());
}
Some(external_content_digest.to_vec())
}
None => match &self.encapsulated_content_info.econtent {
None => {
// This case is allowed. E.g. for degenerate certificates-only messages.
// See RFC 5652 § 5.2 or RFC 8894 § 3.4.
None
}
Some(content) => {
let mut hasher = get_hasher(&self.digest_algorithm).ok_or_else(|| {
// Unsupported hash algorithm: {}, &self.digest_algorithm.oid.to_string()
builder::Error::from(der::Error::from(ErrorKind::Failed))
})?;
// Only the octets comprising the value of the eContent
// OCTET STRING are input to the message digest algorithm, not the tag
// or the length octets.
let content_value = content.value();
hasher.update(content_value);
Some(hasher.finalize_reset().to_vec())
}
},
};
// This implementation uses signed attributes to store the message digest.
if self.signed_attributes.is_none() {
self.signed_attributes = Some(vec![]);
}
let signed_attributes = self
.signed_attributes
.as_mut()
.expect("Signed attributes must be present.");
if let Some(message_digest) = message_digest {
// Add digest attribute to (to be) signed attributes
signed_attributes.push(
create_message_digest_attribute(&message_digest)
.map_err(|_| der::Error::from(ErrorKind::Failed))?,
);
// The content-type attribute type specifies the content type of the
// ContentInfo within signed-data or authenticated-data. The content-
// type attribute type MUST be present whenever signed attributes are
// present in signed-data or authenticated attributes present in
// authenticated-data. The content-type attribute value MUST match the
// encapContentInfo eContentType value in the signed-data or
// authenticated-data.
let econtent_type = self.encapsulated_content_info.econtent_type;
let signed_attributes_content_type = signed_attributes.iter().find(|attr| {
attr.oid.cmp(&const_oid::db::rfc5911::ID_CONTENT_TYPE) == Ordering::Equal
});
if let Some(signed_attributes_content_type) = signed_attributes_content_type {
if signed_attributes_content_type.values.len() != 1 {
return Err(der::Error::from(ErrorKind::Failed).into());
}
let Some(value) = signed_attributes_content_type.values.get(0) else {
return Err(der::Error::from(ErrorKind::Failed).into());
};
let value = value.decode_as::<ObjectIdentifier>()?;
// Check against `eContentType`
if value != econtent_type {
// Mismatch between content types: encapsulated content info <-> signed attributes.
return Err(der::Error::from(ErrorKind::Failed).into());
}
} else {
signed_attributes.push(
create_content_type_attribute(econtent_type)
.map_err(|_| der::Error::from(ErrorKind::Failed))?,
);
}
}
// Now use `signer` to sign the DER encoded signed attributes
let signed_attributes = SignedAttributes::try_from(signed_attributes.to_owned())
.map_err(|_| der::Error::from(ErrorKind::Failed))?;
let mut signed_attributes_der = Vec::new();
signed_attributes.encode_to_vec(&mut signed_attributes_der)?;
Ok(signed_attributes_der)
}
In the same builder file (signed_data.rs), SignedDataBuilder::add_digest_algorithm pushes onto self.digest_algorithms without deduplicating equal entries, and SetOfVec::try_from keeps those duplicates in SignedData.digest_algorithms:
pub fn add_digest_algorithm(
&mut self,
digest_algorithm: AlgorithmIdentifierOwned,
) -> Result<&mut Self> {
self.digest_algorithms.push(digest_algorithm);
Ok(self)
}
- Lingua principale
- Rust
- Stelle
- 352
- Fork
- 209
- Merge medio
- 4h 12m
- PR unite (30g)
- 39
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di RustCrypto/formats
-
x509-cert: v1 CRLs fail to decode (`TBSCertList.version` is OPTIONAL)Forse già presa @lyn1dev l’ha presa 12 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
RustCrypto/formats#2544 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
cms: `OtherRevocationInfoFormat.other_format` should be an OBJECT IDENTIFIERForse già presa @AmanBoronbaev l’ha presa 18 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
RustCrypto/formats#2543 ·
I maintainer di solito rispondono entro 1 giorno
-
cms: CHOICE types in `SET OF` are ordered as `SEQUENCE OF INTEGER`, not by their bytesForse già presa @brother-z l’ha presa 21 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
RustCrypto/formats#2538 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
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)Forse già presa @choksi2212 l’ha presa 43 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
RustCrypto/formats#2486 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
IssuingDistributionPoint has the wrong AssociatedOid (id-pe-subjectInfoAccess)Forse già presa @eyusd l’ha presa 122 giorni fa. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 86/100
RustCrypto/formats#2389 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di RustCrypto/formats
Issue simili
-
The new tests repeat each other and one only checks a two-line helperForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertainfra
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
storytold/wordcraft#9405 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
in-progress
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
area: ai-assistants documentation help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
BetaBots-LLC/latticegate#17 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 94/100
storytold/craft-libs#5594 ·
I maintainer di solito rispondono entro 1 giorno
-
available documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Nixitov/Riptide-Native#932 ·
I maintainer di solito rispondono entro 1 giorno