I'm developing a web service using Scalatra and I want to use HMAC for bidirectional authentication.
So far, I've implemented the client authentication to the server: the client (an Android app) calculates a HMAC/SHA512 for each request using these parameters: a shared secret, the HTTP method, URL, some headers (timestamp, clientId etc) and the request body (if it's a POST or a PUT). This HMAC is then added to a specific header and the request is sent to the server (which validates the HMAC in the request header with a HMAC that it calculates the same as the client).
Now, I want to do the opposite thing: have the server authenticate to the client using the stored shared secret, the request HTTP method, URL and the response body.
So far, I've found that I can override renderResponse(actionResult: Any)
, renderResponseBody(actionResult: Any)
or even renderPipeline
and I've decided to go with overriding renderPipeline
as it seems to be the easiest to handle.
In my overriden renderPipeline
I transform the response body to a byte array (loading the served File
in memory if serving a File
), calculate the HMAC and add it to the response
headers.
What I want to know is: are there cases when overriding renderPipeline
this way would break either the authentication functionality presented above (like renderPipeline
not being called or being called multiple times or the headers having been sent befor renderPipeline
is called to render the body) or some other functionality in Scalatra?
As a note I do not calculate the HMAC when the action returns Unit
and the response output is being written directly by the action.