fix(auth): handle single + response (#145)

This commit is contained in:
Friedel Ziegelmayer 2019-10-21 16:49:15 +02:00 committed by Jon Gjengset
parent 0e5aa5c004
commit 465481de88

View file

@ -323,22 +323,29 @@ impl<T: Read + Write> Client<T> {
// early (see also comment on `login`) // early (see also comment on `login`)
ok_or_unauth_client_err!(self.readline(&mut line), self); ok_or_unauth_client_err!(self.readline(&mut line), self);
if line.starts_with(b"+ ") { // Some servers will only send `+\r\n`.
let line_str = ok_or_unauth_client_err!( if line.starts_with(b"+ ") || &line == b"+\r\n" {
match str::from_utf8(line.as_slice()) { let challenge = if &line == b"+\r\n" {
Ok(line_str) => Ok(line_str), Vec::new()
Err(e) => Err(Error::Parse(ParseError::DataNotUtf8(line, e))), } else {
}, let line_str = ok_or_unauth_client_err!(
self match str::from_utf8(line.as_slice()) {
); Ok(line_str) => Ok(line_str),
let data = ok_or_unauth_client_err!(parse_authenticate_response(line_str), self); Err(e) => Err(Error::Parse(ParseError::DataNotUtf8(line, e))),
let challenge = ok_or_unauth_client_err!( },
base64::decode(data).map_err(|e| Error::Parse(ParseError::Authentication( self
data.to_string(), );
Some(e) let data =
))), ok_or_unauth_client_err!(parse_authenticate_response(line_str), self);
self ok_or_unauth_client_err!(
); base64::decode(data).map_err(|e| Error::Parse(ParseError::Authentication(
data.to_string(),
Some(e)
))),
self
)
};
let raw_response = &authenticator.process(&challenge); let raw_response = &authenticator.process(&challenge);
let auth_response = base64::encode(raw_response); let auth_response = base64::encode(raw_response);
ok_or_unauth_client_err!( ok_or_unauth_client_err!(