feat(protocol): define gateway control envelopes

This commit is contained in:
sechmachine
2026-07-29 17:24:18 +07:00
parent 36f6edffca
commit 0ea21cd3f2
29 changed files with 1445 additions and 41 deletions
+100 -3
View File
@@ -1,6 +1,6 @@
// Code generated by tools/generate.py; DO NOT EDIT.
#![allow(non_snake_case)]
pub const SCHEMA_SHA256: &str = "792abfb9cfe70e79911d499d76c009ab848713278bc240b88576df520580e480";
pub const SCHEMA_SHA256: &str = "e35414af52d7a097dea05567fdab11f842a42e529fb6cbedd281c48dbf930b17";
pub const CURRENT_WIRE_VERSION: &str = "1";
pub const N_MINUS_1_WIRE_VERSION: &str = "0";
pub const N_MINUS_2_WIRE_VERSION: &str = "-1";
@@ -272,6 +272,33 @@ impl ChannelFrame {
pub fn payload(&self) -> &String { &self.payload }
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ClipboardPolicy {
clientToProviderEnabled: bool,
providerToClientEnabled: bool,
maxTextBytes: i64,
maxUpdatesPerMinute: i64,
}
impl ClipboardPolicy {
pub fn new(clientToProviderEnabled: bool, providerToClientEnabled: bool, maxTextBytes: i64, maxUpdatesPerMinute: i64) -> Result<Self, ValidationError> {
let value = Self { clientToProviderEnabled, providerToClientEnabled, maxTextBytes, maxUpdatesPerMinute };
value.validate()?;
Ok(value)
}
pub fn validate(&self) -> Result<(), ValidationError> {
if self.maxTextBytes < 1 { return Err(ValidationError::new("max_text_bytes", "minimum")); }
if self.maxTextBytes > 65536 { return Err(ValidationError::new("max_text_bytes", "maximum")); }
if self.maxUpdatesPerMinute < 1 { return Err(ValidationError::new("max_updates_per_minute", "minimum")); }
if self.maxUpdatesPerMinute > 120 { return Err(ValidationError::new("max_updates_per_minute", "maximum")); }
Ok(())
}
pub fn clientToProviderEnabled(&self) -> &bool { &self.clientToProviderEnabled }
pub fn providerToClientEnabled(&self) -> &bool { &self.providerToClientEnabled }
pub fn maxTextBytes(&self) -> &i64 { &self.maxTextBytes }
pub fn maxUpdatesPerMinute(&self) -> &i64 { &self.maxUpdatesPerMinute }
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ClipboardText {
text: String,
@@ -612,6 +639,71 @@ impl FieldViolation {
pub fn code(&self) -> &String { &self.code }
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GatewayClipboardAudit {
version: String,
sessionId: String,
direction: String,
outcome: String,
textBytes: i64,
reason: String,
}
impl GatewayClipboardAudit {
pub fn new(version: String, sessionId: String, direction: String, outcome: String, textBytes: i64, reason: String) -> Result<Self, ValidationError> {
let value = Self { version, sessionId, direction, outcome, textBytes, reason };
value.validate()?;
Ok(value)
}
pub fn validate(&self) -> Result<(), ValidationError> {
if self.version != "1" { return Err(ValidationError::new("version", "invalid_value")); }
if self.sessionId.is_empty() { return Err(ValidationError::new("session_id", "required")); }
if !self.sessionId.is_empty() && self.sessionId.len() < 1 { return Err(ValidationError::new("session_id", "min_length")); }
if self.sessionId.len() > 128 { return Err(ValidationError::new("session_id", "max_length")); }
if self.direction != "client_to_provider" && self.direction != "provider_to_client" { return Err(ValidationError::new("direction", "invalid_value")); }
if self.outcome != "forwarded" && self.outcome != "suppressed" && self.outcome != "rejected" { return Err(ValidationError::new("outcome", "invalid_value")); }
if self.textBytes < 0 { return Err(ValidationError::new("text_bytes", "minimum")); }
if self.textBytes > 65536 { return Err(ValidationError::new("text_bytes", "maximum")); }
if self.reason != "forwarded" && self.reason != "loop" && self.reason != "policy" && self.reason != "rate" && self.reason != "provider" && self.reason != "malformed" { return Err(ValidationError::new("reason", "invalid_value")); }
Ok(())
}
pub fn version(&self) -> &String { &self.version }
pub fn sessionId(&self) -> &String { &self.sessionId }
pub fn direction(&self) -> &String { &self.direction }
pub fn outcome(&self) -> &String { &self.outcome }
pub fn textBytes(&self) -> &i64 { &self.textBytes }
pub fn reason(&self) -> &String { &self.reason }
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GatewayClipboardText {
direction: String,
text: String,
encoding: String,
loopToken: String,
}
impl GatewayClipboardText {
pub fn new(direction: String, text: String, encoding: String, loopToken: String) -> Result<Self, ValidationError> {
let value = Self { direction, text, encoding, loopToken };
value.validate()?;
Ok(value)
}
pub fn validate(&self) -> Result<(), ValidationError> {
if self.direction != "client_to_provider" && self.direction != "provider_to_client" { return Err(ValidationError::new("direction", "invalid_value")); }
if self.text.len() > 65536 { return Err(ValidationError::new("text", "max_length")); }
if self.encoding != "utf-8" { return Err(ValidationError::new("encoding", "invalid_value")); }
if self.loopToken.is_empty() { return Err(ValidationError::new("loop_token", "required")); }
if !self.loopToken.is_empty() && self.loopToken.len() < 16 { return Err(ValidationError::new("loop_token", "min_length")); }
if self.loopToken.len() > 128 { return Err(ValidationError::new("loop_token", "max_length")); }
Ok(())
}
pub fn direction(&self) -> &String { &self.direction }
pub fn text(&self) -> &String { &self.text }
pub fn encoding(&self) -> &String { &self.encoding }
pub fn loopToken(&self) -> &String { &self.loopToken }
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GatewayDrain {
version: String,
@@ -1001,11 +1093,13 @@ pub struct ProviderSessionWork {
clientCertificatePem: String,
clientPrivateKeyPem: String,
serverCertificatePem: String,
clipboardPolicy: ClipboardPolicy,
providerApplicationTerminationAllowed: bool,
}
impl ProviderSessionWork {
pub fn new(version: String, sessionId: String, gatewayId: String, reconnectSequence: i64, expiresAt: String, providerProfile: String, providerIdentity: String, policyVersionId: String, applicationId: String, clientId: String, managementHost: String, managementPort: i64, streamHost: String, streamPort: i64, clientCertificatePem: String, clientPrivateKeyPem: String, serverCertificatePem: String) -> Result<Self, ValidationError> {
let value = Self { version, sessionId, gatewayId, reconnectSequence, expiresAt, providerProfile, providerIdentity, policyVersionId, applicationId, clientId, managementHost, managementPort, streamHost, streamPort, clientCertificatePem, clientPrivateKeyPem, serverCertificatePem };
pub fn new(version: String, sessionId: String, gatewayId: String, reconnectSequence: i64, expiresAt: String, providerProfile: String, providerIdentity: String, policyVersionId: String, applicationId: String, clientId: String, managementHost: String, managementPort: i64, streamHost: String, streamPort: i64, clientCertificatePem: String, clientPrivateKeyPem: String, serverCertificatePem: String, clipboardPolicy: ClipboardPolicy, providerApplicationTerminationAllowed: bool) -> Result<Self, ValidationError> {
let value = Self { version, sessionId, gatewayId, reconnectSequence, expiresAt, providerProfile, providerIdentity, policyVersionId, applicationId, clientId, managementHost, managementPort, streamHost, streamPort, clientCertificatePem, clientPrivateKeyPem, serverCertificatePem, clipboardPolicy, providerApplicationTerminationAllowed };
value.validate()?;
Ok(value)
}
@@ -1051,6 +1145,7 @@ impl ProviderSessionWork {
if self.serverCertificatePem.is_empty() { return Err(ValidationError::new("server_certificate_pem", "required")); }
if !self.serverCertificatePem.is_empty() && self.serverCertificatePem.len() < 1 { return Err(ValidationError::new("server_certificate_pem", "min_length")); }
if self.serverCertificatePem.len() > 32768 { return Err(ValidationError::new("server_certificate_pem", "max_length")); }
self.clipboardPolicy.validate().map_err(|_| ValidationError::new("clipboard_policy", "invalid_object"))?;
Ok(())
}
pub fn version(&self) -> &String { &self.version }
@@ -1070,6 +1165,8 @@ impl ProviderSessionWork {
pub fn clientCertificatePem(&self) -> &String { &self.clientCertificatePem }
pub fn clientPrivateKeyPem(&self) -> &String { &self.clientPrivateKeyPem }
pub fn serverCertificatePem(&self) -> &String { &self.serverCertificatePem }
pub fn clipboardPolicy(&self) -> &ClipboardPolicy { &self.clipboardPolicy }
pub fn providerApplicationTerminationAllowed(&self) -> &bool { &self.providerApplicationTerminationAllowed }
}
#[derive(Debug, Clone, PartialEq, Eq)]