security - How to pass API token with timestamp reliably -
i'm making api call 1 app another. handle authorization passing md5
ed shared secret + timestamp...
$token = md5( $secret . time() );
then @ api endpoint, check authenticity of request this...
if ( md5($shared_secret . time() ) == $token ) ...do stuff
this works. isn't reliable i'd like. suspect reason due latency in network (or slow localhost server) causing timestamps mismatched second or so.
i worked around in lazy way dropping last digit of timestamp, creating 10 second window slowpoke server make call. however, i'm not satisfied because if call happens fall @ end of 9th second, i'll have same problem again (send @ #######49 != received @ ########50).
there must better way this. it?
consider using token = time || mac(time, shared_secret)
|| concatenation , mac message authentication algorithm such hmac, takes secret key , data , produces authentication tag. on server end, check mac valid , time (received in plaintext) within acceptable window.
this more secure current solution (md5 makes poor mac) , solves window problem.
note scheme susceptible replay attacks within error window allow (e.g. same token sent ten times in 1 second window, , server has no way of telling).
Comments
Post a Comment