cascade: compare lineages and refuse provider aliases
Release policy now requires distinct adjacent lineages, and no provider can be registered under another provider's name or a slot name. Refs: R3
This commit is contained in:
parent
598203b475
commit
a3b33ae10c
|
|
@ -48,7 +48,8 @@ pub struct Suite {
|
|||
pub struct Policy {
|
||||
/// The vetted layer must come from a FIPS-mode provider (release builds).
|
||||
pub require_fips_vetted_layer: bool,
|
||||
/// Adjacent layers must come from different providers.
|
||||
/// Adjacent layers must come from different library lineages
|
||||
/// ([`CryptoProvider::lineage`]).
|
||||
pub require_distinct_adjacent_providers: bool,
|
||||
/// Experimental-tier layers are allowed.
|
||||
pub allow_experimental: bool,
|
||||
|
|
@ -68,13 +69,17 @@ impl Policy {
|
|||
}
|
||||
|
||||
/// Release builds (D-26): the vetted layer must come from a provider in
|
||||
/// FIPS mode (AWS-LC-FIPS by default). A build without a FIPS module
|
||||
/// cannot resolve any suite.
|
||||
/// FIPS mode (AWS-LC-FIPS by default), and adjacent layers from different
|
||||
/// library lineages. A build without a FIPS module cannot resolve any
|
||||
/// suite.
|
||||
pub fn release() -> Self {
|
||||
Self { require_fips_vetted_layer: true, ..Self::development() }
|
||||
Self { require_fips_vetted_layer: true, require_distinct_adjacent_providers: true, ..Self::development() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Slot names a suite may use besides provider names; see [`ProviderSet::bind`].
|
||||
const SLOTS: &[&str] = &[crate::suites::VETTED];
|
||||
|
||||
/// The providers this build has, with the algorithms that passed their
|
||||
/// known-answer self-test. An algorithm without a passing vector is treated as
|
||||
/// failed: the gate fails closed (S6).
|
||||
|
|
@ -92,16 +97,33 @@ impl ProviderSet {
|
|||
|
||||
/// Add `provider` after running its self-test. Algorithms that fail are
|
||||
/// recorded and every suite using them refuses to resolve.
|
||||
///
|
||||
/// # Panics
|
||||
/// If the provider's name is a reserved slot name (a build error).
|
||||
pub fn add(&mut self, provider: Arc<dyn CryptoProvider>) -> &mut Self {
|
||||
let name = provider.provider_name();
|
||||
self.bind(name, provider)
|
||||
assert!(!SLOTS.contains(&name), "provider name {name:?} is a reserved slot");
|
||||
self.bind_unchecked(name, provider)
|
||||
}
|
||||
|
||||
/// Add `provider` under the slot `slot` (for example
|
||||
/// [`crate::suites::VETTED`]) after running its self-test. Providers that
|
||||
/// implement an algorithm produce the same bytes, so the binding can change
|
||||
/// between builds without changing any ciphertext.
|
||||
///
|
||||
/// # Panics
|
||||
/// If `slot` is neither a reserved slot nor the provider's own name, so
|
||||
/// one library can never pose as another (a build error).
|
||||
pub fn bind(&mut self, slot: &'static str, provider: Arc<dyn CryptoProvider>) -> &mut Self {
|
||||
assert!(
|
||||
SLOTS.contains(&slot) || slot == provider.provider_name(),
|
||||
"cannot bind {:?} under the name {slot:?}",
|
||||
provider.provider_name()
|
||||
);
|
||||
self.bind_unchecked(slot, provider)
|
||||
}
|
||||
|
||||
fn bind_unchecked(&mut self, slot: &'static str, provider: Arc<dyn CryptoProvider>) -> &mut Self {
|
||||
let name = slot;
|
||||
self.passed.retain(|(p, _)| *p != name);
|
||||
let report = provider.self_test();
|
||||
|
|
@ -172,9 +194,9 @@ impl ProviderSet {
|
|||
if self.failed_self_test(anchor.provider, KdfAlgorithm::Sha512 as u32) {
|
||||
return Err(CascadeError::SelfTestFailed(format!("HKDF-SHA-512 in {}", anchor.provider)));
|
||||
}
|
||||
// Distinct means distinct implementations, so compare what the slots
|
||||
// are bound to, not the slot names.
|
||||
let implementation = |slot: &str| self.providers[slot].provider_name();
|
||||
// Distinct means distinct code bases, so compare the lineage of what
|
||||
// the slots are bound to, not the slot names.
|
||||
let implementation = |slot: &str| self.providers[slot].lineage();
|
||||
if policy.require_distinct_adjacent_providers
|
||||
&& suite.layers.windows(2).any(|w| implementation(w[0].provider) == implementation(w[1].provider))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -67,6 +67,14 @@ impl CryptoProvider for TestProvider {
|
|||
fn provider_name(&self) -> &'static str {
|
||||
self.name
|
||||
}
|
||||
fn lineage(&self) -> &'static str {
|
||||
// Test providers named "bssl-*" claim AWS-LC's lineage.
|
||||
if self.name.starts_with("bssl-") {
|
||||
"boringssl"
|
||||
} else {
|
||||
self.name
|
||||
}
|
||||
}
|
||||
fn fips_mode(&self) -> bool {
|
||||
self.fips
|
||||
}
|
||||
|
|
@ -302,3 +310,30 @@ fn slots_bind_providers_and_distinct_compares_implementations() {
|
|||
let unbound = suite(1, &[(AesGcm256, "unbound-slot")]);
|
||||
assert!(matches!(ProviderSet::new().resolve(&unbound, &dev), Err(CascadeError::Policy(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distinct_rule_compares_lineages_and_release_turns_it_on() {
|
||||
let mut p = providers();
|
||||
p.add(TestProvider::arc("bssl-fork", false, None));
|
||||
assert!(Policy::release().require_distinct_adjacent_providers);
|
||||
let distinct = Policy { require_distinct_adjacent_providers: true, ..Policy::development() };
|
||||
// AWS-LC next to another BoringSSL fork is one lineage, not two.
|
||||
let forks = suite(1, &[(AesGcm256, "awslc"), (ChaCha20Poly1305, "bssl-fork")]);
|
||||
assert!(matches!(p.resolve(&forks, &distinct), Err(CascadeError::Policy(_))));
|
||||
let mixed = suite(1, &[(AesGcm256, "awslc"), (XChaCha20Poly1305, "other")]);
|
||||
assert!(p.resolve(&mixed, &distinct).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "cannot bind")]
|
||||
fn a_provider_cannot_pose_under_another_name() {
|
||||
let mut p = ProviderSet::new();
|
||||
p.bind("rustcrypto", Arc::new(AwsLcProvider::new()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "reserved slot")]
|
||||
fn a_provider_named_like_a_slot_is_refused() {
|
||||
let mut p = ProviderSet::new();
|
||||
p.add(TestProvider::arc("vetted", false, None));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue