Skip to main content

Policy

Struct Policy 

Source
#[non_exhaustive]
pub struct Policy {
Show 13 fields pub tls_versions: Vec<TlsVersion>, pub cipher_suites: Option<Vec<String>>, pub kx_groups: Option<Vec<String>>, pub cipher_profiles: Vec<CipherProfile>, pub crypto: Crypto, pub certificate: CertificateType, pub pin_digests: Vec<Digest>, pub check_validity: bool, pub allow_chain_when_pinned: bool, pub allow_resumption: bool, pub require_ems: bool, pub waiting: WaitingLimits, pub acl: Option<Acl>,
}
Expand description

What a TLS configuration and a trust decision are allowed to do.

Start from Policy::modern, Policy::intermediate, Policy::legacy or a policy of your own, then change any field. Default is intermediate (TLS 1.2 and 1.3). Nothing is silently non-default: non_defaults lists every setting that differs from the default, and the configuration builders return that list.

A policy is [Describe]: its keys’ defaults are the intermediate preset’s, so a document names only what differs, and an unknown key is refused. A coqui_builder::Partial<Policy> is filled from text and built; with the serde feature the policy itself is also read through any serde format (it is not written).

The struct is #[non_exhaustive]: start from a preset and assign the fields to change.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§tls_versions: Vec<TlsVersion>

TLS versions offered and accepted. Non-empty.

§cipher_suites: Option<Vec<String>>

An allow-list of cipher suites by IANA name, for example TLS13_AES_256_GCM_SHA384. None allows every suite the cipher profiles give for tls_versions. An unknown name is an error that lists the supported ones.

§kx_groups: Option<Vec<String>>

An allow-list of key-exchange groups by name, for example X25519; None allows all the cipher profiles give.

§cipher_profiles: Vec<CipherProfile>

The algorithm profiles allowed; what is offered is their union, in the order of the first listed, narrowed by the versions, the provider, cipher_suites and kx_groups. Every preset allows [CipherProfile::Mozilla]. Text key cipher_profiles.

§crypto: Crypto

The crypto provider; Crypto::Ring in every preset. Text key crypto.

§certificate: CertificateType

What peers authenticate with: CertificateType::X509 (the default in every preset) or CertificateType::RawPublicKey. Text key certificate.

§pin_digests: Vec<Digest>

Digests a pin may use. Pins are compared in constant time whatever their digest.

§check_validity: bool

Whether a pinned certificate must be inside its validity dates.

§allow_chain_when_pinned: bool

Whether a pinned peer may present a chain; strict refuses one.

§allow_resumption: bool

Whether TLS sessions may be resumed. A resumed handshake skips the certificate verifiers, so a peer removed from the trust store or no longer pinned can reconnect on a session it already holds, and the access control list’s fingerprint rules are not checked again (its address rules are). Every preset leaves it off; non_defaults reports it.

§require_ems: bool

Whether a TLS 1.2 connection must use the extended master secret (RFC 7627). Without it a TLS 1.2 session’s keys and exporter are not bound to its handshake, which an attacker can use to synchronise two sessions (the triple handshake). modern and intermediate set it; legacy does not, for TLS 1.2 stacks older than RFC 7627. TLS 1.3 needs nothing like it.

§waiting: WaitingLimits

The bounds of a store-backed pin set’s waiting queue: entries per source, entries in all, and how long before the same certificate from the same source is recorded again. In the text form a table: per_source, total and rerecord (a duration, a number of seconds in a hand-written document).

§acl: Option<Acl>

An ordered access control list for connecting clients, applied by every server configuration built under this policy: by address when the ClientHello arrives (Refusal::AddressDenied) and by the client certificate’s fingerprint before the trust store is consulted (Refusal::PeerDenied). Its fingerprints may be written in any spelling a PeerId parses, and are made canonical where a configuration is built or a policy is read through serde; a rule naming something else, or a digest other than SHA-256, is an error there and in check. None for none.

Implementations§

Source§

impl Policy

Source

pub fn deserialize_over<'de, D: Deserializer<'de>>( base: Policy, deserializer: D, ) -> Result<Policy, D::Error>

Reads a policy document over base instead of the intermediate preset: the keys it names replace the base’s (a table such as waiting key by key, a list whole), and the rest are kept. A consumer with its own default profile reads its configuration with this.

§Errors

The deserializer’s error for an unknown key or a value of the wrong type or form, and, with the acl feature, for a rule whose fingerprint is not a SHA-256 peer id; the list’s fingerprints are made canonical.

Source§

impl Policy

Source

pub fn intermediate() -> Self

The intermediate preset, the default: TLS 1.2 and 1.3 (TLS 1.2 with ECDHE, AEAD suites and the extended master secret); pins SHA-256, SHA-384 or SHA-512; validity dates checked; no chain on a pinned path; no session resumption; waiting queues capped.

