[WISH] Modification of HTTP-library (Digest Access Authentication)

moster67

Expert
Licensed User
Longtime User
Erel,

I am connecting to a server which implements Digest Access Authentication (using GET) but I always receive an authentication-error (unauthorized).

I have a read the protocol (here: Digest access authentication - Wikipedia, the free encyclopedia) and I guess your HttpClientWrapper is based on RFC 2617 and not RFC 2069 which is obsolete. I think I have understood quite well how this protocol works and I guess I could implement my own code using the http-library but that would be like reinventing the wheel since I noted that the HttpClientWrapper already supports Digest Access Authentication.

I have searched my very simple sample-code for errors but I cannot find anything wrong with it.

Using Firefox, I had a look at the Server Response generated by the server and noted that the server response is slightly different from the examples shown in above wikipedia-page (which perhaps are standard).

As a reply to my first client request, I receive of course an authentication-error as the protocol forsees:

B4X:
HTTP/1.1 401 Unauthorized

while the response headers are as follows:

B4X:
WWW-Authenticate: Digest qop="auth", realm="mydomain.com", nonce="1372111356"

This reply seems to include all the necessary information so the client can generate the correct successive Client request but this is not the problem in my opinion. I think the problem is the order of the information in the response headers, namely:

B4X:
Digest qop="auth", realm=....

while standard response (I think) should be in the following order:

B4X:
Digest realm="mydomain.com, qop="auth"....

I had a look at your HttpClientWrapper and noted that you assign digest to true if:

B4X:
else if (v.contains("digest realm")) {
                digest = true;
                challenge = h;
              }

I am not 100% sure but I think if you are checking for the string to be exactly as
B4X:
digest realm
your code, in my specific case, will never assign digest to true since the server-response I get from the server is
B4X:
Digest qop="auth", realm=....

Perhaps you can modify your above code to check if both words (digest and realm) are present in the response headers from the server, even if they are not in the order you expected them, using AND or another solution you find suitable.

If I am correct, this may resolve my connection-problem unless there are other problems along the road with the implementation of Digest Access Authentication in the server-firmware. If you agree, can you please recompile a new http-library? At the moment I am stuck with this new project until I resolve this issue.

Thanks.
 
Last edited:

moster67

Expert
Licensed User
Longtime User
That was it. Problem resolved! :sign0060:

Thank you Erel.
 
Top