Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,10 @@ pub proof fn lemma_one_san_conditions(p: ps::PathCert, y: s::Certificate)

/// **`theorem_path_cert_back`'s and `theorem_path_cert_fwd`'s conditions are met
/// by a certificate with an extension,** so they, and `theorem_reading`, are
/// not vacuous. And **`subject_rule` is not enforced:** the certificate's
/// subject is empty and its subjectAltName is not critical, so 7.2.1 refuses
/// it, and `parse_path_cert` keeps it (limbo pins the same for a whole path:
/// not vacuous. And **`subject_rule` is not `parse_path_cert`'s:** the
/// certificate's subject is empty and its subjectAltName is not critical, so
/// 7.2.1 refuses it, and `parse_path_cert` keeps it. `leaf_profile` step 4
/// refuses it as a target (`theorem_subject_rule_target`; limbo:
/// `rfc5280::san::noncritical-with-empty-subject`).
#[verifier::spinoff_prover]
pub proof fn example_path_conditions_hold()
Expand Down
139 changes: 138 additions & 1 deletion crates/clazel-x509/src/independent/equivalence_requirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! | `version_rules` | always | `theorem_version_rules` |
//! | `signature_algorithms_agree` | one way: `equivalence_signature.rs`; RSA NULL against absent stays | `theorem_signature_algorithms` |
//! | `issuer_non_empty` | always | `theorem_issuer_non_empty` |
//! | `subject_rule` | target: enforced by `path/profile.rs` step 4, not yet proven against this predicate; intermediates: implied by `issuer_non_empty` of the next certificate | `example_path_conditions_hold` |
//! | `subject_rule` | target: `path/profile.rs` steps 1 and 4; intermediates: implied by `issuer_non_empty` of the next certificate | `theorem_subject_rule_target`, `example_path_conditions_hold` |
//! | `extensions_acceptable` | any role, for a relying party with every form | `theorem_extensions_acceptable` |
//! | `no_duplicate_extensions` | always, and stricter: RFC 5280 covers foreign ids | `theorem_no_duplicates` |
//! | `key_identifiers_non_critical` | any role | `theorem_key_identifiers` |
Expand Down Expand Up @@ -83,13 +83,17 @@ use crate::name_constraints::spec as nc;
#[cfg(verus_only)]
use crate::path::parsed::spec as ps;
#[cfg(verus_only)]
use crate::path::profile as pf;
#[cfg(verus_only)]
use crate::path::spec as pt;
#[cfg(verus_only)]
use crate::policy_constraints::spec as pc;
#[cfg(verus_only)]
use crate::spec as h;
#[cfg(verus_only)]
use crate::tbs::spec as t;
#[cfg(verus_only)]
use crate::time::spec as tm;

