2

We are currently designing a REST API, and thinking about securing it.
Going through a lot of documentation, it has become clear that 2 options are available.

HMAC Authentication

By hashing with HMAC-sha1 a series of predefined elements with the secret_key, we sign the request. The verification is done by doing the exact same process server side and comparing the resulting hashes.

Our implementation goes like this:

  • Getting current timestamp
  • Creating HMAC: hmac(full_url + request_body + timestamp + secret_key + token)
  • Sending the signature as it: clientId + hmac_signature + timestamp + token

The main advantage of this, is that the secret_key is never transmitted in the request, which prevents replay attacks mostly. But as a drawback we have to store the client credentials (secret_key) in a raw format in our database. And if our database gets compromised we might as well revoke all current API clients credentials.

HTTPS Authentication

Using SSL over our API will allow us to create a secure channel to exchange private information.
We basically send the same information without hashing it with HMAC.

Our design is going to be exactly like (or very similar to) the OAuth2 specification.

Comparing to HMAC this has many advantages as we delegate most of the job to SSL. And clients do not have to include a library for hashing like with HMAC. Finally our database is safe since client's secret_key will be securely stored.

But if someone successfully sniffs out one request, he could steal the secret_key and start to create his own requests.

Is there a way to use the advantages of HTTPS without sending clear credentials and without having to store clear credentials?

One of our alternative designs was using private/public key generated client side, and use it to exchange a key to encrypt secret_key for future requests. But not many browsers have this capability (<keygen>) and it is quite an annoyance for mobile applications.

  • 1
    https will not send clear credentials. how will someone sniff one https request to get key? – mcgyver5 Jul 13 '15 at 15:05
  • Credentials will be sent in clear through the ssl connection. Maybe this is a misunderstanding from myself, but doesn't this makes it vulnerable if someone use mitm attack ? – Cyrbil Jul 13 '15 at 15:10
  • 1
    part of the purpose of ssl/tls (https) is to not send credentials in the clear. When working, it defeats mitm. – mcgyver5 Jul 13 '15 at 15:13
  • What part of ssl am I missing ? One could easily setup an ssl proxy and observe https traffic. I have seen it for many mobile application and seen used to get token and credentials.. – Cyrbil Jul 13 '15 at 15:19
  • 1
    What you are missing is that the client-to-server HTTPS connection will have to terminate at the proxy and the proxy will then have to create a new HTTPS connection to the server. Both the client and the server will be aware of this and as long as you have configured the client and server correctly (default for most systems) the client will protest because the endpoint (proxy) will not match the device registered to the SSL certificate identifying the server. – David Scholefield Jul 13 '15 at 16:42
2

As pointed out in the comments, ssl/tls will protect your credentials in transit. Encrypting traffic is part of the purpose of the protocol. The other major purpose of the protocol: verifying that you are communicating directly with the party you think you are communicating with.

The OP said that ssl proxies are possible and has seen it in action for mobile applications.
It is true that ssl man-in-the-middle proxies exist, but the client will warn that the server it is talking to has failed to present a valid certificate (and if the client is a browser, not proceed).

If your Rest API is configured to ignore bad SSL certificates (and some are - i know, I've written one), then, yes, a ssl MITM proxy would indeed be able to sniff your credentials. This is purposely subverting the SSL/TLS protocol (you can't say you are using SSL/TLS in this case).
This is why "self-signed" certificates are only for development and testing purposes.

  • SSL/TLS will protect your credentials in transit with one or two minor exceptions, such as a workplace installing a root certificate off of an SSL-inspecting firewall into the certificate store on all of their workstations (on all machines joined to an Active Directory domain, for instance). – Craig Jul 13 '15 at 20:50
  • Yup. There are ways to subvert the protocol. Rogue certificate authorities (phreedom.org/research/rogue-ca) are another. – mcgyver5 Jul 18 '15 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.