b/f: fix evaluating 401/407 reply on nonce reuse

sayer/1.4-spce2.6
Stefan Sayer 15 years ago
parent 51cae30c0c
commit 568466ad65

@ -105,7 +105,9 @@ UACAuth::UACAuth(AmSipDialog* dlg,
UACAuthCred* cred)
: dlg(dlg),
credential(cred),
AmSessionEventHandler()
AmSessionEventHandler(),
nonce_count(0),
nonce_reuse(false)
{
}
@ -139,12 +141,15 @@ bool UACAuth::onSipReply(const AmSipReply& reply, int old_dlg_status, const stri
// credential->realm.c_str(),
// credential->user.c_str(),
// credential->pwd.c_str());
if (((reply.code == 401) &&
if (!nonce_reuse &&
(((reply.code == 401) &&
getHeader(ri->second.hdrs, SIP_HDR_AUTHORIZATION, true).length()) ||
((reply.code == 407) &&
getHeader(ri->second.hdrs, SIP_HDR_PROXY_AUTHORIZATION, true).length())) {
getHeader(ri->second.hdrs, SIP_HDR_PROXY_AUTHORIZATION, true).length()))) {
DBG("Authorization failed!\n");
} else {
nonce_reuse = false;
string auth_hdr = (reply.code==407) ?
getHeader(reply.hdrs, SIP_HDR_PROXY_AUTHENTICATE, true) :
getHeader(reply.hdrs, SIP_HDR_WWW_AUTHENTICATE, true);
@ -157,9 +162,13 @@ bool UACAuth::onSipReply(const AmSipReply& reply, int old_dlg_status, const stri
ri->second.method,
auth_uri, ri->second.body, result)) {
string hdrs = ri->second.hdrs;
// TODO(?): strip headers
// ((code==401) ? stripHeader(ri->second.hdrs, "Authorization") :
// stripHeader(ri->second.hdrs, "Proxy-Authorization"));
// strip other auth headers
if (reply.code == 401) {
removeHeader(hdrs, SIP_HDR_AUTHORIZATION);
} else {
removeHeader(hdrs, SIP_HDR_PROXY_AUTHORIZATION);
}
if (hdrs == "\r\n" || hdrs == "\r" || hdrs == "\n")
hdrs = result;
@ -225,6 +234,10 @@ bool UACAuth::onSendRequest(const string& method,
hdrs = result;
else
hdrs += result;
nonce_reuse = true;
} else {
nonce_reuse = false;
}
DBG("adding %d to list of sent requests.\n", cseq);

@ -111,6 +111,8 @@ class UACAuth : public AmSessionEventHandler
string nonce; // last nonce received from server
unsigned int nonce_count;
bool nonce_reuse; // reused nonce?
std::string find_attribute(const std::string& name, const std::string& header);
bool parse_header(const std::string& auth_hdr, UACAuthDigestChallenge& challenge);

Loading…
Cancel
Save