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>
impl<B: ShareBackend> EncryptedBackend<B>
Sourcepub fn builder(inner: B, key: [u8; 32]) -> EncryptedBackendBuilder<B>
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>
impl<B> Clone for EncryptedBackend<B>
Source§impl<B> Debug for EncryptedBackend<B>
impl<B> Debug 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,
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,
Source§fn unlink<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 SmbPath,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn unlink<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 SmbPath,
) -> Pin<Box<dyn Future<Output = SmbResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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,
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,
Source§fn capabilities(&self) -> BackendCapabilities
fn capabilities(&self) -> BackendCapabilities
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,
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,
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,
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,
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 moreSource§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,
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,
path that
stream names, whatever the case of its spelling. Fail with
SmbError::NotFound when the file has no such stream. Read moreSource§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,
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,
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 moreSource§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,
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,
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 moreSource§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,
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,
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