replace openssl with sha-1 for component handshake

This commit is contained in:
Emmanuel Gil Peyrot 2017-05-02 17:21:26 +01:00
commit b4795cecd4
3 changed files with 8 additions and 5 deletions

View file

@ -21,6 +21,7 @@ base64 = "0.4.0"
minidom = "0.2.0" minidom = "0.2.0"
jid = "0.2.0" jid = "0.2.0"
sasl = "0.3.0" sasl = "0.3.0"
sha-1 = "0.3.2"
[features] [features]
insecure = [] insecure = []

View file

@ -5,12 +5,13 @@ use ns;
use plugin::{Plugin, PluginProxyBinding}; use plugin::{Plugin, PluginProxyBinding};
use event::AbstractEvent; use event::AbstractEvent;
use connection::{Connection, Component2S}; use connection::{Connection, Component2S};
use openssl::hash::{hash, MessageDigest}; use sha_1::{Sha1, Digest};
use minidom::Element; use minidom::Element;
use xml::reader::XmlEvent as ReaderEvent; use xml::reader::XmlEvent as ReaderEvent;
use std::fmt::Write;
use std::sync::mpsc::{Receiver, channel}; use std::sync::mpsc::{Receiver, channel};
/// A builder for `Component`s. /// A builder for `Component`s.
@ -147,11 +148,11 @@ impl Component {
} }
} }
let concatenated = format!("{}{}", sid, secret); let concatenated = format!("{}{}", sid, secret);
let hash = hash(MessageDigest::sha1(), concatenated.as_bytes())?; let mut hasher = Sha1::default();
hasher.input(concatenated.as_bytes());
let mut handshake = String::new(); let mut handshake = String::new();
for byte in hash { for byte in hasher.result() {
// TODO: probably terrible perfs! write!(handshake, "{:02x}", byte)?;
handshake = format!("{}{:x}", handshake, byte);
} }
let mut elem = Element::builder("handshake") let mut elem = Element::builder("handshake")
.ns(ns::COMPONENT_ACCEPT) .ns(ns::COMPONENT_ACCEPT)

View file

@ -2,6 +2,7 @@ extern crate xml;
extern crate openssl; extern crate openssl;
extern crate minidom; extern crate minidom;
extern crate base64; extern crate base64;
extern crate sha_1;
pub extern crate jid; pub extern crate jid;
pub extern crate sasl; pub extern crate sasl;