mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
replace parts of client::auth with xmpp-parsers
This commit is contained in:
parent
db81338bc6
commit
2a17ffc624
3 changed files with 21 additions and 34 deletions
|
@ -21,7 +21,6 @@ minidom = "0.9"
|
||||||
native-tls = "0.1"
|
native-tls = "0.1"
|
||||||
tokio-tls = "0.1"
|
tokio-tls = "0.1"
|
||||||
sasl = "0.4"
|
sasl = "0.4"
|
||||||
rustc-serialize = "0.3"
|
|
||||||
jid = { version = "0.5", features = ["minidom"] }
|
jid = { version = "0.5", features = ["minidom"] }
|
||||||
domain = "0.2"
|
domain = "0.2"
|
||||||
xmpp-parsers = "0.10"
|
xmpp-parsers = "0.10"
|
||||||
|
|
|
@ -5,9 +5,9 @@ use sasl::common::Credentials;
|
||||||
use sasl::common::scram::{Sha1, Sha256};
|
use sasl::common::scram::{Sha1, Sha256};
|
||||||
use sasl::client::Mechanism;
|
use sasl::client::Mechanism;
|
||||||
use sasl::client::mechanisms::{Scram, Plain, Anonymous};
|
use sasl::client::mechanisms::{Scram, Plain, Anonymous};
|
||||||
use serialize::base64::FromBase64;
|
|
||||||
use minidom::Element;
|
use minidom::Element;
|
||||||
use xmpp_parsers::sasl::{Auth, Response, Mechanism as XMPPMechanism};
|
use xmpp_parsers::sasl::{Auth, Challenge, Response, Success, Failure, Mechanism as XMPPMechanism};
|
||||||
|
use try_from::TryFrom;
|
||||||
|
|
||||||
use xmpp_codec::Packet;
|
use xmpp_codec::Packet;
|
||||||
use xmpp_stream::XMPPStream;
|
use xmpp_stream::XMPPStream;
|
||||||
|
@ -30,9 +30,9 @@ enum ClientAuthState<S: AsyncWrite> {
|
||||||
impl<S: AsyncWrite> ClientAuth<S> {
|
impl<S: AsyncWrite> ClientAuth<S> {
|
||||||
pub fn new(stream: XMPPStream<S>, creds: Credentials) -> Result<Self, String> {
|
pub fn new(stream: XMPPStream<S>, creds: Credentials) -> Result<Self, String> {
|
||||||
let mechs: Vec<(Box<Mechanism>, XMPPMechanism)> = vec![
|
let mechs: Vec<(Box<Mechanism>, XMPPMechanism)> = vec![
|
||||||
// (Box::new(Scram::<Sha256>::from_credentials(creds.clone()).unwrap()),
|
(Box::new(Scram::<Sha256>::from_credentials(creds.clone()).unwrap()),
|
||||||
// XMPPMechanism::ScramSha256
|
XMPPMechanism::ScramSha256
|
||||||
// ),
|
),
|
||||||
(Box::new(Scram::<Sha1>::from_credentials(creds.clone()).unwrap()),
|
(Box::new(Scram::<Sha1>::from_credentials(creds.clone()).unwrap()),
|
||||||
XMPPMechanism::ScramSha1
|
XMPPMechanism::ScramSha1
|
||||||
),
|
),
|
||||||
|
@ -109,33 +109,22 @@ impl<S: AsyncRead + AsyncWrite> Future for ClientAuth<S> {
|
||||||
},
|
},
|
||||||
ClientAuthState::WaitRecv(mut stream) =>
|
ClientAuthState::WaitRecv(mut stream) =>
|
||||||
match stream.poll() {
|
match stream.poll() {
|
||||||
Ok(Async::Ready(Some(Packet::Stanza(ref stanza))))
|
Ok(Async::Ready(Some(Packet::Stanza(stanza)))) => {
|
||||||
if stanza.is("challenge", NS_XMPP_SASL) =>
|
if let Ok(challenge) = Challenge::try_from(stanza.clone()) {
|
||||||
{
|
let response = try!(self.mechanism.response(&challenge.data));
|
||||||
let content = try!(
|
self.send(stream, Response { data: response });
|
||||||
stanza.text()
|
self.poll()
|
||||||
.from_base64()
|
} else if let Ok(_) = Success::try_from(stanza.clone()) {
|
||||||
.map_err(|e| format!("{}", e))
|
let start = stream.restart();
|
||||||
);
|
self.state = ClientAuthState::Start(start);
|
||||||
let response = try!(self.mechanism.response(&content));
|
self.poll()
|
||||||
self.send(stream, Response { data: response });
|
} else if let Ok(failure) = Failure::try_from(stanza) {
|
||||||
self.poll()
|
let e = failure.data;
|
||||||
},
|
Err(e)
|
||||||
Ok(Async::Ready(Some(Packet::Stanza(ref stanza))))
|
} else {
|
||||||
if stanza.is("success", NS_XMPP_SASL) =>
|
Ok(Async::NotReady)
|
||||||
{
|
}
|
||||||
let start = stream.restart();
|
}
|
||||||
self.state = ClientAuthState::Start(start);
|
|
||||||
self.poll()
|
|
||||||
},
|
|
||||||
Ok(Async::Ready(Some(Packet::Stanza(ref stanza))))
|
|
||||||
if stanza.is("failure", NS_XMPP_SASL) =>
|
|
||||||
{
|
|
||||||
let e = stanza.children().next()
|
|
||||||
.map(|child| child.name())
|
|
||||||
.unwrap_or("Authentication failure");
|
|
||||||
Err(e.to_owned())
|
|
||||||
},
|
|
||||||
Ok(Async::Ready(event)) => {
|
Ok(Async::Ready(event)) => {
|
||||||
println!("ClientAuth ignore {:?}", event);
|
println!("ClientAuth ignore {:?}", event);
|
||||||
Ok(Async::NotReady)
|
Ok(Async::NotReady)
|
||||||
|
|
|
@ -10,7 +10,6 @@ extern crate minidom;
|
||||||
extern crate native_tls;
|
extern crate native_tls;
|
||||||
extern crate tokio_tls;
|
extern crate tokio_tls;
|
||||||
extern crate sasl;
|
extern crate sasl;
|
||||||
extern crate rustc_serialize as serialize;
|
|
||||||
extern crate jid;
|
extern crate jid;
|
||||||
extern crate domain;
|
extern crate domain;
|
||||||
extern crate idna;
|
extern crate idna;
|
||||||
|
|
Loading…
Reference in a new issue