added more channel binding infrastructure

This commit is contained in:
lumi 2017-02-25 06:58:42 +01:00
parent 6579ce6563
commit a88d9aa566
2 changed files with 13 additions and 2 deletions

View file

@ -68,11 +68,12 @@ impl ClientBuilder {
/// Connects to the server and returns a `Client` when succesful. /// Connects to the server and returns a `Client` when succesful.
pub fn connect(self) -> Result<Client, Error> { pub fn connect(self) -> Result<Client, Error> {
let host = &self.host.unwrap_or(self.jid.domain.clone()); let host = &self.host.unwrap_or(self.jid.domain.clone());
// TODO: channel binding
let mut transport = SslTransport::connect(host, self.port)?; let mut transport = SslTransport::connect(host, self.port)?;
C2S::init(&mut transport, &self.jid.domain, "before_sasl")?; C2S::init(&mut transport, &self.jid.domain, "before_sasl")?;
let (sender_out, sender_in) = channel(); let (sender_out, sender_in) = channel();
let (dispatcher_out, dispatcher_in) = channel(); let (dispatcher_out, dispatcher_in) = channel();
let mut credentials = self.credentials.expect("can't connect without credentials");
credentials.channel_binding = transport.channel_bind();
let mut client = Client { let mut client = Client {
jid: self.jid, jid: self.jid,
transport: transport, transport: transport,
@ -81,7 +82,7 @@ impl ClientBuilder {
sender_in: sender_in, sender_in: sender_in,
dispatcher_in: dispatcher_in, dispatcher_in: dispatcher_in,
}; };
client.connect(self.credentials.expect("can't connect without credentials"))?; client.connect(credentials)?;
client.bind()?; client.bind()?;
Ok(client) Ok(client)
} }

View file

@ -35,6 +35,11 @@ pub trait Transport {
/// Resets the stream. /// Resets the stream.
fn reset_stream(&mut self); fn reset_stream(&mut self);
/// Gets channel binding data.
fn channel_bind(&self) -> Option<Vec<u8>> {
None
}
} }
/// A transport which uses STARTTLS. /// A transport which uses STARTTLS.
@ -73,6 +78,11 @@ impl Transport for SslTransport {
.. Default::default() .. Default::default()
}); });
} }
fn channel_bind(&self) -> Option<Vec<u8>> {
// TODO: channel binding
None
}
} }
impl SslTransport { impl SslTransport {