views:

171

answers:

3

Because I don't exactly know how any auth method works I want to write my own. So, what I want to do is the following. A client sends over HTTPs username+password(or SHA1(username+password)) the server gets the username+password and generates a big random number and stores it in a table called TOKENS(in some database) along with his IP, then it give the client that exact number. From now on, all the requests made by the client are accompanied by that TOKEN and if the TOKEN is not in the table TOKENS then any such request will fail. If the user hasn't made any requests in 2 hours the TOKEN will expire. If the user wants to log out he makes a request '/logout' to the server and the server deletes from the table TOKENS the entry containing his token but ONLY if the request to '/logout' originates from his IP.

Maybe I am reinventing the wheel... this wouldn't be very good so my question is if there is some auth system that already works like this , what is it's name , does it have any OSS C++ libraries or Python libraries available ?

I am not sure if finding such an auth system and configuring it would take longer than writing it myself, on the other hand I know security is a delicate problem so I am approaching this with some doubt that I am capable of writing something secure enough.

Also, is there a good OSS C++ HTTP library ? I'm planning to write a RESTful Desktop client for a web app. Depending on the available libraries I will choose if I'll write it in C++ or Python.

A: 

If you are implementing such authentication system over ordinary HTTP, you are vulnerable to replay attacks. Attacker could sniff out the SHA1(username+password) and just resend it every time he/she wants to log in. To make such authentication system work, you will need to use a nonce.

You might want to look at HTTP Digest authentication for tips.

hrnt
what if he sniffs the nonce as well ?even more ... he has access to the RESTful Desktop Client becauseit will be publicly downloadable.
xxxxxxx
also , what does the dotted horizontal line in the wikipedia diagrammean ? does it mean something special as opposed to the continous one ?
xxxxxxx
Nonce is only used once, which is why you cannot use that value for replay attacks. What do you mean with horizontal line? Do you mean the colon (:)? If you mean that, it is just a colon :) The values are separated by the colon character ':'.
hrnt
This drawing , the horizontal lines with the arrow at the end ... http://upload.wikimedia.org/wikipedia/commons/4/4f/Nonce-cnonce-uml.svg
xxxxxxx
Ah, I see. That looks like a UML sequence diagram. Dashed horizontal lines are used to indicate return values.
hrnt
so any thoughts on the other questions ?
xxxxxxx
There is [cURL][1] which has C++ bindings. I haven't tried it myself, but it should support HTTP Digest authentication. Don't reinvent the wheel. [1]: http://curlpp.org/
hrnt
A: 

Because I don't exactly know how any auth method works I want to write my own

How could you ever write something you don't understand? Learn at least one, the underlaying concepts are similar in every library.

Python has repoze.what.

THC4k
A: 

I would highly recommend OAuth here, for which many open source libraries are available.

Jon Moore