-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from OpenXbox/develop
Sync master with develop
- Loading branch information
Showing
35 changed files
with
1,714 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/target | ||
*/target | ||
Cargo.lock | ||
Cargo.lock | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "webrtc-srtp"] | ||
path = webrtc-srtp | ||
url = [email protected]:OpenXbox/srtp.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[workspace] | ||
members = ["xal", "smartglass", "gamestreaming", "client"] | ||
members = ["xal", "smartglass", "gamestreaming", "client", "pcap_parser", "teredo"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use std::convert::TryInto; | ||
|
||
/// Implementation of MS-SRTP | ||
/// Source: https://docs.microsoft.com/en-us/openspecs/office_protocols/ms-srtp/bf622cc1-9fb5-4fa2-b18d-239a84dcca65 | ||
/// | ||
/// SRTP requires that each endpoint in an SRTP session maintain cryptographic contexts. For more information, see | ||
/// [RFC3711] section 3.2.3. This protocol maintains cryptographic contexts differently from SRTP [RFC3711]. | ||
/// | ||
/// This protocol maintains two cryptographic contexts per SRTP session: | ||
/// | ||
/// - One for all media streams on the send direction. | ||
/// - One for all media streams on the receive direction. | ||
/// | ||
/// This protocol supports multiple media streams sharing the same SRTP session. Each media stream MUST be uniquely | ||
/// identified by one Synchronization Source (SSRC). This protocol maintains per SSRC transform independent | ||
/// parameters in cryptographic contexts, as specified in section 3.1.3.2. | ||
/// | ||
/// When sending or receiving an SRTP packet, this protocol first uses the SRTP session and direction to identify | ||
/// the cryptographic context, then uses the SSRC in the packet to decide the per SSRC transform independent | ||
/// parameters in the cryptographic context. | ||
use crate::webrtc::srtp::{protection_profile, context}; | ||
use crate::webrtc::rtp::header::Header; | ||
|
||
type Error = Box<dyn std::error::Error>; | ||
type Result<T> = std::result::Result<T, Error>; | ||
|
||
pub struct MsSrtpCryptoContext { | ||
crypto_ctx_in: context::Context, | ||
crypto_ctx_out: context::Context, | ||
} | ||
|
||
impl MsSrtpCryptoContext { | ||
pub fn new(master_key: [u8; 16], master_salt: [u8; 14]) -> Result<Self> { | ||
Ok(Self { | ||
crypto_ctx_in: context::Context::new( | ||
&master_key, | ||
&master_salt, | ||
protection_profile::ProtectionProfile::AEADAES128GCM_MS_SRTP, | ||
None, | ||
None, | ||
)?, | ||
crypto_ctx_out: context::Context::new( | ||
&master_key, | ||
&master_salt, | ||
protection_profile::ProtectionProfile::AEADAES128GCM_MS_SRTP, | ||
None, | ||
None, | ||
)?, | ||
}) | ||
} | ||
|
||
pub fn from_base64(master_bytes: &str) -> Result<Self> { | ||
let master_bytes = base64::decode(master_bytes)?; | ||
Self::new( | ||
master_bytes[..16].try_into()?, | ||
master_bytes[16..].try_into()? | ||
) | ||
} | ||
|
||
pub fn decrypt_rtp_with_header( | ||
&mut self, | ||
encrypted: &[u8], | ||
header: &Header | ||
) -> Result<Vec<u8>> { | ||
Ok(self.crypto_ctx_out.decrypt_rtp_with_header(encrypted, header)?) | ||
} | ||
|
||
pub fn decrypt_rtp(&mut self, encrypted: &[u8]) -> Result<Vec<u8>> { | ||
Ok(self.crypto_ctx_in.decrypt_rtp(encrypted)?) | ||
} | ||
|
||
pub fn encrypt_rtp_with_header( | ||
&mut self, | ||
plaintext: &[u8], | ||
header: &Header | ||
) -> Result<Vec<u8>> { | ||
Ok(self.crypto_ctx_out.encrypt_rtp_with_header(plaintext, header)?) | ||
} | ||
|
||
pub fn encrypt_rtp(&mut self, plaintext: &[u8]) -> Result<Vec<u8>> { | ||
Ok(self.crypto_ctx_out.encrypt_rtp(plaintext)?) | ||
} | ||
|
||
pub fn decrypt_rtp_as_host(&mut self, encrypted: &[u8]) -> Result<Vec<u8>> { | ||
Ok(self.crypto_ctx_out.decrypt_rtp(encrypted)?) | ||
} | ||
|
||
pub fn encrypt_rtp_as_host(&mut self, encrypted: &[u8]) -> Result<Vec<u8>> { | ||
Ok(self.crypto_ctx_in.decrypt_rtp(encrypted)?) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::MsSrtpCryptoContext; | ||
|
||
pub const SRTP_KEY: &str = "RdHzuLLVGuO1aHILIEVJ1UzR7RWVioepmpy+9SRf"; | ||
|
||
#[test] | ||
fn test_decrypt() { | ||
let data = include_bytes!("../testdata/rtp_connection_probing.bin"); | ||
let mut context = MsSrtpCryptoContext::from_base64(SRTP_KEY) | ||
.expect("Failed to initialize crypto context"); | ||
|
||
assert_eq!(data.len(), 1364); | ||
|
||
let decrypted = context.decrypt_rtp(data) | ||
.expect("Failed to decrypt packet"); | ||
|
||
assert_eq!(decrypted.len(), 1348); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum AudioPacketType { | ||
ServerHandshake = 1, | ||
ClientHandshake = 2, | ||
Control = 3, | ||
Data = 4, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum AudioCodec { | ||
Opus = 0, | ||
PCM = 1, | ||
AAC = 2 | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum AudioControlFlags { | ||
StopStream = 0x08, | ||
StartStream = 0x10, | ||
Reinitialize = 0x40, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct PCMAudioFormat { | ||
pub bits: u32, | ||
pub is_float: u32, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct AudioFormat { | ||
pub channels: u32, | ||
pub frequency: u32, | ||
pub codec: u32, | ||
pub pcm_format: Option<PCMAudioFormat>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct AudioServerHandshake { | ||
pub protocol_version: u32, | ||
pub reference_timestamp: u64, | ||
pub format_count: u32, | ||
pub formats: Box<[AudioFormat]> | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct AudioClientHandshake { | ||
pub initial_frame_id: u32, | ||
pub requested_format: AudioFormat | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct AudioControl { | ||
pub flags: u32, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct AudioData { | ||
pub flags: u32, | ||
pub frame_id: u32, | ||
pub timestamp: u64, | ||
pub data_size: u32, | ||
pub data: Vec<u8> | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum AudioPacket { | ||
ServerHandshake(AudioServerHandshake), | ||
ClientHandshake(AudioClientHandshake), | ||
Control(AudioControl), | ||
Data(AudioData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum InputPacketType { | ||
ServerHandshakeV3 = 1, | ||
ClientHandshakeV3 = 2, | ||
FrameAck = 3, | ||
FrameV3 = 4, | ||
|
||
ServerHandshakeV4 = 5, | ||
ClientHandshakeV4 = 6, | ||
FrameV4 = 7, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct InputServerHandshake { | ||
pub min_protocol_version: u32, | ||
pub max_protocol_version: u32, | ||
pub desktop_width: u32, | ||
pub desktop_height: u32, | ||
pub maximum_touches: u32, | ||
pub initial_frame_id: u32, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct InputClientHandshake { | ||
pub min_protocol_version: u32, | ||
pub max_protocol_version: u32, | ||
pub maximum_touches: u32, | ||
pub reference_timestamp: u64, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum InputPacket { | ||
ServerHandshake(InputServerHandshake), | ||
ClientHandshake(InputClientHandshake), | ||
FrameAck, | ||
Frame | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum MessagePacketType { | ||
Handshake = 1, | ||
Data = 2, | ||
CancelRequest = 3, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct MessageData { | ||
pub unknown1: u32, | ||
pub unknown2: u32, | ||
pub unknown3: u32, | ||
pub unknown4: u32, | ||
pub unknown5: u32, | ||
pub unknown6: u32, | ||
} |
Oops, something went wrong.