Add missing messages and clean up imports

This commit is contained in:
Leon Grünewald 2024-09-17 02:00:49 +02:00
parent 145181e364
commit 2b1e16e1cb
2 changed files with 82 additions and 23 deletions

View file

@ -3,7 +3,7 @@ use bytes::{Buf, BufMut, BytesMut};
use prost::Message; use prost::Message;
use tokio_util::codec::{Decoder, Encoder}; use tokio_util::codec::{Decoder, Encoder};
use crate::MumbleMessage; use crate::MumbleMessage;
use crate::proto::{Authenticate, Version, Ping, CryptSetup, CodecVersion, ChannelState, PermissionQuery, UserState, ServerSync, ServerConfig, UdpTunnel, UserRemove}; use crate::proto::*;
pub struct MumbleTcpCodec {} pub struct MumbleTcpCodec {}
@ -40,14 +40,23 @@ impl Decoder for MumbleTcpCodec {
mumble_message = Some(MumbleMessage::Version { data: Version::decode(message_data)? }); mumble_message = Some(MumbleMessage::Version { data: Version::decode(message_data)? });
} }
1 => { 1 => {
mumble_message = Some(MumbleMessage::UDPTunnel { data: UdpTunnel::decode(message_data)? }); mumble_message = Some(MumbleMessage::UdpTunnel { data: UdpTunnel::decode(message_data)? });
} }
2 => {
bail!("The server should never send Authenticate")
},
3 => { 3 => {
mumble_message = Some(MumbleMessage::Ping { data: Ping::decode(message_data)? }); mumble_message = Some(MumbleMessage::Ping { data: Ping::decode(message_data)? });
}, },
4 => {
mumble_message = Some(MumbleMessage::Reject { data: Reject::decode(message_data)? });
}
5 => { 5 => {
mumble_message = Some(MumbleMessage::ServerSync { data: ServerSync::decode(message_data)? }); mumble_message = Some(MumbleMessage::ServerSync { data: ServerSync::decode(message_data)? });
} }
6 => {
mumble_message = Some(MumbleMessage::ChannelRemove { data: ChannelRemove::decode(message_data)? });
}
7 => { 7 => {
mumble_message = Some(MumbleMessage::ChannelState { data: ChannelState::decode(message_data)? }); mumble_message = Some(MumbleMessage::ChannelState { data: ChannelState::decode(message_data)? });
} }
@ -57,18 +66,54 @@ impl Decoder for MumbleTcpCodec {
9 => { 9 => {
mumble_message = Some(MumbleMessage::UserState { data: UserState::decode(message_data)? }); mumble_message = Some(MumbleMessage::UserState { data: UserState::decode(message_data)? });
}, },
10 => {
mumble_message = Some(MumbleMessage::BanList { data: BanList::decode(message_data)? });
},
11 => {
mumble_message = Some(MumbleMessage::TextMessage { data: TextMessage::decode(message_data)? });
},
12 => {
mumble_message = Some(MumbleMessage::PermissionDenied { data: PermissionDenied::decode(message_data)? });
},
13 => {
mumble_message = Some(MumbleMessage::Acl { data: Acl::decode(message_data)? });
}
14 => {
mumble_message = Some(MumbleMessage::QueryUsers { data: QueryUsers::decode(message_data)? });
}
15 => { 15 => {
mumble_message = Some(MumbleMessage::CryptSetup { data: CryptSetup::decode(message_data)? }); mumble_message = Some(MumbleMessage::CryptSetup { data: CryptSetup::decode(message_data)? });
} }
16 => {
mumble_message = Some(MumbleMessage::ContextActionModify { data: ContextActionModify::decode(message_data)? });
}
17 => {
mumble_message = Some(MumbleMessage::ContextAction { data: ContextAction::decode(message_data)? });
}
18 => {
mumble_message = Some(MumbleMessage::UserList { data: UserList::decode(message_data)? });
}
19 => {
mumble_message = Some(MumbleMessage::VoiceTarget { data: VoiceTarget::decode(message_data)? });
}
20 => { 20 => {
mumble_message = Some(MumbleMessage::PermissionQuery {data: PermissionQuery::decode(message_data)?}); mumble_message = Some(MumbleMessage::PermissionQuery {data: PermissionQuery::decode(message_data)?});
} }
21 => { 21 => {
mumble_message = Some(MumbleMessage::CodecVersion {data: CodecVersion::decode(message_data)?}); mumble_message = Some(MumbleMessage::CodecVersion {data: CodecVersion::decode(message_data)?});
}, },
22 => {
mumble_message = Some(MumbleMessage::UserStats {data: UserStats::decode(message_data)?});
}
23 => {
mumble_message = Some(MumbleMessage::RequestBlob {data: RequestBlob::decode(message_data)?});
}
24 => { 24 => {
mumble_message = Some(MumbleMessage::ServerConfig {data: ServerConfig::decode(message_data)?}); mumble_message = Some(MumbleMessage::ServerConfig {data: ServerConfig::decode(message_data)?});
} }
25 => {
mumble_message = Some(MumbleMessage::SuggestConfig {data: SuggestConfig::decode(message_data)?});
}
_ => { _ => {
eprintln!("Unknown message type {:?}", message_type); eprintln!("Unknown message type {:?}", message_type);
} }

View file

@ -10,62 +10,73 @@ pub mod udp {
} }
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
use std::net::{Ipv4Addr, SocketAddr}; use std::net::Ipv4Addr;
use tokio::net::{TcpStream, UdpSocket}; use tokio::net::{TcpStream, UdpSocket};
use tokio::io::AsyncWriteExt;
use tokio_stream::StreamExt;
use prost::Message;
use tokio_rustls::rustls::{ClientConfig, DigitallySignedStruct, Error, RootCertStore, SignatureScheme}; use tokio_rustls::rustls::{ClientConfig, DigitallySignedStruct, Error, RootCertStore, SignatureScheme};
use tokio_rustls::client::TlsStream; use tokio_rustls::client::TlsStream;
use tokio_rustls::{TlsConnector}; use tokio_rustls::{TlsConnector};
use std::sync::Arc; use std::sync::Arc;
use std::time::SystemTime;
use rustls_pki_types::{CertificateDer, ServerName, UnixTime}; use rustls_pki_types::{CertificateDer, ServerName, UnixTime};
use tokio_util::codec::Framed; use tokio_util::codec::Framed;
use crate::codec::MumbleTcpCodec; use crate::codec::MumbleTcpCodec;
use tokio_rustls::rustls::client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier}; use tokio_rustls::rustls::client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier};
use crate::proto::{Authenticate, Version, Ping, CryptSetup, CodecVersion, ChannelState, PermissionQuery, UserState, ServerSync, ServerConfig, UdpTunnel, UserRemove}; use crate::proto::*;
#[derive(Debug)] #[derive(Debug)]
pub enum MumbleMessage { pub enum MumbleMessage {
Version {data: Version}, Version {data: Version},
UDPTunnel { data: UdpTunnel }, UdpTunnel { data: UdpTunnel },
Authenticate {data: Authenticate},
Ping { data: Ping }, Ping { data: Ping },
Reject { data: Reject },
Authenticate {data: Authenticate},
ServerSync { data: ServerSync }, ServerSync { data: ServerSync },
ChannelRemove { data: ChannelRemove },
ChannelState { data: ChannelState }, ChannelState { data: ChannelState },
UserRemove { data: UserRemove }, UserRemove { data: UserRemove },
UserState { data: UserState }, UserState { data: UserState },
BanList { data: BanList },
TextMessage { data: TextMessage },
PermissionDenied { data: PermissionDenied },
Acl { data: Acl },
QueryUsers { data: QueryUsers },
CryptSetup { data: CryptSetup }, CryptSetup { data: CryptSetup },
ContextActionModify { data: ContextActionModify },
ContextAction { data: ContextAction },
UserList { data: UserList },
VoiceTarget { data: VoiceTarget },
PermissionQuery { data: PermissionQuery }, PermissionQuery { data: PermissionQuery },
CodecVersion { data: CodecVersion }, CodecVersion { data: CodecVersion },
UserStats { data: UserStats },
RequestBlob { data: RequestBlob },
ServerConfig { data: ServerConfig }, ServerConfig { data: ServerConfig },
UnknownMessage SuggestConfig { data: SuggestConfig }
} }
pub struct MumbleClient { pub struct MumbleClient {
host: SocketAddr, host: String,
name: String,
port: u16,
password: Option<String>
} }
pub(crate) struct NoVerifier; pub(crate) struct NoVerifier;
impl Debug for NoVerifier { impl Debug for NoVerifier {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
todo!() write!(f, "NoVerifier")
} }
} }
impl ServerCertVerifier for NoVerifier { impl ServerCertVerifier for NoVerifier {
fn verify_server_cert(&self, end_entity: &CertificateDer<'_>, intermediates: &[CertificateDer<'_>], server_name: &ServerName<'_>, ocsp_response: &[u8], now: UnixTime) -> Result<ServerCertVerified, Error> { fn verify_server_cert(&self, _end_entity: &CertificateDer<'_>, _intermediates: &[CertificateDer<'_>], _server_name: &ServerName<'_>, _ocsp_response: &[u8], _now: UnixTime) -> Result<ServerCertVerified, Error> {
Ok(ServerCertVerified::assertion()) Ok(ServerCertVerified::assertion())
} }
fn verify_tls12_signature(&self, message: &[u8], cert: &CertificateDer<'_>, dss: &DigitallySignedStruct) -> Result<HandshakeSignatureValid, Error> { fn verify_tls12_signature(&self, _message: &[u8], _cert: &CertificateDer<'_>, _dss: &DigitallySignedStruct) -> Result<HandshakeSignatureValid, Error> {
Ok(HandshakeSignatureValid::assertion()) Ok(HandshakeSignatureValid::assertion())
} }
fn verify_tls13_signature(&self, message: &[u8], cert: &CertificateDer<'_>, dss: &DigitallySignedStruct) -> Result<HandshakeSignatureValid, Error> { fn verify_tls13_signature(&self, _message: &[u8], _cert: &CertificateDer<'_>, _dss: &DigitallySignedStruct) -> Result<HandshakeSignatureValid, Error> {
Ok(HandshakeSignatureValid::assertion()) Ok(HandshakeSignatureValid::assertion())
} }
@ -89,9 +100,12 @@ impl ServerCertVerifier for NoVerifier {
} }
impl MumbleClient { impl MumbleClient {
pub fn new(host: SocketAddr) -> Self { pub fn new(host: String, port: Option<u16>, name: String, password: Option<String>) -> Self {
Self { Self {
host host,
port: port.unwrap_or(64738),
name,
password
} }
} }
@ -108,8 +122,8 @@ impl MumbleClient {
.set_certificate_verifier(Arc::new(NoVerifier)); .set_certificate_verifier(Arc::new(NoVerifier));
let connector = TlsConnector::from(Arc::new(config)); let connector = TlsConnector::from(Arc::new(config));
let dnsname = ServerName::try_from("127.0.0.1")?; let dnsname = ServerName::try_from(self.host.clone())?;
let stream = TcpStream::connect(&self.host).await?; let stream = TcpStream::connect((self.host.clone(), self.port)).await?;
Ok(connector.connect(dnsname, stream).await?) Ok(connector.connect(dnsname, stream).await?)
} }
@ -133,8 +147,8 @@ impl MumbleClient {
}}).await?; }}).await?;
framed.send(MumbleMessage::Authenticate { data: Authenticate { framed.send(MumbleMessage::Authenticate { data: Authenticate {
username:Some(String::from("Botty")), username: Some(self.name.clone()),
password: Some(String::new()), password: self.password.clone(),
tokens: vec![], tokens: vec![],
celt_versions: vec![], celt_versions: vec![],
opus: Some(true), opus: Some(true),