verus! {

Expand Down Expand Up @@ -804,6 +808,139 @@ pub proof fn theorem_ca_only(p: ps::PathCert, y: s::Certificate)
{
}

// ---------------------------------------------------------------------
// 7.2.1, the subject of a target.
// ---------------------------------------------------------------------

/// An encoding of a SEQUENCE with no contents: a Name with no RDN.
pub open spec fn empty_sequence(t: i::Tlv) -> bool {
i::has_tag(t, 0, 16, true) && t.contents.len() == 0
}

/// X.690 8.1.2.2 and 8.1.3.4: an empty SEQUENCE is the two octets 30 00.
/// Universal 16 constructed has the one identifier octet 0x30, and a length
/// of 0 the short form (10.1 refuses a long one below 128).
pub proof fn lemma_empty_sequence_octets(input: Seq<u8>)
requires
i::parse_tlv(input) is Some,
empty_sequence(i::parse_tlv(input)->Some_0),
ensures
i::parse_tlv(input)->Some_0.encoding =~= seq![0x30u8, 0x00],
{
let leading = input[0];
assert(leading % 32 < 31);
assert(leading == 0x30u8) by (nonlinear_arith)
requires
(leading / 64) as nat == 0,
(leading / 32) % 2 == 1,
(leading % 32) as nat == 16,
;
assert(input[1] == 0u8);
}

/// Every empty SEQUENCE `parse_tlvs` reads is the two octets 30 00.
pub proof fn lemma_tlvs_empty_sequences(input: Seq<u8>, k: int)
requires
i::parse_tlvs(input) is Some,
0 <= k < i::parse_tlvs(input)->Some_0.len(),
empty_sequence(i::parse_tlvs(input)->Some_0[k]),
ensures
i::parse_tlvs(input)->Some_0[k].encoding =~= seq![0x30u8, 0x00],
decreases input.len(),
{
let t = i::parse_tlv(input)->Some_0;
let rest = input.subrange(t.encoding.len() as int, input.len() as int);
if k == 0 {
lemma_empty_sequence_octets(input);
} else {
lemma_tlvs_empty_sequences(rest, k - 1);
}
}

/// The frame's subject, if it has no contents, is the two octets 30 00.
pub proof fn lemma_frame_subject_octets(der: Seq<u8>, f: CertificateFrame)
requires
decode_certificate_frame(der) == Some(f),
f.to_be_signed.subject.contents.len() == 0,
ensures
f.to_be_signed.subject.encoding =~= seq![0x30u8, 0x00],
{
let u = i::parse_single(der)->Some_0;
let l = s::sequence_elements(u)->Some_0;
let e0 = s::sequence_elements(l[0])->Some_0;
let m = s::after_version(e0);
lemma_tlvs_empty_sequences(l[0].contents, (m + 4) as int);
}

/// The crate's basicConstraints is the one `check_extensions` reads.
pub proof fn lemma_path_basic(der: Seq<u8>)
requires
ps::parse_path_cert(der) is Some,
ensures
lf::optional_basic_constraints(ps::parse_path_cert(der)->Some_0.extensions) == Some(
ps::parse_path_cert(der)->Some_0.basic,
),
{
}

/// **7.2.1, `subject_rule`, for a target.** `leaf_profile` step 1
/// (`check_extensions` step 3) refuses a CA, and step 4 an empty subject
/// without a critical subjectAltName, so a target it accepts keeps the
/// clause. The Names and the key are asked to decode, as in
/// [`theorem_issuer_non_empty`], since production does not parse them.
#[verifier::spinoff_prover]
pub proof fn theorem_subject_rule_target(der: Seq<u8>, reference: h::ReferenceIdentity, now: tm::CertificateTime)
requires
der.len() < two64(),
ps::parse_path_cert(der) is Some,
path_conditions(ps::parse_path_cert(der)->Some_0),
pf::leaf_profile(ps::parse_path_cert(der)->Some_0, reference, now) is Ok,
s::decode_name(decode_certificate_frame(der)->Some_0.to_be_signed.issuer) is Some,
s::decode_name(decode_certificate_frame(der)->Some_0.to_be_signed.subject) is Some,
s::decode_subject_public_key_info(
decode_certificate_frame(der)->Some_0.to_be_signed.subject_public_key_info,
) is Some,
ensures
s::decode_certificate(der) is Some,
r::subject_rule(s::decode_certificate(der)->Some_0),
{
hide(ps::parse_path_cert);
hide(decode_certificate_frame);
hide(lf::check_extensions);
theorem_path_cert_fwd(der);
let p = ps::parse_path_cert(der)->Some_0;
let f = decode_certificate_frame(der)->Some_0;
theorem_frame_completes(der, f);
let y = s::decode_certificate(der)->Some_0;
let v = r::extensions_of(y);
assert(v == listed(f.to_be_signed.extensions));
assert(!r::is_ca_certificate(y)) by {
reveal(ps::parse_path_cert);
reveal(lf::check_extensions);
lemma_path_basic(der);
lemma_is_ca(p, y);
}
if y.to_be_signed.subject.rdn_sequence.len() == 0 {
let g = f.to_be_signed.subject;
let l = s::sequence_elements(g)->Some_0;
lemma_rdn_list_len(l, 0);
if g.contents.len() > 0 {
lemma_some_element(g, l);
}
assert(g.contents.len() == 0);
assert(g.encoding =~= seq![0x30u8, 0x00]) by {
reveal(decode_certificate_frame);
lemma_frame_subject_octets(der, f);
}
assert(pf::subject_is_empty(p));
assert(pf::san_is_critical(p));
lemma_oids();
lemma_find(p.extensions, v, x::subject_alt_name_oid(), 0);
let idx = lf::find_extension_index(p.extensions, x::subject_alt_name_oid(), 0)->Some_0;
assert(extension_agree(p.extensions[idx], v[idx]));
}
}

// ---------------------------------------------------------------------
// dNSName.
// ---------------------------------------------------------------------
Expand Down
Loading