Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(wasm): import ironrdp-decoder source into infisical
bernie-g4663e079fa81
diff --git a/wasm/ironrdp-decoder/.gitignore b/wasm/ironrdp-decoder/.gitignorenew file mode 100644index 0000000000..7b93ed31e2--- /dev/null+++ b/wasm/ironrdp-decoder/.gitignore@@ -0,0 +1,3 @@+/target+/pkg+Cargo.lockdiff --git a/wasm/ironrdp-decoder/Cargo.toml b/wasm/ironrdp-decoder/Cargo.tomlnew file mode 100644index 0000000000..96becf65d6--- /dev/null+++ b/wasm/ironrdp-decoder/Cargo.toml@@ -0,0 +1,34 @@+[package]+name = "infisical-rdp-decoder-wasm"+version = "0.0.1"+edition = "2021"+description = "Minimal IronRDP-backed decoder for offline session replay (WASM)"+publish = false++[lib]+crate-type = ["cdylib", "rlib"]++[dependencies]+# IronRDP: we reuse upstream's decoders + ActiveStage state machine so the+# replay viewer matches a live session's rendering. Versions match the+# native bridge (packages/pam/handlers/rdp/native/Cargo.toml).+ironrdp-pdu = "0.7"+ironrdp-core = "0.1"+ironrdp-graphics = "0.7"+ironrdp-session = "0.8"+ironrdp-connector = "0.8"+ironrdp-svc = "0.6"++# wasm-bindgen for JS interop.+wasm-bindgen = "0.2"+js-sys = "0.3"++# Error + logging helpers.+anyhow = "1"+tracing = "0.1"+tracing-wasm = "0.2"++[profile.release]+opt-level = "s"+lto = true+codegen-units = 1diff --git a/wasm/ironrdp-decoder/src/lib.rs b/wasm/ironrdp-decoder/src/lib.rsnew file mode 100644index 0000000000..586fe5d134--- /dev/null+++ b/wasm/ironrdp-decoder/src/lib.rs@@ -0,0 +1,243 @@+//! Offline RDP session replay decoder, backed by IronRDP's own decoders.+//!+//! Consumers (the browser-side replay page) feed raw FastPath / X.224 PDU+//! bytes captured by the gateway during a live session. We drive those+//! bytes through `ironrdp-session`'s `ActiveStage` + `DecodedImage`, then+//! expose the resulting framebuffer as an RGBA buffer JS can blit onto a+//! canvas via `putImageData`.+//!+//! We reuse IronRDP's decoders instead of rewriting them so the replay+//! output matches what a live IronRDP client would render: bitmap RLE,+//! RDP6 streams, pointer compositing -- all handled upstream.++use std::sync::Arc;++use ironrdp_connector::connection_activation::ConnectionActivationSequence;+use ironrdp_connector::{BitmapConfig, Config, ConnectionResult, Credentials, DesktopSize};+use ironrdp_graphics::image_processing::PixelFormat;+use ironrdp_pdu::gcc::KeyboardType;+use ironrdp_pdu::input::fast_path::FastPathInputEvent;+use ironrdp_pdu::input::mouse::{MousePdu, PointerFlags};+use ironrdp_pdu::rdp::capability_sets::{BitmapCodecs, MajorPlatformType};+use ironrdp_pdu::rdp::client_info::{PerformanceFlags, TimezoneInfo};+use ironrdp_pdu::Action;+use ironrdp_session::image::DecodedImage;+use ironrdp_session::{ActiveStage, ActiveStageOutput};+use ironrdp_svc::StaticChannelSet;+use wasm_bindgen::prelude::*;++/// A decoder session tied to a specific desktop size. Create one per+/// replay, feed PDUs in original order, read out the framebuffer + dirty+/// regions after each call.+#[wasm_bindgen]+pub struct RdpDecoder {+ stage: ActiveStage,+ image: DecodedImage,+ last_dirty: Vec<DirtyRect>,+}++#[wasm_bindgen]+#[derive(Clone, Copy)]+pub struct DirtyRect {+ pub x: u16,+ pub y: u16,+ pub w: u16,+ pub h: u16,+}++#[wasm_bindgen]+pub enum PduAction {+ X224 = 0,+ FastPath = 1,+}++#[wasm_bindgen]+impl RdpDecoder {+ /// Construct a decoder with a framebuffer of `width x height` pixels+ /// in RGBA32 format.+ #[wasm_bindgen(constructor)]+ pub fn new(width: u16, height: u16) -> RdpDecoder {+ let desktop_size = DesktopSize { width, height };+ // These channel IDs aren't load-bearing for offline replay — the+ // ActiveStage uses them to route X.224 payloads and we only feed+ // FastPath bytes. Any valid u16s would do.+ let io_channel_id: u16 = 1003;+ let user_channel_id: u16 = 1002;++ let connection_result = ConnectionResult {+ io_channel_id,+ user_channel_id,+ static_channels: StaticChannelSet::default(),+ desktop_size,+ enable_server_pointer: true,+ pointer_software_rendering: true,+ connection_activation: ConnectionActivationSequence::new(+ stub_config(desktop_size),+ io_channel_id,+ user_channel_id,+ ),+ };++ let stage = ActiveStage::new(connection_result);+ let image = DecodedImage::new(PixelFormat::RgbA32, width, height);++ RdpDecoder {+ stage,+ image,+ last_dirty: Vec::new(),+ }+ }++ /// Feed one captured PDU into the decoder. Returns the number of+ /// dirty rectangles produced; read each via `dirty_rect(i)`.+ ///+ /// `action` is 0 for X.224 and 1 for FastPath; mirrors the tap event+ /// emitted by the gateway.+ pub fn feed(&mut self, action: u8, bytes: &[u8]) -> u32 {+ let action = match action {+ 0 => Action::X224,+ 1 => Action::FastPath,+ _ => return 0,+ };+ self.last_dirty.clear();+ let outputs = match self.stage.process(&mut self.image, action, bytes) {+ Ok(o) => o,+ Err(_) => return 0,+ };+ for out in outputs {+ if let ActiveStageOutput::GraphicsUpdate(region) = out {+ // InclusiveRectangle: left/top/right/bottom inclusive.+ let x = region.left;+ let y = region.top;+ let w = region.right.saturating_sub(region.left).saturating_add(1);+ let h = region.bottom.saturating_sub(region.top).saturating_add(1);+ self.last_dirty.push(DirtyRect { x, y, w, h });+ }+ }+ self.last_dirty.len() as u32+ }++ /// Move the server-rendered pointer sprite to (x, y) and re-composite+ /// it into the framebuffer. Returns the number of dirty rectangles+ /// produced (read via `dirty_rect(i)`, same as `feed`).+ ///+ /// The server only emits PositionPointer PDUs for server-initiated+ /// cursor moves (dialog focus pulls, etc). Client-driven mouse+ /// movement is resolved locally — a live IronRDP client calls this+ /// on every mousemove. For replay we drive it from recorded input+ /// events so the cursor tracks the user's actual pointer path.+ pub fn move_pointer(&mut self, x: u16, y: u16) -> u32 {+ self.last_dirty.clear();+ let event = FastPathInputEvent::MouseEvent(MousePdu {+ flags: PointerFlags::empty(),+ number_of_wheel_rotation_units: 0,+ x_position: x,+ y_position: y,+ });+ let outputs = match self+ .stage+ .process_fastpath_input(&mut self.image, &[event])+ {+ Ok(o) => o,+ Err(_) => return 0,+ };+ for out in outputs {+ if let ActiveStageOutput::GraphicsUpdate(region) = out {+ let rx = region.left;+ let ry = region.top;+ let rw = region.right.saturating_sub(region.left).saturating_add(1);+ let rh = region.bottom.saturating_sub(region.top).saturating_add(1);+ self.last_dirty.push(DirtyRect {+ x: rx,+ y: ry,+ w: rw,+ h: rh,+ });+ }+ }+ self.last_dirty.len() as u32+ }++ /// Returns the i-th dirty rect from the most recent `feed()` call.+ pub fn dirty_rect(&self, i: u32) -> Option<DirtyRect> {+ self.last_dirty.get(i as usize).copied()+ }++ /// Returns a pointer into the WASM linear memory for the RGBA+ /// framebuffer. JS reads this as a `Uint8Array` of length+ /// `width * height * 4`.+ pub fn buffer_ptr(&self) -> *const u8 {+ self.image.data().as_ptr()+ }++ pub fn buffer_len(&self) -> usize {+ self.image.data().len()+ }++ pub fn width(&self) -> u16 {+ self.image.width()+ }++ pub fn height(&self) -> u16 {+ self.image.height()+ }++ /// Returns the row stride in bytes. Usually `width * 4` but IronRDP+ /// may align differently.+ pub fn stride(&self) -> usize {+ self.image.stride()+ }+}++#[wasm_bindgen(start)]+pub fn start() {+ tracing_wasm::set_as_global_default();+}++/// Build a minimal Config for ConnectionActivationSequence. The sequence+/// is only used to interpret server-initiated reactivation PDUs; offline+/// replay shouldn't hit those. If it does, the decoder will surface the+/// resulting error up to JS.+fn stub_config(desktop_size: DesktopSize) -> Config {+ Config {+ desktop_size,+ desktop_scale_factor: 0,+ enable_tls: false,+ enable_credssp: false,+ credentials: Credentials::UsernamePassword {+ username: String::new(),+ password: String::new(),+ },+ domain: None,+ client_build: 0,+ client_name: "infisical-replay".to_owned(),+ keyboard_type: KeyboardType::IbmEnhanced,+ keyboard_subtype: 0,+ keyboard_functional_keys_count: 12,+ keyboard_layout: 0,+ ime_file_name: String::new(),+ bitmap: Some(BitmapConfig {+ lossy_compression: false,+ color_depth: 32,+ codecs: BitmapCodecs(Vec::new()),+ }),+ dig_product_id: String::new(),+ client_dir: String::new(),+ platform: MajorPlatformType::UNSPECIFIED,+ hardware_id: None,+ request_data: None,+ autologon: false,+ enable_audio_playback: false,+ performance_flags: PerformanceFlags::default(),+ license_cache: None,+ timezone_info: TimezoneInfo::default(),+ enable_server_pointer: true,+ pointer_software_rendering: true,+ }+}++// Silence unused Arc import in trimmed-down builds.+#[allow(dead_code)]+fn _assert_arc_used() {+ let _: Arc<()> = Arc::new(());+}