sheave_core::handshake

Struct Handshake

Source
pub struct Handshake(/* private fields */);
Expand description

The 1536 bytes handshake data. This respectively consists of following parts:

RangeRepresentation
First 4 bytesTimestamp (in milliseconds)
Second 4 bytesFlash Player version/Flash Media Server version
Remained bytesRandoms for handshake (may be contained digest/signature)

Implementations§

Source§

impl Handshake

Source

pub const CLIENT_KEY: &'static [u8] = b"Genuine Adobe Flash Player 001"

The key which is used to imprint ant client-side digest.

Source

pub const SERVER_KEY: &'static [u8] = b"Genuine Adobe Flash Media Server 001"

The key which is used to imprint any server-side digest.

Source

pub const COMMON_KEY: &'static [u8] = _

The key which is used to imprint any signature. Both sides are required to contain this into a key of signature.

Source

pub fn new(timestamp: Duration, version: Version) -> Self

Constructs handshake data.

§Examples
use std::time::Duration;
use sheave_core::handshake::{
    Handshake,
    Version,
    EncryptionAlgorithm
};

// If you are a client.
let mut client_handshake = Handshake::new(Duration::default(), Version::LATEST_CLIENT);
// If you are a server.
let mut server_handshake = Handshake::new(Duration::default(), Version::LATEST_SERVER);
Source

pub fn get_bytes(&self) -> &[u8]

Gets all handshake data.

Source

pub fn get_timestamp(&self) -> Duration

Gets first 4 bytes as timestamp.

Source

pub fn get_version(&self) -> Version

Gets second 4 bytes as Flash Player version/Flash Media Server version.

Source

pub fn get_digest(&self, encryption_algorithm: EncryptionAlgorithm) -> &[u8]

Gets a digest contained in this handshake bytes. Note its place is different by whether encrypts handshake bytes.

§Examples
use std::time::Instant;
use sheave_core::handshake::{
    EncryptionAlgorithm,
    Handshake,
    Version
};

let handshake = Handshake::new(Instant::now().elapsed(), Version::LATEST_CLIENT);

assert_ne!(handshake.get_digest(EncryptionAlgorithm::NotEncrypted), handshake.get_digest(EncryptionAlgorithm::DiffieHellman))
Source

pub fn imprint_digest( &mut self, encryption_algorithm: EncryptionAlgorithm, key: &[u8], )

Imprints an HMAC-SHA256 digest into handshake data.

§Examples
use std::time::Duration;
use sheave_core::handshake::{
    Handshake,
    Version,
    EncryptionAlgorithm
};

// In a case of sending client-side request.
let mut client_handshake = Handshake::new(Duration::default(), Version::LATEST_CLIENT);
client_handshake.imprint_digest(EncryptionAlgorithm::NotEncrypted, Handshake::CLIENT_KEY);

// In a case of sending server-side request.
let mut server_handshake = Handshake::new(Duration::default(), Version::LATEST_SERVER);
server_handshake.imprint_digest(EncryptionAlgorithm::NotEncrypted, Handshake::SERVER_KEY);
Source

pub fn did_digest_match( &self, encryption_algorithm: EncryptionAlgorithm, key: &[u8], ) -> bool

Checks whether imprinted digest matches with one computed by given key.

§Examples
use std::time::Duration;
use sheave_core::handshake::{
    Handshake,
    Version,
    EncryptionAlgorithm
};

// In a case of checking server-side request.
let mut server_handshake = Handshake::new(Duration::default(), Version::LATEST_SERVER);
server_handshake.imprint_digest(EncryptionAlgorithm::NotEncrypted, Handshake::SERVER_KEY);
assert!(server_handshake.did_digest_match(EncryptionAlgorithm::NotEncrypted, Handshake::SERVER_KEY));

// In a case of checking client-side request.
let mut client_handshake = Handshake::new(Duration::default(), Version::LATEST_CLIENT);
server_handshake.imprint_digest(EncryptionAlgorithm::NotEncrypted, Handshake::CLIENT_KEY);
assert!(server_handshake.did_digest_match(EncryptionAlgorithm::NotEncrypted, Handshake::CLIENT_KEY));
Source

pub fn get_signature(&self) -> &[u8]

Gets a signature contained into this handshake bytes.

Source

pub fn imprint_signature( &mut self, encryption_algorithm: EncryptionAlgorithm, key: &[u8], )

Imprints an HMAC-SHA256 signature into handshake data.

§Examples
use std::time::Duration;
use sheave_core::handshake::{
    Handshake,
    Version,
    EncryptionAlgorithm
};

// In a case of exchanging client-side request with server-side response.
let mut client_handshake = Handshake::new(Duration::default(), Version::LATEST_CLIENT);
client_handshake.imprint_digest(EncryptionAlgorithm::NotEncrypted, Handshake::CLIENT_KEY);
let mut key: Vec<u8> = Vec::new();
key.extend_from_slice(Handshake::SERVER_KEY);
key.extend_from_slice(Handshake::COMMON_KEY);
client_handshake.imprint_signature(EncryptionAlgorithm::NotEncrypted, key.as_slice());

// In a case of exchanging server-side request with client-side response.
let mut server_handshake = Handshake::new(Duration::default(), Version::LATEST_SERVER);
server_handshake.imprint_digest(EncryptionAlgorithm::NotEncrypted, Handshake::SERVER_KEY);
let mut key: Vec<u8> = Vec::new();
key.extend_from_slice(Handshake::CLIENT_KEY);
key.extend_from_slice(Handshake::COMMON_KEY);
server_handshake.imprint_signature(EncryptionAlgorithm::NotEncrypted, key.as_slice());
Source

pub fn did_signature_match( &self, encryption_algorithm: EncryptionAlgorithm, key: &[u8], ) -> bool

Checks whether imprinted signature matches one computed by given key.

§Examples
use std::time::Duration;
use sheave_core::handshake::{
    Handshake,
    Version,
    EncryptionAlgorithm
};

// In a case of checking client-side response.
let mut client_handshake = Handshake::new(Duration::default(), Version::LATEST_CLIENT);
client_handshake.imprint_digest(EncryptionAlgorithm::NotEncrypted, Handshake::CLIENT_KEY);
let mut key: Vec<u8> = Vec::new();
key.extend_from_slice(Handshake::SERVER_KEY);
key.extend_from_slice(Handshake::COMMON_KEY);
client_handshake.imprint_signature(EncryptionAlgorithm::NotEncrypted, key.as_slice());
assert!(client_handshake.did_signature_match(EncryptionAlgorithm::NotEncrypted, key.as_slice()));

// In a case of checking server-side response.
let mut server_handshake = Handshake::new(Duration::default(), Version::LATEST_SERVER);
server_handshake.imprint_digest(EncryptionAlgorithm::NotEncrypted, Handshake::SERVER_KEY);
let mut key: Vec<u8> = Vec::new();
key.extend_from_slice(Handshake::CLIENT_KEY);
key.extend_from_slice(Handshake::COMMON_KEY);
server_handshake.imprint_signature(EncryptionAlgorithm::NotEncrypted, key.as_slice());
assert!(server_handshake.did_signature_match(EncryptionAlgorithm::NotEncrypted, key.as_slice()));

Trait Implementations§

Source§

impl Debug for Handshake

Source§

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

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

impl From<[u8; 1536]> for Handshake

Source§

fn from(handshake_bytes: [u8; 1536]) -> Self

Converts to this type from the input type.

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

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

§

fn vzip(self) -> V