Skip to main content

KeyMethodV2

Struct KeyMethodV2 

Source
pub struct KeyMethodV2 {
    pub pre_master: [u8; 48],
    pub random1: [u8; 32],
    pub random2: [u8; 32],
    pub options: String,
    pub username: Option<String>,
    pub password: Option<String>,
    pub peer_info: Option<String>,
}
Expand description

Key method v2 data (exchanged during TLS handshake)

Fields§

§pre_master: [u8; 48]

Pre-master secret (48 bytes)

§random1: [u8; 32]

Random data 1 (32 bytes) - used as EKM context and PRF seed

§random2: [u8; 32]

Random data 2 (32 bytes) - used as additional PRF seed

§options: String

Options string

§username: Option<String>

Username (if using auth)

§password: Option<String>

Password (if using auth)

§peer_info: Option<String>

Peer info

Implementations§

Source§

impl KeyMethodV2

Source

pub fn parse(data: &[u8]) -> Result<Self>

Parse key method v2 data from bytes (received from TLS plaintext)

Format (OpenVPN key_source + metadata):

  • 4 bytes: literal 0
  • 1 byte: key method (must be 2)
  • 48 bytes: pre-master secret
  • 32 bytes: random1
  • 32 bytes: random2
  • 2 bytes + N bytes: options string (length-prefixed, null-terminated)
  • 2 bytes + N bytes: username (length-prefixed, optional)
  • 2 bytes + N bytes: password (length-prefixed, optional)
  • 2 bytes + N bytes: peer_info (length-prefixed, optional)
Source

pub fn parse_from_server(data: &[u8]) -> Result<Self>

Parse key method v2 data from server (received from TLS plaintext)

The server format omits the pre_master secret, only sending:

  • 4 bytes: literal 0
  • 1 byte: key method (must be 2)
  • 32 bytes: random1
  • 32 bytes: random2
  • 2 bytes + N bytes: options string (length-prefixed, null-terminated)
Source

pub fn encode(&self, is_server: bool) -> Vec<u8>

Encode to bytes (OpenVPN key_method_v2 wire format)

When is_server is true (server writing its response), pre_master is NOT included in the key source material – only random1 and random2. When is_server is false (client writing), pre_master IS included. This matches the OpenVPN key_source2_randomize_write asymmetry.

Trait Implementations§

Source§

impl Clone for KeyMethodV2

Source§

fn clone(&self) -> KeyMethodV2

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyMethodV2

Source§

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

Formats the value using the given formatter. 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> 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, 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 = 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