This commit is contained in:
Jasper Hugo 2022-03-06 16:24:02 +07:00
parent c68a7cbe0a
commit 44208e28b3
15 changed files with 581 additions and 499 deletions

View File

@ -53,7 +53,10 @@ struct Opt {
#[structopt(short, long, parse(from_occurrences))]
verbose: u8,
#[cfg(feature = "tls-insecure")]
#[structopt(long, help = "Disable TLS certificate verification (use with extreme caution)")]
#[structopt(
long,
help = "Disable TLS certificate verification (use with extreme caution)"
)]
tls_insecure: bool,
}

View File

@ -4,17 +4,15 @@ use jid::Jid;
use xmpp_parsers::{
iq::IqSetPayload,
jingle::{ContentId, Creator, Disposition, ReasonElement, Senders, SessionId},
jingle_ibb::Transport as IbbTransport,
jingle_grouping::Group,
jingle_ibb::Transport as IbbTransport,
jingle_s5b::Transport as Socks5Transport,
ns::{JINGLE, JINGLE_GROUPING, JINGLE_IBB, JINGLE_ICE_UDP, JINGLE_RTP, JINGLE_S5B},
Element,
Error,
Element, Error,
};
use crate::{
jingle_ice_udp::Transport as IceUdpTransport,
jingle_rtp::Description as RtpDescription,
jingle_ice_udp::Transport as IceUdpTransport, jingle_rtp::Description as RtpDescription,
};
generate_attribute!(
@ -169,7 +167,8 @@ impl TryFrom<Element> for Jingle {
if child.is("content", JINGLE) {
let content = Content::try_from(child)?;
jingle.contents.push(content);
} else if child.is("reason", JINGLE) {
}
else if child.is("reason", JINGLE) {
if jingle.reason.is_some() {
return Err(Error::ParseError(
"Jingle must not have more than one reason.",
@ -177,7 +176,8 @@ impl TryFrom<Element> for Jingle {
}
let reason = ReasonElement::try_from(child)?;
jingle.reason = Some(reason);
} else if child.is("group", JINGLE_GROUPING) {
}
else if child.is("group", JINGLE_GROUPING) {
if jingle.group.is_some() {
return Err(Error::ParseError(
"Jingle must not have more than one grouping.",
@ -185,7 +185,8 @@ impl TryFrom<Element> for Jingle {
}
let group = Group::try_from(child)?;
jingle.group = Some(group);
} else {
}
else {
jingle.other.push(child);
}
}
@ -224,7 +225,8 @@ impl TryFrom<Element> for Description {
fn try_from(elem: Element) -> Result<Description, Error> {
Ok(if elem.is("description", JINGLE_RTP) {
Description::Rtp(RtpDescription::try_from(elem)?)
} else {
}
else {
Description::Unknown(elem)
})
}
@ -267,11 +269,14 @@ impl TryFrom<Element> for Transport {
fn try_from(elem: Element) -> Result<Transport, Error> {
Ok(if elem.is("transport", JINGLE_ICE_UDP) {
Transport::IceUdp(IceUdpTransport::try_from(elem)?)
} else if elem.is("transport", JINGLE_IBB) {
}
else if elem.is("transport", JINGLE_IBB) {
Transport::Ibb(IbbTransport::try_from(elem)?)
} else if elem.is("transport", JINGLE_S5B) {
}
else if elem.is("transport", JINGLE_S5B) {
Transport::Socks5(Socks5Transport::try_from(elem)?)
} else {
}
else {
Transport::Unknown(elem)
})
}

View File

@ -44,4 +44,3 @@ impl Fingerprint {
Ok(Fingerprint::from_hash(setup, hash))
}
}

View File

@ -3,10 +3,7 @@ use xmpp_parsers::{
ns::{JINGLE_DTLS, JINGLE_ICE_UDP},
};
use crate::{
jingle_dtls_srtp::Fingerprint,
ns::JITSI_COLIBRI,
};
use crate::{jingle_dtls_srtp::Fingerprint, ns::JITSI_COLIBRI};
generate_element!(
/// Wrapper element for an ICE-UDP transport.

View File

@ -1,4 +1,7 @@
use xmpp_parsers::{jingle_ssma::{Parameter, Semantics}, ns::JINGLE_SSMA};
use xmpp_parsers::{
jingle_ssma::{Parameter, Semantics},
ns::JINGLE_SSMA,
};
use crate::ns::JITSI_MEET;

View File

@ -32,7 +32,7 @@ macro_rules! get_attr {
$attr,
"' missing."
)));
}
},
}
};
($elem:ident, $attr:tt, RequiredNonEmpty, $value:ident, $func:expr) => {
@ -43,7 +43,7 @@ macro_rules! get_attr {
$attr,
"' must not be empty."
)));
}
},
Some($value) => $func,
None => {
return Err(xmpp_parsers::Error::ParseError(concat!(
@ -51,7 +51,7 @@ macro_rules! get_attr {
$attr,
"' missing."
)));
}
},
}
};
($elem:ident, $attr:tt, Default, $value:ident, $func:expr) => {
@ -528,14 +528,15 @@ macro_rules! finish_parse_elem {
macro_rules! generate_serialiser {
($builder:ident, $parent:ident, $elem:ident, Required, String, ($name:tt, $ns:ident)) => {
$builder.append(
xmpp_parsers::Element::builder($name, $ns)
.append(::minidom::Node::Text($parent.$elem)),
xmpp_parsers::Element::builder($name, $ns).append(::minidom::Node::Text($parent.$elem)),
)
};
($builder:ident, $parent:ident, $elem:ident, Option, String, ($name:tt, $ns:ident)) => {
$builder.append_all($parent.$elem.map(|elem| {
xmpp_parsers::Element::builder($name, $ns).append(::minidom::Node::Text(elem))
}))
$builder.append_all(
$parent
.$elem
.map(|elem| xmpp_parsers::Element::builder($name, $ns).append(::minidom::Node::Text(elem))),
)
};
($builder:ident, $parent:ident, $elem:ident, Option, $constructor:ident, ($name:tt, *)) => {
$builder.append_all(

View File

@ -139,10 +139,13 @@ pub unsafe extern "C" fn gstmeet_connection_join_conference(
};
let region = if (*config).region.is_null() {
None
} else {
Some(CStr::from_ptr((*config).region)
}
else {
Some(
CStr::from_ptr((*config).region)
.to_string_lossy()
.to_string())
.to_string(),
)
};
let config = JitsiConferenceConfig {
muc,

View File

@ -6,7 +6,7 @@ use futures::{
sink::SinkExt,
stream::{StreamExt, TryStreamExt},
};
use rand::{RngCore, thread_rng};
use rand::{thread_rng, RngCore};
use tokio::{
sync::{mpsc, Mutex},
time::sleep,
@ -46,7 +46,13 @@ impl ColibriChannel {
.header("connection", "Upgrade")
.header("upgrade", "websocket")
.body(())?;
match tokio_tungstenite::connect_async_tls_with_config(request, None, Some(wss_connector(tls_insecure)?)).await {
match tokio_tungstenite::connect_async_tls_with_config(
request,
None,
Some(wss_connector(tls_insecure)?),
)
.await
{
Ok((websocket, _)) => break websocket,
Err(e) => {
if retries < MAX_CONNECT_RETRIES {
@ -57,7 +63,7 @@ impl ColibriChannel {
else {
return Err(e).context("Failed to connect Colibri WebSocket");
}
}
},
}
};

View File

@ -15,13 +15,13 @@ use tracing::{debug, error, info, trace, warn};
use uuid::Uuid;
pub use xmpp_parsers::disco::Feature;
use xmpp_parsers::{
disco::{DiscoInfoQuery, DiscoInfoResult, Identity},
caps::{self, Caps},
disco::{DiscoInfoQuery, DiscoInfoResult, Identity},
ecaps2::{self, ECaps2},
hashes::{Algo, Hash},
iq::{Iq, IqType},
message::{Message, MessageType},
muc::{Muc, MucUser, user::Status as MucStatus},
muc::{user::Status as MucStatus, Muc, MucUser},
nick::Nick,
ns,
presence::{self, Presence},
@ -42,9 +42,7 @@ const DISCO_NODE: &str = "https://github.com/avstack/gst-meet";
static DISCO_INFO: Lazy<DiscoInfoResult> = Lazy::new(|| DiscoInfoResult {
node: None,
identities: vec![
Identity::new("client", "bot", "en", "gst-meet"),
],
identities: vec![Identity::new("client", "bot", "en", "gst-meet")],
features: vec![
Feature::new(ns::DISCO_INFO),
Feature::new(ns::JINGLE_RTP_AUDIO),
@ -59,9 +57,8 @@ static DISCO_INFO: Lazy<DiscoInfoResult> = Lazy::new(|| DiscoInfoResult {
extensions: vec![],
});
static COMPUTED_CAPS_HASH: Lazy<Hash> = Lazy::new(|| {
caps::hash_caps(&caps::compute_disco(&DISCO_INFO), Algo::Sha_1).unwrap()
});
static COMPUTED_CAPS_HASH: Lazy<Hash> =
Lazy::new(|| caps::hash_caps(&caps::compute_disco(&DISCO_INFO), Algo::Sha_1).unwrap());
#[derive(Debug, Clone, Copy)]
enum JitsiConferenceState {
@ -154,18 +151,23 @@ impl JitsiConference {
let focus = config.focus.clone();
let ecaps2_hash =
ecaps2::hash_ecaps2(&ecaps2::compute_disco(&DISCO_INFO)?, Algo::Sha_256)?;
let ecaps2_hash = ecaps2::hash_ecaps2(&ecaps2::compute_disco(&DISCO_INFO)?, Algo::Sha_256)?;
let mut presence = vec![
Muc::new().into(),
Caps::new(DISCO_NODE, COMPUTED_CAPS_HASH.clone()).into(),
ECaps2::new(vec![ecaps2_hash]).into(),
Element::builder("stats-id", ns::DEFAULT_NS).append("gst-meet").build(),
Element::builder("stats-id", ns::DEFAULT_NS)
.append("gst-meet")
.build(),
Element::builder("jitsi_participant_codecType", ns::DEFAULT_NS)
.append(config.video_codec.as_str())
.build(),
Element::builder("audiomuted", ns::DEFAULT_NS).append("false").build(),
Element::builder("videomuted", ns::DEFAULT_NS).append("false").build(),
Element::builder("audiomuted", ns::DEFAULT_NS)
.append("false")
.build(),
Element::builder("videomuted", ns::DEFAULT_NS)
.append("false")
.build(),
Element::builder("nick", "http://jabber.org/protocol/nick")
.append(config.nick.as_str())
.build(),
@ -268,14 +270,17 @@ impl JitsiConference {
#[tracing::instrument(level = "debug", err)]
pub async fn set_muted(&self, media_type: MediaType, muted: bool) -> Result<()> {
let mut locked_inner = self.inner.lock().await;
let element = Element::builder(media_type.jitsi_muted_presence_element_name(), ns::DEFAULT_NS)
let element = Element::builder(
media_type.jitsi_muted_presence_element_name(),
ns::DEFAULT_NS,
)
.append(muted.to_string())
.build();
locked_inner.presence.retain(|el| el.name() != media_type.jitsi_muted_presence_element_name());
locked_inner
.presence
.retain(|el| el.name() != media_type.jitsi_muted_presence_element_name());
locked_inner.presence.push(element);
self
.send_presence(&locked_inner.presence)
.await
self.send_presence(&locked_inner.presence).await
}
pub async fn pipeline(&self) -> Result<gstreamer::Pipeline> {
@ -479,7 +484,11 @@ impl StanzaFilter for JitsiConference {
},
JoiningMuc => {
let presence = Presence::try_from(element)?;
if let Some(payload) = presence.payloads.iter().find(|payload| payload.is("x", ns::MUC_USER)) {
if let Some(payload) = presence
.payloads
.iter()
.find(|payload| payload.is("x", ns::MUC_USER))
{
let muc_user = MucUser::try_from(payload.clone())?;
if muc_user.status.contains(&MucStatus::SelfPresence) {
debug!("Joined MUC: {}", self.config.muc);
@ -500,23 +509,28 @@ impl StanzaFilter for JitsiConference {
if let Some(node) = query.node {
match node.splitn(2, '#').collect::<Vec<_>>().as_slice() {
// TODO: also support ecaps2, as we send it in our presence.
[uri, hash] if *uri == DISCO_NODE && *hash == COMPUTED_CAPS_HASH.to_base64() => {
[uri, hash]
if *uri == DISCO_NODE && *hash == COMPUTED_CAPS_HASH.to_base64() =>
{
let mut disco_info = DISCO_INFO.clone();
disco_info.node = Some(node);
let iq = Iq::from_result(iq.id, Some(disco_info))
.with_from(Jid::Full(self.jid.clone()))
.with_to(iq.from.unwrap());
self.xmpp_tx.send(iq.into()).await?;
}
},
_ => {
let error = StanzaError::new(
ErrorType::Cancel, DefinedCondition::ItemNotFound,
"en", format!("Unknown disco#info node: {}", node));
ErrorType::Cancel,
DefinedCondition::ItemNotFound,
"en",
format!("Unknown disco#info node: {}", node),
);
let iq = Iq::from_error(iq.id, error)
.with_from(Jid::Full(self.jid.clone()))
.with_to(iq.from.unwrap());
self.xmpp_tx.send(iq.into()).await?;
}
},
}
}
else {
@ -579,7 +593,8 @@ impl StanzaFilter for JitsiConference {
if let Some(colibri_url) = colibri_url {
info!("Connecting Colibri WebSocket to {}", colibri_url);
let colibri_channel = ColibriChannel::new(&colibri_url, self.tls_insecure).await?;
let colibri_channel =
ColibriChannel::new(&colibri_url, self.tls_insecure).await?;
let (tx, rx) = mpsc::channel(8);
colibri_channel.subscribe(tx).await;
jingle_session.colibri_channel = Some(colibri_channel);
@ -593,7 +608,6 @@ impl StanzaFilter for JitsiConference {
// End-to-end ping
if let ColibriMessage::EndpointMessage { to, .. } = &msg {
// if to ==
}
let locked_inner = self_.inner.lock().await;
@ -687,7 +701,9 @@ impl StanzaFilter for JitsiConference {
if let Err(e) = f(self.clone(), participant.clone()).await {
warn!("on_participant failed: {:?}", e);
}
else if let Some(jingle_session) = self.jingle_session.lock().await.as_ref() {
else if let Some(jingle_session) =
self.jingle_session.lock().await.as_ref()
{
gstreamer::debug_bin_to_dot_file(
&jingle_session.pipeline(),
gstreamer::DebugGraphDetails::ALL,

View File

@ -72,7 +72,8 @@ impl Codec {
fn is_rtx(&self, rtx_pt: u8) -> bool {
if let Some(pt) = self.rtx_pt {
pt == rtx_pt
} else {
}
else {
false
}
}
@ -180,7 +181,10 @@ impl JingleSession {
Ok(self.pipeline_state_null_rx.await?)
}
fn parse_rtp_description(description: &RtpDescription, remote_ssrc_map: &mut HashMap<u32, Source>) -> Result<Option<ParsedRtpDescription>> {
fn parse_rtp_description(
description: &RtpDescription,
remote_ssrc_map: &mut HashMap<u32, Source>,
) -> Result<Option<ParsedRtpDescription>> {
let mut opus = None;
let mut h264 = None;
let mut vp8 = None;
@ -222,7 +226,7 @@ impl JingleSession {
rtx_pt: None,
rtcp_fbs: pt.rtcp_fbs.clone(),
});
}
},
"VP8" => {
vp8 = Some(Codec {
name: CodecName::Vp8,
@ -230,7 +234,7 @@ impl JingleSession {
rtx_pt: None,
rtcp_fbs: pt.rtcp_fbs.clone(),
});
}
},
"VP9" => {
vp9 = Some(Codec {
name: CodecName::Vp9,
@ -238,7 +242,7 @@ impl JingleSession {
rtx_pt: None,
rtcp_fbs: pt.rtcp_fbs.clone(),
});
}
},
_ => (),
}
}
@ -326,7 +330,10 @@ impl JingleSession {
}))
}
async fn setup_ice(conference: &JitsiConference, transport: &IceUdpTransport) -> Result<(nice::Agent, u32, u32)> {
async fn setup_ice(
conference: &JitsiConference,
transport: &IceUdpTransport,
) -> Result<(nice::Agent, u32, u32)> {
let ice_agent = nice::Agent::new(&conference.glib_main_context, nice::Compatibility::Rfc5245);
ice_agent.set_ice_tcp(false);
ice_agent.set_upnp(false);
@ -467,11 +474,16 @@ impl JingleSession {
for content in &jingle.contents {
if let Some(Description::Rtp(description)) = &content.description {
if let Some(description) = JingleSession::parse_rtp_description(description, &mut remote_ssrc_map)? {
if let Some(description) =
JingleSession::parse_rtp_description(description, &mut remote_ssrc_map)?
{
codecs.extend(description.codecs);
audio_hdrext_ssrc_audio_level = audio_hdrext_ssrc_audio_level.or(description.audio_hdrext_ssrc_audio_level);
audio_hdrext_transport_cc = audio_hdrext_transport_cc.or(description.audio_hdrext_transport_cc);
video_hdrext_transport_cc = video_hdrext_transport_cc.or(description.video_hdrext_transport_cc);
audio_hdrext_ssrc_audio_level =
audio_hdrext_ssrc_audio_level.or(description.audio_hdrext_ssrc_audio_level);
audio_hdrext_transport_cc =
audio_hdrext_transport_cc.or(description.audio_hdrext_transport_cc);
video_hdrext_transport_cc =
video_hdrext_transport_cc.or(description.video_hdrext_transport_cc);
}
}
@ -520,7 +532,8 @@ impl JingleSession {
debug!("video SSRC: {}", video_ssrc);
debug!("video RTX SSRC: {}", video_rtx_ssrc);
let (ice_agent, ice_stream_id, ice_component_id) = JingleSession::setup_ice(conference, ice_transport).await?;
let (ice_agent, ice_stream_id, ice_component_id) =
JingleSession::setup_ice(conference, ice_transport).await?;
let (ice_local_ufrag, ice_local_pwd) = ice_agent
.local_credentials(ice_stream_id)
@ -662,9 +675,14 @@ impl JingleSession {
None
});
let pts: Vec<(String, u32)> = codecs.iter()
let pts: Vec<(String, u32)> = codecs
.iter()
.filter(|codec| codec.is_video())
.flat_map(|codec| codec.rtx_pt.map(|rtx_pt| (codec.pt.to_string(), rtx_pt as u32)))
.flat_map(|codec| {
codec
.rtx_pt
.map(|rtx_pt| (codec.pt.to_string(), rtx_pt as u32))
})
.collect();
{
let pts = pts.clone();
@ -777,7 +795,8 @@ impl JingleSession {
let source_element = match source.media_type {
MediaType::Audio => {
let codec = codecs.iter()
let codec = codecs
.iter()
.filter(|codec| codec.is_audio())
.find(|codec| codec.is(pt));
if let Some(codec) = codec {
@ -788,7 +807,8 @@ impl JingleSession {
}
},
MediaType::Video => {
let codec = codecs.iter()
let codec = codecs
.iter()
.filter(|codec| codec.is_video())
.find(|codec| codec.is(pt));
if let Some(codec) = codec {
@ -902,7 +922,8 @@ impl JingleSession {
let audio_sink_element = gstreamer::ElementFactory::make(opus.make_pay_name(), None)?;
audio_sink_element.set_property("pt", opus.pt as u32);
audio_sink_element
} else {
}
else {
bail!("no opus payload type in jingle session-initiate");
};
audio_sink_element.set_property("min-ptime", 10i64 * 1000 * 1000);
@ -1045,7 +1066,7 @@ impl JingleSession {
debug!("pipeline state is null");
pipeline_state_null_tx.send(()).unwrap();
break;
}
},
_ => {},
}
}
@ -1077,12 +1098,7 @@ impl JingleSession {
description.payload_types = if initiate_content.name.0 == "audio" {
let codec = codecs.iter().find(|codec| codec.name == CodecName::Opus);
if let Some(codec) = codec {
let mut pt = PayloadType::new(
codec.pt,
"opus".to_owned(),
48000,
2,
);
let mut pt = PayloadType::new(codec.pt, "opus".to_owned(), 48000, 2);
pt.rtcp_fbs = codec.rtcp_fbs.clone();
vec![pt]
}
@ -1168,18 +1184,16 @@ impl JingleSession {
));
}
if let Some(hdrext) = audio_hdrext_transport_cc {
description.hdrexts.push(RtpHdrext::new(
hdrext,
RTP_HDREXT_TRANSPORT_CC.to_owned(),
));
description
.hdrexts
.push(RtpHdrext::new(hdrext, RTP_HDREXT_TRANSPORT_CC.to_owned()));
}
}
else if initiate_content.name.0 == "video" {
if let Some(hdrext) = video_hdrext_transport_cc {
description.hdrexts.push(RtpHdrext::new(
hdrext,
RTP_HDREXT_TRANSPORT_CC.to_owned(),
));
description
.hdrexts
.push(RtpHdrext::new(hdrext, RTP_HDREXT_TRANSPORT_CC.to_owned()));
}
}
@ -1227,10 +1241,7 @@ impl JingleSession {
jingle_accept = jingle_accept.set_group(jingle_grouping::Group {
semantics: jingle_grouping::Semantics::Bundle,
contents: vec![
GroupContent::new("video"),
GroupContent::new("audio"),
],
contents: vec![GroupContent::new("video"), GroupContent::new("audio")],
});
let accept_iq_id = generate_id();

View File

@ -1,4 +1,7 @@
#[cfg(any(feature = "tls-rustls-native-roots", feature = "tls-rustls-webpki-roots"))]
#[cfg(any(
feature = "tls-rustls-native-roots",
feature = "tls-rustls-webpki-roots"
))]
use std::sync::Arc;
#[cfg(not(feature = "tls-insecure"))]
@ -19,11 +22,15 @@ pub(crate) fn wss_connector(insecure: bool) -> Result<tokio_tungstenite::Connect
.with_no_client_auth();
#[cfg(feature = "tls-insecure")]
if insecure {
config.dangerous().set_certificate_verifier(Arc::new(InsecureServerCertVerifier));
config
.dangerous()
.set_certificate_verifier(Arc::new(InsecureServerCertVerifier));
}
#[cfg(not(feature = "tls-insecure"))]
if insecure {
bail!("Insecure TLS mode can only be enabled if the tls-insecure feature was enabled at compile time.")
bail!(
"Insecure TLS mode can only be enabled if the tls-insecure feature was enabled at compile time."
)
}
Ok(Connector::Rustls(Arc::new(config)))
}
@ -31,15 +38,13 @@ pub(crate) fn wss_connector(insecure: bool) -> Result<tokio_tungstenite::Connect
#[cfg(feature = "tls-rustls-webpki-roots")]
pub(crate) fn wss_connector(insecure: bool) -> Result<tokio_tungstenite::Connector> {
let mut roots = rustls::RootCertStore::empty();
roots.add_server_trust_anchors(
webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
roots.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
rustls::OwnedTrustAnchor::from_subject_spki_name_constraints(
ta.subject,
ta.spki,
ta.name_constraints,
)
})
);
}));
let config = rustls::ClientConfig::builder()
.with_safe_defaults()
@ -47,11 +52,15 @@ pub(crate) fn wss_connector(insecure: bool) -> Result<tokio_tungstenite::Connect
.with_no_client_auth();
#[cfg(feature = "tls-insecure")]
if insecure {
config.dangerous().set_certificate_verifier(Arc::new(InsecureServerCertVerifier));
config
.dangerous()
.set_certificate_verifier(Arc::new(InsecureServerCertVerifier));
}
#[cfg(not(feature = "tls-insecure"))]
if insecure {
bail!("Insecure TLS mode can only be enabled if the tls-insecure feature was enabled at compile time.")
bail!(
"Insecure TLS mode can only be enabled if the tls-insecure feature was enabled at compile time."
)
}
Ok(Connector::Rustls(Arc::new(config)))
}
@ -67,17 +76,39 @@ pub(crate) fn wss_connector(insecure: bool) -> Result<tokio_tungstenite::Connect
}
#[cfg(not(feature = "tls-insecure"))]
if insecure {
bail!("Insecure TLS mode can only be enabled if the tls-insecure feature was enabled at compile time.")
bail!(
"Insecure TLS mode can only be enabled if the tls-insecure feature was enabled at compile time."
)
}
Ok(Connector::NativeTls(builder.build()?))
}
#[cfg(all(feature = "tls-insecure", any(feature = "tls-rustls-native-roots", feature = "tls-rustls-webpki-roots")))]
#[cfg(all(
feature = "tls-insecure",
any(
feature = "tls-rustls-native-roots",
feature = "tls-rustls-webpki-roots"
)
))]
struct InsecureServerCertVerifier;
#[cfg(all(feature = "tls-insecure", any(feature = "tls-rustls-native-roots", feature = "tls-rustls-webpki-roots")))]
#[cfg(all(
feature = "tls-insecure",
any(
feature = "tls-rustls-native-roots",
feature = "tls-rustls-webpki-roots"
)
))]
impl rustls::client::ServerCertVerifier for InsecureServerCertVerifier {
fn verify_server_cert(&self, _end_entity: &rustls::Certificate, _intermediates: &[rustls::Certificate], _server_name: &rustls::ServerName, _scts: &mut dyn Iterator<Item = &[u8]>, _ocsp_response: &[u8], _now: std::time::SystemTime) -> Result<rustls::client::ServerCertVerified, rustls::Error> {
fn verify_server_cert(
&self,
_end_entity: &rustls::Certificate,
_intermediates: &[rustls::Certificate],
_server_name: &rustls::ServerName,
_scts: &mut dyn Iterator<Item = &[u8]>,
_ocsp_response: &[u8],
_now: std::time::SystemTime,
) -> Result<rustls::client::ServerCertVerified, rustls::Error> {
Ok(rustls::client::ServerCertVerified::assertion())
}
}

View File

@ -5,7 +5,7 @@ use futures::{
sink::{Sink, SinkExt},
stream::{Stream, StreamExt, TryStreamExt},
};
use rand::{RngCore, thread_rng};
use rand::{thread_rng, RngCore};
use tokio::sync::{mpsc, oneshot, Mutex};
use tokio_stream::wrappers::ReceiverStream;
use tokio_tungstenite::tungstenite::{
@ -22,7 +22,9 @@ use xmpp_parsers::{
BareJid, Element, FullJid, Jid,
};
use crate::{pinger::Pinger, stanza_filter::StanzaFilter, tls::wss_connector, util::generate_id, xmpp};
use crate::{
pinger::Pinger, stanza_filter::StanzaFilter, tls::wss_connector, util::generate_id, xmpp,
};
#[derive(Debug, Clone, Copy)]
enum ConnectionState {
@ -85,12 +87,21 @@ impl Connection {
.header("sec-websocket-protocol", "xmpp")
.header("sec-websocket-key", base64::encode(&key))
.header("sec-websocket-version", "13")
.header("host", websocket_url.host().context("invalid WebSocket URL: missing host")?)
.header(
"host",
websocket_url
.host()
.context("invalid WebSocket URL: missing host")?,
)
.header("connection", "Upgrade")
.header("upgrade", "websocket")
.body(())
.context("failed to build WebSocket request")?;
let (websocket, _response) = tokio_tungstenite::connect_async_tls_with_config(request, None, Some(wss_connector(tls_insecure)?))
let (websocket, _response) = tokio_tungstenite::connect_async_tls_with_config(
request,
None,
Some(wss_connector(tls_insecure)?),
)
.await
.context("failed to connect XMPP WebSocket")?;
let (sink, stream) = websocket.split();

View File

@ -2,12 +2,7 @@
// from ../../gir-files (@ 8e47c67)
// DO NOT EDIT
use std::{
boxed::Box as Box_,
fmt,
mem::transmute,
ptr, slice,
};
use std::{boxed::Box as Box_, fmt, mem::transmute, ptr, slice};
use glib::{
ffi::gpointer,
@ -48,7 +43,8 @@ extern "C" fn attach_recv_cb(
user_data: gpointer,
) {
if !user_data.is_null() {
let closure: &mut Box<dyn FnMut(Agent, u32, u32, &str)> = unsafe { &mut *(user_data as *mut _) };
let closure: &mut Box<dyn FnMut(Agent, u32, u32, &str)> =
unsafe { &mut *(user_data as *mut _) };
let slice = unsafe { slice::from_raw_parts(data, len as usize) };
let bytes: Vec<_> = slice.iter().map(|b| *b as u8).collect();
if let Ok(s) = std::str::from_utf8(&bytes) {