cargo conflict

This commit is contained in:
irving ou 2025-05-28 15:05:30 -04:00
parent f79954cc87
commit 41ad74dbf1
8 changed files with 70 additions and 44 deletions

View file

@ -21,7 +21,6 @@ pub struct Config {
pub connector: connector::Config,
pub clipboard_type: ClipboardType,
pub rdcleanpath: Option<RDCleanPathConfig>,
pub pcb: Option<String>,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
@ -258,21 +257,6 @@ impl Config {
.pipe(Destination::new)?
};
let username = if let Some(username) = args.username {
username
} else {
inquire::Text::new("Username:").prompt().context("Username prompt")?
};
let password = if let Some(password) = args.password {
password
} else {
inquire::Password::new("Password:")
.without_confirmation()
.prompt()
.context("Password prompt")?
};
let codecs: Vec<_> = args.codecs.iter().map(|s| s.as_str()).collect();
let codecs = match client_codecs_capabilities(&codecs) {
Ok(codecs) => codecs,
@ -307,8 +291,28 @@ impl Config {
args.clipboard_type
};
let credentials = if args.username.is_none() && args.password.is_none() {
Credentials::None
} else {
let username = args.username.unwrap_or_else(|| {
inquire::Text::new("Username:")
.prompt()
.context("Username prompt")
.unwrap_or_else(|_| "Administrator".to_owned())
});
let password = args.password.unwrap_or_else(|| {
inquire::Password::new("Password:")
.prompt()
.context("Password prompt")
.unwrap_or_else(|_| "password".to_owned())
});
Credentials::UsernamePassword { username, password }
};
let connector = connector::Config {
credentials: Credentials::UsernamePassword { username, password },
credentials,
domain: args.domain,
enable_tls: !args.no_tls,
enable_credssp: !args.no_credssp,
@ -349,6 +353,7 @@ impl Config {
request_data: None,
pointer_software_rendering: true,
performance_flags: PerformanceFlags::default(),
pcb: args.pcb,
};
let rdcleanpath = args
@ -362,7 +367,6 @@ impl Config {
connector,
clipboard_type,
rdcleanpath,
pcb: args.pcb,
})
}
}

View file

@ -147,23 +147,6 @@ async fn connect(
connector.attach_static_channel(cliprdr);
}
if let Some(pcb) = &config.pcb {
let pdu = ironrdp::pdu::pcb::PreconnectionBlob {
id: 0,
version: ironrdp::pdu::pcb::PcbVersion::V2,
v2_payload: Some(pcb.to_owned()),
};
let mut encoded: Vec<_> = Vec::new();
let mut cursor = WriteCursor::new(&mut encoded);
pdu.encode(&mut cursor)
.map_err(|e| connector::custom_err!("encode PreconnectionBlob", e))?;
framed
.write_all(&encoded)
.await
.map_err(|e| connector::custom_err!("couldnt write PreconnectionBlob", e))?;
}
let should_upgrade = ironrdp_tokio::connect_begin(&mut framed, &mut connector).await?;

View file

@ -214,7 +214,7 @@ impl Sequence for ClientConnector {
//== Connection Initiation ==//
// Exchange supported security protocols and a few other connection flags.
ClientConnectorState::ConnectionInitiationSendRequest => {
ClientConnectorState::ConnectionInitiationSendRequest => 'state: {
debug!("Connection Initiation");
let mut security_protocol = nego::SecurityProtocol::empty();
@ -240,6 +240,23 @@ impl Sequence for ClientConnector {
return Err(reason_err!("Initiation", "standard RDP security is not supported",));
}
// If there's pcb, we send it in the first message.
if let Some(pcb) = &self.config.pcb {
let pcb = ironrdp_pdu::pcb::PreconnectionBlob {
version: ironrdp_pdu::pcb::PcbVersion::V2,
id: 0,
v2_payload: Some(pcb.to_owned()),
};
let written = ironrdp_core::encode_buf(&pcb, output).map_err(ConnectorError::encode)?;
break 'state (
Written::from_size(written)?,
ClientConnectorState::EnhancedSecurityUpgrade {
selected_protocol: security_protocol,
},
);
}
let connection_request = nego::ConnectionRequest {
nego_data: self.config.request_data.clone().or_else(|| {
self.config

View file

@ -5,7 +5,7 @@ use picky_asn1_x509::{oids, Certificate, ExtensionView, GeneralName};
use sspi::credssp::{self, ClientState, CredSspClient};
use sspi::generator::{Generator, NetworkRequest};
use sspi::negotiate::ProtocolConfig;
use sspi::Username;
use sspi::{AuthIdentity, Username};
use crate::{ConnectorError, ConnectorErrorKind, ConnectorResult, Credentials, ServerName, Written};
@ -97,15 +97,17 @@ impl CredsspSequence {
server_public_key: Vec<u8>,
kerberos_config: Option<KerberosConfig>,
) -> ConnectorResult<(Self, credssp::TsRequest)> {
let credentials: sspi::Credentials = match &credentials {
let credentials: Option<sspi::Credentials> = match &credentials {
Credentials::UsernamePassword { username, password } => {
let username = Username::new(username, domain).map_err(|e| custom_err!("invalid username", e))?;
sspi::AuthIdentity {
username,
password: password.to_owned().into(),
}
.into()
Some(
sspi::AuthIdentity {
username,
password: password.to_owned().into(),
}
.into(),
)
}
Credentials::SmartCard { pin, config } => match config {
Some(config) => {
@ -126,12 +128,13 @@ impl CredsspSequence {
private_key_file_index: None,
private_key: Some(key.into()),
};
sspi::Credentials::SmartCard(Box::new(identity))
Some(sspi::Credentials::SmartCard(Box::new(identity)))
}
None => {
return Err(general_err!("smart card configuration missing"));
}
},
Credentials::None => None,
};
let server_name = server_name.into_inner();

View file

@ -67,6 +67,7 @@ pub struct SmartCardIdentity {
#[derive(Debug, Clone)]
pub enum Credentials {
None,
UsernamePassword {
username: String,
password: String,
@ -80,6 +81,7 @@ pub enum Credentials {
impl Credentials {
fn username(&self) -> Option<&str> {
match self {
Self::None => None,
Self::UsernamePassword { username, .. } => Some(username),
Self::SmartCard { .. } => None, // Username is ultimately provided by the smart card certificate.
}
@ -87,10 +89,15 @@ impl Credentials {
fn secret(&self) -> &str {
match self {
Self::None => "",
Self::UsernamePassword { password, .. } => password,
Self::SmartCard { pin, .. } => pin,
}
}
fn is_none(&self) -> bool {
matches!(self, Self::None)
}
}
#[derive(Debug, Clone)]
@ -187,6 +194,8 @@ pub struct Config {
pub no_server_pointer: bool,
pub pointer_software_rendering: bool,
pub performance_flags: PerformanceFlags,
pub pcb: Option<String>,
}
ironrdp_core::assert_impl!(Config: Send, Sync);

View file

@ -578,6 +578,12 @@ impl<'a> WriteCursor<'a> {
self.pos
}
/// Returns the number of bytes written.
#[inline]
pub const fn bytes_written(&self) -> usize {
self.pos
}
/// Write an array of bytes to the buffer.
#[inline]
#[track_caller]

View file

@ -861,6 +861,8 @@ fn build_config(
desktop_scale_factor: 0,
hardware_id: None,
license_cache: None,
// TODO: implement this
pcb: None,
}
}