Kopete - jabber: Add SASL PLAIN method for authentication

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
pull/1/head
Slávek Banko 8 years ago
parent d2625220de
commit a9aee0e6e0

@ -155,6 +155,7 @@ public:
TQString out_mech; TQString out_mech;
TQByteArray out_buf; TQByteArray out_buf;
bool capable; bool capable;
bool allow_plain;
int err; int err;
TQCA_SASLNeedParams need; TQCA_SASLNeedParams need;
@ -207,12 +208,13 @@ public:
host = _host; host = _host;
} }
void setSecurityProps(bool, bool, bool, bool, bool reqForward, bool reqCreds, bool reqMutual, int ssfMin, int, const TQString &, int) void setSecurityProps(bool noPlain, bool, bool, bool, bool reqForward, bool reqCreds, bool reqMutual, int ssfMin, int, const TQString &, int)
{ {
if(reqForward || reqCreds || reqMutual || ssfMin > 0) if(reqForward || reqCreds || reqMutual || ssfMin > 0)
capable = false; capable = false;
else else
capable = true; capable = true;
allow_plain = !noPlain;
} }
int security() const int security() const
@ -228,8 +230,17 @@ public:
bool clientStart(const TQStringList &mechlist) bool clientStart(const TQStringList &mechlist)
{ {
bool haveMech = false; bool haveMech = false;
resetState();
step = 0;
for(TQStringList::ConstIterator it = mechlist.begin(); it != mechlist.end(); ++it) { for(TQStringList::ConstIterator it = mechlist.begin(); it != mechlist.end(); ++it) {
if((*it) == "PLAIN" && allow_plain) {
out_mech = "PLAIN";
haveMech = true;
break;
}
if((*it) == "DIGEST-MD5") { if((*it) == "DIGEST-MD5") {
out_mech = "DIGEST-MD5";
haveMech = true; haveMech = true;
break; break;
} }
@ -238,9 +249,6 @@ public:
err = TQCA::SASL::NoMech; err = TQCA::SASL::NoMech;
return false; return false;
} }
resetState();
step = 0;
return true; return true;
} }
@ -316,7 +324,7 @@ public:
const TQByteArray *clientInit() const const TQByteArray *clientInit() const
{ {
return 0; return out_mech == "PLAIN" ? &out_buf : 0;
} }
TQByteArray result() const TQByteArray result() const
@ -326,8 +334,49 @@ public:
int clientTryAgain() int clientTryAgain()
{ {
if( out_mech == "PLAIN" ) {
if(step == 0) {
// First, check if we have everything
if(need.user || need.pass) {
err = -1;
return Error;
}
if(!have.user) {
need.user = true;
}
if(!have.pass) {
need.pass = true;
}
if(need.user || need.pass) {
return NeedParams;
}
TQCString authz_ = authz.utf8();
TQCString user_ = user.utf8();
TQCString pass_ = pass.utf8();
int l = 0;
out_buf.resize(authz_.length() + 1 + user_.length() + 1 + pass_.length());
memcpy(&out_buf[l], authz_.data(), authz_.length());
l += authz_.length();
out_buf[l] = '\0';
l += 1;
memcpy(&out_buf[l], user_.data(), user_.length());
l += user_.length();
out_buf[l] = '\0';
l += 1;
memcpy(&out_buf[l], pass_.data(), pass_.length());
++step;
return Continue;
}
out_buf.resize(0);
return Success;
}
if( out_mech == "DIGEST-MD5" ) {
if(step == 0) { if(step == 0) {
out_mech = "DIGEST-MD5";
++step; ++step;
return Continue; return Continue;
} }
@ -404,7 +453,7 @@ public:
++step; ++step;
return Continue; return Continue;
} }
else {
out_buf.resize(0); out_buf.resize(0);
return Success; return Success;
} }

Loading…
Cancel
Save