Skip to main content

EncryptedBackend

Struct EncryptedBackend 

Source
pub struct EncryptedBackend<B> { /* private fields */ }
Expand description

Serves the files of another backend with their contents encrypted, and by default their names too, under a 32-byte key. The inner backend stores ciphertext; clients see plaintext.

The root of the inner backend holds one object that is not a file of the share, the marker .smb-encryption. It records the settings the share was made with and a check value of the key. build writes it into an empty root and reads it from any other, so a wrong key, or settings that differ from the share’s, fail the build. A root with entries and no marker fails it too, unless restore_marker is set.

The block size, whether names are encrypted and the long-name threshold are fixed when the share is made. The key is not stored anywhere, and the data cannot be read without it. Give each share a key of its own. With one key, a stored file copied into another share’s storage reads back through that share when both use the same block size.

File sizes, times and attributes, the shape of the tree and the length of every name stay visible in the inner backend.

A read of a block that fails authentication returns SmbError::Io, which clients see as STATUS_UNEXPECTED_IO_ERROR. A crash can leave the block being written unreadable.

With encrypted names over an S3Backend, build that backend with case_insensitive(false).

The backend reports no named streams and no extended attributes, and answers copy_range and clone_range with NotSupported.

Clones share all state, so several shares can serve one encrypted tree through clones of one backend. Two backends built separately over one tree are not supported.

use smb_server::{Access, EncryptedBackend, Share, ShareBackend, SmbServer};
let vault = EncryptedBackend::builder(inner, key).build().await?;
SmbServer::builder()
    .listen("0.0.0.0:4445".parse()?)
    .user("alice", "password")
    .share(Share::new("vault", vault).user("alice", Access::ReadWrite))
    .build()?
    .serve()
    .await?;

Implementations§

Source§

impl<B: ShareBackend> EncryptedBackend<B>

Source

pub fn builder(inner: B, key: [u8; 32]) -> EncryptedBackendBuilder<B>

Settings for an encrypted view of inner under key.

build wipes the builder’s buffer for key once the keys are derived, and dropping the builder wipes it too. Copies of key that the caller keeps are the caller’s to wipe. The hmac and sha2 crates keep key-derived bytes in internal state that they do not wipe. The GHASH subkey of aes-gcm is not wiped either: it sits in each cipher and in copies made during setup and for every operation, and aes-gcm wipes only one temporary copy.

Trait Implementations§

Source§

impl<B> Clone for EncryptedBackend<B>

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<B> Debug for EncryptedBackend<B>

Source§

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

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

impl<B: ShareBackend> ShareBackend for EncryptedBackend<B>

Source§

fn open<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 SmbPath, opts: OpenOptions, ) -> Pin<Box<dyn Future<Output = SmbResult<(Box<dyn Handle>, OpenAction)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Open or create a file or directory. Returns a fresh handle and what the open did to the file. Read more
Delete a file or an empty directory.
Source§

fn rename<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, from: &'life1 SmbPath, to: &'life2 SmbPath, replace_if_exists: bool, ) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Rename from to to. Read more
Source§

fn capabilities(&self) -> BackendCapabilities

Static capabilities. TREE_CONNECT clamps access to read-only when is_read_only is set.
Source§

fn volume_info<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = SmbResult<VolumeInfo>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Size, free space and identity of the volume behind the share, for the filesystem QUERY_INFO classes. The default returns VolumeInfo::default.
Source§

fn open_stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, file: Box<dyn Handle>, _path: &'life1 SmbPath, _stream: &'life2 StreamName, _opts: OpenOptions, ) -> Pin<Box<dyn Future<Output = SmbResult<(Box<dyn Handle>, OpenAction)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Open or create the named stream stream of the file or directory at path. file is the handle open just gave for path, opened for reading. The backend owns it and closes it, also when this fails; it may keep it for as long as the stream’s handle lasts, so the stream follows the file through renames. opts.intent applies to the stream; opts.directory and opts.non_directory are false. The handle reads and writes the stream: its stat reports the file’s times, attributes and id with the stream’s sizes, set_times and set_attributes change the file, and truncate the stream. A write or size change of the stream updates the file’s last write time, which the protocol layer reports as a change of the file. Read more
Source§

fn remove_stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _path: &'life1 SmbPath, _file_index: u64, _stream: &'life2 StreamName, ) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Remove the named stream of the file or directory at path that stream names, whatever the case of its spelling. Fail with SmbError::NotFound when the file has no such stream. Read more
Source§

fn rename_stream<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _path: &'life1 SmbPath, _file_index: u64, _from: Option<&'life2 StreamName>, _to: Option<&'life3 StreamName>, _replace_if_exists: bool, ) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Rename a stream of the file or directory at path, which has the id file_index as ShareBackend::remove_stream says: the named stream from names, or the default stream when from is None, to the named stream to, or to the default stream when to is None. Names compare without regard to case, and a renamed stream takes the spelling of to. from and to never name the same stream, and a directory, which has no default stream, only renames a named stream to another. Read more
Source§

fn copy_range<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _src: &'life1 dyn Handle, _src_offset: u64, _dst: &'life2 dyn Handle, _dst_offset: u64, _len: u64, ) -> Pin<Box<dyn Future<Output = SmbResult<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Copies len bytes from src_offset of src to dst_offset of dst inside the storage, for a client’s server-side copy, and returns the number copied. dst is a handle this backend gave. src may be a handle of another backend or share, or of the same file as dst. A copy past the end of dst leaves a gap that reads as zeros, as Handle::write does. Read more
Source§

fn clone_range<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _src: &'life1 dyn Handle, _src_offset: u64, _dst: &'life2 dyn Handle, _dst_offset: u64, _len: u64, ) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Makes the len bytes at dst_offset of dst share their storage with the len bytes at src_offset of src, for a client’s duplicate extents request: the bytes read the same, and a later write to either file leaves the other as it is. dst is a handle this backend gave. src may be a handle of another backend or share. Read more

Auto Trait Implementations§

§

impl<B> !RefUnwindSafe for EncryptedBackend<B>

§

impl<B> !UnwindSafe for EncryptedBackend<B>

§

impl<B> Forget for EncryptedBackend<B>

§

impl<B> Freeze for EncryptedBackend<B>
where Arc<Shared<B>>: Freeze,

§

impl<B> Move for EncryptedBackend<B>

§

impl<B> Send for EncryptedBackend<B>
where Arc<Shared<B>>: Send,

§

impl<B> Sync for EncryptedBackend<B>
where Arc<Shared<B>>: Sync,

§

impl<B> Unpin for EncryptedBackend<B>
where Arc<Shared<B>>: Unpin,

§

impl<B> UnsafeUnpin for EncryptedBackend<B>
where Arc<Shared<B>>: UnsafeUnpin,

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> Instrument for T

Source§

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

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

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.

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

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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