I have been following a couple of articles regarding RESTful web services with WCF and more specifically, how to go about authentication in these. The main article I have been referencing is Aaron Skonnard's RESTful Web Services with WCF 3.5. Another one that specifically deals with HMAC authentication is Itai Goldstiens article which is based on Skonnards article.
I am confused about the "User Key" that is referenced to in both articles. I have a client application that is going to require a user to have both a user name and password.
- Does this then mean that the key I use to initialise the System.Security.Cryptography.HMACMD5 class is simply the users password?
Given the method used to create the Mac in Itai's article (shown below), am I right is thinking that
key
is the users password andtext
is the string we are using confirm that the details are in fact correct?public static string EncodeText(byte[] key, string text, Encoding encoding) { HMACMD5 hmacMD5 = new HMACMD5(key); byte[] textBytes = encoding.GetBytes(text); byte[] encodedTextBytes = hmacMD5.ComputeHash(textBytes); string encodedText = Convert.ToBase64String(encodedTextBytes); return encodedText; }
In my example, the text
parameter would be a combination of request uri, a shared secret and timestamp (which will be available as a request header and used to prevent replay attacks).
Is this form of authentication decent? I've come across another thread here that suggests that the method defined in the articles above is "..a (sic) ugly hack." The author doesn't suggest why, but it is discouraging given that I've spent a few hours reading about this and getting it working. However, it's worth noting that the accepted answer on this question talks about a custom HMAC authorisation scheme so it is possible the ugly hack reference is simply the implementation of it rather than the use of HMAC algorithms themselves.
The diagram below if from the wikipedia article on Message Authentication Code. I feel like this should be a secure way to go, but I just want to make sure I understand it's use correctly and also make sure this isn't simply some dated mechanism that has been surpassed by something much better.