Skip to main content

CertStore

Struct CertStore 

Source
pub struct CertStore {
    dir: PathBuf,
    account_dir: PathBuf,
}
Expand description

Where this crate’s own state lives inside a PDS data directory: a tls/ subdirectory, so it sits beside the write-ahead log and blob store rather than mixed into either.

§Two directories, because two things have different scopes

The ACME account is one account per deployment however many zones it serves — orders are per certificate, registration is not — so acme-account.json stays at the tls/ root. A certificate covers exactly one zone (<zone> plus *.<zone>, and a wildcard matches one label, so a second zone needs a second certificate), so each zone’s certificate and key live in tls/zones/<zone>/. CertStore::open_zone is the constructor that splits them; CertStore::open points both at the root and is what a caller with no zone at all — a test, or a tool only touching the account — wants.

Fields§

§dir: PathBuf§account_dir: PathBuf

Implementations§

Source§

impl CertStore

Source

pub fn open(data_dir: &Path) -> Result<Self, StorageError>

Opens <data_dir>/tls, creating it 0700 if absent and tightening it to 0700 if it already existed.

Source

pub fn open_zone(data_dir: &Path, zone: &str) -> Result<Self, StorageError>

Opens <data_dir>/tls/zones/<zone> for zone’s certificate, with the ACME account still read from and written to <data_dir>/tls.

One directory per zone is what makes a per-zone certificate pair possible at all: two zones’ cert.pem files cannot share a path, and the alternative — one file whose contents depend on which zone was bootstrapped last — is the bug this layout exists to make unrepresentable.

A zone hostname is a validated DNS name by the time it reaches here, but this checks anyway rather than joining an attacker-controlled string onto a path: anything with a separator, a .., or nothing in it at all is refused.

Source

pub fn directory(&self) -> &Path

The directory this store keeps zone’s certificate in.

Source

pub fn account_credentials(&self) -> Result<Option<StoredAccount>, StorageError>

The ACME account last saved here, if any: the credentials, and the directory they were registered against.

Source

pub fn save_account_credentials( &self, credentials: &AccountCredentials, ) -> Result<(), StorageError>

Persists ACME account credentials, 0600.

Source

pub fn certificate( &self, ) -> Result<Option<(String, String, CertMeta)>, StorageError>

The certificate chain, key and metadata last saved here, if any.

Source

pub fn save_certificate( &self, cert_pem: &str, key_pem: &str, meta: &CertMeta, ) -> Result<(), StorageError>

Persists a certificate chain, its key and metadata, each 0600.

All three are staged beside their final paths before any is renamed into place (see Staged), so a save that fails leaves the previous set untouched, and a crash leaves every file whole: its old contents or its new ones, never empty or cut short. meta.json is renamed last, so its presence means the key and certificate beside it were both written in full. The renames are three steps, not one: a crash between them can leave a new key beside the old certificate, or a certificate with no meta.json. The next bootstrap finds that set unusable and orders a new certificate.

Source

fn read_string(&self, name: &str) -> Result<String, StorageError>

Source

fn read_json<T: DeserializeOwned>( &self, name: &str, ) -> Result<Option<T>, StorageError>

Source

fn read_json_at<T: DeserializeOwned>( &self, path: &Path, ) -> Result<Option<T>, StorageError>

Trait Implementations§

Source§

impl Clone for CertStore

Source§

fn clone(&self) -> CertStore

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 CertStore

Source§

fn fmt(&self, f: &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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more