Skip to main content

Identity

Struct Identity 

Source
pub struct Identity { /* private fields */ }
Expand description

This side’s certificate and its private key, with the intermediates that issued the certificate when it has any.

A peer identity is one self-issued certificate (from_pem). A server a browser reaches under web PKI presents a CA-issued certificate with its intermediates (from_pem_chain). The fingerprint is always the leaf certificate’s.

On disk it is one PEM file: the certificate block, then a PKCS#8 PRIVATE KEY block.

Implementations§

Source§

impl Identity

Source

pub fn from_pem(text: &str) -> Result<Self, PeerError>

Reads one certificate and its matching private key from PEM text.

§Errors

PeerError::Certificate when either is missing, malformed or not a pair, or when more than one certificate is present.

Source

pub fn from_pem_chain(text: &str) -> Result<Self, PeerError>

Reads a certificate, the intermediates that issued it and the leaf’s private key from PEM text: the leaf certificate first, then each issuer in order up to (not necessarily including) the root, and one private key in any block position.

A configuration built from it presents the whole chain. The fingerprint is the leaf’s. A peer that pins this identity refuses the chain unless its policy sets allow_chain_when_pinned. One certificate alone gives the same identity as from_pem.

§Errors

PeerError::Certificate when there is no certificate or no key, either is malformed, or the key is not the first certificate’s.

Source

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

The identity as PEM text: the certificate, its intermediates in order, then the PKCS#8 private key. Text with intermediates reads back with from_pem_chain only.

§Errors

PeerError::Certificate when the key is not PKCS#8.

Source

pub fn read(path: &Path) -> Result<Option<Self>, PeerError>

Reads the identity file at path; None when it is absent. The file holds the certificate, the intermediates that issued it, if any, and its key, as from_pem_chain reads them: what write_new writes for any identity.

§Errors

PeerError::Io when it cannot be read, PeerError::Certificate when invalid.

Source

pub fn write_new(&self, path: &Path) -> Result<(), PeerError>

Writes the identity file without replacing an existing one, readable by its owner alone (0600 on Unix). Parent directories are created.

§Errors

PeerError::Io with kind AlreadyExists when path exists.

Source

pub fn fingerprint(&self) -> PeerId

The certificate’s fingerprint: what a peer pins.

Source

pub fn certificate_der(&self) -> &[u8] ⓘ

The certificate, DER encoded.

Source

pub fn public_key_der(&self) -> &[u8] ⓘ

The certificate’s SubjectPublicKeyInfo, DER encoded: what this side sends when the policy’s certificate is RawPublicKey.

Source

pub fn public_key_fingerprint(&self) -> PeerId

The id of the public_key_der (SHA-256): what a peer pins when it authenticates this side by its raw public key.

Source

pub fn raw_peer_identity(&self) -> PeerIdentity

This identity as a remote peer sees it after a raw-public-key handshake.

Source

pub fn intermediates_der(&self) -> impl ExactSizeIterator<Item = &[u8]>

The intermediates presented after the certificate, DER encoded, in order; none for an identity read by from_pem or generated.

Source

pub fn peer_identity(&self) -> PeerIdentity

This identity as the value a remote peer sees after a handshake.

Source

pub fn certificate_chain(&self) -> Vec<CertificateDer<'static>>

The certificate followed by its intermediates, as a configuration presents them: for a host that builds a rustls or quinn configuration of its own.

Source

pub fn private_key_der(&self) -> PrivateKeyDer<'static>

A copy of the private key, DER encoded, for a host that builds a rustls or quinn configuration of its own. It is the secret of this identity: keep it in memory only. Its Debug shows no key material.

Source§

impl Identity

Source

pub fn generate() -> Result<Self, PeerError>

Creates a self-signed ECDSA P-256 identity without writing it, valid for rcgen’s default period (decades).

Every generated certificate has the common name coqui-peer, a DNS subjectAltName SERVER_NAME, a subjectKeyIdentifier and basicConstraints CA:FALSE. Peers pin it by fingerprint, so the name is not checked.

§Errors

PeerError::Certificate when key generation fails.

Source

pub fn builder() -> IdentityBuilder

A builder for a self-signed identity with a validity window of your own; see IdentityBuilder. generate is the same with the defaults.

Source

pub fn open_or_create(path: &Path) -> Result<Self, PeerError>

Reads the identity file at path, creating and writing a new identity when absent. Two processes racing to create it end with the same identity.

§Errors

As read and write_new.

Source§

impl Identity

Source

pub fn renew_before(&self, margin: Duration) -> bool

Whether this identity’s certificate ends within margin from now: time to make a successor and announce it. An unreadable validity is due.

Source

pub fn renew_before_at(&self, margin: Duration, now: SystemTime) -> bool

renew_before at now.

Trait Implementations§

Source§

impl Clone for Identity

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 Identity

Source§

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

Formats the value using the given formatter. Read more

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> 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.