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
impl Identity
Sourcepub fn from_pem(text: &str) -> Result<Self, PeerError>
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.
Sourcepub fn from_pem_chain(text: &str) -> Result<Self, PeerError>
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.
Sourcepub fn to_pem(&self) -> Result<String, PeerError>
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.
Sourcepub fn read(path: &Path) -> Result<Option<Self>, PeerError>
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.
Sourcepub fn write_new(&self, path: &Path) -> Result<(), PeerError>
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.
Sourcepub fn fingerprint(&self) -> PeerId
pub fn fingerprint(&self) -> PeerId
The certificate’s fingerprint: what a peer pins.
Sourcepub fn certificate_der(&self) -> &[u8] ⓘ
pub fn certificate_der(&self) -> &[u8] ⓘ
The certificate, DER encoded.
Sourcepub fn public_key_der(&self) -> &[u8] ⓘ
pub fn public_key_der(&self) -> &[u8] ⓘ
The certificate’s SubjectPublicKeyInfo, DER encoded: what this side sends when the
policy’s certificate is
RawPublicKey.
Sourcepub fn public_key_fingerprint(&self) -> PeerId
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.
Sourcepub fn raw_peer_identity(&self) -> PeerIdentity
pub fn raw_peer_identity(&self) -> PeerIdentity
This identity as a remote peer sees it after a raw-public-key handshake.
Sourcepub fn intermediates_der(&self) -> impl ExactSizeIterator<Item = &[u8]>
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.
Sourcepub fn peer_identity(&self) -> PeerIdentity
pub fn peer_identity(&self) -> PeerIdentity
This identity as the value a remote peer sees after a handshake.
Sourcepub fn certificate_chain(&self) -> Vec<CertificateDer<'static>>
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.
Sourcepub fn private_key_der(&self) -> PrivateKeyDer<'static>
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
impl Identity
Sourcepub fn generate() -> Result<Self, PeerError>
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.
Sourcepub fn builder() -> IdentityBuilder
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§impl Identity
impl Identity
Sourcepub fn renew_before(&self, margin: Duration) -> bool
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.
Sourcepub fn renew_before_at(&self, margin: Duration, now: SystemTime) -> bool
pub fn renew_before_at(&self, margin: Duration, now: SystemTime) -> bool
renew_before at now.