ActiveHandshake

Struct ActiveHandshake 

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

Provides the active part of a handshake.

The active part of the handshake initializes the handshake procedure. It will generate the necessary initialization data and provide the passive part with a challenge, before it will complete the handshake. Generally, you’re expected to transfer the returned data to the other side by whatever means appropriate. Depending on the security features that you want, you can decide to end the handshake early. However, the following will assume you want all security features enabled.

An example procedure would be as follows:

let mut handshake = ActiveHandshake::default();
let init = handshake.initialize(SecurityFeature::all()).expect("Should be able to initialize handshake.");
// You should now transfer the data contained in `init` to the other side.
// The other side would then give you their public part of their side. With that, you can
// generate a challenge.
// You should get `value_b` & `value_key` from the passive side of the handshake.
let challenge = handshake.start_challenge(value_b, value_key).expect("Should be able to start the challenge.");
// This challenge should again be transferred to the other side. At this point the handshake it
// technically complete; all data has been exchanged. However, we should wait for the passive
// side to acknowledge the challenge.
let encryption = handshake.finish().expect("Should have finished handshake.").expect("Encryption should've been established.");

Implementations§

Source§

impl ActiveHandshake

Source

pub fn initialize( &mut self, features: SecurityFeature, ) -> Result<PassiveInitializationData, SilkroadSecurityError>

Starts the handshake process.

This generates the private key parts and returns PassiveInitializationData, which should be transferred to the client. This should later be followed by calling start_challenge() with the client response. The content of the PassiveInitializationData may vary depending on the configured security features.

If a handshake has already been started or completed, will return SilkroadSecurityError::AlreadyInitialized.

Source

pub fn start_challenge( &mut self, value_b: u32, client_key: u64, ) -> Result<u64, SilkroadSecurityError>

Create a challenge to the client.

This creates a challenge for the client, signaling a switch to an encrypted channel using the exchanged key material. We also check if the key, that the client sent us, matches what we would expect given what we’ve witnessed in the key exchange.

If successful, returns the challenge for the client. If initialize hasn’t been called, returns SilkroadSecurityError::SecurityUninitialized. If the passed key does not match the key we expected, will return SilkroadSecurityError::KeyExchangeMismatch.

Source

pub fn finish(self) -> Result<Option<SilkroadEncryption>, SilkroadSecurityError>

Finishes the handshake process.

This will try to finish the handshake process, at whatever stage we are. Depending on the configured settings, this may be at different stages. If no security features are configured: at any point. If only check bytes are configured: after initialization. If encryption is configured: after having created the client challenge.

Trait Implementations§

Source§

impl Default for ActiveHandshake

Source§

fn default() -> ActiveHandshake

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

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V