views:

51

answers:

2

Hi,

I would like to use the HTTPS to secure the communication between my client and the server. The first encrypted communication will be used to authenticate the user - i.e. checking his/her user name and password.

After the user credentials will be successfully checked by server I would like to start getting some data in subsequent requests. BUT how the server will determine that the subsequent request is send by the user, whose credentials were already checked?

Since the TCP connection might be closed between login and subsequent HTTPS requests, (I think) this means that the SSL context must be released by the server, so with the new GET request, the new TCP connection must be established and the new SSL(TLS) handshake must be done (i.e. new shared password for the encryption must be exchanged by both sides, etc.)

For this I think server needs to send back to the client in 200 OK response for the initial authentication request some randomly generated nonce (which is valid for a certain time), which I will include in every subsequent request, so the server will be able to detect, based on this randomly generated nonce, which user name is behind the request and check that this user is already logged in. Is my understanding correct?

Thanks a lot for the reply BR STeN

A: 

The simplest method is to require all communication to go via HTTPS (so the data is confidential; nobody other than the client and the server can see it) and to use simple username and password on every request inside that secure connection. This is dead simple to do in practice (the username and password actually go over the connection as an HTTP header, which is OK here because we're using HTTPS) and the server can check every time that the user is allowed. You don't need to worry about the SSL handshakes; that's the SSL/HTTPS layer's responsibility (and that's why HTTPS/SSL is nice).

Alternatively, the login can be done with any method and generate some kind of magic number (e.g., a UUID or a cryptographic hash of a random number and the user's name) that is stored in a session cookie. Subsequent requests can just check that the magic number is one that it recognizes from session start (and that not too much time has passed since it was issued); logout just becomes forgetting the magic number on the server side (and asking the client to forget too). It's a bit more work to implement this, but still isn't hard and there are libraries for server-side to handle the donkey work.

The first option is particularly good for where you're writing something to be used by other programs, as it is really easy to implement. The second option is better where the client is a web browser as it gives users more control over when their browser is authorized (program APIs don't tend to need that sort of thing). Whenever the client is going to be a browser, you need to take care to armor against other types of attack too (e.g., various types of request forgery) but that's pretty much independent of everything else.

Donal Fellows
Hi, thanks a lot for a your comment! All communication is going over HTTPS - with no exception. I was thinking the same - either send username/passw in every request or let the server to reply to the first request with some magic, which I will use then in every request instead of repeating the username/pass (my client is not a browser, but custom app.). I think both approaches are more or less same, while the 2nd needs more work to be done on server. Can I ask you what is the industry standard? Are HTTPS application made in a way that they resend username/passw in every request? Thanks,BR STeN
STeN
@STeN: There are several "industry standards", depending on what your requirements really are. I've listed two above that are both very common and which have somewhat different common use patterns. There are others (e.g., client certificates at the SSL level) but they're less common and you're more likely to run into problems with getting portable implementations or good deployments.
Donal Fellows
Thanks - your advices are really good!
STeN
A: 

Inventing custom authentication mechanism in your case is very risky - it's easy to make a mistake that will let lots of wrong doing. So the right approach, as for me, would be to use HTTPS and pass user credentials with each request.

Eugene Mayevski 'EldoS Corp
Hi, I will use HTTPS only. But still the server needs to know who is accessing it. The communication must be safe, but user must authenticate also in order to access the system. As Mr. Donal Fellows suggested in the comment below - the easiest is to include the username and password in the every request... Thanks for your comment.
STeN