From 2e746f89e21b295d28d8878bbd96384abdb3a273 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 1 Aug 2018 01:07:10 +0200 Subject: [PATCH] replace sha-1 with xmpp-parsers for component handshake --- Cargo.toml | 1 - src/component/auth.rs | 14 ++++---------- src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2faf4fb5..fab462b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,5 +27,4 @@ domain = "0.2" xmpp-parsers = "0.10" idna = "0.1" try_from = "0.2" -sha-1 = "0.7" quick-xml = "0.12" diff --git a/src/component/auth.rs b/src/component/auth.rs index bd1c9aa7..2149da8f 100644 --- a/src/component/auth.rs +++ b/src/component/auth.rs @@ -2,7 +2,7 @@ use std::mem::replace; use futures::{Future, Poll, Async, sink, Sink, Stream}; use tokio_io::{AsyncRead, AsyncWrite}; use minidom::Element; -use sha1::{Sha1, Digest}; +use xmpp_parsers::component::Handshake; use xmpp_codec::Packet; use xmpp_stream::XMPPStream; @@ -28,19 +28,13 @@ impl ComponentAuth { }; this.send( stream, - "handshake", - // TODO: sha1(sid + password) - &format!("{:x}", Sha1::digest((sid + &password).as_bytes())) + Handshake::from_password_and_stream_id(&password, &sid) ); return Ok(this); } - fn send(&mut self, stream: XMPPStream, nonza_name: &str, handshake: &str) { - let nonza = Element::builder(nonza_name) - .ns(NS_JABBER_COMPONENT_ACCEPT) - .append(handshake) - .build(); - + fn send(&mut self, stream: XMPPStream, handshake: Handshake) { + let nonza = Element::from(handshake); let send = stream.send(Packet::Stanza(nonza)); self.state = ComponentAuthState::WaitSend(send); diff --git a/src/lib.rs b/src/lib.rs index 7c42c378..222b3c47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ extern crate rustc_serialize as serialize; extern crate jid; extern crate domain; extern crate idna; -extern crate sha1; +extern crate xmpp_parsers; pub mod xmpp_codec; pub mod xmpp_stream;