Skip to main content

HostExpectation

Struct HostExpectation 

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

Which program the client is willing to talk to, passed to Client::connect_expecting.

The host must run as the client’s own user (always) and its executable, read from the kernel for the connected socket’s process, must be one of the paths named here. Both sides of the comparison are canonicalised when the check runs, so a symlink, a .. or a case difference on a case-insensitive volume does not matter; the same file reached by another name (a hard link) is the same executable.

An expectation with no path matches nothing: it fails closed.

The install-relative constructors (sibling_executable, bundle_executable, relative_to_current_exe) derive the host’s path from where THIS process’s executable lives, so an engine shipped inside an app can name its app without a hard-coded path. They inherit the trust of that location: see the README, “What this does not do”.

Implementations§

Source§

impl HostExpectation

Source

pub fn executable(path: impl Into<PathBuf>) -> Self

The host is the program at path.

Source

pub fn any_of<I, P>(paths: I) -> Self
where I: IntoIterator<Item = P>, P: Into<PathBuf>,

The host is any one of paths (a release path and a QA path, say). Empty matches nothing.

Source

pub fn or_executable(self, path: impl Into<PathBuf>) -> Self

Also accept the program at path.

Source

pub fn sibling_executable(file_name: impl AsRef<OsStr>) -> Result<Self>

The host is the executable file_name in the same directory as THIS process’s executable (symlinks resolved first). Fails when the running executable cannot be located or file_name is not a bare file name.

Source

pub fn bundle_executable(file_name: impl AsRef<OsStr>) -> Result<Self>

The host is the main executable file_name of the macOS app bundle that contains THIS process’s executable: <App>.app/Contents/MacOS/<file_name>. For an engine or command line tool shipped inside the app, whether it sits in Contents/Resources/bin or in Contents/MacOS itself. Fails when the running executable is not inside an .app directory or file_name is not a bare file name.

Source

pub fn relative_to_current_exe( levels_up: usize, relative: impl AsRef<Path>, ) -> Result<Self>

The host is relative under the directory levels_up levels above THIS process’s executable (symlinks resolved first; 1 is the directory that holds it). For install layouts that are neither a sibling nor a macOS bundle, for example relative_to_current_exe(2, "bin/app") for <root>/libexec/engine and <root>/bin/app.

Source

pub fn with_verifier( self, check: impl Fn(&HostProcess) -> Result<(), String> + Send + Sync + 'static, ) -> Self

Add a check that runs AFTER the executable matched, with the host the OS identified. A returned Err(reason) refuses the host as HostIdentityReason::Refused. The check runs before the first application byte is written.

This is the hook for a stronger identity than a path. This crate links no code-signing API, so the macOS team-identifier check is the caller’s: link Security.framework in the app, build a SecCode for the host from HostProcess::audit_token with SecCodeCopyGuestWithAttributes and kSecGuestAttributeAudit (never from the pid alone, which can be reused), read kSecCodeInfoTeamIdentifier with SecCodeCopySigningInformation and compare it with your own (SecCodeCopySelf). On Windows the same hook carries an Authenticode (WinVerifyTrust) check of HostProcess::executable.

Source

pub fn executables(&self) -> &[PathBuf]

The executables this expectation names, as supplied.

Trait Implementations§

Source§

impl Clone for HostExpectation

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 HostExpectation

Source§

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

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

impl Default for HostExpectation

Source§

fn default() -> Self

Returns the “default value” for a type. 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
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> 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.