|
| 1 | +# Curated RFC schemas |
| 2 | + |
| 3 | +This directory holds ASN.1 modules transcribed from published RFCs, curated so |
| 4 | +that `vest_asn1` can compile them. They are inputs to the verification corpus, |
| 5 | +not part of the `vest_asn1` library. |
| 6 | + |
| 7 | +| Schema | Source | Generated module | |
| 8 | +| --- | --- | --- | |
| 9 | +| [`CMS-RFC5652-Curated.asn1`](CMS-RFC5652-Curated.asn1) | RFC 5652 §12, with structured dependencies from RFC 5280 App. A and RFC 5755 §4 | [`vest_asn1_tests/src/generated_cms.rs`](../../vest_asn1_tests/src/generated_cms.rs) | |
| 10 | + |
| 11 | +The header comment of each schema records its curation rules — what was |
| 12 | +expanded, what was replaced by ordinary wire types, and what was deliberately |
| 13 | +left out. |
| 14 | + |
| 15 | +## Generating `generated_cms.rs` |
| 16 | + |
| 17 | +The rule is recorded once, in the `generate` target of |
| 18 | +[`vest_asn1_tests/Makefile`](../../vest_asn1_tests/Makefile). Regenerate with: |
| 19 | + |
| 20 | +```sh |
| 21 | +make -C vest_asn1_tests generate |
| 22 | +``` |
| 23 | + |
| 24 | +which runs, for this schema: |
| 25 | + |
| 26 | +```sh |
| 27 | +cargo run -p vest_asn1 -- --rules ber \ |
| 28 | + --der-definition SignedAttributes \ |
| 29 | + --der-definition AuthAttributes \ |
| 30 | + --der-definition Certificate \ |
| 31 | + --der-definition CertificateList \ |
| 32 | + --der-definition AttributeCertificate \ |
| 33 | + --der-definition AttributeCertificateV1 \ |
| 34 | + vest_asn1/rfcs/CMS-RFC5652-Curated.asn1 -o vest_asn1_tests/src/generated_cms.rs |
| 35 | +``` |
| 36 | + |
| 37 | +CI regenerates and requires `git diff --exit-code` to be empty, so the committed |
| 38 | +module and this command cannot drift apart. |
| 39 | + |
| 40 | +## Why BER is the default |
| 41 | + |
| 42 | +RFC 5652 §1 states the design intent for every CMS content type: |
| 43 | + |
| 44 | +> As a general design philosophy, each content type permits single pass |
| 45 | +> processing using indefinite-length Basic Encoding Rules (BER) encoding. |
| 46 | +
|
| 47 | +and §5.2 confirms that the carried content itself is unconstrained: |
| 48 | + |
| 49 | +> The eContent need not be DER encoded. |
| 50 | +
|
| 51 | +So the CMS envelope — `ContentInfo`, `SignedData`, `EnvelopedData`, |
| 52 | +`DigestedData`, `EncryptedData`, `AuthenticatedData`, the `RecipientInfo` |
| 53 | +family, `SignerInfo`, and the unsigned/unauthenticated/unprotected attribute |
| 54 | +sets — is generated under BER. |
| 55 | + |
| 56 | +## Why the overrides are DER |
| 57 | + |
| 58 | +Each override is a structure whose octets are an input to a signature or digest. |
| 59 | +A verifier that does not re-encode — and a Vest-generated parser must not |
| 60 | +re-encode, since re-encoding is precisely the step that reintroduces |
| 61 | +malleability — has to receive those octets already in DER. |
| 62 | + |
| 63 | +| Definition | Authority | Text | |
| 64 | +| --- | --- | --- | |
| 65 | +| `SignedAttributes` | RFC 5652 §5.3 | "SignedAttributes MUST be DER encoded, even if the rest of the structure is BER encoded." | |
| 66 | +| `AuthAttributes` | RFC 5652 §9.1 | "The AuthAttributes structure MUST be DER encoded, even if the rest of the structure is BER encoded." | |
| 67 | +| `Certificate` | RFC 5280 §4.1.1.3 | "The signatureValue field contains a digital signature computed upon the ASN.1 DER encoded tbsCertificate." | |
| 68 | +| | RFC 5755 §7.3 | "the digest MUST be calculated over the DER encoding of the entire PKC, including the signature value." | |
| 69 | +| `CertificateList` | RFC 5280 §5.1.1.3 | "The signatureValue field contains a digital signature computed upon the ASN.1 DER encoded tbsCertList." | |
| 70 | +| `AttributeCertificate` | RFC 5755 §7.3 | Same signed-object shape; RFC 5755 §4 profiles ACs on top of RFC 5280. | |
| 71 | +| `AttributeCertificateV1` | RFC 5652 §12.2 | Same signed-object shape. Declared obsolete by §10.2.2, but retained for backward compatibility. | |
| 72 | + |
| 73 | +RFC 5652 §1 also says that "signed attributes and authenticated attributes are |
| 74 | +the only data types used in the CMS that require DER encoding". That is a |
| 75 | +statement about the types CMS itself defines. `Certificate`, `CertificateList`, |
| 76 | +and `AttributeCertificate` are imported from RFC 5280 and RFC 5755, and are |
| 77 | +governed by those documents. |
| 78 | + |
| 79 | +`vest_asn1` propagates a rule to every transitive child of an overridden |
| 80 | +definition without changing its parents, so the six roots above put the whole |
| 81 | +X.509 subtree under DER — `TBSCertificate`, `AlgorithmIdentifier`, `Name`, |
| 82 | +`RDNSequence`, `Extensions`, `Validity`, `SubjectPublicKeyInfo`, `GeneralName`, |
| 83 | +the X.400 `ORAddress` subtree, and `Attribute`/`AttributeValue`. The result is a |
| 84 | +62/62 split between DER and BER nominal formats. |
| 85 | + |
| 86 | +`PersonalName` lands in that closure via |
| 87 | +`AttributeCertificate → GeneralNames → GeneralName → ORAddress → |
| 88 | +BuiltInStandardAttributes`. It has to: it is a heterogeneous `SET`, and BER |
| 89 | +permits a `SET` to carry its components in any order, so `vest_asn1` emits |
| 90 | +heterogeneous `SET`s only under DER, where X.690 clause 11 fixes them in |
| 91 | +ascending tag order and a single fixed-order combinator is sound. |
| 92 | + |
| 93 | +## What is deliberately *not* overridden |
| 94 | + |
| 95 | +`ExtendedCertificate` is a signed object too, but its closure reaches |
| 96 | +`UnauthAttributes`, which CMS leaves under BER. Forcing it to DER would make |
| 97 | +unauthenticated attributes stricter than RFC 5652 allows. RFC 5652 §10.2.2 also |
| 98 | +declares it obsolete: |
| 99 | + |
| 100 | +> The PKCS #6 extended certificate is obsolete. The PKCS #6 certificate is |
| 101 | +> included for backward compatibility, and PKCS #6 certificates SHOULD NOT be |
| 102 | +> used. |
| 103 | +
|
| 104 | +so it stays BER. |
| 105 | + |
| 106 | +## Known strictness deviations |
| 107 | + |
| 108 | +`vest_asn1` gives each definition exactly one rule, so a definition shared |
| 109 | +between a DER and a BER context resolves to DER. Two shared definitions in this |
| 110 | +schema are therefore stricter than RFC 5652 alone requires: |
| 111 | + |
| 112 | +- **`Attribute` / `AttributeValue`** are DER because `SignedAttributes` and |
| 113 | + `AuthAttributes` reach them. `UnsignedAttributes`, `UnauthAttributes`, and |
| 114 | + `UnprotectedAttributes` remain BER `SET OF`s, but their *elements* must now be |
| 115 | + DER-encoded. RFC 5652 permits BER there. |
| 116 | +- **`AlgorithmIdentifier`** is DER because `TBSCertificate` reaches it. The |
| 117 | + aliases `DigestAlgorithmIdentifier`, `SignatureAlgorithmIdentifier`, |
| 118 | + `KeyEncryptionAlgorithmIdentifier`, `ContentEncryptionAlgorithmIdentifier`, |
| 119 | + `MessageAuthenticationCodeAlgorithm`, and `KeyDerivationAlgorithmIdentifier` |
| 120 | + stay BER as parents, but the algorithm identifier they wrap — including the |
| 121 | + one in a BER `SignerInfo` — must be DER-encoded. RFC 5652 permits BER there. |
| 122 | + |
| 123 | +Both narrow the set of accepted encodings; neither accepts anything the RFCs |
| 124 | +reject. Splitting the shared definitions in the curated schema would remove them |
| 125 | +at the cost of introducing type names that do not appear in the source RFCs. |
| 126 | + |
| 127 | +## Scope |
| 128 | + |
| 129 | +This is a wire schema. It does not express CMS version-selection rules, |
| 130 | +algorithm policy, attribute uniqueness, `ANY DEFINED BY` dispatch, or any |
| 131 | +cryptographic validation. See [`../scalability.md`](../scalability.md) for how |
| 132 | +this module drove the nominal-format and start-domain design. |
0 commit comments