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
impl ActiveHandshake
Sourcepub fn initialize(
&mut self,
features: SecurityFeature,
) -> Result<PassiveInitializationData, SilkroadSecurityError>
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.
Sourcepub fn start_challenge(
&mut self,
value_b: u32,
client_key: u64,
) -> Result<u64, SilkroadSecurityError>
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.
Sourcepub fn finish(self) -> Result<Option<SilkroadEncryption>, SilkroadSecurityError>
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.