Two peers that both allow TLS 1.3 negotiate it, and the TLS 1.3 downgrade protection keeps an attacker from forcing 1.2 between them; allowing 1.2 only admits peers that cannot speak 1.3.

Source

pub fn modern() -> Self

The modern preset: intermediate with TLS 1.3 only. A choice, never required: it refuses peers that speak only TLS 1.2, and keeps client certificates from passive observers when such peers would otherwise be served (TLS 1.2 sends the client’s certificate unencrypted).

Source

pub fn legacy() -> Self

The legacy preset: intermediate, and SHA-1 pins and TLS 1.2 without the extended master secret accepted, for interoperability with old peers only. A peer that cannot take a TLS 1.3 ClientHello at all is served by setting tls_versions to TLS 1.2 alone.

Source

pub fn preset(name: &str) -> Result<Self, PeerError>

The built-in preset called name: modern, intermediate or legacy.

§Errors

PeerError::Policy for any other name.

Source§

impl Policy

Source

pub fn non_defaults(&self) -> Vec<NonDefault>

Every setting that differs from the default (intermediate) preset, as plain data named by its key (waiting.per_source, tls_versions). Empty for intermediate; modern reports tls_versions and legacy reports pin_digests and require_ems. A value prints as its type and text (bool(true), [TlsVersion(1.3)]). With the acl feature, a list present is one entry, acl; coqui_builder::non_defaults over the list reports its own settings.

Source

pub fn non_defaults_against(&self, baseline: &Self) -> Vec<NonDefault>

As non_defaults, against baseline instead of the defaults, for a consumer whose own baseline differs from them (non_defaults_against(&Policy::modern()) reports TLS 1.2).

Source

pub fn admits_address( &self, source: SocketAddr, local: SocketAddr, ) -> Result<(), Refusal>

Whether the access control list admits, by address, a client from source to local that will present a certificate: a rule naming a fingerprint defers to the handshake. Without a list, every address is admitted. For a host that refuses a connection before its handshake, such as a quinn Incoming.

§Errors

Refusal::AddressDenied with the deciding rule.

Source

pub fn admits_anonymous( &self, source: SocketAddr, local: SocketAddr, ) -> Result<(), Refusal>

admits_address for a client that proves no identity at the TLS layer: rules naming a fingerprint cannot match it.

§Errors

Refusal::AddressDenied with the deciding rule.

Source

pub fn check_pin(&self, fingerprint: &PeerId) -> Result<(), PeerError>

Whether this policy lets a pin use the digest of fingerprint.

§Errors

PeerError::Policy naming the digest and the allowed ones.

Source

pub fn check(&self) -> Result<(), PeerError>

Checks this policy as building a configuration under it does, without building one: its versions, cipher profiles, cipher suites and key-exchange groups against the crypto provider and this build, and, with the acl feature, that every fingerprint of its access control list is a SHA-256 peer id. A host that builds its configurations later (one per connection) checks the policy it read with this.

§Errors

PeerError::Policy naming the first setting that fails, as a configuration builder would report it.

Source

pub fn crypto_provider(&self) -> Result<Arc<CryptoProvider>, PeerError>

The crypto provider (crypto) narrowed to what this policy offers: the union of its cipher_profiles, its versions, and its cipher_suites and kx_groups when set.

§Errors

PeerError::Policy for an unknown suite or group name (listing the supported ones), a provider or profile this build lacks, or when no suite or no group is left.

Source

pub fn supported_cipher_suites(&self) -> Result<Vec<String>, PeerError>

The cipher suite IANA names the provider this policy selects can offer, for choosing cipher_suites from.

§Errors

PeerError::Policy when this build lacks that provider.

Source

pub fn supported_kx_groups(&self) -> Result<Vec<String>, PeerError>

The key-exchange group names the provider this policy selects can offer, for choosing kx_groups from.

§Errors

PeerError::Policy when this build lacks that provider.

Trait Implementations§

Source§

impl Clone for Policy

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Policy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Policy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Describe for Policy

Source§

type Fill = __Fill

The partly filled state of this type: what Partial holds.
Source§

fn description() -> Description

What this type is.
§

const OPTIONAL: bool = false

The type is Option<_>: leaving a field of it out is a value of its own, so it is never required.
§

const LEAF: bool = false

The type is one text: a [Leaf], or an untagged enum whose arms all are. An untagged enum counts the arms that are not, and holds at most one.
Source§

impl<'de> Deserialize<'de> for Policy

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Reads the document over the intermediate preset.

Source§

impl Eq for Policy

Source§

impl Fields for Policy

Source§

impl Inspect for Policy

Source§

fn at(&self, __at: &[Segment]) -> Option<Datum>

The leaf at at, or None.
Source§

fn entries(&self, __at: &[Segment]) -> Option<Entries>

The structure at at, or None.
Source§

impl PartialEq for Policy

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Policy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.