#[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
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: CryptoThe crypto provider; Crypto::Ring in every preset. Text key crypto.
certificate: CertificateTypeWhat 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: boolWhether a pinned certificate must be inside its validity dates.
allow_chain_when_pinned: boolWhether a pinned peer may present a chain; strict refuses one.
allow_resumption: boolWhether 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: boolWhether 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: WaitingLimitsThe 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
impl Policy
Sourcepub fn deserialize_over<'de, D: Deserializer<'de>>(
base: Policy,
deserializer: D,
) -> Result<Policy, D::Error>
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
impl Policy
Sourcepub fn intermediate() -> Self
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.
Sourcepub fn modern() -> Self
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§impl Policy
impl Policy
Sourcepub fn non_defaults(&self) -> Vec<NonDefault>
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.
Sourcepub fn non_defaults_against(&self, baseline: &Self) -> Vec<NonDefault>
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).
Sourcepub fn admits_address(
&self,
source: SocketAddr,
local: SocketAddr,
) -> Result<(), Refusal>
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.
Sourcepub fn admits_anonymous(
&self,
source: SocketAddr,
local: SocketAddr,
) -> Result<(), Refusal>
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.
Sourcepub fn check_pin(&self, fingerprint: &PeerId) -> Result<(), PeerError>
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.
Sourcepub fn check(&self) -> Result<(), PeerError>
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.
Sourcepub fn crypto_provider(&self) -> Result<Arc<CryptoProvider>, PeerError>
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.
Sourcepub fn supported_cipher_suites(&self) -> Result<Vec<String>, PeerError>
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.
Sourcepub fn supported_kx_groups(&self) -> Result<Vec<String>, PeerError>
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 Describe for Policy
impl Describe for Policy
Source§impl<'de> Deserialize<'de> for Policy
impl<'de> Deserialize<'de> for Policy
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Reads the document over the intermediate preset.