I'm trying to approach a local XMPP server (Openfire) with a NodeJS application.
I would like to use the DIGEST-MD5 mechanism (I am aware that it has been declared obsolete).
I found this article explaining how the mechanism works: https://wiki.xmpp.org/web/SASL_and_DIGEST-MD5
However, when implementing the mechanism as described in the article, my calculated response is incorrect.
I have done my best to find out what I'm doing wrong, but I can't seem to figure it out.
I am certain that the rest of my stanza is correct, it's just the response that isn't right.
Here is my code for calculating the response:
var x = username + ':' + realm + ':' + pswd;
var y = crypto.createHash('md5').update(x).digest();
var a1 = y + ':' + nonce + ':' + cnonce + ':' + authzid;
var a2 = 'AUTHENTICATE:' + digestUri;
var ha1 = crypto.createHash('md5').update(a1).digest("hex");
var ha2 = crypto.createHash('md5').update(a2).digest("hex");
var kd = ha1 + ':' + nonce + ':00000001:' + cnonce + ':auth:' + ha2;
var z = crypto.createHash('md5').update(kd).digest("hex");
Where z is the final response.
As you can see I am making use of the crypto library for my hashing.
The example mentioned in the article above is a follows:
username="rob",realm="cataclysm.cx",nonce="OA6MG9tEQGm2hh",cnonce="OA6MHXh6VqTrRk",nc=00000001,qop=auth,digesturi="xmpp/cataclysm.cx",response=d388dad90d4bbd760a152321f2143af7,charset=utf-8,authzid="rob@cataclysm.cx/myResource"
When I plug all these values into my own implementation (with the password being 'secret'), my calculated response is:
5093acf6b3bc5687231539507cc2fb20
instead of the expected d388dad90d4bbd760a152321f2143af7.
Other examples don't give me the right result either.
So, what on earth am I doing wrong?
Any and all help would be greatly appreciated!